2 FreeRTOS V8.2.3 - Copyright (C) 2015 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
70 /* Basic interrupt driven serial port driver for uart1.
\r
73 /* Standard includes. */
\r
76 /* Kernel includes. */
\r
77 #include "FreeRTOS.h"
\r
81 /* Demo application includes. */
\r
82 #include <machine/uart.h>
\r
83 #include <machine/ic.h>
\r
85 /*-----------------------------------------------------------*/
\r
87 #define comBLOCK_RETRY_TIME 10
\r
88 /*-----------------------------------------------------------*/
\r
90 /* The interrupt handlers are naked functions that call C handlers. The C
\r
91 handlers are marked as noinline to ensure they work correctly when the
\r
93 void interrupt5_handler( void ) __attribute__((naked));
\r
94 static void prvTxHandler( void ) __attribute__((noinline));
\r
95 void interrupt6_handler( void ) __attribute__((naked));
\r
96 static void prvRxHandler( void ) __attribute__((noinline));
\r
98 /*-----------------------------------------------------------*/
\r
100 /* Queues used to hold received characters, and characters waiting to be
\r
102 static QueueHandle_t xRxedChars;
\r
103 static QueueHandle_t xCharsForTx;
\r
104 /*-----------------------------------------------------------*/
\r
106 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
108 /* Create the queues used to hold Rx and Tx characters. */
\r
109 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
110 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
112 if( ( xRxedChars ) && ( xCharsForTx ) )
\r
114 /* Set up interrupts */
\r
115 /* tx interrupt will be enabled when we need to send something */
\r
116 uart1->tx_mask = 0;
\r
117 uart1->rx_mask = 1;
\r
118 irq[IRQ_UART1_TX].ien = 1;
\r
119 irq[IRQ_UART1_RX].ien = 1;
\r
122 return ( xComPortHandle ) 0;
\r
124 /*-----------------------------------------------------------*/
\r
126 signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
128 /* The port handle is not required as this driver only supports uart1. */
\r
131 /* Get the next character from the buffer. Return false if no characters
\r
132 are available, or arrive before xBlockTime expires. */
\r
133 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
142 /*-----------------------------------------------------------*/
\r
144 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
147 signed char *pChNext;
\r
149 /* Send each character in the string, one at a time. */
\r
150 pChNext = ( signed char * )pcString;
\r
151 for( i = 0; i < usStringLength; i++ )
\r
153 /* Block until character has been transmitted. */
\r
154 while( xSerialPutChar( pxPort, *pChNext, comBLOCK_RETRY_TIME ) != pdTRUE ); pChNext++;
\r
157 /*-----------------------------------------------------------*/
\r
159 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
\r
163 /* Place the character in the queue of characters to be transmitted. */
\r
164 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) != pdPASS )
\r
169 /* Turn on the Tx interrupt so the ISR will remove the character from the
\r
170 queue and send it. This does not need to be in a critical section as
\r
171 if the interrupt has already removed the character the next interrupt
\r
172 will simply turn off the Tx interrupt again. */
\r
173 uart1->tx_mask = 1;
\r
177 /*-----------------------------------------------------------*/
\r
179 void vSerialClose( xComPortHandle xPort )
\r
181 /* Not supported as not required by the demo application. */
\r
184 /*-----------------------------------------------------------*/
\r
186 /* UART Tx interrupt handler. */
\r
187 void interrupt5_handler( void )
\r
189 /* This is a naked function. */
\r
190 portSAVE_CONTEXT();
\r
192 portRESTORE_CONTEXT();
\r
194 /*-----------------------------------------------------------*/
\r
196 static void prvTxHandler( void )
\r
199 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
201 /* The interrupt was caused by the transmit fifo having space for at least one
\r
202 character. Are there any more characters to transmit? */
\r
203 if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
\r
205 /* A character was retrieved from the queue so can be sent to the uart now. */
\r
206 uart1->tx_data = cChar;
\r
210 /* Queue empty, nothing to send so turn off the Tx interrupt. */
\r
211 uart1->tx_mask = 0;
\r
214 /* If an event caused a task to unblock then we call "Yield from ISR" to
\r
215 ensure that the unblocked task is the task that executes when the interrupt
\r
216 completes if the unblocked task has a priority higher than the interrupted
\r
218 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
220 /*-----------------------------------------------------------*/
\r
222 /* UART Rx interrupt. */
\r
223 void interrupt6_handler( void )
\r
225 portSAVE_CONTEXT();
\r
227 portRESTORE_CONTEXT();
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvRxHandler( void )
\r
234 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
236 /* The interrupt was caused by the receiver getting data. */
\r
237 cChar = uart1->rx_data;
\r
239 xQueueSendFromISR(xRxedChars, &cChar, &xHigherPriorityTaskWoken );
\r
241 /* If an event caused a task to unblock then we call "Yield from ISR" to
\r
242 ensure that the unblocked task is the task that executes when the interrupt
\r
243 completes if the unblocked task has a priority higher than the interrupted
\r
245 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
247 /*-----------------------------------------------------------*/
\r