]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo/serial.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemo / serial.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \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
12 \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
19 \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
24 \r
25     ***************************************************************************\r
26      *                                                                       *\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
31      *                                                                       *\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
36      *                                                                       *\r
37     ***************************************************************************\r
38 \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
42 \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
46 \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
51 \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
55 \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
58 \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
62 \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
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71         BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.\r
72 */\r
73 \r
74 /* Scheduler includes. */\r
75 #include "FreeRTOS.h"\r
76 #include "queue.h"\r
77 #include "comtest_strings.h"\r
78 \r
79 /* Library includes. */\r
80 #include "xuartlite.h"\r
81 #include "xuartlite_l.h"\r
82 \r
83 /* Demo application includes. */\r
84 #include "serial.h"\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \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
92 \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
96 \r
97 /* The queue used to hold received characters. */\r
98 static QueueHandle_t xRxedChars;\r
99 \r
100 /*-----------------------------------------------------------*/\r
101 \r
102 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
103 {\r
104 portBASE_TYPE xStatus;\r
105 \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
110 \r
111         /* Create the queue used to hold Rx characters. */\r
112         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
113 \r
114         /* If the queue was created correctly, then setup the serial port\r
115         hardware. */\r
116         if( xRxedChars != NULL )\r
117         {\r
118                 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );\r
119 \r
120                 if( xStatus == XST_SUCCESS )\r
121                 {\r
122                         /* Complete initialisation of the UART and its associated\r
123                         interrupts. */\r
124                         XUartLite_ResetFifos( &xUartLiteInstance );\r
125                         \r
126                         /* Install the handlers that the standard Xilinx library interrupt\r
127                         service routine will call when Rx and Tx events occur \r
128                         respectively. */\r
129                         XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
130                         XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
131                         \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
136                         \r
137                         /* Enable the interrupt in the peripheral. */\r
138                         XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
139                         \r
140                         /* Enable the interrupt in the interrupt controller.\r
141                         *NOTE* The vPortEnableInterrupt() API function must be used for this\r
142                         purpose. */\r
143                         vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
144                 }\r
145 \r
146                 configASSERT( xStatus == pdPASS );\r
147         }\r
148 \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
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime )\r
156 {\r
157         /* The port handle is not required as this driver only supports one port. */\r
158         ( void ) pxPort;\r
159 \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
163         {\r
164                 return pdTRUE;\r
165         }\r
166         else\r
167         {\r
168                 return pdFALSE;\r
169         }\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
174 {\r
175         ( void ) pxPort;\r
176 \r
177         /* Output uxStringLength bytes starting from pcString. */\r
178         XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
183 {\r
184 signed char cRxedChar;\r
185 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
186 \r
187         ( void ) pvUnused;\r
188         ( void ) uxByteCount;\r
189 \r
190         /* Place any received characters into the receive queue. */\r
191         while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )\r
192         {\r
193                 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);\r
194                 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );\r
195         }\r
196 \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
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
209 {\r
210         ( void ) pvUnused;\r
211         ( void ) uxByteCount;\r
212 \r
213         /* Nothing to do here.  The Xilinx library function takes care of the\r
214         transmission. */\r
215         portNOP();\r
216 }\r
217 \r
218 \r
219 \r
220 \r
221 \r
222 \r
223 \r
224 \r
225         \r