2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\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
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\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
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\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
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\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
70 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
71 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
72 called. The demo applications included in the FreeRTOS.org download switch
\r
73 to supervisor mode prior to main being called. If you are not using one of
\r
74 these demo application projects then ensure Supervisor mode is used.
\r
78 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
79 * documentation provides more details of the demo application tasks.
\r
81 * A few tasks are created that are not part of the standard demo. These are
\r
82 * the 'LCD' task, the 'LCD Message' task, a WEB server task and the 'Check'
\r
85 * The LCD task is the only task that accesses the LCD directly, so mutual
\r
86 * exclusion is ensured. Any task wishing to display text sends the LCD task
\r
87 * a message containing a pointer to the string that should be displayed.
\r
88 * The LCD task itself just blocks on a queue waiting for such a message to
\r
89 * arrive - processing each in turn.
\r
91 * The LCD Message task does nothing other than periodically send messages to
\r
92 * the LCD task. The messages originating from the LCD Message task are
\r
93 * displayed on the top row of the LCD.
\r
95 * The Check task only executes every three seconds but has the highest
\r
96 * priority so is guaranteed to get processor time. Its main function is to
\r
97 * check that all the other tasks are still operational. Most tasks maintain
\r
98 * a unique count that is incremented each time the task successfully completes
\r
99 * a cycle of its function. Should any error occur within such a task the
\r
100 * count is permanently halted. The check task sets a bit in an error status
\r
101 * flag should it find any counter variable at a value that indicates an
\r
102 * error has occurred. The error flag value is converted to a string and sent
\r
103 * to the LCD task for display on the bottom row on the LCD.
\r
106 /* Standard includes. */
\r
109 /* Library includes. */
\r
110 #include "91x_lib.h"
\r
112 /* Scheduler includes. */
\r
113 #include "FreeRTOS.h"
\r
117 /* Demo application includes. */
\r
120 #include "integer.h"
\r
122 #include "BlockQ.h"
\r
123 #include "semtest.h"
\r
124 #include "dynamic.h"
\r
125 #include "partest.h"
\r
127 #include "comtest2.h"
\r
128 #include "serial.h"
\r
129 #include "GenQTest.h"
\r
133 #include "BasicWEB.h"
\r
137 /* Priorities for the demo application tasks. */
\r
138 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
139 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
140 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
141 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
142 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
143 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
144 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
145 #define mainMSG_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
146 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
148 /* Delays used by the various tasks defined in this file. */
\r
149 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
150 #define mainSTRING_WRITE_DELAY ( 500 / portTICK_RATE_MS )
\r
151 #define mainLCD_DELAY ( 20 / portTICK_RATE_MS )
\r
153 /* Constants for the ComTest tasks. */
\r
154 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
155 #define mainCOM_TEST_LED ( 3 )
\r
157 /* The maximum number of messages that can be pending to be written to the LCD. */
\r
158 #define mainLCD_QUEUE_LEN ( 6 )
\r
160 /* Dimension the buffer used to write the error flag string. */
\r
161 #define mainMAX_FLAG_STRING_LEN ( 32 )
\r
163 /* The structure that is passed on the LCD message queue. */
\r
166 char **ppcMessageToDisplay; /*<< Points to a char* pointing to the message to display. */
\r
167 portBASE_TYPE xRow; /*<< The row on which the message should be displayed. */
\r
169 /*-----------------------------------------------------------*/
\r
172 * The task that executes at the highest priority and calls
\r
173 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
176 static void vErrorChecks( void *pvParameters );
\r
179 * Configure the processor clock and ports.
\r
181 static void prvSetupHardware( void );
\r
184 * Checks that all the demo application tasks are still executing without error
\r
185 * - as described at the top of the file. Called by vErrorChecks().
\r
187 static void prvCheckOtherTasksAreStillRunning( void );
\r
191 * The WEB server task prototype. The task is created in this file but defined
\r
192 * elsewhere. STACK_UIP is defined when the uIP stack is used in preference
\r
193 * to the lwIP stack.
\r
195 extern void vuIP_Task(void *pvParameters);
\r
199 * The task that displays text on the LCD.
\r
201 static void prvLCDTask( void * pvParameters );
\r
204 * The task that sends messages to be displayed on the top row of the LCD.
\r
206 static void prvLCDMessageTask( void * pvParameters );
\r
208 /*-----------------------------------------------------------*/
\r
210 /* The queue used to pass messages to the LCD task. */
\r
211 static xQueueHandle xLCDQueue;
\r
213 /* Error status flag. */
\r
214 static unsigned long ulErrorFlags = 0;
\r
216 /*-----------------------------------------------------------*/
\r
219 * Starts all the other tasks, then starts the scheduler.
\r
227 /* Setup any hardware that has not already been configured by the low
\r
228 level init routines. */
\r
229 prvSetupHardware();
\r
230 /* Create the queue used to send data to the LCD task. */
\r
231 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LEN, sizeof( xLCDMessage ) );
\r
233 /* Start all the standard demo application tasks. */
\r
234 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
235 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
236 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
237 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
238 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
239 vStartDynamicPriorityTasks();
\r
240 vStartMathTasks( tskIDLE_PRIORITY );
\r
241 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
242 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
243 vStartQueuePeekTasks();
\r
245 /* Start the tasks which are defined in this file. */
\r
246 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
247 xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainLCD_TASK_PRIORITY, NULL );
\r
248 xTaskCreate( prvLCDMessageTask, "MSG", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainMSG_TASK_PRIORITY, NULL );
\r
250 /* Start either the uIP TCP/IP stack or the lwIP TCP/IP stack. */
\r
252 /* Finally, create the WEB server task. */
\r
253 xTaskCreate( vuIP_Task, "uIP", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
257 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
\r
259 sys_set_state( ( signed char * ) "httpd", lwipBASIC_SERVER_STACK_SIZE );
\r
260 sys_thread_new( vBasicWEBServer, ( void * ) NULL, basicwebWEBSERVER_PRIORITY );
\r
261 sys_set_default_state();
\r
264 /* Start the scheduler.
\r
266 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
267 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
268 called. The demo applications included in the FreeRTOS.org download switch
\r
269 to supervisor mode prior to main being called. If you are not using one of
\r
270 these demo application projects then ensure Supervisor mode is used here. */
\r
272 vTaskStartScheduler();
\r
274 /* We should never get here as control is now taken by the scheduler. */
\r
277 /*-----------------------------------------------------------*/
\r
279 static void prvSetupHardware( void )
\r
281 /* Configuration taken from the ST code.
\r
283 Set Flash banks size & address */
\r
284 FMI_BankRemapConfig( 4, 2, 0, 0x80000 );
\r
286 /* FMI Waite States */
\r
287 FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH );
\r
289 /* Configure the FPLL = 96MHz, and APB to 48MHz. */
\r
290 SCU_PCLKDivisorConfig( SCU_PCLK_Div2 );
\r
291 SCU_PLLFactorsConfig( 192, 25, 2 );
\r
292 SCU_PLLCmd( ENABLE );
\r
293 SCU_MCLKSourceConfig( SCU_MCLK_PLL );
\r
295 WDG_Cmd( DISABLE );
\r
298 /* GPIO8 clock source enable, used by the LCD. */
\r
299 SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
\r
300 GPIO_DeInit(GPIO8);
\r
302 /* GPIO 9 clock source enable, used by the LCD. */
\r
303 SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
\r
304 GPIO_DeInit(GPIO9);
\r
306 /* Enable VIC clock */
\r
307 SCU_AHBPeriphClockConfig(__VIC, ENABLE);
\r
308 SCU_AHBPeriphReset(__VIC, DISABLE);
\r
310 /* Peripheral initialisation. */
\r
311 vParTestInitialise();
\r
313 /*-----------------------------------------------------------*/
\r
315 static void vErrorChecks( void *pvParameters )
\r
317 static char cCheckVal[ mainMAX_FLAG_STRING_LEN ];
\r
318 char *pcFlagString;
\r
319 xLCDMessage xMessageToSend;
\r
320 portTickType xLastWakeTime;
\r
321 char *pcStringsToDisplay[] = {
\r
322 "Check status flag"
\r
325 /* The parameters are not used in this task. */
\r
326 ( void ) pvParameters;
\r
328 pcFlagString = &cCheckVal[ 0 ];
\r
330 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
331 functions correctly. */
\r
332 xLastWakeTime = xTaskGetTickCount();
\r
334 /* Cycle for ever, delaying then checking all the other tasks are still
\r
335 operating without error. */
\r
338 /* Delay until it is time to execute again. */
\r
339 vTaskDelayUntil( &xLastWakeTime, mainCHECK_PERIOD );
\r
341 /* Check all the other tasks to see if the error flag needs updating. */
\r
342 prvCheckOtherTasksAreStillRunning();
\r
344 /* Create a string indicating the error flag status. */
\r
345 sprintf( cCheckVal, "equals 0x%x ", ulErrorFlags );
\r
346 xMessageToSend.xRow = Line2;
\r
348 /* Send the first part of the message to the LCD task. */
\r
349 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ 0 ];
\r
350 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
351 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
353 /* Send the second part of the message to the LCD task. */
\r
354 xMessageToSend.ppcMessageToDisplay = &pcFlagString;
\r
355 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
358 /*-----------------------------------------------------------*/
\r
360 static void prvCheckOtherTasksAreStillRunning( void )
\r
362 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
364 ulErrorFlags |= 0x01;
\r
367 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
369 ulErrorFlags |= 0x02;
\r
372 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
374 ulErrorFlags |= 0x04;
\r
377 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
379 ulErrorFlags |= 0x08;
\r
382 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
384 ulErrorFlags |= 0x10;
\r
387 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
389 ulErrorFlags |= 0x20;
\r
392 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
394 ulErrorFlags |= 0x40;
\r
397 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
399 ulErrorFlags |= 0x80;
\r
402 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
404 ulErrorFlags |= 0x100;
\r
408 /*-----------------------------------------------------------*/
\r
410 static void prvLCDMessageTask( void * pvParameters )
\r
412 xQueueHandle *pxLCDQueue;
\r
413 xLCDMessage xMessageToSend;
\r
414 portBASE_TYPE xIndex = 0;
\r
416 /* The strings that are written to the LCD. */
\r
417 char *pcStringsToDisplay[] = {
\r
421 "www.FreeRTOS.org",
\r
426 /* To test the parameter passing mechanism, the queue on which messages are
\r
427 posted is passed in as a parameter even though it is available as a file
\r
428 scope variable anyway. */
\r
429 pxLCDQueue = ( xQueueHandle * ) pvParameters;
\r
433 /* Wait until it is time to move onto the next string. */
\r
434 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
436 /* Configure the message object to send to the LCD task. */
\r
437 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ xIndex ];
\r
438 xMessageToSend.xRow = Line1;
\r
440 /* Post the message to be displayed. */
\r
441 xQueueSend( *pxLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
443 /* Move onto the next message, wrapping when necessary. */
\r
445 if( *( pcStringsToDisplay[ xIndex ] ) == 0x00 )
\r
449 /* Delay longer before going back to the start of the messages. */
\r
450 vTaskDelay( mainSTRING_WRITE_DELAY * 2 );
\r
454 /*-----------------------------------------------------------*/
\r
456 void prvLCDTask( void * pvParameters )
\r
458 xQueueHandle *pxLCDQueue;
\r
459 xLCDMessage xReceivedMessage;
\r
462 /* To test the parameter passing mechanism, the queue on which messages are
\r
463 received is passed in as a parameter even though it is available as a file
\r
464 scope variable anyway. */
\r
465 pxLCDQueue = ( xQueueHandle * ) pvParameters;
\r
471 /* Wait for a message to arrive. */
\r
472 if( xQueueReceive( *pxLCDQueue, &xReceivedMessage, portMAX_DELAY ) )
\r
474 /* Where is the string we are going to display? */
\r
475 pcString = *xReceivedMessage.ppcMessageToDisplay;
\r
476 LCD_DisplayString(xReceivedMessage.xRow, pcString, BlackText);
\r
478 /* The delay here is just to ensure the LCD task does not starve
\r
479 out lower priority tasks as writing to the LCD can take a long
\r
481 vTaskDelay( mainLCD_DELAY );
\r
485 /*-----------------------------------------------------------*/
\r