14 // Demo application includes
20 // Constants to determine the ISR source
22 #define serSOURCE_THRE ((unsigned portCHAR) 0x02)
23 #define serSOURCE_RX_TIMEOUT ((unsigned portCHAR) 0x0c)
24 #define serSOURCE_ERROR ((unsigned portCHAR) 0x06)
25 #define serSOURCE_RX ((unsigned portCHAR) 0x04)
26 #define serINTERRUPT_SOURCE_MASK ((unsigned portCHAR) 0x0f)
29 // Queues used to hold received characters, and characters waiting to be transmitted
31 static xQueueHandle xRX0Queue;
32 static xQueueHandle xTX0Queue;
33 static volatile portLONG lTHREEmpty0;
34 static xQueueHandle xRX1Queue;
35 static xQueueHandle xTX1Queue;
36 static volatile portLONG lTHREEmpty1;
41 void uartISRCreateQueues (portCHAR pxPort, unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRX0Queue, xQueueHandle *pxTX0Queue, portLONG volatile **pplTHREEmptyFlag)
48 // Create the queues used to hold Rx and Tx characters
50 *pxRX0Queue = xRX0Queue = xQueueCreate (uxQueueLength, (unsigned portBASE_TYPE) sizeof (signed portCHAR));
51 *pxTX0Queue = xTX0Queue = xQueueCreate (uxQueueLength + 1, (unsigned portBASE_TYPE) sizeof (signed portCHAR));
54 // Initialise the THRE empty flag - and pass back a reference
56 lTHREEmpty0 = (portLONG) pdTRUE;
57 *pplTHREEmptyFlag = &lTHREEmpty0;
64 // Create the queues used to hold Rx and Tx characters
66 *pxRX0Queue = xRX1Queue = xQueueCreate (uxQueueLength, (unsigned portCHAR) sizeof (signed portCHAR));
67 *pxTX0Queue = xTX1Queue = xQueueCreate (uxQueueLength + 1, (unsigned portCHAR) sizeof (signed portCHAR));
70 // Initialise the THRE empty flag - and pass back a reference
72 lTHREEmpty1 = (portLONG) pdTRUE;
73 *pplTHREEmptyFlag = &lTHREEmpty1;
82 void uartISR0 (void) __attribute__ ((naked));
85 portENTER_SWITCHING_ISR ();
87 signed portCHAR cChar;
88 portBASE_TYPE xTaskWokenByTx = pdFALSE;
89 portBASE_TYPE xTaskWokenByRx = pdFALSE;
91 switch (UART0_IIR & serINTERRUPT_SOURCE_MASK)
94 // Not handling this, but clear the interrupt
96 case serSOURCE_ERROR :
103 // The THRE is empty. If there is another character in the Tx queue, send it now,
104 // otherwise, no more characters, so indicate THRE is available
106 case serSOURCE_THRE :
108 if (xQueueReceiveFromISR (xTX0Queue, &cChar, &xTaskWokenByTx) == pdTRUE)
111 lTHREEmpty0 = pdTRUE;
116 // A character was received. Place it in the queue of received characters
118 case serSOURCE_RX_TIMEOUT :
123 if (xQueueSendFromISR (xRX0Queue, &cChar, (portBASE_TYPE) pdFALSE))
124 xTaskWokenByRx = pdTRUE;
132 VIC_VectAddr = (unsigned portLONG) 0;
134 portEXIT_SWITCHING_ISR ((xTaskWokenByTx || xTaskWokenByRx));
140 void uartISR1 (void) __attribute__ ((naked));
143 portENTER_SWITCHING_ISR ();
145 signed portCHAR cChar;
146 portBASE_TYPE xTaskWokenByTx = pdFALSE;
147 portBASE_TYPE xTaskWokenByRx = pdFALSE;
149 switch (UART1_IIR & serINTERRUPT_SOURCE_MASK)
152 // Not handling this, but clear the interrupt
154 case serSOURCE_ERROR :
161 // The THRE is empty. If there is another character in the Tx queue, send it now,
162 // otherwise, no more characters, so indicate THRE is available
164 case serSOURCE_THRE :
166 if (xQueueReceiveFromISR (xTX1Queue, &cChar, &xTaskWokenByTx) == pdTRUE)
169 lTHREEmpty1 = pdTRUE;
174 // A character was received. Place it in the queue of received characters
176 case serSOURCE_RX_TIMEOUT :
181 if (xQueueSendFromISR (xRX1Queue, &cChar, (portBASE_TYPE) pdFALSE))
182 xTaskWokenByRx = pdTRUE;
190 VIC_VectAddr = (unsigned portLONG) 0;
192 portEXIT_SWITCHING_ISR ((xTaskWokenByTx || xTaskWokenByRx));