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
30 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
31 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
32 called. The demo applications included in the FreeRTOS.org download switch
\r
33 to supervisor mode prior to main being called. If you are not using one of
\r
34 these demo application projects then ensure Supervisor mode is used.
\r
38 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
39 * documentation provides more details of the demo application tasks.
\r
41 * Main.c also creates a task called "Check". This only executes every three
\r
42 * seconds but has the highest priority so is guaranteed to get processor time.
\r
43 * Its main function is to check that all the other tasks are still operational.
\r
44 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
45 * incremented each time the task successfully completes its function. Should
\r
46 * any error occur within such a task the count is permanently halted. The
\r
47 * check task inspects the count of each task to ensure it has changed since
\r
48 * the last time the check task executed. If all the count variables have
\r
49 * changed all the tasks are still executing error free, and the check task
\r
50 * toggles the onboard LED. Should any task contain an error at any time
\r
51 * the LED toggle rate will change from 3 seconds to 500ms.
\r
55 /* Library includes. */
\r
59 /* Scheduler includes. */
\r
60 #include "FreeRTOS.h"
\r
63 /* Demo application includes. */
\r
65 #include "integer.h"
\r
68 #include "semtest.h"
\r
69 #include "dynamic.h"
\r
70 #include "partest.h"
\r
71 #include "comtest2.h"
\r
73 /* Priorities for the demo application tasks. */
\r
74 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
75 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
76 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
77 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
78 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
79 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
81 /* Constants required by the 'Check' task. */
\r
82 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
83 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
84 #define mainCHECK_TASK_LED ( 4 )
\r
86 /* Constants for the ComTest tasks. */
\r
87 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
88 #define mainCOM_TEST_LED ( 6 ) /* The LED built onto the kickstart board. */
\r
91 * The task that executes at the highest priority and calls
\r
92 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
95 static void vErrorChecks( void *pvParameters );
\r
98 * Configure the processor for use with the IAR STR71x demo board. This
\r
99 * just sets the PLL for the required frequency.
\r
101 static void prvSetupHardware( void );
\r
104 * Checks that all the demo application tasks are still executing without error
\r
105 * - as described at the top of the file. Called by vErrorChecks().
\r
107 static long prvCheckOtherTasksAreStillRunning( void );
\r
110 /*-----------------------------------------------------------*/
\r
113 * Starts all the other tasks, then starts the scheduler.
\r
117 /* Setup any hardware that has not already been configured by the low
\r
118 level init routines. */
\r
119 prvSetupHardware();
\r
121 /* Initialise the LED outputs for use by the demo application tasks. */
\r
122 vParTestInitialise();
\r
124 /* Start all the standard demo application tasks. */
\r
125 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
126 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
127 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
128 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
129 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
130 vStartDynamicPriorityTasks();
\r
131 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
133 /* Start the check task - which is defined in this file. */
\r
134 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
136 /* Start the scheduler.
\r
138 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
139 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
140 called. The demo applications included in the FreeRTOS.org download switch
\r
141 to supervisor mode prior to main being called. If you are not using one of
\r
142 these demo application projects then ensure Supervisor mode is used here. */
\r
144 vTaskStartScheduler();
\r
146 /* We should never get here as control is now taken by the scheduler. */
\r
149 /*-----------------------------------------------------------*/
\r
151 static void prvSetupHardware( void )
\r
153 /* Setup the PLL to generate a 48MHz clock from the 4MHz CLK. */
\r
155 /* Turn of the div by two. */
\r
156 RCCU_Div2Config( DISABLE );
\r
158 /* 48MHz = ( 4MHz * 12 ) / 1 */
\r
159 RCCU_PLL1Config( RCCU_PLL1_Mul_12, RCCU_Div_1 );
\r
160 RCCU_RCLKSourceConfig( RCCU_PLL1_Output );
\r
162 /*-----------------------------------------------------------*/
\r
164 static void vErrorChecks( void *pvParameters )
\r
166 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
167 TickType_t xLastWakeTime;
\r
169 /* The parameters are not used in this task. */
\r
170 ( void ) pvParameters;
\r
172 /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()
\r
173 functions correctly. */
\r
174 xLastWakeTime = xTaskGetTickCount();
\r
176 /* Cycle for ever, delaying then checking all the other tasks are still
\r
177 operating without error. If an error is detected then the delay period
\r
178 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
179 the on board LED flash rate will increase. */
\r
183 /* Delay until it is time to execute again. The delay period is
\r
184 shorter following an error so the LED flashes faster. */
\r
185 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
\r
187 /* Check all the standard demo application tasks are executing without
\r
189 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
191 /* An error has been detected in one of the tasks - flash faster. */
\r
192 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
195 vParTestToggleLED( mainCHECK_TASK_LED );
\r
198 /*-----------------------------------------------------------*/
\r
200 static long prvCheckOtherTasksAreStillRunning( void )
\r
202 long lReturn = ( long ) pdPASS;
\r
204 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
205 that they are all still running, and that none of them have detected
\r
208 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
210 lReturn = ( long ) pdFAIL;
\r
213 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
215 lReturn = ( long ) pdFAIL;
\r
218 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
220 lReturn = ( long ) pdFAIL;
\r
223 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
225 lReturn = ( long ) pdFAIL;
\r
228 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
230 lReturn = ( long ) pdFAIL;
\r
233 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
235 lReturn = ( long ) pdFAIL;
\r
240 /*-----------------------------------------------------------*/
\r