]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo/serial.c
Update version numbers to V7.4.1.
[freertos] / FreeRTOS / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemo / serial.c
1 /*\r
2     FreeRTOS V7.4.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /*\r
76         BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.\r
77 */\r
78 \r
79 /* Scheduler includes. */\r
80 #include "FreeRTOS.h"\r
81 #include "queue.h"\r
82 #include "comtest_strings.h"\r
83 \r
84 /* Library includes. */\r
85 #include "xuartlite.h"\r
86 #include "xuartlite_l.h"\r
87 \r
88 /* Demo application includes. */\r
89 #include "serial.h"\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /* Functions that are installed as the handler for interrupts that are caused by\r
94 Rx and Tx events respectively. */\r
95 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
96 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
97 \r
98 /* Structure that hold the state of the UARTLite peripheral used by this demo.\r
99 This is used by the Xilinx peripheral driver API functions. */\r
100 static XUartLite xUartLiteInstance;\r
101 \r
102 /* The queue used to hold received characters. */\r
103 static xQueueHandle xRxedChars;\r
104 \r
105 /*-----------------------------------------------------------*/\r
106 \r
107 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
108 {\r
109 portBASE_TYPE xStatus;\r
110 \r
111         /* The standard demo header file requires a baud rate to be passed into this\r
112         function.  However, in this case the baud rate is configured when the\r
113         hardware is generated, leaving the ulWantedBaud parameter redundant. */\r
114         ( void ) ulWantedBaud;\r
115 \r
116         /* Create the queue used to hold Rx characters. */\r
117         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
118 \r
119         /* If the queue was created correctly, then setup the serial port\r
120         hardware. */\r
121         if( xRxedChars != NULL )\r
122         {\r
123                 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );\r
124 \r
125                 if( xStatus == XST_SUCCESS )\r
126                 {\r
127                         /* Complete initialisation of the UART and its associated\r
128                         interrupts. */\r
129                         XUartLite_ResetFifos( &xUartLiteInstance );\r
130                         \r
131                         /* Install the handlers that the standard Xilinx library interrupt\r
132                         service routine will call when Rx and Tx events occur \r
133                         respectively. */\r
134                         XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
135                         XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
136                         \r
137                         /* Install the standard Xilinx library interrupt handler itself.\r
138                         *NOTE* The xPortInstallInterruptHandler() API function must be used \r
139                         for     this purpose. */                        \r
140                         xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );\r
141                         \r
142                         /* Enable the interrupt in the peripheral. */\r
143                         XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
144                         \r
145                         /* Enable the interrupt in the interrupt controller.\r
146                         *NOTE* The vPortEnableInterrupt() API function must be used for this\r
147                         purpose. */\r
148                         vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
149                 }\r
150 \r
151                 configASSERT( xStatus == pdPASS );\r
152         }\r
153 \r
154         /* This demo file only supports a single port but something must be\r
155         returned to comply with the standard demo header file. */\r
156         return ( xComPortHandle ) 0;\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
161 {\r
162         /* The port handle is not required as this driver only supports one port. */\r
163         ( void ) pxPort;\r
164 \r
165         /* Get the next character from the receive queue.  Return false if no \r
166         characters are available, or arrive before xBlockTime expires. */\r
167         if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
168         {\r
169                 return pdTRUE;\r
170         }\r
171         else\r
172         {\r
173                 return pdFALSE;\r
174         }\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
179 {\r
180         ( void ) pxPort;\r
181 \r
182         /* Output uxStringLength bytes starting from pcString. */\r
183         XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
188 {\r
189 signed char cRxedChar;\r
190 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
191 \r
192         ( void ) pvUnused;\r
193         ( void ) uxByteCount;\r
194 \r
195         /* Place any received characters into the receive queue. */\r
196         while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )\r
197         {\r
198                 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);\r
199                 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );\r
200         }\r
201 \r
202         /* If calling xQueueSendFromISR() caused a task to unblock, and the task \r
203         that unblocked has a priority equal to or greater than the task currently\r
204         in the Running state (the task that was interrupted), then \r
205         xHigherPriorityTaskWoken will have been set to pdTRUE internally within the\r
206         xQueueSendFromISR() API function.  If xHigherPriorityTaskWoken is equal to\r
207         pdTRUE then a context switch should be requested to ensure that the \r
208         interrupt returns to the highest priority task that is able     to run. */\r
209         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
210 }\r
211 /*-----------------------------------------------------------*/\r
212 \r
213 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
214 {\r
215         ( void ) pvUnused;\r
216         ( void ) uxByteCount;\r
217 \r
218         /* Nothing to do here.  The Xilinx library function takes care of the\r
219         transmission. */\r
220         portNOP();\r
221 }\r
222 \r
223 \r
224 \r
225 \r
226 \r
227 \r
228 \r
229 \r
230         \r