2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
72 * Creates all the demo application tasks, then starts the scheduler. The WEB
73 * documentation provides more details of the standard demo application tasks.
74 * In addition to the standard demo tasks, the following tasks and tests are
75 * defined and/or created within this file:
77 * "Web server" - Very basic demonstration of the lwIP stack. The WEB server
78 * simply generates a page that shows the current state of all the tasks within
79 * the system, including the high water mark of each task stack. The high water
80 * mark is displayed as the amount of stack that has never been used, so the
81 * closer the value is to zero the closer the task has come to overflowing its
82 * stack. The IP address and net mask are set within FreeRTOSConfig.h.
84 * "Check" task - This only executes every five seconds but has a high priority
85 * to ensure it gets processor time. Its main function is to check that all the
86 * standard demo tasks are still operational. While no errors have been
87 * discovered the check task will toggle an LED every 5 seconds - the toggle
88 * rate increasing to 500ms being a visual indication that at least one task has
89 * reported unexpected behaviour.
91 * "Reg test" tasks - These fill the registers with known values, then check
92 * that each register still contains its expected value. Each task uses
93 * different values. The tasks run with very low priority so get preempted very
94 * frequently. A register containing an unexpected value is indicative of an
95 * error in the context switching mechanism.
99 /* Standard includes. */
102 /* Scheduler includes. */
103 #include "FreeRTOS.h"
108 /* Demo app includes. */
115 #include "GenQTest.h"
117 #include "recmutex.h"
119 /*-----------------------------------------------------------*/
121 /* The time between cycles of the 'check' functionality - as described at the
123 #define mainNO_ERROR_PERIOD ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
125 /* The rate at which the LED controlled by the 'check' task will flash should an
126 error have been detected. */
127 #define mainERROR_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
129 /* The LED controlled by the 'check' task. */
130 #define mainCHECK_LED ( 3 )
132 /* ComTest constants - there is no free LED for the comtest tasks. */
133 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
134 #define mainCOM_TEST_LED ( 5 )
136 /* Task priorities. */
137 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
138 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
139 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
140 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
141 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
142 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
143 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
144 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
145 #define mainWEB_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
148 * Configure the hardware for the demo.
150 static void prvSetupHardware( void );
153 * Implements the 'check' task functionality as described at the top of this
156 static void prvCheckTask( void *pvParameters );
159 * Implement the 'Reg test' functionality as described at the top of this file.
161 static void vRegTest1Task( void *pvParameters );
162 static void vRegTest2Task( void *pvParameters );
164 /*-----------------------------------------------------------*/
166 /* Counters used to detect errors within the reg test tasks. */
167 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
169 /*-----------------------------------------------------------*/
173 extern void vBasicWEBServer( void *pv );
175 /* Setup the hardware ready for this demo. */
177 ( void )sys_thread_new("HTTPD", vBasicWEBServer, NULL, 320, mainWEB_TASK_PRIORITY );
179 /* Start the standard demo tasks. */
180 vStartLEDFlashTasks( tskIDLE_PRIORITY );
181 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
182 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
183 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
184 vStartQueuePeekTasks();
185 vStartRecursiveMutexTasks();
186 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
188 /* Start the reg test tasks - defined in this file. */
189 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
190 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
192 /* Create the check task. */
193 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
195 /* The suicide tasks must be created last as they need to know how many
196 tasks were running prior to their creation in order to ascertain whether
197 or not the correct/expected number of tasks are running at any given time. */
198 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
200 /* Start the scheduler. */
201 vTaskStartScheduler();
203 /* Will only get here if there was insufficient memory to create the idle
209 /*-----------------------------------------------------------*/
211 static void prvCheckTask( void *pvParameters )
213 unsigned ulTicksToWait = mainNO_ERROR_PERIOD, ulError = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
214 TickType_t xLastExecutionTime;
216 ( void ) pvParameters;
218 /* Initialise the variable used to control our iteration rate prior to
220 xLastExecutionTime = xTaskGetTickCount();
224 /* Wait until it is time to run the tests again. */
225 vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
227 /* Has an error been found in any task? */
228 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
233 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
238 if( xAreBlockingQueuesStillRunning() != pdTRUE )
243 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
248 if( xArePollingQueuesStillRunning() != pdTRUE )
253 if( xIsCreateTaskStillRunning() != pdTRUE )
258 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
263 if( ulLastRegTest1Count == ulRegTest1Counter )
268 if( ulLastRegTest2Count == ulRegTest2Counter )
273 ulLastRegTest1Count = ulRegTest1Counter;
274 ulLastRegTest2Count = ulRegTest2Counter;
276 /* If an error has been found then increase our cycle rate, and in so
277 going increase the rate at which the check task LED toggles. */
280 ulTicksToWait = mainERROR_PERIOD;
283 /* Toggle the LED each iteration. */
284 vParTestToggleLED( mainCHECK_LED );
287 /*-----------------------------------------------------------*/
289 void prvSetupHardware( void )
291 portDISABLE_INTERRUPTS();
293 /* Setup the port used to toggle LEDs. */
294 vParTestInitialise();
296 /*-----------------------------------------------------------*/
298 void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
300 /* This will get called if a stack overflow is detected during the context
301 switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
302 problems within nested interrupts, but only do this for debug purposes as
303 it will increase the context switch time. */
312 /*-----------------------------------------------------------*/
314 static void vRegTest1Task( void *pvParameters )
316 /* Sanity check - did we receive the parameter expected? */
317 if( pvParameters != &ulRegTest1Counter )
319 /* Change here so the check task can detect that an error occurred. */
325 /* Set all the registers to known values, then check that each retains its
326 expected value - as described at the top of this file. If an error is
327 found then the loop counter will no longer be incremented allowing the check
328 task to recognise the error. */
329 asm volatile ( "reg_test_1_start: \n\t"
346 " cmpi.l #1, d0 \n\t"
347 " bne reg_test_1_error \n\t"
348 " cmpi.l #2, d1 \n\t"
349 " bne reg_test_1_error \n\t"
350 " cmpi.l #3, d2 \n\t"
351 " bne reg_test_1_error \n\t"
352 " cmpi.l #4, d3 \n\t"
353 " bne reg_test_1_error \n\t"
354 " cmpi.l #5, d4 \n\t"
355 " bne reg_test_1_error \n\t"
356 " cmpi.l #6, d5 \n\t"
357 " bne reg_test_1_error \n\t"
358 " cmpi.l #7, d6 \n\t"
359 " bne reg_test_1_error \n\t"
360 " cmpi.l #8, d7 \n\t"
361 " bne reg_test_1_error \n\t"
363 " cmpi.l #9, d0 \n\t"
364 " bne reg_test_1_error \n\t"
366 " cmpi.l #10, d0 \n\t"
367 " bne reg_test_1_error \n\t"
369 " cmpi.l #11, d0 \n\t"
370 " bne reg_test_1_error \n\t"
372 " cmpi.l #12, d0 \n\t"
373 " bne reg_test_1_error \n\t"
375 " cmpi.l #13, d0 \n\t"
376 " bne reg_test_1_error \n\t"
378 " cmpi.l #14, d0 \n\t"
379 " bne reg_test_1_error \n\t"
381 " cmpi.l #15, d0 \n\t"
382 " bne reg_test_1_error \n\t"
383 " move ulRegTest1Counter, d0 \n\t"
385 " move d0, ulRegTest1Counter \n\t"
386 " bra reg_test_1_start \n\t"
387 "reg_test_1_error: \n\t"
388 " bra reg_test_1_error \n\t"
391 /*-----------------------------------------------------------*/
393 static void vRegTest2Task( void *pvParameters )
395 /* Sanity check - did we receive the parameter expected? */
396 if( pvParameters != &ulRegTest2Counter )
398 /* Change here so the check task can detect that an error occurred. */
404 /* Set all the registers to known values, then check that each retains its
405 expected value - as described at the top of this file. If an error is
406 found then the loop counter will no longer be incremented allowing the check
407 task to recognise the error. */
408 asm volatile ( "reg_test_2_start: \n\t"
409 " moveq #10, d0 \n\t"
410 " moveq #20, d1 \n\t"
411 " moveq #30, d2 \n\t"
412 " moveq #40, d3 \n\t"
413 " moveq #50, d4 \n\t"
414 " moveq #60, d5 \n\t"
415 " moveq #70, d6 \n\t"
416 " moveq #80, d7 \n\t"
418 " move #100, a1 \n\t"
419 " move #110, a2 \n\t"
420 " move #120, a3 \n\t"
421 " move #130, a4 \n\t"
422 " move #140, a5 \n\t"
423 " move #150, a6 \n\t"
425 " cmpi.l #10, d0 \n\t"
426 " bne reg_test_2_error \n\t"
427 " cmpi.l #20, d1 \n\t"
428 " bne reg_test_2_error \n\t"
429 " cmpi.l #30, d2 \n\t"
430 " bne reg_test_2_error \n\t"
431 " cmpi.l #40, d3 \n\t"
432 " bne reg_test_2_error \n\t"
433 " cmpi.l #50, d4 \n\t"
434 " bne reg_test_2_error \n\t"
435 " cmpi.l #60, d5 \n\t"
436 " bne reg_test_2_error \n\t"
437 " cmpi.l #70, d6 \n\t"
438 " bne reg_test_2_error \n\t"
439 " cmpi.l #80, d7 \n\t"
440 " bne reg_test_2_error \n\t"
442 " cmpi.l #90, d0 \n\t"
443 " bne reg_test_2_error \n\t"
445 " cmpi.l #100, d0 \n\t"
446 " bne reg_test_2_error \n\t"
448 " cmpi.l #110, d0 \n\t"
449 " bne reg_test_2_error \n\t"
451 " cmpi.l #120, d0 \n\t"
452 " bne reg_test_2_error \n\t"
454 " cmpi.l #130, d0 \n\t"
455 " bne reg_test_2_error \n\t"
457 " cmpi.l #140, d0 \n\t"
458 " bne reg_test_2_error \n\t"
460 " cmpi.l #150, d0 \n\t"
461 " bne reg_test_2_error \n\t"
462 " move ulRegTest1Counter, d0 \n\t"
464 " move d0, ulRegTest2Counter \n\t"
465 " bra reg_test_2_start \n\t"
466 "reg_test_2_error: \n\t"
467 " bra reg_test_2_error \n\t"
470 /*-----------------------------------------------------------*/