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