projects
/
pub
/
lufa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f64e3db
)
Switch software UART over to timer 1 and remove timer prescaling to try to prevent...
author
Dean Camera
<dean@fourwalledcubicle.com>
Wed, 26 May 2010 07:51:25 +0000
(07:51 +0000)
committer
Dean Camera
<dean@fourwalledcubicle.com>
Wed, 26 May 2010 07:51:25 +0000
(07:51 +0000)
Projects/XPLAINBridge/Lib/SoftUART.c
patch
|
blob
|
blame
|
history
Projects/XPLAINBridge/Lib/SoftUART.h
patch
|
blob
|
blame
|
history
Projects/XPLAINBridge/XPLAINBridge.c
patch
|
blob
|
blame
|
history
diff --git
a/Projects/XPLAINBridge/Lib/SoftUART.c
b/Projects/XPLAINBridge/Lib/SoftUART.c
index
0591284
..
c001c07
100644
(file)
--- a/
Projects/XPLAINBridge/Lib/SoftUART.c
+++ b/
Projects/XPLAINBridge/Lib/SoftUART.c
@@
-44,10
+44,10
@@
static uint8_t RX_BitMask, RX_Data;
void SoftUART_Init(void)
{
void SoftUART_Init(void)
{
- OCR
2B = TCNT2
+ 1; // force first compare
- TCCR
2A = (1 << COM2B1) | (1 << COM2B0); //
T1 mode 0
- TCCR
2B = (1 << FOC2B) | (1 << CS21); // CLK/8, T1 mode 0
- TIMSK
2 = (1 << OCIE2
B); // enable tx and wait for start
+ OCR
1B = TCNT1
+ 1; // force first compare
+ TCCR
1B = (1 << CS10); // CLK/1,
T1 mode 0
+ TCCR
1C = (1 << FOC1B);
+ TIMSK
1 = (1 << OCIE1
B); // enable tx and wait for start
EICRA = (1 << ISC01); // -ve edge
EIMSK = (1 << INT0); // enable INT0 interrupt
EICRA = (1 << ISC01); // -ve edge
EIMSK = (1 << INT0); // enable INT0 interrupt
@@
-59,22
+59,22
@@
void SoftUART_Init(void)
/* ISR to detect the start of a bit being sent to the software UART. */
ISR(INT0_vect)
{
/* ISR to detect the start of a bit being sent to the software UART. */
ISR(INT0_vect)
{
- OCR
2A = TCNT2 + (uint16_t)((BIT_TIME / 8.0f) * 1.5f);
// scan 1.5 bits after start
+ OCR
1A = TCNT1 + ((BIT_TIME * 3) / 2) - 1;
// scan 1.5 bits after start
RX_Data = 0; // clear bit storage
RX_BitMask = (1 << 0); // bit mask
RX_Data = 0; // clear bit storage
RX_BitMask = (1 << 0); // bit mask
- TIFR
2 = (1 << OCF2
A); // clear pending interrupt
+ TIFR
1 = (1 << OCF1
A); // clear pending interrupt
if (!(SRXPIN & (1 << SRX))) // still low
{
if (!(SRXPIN & (1 << SRX))) // still low
{
- TIMSK
2 = (1 << OCIE2A) | (1 << OCIE2
B); // wait for first bit
+ TIMSK
1 = (1 << OCIE1A) | (1 << OCIE1
B); // wait for first bit
EIMSK &= ~(1 << INT0);
}
}
/* ISR to manage the reception of bits to the software UART. */
EIMSK &= ~(1 << INT0);
}
}
/* ISR to manage the reception of bits to the software UART. */
-ISR(TIMER
2
_COMPA_vect)
+ISR(TIMER
1
_COMPA_vect)
{
if (RX_BitMask)
{
{
if (RX_BitMask)
{
@@
-83,37
+83,37
@@
ISR(TIMER2_COMPA_vect)
RX_BitMask <<= 1;
RX_BitMask <<= 1;
- OCR
2A += BIT_TIME / 8;
// next bit slice
+ OCR
1A += BIT_TIME;
// next bit slice
}
else
{
RingBuffer_Insert(&UARTtoUSB_Buffer, RX_Data);
}
else
{
RingBuffer_Insert(&UARTtoUSB_Buffer, RX_Data);
- TIMSK
2 = (1 << OCIE2
B); // enable tx and wait for start
+ TIMSK
1 = (1 << OCIE1
B); // enable tx and wait for start
EIMSK |= (1 << INT0); // enable START irq
EIFR = (1 << INTF0); // clear any pending
}
}
/* ISR to manage the transmission of bits via the software UART. */
EIMSK |= (1 << INT0); // enable START irq
EIFR = (1 << INTF0); // clear any pending
}
}
/* ISR to manage the transmission of bits via the software UART. */
-ISR(TIMER
2
_COMPB_vect)
+ISR(TIMER
1
_COMPB_vect)
{
{
- OCR
2B += BIT_TIME / 8;
// next bit slice
+ OCR
1B += BIT_TIME;
// next bit slice
if (TX_BitsRemaining)
{
if (--TX_BitsRemaining != 9) // no start bit
{
if (TX_Data & (1 << 0)) // test inverted data
if (TX_BitsRemaining)
{
if (--TX_BitsRemaining != 9) // no start bit
{
if (TX_Data & (1 << 0)) // test inverted data
-
TCCR2A = (1 << COM2B1
);
+
STXPORT &= ~(1 << STX
);
else
else
-
TCCR2A = (1 << COM2B1) | (1 << COM2B0
);
+
STXPORT = (1 << STX
);
TX_Data >>= 1; // shift zero in from left
}
else
{
TX_Data >>= 1; // shift zero in from left
}
else
{
- TCCR2A = (1 << COM2B1); // START bit
+ STXPORT &= ~(1 << STX);
}
}
else if (USBtoUART_Buffer.Count)
}
}
else if (USBtoUART_Buffer.Count)
diff --git
a/Projects/XPLAINBridge/Lib/SoftUART.h
b/Projects/XPLAINBridge/Lib/SoftUART.h
index
a9401da
..
a685a6d
100644
(file)
--- a/
Projects/XPLAINBridge/Lib/SoftUART.h
+++ b/
Projects/XPLAINBridge/Lib/SoftUART.h
@@
-43,7
+43,7
@@
/* Macros: */
#define BAUD 9600
/* Macros: */
#define BAUD 9600
- #define BIT_TIME (
uint16_t)((F_CPU + (BAUD / 2.0f
)) / BAUD)
+ #define BIT_TIME (
(F_CPU + (BAUD / 2
)) / BAUD)
#define SRX PD0
#define SRXPIN PIND
#define SRX PD0
#define SRXPIN PIND
diff --git
a/Projects/XPLAINBridge/XPLAINBridge.c
b/Projects/XPLAINBridge/XPLAINBridge.c
index
308c2ab
..
d92e2b4
100644
(file)
--- a/
Projects/XPLAINBridge/XPLAINBridge.c
+++ b/
Projects/XPLAINBridge/XPLAINBridge.c
@@
-156,7
+156,7
@@
void SetupHardware(void)
_delay_ms(10);
/* Select the firmware mode based on the JTD pin's value */
_delay_ms(10);
/* Select the firmware mode based on the JTD pin's value */
- CurrentFirmwareMode =
MODE_USART_BRIDGE;//
(PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER;
+ CurrentFirmwareMode = (PINF & (1 << 7)) ? MODE_USART_BRIDGE : MODE_PDI_PROGRAMMER;
/* Re-enable JTAG debugging */
MCUCR &= ~(1 << JTD);
/* Re-enable JTAG debugging */
MCUCR &= ~(1 << JTD);