2 FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\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
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
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\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
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\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
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
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
67 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
68 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
69 called. The demo applications included in the FreeRTOS.org download switch
\r
70 to supervisor mode prior to main being called. If you are not using one of
\r
71 these demo application projects then ensure Supervisor mode is used.
\r
75 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
76 * documentation provides more details of the demo application tasks.
\r
78 * A few tasks are created that are not part of the standard demo. These are
\r
79 * the 'LCD' task, the 'LCD Message' task, a WEB server task and the 'Check'
\r
82 * The LCD task is the only task that accesses the LCD directly, so mutual
\r
83 * exclusion is ensured. Any task wishing to display text sends the LCD task
\r
84 * a message containing a pointer to the string that should be displayed.
\r
85 * The LCD task itself just blocks on a queue waiting for such a message to
\r
86 * arrive - processing each in turn.
\r
88 * The LCD Message task does nothing other than periodically send messages to
\r
89 * the LCD task. The messages originating from the LCD Message task are
\r
90 * displayed on the top row of the LCD.
\r
92 * The Check task only executes every three seconds but has the highest
\r
93 * priority so is guaranteed to get processor time. Its main function is to
\r
94 * check that all the other tasks are still operational. Most tasks maintain
\r
95 * a unique count that is incremented each time the task successfully completes
\r
96 * a cycle of its function. Should any error occur within such a task the
\r
97 * count is permanently halted. The check task sets a bit in an error status
\r
98 * flag should it find any counter variable at a value that indicates an
\r
99 * error has occurred. The error flag value is converted to a string and sent
\r
100 * to the LCD task for display on the bottom row on the LCD.
\r
103 /* Standard includes. */
\r
106 /* Library includes. */
\r
107 #include "91x_lib.h"
\r
109 /* Scheduler includes. */
\r
110 #include "FreeRTOS.h"
\r
114 /* Demo application includes. */
\r
117 #include "integer.h"
\r
119 #include "BlockQ.h"
\r
120 #include "semtest.h"
\r
121 #include "dynamic.h"
\r
122 #include "partest.h"
\r
124 #include "comtest2.h"
\r
125 #include "serial.h"
\r
126 #include "GenQTest.h"
\r
130 #include "BasicWEB.h"
\r
134 /* Priorities for the demo application tasks. */
\r
135 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
136 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
137 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
138 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
139 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
140 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
141 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
142 #define mainMSG_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
143 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
145 /* Delays used by the various tasks defined in this file. */
\r
146 #define mainCHECK_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
147 #define mainSTRING_WRITE_DELAY ( 500 / portTICK_PERIOD_MS )
\r
148 #define mainLCD_DELAY ( 20 / portTICK_PERIOD_MS )
\r
150 /* Constants for the ComTest tasks. */
\r
151 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
152 #define mainCOM_TEST_LED ( 3 )
\r
154 /* The maximum number of messages that can be pending to be written to the LCD. */
\r
155 #define mainLCD_QUEUE_LEN ( 6 )
\r
157 /* Dimension the buffer used to write the error flag string. */
\r
158 #define mainMAX_FLAG_STRING_LEN ( 32 )
\r
160 /* The structure that is passed on the LCD message queue. */
\r
163 char **ppcMessageToDisplay; /*<< Points to a char* pointing to the message to display. */
\r
164 portBASE_TYPE xRow; /*<< The row on which the message should be displayed. */
\r
166 /*-----------------------------------------------------------*/
\r
169 * The task that executes at the highest priority and calls
\r
170 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
173 static void vErrorChecks( void *pvParameters );
\r
176 * Configure the processor clock and ports.
\r
178 static void prvSetupHardware( void );
\r
181 * Checks that all the demo application tasks are still executing without error
\r
182 * - as described at the top of the file. Called by vErrorChecks().
\r
184 static void prvCheckOtherTasksAreStillRunning( void );
\r
188 * The WEB server task prototype. The task is created in this file but defined
\r
189 * elsewhere. STACK_UIP is defined when the uIP stack is used in preference
\r
190 * to the lwIP stack.
\r
192 extern void vuIP_Task(void *pvParameters);
\r
196 * The task that displays text on the LCD.
\r
198 static void prvLCDTask( void * pvParameters );
\r
201 * The task that sends messages to be displayed on the top row of the LCD.
\r
203 static void prvLCDMessageTask( void * pvParameters );
\r
205 /*-----------------------------------------------------------*/
\r
207 /* The queue used to pass messages to the LCD task. */
\r
208 static QueueHandle_t xLCDQueue;
\r
210 /* Error status flag. */
\r
211 static unsigned long ulErrorFlags = 0;
\r
213 /*-----------------------------------------------------------*/
\r
216 * Starts all the other tasks, then starts the scheduler.
\r
224 /* Setup any hardware that has not already been configured by the low
\r
225 level init routines. */
\r
226 prvSetupHardware();
\r
227 /* Create the queue used to send data to the LCD task. */
\r
228 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LEN, sizeof( xLCDMessage ) );
\r
230 /* Start all the standard demo application tasks. */
\r
231 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
232 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
233 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
234 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
235 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
236 vStartDynamicPriorityTasks();
\r
237 vStartMathTasks( tskIDLE_PRIORITY );
\r
238 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
239 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
240 vStartQueuePeekTasks();
\r
242 /* Start the tasks which are defined in this file. */
\r
243 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
244 xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainLCD_TASK_PRIORITY, NULL );
\r
245 xTaskCreate( prvLCDMessageTask, "MSG", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainMSG_TASK_PRIORITY, NULL );
\r
247 /* Start either the uIP TCP/IP stack or the lwIP TCP/IP stack. */
\r
249 /* Finally, create the WEB server task. */
\r
250 xTaskCreate( vuIP_Task, "uIP", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
254 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
\r
256 sys_set_state( ( signed char * ) "httpd", lwipBASIC_SERVER_STACK_SIZE );
\r
257 sys_thread_new( vBasicWEBServer, ( void * ) NULL, basicwebWEBSERVER_PRIORITY );
\r
258 sys_set_default_state();
\r
261 /* Start the scheduler.
\r
263 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
264 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
265 called. The demo applications included in the FreeRTOS.org download switch
\r
266 to supervisor mode prior to main being called. If you are not using one of
\r
267 these demo application projects then ensure Supervisor mode is used here. */
\r
269 vTaskStartScheduler();
\r
271 /* We should never get here as control is now taken by the scheduler. */
\r
274 /*-----------------------------------------------------------*/
\r
276 static void prvSetupHardware( void )
\r
278 /* Configuration taken from the ST code.
\r
280 Set Flash banks size & address */
\r
281 FMI_BankRemapConfig( 4, 2, 0, 0x80000 );
\r
283 /* FMI Waite States */
\r
284 FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH );
\r
286 /* Configure the FPLL = 96MHz, and APB to 48MHz. */
\r
287 SCU_PCLKDivisorConfig( SCU_PCLK_Div2 );
\r
288 SCU_PLLFactorsConfig( 192, 25, 2 );
\r
289 SCU_PLLCmd( ENABLE );
\r
290 SCU_MCLKSourceConfig( SCU_MCLK_PLL );
\r
292 WDG_Cmd( DISABLE );
\r
295 /* GPIO8 clock source enable, used by the LCD. */
\r
296 SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
\r
297 GPIO_DeInit(GPIO8);
\r
299 /* GPIO 9 clock source enable, used by the LCD. */
\r
300 SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
\r
301 GPIO_DeInit(GPIO9);
\r
303 /* Enable VIC clock */
\r
304 SCU_AHBPeriphClockConfig(__VIC, ENABLE);
\r
305 SCU_AHBPeriphReset(__VIC, DISABLE);
\r
307 /* Peripheral initialisation. */
\r
308 vParTestInitialise();
\r
310 /*-----------------------------------------------------------*/
\r
312 static void vErrorChecks( void *pvParameters )
\r
314 static char cCheckVal[ mainMAX_FLAG_STRING_LEN ];
\r
315 char *pcFlagString;
\r
316 xLCDMessage xMessageToSend;
\r
317 TickType_t xLastWakeTime;
\r
318 char *pcStringsToDisplay[] = {
\r
319 "Check status flag"
\r
322 /* The parameters are not used in this task. */
\r
323 ( void ) pvParameters;
\r
325 pcFlagString = &cCheckVal[ 0 ];
\r
327 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
328 functions correctly. */
\r
329 xLastWakeTime = xTaskGetTickCount();
\r
331 /* Cycle for ever, delaying then checking all the other tasks are still
\r
332 operating without error. */
\r
335 /* Delay until it is time to execute again. */
\r
336 vTaskDelayUntil( &xLastWakeTime, mainCHECK_PERIOD );
\r
338 /* Check all the other tasks to see if the error flag needs updating. */
\r
339 prvCheckOtherTasksAreStillRunning();
\r
341 /* Create a string indicating the error flag status. */
\r
342 sprintf( cCheckVal, "equals 0x%x ", ulErrorFlags );
\r
343 xMessageToSend.xRow = Line2;
\r
345 /* Send the first part of the message to the LCD task. */
\r
346 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ 0 ];
\r
347 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
348 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
350 /* Send the second part of the message to the LCD task. */
\r
351 xMessageToSend.ppcMessageToDisplay = &pcFlagString;
\r
352 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
355 /*-----------------------------------------------------------*/
\r
357 static void prvCheckOtherTasksAreStillRunning( void )
\r
359 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
361 ulErrorFlags |= 0x01;
\r
364 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
366 ulErrorFlags |= 0x02;
\r
369 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
371 ulErrorFlags |= 0x04;
\r
374 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
376 ulErrorFlags |= 0x08;
\r
379 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
381 ulErrorFlags |= 0x10;
\r
384 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
386 ulErrorFlags |= 0x20;
\r
389 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
391 ulErrorFlags |= 0x40;
\r
394 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
396 ulErrorFlags |= 0x80;
\r
399 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
401 ulErrorFlags |= 0x100;
\r
405 /*-----------------------------------------------------------*/
\r
407 static void prvLCDMessageTask( void * pvParameters )
\r
409 QueueHandle_t *pxLCDQueue;
\r
410 xLCDMessage xMessageToSend;
\r
411 portBASE_TYPE xIndex = 0;
\r
413 /* The strings that are written to the LCD. */
\r
414 char *pcStringsToDisplay[] = {
\r
418 "www.FreeRTOS.org",
\r
423 /* To test the parameter passing mechanism, the queue on which messages are
\r
424 posted is passed in as a parameter even though it is available as a file
\r
425 scope variable anyway. */
\r
426 pxLCDQueue = ( QueueHandle_t * ) pvParameters;
\r
430 /* Wait until it is time to move onto the next string. */
\r
431 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
433 /* Configure the message object to send to the LCD task. */
\r
434 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ xIndex ];
\r
435 xMessageToSend.xRow = Line1;
\r
437 /* Post the message to be displayed. */
\r
438 xQueueSend( *pxLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
440 /* Move onto the next message, wrapping when necessary. */
\r
442 if( *( pcStringsToDisplay[ xIndex ] ) == 0x00 )
\r
446 /* Delay longer before going back to the start of the messages. */
\r
447 vTaskDelay( mainSTRING_WRITE_DELAY * 2 );
\r
451 /*-----------------------------------------------------------*/
\r
453 void prvLCDTask( void * pvParameters )
\r
455 QueueHandle_t *pxLCDQueue;
\r
456 xLCDMessage xReceivedMessage;
\r
459 /* To test the parameter passing mechanism, the queue on which messages are
\r
460 received is passed in as a parameter even though it is available as a file
\r
461 scope variable anyway. */
\r
462 pxLCDQueue = ( QueueHandle_t * ) pvParameters;
\r
468 /* Wait for a message to arrive. */
\r
469 if( xQueueReceive( *pxLCDQueue, &xReceivedMessage, portMAX_DELAY ) )
\r
471 /* Where is the string we are going to display? */
\r
472 pcString = *xReceivedMessage.ppcMessageToDisplay;
\r
473 LCD_DisplayString(xReceivedMessage.xRow, pcString, BlackText);
\r
475 /* The delay here is just to ensure the LCD task does not starve
\r
476 out lower priority tasks as writing to the LCD can take a long
\r
478 vTaskDelay( mainLCD_DELAY );
\r
482 /*-----------------------------------------------------------*/
\r