2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0.
\r
74 This file contains all the serial port components that must be compiled
\r
75 to ARM mode. The components that can be compiled to either ARM or THUMB
\r
76 mode are contained in serial.c.
\r
80 /* Standard includes. */
\r
83 /* Scheduler includes. */
\r
84 #include "FreeRTOS.h"
\r
88 /* Demo application includes. */
\r
91 /*-----------------------------------------------------------*/
\r
93 /* Constant to access the VIC. */
\r
94 #define serCLEAR_VIC_INTERRUPT ( ( unsigned long ) 0 )
\r
96 /* Constants to determine the ISR source. */
\r
97 #define serSOURCE_THRE ( ( unsigned char ) 0x02 )
\r
98 #define serSOURCE_RX_TIMEOUT ( ( unsigned char ) 0x0c )
\r
99 #define serSOURCE_ERROR ( ( unsigned char ) 0x06 )
\r
100 #define serSOURCE_RX ( ( unsigned char ) 0x04 )
\r
101 #define serINTERRUPT_SOURCE_MASK ( ( unsigned char ) 0x0f )
\r
103 /* Queues used to hold received characters, and characters waiting to be
\r
105 static QueueHandle_t xRxedChars;
\r
106 static QueueHandle_t xCharsForTx;
\r
107 static volatile long lTHREEmpty;
\r
109 /*-----------------------------------------------------------*/
\r
112 * The queues are created in serialISR.c as they are used from the ISR.
\r
113 * Obtain references to the queues and THRE Empty flag.
\r
115 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, QueueHandle_t *pxRxedChars, QueueHandle_t *pxCharsForTx, long volatile **pplTHREEmptyFlag );
\r
117 /* UART0 interrupt service routine entry point. */
\r
118 void vUART_ISR_Wrapper( void ) __attribute__ ((naked));
\r
120 /* UART0 interrupt service routine handler. */
\r
121 void vUART_ISR_Handler( void ) __attribute__ ((noinline));
\r
123 /*-----------------------------------------------------------*/
\r
124 void vSerialISRCreateQueues( unsigned portBASE_TYPE uxQueueLength, QueueHandle_t *pxRxedChars,
\r
125 QueueHandle_t *pxCharsForTx, long volatile **pplTHREEmptyFlag )
\r
127 /* Create the queues used to hold Rx and Tx characters. */
\r
128 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
129 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
131 /* Pass back a reference to the queues so the serial API file can
\r
132 post/receive characters. */
\r
133 *pxRxedChars = xRxedChars;
\r
134 *pxCharsForTx = xCharsForTx;
\r
136 /* Initialise the THRE empty flag - and pass back a reference. */
\r
137 lTHREEmpty = ( long ) pdTRUE;
\r
138 *pplTHREEmptyFlag = &lTHREEmpty;
\r
140 /*-----------------------------------------------------------*/
\r
142 void vUART_ISR_Wrapper( void )
\r
144 /* Save the context of the interrupted task. */
\r
145 portSAVE_CONTEXT();
\r
147 /* Call the handler. This must be a separate function from the wrapper
\r
148 to ensure the correct stack frame is set up. */
\r
149 __asm volatile ("bl vUART_ISR_Handler");
\r
151 /* Restore the context of whichever task is going to run next. */
\r
152 portRESTORE_CONTEXT();
\r
154 /*-----------------------------------------------------------*/
\r
156 void vUART_ISR_Handler( void )
\r
159 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
161 /* What caused the interrupt? */
\r
162 switch( UART0_IIR & serINTERRUPT_SOURCE_MASK )
\r
164 case serSOURCE_ERROR : /* Not handling this, but clear the interrupt. */
\r
168 case serSOURCE_THRE : /* The THRE is empty. If there is another
\r
169 character in the Tx queue, send it now. */
\r
170 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
176 /* There are no further characters
\r
177 queued to send so we can indicate
\r
178 that the THRE is available. */
\r
179 lTHREEmpty = pdTRUE;
\r
183 case serSOURCE_RX_TIMEOUT :
\r
184 case serSOURCE_RX : /* A character was received. Place it in
\r
185 the queue of received characters. */
\r
187 xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
190 default : /* There is nothing to do, leave the ISR. */
\r
194 if( xHigherPriorityTaskWoken )
\r
196 portYIELD_FROM_ISR();
\r
199 /* Clear the ISR in the VIC. */
\r
200 VICVectAddr = serCLEAR_VIC_INTERRUPT;
\r