]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/serial.c
Update CreateProjectDirectoryStructure.bat to add in the lwIP source files, and add...
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / serial.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\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
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \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
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55         BASIC INTERRUPT DRIVEN SERIAL PORT DRIVER FOR a UARTLite peripheral.\r
56 */\r
57 \r
58 /* Scheduler includes. */\r
59 #include "FreeRTOS.h"\r
60 #include "queue.h"\r
61 #include "comtest_strings.h"\r
62 \r
63 /* Library includes. */\r
64 #include "xuartlite.h"\r
65 #include "xuartlite_l.h"\r
66 \r
67 /* Demo application includes. */\r
68 #include "serial.h"\r
69 \r
70 /*-----------------------------------------------------------*/\r
71 \r
72 /* Functions that are installed as the handler for interrupts that are caused by\r
73 Rx and Tx events respectively. */\r
74 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
75 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
76 \r
77 /* Structure that hold the state of the UARTLite peripheral used by this demo.\r
78 This is used by the Xilinx peripheral driver API functions. */\r
79 static XUartLite xUartLiteInstance;\r
80 \r
81 /* The queue used to hold received characters. */\r
82 static xQueueHandle xRxedChars;\r
83 \r
84 /*-----------------------------------------------------------*/\r
85 \r
86 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
87 {\r
88 portBASE_TYPE xStatus;\r
89 \r
90         /* The standard demo header file requires a baud rate to be passed into this\r
91         function.  However, in this case the baud rate is configured when the\r
92         hardware is generated, leaving the ulWantedBaud parameter redundant. */\r
93         ( void ) ulWantedBaud;\r
94 \r
95         /* Create the queue used to hold Rx characters. */\r
96         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
97 \r
98         /* If the queue was created correctly, then setup the serial port\r
99         hardware. */\r
100         if( xRxedChars != NULL )\r
101         {\r
102                 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );\r
103 \r
104                 if( xStatus == XST_SUCCESS )\r
105                 {\r
106                         /* Complete initialisation of the UART and its associated\r
107                         interrupts. */\r
108                         XUartLite_ResetFifos( &xUartLiteInstance );\r
109                         \r
110                         /* Install the handlers that the standard Xilinx library interrupt\r
111                         service routine will call when Rx and Tx events occur \r
112                         respectively. */\r
113                         XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
114                         XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
115                         \r
116                         /* Install the standard Xilinx library interrupt handler itself.\r
117                         *NOTE* The xPortInstallInterruptHandler() API function must be used \r
118                         for     this purpose. */                        \r
119                         xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );\r
120                         \r
121                         /* Enable the interrupt in the peripheral. */\r
122                         XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
123                         \r
124                         /* Enable the interrupt in the interrupt controller.\r
125                         *NOTE* The vPortEnableInterrupt() API function must be used for this\r
126                         purpose. */\r
127                         vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
128                 }\r
129 \r
130                 configASSERT( xStatus == pdPASS );\r
131         }\r
132 \r
133         /* This demo file only supports a single port but something must be\r
134         returned to comply with the standard demo header file. */\r
135         return ( xComPortHandle ) 0;\r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
140 {\r
141         /* The port handle is not required as this driver only supports one port. */\r
142         ( void ) pxPort;\r
143 \r
144         /* Get the next character from the receive queue.  Return false if no \r
145         characters are available, or arrive before xBlockTime expires. */\r
146         if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
147         {\r
148                 return pdTRUE;\r
149         }\r
150         else\r
151         {\r
152                 return pdFALSE;\r
153         }\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength )\r
158 {\r
159         /* Output uxStringLength bytes starting from pcString. */\r
160         XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, uxStringLength );\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
165 {\r
166 signed char cRxedChar;\r
167 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
168 \r
169         /* Place any received characters into the receive queue. */\r
170         while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )\r
171         {\r
172                 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);\r
173                 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );\r
174         }\r
175 \r
176         /* If calling xQueueSendFromISR() caused a task to unblock, and the task \r
177         that unblocked has a priority equal to or greater than the task currently\r
178         in the Running state (the task that was interrupted), then \r
179         xHigherPriorityTaskWoken will have been set to pdTRUE internally within the\r
180         xQueueSendFromISR() API function.  If xHigherPriorityTaskWoken is equal to\r
181         pdTRUE then a context switch should be requested to ensure that the \r
182         interrupt returns to the highest priority task that is able     to run. */\r
183         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
188 {\r
189         /* Nothing to do here.  The Xilinx library function takes care of the\r
190         transmission. */\r
191         portNOP();\r
192 }\r
193 \r
194 \r
195 \r
196 \r
197 \r
198 \r
199 \r
200 \r
201         \r