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
174 #if ( INCLUDE_StartIntegerMathTasks == 1 )
\r
175 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
177 #if ( INCLUDE_AltStartComTestTasks == 1 )
\r
178 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
180 #if ( INCLUDE_StartPolledQueueTasks == 1 )
\r
181 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
183 #if ( INCLUDE_StartSemaphoreTasks == 1 )
\r
184 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
186 #if ( INCLUDE_StartBlockingQueueTasks == 1 )
\r
187 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
189 #if ( INCLUDE_StartDynamicPriorityTasks == 1 )
\r
190 vStartDynamicPriorityTasks();
\r
192 #if ( INCLUDE_StartMathTasks == 1 )
\r
193 vStartMathTasks( tskIDLE_PRIORITY );
\r
195 #if ( INCLUDE_StartFlashCoRoutines == 1 )
\r
196 vStartFlashCoRoutines( ledNUMBER_OF_LEDS );
\r
198 #if ( INCLUDE_StartHookCoRoutines == 1 )
\r
199 vStartHookCoRoutines();
\r
201 #if ( INCLUDE_StartGenericQueueTasks == 1 )
\r
202 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
204 #if ( INCLUDE_StartQueuePeekTasks == 1 )
\r
205 vStartQueuePeekTasks();
\r
207 #if ( INCLUDE_CreateBlockTimeTasks == 1 )
\r
208 vCreateBlockTimeTasks();
\r
210 #if ( INCLUDE_CreateSuicidalTasks == 1 )
\r
211 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
213 #if ( INCLUDE_TraceListTasks == 1 )
\r
214 vTraceListTasks( TASK_UTILITY_PRIORITY );
\r
217 /* Start the 'Check' task which is defined in this file. */
\r
218 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
220 vTaskStartScheduler();
\r
222 /* Should not reach here */
\r
225 __asm( " NOP " ); /* // */
\r
229 /*-----------------------------------------------------------*/
\r
230 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
\r
232 if( uxLED < ledNUMBER_OF_LEDS )
\r
236 /* Toggle the state of the single genuine on board LED. */
\r
237 if( (sState[0] & ((portCHAR) (1 << uxLED))) == 0 )
\r
239 PDR09 |= ( 1 << uxLED );
\r
240 sState[0] |= ( 1 << uxLED );
\r
244 PDR09 &= ~( 1 << uxLED );
\r
245 sState[0] &= ~( 1 << uxLED );
\r
254 uxLED -= ledNUMBER_OF_LEDS;
\r
256 if( (sState[1] & ((portCHAR) (1 << uxLED))) == 0 )
\r
258 PDR00 |= ( 1 << uxLED );
\r
259 sState[1] |= ( 1 << uxLED );
\r
263 PDR00 &= ~( 1 << uxLED );
\r
264 sState[1] &= ~( 1 << uxLED );
\r
271 /*-----------------------------------------------------------*/
\r
272 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
\r
274 /* Set or clear the output [in this case show or hide the '*' character. */
\r
275 if( uxLED < ledNUMBER_OF_LEDS )
\r
281 PDR09 &= ~( 1 << uxLED );
\r
282 sState[0] &= ~( 1 << uxLED );
\r
286 PDR09 |= ( 1 << uxLED );
\r
287 sState[0] |= ( 1 << uxLED );
\r
299 PDR00 &= ~( 1 << uxLED );
\r
300 sState[1] &= ~( 1 << uxLED );
\r
304 PDR00 |= ( 1 << uxLED );
\r
305 sState[1] |= ( 1 << uxLED );
\r
313 /*-----------------------------------------------------------*/
\r
314 static void vErrorChecks( void *pvParameters )
\r
316 static volatile unsigned portLONG ulDummyVariable = 3UL;
\r
317 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
318 ( void ) pvParameters;
\r
320 /* Cycle for ever, delaying then checking all the other tasks are still
\r
321 operating without error. */
\r
324 /* Wait until it is time to check again. The time we wait here depends
\r
325 on whether an error has been detected or not. When an error is
\r
326 detected the time is shortened resulting in a faster LED flash rate. */
\r
327 vTaskDelay( xDelayPeriod );
\r
329 /* Perform a bit of 32bit maths to ensure the registers used by the
\r
330 integer tasks get some exercise outside of the integer tasks
\r
331 themselves. The result here is not important we are just deliberately
\r
332 changing registers used by other tasks to ensure that their context
\r
333 switch is operating as required. - see the demo application
\r
334 documentation for more info. */
\r
335 ulDummyVariable *= 3UL;
\r
337 /* See if the other tasks are all ok. */
\r
338 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
340 /* An error occurred in one of the tasks so shorten the delay
\r
341 period - which has the effect of increasing the frequency of the
\r
343 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
347 vParTestToggleLED( mainCHECK_TEST_LED );
\r
351 /*-----------------------------------------------------------*/
\r
352 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
354 static portSHORT sNoErrorFound = pdTRUE;
\r
356 /* The demo tasks maintain a count that increments every cycle of the task
\r
357 provided that the task has never encountered an error. This function
\r
358 checks the counts maintained by the tasks to ensure they are still being
\r
359 incremented. A count remaining at the same value between calls therefore
\r
360 indicates that an error has been detected. Only tasks that do not flash
\r
361 an LED are checked. */
\r
362 #if ( INCLUDE_StartIntegerMathTasks == 1 )
\r
363 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
365 sNoErrorFound = pdFALSE;
\r
369 #if ( INCLUDE_AltStartComTestTasks == 1 )
\r
370 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
372 sNoErrorFound = pdFALSE;
\r
376 #if ( INCLUDE_StartPolledQueueTasks == 1 )
\r
377 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
379 sNoErrorFound = pdFALSE;
\r
383 #if ( INCLUDE_StartSemaphoreTasks == 1 )
\r
384 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
386 sNoErrorFound = pdFALSE;
\r
390 #if ( INCLUDE_StartBlockingQueueTasks == 1 )
\r
391 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
393 sNoErrorFound = pdFALSE;
\r
397 #if ( INCLUDE_StartDynamicPriorityTasks == 1 )
\r
398 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
400 sNoErrorFound = pdFALSE;
\r
404 #if ( INCLUDE_StartMathTasks == 1 )
\r
405 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
407 sNoErrorFound = pdFALSE;
\r
411 #if ( INCLUDE_StartFlashCoRoutines == 1 )
\r
412 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
414 sNoErrorFound = pdFALSE;
\r
418 #if ( INCLUDE_StartHookCoRoutines == 1 )
\r
419 if( xAreHookCoRoutinesStillRunning() != pdTRUE )
\r
421 sNoErrorFound = pdFALSE;
\r
425 #if ( INCLUDE_StartGenericQueueTasks == 1 )
\r
426 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
428 sNoErrorFound = pdFALSE;
\r
432 #if ( INCLUDE_StartQueuePeekTasks == 1 )
\r
433 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
435 sNoErrorFound = pdFALSE;
\r
439 #if ( INCLUDE_CreateBlockTimeTasks == 1 )
\r
440 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
442 sNoErrorFound = pdFALSE;
\r
446 #if ( INCLUDE_CreateSuicidalTasks == 1 )
\r
447 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
449 sNoErrorFound = pdFALSE;
\r
453 return sNoErrorFound;
\r
456 /*---------------------------------------------------------------------------*/
\r