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