2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.
\r
69 /* Scheduler includes. */
\r
70 #include "FreeRTOS.h"
\r
72 #include "comtest_strings.h"
\r
74 /* Library includes. */
\r
75 #include "xuartlite.h"
\r
76 #include "xuartlite_l.h"
\r
78 /* Demo application includes. */
\r
81 /*-----------------------------------------------------------*/
\r
83 /* Functions that are installed as the handler for interrupts that are caused by
\r
84 Rx and Tx events respectively. */
\r
85 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
86 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
88 /* Structure that hold the state of the UARTLite peripheral used by this demo.
\r
89 This is used by the Xilinx peripheral driver API functions. */
\r
90 static XUartLite xUartLiteInstance;
\r
92 /* The queue used to hold received characters. */
\r
93 static xQueueHandle xRxedChars;
\r
95 /*-----------------------------------------------------------*/
\r
97 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
99 portBASE_TYPE xStatus;
\r
101 /* The standard demo header file requires a baud rate to be passed into this
\r
102 function. However, in this case the baud rate is configured when the
\r
103 hardware is generated, leaving the ulWantedBaud parameter redundant. */
\r
104 ( void ) ulWantedBaud;
\r
106 /* Create the queue used to hold Rx characters. */
\r
107 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
109 /* If the queue was created correctly, then setup the serial port
\r
111 if( xRxedChars != NULL )
\r
113 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
115 if( xStatus == XST_SUCCESS )
\r
117 /* Complete initialisation of the UART and its associated
\r
119 XUartLite_ResetFifos( &xUartLiteInstance );
\r
121 /* Install the handlers that the standard Xilinx library interrupt
\r
122 service routine will call when Rx and Tx events occur
\r
124 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
125 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
127 /* Install the standard Xilinx library interrupt handler itself.
\r
128 *NOTE* The xPortInstallInterruptHandler() API function must be used
\r
129 for this purpose. */
\r
130 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
132 /* Enable the interrupt in the peripheral. */
\r
133 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
135 /* Enable the interrupt in the interrupt controller.
\r
136 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
138 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
141 configASSERT( xStatus == pdPASS );
\r
144 /* This demo file only supports a single port but something must be
\r
145 returned to comply with the standard demo header file. */
\r
146 return ( xComPortHandle ) 0;
\r
148 /*-----------------------------------------------------------*/
\r
150 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
152 /* The port handle is not required as this driver only supports one port. */
\r
155 /* Get the next character from the receive queue. Return false if no
\r
156 characters are available, or arrive before xBlockTime expires. */
\r
157 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
166 /*-----------------------------------------------------------*/
\r
168 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
172 /* Output uxStringLength bytes starting from pcString. */
\r
173 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );
\r
175 /*-----------------------------------------------------------*/
\r
177 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
179 signed char cRxedChar;
\r
180 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
183 ( void ) uxByteCount;
\r
185 /* Place any received characters into the receive queue. */
\r
186 while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
\r
188 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
\r
189 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
\r
192 /* If calling xQueueSendFromISR() caused a task to unblock, and the task
\r
193 that unblocked has a priority equal to or greater than the task currently
\r
194 in the Running state (the task that was interrupted), then
\r
195 xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
\r
196 xQueueSendFromISR() API function. If xHigherPriorityTaskWoken is equal to
\r
197 pdTRUE then a context switch should be requested to ensure that the
\r
198 interrupt returns to the highest priority task that is able to run. */
\r
199 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
201 /*-----------------------------------------------------------*/
\r
203 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
206 ( void ) uxByteCount;
\r
208 /* Nothing to do here. The Xilinx library function takes care of the
\r