2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
73 #include "comtest_strings.h"
\r
75 /* Library includes. */
\r
76 #include "xuartlite.h"
\r
77 #include "xuartlite_l.h"
\r
79 /* Demo application includes. */
\r
82 /*-----------------------------------------------------------*/
\r
84 /* Functions that are installed as the handler for interrupts that are caused by
\r
85 Rx and Tx events respectively. */
\r
86 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
87 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
89 /* Structure that hold the state of the UARTLite peripheral used by this demo.
\r
90 This is used by the Xilinx peripheral driver API functions. */
\r
91 static XUartLite xUartLiteInstance;
\r
93 /* The queue used to hold received characters. */
\r
94 static QueueHandle_t xRxedChars;
\r
96 /*-----------------------------------------------------------*/
\r
98 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
100 portBASE_TYPE xStatus;
\r
102 /* The standard demo header file requires a baud rate to be passed into this
\r
103 function. However, in this case the baud rate is configured when the
\r
104 hardware is generated, leaving the ulWantedBaud parameter redundant. */
\r
105 ( void ) ulWantedBaud;
\r
107 /* Create the queue used to hold Rx characters. */
\r
108 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
110 /* If the queue was created correctly, then setup the serial port
\r
112 if( xRxedChars != NULL )
\r
114 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
116 if( xStatus == XST_SUCCESS )
\r
118 /* Complete initialisation of the UART and its associated
\r
120 XUartLite_ResetFifos( &xUartLiteInstance );
\r
122 /* Install the handlers that the standard Xilinx library interrupt
\r
123 service routine will call when Rx and Tx events occur
\r
125 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
126 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
128 /* Install the standard Xilinx library interrupt handler itself.
\r
129 *NOTE* The xPortInstallInterruptHandler() API function must be used
\r
130 for this purpose. */
\r
131 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
133 /* Enable the interrupt in the peripheral. */
\r
134 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
136 /* Enable the interrupt in the interrupt controller.
\r
137 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
139 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
142 configASSERT( xStatus == pdPASS );
\r
145 /* This demo file only supports a single port but something must be
\r
146 returned to comply with the standard demo header file. */
\r
147 return ( xComPortHandle ) 0;
\r
149 /*-----------------------------------------------------------*/
\r
151 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
153 /* The port handle is not required as this driver only supports one port. */
\r
156 /* Get the next character from the receive queue. Return false if no
\r
157 characters are available, or arrive before xBlockTime expires. */
\r
158 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
167 /*-----------------------------------------------------------*/
\r
169 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
173 /* Output uxStringLength bytes starting from pcString. */
\r
174 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
180 signed char cRxedChar;
\r
181 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
184 ( void ) uxByteCount;
\r
186 /* Place any received characters into the receive queue. */
\r
187 while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
\r
189 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
\r
190 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
\r
193 /* If calling xQueueSendFromISR() caused a task to unblock, and the task
\r
194 that unblocked has a priority equal to or greater than the task currently
\r
195 in the Running state (the task that was interrupted), then
\r
196 xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
\r
197 xQueueSendFromISR() API function. If xHigherPriorityTaskWoken is equal to
\r
198 pdTRUE then a context switch should be requested to ensure that the
\r
199 interrupt returns to the highest priority task that is able to run. */
\r
200 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
202 /*-----------------------------------------------------------*/
\r
204 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
207 ( void ) uxByteCount;
\r
209 /* Nothing to do here. The Xilinx library function takes care of the
\r