2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.
\r
71 /* Scheduler includes. */
\r
72 #include "FreeRTOS.h"
\r
74 #include "comtest_strings.h"
\r
76 /* Library includes. */
\r
77 #include "xuartlite.h"
\r
78 #include "xuartlite_l.h"
\r
80 /* Demo application includes. */
\r
83 /*-----------------------------------------------------------*/
\r
85 /* Functions that are installed as the handler for interrupts that are caused by
\r
86 Rx and Tx events respectively. */
\r
87 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
88 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
90 /* Structure that hold the state of the UARTLite peripheral used by this demo.
\r
91 This is used by the Xilinx peripheral driver API functions. */
\r
92 static XUartLite xUartLiteInstance;
\r
94 /* The queue used to hold received characters. */
\r
95 static xQueueHandle xRxedChars;
\r
97 /*-----------------------------------------------------------*/
\r
99 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
101 portBASE_TYPE xStatus;
\r
103 /* The standard demo header file requires a baud rate to be passed into this
\r
104 function. However, in this case the baud rate is configured when the
\r
105 hardware is generated, leaving the ulWantedBaud parameter redundant. */
\r
106 ( void ) ulWantedBaud;
\r
108 /* Create the queue used to hold Rx characters. */
\r
109 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
111 /* If the queue was created correctly, then setup the serial port
\r
113 if( xRxedChars != NULL )
\r
115 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
117 if( xStatus == XST_SUCCESS )
\r
119 /* Complete initialisation of the UART and its associated
\r
121 XUartLite_ResetFifos( &xUartLiteInstance );
\r
123 /* Install the handlers that the standard Xilinx library interrupt
\r
124 service routine will call when Rx and Tx events occur
\r
126 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
127 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
129 /* Install the standard Xilinx library interrupt handler itself.
\r
130 *NOTE* The xPortInstallInterruptHandler() API function must be used
\r
131 for this purpose. */
\r
132 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
134 /* Enable the interrupt in the peripheral. */
\r
135 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
137 /* Enable the interrupt in the interrupt controller.
\r
138 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
140 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
143 configASSERT( xStatus == pdPASS );
\r
146 /* This demo file only supports a single port but something must be
\r
147 returned to comply with the standard demo header file. */
\r
148 return ( xComPortHandle ) 0;
\r
150 /*-----------------------------------------------------------*/
\r
152 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
154 /* The port handle is not required as this driver only supports one port. */
\r
157 /* Get the next character from the receive queue. Return false if no
\r
158 characters are available, or arrive before xBlockTime expires. */
\r
159 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
168 /*-----------------------------------------------------------*/
\r
170 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
174 /* Output uxStringLength bytes starting from pcString. */
\r
175 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );
\r
177 /*-----------------------------------------------------------*/
\r
179 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
181 signed char cRxedChar;
\r
182 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
185 ( void ) uxByteCount;
\r
187 /* Place any received characters into the receive queue. */
\r
188 while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
\r
190 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
\r
191 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
\r
194 /* If calling xQueueSendFromISR() caused a task to unblock, and the task
\r
195 that unblocked has a priority equal to or greater than the task currently
\r
196 in the Running state (the task that was interrupted), then
\r
197 xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
\r
198 xQueueSendFromISR() API function. If xHigherPriorityTaskWoken is equal to
\r
199 pdTRUE then a context switch should be requested to ensure that the
\r
200 interrupt returns to the highest priority task that is able to run. */
\r
201 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
203 /*-----------------------------------------------------------*/
\r
205 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
208 ( void ) uxByteCount;
\r
210 /* Nothing to do here. The Xilinx library function takes care of the
\r