2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
31 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
32 * documentation provides more details of the standard demo application tasks.
\r
33 * In addition to the standard demo tasks, the following tasks and tests are
\r
34 * defined and/or created within this file:
\r
36 * "Check" task - This only executes every five seconds but has a high priority
\r
37 * to ensure it gets processor time. Its main function is to check that all the
\r
38 * standard demo tasks are still operational. While no errors have been
\r
39 * discovered the check task will toggle an LED every 5 seconds - the toggle
\r
40 * rate increasing to 500ms being a visual indication that at least one task has
\r
41 * reported unexpected behaviour.
\r
43 * "Reg test" tasks - These fill the registers with known values, then check
\r
44 * that each register still contains its expected value. Each task uses
\r
45 * different values. The tasks run with very low priority so get preempted very
\r
46 * frequently. A register containing an unexpected value is indicative of an
\r
47 * error in the context switching mechanism.
\r
51 /* Standard includes. */
\r
54 /* Scheduler includes. */
\r
55 #include "FreeRTOS.h"
\r
60 /* Demo app includes. */
\r
62 #include "crflash.h"
\r
63 #include "partest.h"
\r
64 #include "semtest.h"
\r
65 #include "GenQTest.h"
\r
67 #include "comtest2.h"
\r
69 /*-----------------------------------------------------------*/
\r
71 /* The time between cycles of the 'check' functionality - as described at the
\r
72 top of this file. */
\r
73 #define mainNO_ERROR_PERIOD ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
75 /* The rate at which the LED controlled by the 'check' task will flash should an
\r
76 error have been detected. */
\r
77 #define mainERROR_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
79 /* The LED controlled by the 'check' task. */
\r
80 #define mainCHECK_LED ( 3 )
\r
82 /* ComTest constants - there is no free LED for the comtest tasks. */
\r
83 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
84 #define mainCOM_TEST_LED ( 5 )
\r
86 /* Task priorities. */
\r
87 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
88 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
89 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
90 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
91 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
93 /* Co-routines are used to flash the LEDs. */
\r
94 #define mainNUM_FLASH_CO_ROUTINES ( 3 )
\r
96 /* The baud rate used by the comtest tasks. */
\r
97 #define mainBAUD_RATE ( 38400 )
\r
99 /* There is no spare LED for the comtest tasks, so this is set to an invalid
\r
101 #define mainCOM_LED ( 4 )
\r
104 * Configure the hardware for the demo.
\r
106 static void prvSetupHardware( void );
\r
109 * Implements the 'check' task functionality as described at the top of this
\r
112 static void prvCheckTask( void *pvParameters );
\r
115 * Implement the 'Reg test' functionality as described at the top of this file.
\r
117 static void vRegTest1Task( void *pvParameters );
\r
118 static void vRegTest2Task( void *pvParameters );
\r
120 /*-----------------------------------------------------------*/
\r
122 /* Counters used to detect errors within the reg test tasks. */
\r
123 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
\r
125 /*-----------------------------------------------------------*/
\r
129 /* Setup the hardware ready for this demo. */
\r
130 prvSetupHardware();
\r
132 /* Start the standard demo tasks. */
\r
133 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
134 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
135 vStartQueuePeekTasks();
\r
136 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
137 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainBAUD_RATE, mainCOM_LED );
\r
139 /* For demo purposes use some co-routines to flash the LEDs. */
\r
140 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
142 /* Create the check task. */
\r
143 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
146 /* Start the reg test tasks - defined in this file. */
\r
147 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
\r
148 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
\r
150 /* Start the scheduler. */
\r
151 vTaskStartScheduler();
\r
153 /* Will only get here if there was insufficient memory to create the idle
\r
159 /*-----------------------------------------------------------*/
\r
161 static void prvCheckTask( void *pvParameters )
\r
163 unsigned long ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
\r
164 TickType_t xLastExecutionTime;
\r
165 volatile unsigned portBASE_TYPE uxUnusedStack;
\r
167 ( void ) pvParameters;
\r
169 /* Initialise the variable used to control our iteration rate prior to
\r
171 xLastExecutionTime = xTaskGetTickCount();
\r
175 /* Wait until it is time to run the tests again. */
\r
176 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
\r
178 /* Has an error been found in any task? */
\r
179 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
184 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
189 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
194 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
199 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
204 if( ulLastRegTest1Count == ulRegTest1Counter )
\r
206 ulError |= 0x1000UL;
\r
209 if( ulLastRegTest2Count == ulRegTest2Counter )
\r
211 ulError |= 0x1000UL;
\r
214 ulLastRegTest1Count = ulRegTest1Counter;
\r
215 ulLastRegTest2Count = ulRegTest2Counter;
\r
217 /* If an error has been found then increase our cycle rate, and in so
\r
218 doing increase the rate at which the check task LED toggles. */
\r
221 ulTicksToWait = mainERROR_PERIOD;
\r
224 /* Toggle the LED each iteration. */
\r
225 vParTestToggleLED( mainCHECK_LED );
\r
227 /* For demo only - how much unused stack does this task have? */
\r
228 uxUnusedStack = uxTaskGetStackHighWaterMark( NULL );
\r
231 /*-----------------------------------------------------------*/
\r
233 void prvSetupHardware( void )
\r
235 portDISABLE_INTERRUPTS();
\r
237 /* Setup the port used to toggle LEDs. */
\r
238 vParTestInitialise();
\r
240 /*-----------------------------------------------------------*/
\r
242 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
\r
244 /* This will get called if a stack overflow is detected during the context
\r
245 switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
\r
246 problems within nested interrupts, but only do this for debug purposes as
\r
247 it will increase the context switch time. */
\r
250 ( void ) pcTaskName;
\r
256 /*-----------------------------------------------------------*/
\r
258 void vApplicationIdleHook( void );
\r
259 void vApplicationIdleHook( void )
\r
261 /* The co-routines run in the idle task. */
\r
262 vCoRoutineSchedule();
\r
264 /*-----------------------------------------------------------*/
\r
268 /* To keep the linker happy only as the libraries have been removed from
\r
273 /*-----------------------------------------------------------*/
\r
275 static void vRegTest1Task( void *pvParameters )
\r
277 /* Sanity check - did we receive the parameter expected? */
\r
278 if( pvParameters != &ulRegTest1Counter )
\r
280 /* Change here so the check task can detect that an error occurred. */
\r
286 /* Set all the registers to known values, then check that each retains its
\r
287 expected value - as described at the top of this file. If an error is
\r
288 found then the loop counter will no longer be incremented allowing the check
\r
289 task to recognise the error. */
\r
290 asm volatile ( "reg_test_1_start: \n\t"
\r
291 " moveq #1, d0 \n\t"
\r
292 " moveq #2, d1 \n\t"
\r
293 " moveq #3, d2 \n\t"
\r
294 " moveq #4, d3 \n\t"
\r
295 " moveq #5, d4 \n\t"
\r
296 " moveq #6, d5 \n\t"
\r
297 " moveq #7, d6 \n\t"
\r
298 " moveq #8, d7 \n\t"
\r
299 " move #9, a0 \n\t"
\r
300 " move #10, a1 \n\t"
\r
301 " move #11, a2 \n\t"
\r
302 " move #12, a3 \n\t"
\r
303 " move #13, a4 \n\t"
\r
304 " move #14, a5 \n\t"
\r
305 " move #15, a6 \n\t"
\r
307 " cmpi.l #1, d0 \n\t"
\r
308 " bne reg_test_1_error \n\t"
\r
309 " cmpi.l #2, d1 \n\t"
\r
310 " bne reg_test_1_error \n\t"
\r
311 " cmpi.l #3, d2 \n\t"
\r
312 " bne reg_test_1_error \n\t"
\r
313 " cmpi.l #4, d3 \n\t"
\r
314 " bne reg_test_1_error \n\t"
\r
315 " cmpi.l #5, d4 \n\t"
\r
316 " bne reg_test_1_error \n\t"
\r
317 " cmpi.l #6, d5 \n\t"
\r
318 " bne reg_test_1_error \n\t"
\r
319 " cmpi.l #7, d6 \n\t"
\r
320 " bne reg_test_1_error \n\t"
\r
321 " cmpi.l #8, d7 \n\t"
\r
322 " bne reg_test_1_error \n\t"
\r
323 " move a0, d0 \n\t"
\r
324 " cmpi.l #9, d0 \n\t"
\r
325 " bne reg_test_1_error \n\t"
\r
326 " move a1, d0 \n\t"
\r
327 " cmpi.l #10, d0 \n\t"
\r
328 " bne reg_test_1_error \n\t"
\r
329 " move a2, d0 \n\t"
\r
330 " cmpi.l #11, d0 \n\t"
\r
331 " bne reg_test_1_error \n\t"
\r
332 " move a3, d0 \n\t"
\r
333 " cmpi.l #12, d0 \n\t"
\r
334 " bne reg_test_1_error \n\t"
\r
335 " move a4, d0 \n\t"
\r
336 " cmpi.l #13, d0 \n\t"
\r
337 " bne reg_test_1_error \n\t"
\r
338 " move a5, d0 \n\t"
\r
339 " cmpi.l #14, d0 \n\t"
\r
340 " bne reg_test_1_error \n\t"
\r
341 " move a6, d0 \n\t"
\r
342 " cmpi.l #15, d0 \n\t"
\r
343 " bne reg_test_1_error \n\t"
\r
344 " move ulRegTest1Counter, d0 \n\t"
\r
345 " addq #1, d0 \n\t"
\r
346 " move d0, ulRegTest1Counter \n\t"
\r
347 " bra reg_test_1_start \n\t"
\r
348 "reg_test_1_error: \n\t"
\r
349 " bra reg_test_1_error \n\t"
\r
352 /*-----------------------------------------------------------*/
\r
354 static void vRegTest2Task( void *pvParameters )
\r
356 /* Sanity check - did we receive the parameter expected? */
\r
357 if( pvParameters != &ulRegTest2Counter )
\r
359 /* Change here so the check task can detect that an error occurred. */
\r
365 /* Set all the registers to known values, then check that each retains its
\r
366 expected value - as described at the top of this file. If an error is
\r
367 found then the loop counter will no longer be incremented allowing the check
\r
368 task to recognise the error. */
\r
369 asm volatile ( "reg_test_2_start: \n\t"
\r
370 " moveq #10, d0 \n\t"
\r
371 " moveq #20, d1 \n\t"
\r
372 " moveq #30, d2 \n\t"
\r
373 " moveq #40, d3 \n\t"
\r
374 " moveq #50, d4 \n\t"
\r
375 " moveq #60, d5 \n\t"
\r
376 " moveq #70, d6 \n\t"
\r
377 " moveq #80, d7 \n\t"
\r
378 " move #90, a0 \n\t"
\r
379 " move #100, a1 \n\t"
\r
380 " move #110, a2 \n\t"
\r
381 " move #120, a3 \n\t"
\r
382 " move #130, a4 \n\t"
\r
383 " move #140, a5 \n\t"
\r
384 " move #150, a6 \n\t"
\r
386 " cmpi.l #10, d0 \n\t"
\r
387 " bne reg_test_2_error \n\t"
\r
388 " cmpi.l #20, d1 \n\t"
\r
389 " bne reg_test_2_error \n\t"
\r
390 " cmpi.l #30, d2 \n\t"
\r
391 " bne reg_test_2_error \n\t"
\r
392 " cmpi.l #40, d3 \n\t"
\r
393 " bne reg_test_2_error \n\t"
\r
394 " cmpi.l #50, d4 \n\t"
\r
395 " bne reg_test_2_error \n\t"
\r
396 " cmpi.l #60, d5 \n\t"
\r
397 " bne reg_test_2_error \n\t"
\r
398 " cmpi.l #70, d6 \n\t"
\r
399 " bne reg_test_2_error \n\t"
\r
400 " cmpi.l #80, d7 \n\t"
\r
401 " bne reg_test_2_error \n\t"
\r
402 " move a0, d0 \n\t"
\r
403 " cmpi.l #90, d0 \n\t"
\r
404 " bne reg_test_2_error \n\t"
\r
405 " move a1, d0 \n\t"
\r
406 " cmpi.l #100, d0 \n\t"
\r
407 " bne reg_test_2_error \n\t"
\r
408 " move a2, d0 \n\t"
\r
409 " cmpi.l #110, d0 \n\t"
\r
410 " bne reg_test_2_error \n\t"
\r
411 " move a3, d0 \n\t"
\r
412 " cmpi.l #120, d0 \n\t"
\r
413 " bne reg_test_2_error \n\t"
\r
414 " move a4, d0 \n\t"
\r
415 " cmpi.l #130, d0 \n\t"
\r
416 " bne reg_test_2_error \n\t"
\r
417 " move a5, d0 \n\t"
\r
418 " cmpi.l #140, d0 \n\t"
\r
419 " bne reg_test_2_error \n\t"
\r
420 " move a6, d0 \n\t"
\r
421 " cmpi.l #150, d0 \n\t"
\r
422 " bne reg_test_2_error \n\t"
\r
423 " move ulRegTest1Counter, d0 \n\t"
\r
424 " addq #1, d0 \n\t"
\r
425 " move d0, ulRegTest2Counter \n\t"
\r
426 " bra reg_test_2_start \n\t"
\r
427 "reg_test_2_error: \n\t"
\r
428 " bra reg_test_2_error \n\t"
\r
431 /*-----------------------------------------------------------*/
\r