2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
30 * Creates all the demo application tasks, then starts the scheduler. The WEB
31 * documentation provides more details of the standard demo application tasks.
32 * In addition to the standard demo tasks, the following tasks and tests are
33 * defined and/or created within this file:
35 * "Web server" - Very basic demonstration of the lwIP stack. The WEB server
36 * simply generates a page that shows the current state of all the tasks within
37 * the system, including the high water mark of each task stack. The high water
38 * mark is displayed as the amount of stack that has never been used, so the
39 * closer the value is to zero the closer the task has come to overflowing its
40 * stack. The IP address and net mask are set within FreeRTOSConfig.h.
42 * "Check" task - This only executes every five seconds but has a high priority
43 * to ensure it gets processor time. Its main function is to check that all the
44 * standard demo tasks are still operational. While no errors have been
45 * discovered the check task will toggle an LED every 5 seconds - the toggle
46 * rate increasing to 500ms being a visual indication that at least one task has
47 * reported unexpected behaviour.
49 * "Reg test" tasks - These fill the registers with known values, then check
50 * that each register still contains its expected value. Each task uses
51 * different values. The tasks run with very low priority so get preempted very
52 * frequently. A register containing an unexpected value is indicative of an
53 * error in the context switching mechanism.
57 /* Standard includes. */
60 /* Scheduler includes. */
66 /* Demo app includes. */
77 /*-----------------------------------------------------------*/
79 /* The time between cycles of the 'check' functionality - as described at the
81 #define mainNO_ERROR_PERIOD ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
83 /* The rate at which the LED controlled by the 'check' task will flash should an
84 error have been detected. */
85 #define mainERROR_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
87 /* The LED controlled by the 'check' task. */
88 #define mainCHECK_LED ( 3 )
90 /* ComTest constants - there is no free LED for the comtest tasks. */
91 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
92 #define mainCOM_TEST_LED ( 5 )
94 /* Task priorities. */
95 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
96 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
97 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
98 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
99 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
100 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
101 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
102 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
103 #define mainWEB_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
106 * Configure the hardware for the demo.
108 static void prvSetupHardware( void );
111 * Implements the 'check' task functionality as described at the top of this
114 static void prvCheckTask( void *pvParameters );
117 * Implement the 'Reg test' functionality as described at the top of this file.
119 static void vRegTest1Task( void *pvParameters );
120 static void vRegTest2Task( void *pvParameters );
122 /*-----------------------------------------------------------*/
124 /* Counters used to detect errors within the reg test tasks. */
125 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
127 /*-----------------------------------------------------------*/
131 extern void vBasicWEBServer( void *pv );
133 /* Setup the hardware ready for this demo. */
135 ( void )sys_thread_new("HTTPD", vBasicWEBServer, NULL, 320, mainWEB_TASK_PRIORITY );
137 /* Start the standard demo tasks. */
138 vStartLEDFlashTasks( tskIDLE_PRIORITY );
139 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
140 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
141 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
142 vStartQueuePeekTasks();
143 vStartRecursiveMutexTasks();
144 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
146 /* Start the reg test tasks - defined in this file. */
147 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
148 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
150 /* Create the check task. */
151 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
153 /* The suicide tasks must be created last as they need to know how many
154 tasks were running prior to their creation in order to ascertain whether
155 or not the correct/expected number of tasks are running at any given time. */
156 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
158 /* Start the scheduler. */
159 vTaskStartScheduler();
161 /* Will only get here if there was insufficient memory to create the idle
167 /*-----------------------------------------------------------*/
169 static void prvCheckTask( void *pvParameters )
171 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
172 TickType_t xLastExecutionTime;
174 ( void ) pvParameters;
176 /* Initialise the variable used to control our iteration rate prior to
178 xLastExecutionTime = xTaskGetTickCount();
182 /* Wait until it is time to run the tests again. */
183 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
185 /* Has an error been found in any task? */
186 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
191 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
196 if( xAreBlockingQueuesStillRunning() != pdTRUE )
201 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
206 if( xArePollingQueuesStillRunning() != pdTRUE )
211 if( xIsCreateTaskStillRunning() != pdTRUE )
216 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
221 if( ulLastRegTest1Count == ulRegTest1Counter )
226 if( ulLastRegTest2Count == ulRegTest2Counter )
231 ulLastRegTest1Count = ulRegTest1Counter;
232 ulLastRegTest2Count = ulRegTest2Counter;
234 /* If an error has been found then increase our cycle rate, and in so
235 going increase the rate at which the check task LED toggles. */
238 ulTicksToWait = mainERROR_PERIOD;
241 /* Toggle the LED each iteration. */
242 vParTestToggleLED( mainCHECK_LED );
245 /*-----------------------------------------------------------*/
247 void prvSetupHardware( void )
249 portDISABLE_INTERRUPTS();
251 /* Setup the port used to toggle LEDs. */
252 vParTestInitialise();
254 /*-----------------------------------------------------------*/
256 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
258 /* This will get called if a stack overflow is detected during the context
259 switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
260 problems within nested interrupts, but only do this for debug purposes as
261 it will increase the context switch time. */
270 /*-----------------------------------------------------------*/
272 static void vRegTest1Task( void *pvParameters )
274 /* Sanity check - did we receive the parameter expected? */
275 if( pvParameters != &ulRegTest1Counter )
277 /* Change here so the check task can detect that an error occurred. */
283 /* Set all the registers to known values, then check that each retains its
284 expected value - as described at the top of this file. If an error is
285 found then the loop counter will no longer be incremented allowing the check
286 task to recognise the error. */
287 asm volatile ( "reg_test_1_start: \n\t"
304 " cmpi.l #1, d0 \n\t"
305 " bne reg_test_1_error \n\t"
306 " cmpi.l #2, d1 \n\t"
307 " bne reg_test_1_error \n\t"
308 " cmpi.l #3, d2 \n\t"
309 " bne reg_test_1_error \n\t"
310 " cmpi.l #4, d3 \n\t"
311 " bne reg_test_1_error \n\t"
312 " cmpi.l #5, d4 \n\t"
313 " bne reg_test_1_error \n\t"
314 " cmpi.l #6, d5 \n\t"
315 " bne reg_test_1_error \n\t"
316 " cmpi.l #7, d6 \n\t"
317 " bne reg_test_1_error \n\t"
318 " cmpi.l #8, d7 \n\t"
319 " bne reg_test_1_error \n\t"
321 " cmpi.l #9, d0 \n\t"
322 " bne reg_test_1_error \n\t"
324 " cmpi.l #10, d0 \n\t"
325 " bne reg_test_1_error \n\t"
327 " cmpi.l #11, d0 \n\t"
328 " bne reg_test_1_error \n\t"
330 " cmpi.l #12, d0 \n\t"
331 " bne reg_test_1_error \n\t"
333 " cmpi.l #13, d0 \n\t"
334 " bne reg_test_1_error \n\t"
336 " cmpi.l #14, d0 \n\t"
337 " bne reg_test_1_error \n\t"
339 " cmpi.l #15, d0 \n\t"
340 " bne reg_test_1_error \n\t"
341 " move ulRegTest1Counter, d0 \n\t"
343 " move d0, ulRegTest1Counter \n\t"
344 " bra reg_test_1_start \n\t"
345 "reg_test_1_error: \n\t"
346 " bra reg_test_1_error \n\t"
349 /*-----------------------------------------------------------*/
351 static void vRegTest2Task( void *pvParameters )
353 /* Sanity check - did we receive the parameter expected? */
354 if( pvParameters != &ulRegTest2Counter )
356 /* Change here so the check task can detect that an error occurred. */
362 /* Set all the registers to known values, then check that each retains its
363 expected value - as described at the top of this file. If an error is
364 found then the loop counter will no longer be incremented allowing the check
365 task to recognise the error. */
366 asm volatile ( "reg_test_2_start: \n\t"
367 " moveq #10, d0 \n\t"
368 " moveq #20, d1 \n\t"
369 " moveq #30, d2 \n\t"
370 " moveq #40, d3 \n\t"
371 " moveq #50, d4 \n\t"
372 " moveq #60, d5 \n\t"
373 " moveq #70, d6 \n\t"
374 " moveq #80, d7 \n\t"
376 " move #100, a1 \n\t"
377 " move #110, a2 \n\t"
378 " move #120, a3 \n\t"
379 " move #130, a4 \n\t"
380 " move #140, a5 \n\t"
381 " move #150, a6 \n\t"
383 " cmpi.l #10, d0 \n\t"
384 " bne reg_test_2_error \n\t"
385 " cmpi.l #20, d1 \n\t"
386 " bne reg_test_2_error \n\t"
387 " cmpi.l #30, d2 \n\t"
388 " bne reg_test_2_error \n\t"
389 " cmpi.l #40, d3 \n\t"
390 " bne reg_test_2_error \n\t"
391 " cmpi.l #50, d4 \n\t"
392 " bne reg_test_2_error \n\t"
393 " cmpi.l #60, d5 \n\t"
394 " bne reg_test_2_error \n\t"
395 " cmpi.l #70, d6 \n\t"
396 " bne reg_test_2_error \n\t"
397 " cmpi.l #80, d7 \n\t"
398 " bne reg_test_2_error \n\t"
400 " cmpi.l #90, d0 \n\t"
401 " bne reg_test_2_error \n\t"
403 " cmpi.l #100, d0 \n\t"
404 " bne reg_test_2_error \n\t"
406 " cmpi.l #110, d0 \n\t"
407 " bne reg_test_2_error \n\t"
409 " cmpi.l #120, d0 \n\t"
410 " bne reg_test_2_error \n\t"
412 " cmpi.l #130, d0 \n\t"
413 " bne reg_test_2_error \n\t"
415 " cmpi.l #140, d0 \n\t"
416 " bne reg_test_2_error \n\t"
418 " cmpi.l #150, d0 \n\t"
419 " bne reg_test_2_error \n\t"
420 " move ulRegTest1Counter, d0 \n\t"
422 " move d0, ulRegTest2Counter \n\t"
423 " bra reg_test_2_start \n\t"
424 "reg_test_2_error: \n\t"
425 " bra reg_test_2_error \n\t"
428 /*-----------------------------------------------------------*/