2 * FreeRTOS Kernel V10.2.1
3 * Copyright (C) 2019 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
29 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
30 The processor MUST be in supervisor mode when vTaskStartScheduler is
31 called. The demo applications included in the FreeRTOS.org download switch
32 to supervisor mode prior to main being called. If you are not using one of
33 these demo application projects then ensure Supervisor mode is used.
37 * Creates all the demo application tasks, then starts the scheduler. The WEB
38 * documentation provides more details of the demo application tasks.
40 * Main.c also creates a task called "Check". This only executes every three
41 * seconds but has the highest priority so is guaranteed to get processor time.
42 * Its main function is to check that all the other tasks are still operational.
43 * Each task (other than the "flash" tasks) maintains a unique count that is
44 * incremented each time the task successfully completes its function. Should
45 * any error occur within such a task the count is permanently halted. The
46 * check task inspects the count of each task to ensure it has changed since
47 * the last time the check task executed. If all the count variables have
48 * changed all the tasks are still executing error free, and the check task
49 * toggles the onboard LED. Should any task contain an error at any time
50 * the LED toggle rate will change from 3 seconds to 500ms.
54 /* Library includes. */
58 /* Scheduler includes. */
62 /* Demo application includes. */
72 /* Priorities for the demo application tasks. */
73 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
74 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
75 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
76 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
77 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
78 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
80 /* Constants required by the 'Check' task. */
81 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
82 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
83 #define mainCHECK_TASK_LED ( 4 )
85 /* Constants for the ComTest tasks. */
86 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
87 #define mainCOM_TEST_LED ( 6 ) /* The LED built onto the kickstart board. */
90 * The task that executes at the highest priority and calls
91 * prvCheckOtherTasksAreStillRunning(). See the description at the top
94 static void vErrorChecks( void *pvParameters );
97 * Configure the processor for use with the IAR STR71x demo board. This
98 * just sets the PLL for the required frequency.
100 static void prvSetupHardware( void );
103 * Checks that all the demo application tasks are still executing without error
104 * - as described at the top of the file. Called by vErrorChecks().
106 static long prvCheckOtherTasksAreStillRunning( void );
109 /*-----------------------------------------------------------*/
112 * Starts all the other tasks, then starts the scheduler.
116 /* Setup any hardware that has not already been configured by the low
117 level init routines. */
120 /* Initialise the LED outputs for use by the demo application tasks. */
121 vParTestInitialise();
123 /* Start all the standard demo application tasks. */
124 vStartIntegerMathTasks( tskIDLE_PRIORITY );
125 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
126 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
127 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
128 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
129 vStartDynamicPriorityTasks();
130 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
132 /* Start the check task - which is defined in this file. */
133 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
135 /* Start the scheduler.
137 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
138 The processor MUST be in supervisor mode when vTaskStartScheduler is
139 called. The demo applications included in the FreeRTOS.org download switch
140 to supervisor mode prior to main being called. If you are not using one of
141 these demo application projects then ensure Supervisor mode is used here. */
143 vTaskStartScheduler();
145 /* We should never get here as control is now taken by the scheduler. */
148 /*-----------------------------------------------------------*/
150 static void prvSetupHardware( void )
152 /* Setup the PLL to generate a 48MHz clock from the 4MHz CLK. */
154 /* Turn of the div by two. */
155 RCCU_Div2Config( DISABLE );
157 /* 48MHz = ( 4MHz * 12 ) / 1 */
158 RCCU_PLL1Config( RCCU_PLL1_Mul_12, RCCU_Div_1 );
159 RCCU_RCLKSourceConfig( RCCU_PLL1_Output );
161 /*-----------------------------------------------------------*/
163 static void vErrorChecks( void *pvParameters )
165 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
166 TickType_t xLastWakeTime;
168 /* The parameters are not used in this task. */
169 ( void ) pvParameters;
171 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
172 functions correctly. */
173 xLastWakeTime = xTaskGetTickCount();
175 /* Cycle for ever, delaying then checking all the other tasks are still
176 operating without error. If an error is detected then the delay period
177 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
178 the on board LED flash rate will increase. */
182 /* Delay until it is time to execute again. The delay period is
183 shorter following an error so the LED flashes faster. */
184 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
186 /* Check all the standard demo application tasks are executing without
188 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
190 /* An error has been detected in one of the tasks - flash faster. */
191 xDelayPeriod = mainERROR_FLASH_PERIOD;
194 vParTestToggleLED( mainCHECK_TASK_LED );
197 /*-----------------------------------------------------------*/
199 static long prvCheckOtherTasksAreStillRunning( void )
201 long lReturn = ( long ) pdPASS;
203 /* Check all the demo tasks (other than the flash tasks) to ensure
204 that they are all still running, and that none of them have detected
207 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
209 lReturn = ( long ) pdFAIL;
212 if( xArePollingQueuesStillRunning() != pdTRUE )
214 lReturn = ( long ) pdFAIL;
217 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
219 lReturn = ( long ) pdFAIL;
222 if( xAreBlockingQueuesStillRunning() != pdTRUE )
224 lReturn = ( long ) pdFAIL;
227 if( xAreComTestTasksStillRunning() != pdTRUE )
229 lReturn = ( long ) pdFAIL;
232 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
234 lReturn = ( long ) pdFAIL;
239 /*-----------------------------------------------------------*/