2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
30 * documentation provides more details of the standard demo application tasks.
\r
32 * A "Check" task is created in addition to the standard demo tasks. This
\r
33 * only executes every three seconds but has a high priority to ensure it gets
\r
34 * processor time. Its main function is to check that all the standard demo
\r
35 * tasks are still operational. If everything is running as expected then the
\r
36 * check task will toggle an LED every 3 seconds. An error being discovered in
\r
37 * any task will cause the toggle rate to increase to 500ms.
\r
41 /* FreeRTOS includes. */
\r
42 #include "FreeRTOS.h"
\r
45 /* Standard demo includes. */
\r
47 #include "blocktim.h"
\r
48 #include "countsem.h"
\r
50 #include "dynamic.h"
\r
51 #include "GenQTest.h"
\r
52 #include "integer.h"
\r
55 #include "recmutex.h"
\r
56 #include "semtest.h"
\r
57 #include "ParTest.h"
\r
58 #include "comtest2.h"
\r
60 /* Standard includes. */
\r
63 /* Atmel library includes. */
\r
64 #include <pio/pio.h>
\r
66 /* Priorities for the demo application tasks. */
\r
67 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
68 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
69 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
70 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
71 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
72 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
73 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
75 /* The period of the check task both in and out of the presense of an error. */
\r
76 #define mainNO_ERROR_PERIOD ( 5000 / portTICK_PERIOD_MS )
\r
77 #define mainERROR_PERIOD ( 500 / portTICK_PERIOD_MS );
\r
79 /* Constants used by the ComTest task. */
\r
80 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
81 #define mainCOM_TEST_LED ( LED_DS1 )
\r
83 /*-----------------------------------------------------------*/
\r
85 /* Simple hardware setup required by the demo. */
\r
86 static void prvSetupHardware( void );
\r
88 /* The check task as described at the top of this file. */
\r
89 static void prvCheckTask( void *pvParameters );
\r
91 /*-----------------------------------------------------------*/
\r
94 /* Perform any hardware setup necessary to run the demo. */
\r
97 /* First create the 'standard demo' tasks. These exist just to to
\r
98 demonstrate API functions being used and test the kernel port. More
\r
99 information is provided on the FreeRTOS.org WEB site. */
\r
100 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
101 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
102 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
103 vStartDynamicPriorityTasks();
\r
104 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
105 vCreateBlockTimeTasks();
\r
106 vStartCountingSemaphoreTasks();
\r
107 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
108 vStartQueuePeekTasks();
\r
109 vStartRecursiveMutexTasks();
\r
110 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
112 /* Create the check task - this is the task that checks all the other tasks
\r
113 are executing as expected and without reporting any errors. */
\r
114 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
\r
116 /* The death demo tasks must be started last as the sanity checks performed
\r
117 require knowledge of the number of other tasks in the system. */
\r
118 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
120 /* Start the scheduler. From this point on the execution will be under
\r
121 the control of the kernel. */
\r
122 vTaskStartScheduler();
\r
124 /* Will only get here if there was insufficient heap availale for the
\r
125 idle task to be created. */
\r
128 /*-----------------------------------------------------------*/
\r
130 static void prvCheckTask( void * pvParameters )
\r
132 TickType_t xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;
\r
133 static volatile unsigned long ulErrorCode = 0UL;
\r
135 /* Just to remove the compiler warning. */
\r
136 ( void ) pvParameters;
\r
138 /* Initialise xNextWakeTime prior to its first use. From this point on
\r
139 the value of the variable is handled automatically by the kernel. */
\r
140 xNextWakeTime = xTaskGetTickCount();
\r
144 /* Delay until it is time for this task to execute again. */
\r
145 vTaskDelayUntil( &xNextWakeTime, xPeriod );
\r
147 /* Check all the other tasks in the system - latch any reported errors
\r
148 into the ulErrorCode variable. */
\r
149 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
151 ulErrorCode |= 0x01UL;
\r
154 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
156 ulErrorCode |= 0x02UL;
\r
159 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
161 ulErrorCode |= 0x04UL;
\r
164 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
166 ulErrorCode |= 0x08UL;
\r
169 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
171 ulErrorCode |= 0x10UL;
\r
174 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
176 ulErrorCode |= 0x20UL;
\r
179 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
181 ulErrorCode |= 0x40UL;
\r
184 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
186 ulErrorCode |= 0x80UL;
\r
189 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
191 ulErrorCode |= 0x100UL;
\r
194 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
196 ulErrorCode |= 0x200UL;
\r
199 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
201 ulErrorCode |= 0x400UL;
\r
204 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
206 ulErrorCode |= 0x800UL;
\r
209 /* Reduce the block period and in so doing increase the frequency at
\r
210 which this task executes if any errors have been latched. The increased
\r
211 frequency causes the LED toggle rate to increase and so gives some
\r
212 visual feedback that an error has occurred. */
\r
213 if( ulErrorCode != 0x00 )
\r
215 xPeriod = mainERROR_PERIOD;
\r
218 /* Finally toggle the LED. */
\r
219 vParTestToggleLED( LED_POWER );
\r
222 /*-----------------------------------------------------------*/
\r
224 static void prvSetupHardware( void )
\r
226 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };
\r
228 /* Setup the LED outputs. */
\r
229 vParTestInitialise();
\r
231 /* Setup the pins for the UART. */
\r
232 PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );
\r