2 FreeRTOS.org V4.0.4 - Copyright (C) 2003-2006 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
34 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
35 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
36 called. The demo applications included in the FreeRTOS.org download switch
\r
37 to supervisor mode prior to main being called. If you are not using one of
\r
38 these demo application projects then ensure Supervisor mode is used.
\r
42 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
43 * documentation provides more details of the demo application tasks.
\r
45 * A few tasks are created that are not part of the standard demo. These are
\r
46 * the 'LCD' task, the 'LCD Message' task, a WEB server task and the 'Check'
\r
49 * The LCD task is the only task that accesses the LCD directly, so mutual
\r
50 * exclusion is ensured. Any task wishing to display text sends the LCD task
\r
51 * a message containing a pointer to the string that should be displayed.
\r
52 * The LCD task itself just blocks on a queue waiting for such a message to
\r
53 * arrive - processing each in turn.
\r
55 * The LCD Message task does nothing other than periodically send messages to
\r
56 * the LCD task. The messages originating from the LCD Message task are
\r
57 * displayed on the top row of the LCD.
\r
59 * The Check task only executes every three seconds but has the highest
\r
60 * priority so is guaranteed to get processor time. Its main function is to
\r
61 * check that all the other tasks are still operational. Most tasks maintain
\r
62 * a unique count that is incremented each time the task successfully completes
\r
63 * a cycle of its function. Should any error occur within such a task the
\r
64 * count is permanently halted. The check task sets a bit in an error status
\r
65 * flag should it find any counter variable at a value that indicates an
\r
66 * error has occurred. The error flag value is converted to a string and sent
\r
67 * to the LCD task for display on the bottom row on the LCD.
\r
70 /* Standard includes. */
\r
73 /* Library includes. */
\r
74 #include "91x_lib.h"
\r
76 /* Scheduler includes. */
\r
77 #include "FreeRTOS.h"
\r
81 /* Demo application includes. */
\r
84 #include "integer.h"
\r
87 #include "semtest.h"
\r
88 #include "dynamic.h"
\r
89 #include "partest.h"
\r
91 #include "comtest2.h"
\r
94 /* Priorities for the demo application tasks. */
\r
95 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
96 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
97 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
98 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
99 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
100 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
101 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
102 #define mainMSG_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
104 /* Delays used by the various tasks defined in this file. */
\r
105 #define mainCHECK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
106 #define mainSTRING_WRITE_DELAY ( 500 / portTICK_RATE_MS )
\r
107 #define mainLCD_DELAY ( 20 / portTICK_RATE_MS )
\r
109 /* Constants for the ComTest tasks. */
\r
110 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 115200 )
\r
111 #define mainCOM_TEST_LED ( 3 )
\r
113 /* The maximum number of messages that can be pending to be written to the LCD. */
\r
114 #define mainLCD_QUEUE_LEN ( 6 )
\r
116 /* Dimension the buffer used to write the error flag string. */
\r
117 #define mainMAX_FLAG_STRING_LEN ( 32 )
\r
119 /* The structure that is passed on the LCD message queue. */
\r
122 portCHAR **ppcMessageToDisplay; /*<< Points to a char* pointing to the message to display. */
\r
123 portBASE_TYPE xRow; /*<< The row on which the message should be displayed. */
\r
125 /*-----------------------------------------------------------*/
\r
128 * The task that executes at the highest priority and calls
\r
129 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
132 static void vErrorChecks( void *pvParameters );
\r
135 * Configure the processor clock and ports.
\r
137 static void prvSetupHardware( void );
\r
140 * Checks that all the demo application tasks are still executing without error
\r
141 * - as described at the top of the file. Called by vErrorChecks().
\r
143 static void prvCheckOtherTasksAreStillRunning( void );
\r
146 * The WEB server task prototype. The task is created in this file but defined
\r
149 extern void vuIP_Task(void *pvParameters);
\r
152 * The task that displays text on the LCD.
\r
154 static void prvLCDTask( void * pvParameters );
\r
157 * The task that sends messages to be displayed on the top row of the LCD.
\r
159 static void prvLCDMessageTask( void * pvParameters );
\r
161 /*-----------------------------------------------------------*/
\r
163 /* The queue used to pass messages to the LCD task. */
\r
164 static xQueueHandle xLCDQueue;
\r
166 /* Error status flag. */
\r
167 static unsigned portLONG ulErrorFlags = 0;
\r
169 /*-----------------------------------------------------------*/
\r
172 * Starts all the other tasks, then starts the scheduler.
\r
180 /* Setup any hardware that has not already been configured by the low
\r
181 level init routines. */
\r
182 prvSetupHardware();
\r
184 /* Create the queue used to send data to the LCD task. */
\r
185 xLCDQueue = xQueueCreate( mainLCD_QUEUE_LEN, sizeof( xLCDMessage ) );
\r
187 /* Start all the standard demo application tasks. */
\r
188 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
189 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
190 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
191 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
192 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
193 vStartDynamicPriorityTasks();
\r
194 vStartMathTasks( tskIDLE_PRIORITY );
\r
195 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
197 /* Start the tasks which are defined in this file. */
\r
198 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
199 xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainLCD_TASK_PRIORITY, NULL );
\r
200 xTaskCreate( prvLCDMessageTask, "MSG", configMINIMAL_STACK_SIZE, ( void * ) &xLCDQueue, mainMSG_TASK_PRIORITY, NULL );
\r
202 /* Finally, create the WEB server task. */
\r
203 xTaskCreate( vuIP_Task, "uIP", configMINIMAL_STACK_SIZE * 3, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
206 /* Start the scheduler.
\r
208 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
209 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
210 called. The demo applications included in the FreeRTOS.org download switch
\r
211 to supervisor mode prior to main being called. If you are not using one of
\r
212 these demo application projects then ensure Supervisor mode is used here. */
\r
214 vTaskStartScheduler();
\r
216 /* We should never get here as control is now taken by the scheduler. */
\r
219 /*-----------------------------------------------------------*/
\r
221 static void prvSetupHardware( void )
\r
223 /* Configuration taken from the ST code.
\r
225 Set Flash banks size & address */
\r
226 FMI_BankRemapConfig( 4, 2, 0, 0x80000 );
\r
228 /* FMI Waite States */
\r
229 FMI_Config( FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_HIGH );
\r
231 /* Configure the FPLL = 96MHz */
\r
232 SCU_PLLFactorsConfig( 192, 25, 2 );
\r
233 SCU_PLLCmd( ENABLE );
\r
234 SCU_MCLKSourceConfig( SCU_MCLK_PLL );
\r
236 WDG_Cmd( DISABLE );
\r
239 /* GPIO8 clock source enable, used by the LCD. */
\r
240 SCU_APBPeriphClockConfig(__GPIO8, ENABLE);
\r
241 GPIO_DeInit(GPIO8);
\r
243 /* GPIO 9 clock source enable, used by the LCD. */
\r
244 SCU_APBPeriphClockConfig(__GPIO9, ENABLE);
\r
245 GPIO_DeInit(GPIO9);
\r
247 /* Enable VIC clock */
\r
248 SCU_AHBPeriphClockConfig(__VIC, ENABLE);
\r
249 SCU_AHBPeriphReset(__VIC, DISABLE);
\r
251 /* Peripheral initialisation. */
\r
253 vParTestInitialise();
\r
255 /*-----------------------------------------------------------*/
\r
257 static void vErrorChecks( void *pvParameters )
\r
259 static portCHAR cCheckVal[ mainMAX_FLAG_STRING_LEN ];
\r
260 portCHAR *pcFlagString;
\r
261 xLCDMessage xMessageToSend;
\r
262 portTickType xLastWakeTime;
\r
263 portCHAR *pcStringsToDisplay[] = {
\r
264 "Check status flag"
\r
267 /* The parameters are not used in this task. */
\r
268 ( void ) pvParameters;
\r
269 pcFlagString = &cCheckVal[ 0 ];
\r
272 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
273 functions correctly. */
\r
274 xLastWakeTime = xTaskGetTickCount();
\r
276 /* Cycle for ever, delaying then checking all the other tasks are still
\r
277 operating without error. */
\r
281 /* Delay until it is time to execute again. */
\r
282 vTaskDelayUntil( &xLastWakeTime, mainCHECK_PERIOD );
\r
284 /* Check all the other tasks to see if the error flag needs updating. */
\r
285 prvCheckOtherTasksAreStillRunning();
\r
287 /* Create a string indicating the error flag status. */
\r
288 sprintf( cCheckVal, "equals 0x%x ", ulErrorFlags );
\r
289 xMessageToSend.xRow = Line2;
\r
291 /* Send the first part of the message to the LCD task. */
\r
292 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ 0 ];
\r
293 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
294 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
296 /* Send the second part of the message to the LCD task. */
\r
297 xMessageToSend.ppcMessageToDisplay = &pcFlagString;
\r
298 xQueueSend( xLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
301 /*-----------------------------------------------------------*/
\r
303 static void prvCheckOtherTasksAreStillRunning( void )
\r
305 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
307 ulErrorFlags |= 0x01;
\r
310 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
312 ulErrorFlags |= 0x02;
\r
315 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
317 ulErrorFlags |= 0x04;
\r
320 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
322 ulErrorFlags |= 0x08;
\r
325 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
327 ulErrorFlags |= 0x10;
\r
330 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
332 ulErrorFlags |= 0x20;
\r
335 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
337 ulErrorFlags |= 0x40;
\r
340 /*-----------------------------------------------------------*/
\r
342 static void prvLCDMessageTask( void * pvParameters )
\r
344 xQueueHandle *pxLCDQueue;
\r
345 xLCDMessage xMessageToSend;
\r
346 portBASE_TYPE xIndex = 0;
\r
348 /* The strings that are written to the LCD. */
\r
349 portCHAR *pcStringsToDisplay[] = {
\r
353 "www.FreeRTOS.org",
\r
358 /* To test the parameter passing mechanism, the queue on which messages are
\r
359 posted is passed in as a parameter even though it is available as a file
\r
360 scope variable anyway. */
\r
361 pxLCDQueue = ( xQueueHandle * ) pvParameters;
\r
365 /* Wait until it is time to move onto the next string. */
\r
366 vTaskDelay( mainSTRING_WRITE_DELAY );
\r
368 /* Configure the message object to send to the LCD task. */
\r
369 xMessageToSend.ppcMessageToDisplay = &pcStringsToDisplay[ xIndex ];
\r
370 xMessageToSend.xRow = Line1;
\r
372 /* Post the message to be displayed. */
\r
373 xQueueSend( *pxLCDQueue, ( void * ) &xMessageToSend, 0 );
\r
375 /* Move onto the next message, wrapping when necessary. */
\r
377 if( *( pcStringsToDisplay[ xIndex ] ) == 0x00 )
\r
381 /* Delay longer before going back to the start of the messages. */
\r
382 vTaskDelay( mainSTRING_WRITE_DELAY * 2 );
\r
386 /*-----------------------------------------------------------*/
\r
388 void prvLCDTask( void * pvParameters )
\r
390 xQueueHandle *pxLCDQueue;
\r
391 xLCDMessage xReceivedMessage;
\r
392 portCHAR *pcString;
\r
394 /* To test the parameter passing mechanism, the queue on which messages are
\r
395 received is passed in as a parameter even though it is available as a file
\r
396 scope variable anyway. */
\r
397 pxLCDQueue = ( xQueueHandle * ) pvParameters;
\r
401 /* Wait for a message to arrive. */
\r
402 if( xQueueReceive( *pxLCDQueue, &xReceivedMessage, portMAX_DELAY ) )
\r
404 /* Where is the string we are going to display? */
\r
405 pcString = *xReceivedMessage.ppcMessageToDisplay;
\r
406 LCD_DisplayString(xReceivedMessage.xRow, pcString, BlackText);
\r
408 /* The delay here is just to ensure the LCD task does not starve
\r
409 out lower priority tasks as writhing to the LCD can take a long
\r
411 vTaskDelay( mainLCD_DELAY );
\r
415 /*-----------------------------------------------------------*/
\r