2 FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.
\r
79 /* Scheduler includes. */
\r
80 #include "FreeRTOS.h"
\r
82 #include "comtest_strings.h"
\r
84 /* Library includes. */
\r
85 #include "xuartlite.h"
\r
86 #include "xuartlite_l.h"
\r
88 /* Demo application includes. */
\r
91 /*-----------------------------------------------------------*/
\r
93 /* Functions that are installed as the handler for interrupts that are caused by
\r
94 Rx and Tx events respectively. */
\r
95 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
96 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
98 /* Structure that hold the state of the UARTLite peripheral used by this demo.
\r
99 This is used by the Xilinx peripheral driver API functions. */
\r
100 static XUartLite xUartLiteInstance;
\r
102 /* The queue used to hold received characters. */
\r
103 static xQueueHandle xRxedChars;
\r
105 /*-----------------------------------------------------------*/
\r
107 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
109 portBASE_TYPE xStatus;
\r
111 /* The standard demo header file requires a baud rate to be passed into this
\r
112 function. However, in this case the baud rate is configured when the
\r
113 hardware is generated, leaving the ulWantedBaud parameter redundant. */
\r
114 ( void ) ulWantedBaud;
\r
116 /* Create the queue used to hold Rx characters. */
\r
117 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
119 /* If the queue was created correctly, then setup the serial port
\r
121 if( xRxedChars != NULL )
\r
123 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
125 if( xStatus == XST_SUCCESS )
\r
127 /* Complete initialisation of the UART and its associated
\r
129 XUartLite_ResetFifos( &xUartLiteInstance );
\r
131 /* Install the handlers that the standard Xilinx library interrupt
\r
132 service routine will call when Rx and Tx events occur
\r
134 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
135 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
137 /* Install the standard Xilinx library interrupt handler itself.
\r
138 *NOTE* The xPortInstallInterruptHandler() API function must be used
\r
139 for this purpose. */
\r
140 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
142 /* Enable the interrupt in the peripheral. */
\r
143 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
145 /* Enable the interrupt in the interrupt controller.
\r
146 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
148 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
151 configASSERT( xStatus == pdPASS );
\r
154 /* This demo file only supports a single port but something must be
\r
155 returned to comply with the standard demo header file. */
\r
156 return ( xComPortHandle ) 0;
\r
158 /*-----------------------------------------------------------*/
\r
160 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
162 /* The port handle is not required as this driver only supports one port. */
\r
165 /* Get the next character from the receive queue. Return false if no
\r
166 characters are available, or arrive before xBlockTime expires. */
\r
167 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
176 /*-----------------------------------------------------------*/
\r
178 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
182 /* Output uxStringLength bytes starting from pcString. */
\r
183 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );
\r
185 /*-----------------------------------------------------------*/
\r
187 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
189 signed char cRxedChar;
\r
190 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
193 ( void ) uxByteCount;
\r
195 /* Place any received characters into the receive queue. */
\r
196 while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
\r
198 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
\r
199 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
\r
202 /* If calling xQueueSendFromISR() caused a task to unblock, and the task
\r
203 that unblocked has a priority equal to or greater than the task currently
\r
204 in the Running state (the task that was interrupted), then
\r
205 xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
\r
206 xQueueSendFromISR() API function. If xHigherPriorityTaskWoken is equal to
\r
207 pdTRUE then a context switch should be requested to ensure that the
\r
208 interrupt returns to the highest priority task that is able to run. */
\r
209 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
211 /*-----------------------------------------------------------*/
\r
213 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
216 ( void ) uxByteCount;
\r
218 /* Nothing to do here. The Xilinx library function takes care of the
\r