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.
\r
31 * Main.c also creates a task called "Check". This only executes every three
\r
32 * seconds but has the highest priority so is guaranteed to get processor time.
\r
33 * Its main function is to check that all the other tasks are still operational.
\r
34 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
35 * incremented each time the task successfully completes its function. Should
\r
36 * any error occur within such a task the count is permanently halted. The
\r
37 * check task inspects the count of each task to ensure it has changed since
\r
38 * the last time the check task executed. If all the count variables have
\r
39 * changed all the tasks are still executing error free, and the check task
\r
40 * toggles the on board LED. Should any task contain an error at any time
\r
41 * the LED toggle rate will change from 3 seconds to 500ms.
\r
43 * NOTE: The demo application includes tasks that send and receive characters
\r
44 * over the UART. The characters sent by one task are received by another -
\r
45 * with an error condition being flagged should any characters be missed or
\r
46 * received out of order. A loopback connector is required on the 9way D socket
\r
47 * for this mechanism to operation (pins 2 and 3 the socket should be connected
\r
48 * together - a paper clip is normally sufficient).
\r
52 /* Standard includes. */
\r
56 /* Scheduler includes. */
\r
57 #include "FreeRTOS.h"
\r
60 /* Demo application includes. */
\r
61 #include "partest.h"
\r
63 #include "integer.h"
\r
65 #include "comtest2.h"
\r
66 #include "semtest.h"
\r
68 #include "dynamic.h"
\r
71 #include "demoGpio.h"
\r
73 #include "RegTest.h"
\r
75 /*-----------------------------------------------------------*/
\r
77 /* Constants for the ComTest tasks. */
\r
78 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
79 #define mainCOM_TEST_LED ( 5 )
\r
81 /* Priorities for the demo application tasks. */
\r
82 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
83 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
84 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
85 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
86 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
87 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
88 #define main7SEG_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
90 /* The rate at which the on board LED will toggle when there is/is not an
\r
92 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
93 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
94 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 )
\r
96 /* The size of the memory blocks allocated by the vMemCheckTask() task. */
\r
97 #define mainMEM_CHECK_SIZE_1 ( ( size_t ) 51 )
\r
98 #define mainMEM_CHECK_SIZE_2 ( ( size_t ) 52 )
\r
99 #define mainMEM_CHECK_SIZE_3 ( ( size_t ) 151 )
\r
101 /*-----------------------------------------------------------*/
\r
104 * Checks that all the demo application tasks are still executing without error
\r
105 * - as described at the top of the file.
\r
107 static long prvCheckOtherTasksAreStillRunning( void );
\r
110 * The task that executes at the highest priority and calls
\r
111 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
114 static void vErrorChecks( void *pvParameters );
\r
117 * Configure the processor for use with the Olimex demo board. This includes
\r
118 * setup for the I/O, system clock, and access timings.
\r
120 static void prvSetupHardware( void );
\r
123 /*-----------------------------------------------------------*/
\r
126 * Starts all the other tasks, then starts the scheduler.
\r
130 /* Setup the hardware for use with the Xilinx evaluation board. */
\r
131 prvSetupHardware();
\r
133 /* Start the demo/test application tasks. */
\r
134 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
135 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
136 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
137 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
138 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
139 vStartDynamicPriorityTasks();
\r
140 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
141 vStart7SegTasks( main7SEG_TASK_PRIORITY );
\r
142 vStartRegTestTasks();
\r
144 /* Start the check task - which is defined in this file. */
\r
145 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
147 /* Now all the tasks have been started - start the scheduler. */
\r
148 vTaskStartScheduler();
\r
150 /* Should never reach here! */
\r
153 /*-----------------------------------------------------------*/
\r
155 static void vErrorChecks( void *pvParameters )
\r
157 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
159 /* Just to stop compiler warnings. */
\r
160 ( void ) pvParameters;
\r
162 /* Cycle for ever, delaying then checking all the other tasks are still
\r
163 operating without error. If an error is detected then the delay period
\r
164 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
165 the on board LED flash rate will increase. */
\r
169 /* Delay until it is time to execute again. */
\r
170 vTaskDelay( xDelayPeriod );
\r
172 /* Check all the standard demo application tasks are executing without
\r
174 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
176 /* An error has been detected in one of the tasks - flash faster. */
\r
177 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
180 /* The toggle rate of the LED depends on how long this task delays for.
\r
181 An error reduces the delay period and so increases the toggle rate. */
\r
182 vParTestToggleLED( mainON_BOARD_LED_BIT );
\r
185 /*-----------------------------------------------------------*/
\r
187 static void prvSetupHardware( void )
\r
189 /* Initialise LED outputs. */
\r
190 vParTestInitialise();
\r
192 /*-----------------------------------------------------------*/
\r
194 static long prvCheckOtherTasksAreStillRunning( void )
\r
196 long lReturn = pdPASS;
\r
198 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
199 that they are all still running, and that none of them have detected
\r
202 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
207 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
212 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
217 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
222 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
227 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
232 if( xAreRegTestTasksStillRunning() != pdTRUE )
\r
239 /*-----------------------------------------------------------*/
\r
241 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
243 /* This function will be called if a task overflows its stack. Inspect
\r
244 pxCurrentTCB to find the offending task if the overflow was sever enough
\r
245 to corrupt the pcTaskName parameter. */
\r
246 vParTestSetLED( 4, 1 );
\r
249 /*-----------------------------------------------------------*/
\r
251 void vApplicationMallocFailedHook( void )
\r
253 /* This function will be called if a call to pvPortMalloc() fails to return
\r
254 the requested memory. pvPortMalloc() is called internally by the scheduler
\r
255 whenever a task, queue or semaphore is created. */
\r
256 vParTestSetLED( 4, 1 );
\r
259 /*-----------------------------------------------------------*/
\r
261 /* Provide an exit function to prevent a whole load of standard library functions
\r
262 being brought into the build. */
\r
263 void exit( int status )
\r