]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/serial.c
Complete the new comtest_strings.c file.
[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 UART0.\r
56         \r
57         ***Note*** This example uses queues to send each character into an interrupt\r
58         service routine and out of an interrupt service routine individually.  This\r
59         is done to demonstrate queues being used in an interrupt, and to deliberately\r
60         load the system to test the FreeRTOS port.  It is *NOT* meant to be an\r
61         example of an efficient implementation.  An efficient implementation should\r
62         use FIFOs or DMA if available, and only use FreeRTOS API functions when\r
63         enough has been received to warrant a task being unblocked to process the\r
64         data.\r
65 */\r
66 \r
67 /* Scheduler includes. */\r
68 #include "FreeRTOS.h"\r
69 #include "queue.h"\r
70 #include "task.h" /*_RB_ remove this when the file is working. */\r
71 #include "comtest_strings.h"\r
72 \r
73 /* Library includes. */\r
74 #include "xuartlite.h"\r
75 #include "xuartlite_l.h"\r
76 \r
77 /* Demo application includes. */\r
78 #include "serial.h"\r
79 /*-----------------------------------------------------------*/\r
80 \r
81 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
82 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
83 \r
84 static XUartLite xUartLiteInstance;\r
85 \r
86 /* The queue used to hold received characters. */\r
87 static xQueueHandle xRxedChars;\r
88 \r
89 \r
90 /*-----------------------------------------------------------*/\r
91 \r
92 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
93 {\r
94 portBASE_TYPE xStatus;\r
95 \r
96         /* Create the queue used to hold Rx characters. */\r
97         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
98 \r
99         /* If the queue was created correctly then setup the serial port\r
100         hardware. */\r
101         if( xRxedChars != NULL )\r
102         {\r
103                 xStatus = XUartLite_Initialize( &xUartLiteInstance, XPAR_UARTLITE_1_DEVICE_ID );\r
104 \r
105                 if( xStatus == XST_SUCCESS )\r
106                 {\r
107                         /* Complete initialisation of the UART and its associated\r
108                         interrupts. */\r
109                         XUartLite_ResetFifos( &xUartLiteInstance );\r
110                         XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
111                         XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
112                         xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );\r
113                         XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
114                         vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
115                 }\r
116 \r
117                 configASSERT( xStatus == pdPASS );\r
118         }\r
119 \r
120         /* This demo file only supports a single port but something must be\r
121         returned to comply with the standard demo header file. */\r
122         return ( xComPortHandle ) 0;\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
127 {\r
128         /* The port handle is not required as this driver only supports one port. */\r
129         ( void ) pxPort;\r
130 \r
131         /* Get the next character from the buffer.  Return false if no characters\r
132         are available, or arrive before xBlockTime expires. */\r
133         if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
134         {\r
135                 return pdTRUE;\r
136         }\r
137         else\r
138         {\r
139                 return pdFALSE;\r
140         }\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned portBASE_TYPE uxStringLength )\r
145 {\r
146         XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, uxStringLength );\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )\r
151 {\r
152         /* Only vSerialPutString() is used in this demo. */\r
153         ( void ) pxPort;\r
154         ( void ) cOutChar;\r
155         ( void ) xBlockTime;\r
156 \r
157         return pdFALSE;\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 void vSerialClose( xComPortHandle xPort )\r
162 {\r
163         /* Not supported as not required by the demo application. */\r
164 }\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
168 {\r
169 signed char cRxedChar;\r
170 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
171 \r
172         while( XUartLite_IsReceiveEmpty( xUartLiteInstance.RegBaseAddress ) == pdFALSE )\r
173         {\r
174                 cRxedChar = XUartLite_ReadReg( xUartLiteInstance.RegBaseAddress, XUL_RX_FIFO_OFFSET);\r
175                 xQueueSendFromISR( xRxedChars, &cRxedChar, &xHigherPriorityTaskWoken );\r
176         }\r
177 \r
178         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
183 {\r
184         portNOP();\r
185 }\r
186 \r
187 \r
188 \r
189 \r
190 \r
191 \r
192 \r
193 \r
194         \r