2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! Why not get us to quote to get FreeRTOS.org *
\r
30 * running on your hardware - or even write all or part of your application*
\r
31 * for you? See http://www.OpenRTOS.com for details. *
\r
33 ***************************************************************************
\r
34 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
51 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0.
\r
53 This file contains all the serial port components that must be compiled
\r
54 to ARM mode. The components that can be compiled to either ARM or THUMB
\r
55 mode are contained in serial.c.
\r
58 /* This file must always be compiled to ARM mode as it contains ISR
\r
62 /* Standard includes. */
\r
65 /* Scheduler includes. */
\r
66 #include "FreeRTOS.h"
\r
70 /* Demo application includes. */
\r
73 /*-----------------------------------------------------------*/
\r
75 /* Constant to access the VIC. */
\r
76 #define serCLEAR_VIC_INTERRUPT ( ( unsigned portLONG ) 0 )
\r
78 /* Constants to determine the ISR source. */
\r
79 #define serSOURCE_THRE ( ( unsigned portCHAR ) 0x02 )
\r
80 #define serSOURCE_RX_TIMEOUT ( ( unsigned portCHAR ) 0x0c )
\r
81 #define serSOURCE_ERROR ( ( unsigned portCHAR ) 0x06 )
\r
82 #define serSOURCE_RX ( ( unsigned portCHAR ) 0x04 )
\r
83 #define serINTERRUPT_SOURCE_MASK ( ( unsigned portCHAR ) 0x0f )
\r
85 /* Queues used to hold received characters, and characters waiting to be
\r
87 static xQueueHandle xRxedChars;
\r
88 static xQueueHandle xCharsForTx;
\r
89 static volatile portLONG lTHREEmpty;
\r
91 /*-----------------------------------------------------------*/
\r
93 /* UART0 interrupt service routine. This can cause a context switch so MUST
\r
94 be declared "naked". */
\r
95 void vUART_ISR( void );
\r
97 /*-----------------------------------------------------------*/
\r
98 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRxedChars,
\r
99 xQueueHandle *pxCharsForTx, portLONG volatile **pplTHREEmptyFlag )
\r
101 /* Create the queues used to hold Rx and Tx characters. */
\r
102 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
103 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed portCHAR ) );
\r
105 /* Pass back a reference to the queues so the serial API file can
\r
106 post/receive characters. */
\r
107 *pxRxedChars = xRxedChars;
\r
108 *pxCharsForTx = xCharsForTx;
\r
110 /* Initialise the THRE empty flag - and pass back a reference. */
\r
111 lTHREEmpty = pdTRUE;
\r
112 *pplTHREEmptyFlag = &lTHREEmpty;
\r
114 /*-----------------------------------------------------------*/
\r
116 void vUART_ISR( void ) __task
\r
118 portENTER_SWITCHING_ISR()
\r
120 /* Now we can declare the local variables. */
\r
121 static signed portCHAR cChar;
\r
122 static portBASE_TYPE xTaskWokenByRx, xTaskWokenByTx;
\r
124 xTaskWokenByTx = pdFALSE;
\r
125 xTaskWokenByRx = pdFALSE;
\r
127 /* What caused the interrupt? */
\r
128 switch( U0IIR & serINTERRUPT_SOURCE_MASK )
\r
130 case serSOURCE_ERROR : /* Not handling this, but clear the interrupt. */
\r
134 case serSOURCE_THRE : /* The THRE is empty. If there is another
\r
135 character in the Tx queue, send it now. */
\r
136 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xTaskWokenByTx ) == pdTRUE )
\r
142 /* There are no further characters
\r
143 queued to send so we can indicate
\r
144 that the THRE is available. */
\r
145 lTHREEmpty = pdTRUE;
\r
149 case serSOURCE_RX_TIMEOUT :
\r
150 case serSOURCE_RX : /* A character was received. Place it in
\r
151 the queue of received characters. */
\r
153 if( xQueueSendFromISR( xRxedChars, &cChar, pdFALSE ) )
\r
155 xTaskWokenByRx = pdTRUE;
\r
159 default : /* There is nothing to do, leave the ISR. */
\r
163 /* Clear the ISR in the VIC. */
\r
164 VICVectAddr = serCLEAR_VIC_INTERRUPT;
\r
166 /* Exit the ISR. If a task was woken by either a character being received
\r
167 or transmitted then a context switch will occur. */
\r
168 portEXIT_SWITCHING_ISR( ( xTaskWokenByTx || xTaskWokenByRx ) );
\r
170 /*-----------------------------------------------------------*/
\r