2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org 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.org 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.org; 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.org, 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
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
43 /*---------------------------------------------------------------------------
\r
46 - See README.TXT for project description and disclaimer.
\r
48 /*---------------------------------------------------------------------------*/
\r
51 #include "mb96348hs.h"
\r
53 /* Scheduler includes. */
\r
54 #include "FreeRTOS.h"
\r
57 #include <watchdog.h>
\r
60 /*---------------------------------------------------------------------------*/
\r
62 /* Demo task priorities. */
\r
63 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
64 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
65 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
66 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
67 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
68 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
69 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
70 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
71 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
72 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
74 /* Baud rate used by the COM test tasks. */
\r
75 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
77 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
78 top of the page. When the system is operating error free the 'Check' task
\r
79 toggles an LED every three seconds. If an error is discovered in any task the
\r
80 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
81 LCD represent LED's]*/
\r
82 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
83 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
85 /*---------------------------------------------------------------------------*/
\r
86 #define ledNUMBER_OF_LEDS 8
\r
87 #define mainCOM_TEST_LED 0x05
\r
88 #define mainCHECK_TEST_LED 0x07
\r
90 /*---------------------------------------------------------------------------*/
\r
93 * The function that implements the Check task. See the comments at the head
\r
94 * of the page for implementation details.
\r
96 static void vErrorChecks( void *pvParameters );
\r
99 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
100 * to be operating without error - otherwise returns pdFAIL.
\r
102 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
104 /*---------------------------------------------------------------------------*/
\r
105 static unsigned portCHAR sState[2] = { 0xFF, 0xFF };
\r
107 /*---------------------------------------------------------------------------
\r
108 * The below callback function is called from Tick ISR if configUSE_TICK_HOOK
\r
109 * is configured as 1.
\r
110 *---------------------------------------------------------------------------*/
\r
112 /*void vApplicationTickHook ( void )
\r
114 #if WATCHDOG == WTC_IN_TICK
\r
119 /*---------------------------------------------------------------------------
\r
120 * The below callback function is called from Delayed ISR if configUSE_IDLE_HOOK
\r
121 * is configured as 1.
\r
122 *---------------------------------------------------------------------------*/
\r
123 void vApplicationIdleHook( void )
\r
125 #if WATCHDOG == WTC_IN_IDLE
\r
128 #if ( INCLUDE_StartFlashCoRoutines == 1 || INCLUDE_StartHookCoRoutines == 1 )
\r
129 vCoRoutineSchedule();
\r
133 /*---------------------------------------------------------------------------
\r
134 * Initialize Port 00
\r
135 *---------------------------------------------------------------------------*/
\r
136 static void prvInitPort00( void )
\r
144 /*---------------------------------------------------------------------------
\r
145 * Setup the hardware
\r
146 *---------------------------------------------------------------------------*/
\r
147 static void prvSetupHardware( void )
\r
151 #if WATCHDOG != WTC_NONE
\r
156 /*---------------------------------------------------------------------------
\r
158 *---------------------------------------------------------------------------*/
\r
161 InitIrqLevels(); /* Initialize interrupts */
\r
162 __set_il( 7 ); /* Allow all levels */
\r
164 prvSetupHardware();
\r
166 #if WATCHDOG == WTC_IN_TASK
\r
167 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
170 /* Start the standard demo application tasks. */
\r
171 #if ( INCLUDE_StartLEDFlashTasks == 1 )
\r
172 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
175 #if ( INCLUDE_StartIntegerMathTasks == 1 )
\r
176 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
179 #if ( INCLUDE_AltStartComTestTasks == 1 )
\r
180 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
183 #if ( INCLUDE_StartPolledQueueTasks == 1 )
\r
184 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
187 #if ( INCLUDE_StartSemaphoreTasks == 1 )
\r
188 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
191 #if ( INCLUDE_StartBlockingQueueTasks == 1 )
\r
192 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
195 #if ( INCLUDE_StartDynamicPriorityTasks == 1 )
\r
196 vStartDynamicPriorityTasks();
\r
199 #if ( INCLUDE_StartMathTasks == 1 )
\r
200 vStartMathTasks( tskIDLE_PRIORITY );
\r
203 #if ( INCLUDE_StartFlashCoRoutines == 1 )
\r
204 vStartFlashCoRoutines( ledNUMBER_OF_LEDS );
\r
207 #if ( INCLUDE_StartHookCoRoutines == 1 )
\r
208 vStartHookCoRoutines();
\r
211 #if ( INCLUDE_StartGenericQueueTasks == 1 )
\r
212 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
215 #if ( INCLUDE_StartQueuePeekTasks == 1 )
\r
216 vStartQueuePeekTasks();
\r
219 #if ( INCLUDE_CreateBlockTimeTasks == 1 )
\r
220 vCreateBlockTimeTasks();
\r
223 #if ( INCLUDE_CreateSuicidalTasks == 1 )
\r
224 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
227 #if ( INCLUDE_TraceListTasks == 1 )
\r
228 vTraceListTasks( TASK_UTILITY_PRIORITY );
\r
231 /* Start the 'Check' task which is defined in this file. */
\r
232 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
234 vTaskStartScheduler();
\r
236 /* Should not reach here */
\r
239 __asm( " NOP " ); /* // */
\r
243 /*-----------------------------------------------------------*/
\r
244 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
\r
246 if( uxLED < ledNUMBER_OF_LEDS )
\r
250 /* Toggle the state of the single genuine on board LED. */
\r
251 if( (sState[0] & ((portCHAR) (1 << uxLED))) == 0 )
\r
253 PDR09 |= ( 1 << uxLED );
\r
254 sState[0] |= ( 1 << uxLED );
\r
258 PDR09 &= ~( 1 << uxLED );
\r
259 sState[0] &= ~( 1 << uxLED );
\r
268 uxLED -= ledNUMBER_OF_LEDS;
\r
270 if( (sState[1] & ((portCHAR) (1 << uxLED))) == 0 )
\r
272 PDR00 |= ( 1 << uxLED );
\r
273 sState[1] |= ( 1 << uxLED );
\r
277 PDR00 &= ~( 1 << uxLED );
\r
278 sState[1] &= ~( 1 << uxLED );
\r
285 /*-----------------------------------------------------------*/
\r
286 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
\r
288 /* Set or clear the output [in this case show or hide the '*' character. */
\r
289 if( uxLED < ledNUMBER_OF_LEDS )
\r
295 PDR09 &= ~( 1 << uxLED );
\r
296 sState[0] &= ~( 1 << uxLED );
\r
300 PDR09 |= ( 1 << uxLED );
\r
301 sState[0] |= ( 1 << uxLED );
\r
313 PDR00 &= ~( 1 << uxLED );
\r
314 sState[1] &= ~( 1 << uxLED );
\r
318 PDR00 |= ( 1 << uxLED );
\r
319 sState[1] |= ( 1 << uxLED );
\r
327 /*-----------------------------------------------------------*/
\r
328 static void vErrorChecks( void *pvParameters )
\r
330 static volatile unsigned portLONG ulDummyVariable = 3UL;
\r
331 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
332 ( void ) pvParameters;
\r
334 /* Cycle for ever, delaying then checking all the other tasks are still
\r
335 operating without error. */
\r
338 /* Wait until it is time to check again. The time we wait here depends
\r
339 on whether an error has been detected or not. When an error is
\r
340 detected the time is shortened resulting in a faster LED flash rate. */
\r
341 vTaskDelay( xDelayPeriod );
\r
343 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
344 integer tasks get some exercise outside of the integer tasks
\r
345 themselves. The result here is not important we are just deliberately
\r
346 changing registers used by other tasks to ensure that their context
\r
347 switch is operating as required. - see the demo application
\r
348 documentation for more info. */
\r
349 ulDummyVariable *= 3UL;
\r
351 /* See if the other tasks are all ok. */
\r
352 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
354 /* An error occurred in one of the tasks so shorten the delay
\r
355 period - which has the effect of increasing the frequency of the
\r
357 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
361 vParTestToggleLED( mainCHECK_TEST_LED );
\r
365 /*-----------------------------------------------------------*/
\r
366 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
368 static portSHORT sNoErrorFound = pdTRUE;
\r
370 /* The demo tasks maintain a count that increments every cycle of the task
\r
371 provided that the task has never encountered an error. This function
\r
372 checks the counts maintained by the tasks to ensure they are still being
\r
373 incremented. A count remaining at the same value between calls therefore
\r
374 indicates that an error has been detected. Only tasks that do not flash
\r
375 an LED are checked. */
\r
376 #if ( INCLUDE_StartIntegerMathTasks == 1 )
\r
377 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
379 sNoErrorFound = pdFALSE;
\r
383 #if ( INCLUDE_AltStartComTestTasks == 1 )
\r
384 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
386 sNoErrorFound = pdFALSE;
\r
390 #if ( INCLUDE_StartPolledQueueTasks == 1 )
\r
391 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
393 sNoErrorFound = pdFALSE;
\r
397 #if ( INCLUDE_StartSemaphoreTasks == 1 )
\r
398 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
400 sNoErrorFound = pdFALSE;
\r
404 #if ( INCLUDE_StartBlockingQueueTasks == 1 )
\r
405 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
407 sNoErrorFound = pdFALSE;
\r
411 #if ( INCLUDE_StartDynamicPriorityTasks == 1 )
\r
412 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
414 sNoErrorFound = pdFALSE;
\r
418 #if ( INCLUDE_StartMathTasks == 1 )
\r
419 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
421 sNoErrorFound = pdFALSE;
\r
425 #if ( INCLUDE_StartFlashCoRoutines == 1 )
\r
426 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
428 sNoErrorFound = pdFALSE;
\r
432 #if ( INCLUDE_StartHookCoRoutines == 1 )
\r
433 if( xAreHookCoRoutinesStillRunning() != pdTRUE )
\r
435 sNoErrorFound = pdFALSE;
\r
439 #if ( INCLUDE_StartGenericQueueTasks == 1 )
\r
440 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
442 sNoErrorFound = pdFALSE;
\r
446 #if ( INCLUDE_StartQueuePeekTasks == 1 )
\r
447 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
449 sNoErrorFound = pdFALSE;
\r
453 #if ( INCLUDE_CreateBlockTimeTasks == 1 )
\r
454 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
456 sNoErrorFound = pdFALSE;
\r
460 #if ( INCLUDE_CreateSuicidalTasks == 1 )
\r
461 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
463 sNoErrorFound = pdFALSE;
\r
467 return sNoErrorFound;
\r
470 /*---------------------------------------------------------------------------*/
\r