2 FreeRTOS V7.0.1 - Copyright (C) 2011 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 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR UART0.
\r
57 ***Note*** This example uses queues to send each character into an interrupt
\r
58 service routine and out of an interrupt service routine individually. This
\r
59 is done to demonstrate queues being used in an interrupt, and to deliberately
\r
60 load the system to test the FreeRTOS port. It is *NOT* meant to be an
\r
61 example of an efficient implementation. An efficient implementation should
\r
62 use FIFOs or DMA if available, and only use FreeRTOS API functions when
\r
63 enough has been received to warrant a task being unblocked to process the
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
71 #include "task.h" /*_RB_ remove this when the file is working. */
\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
80 /*-----------------------------------------------------------*/
\r
83 #define serINVALID_QUEUE ( ( xQueueHandle ) 0 )
\r
84 #define serNO_BLOCK ( ( portTickType ) 0 )
\r
86 /*-----------------------------------------------------------*/
\r
88 /* The queue used to hold received characters. */
\r
89 static xQueueHandle xRxedChars;
\r
90 static xQueueHandle xCharsForTx;
\r
92 static XUartLite xUartLiteInstance;
\r
94 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
95 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );
\r
97 /*-----------------------------------------------------------*/
\r
100 * See the serial2.h header file.
\r
102 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
\r
104 portBASE_TYPE xStatus;
\r
106 /* Create the queues used to hold Rx/Tx characters. */
\r
107 xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
108 xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
\r
110 /* If the queues were created correctly then setup the serial port
\r
112 if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )
\r
114 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );
\r
116 if( xStatus == XST_SUCCESS )
\r
118 XUartLite_ResetFifos( &xUartLiteInstance );
\r
119 XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );
\r
120 XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );
\r
121 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );
\r
122 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
123 vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );
\r
126 configASSERT( xStatus == pdPASS );
\r
129 /* This demo file only supports a single port but something must be
\r
130 returned to comply with the standard demo header file. */
\r
131 return ( xComPortHandle ) 0;
\r
133 /*-----------------------------------------------------------*/
\r
135 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )
\r
137 extern u8 XUartLite_RecvByte(u32 BaseAddress);
\r
139 // *pcRxedChar = XUartLite_RecvByte( xUartLiteInstance.RegBaseAddress );
\r
141 vTaskDelay( 1000 );
\r
144 /* The port handle is not required as this driver only supports one port. */
\r
147 /* Get the next character from the buffer. Return false if no characters
\r
148 are available, or arrive before xBlockTime expires. */
\r
149 if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )
\r
159 /*-----------------------------------------------------------*/
\r
161 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
\r
163 XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( unsigned portBASE_TYPE ) usStringLength );
\r
166 unsigned portBASE_TYPE uxReturn = 0U;
\r
169 extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);
\r
171 /* Just to avoid compiler warnings. */
\r
174 while( uxReturn != usStringLength )
\r
176 XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, *pc );
\r
179 // uxReturn += XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( ( unsigned portBASE_TYPE ) usStringLength ) - uxReturn );
\r
180 while( XUartLite_IsSending( &xUartLiteInstance ) != pdFALSE )
\r
182 /*_RB_ This function is not yet written to make use of the RTOS. */
\r
187 /*-----------------------------------------------------------*/
\r
189 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )
\r
192 extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);
\r
196 XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, cOutChar );
\r
198 // vTaskDelay( 2 );
\r
201 signed portBASE_TYPE xReturn;
\r
203 if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )
\r
207 /* Enable the UART Tx interrupt. */
\r
208 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );
\r
218 /*-----------------------------------------------------------*/
\r
220 void vSerialClose( xComPortHandle xPort )
\r
222 /* Not supported as not required by the demo application. */
\r
224 /*-----------------------------------------------------------*/
\r
226 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r
230 /*-----------------------------------------------------------*/
\r
232 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )
\r