2 FreeRTOS V8.2.1 - 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
71 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.
\r
74 /* Scheduler includes. */
\r
75 #include "FreeRTOS.h"
\r
77 #include "comtest_strings.h"
\r
79 /* Library includes. */
\r
80 #include "xuartlite.h"
\r
81 #include "xuartlite_l.h"
\r
83 /* Demo application includes. */
\r
86 /*-----------------------------------------------------------*/
\r
88 /* Functions that are installed as the handler for interrupts that are caused by
\r
89 Rx and Tx events respectively. */
\r
90 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
91 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
93 /* Structure that hold the state of the UARTLite peripheral used by this demo.
\r
94 This is used by the Xilinx peripheral driver API functions. */
\r
95 static XUartLite xUartLiteInstance;
\r
97 /* The queue used to hold received characters. */
\r
98 static QueueHandle_t xRxedChars;
\r
100 /*-----------------------------------------------------------*/
\r
102 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
104 portBASE_TYPE xStatus;
\r
106 /* The standard demo header file requires a baud rate to be passed into this
\r
107 function. However, in this case the baud rate is configured when the
\r
108 hardware is generated, leaving the ulWantedBaud parameter redundant. */
\r
109 ( void ) ulWantedBaud;
\r
111 /* Create the queue used to hold Rx characters. */
\r
112 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
114 /* If the queue was created correctly, then setup the serial port
\r
116 if( xRxedChars != NULL )
\r
118 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
120 if( xStatus == XST_SUCCESS )
\r
122 /* Complete initialisation of the UART and its associated
\r
124 XUartLite_ResetFifos( &xUartLiteInstance );
\r
126 /* Install the handlers that the standard Xilinx library interrupt
\r
127 service routine will call when Rx and Tx events occur
\r
129 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
130 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
132 /* Install the standard Xilinx library interrupt handler itself.
\r
133 *NOTE* The xPortInstallInterruptHandler() API function must be used
\r
134 for this purpose. */
\r
135 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
137 /* Enable the interrupt in the peripheral. */
\r
138 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
140 /* Enable the interrupt in the interrupt controller.
\r
141 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
143 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
146 configASSERT( xStatus == pdPASS );
\r
149 /* This demo file only supports a single port but something must be
\r
150 returned to comply with the standard demo header file. */
\r
151 return ( xComPortHandle ) 0;
\r
153 /*-----------------------------------------------------------*/
\r
155 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )
\r
157 /* The port handle is not required as this driver only supports one port. */
\r
160 /* Get the next character from the receive queue. Return false if no
\r
161 characters are available, or arrive before xBlockTime expires. */
\r
162 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
171 /*-----------------------------------------------------------*/
\r
173 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
177 /* Output uxStringLength bytes starting from pcString. */
\r
178 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );
\r
180 /*-----------------------------------------------------------*/
\r
182 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
184 signed char cRxedChar;
\r
185 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
188 ( void ) uxByteCount;
\r
190 /* Place any received characters into the receive queue. */
\r
191 while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )
\r
193 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);
\r
194 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );
\r
197 /* If calling xQueueSendFromISR() caused a task to unblock, and the task
\r
198 that unblocked has a priority equal to or greater than the task currently
\r
199 in the Running state (the task that was interrupted), then
\r
200 xHigherPriorityTaskWoken will have been set to pdTRUE internally within the
\r
201 xQueueSendFromISR() API function. If xHigherPriorityTaskWoken is equal to
\r
202 pdTRUE then a context switch should be requested to ensure that the
\r
203 interrupt returns to the highest priority task that is able to run. */
\r
204 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
206 /*-----------------------------------------------------------*/
\r
208 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
211 ( void ) uxByteCount;
\r
213 /* Nothing to do here. The Xilinx library function takes care of the
\r