9 #if defined(__CDT_PARSER__)
15 #define INTERRUPT_PRIORITY_GROUP 2
16 #define ISR_URX() ISR(URX0, 0)
17 #define ISR_UTX() ISR(UTX0, 0)
26 #define BV_UTXNIE (1<<2)
27 #define uartNRxParityErrorOccurred uart0RxParityErrorOccurred
28 #define uartNRxFramingErrorOccurred uart0RxFramingErrorOccurred
29 #define uartNRxBufferFullOccurred uart0RxBufferFullOccurred
30 #define uartNRxAvailable uart0RxAvailable
31 #define uartNTxAvailable uart0TxAvailable
32 #define uartNInit uart0Init
33 #define uartNSetBaudRate uart0SetBaudRate
34 #define uartNSetParity uart0SetParity
35 #define uartNSetStopBits uart0SetStopBits
36 #define uartNTxSend uart0TxSend
37 #define uartNRxReceiveByte uart0RxReceiveByte
38 #define uartNTxSend uart0TxSend
39 #define uartNTxSendByte uart0TxSendByte
43 #define INTERRUPT_PRIORITY_GROUP 3
44 #define ISR_URX() ISR(URX1, 0)
45 #define ISR_UTX() ISR(UTX1, 0)
54 #define BV_UTXNIE (1<<3)
55 #define uartNRxParityErrorOccurred uart1RxParityErrorOccurred
56 #define uartNRxFramingErrorOccurred uart1RxFramingErrorOccurred
57 #define uartNRxBufferFullOccurred uart1RxBufferFullOccurred
58 #define uartNRxAvailable uart1RxAvailable
59 #define uartNTxAvailable uart1TxAvailable
60 #define uartNInit uart1Init
61 #define uartNSetBaudRate uart1SetBaudRate
62 #define uartNSetParity uart1SetParity
63 #define uartNSetStopBits uart1SetStopBits
64 #define uartNTxSend uart1TxSend
65 #define uartNRxReceiveByte uart1RxReceiveByte
66 #define uartNTxSend uart1TxSend
67 #define uartNTxSendByte uart1TxSendByte
71 static volatile uint8 DATA uartTxBufferMainLoopIndex;
72 static volatile uint8 DATA uartTxBufferInterruptIndex;
74 #define UART_TX_BUFFER_FREE_BYTES() ((uartTxBufferInterruptIndex - uartTxBufferMainLoopIndex - 1) & (sizeof(uartTxBuffer) - 1))
77 static volatile uint8 DATA uartRxBufferMainLoopIndex;
78 static volatile uint8 DATA uartRxBufferInterruptIndex;
80 #define UART_RX_BUFFER_FREE_BYTES() ((uartRxBufferMainLoopIndex - uartRxBufferInterruptIndex - 1) & (sizeof(uartRxBuffer) - 1))
81 #define UART_RX_BUFFER_USED_BYTES() ((uartRxBufferInterruptIndex - uartRxBufferMainLoopIndex) & (sizeof(uartRxBuffer) - 1))
83 volatile BIT uartNRxParityErrorOccurred;
84 volatile BIT uartNRxFramingErrorOccurred;
85 volatile BIT uartNRxBufferFullOccurred;
99 uartTxBufferMainLoopIndex = 0;
100 uartTxBufferInterruptIndex = 0;
101 uartRxBufferMainLoopIndex = 0;
102 uartRxBufferInterruptIndex = 0;
103 uartNRxParityErrorOccurred = 0;
104 uartNRxFramingErrorOccurred = 0;
105 uartNRxBufferFullOccurred = 0;
134 IP0 |= (1<<INTERRUPT_PRIORITY_GROUP);
135 IP1 &= ~(1<<INTERRUPT_PRIORITY_GROUP);
143 void uartNSetBaudRate(
uint32 baud)
149 if (baud < 23 || baud > 1500000)
153 while (baud > 495782)
161 baudMPlus256 = (baud * 11) + (baud * 8663 / 46875);
164 while (baudMPlus256 > 0x1ff)
170 UNBAUD = baudMPlus256;
173 void uartNSetParity(
uint8 parity)
192 UNUCR = (UNUCR & 0b01000111) | tmp;
195 void uartNSetStopBits(
uint8 stopBits)
208 uint8 uartNTxAvailable(
void)
210 return UART_TX_BUFFER_FREE_BYTES();
220 uartTxBuffer[uartTxBufferMainLoopIndex] = *buffer;
223 uartTxBufferMainLoopIndex = (uartTxBufferMainLoopIndex + 1) & (
sizeof(uartTxBuffer) - 1);
230 void uartNTxSendByte(
uint8 byte)
234 uartTxBuffer[uartTxBufferMainLoopIndex] = byte;
235 uartTxBufferMainLoopIndex = (uartTxBufferMainLoopIndex + 1) & (
sizeof(uartTxBuffer) - 1);
240 uint8 uartNRxAvailable(
void)
242 return UART_RX_BUFFER_USED_BYTES();
245 uint8 uartNRxReceiveByte(
void)
249 uint8 byte = uartRxBuffer[uartRxBufferMainLoopIndex];
250 uartRxBufferMainLoopIndex = (uartRxBufferMainLoopIndex + 1) & (
sizeof(uartRxBuffer) - 1);
259 if (uartTxBufferInterruptIndex != uartTxBufferMainLoopIndex)
266 UNDBUF = uartTxBuffer[uartTxBufferInterruptIndex];
267 uartTxBufferInterruptIndex = (uartTxBufferInterruptIndex + 1) & (
sizeof(uartTxBuffer) - 1);
292 if (UART_RX_BUFFER_FREE_BYTES())
295 uartRxBuffer[uartRxBufferInterruptIndex] = UNDBUF;
296 uartRxBufferInterruptIndex = (uartRxBufferInterruptIndex + 1) & (
sizeof(uartRxBuffer) - 1);
301 uartNRxBufferFullOccurred = 1;
308 uartNRxFramingErrorOccurred = 1;
312 uartNRxParityErrorOccurred = 1;