]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/serial.c
Add the comtest_strings.c and serial.c files - Tx is workings, but both files are...
[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 "semphr.h"\r
71 #include "task.h" /*_RB_ remove this when the file is working. */\r
72 #include "comtest_strings.h"\r
73 \r
74 /* Library includes. */\r
75 #include "xuartlite.h"\r
76 #include "xuartlite_l.h"\r
77 \r
78 /* Demo application includes. */\r
79 #include "serial.h"\r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /* Misc defines. */\r
83 #define serINVALID_QUEUE                                ( ( xQueueHandle ) 0 )\r
84 #define serNO_BLOCK                                             ( ( portTickType ) 0 )\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \r
88 /* The queue used to hold received characters. */\r
89 static xQueueHandle xRxedChars;\r
90 static xQueueHandle xCharsForTx;\r
91 \r
92 static XUartLite xUartLiteInstance;\r
93 \r
94 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
95 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount );\r
96 \r
97 /*-----------------------------------------------------------*/\r
98 \r
99 /*\r
100  * See the serial2.h header file.\r
101  */\r
102 xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )\r
103 {\r
104 portBASE_TYPE xStatus;\r
105 \r
106         /* Create the queues used to hold Rx/Tx characters. */\r
107         xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
108         xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) );\r
109         \r
110         /* If the queues were created correctly then setup the serial port\r
111         hardware. */\r
112         if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) )\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                         XUartLite_ResetFifos( &xUartLiteInstance );\r
119                         XUartLite_SetRecvHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvRxHandler, NULL );\r
120                         XUartLite_SetSendHandler( &xUartLiteInstance, ( XUartLite_Handler ) prvTxHandler, NULL );\r
121                         xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_UARTLITE_1_VEC_ID, ( XInterruptHandler ) XUartLite_InterruptHandler, &xUartLiteInstance );\r
122                         XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
123                         vPortEnableInterrupt( XPAR_INTC_0_UARTLITE_1_VEC_ID );\r
124                 }\r
125 \r
126                 configASSERT( xStatus == pdPASS );\r
127         }\r
128 \r
129         /* This demo file only supports a single port but something must be\r
130         returned to comply with the standard demo header file. */\r
131         return ( xComPortHandle ) 0;\r
132 }\r
133 /*-----------------------------------------------------------*/\r
134 \r
135 portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime )\r
136 {\r
137 extern u8 XUartLite_RecvByte(u32 BaseAddress);\r
138 \r
139 //      *pcRxedChar = XUartLite_RecvByte( xUartLiteInstance.RegBaseAddress );\r
140 \r
141         vTaskDelay( 1000 );\r
142         return pdTRUE;\r
143 #if 0\r
144         /* The port handle is not required as this driver only supports one port. */\r
145         ( void ) pxPort;\r
146 \r
147         /* Get the next character from the buffer.  Return false if no characters\r
148         are available, or arrive before xBlockTime expires. */\r
149         if( xQueueReceive( xRxedChars, pcRxedChar, xBlockTime ) )\r
150         {\r
151                 return pdTRUE;\r
152         }\r
153         else\r
154         {\r
155                 return pdFALSE;\r
156         }\r
157 #endif\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )\r
162 {\r
163         XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( unsigned portBASE_TYPE ) usStringLength );\r
164 \r
165 #if 0\r
166 unsigned portBASE_TYPE uxReturn = 0U;\r
167 \r
168 char *pc = pc;\r
169 extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);\r
170 \r
171         /* Just to avoid compiler warnings. */\r
172         ( void ) pxPort;\r
173 \r
174         while( uxReturn != usStringLength )\r
175         {\r
176                 XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, *pc );\r
177                 pc++;\r
178                 uxReturn++;\r
179 //              uxReturn += XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, ( ( unsigned portBASE_TYPE ) usStringLength ) - uxReturn );\r
180                 while( XUartLite_IsSending( &xUartLiteInstance ) != pdFALSE )\r
181                 {\r
182                         /*_RB_ This function is not yet written to make use of the RTOS. */\r
183                 }\r
184         }\r
185 #endif\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, portTickType xBlockTime )\r
190 {\r
191 #if 1\r
192         extern void XUartLite_SendByte(u32 BaseAddress, u8 Data);\r
193 \r
194 //      for( ;; )\r
195 //      {\r
196                 XUartLite_SendByte( xUartLiteInstance.RegBaseAddress, cOutChar );\r
197 //      }\r
198 //      vTaskDelay( 2 );\r
199         return 1;\r
200 #else\r
201 signed portBASE_TYPE xReturn;\r
202 \r
203         if( xQueueSend( xCharsForTx, &cOutChar, xBlockTime ) == pdPASS )\r
204         {\r
205                 xReturn = pdPASS;\r
206                 \r
207                 /* Enable the UART Tx interrupt. */\r
208                 XUartLite_EnableIntr( xUartLiteInstance.RegBaseAddress );\r
209         }\r
210         else\r
211         {\r
212                 xReturn = pdFAIL;\r
213         }\r
214 \r
215         return xReturn;\r
216 #endif\r
217 }\r
218 /*-----------------------------------------------------------*/\r
219 \r
220 void vSerialClose( xComPortHandle xPort )\r
221 {\r
222         /* Not supported as not required by the demo application. */\r
223 }\r
224 /*-----------------------------------------------------------*/\r
225 \r
226 static void prvRxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
227 {\r
228         portNOP();\r
229 }\r
230 /*-----------------------------------------------------------*/\r
231 \r
232 static void prvTxHandler( void *pvUnused, unsigned portBASE_TYPE uxByteCount )\r
233 {\r
234         portNOP();\r
235 }\r
236 \r
237 \r
238 \r
239 \r
240 \r
241         \r