2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\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
59 /* Standard includes. */
\r
62 /* Scheduler includes. */
\r
63 #include "FreeRTOS.h"
\r
67 /* Demo application includes. */
\r
70 /*-----------------------------------------------------------*/
\r
72 /* Constant to access the VIC. */
\r
73 #define serCLEAR_VIC_INTERRUPT ( ( unsigned long ) 0 )
\r
75 /* Constants to determine the ISR source. */
\r
76 #define serSOURCE_THRE ( ( unsigned char ) 0x02 )
\r
77 #define serSOURCE_RX_TIMEOUT ( ( unsigned char ) 0x0c )
\r
78 #define serSOURCE_ERROR ( ( unsigned char ) 0x06 )
\r
79 #define serSOURCE_RX ( ( unsigned char ) 0x04 )
\r
80 #define serINTERRUPT_SOURCE_MASK ( ( unsigned char ) 0x0f )
\r
82 /* Queues used to hold received characters, and characters waiting to be
\r
84 static xQueueHandle xRxedChars;
\r
85 static xQueueHandle xCharsForTx;
\r
86 static volatile long lTHREEmpty;
\r
88 /*-----------------------------------------------------------*/
\r
91 * The queues are created in serialISR.c as they are used from the ISR.
\r
92 * Obtain references to the queues and THRE Empty flag.
\r
94 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRxedChars, xQueueHandle *pxCharsForTx, long volatile **pplTHREEmptyFlag );
\r
96 /* UART0 interrupt service routine entry point. */
\r
97 void vUART_ISR_Wrapper( void ) __attribute__ ((naked));
\r
99 /* UART0 interrupt service routine handler. */
\r
100 void vUART_ISR_Handler( void ) __attribute__ ((noinline));
\r
102 /*-----------------------------------------------------------*/
\r
103 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, xQueueHandle *pxRxedChars,
\r
104 xQueueHandle *pxCharsForTx, long volatile **pplTHREEmptyFlag )
\r
106 /* Create the queues used to hold Rx and Tx characters. */
\r
107 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
108 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
110 /* Pass back a reference to the queues so the serial API file can
\r
111 post/receive characters. */
\r
112 *pxRxedChars = xRxedChars;
\r
113 *pxCharsForTx = xCharsForTx;
\r
115 /* Initialise the THRE empty flag - and pass back a reference. */
\r
116 lTHREEmpty = ( long ) pdTRUE;
\r
117 *pplTHREEmptyFlag = &lTHREEmpty;
\r
119 /*-----------------------------------------------------------*/
\r
121 void vUART_ISR_Wrapper( void )
\r
123 /* Save the context of the interrupted task. */
\r
124 portSAVE_CONTEXT();
\r
126 /* Call the handler. This must be a separate function from the wrapper
\r
127 to ensure the correct stack frame is set up. */
\r
128 __asm volatile ("bl vUART_ISR_Handler");
\r
130 /* Restore the context of whichever task is going to run next. */
\r
131 portRESTORE_CONTEXT();
\r
133 /*-----------------------------------------------------------*/
\r
135 void vUART_ISR_Handler( void )
\r
138 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
140 /* What caused the interrupt? */
\r
141 switch( UART0_IIR & serINTERRUPT_SOURCE_MASK )
\r
143 case serSOURCE_ERROR : /* Not handling this, but clear the interrupt. */
\r
147 case serSOURCE_THRE : /* The THRE is empty. If there is another
\r
148 character in the Tx queue, send it now. */
\r
149 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
155 /* There are no further characters
\r
156 queued to send so we can indicate
\r
157 that the THRE is available. */
\r
158 lTHREEmpty = pdTRUE;
\r
162 case serSOURCE_RX_TIMEOUT :
\r
163 case serSOURCE_RX : /* A character was received. Place it in
\r
164 the queue of received characters. */
\r
166 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
169 default : /* There is nothing to do, leave the ISR. */
\r
173 if( xHigherPriorityTaskWoken )
\r
175 portYIELD_FROM_ISR();
\r
178 /* Clear the ISR in the VIC. */
\r
179 VICVectAddr = serCLEAR_VIC_INTERRUPT;
\r