]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTUS_APS3_GCC/Demo/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTUS_APS3_GCC / Demo / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Creates all the demo application tasks, then starts the scheduler.\r
30  *\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
42  *\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
49  *\r
50  */\r
51 \r
52 /* Standard includes. */\r
53 #include <stdlib.h>\r
54 #include <string.h>\r
55 \r
56 /* Scheduler includes. */\r
57 #include "FreeRTOS.h"\r
58 #include "task.h"\r
59 \r
60 /* Demo application includes. */\r
61 #include "partest.h"\r
62 #include "flash.h"\r
63 #include "integer.h"\r
64 #include "PollQ.h"\r
65 #include "comtest2.h"\r
66 #include "semtest.h"\r
67 #include "flop.h"\r
68 #include "dynamic.h"\r
69 #include "BlockQ.h"\r
70 #include "serial.h"\r
71 #include "demoGpio.h"\r
72 #include "7seg.h"\r
73 #include "RegTest.h"\r
74 \r
75 /*-----------------------------------------------------------*/\r
76 \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
80 \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
89 \r
90 /* The rate at which the on board LED will toggle when there is/is not an\r
91 error. */\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
95 \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
100 \r
101 /*-----------------------------------------------------------*/\r
102 \r
103 /*\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
106  */\r
107 static long prvCheckOtherTasksAreStillRunning( void );\r
108 \r
109 /*\r
110  * The task that executes at the highest priority and calls\r
111  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
112  * of the file.\r
113  */\r
114 static void vErrorChecks( void *pvParameters );\r
115 \r
116 /*\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
119  */\r
120 static void prvSetupHardware( void );\r
121 \r
122 \r
123 /*-----------------------------------------------------------*/\r
124 \r
125 /*\r
126  * Starts all the other tasks, then starts the scheduler.\r
127  */\r
128 int main( void )\r
129 {\r
130         /* Setup the hardware for use with the Xilinx evaluation board. */\r
131         prvSetupHardware();\r
132 \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
143 \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
146 \r
147         /* Now all the tasks have been started - start the scheduler. */\r
148         vTaskStartScheduler();\r
149 \r
150         /* Should never reach here! */\r
151         for( ;; );\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 static void vErrorChecks( void *pvParameters )\r
156 {\r
157 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
158 \r
159         /* Just to stop compiler warnings. */\r
160         ( void ) pvParameters;\r
161 \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
166 \r
167         for( ;; )\r
168         {\r
169                 /* Delay until it is time to execute again. */\r
170                 vTaskDelay( xDelayPeriod );\r
171 \r
172                 /* Check all the standard demo application tasks are executing without\r
173                 error.  */\r
174                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
175                 {\r
176                         /* An error has been detected in one of the tasks - flash faster. */\r
177                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
178                 }\r
179 \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
183         }\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void prvSetupHardware( void )\r
188 {\r
189         /* Initialise LED outputs. */\r
190         vParTestInitialise();\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 static long prvCheckOtherTasksAreStillRunning( void )\r
195 {\r
196 long lReturn = pdPASS;\r
197 \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
200         an error. */\r
201 \r
202         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
203         {\r
204                 lReturn = pdFAIL;\r
205         }\r
206 \r
207         if( xAreComTestTasksStillRunning() != pdTRUE )\r
208         {\r
209                 lReturn = pdFAIL;\r
210         }\r
211 \r
212         if( xArePollingQueuesStillRunning() != pdTRUE )\r
213         {\r
214                 lReturn = pdFAIL;\r
215         }\r
216 \r
217         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
218         {\r
219                 lReturn = pdFAIL;\r
220         }\r
221 \r
222         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
223         {\r
224                 lReturn = pdFAIL;\r
225         }\r
226 \r
227         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
228         {\r
229                 lReturn = pdFAIL;\r
230         }\r
231 \r
232         if( xAreRegTestTasksStillRunning() != pdTRUE )\r
233         {\r
234                 lReturn = pdFAIL;\r
235         }\r
236 \r
237         return lReturn;\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
242 {\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
247         for( ;; );\r
248 }\r
249 /*-----------------------------------------------------------*/\r
250 \r
251 void vApplicationMallocFailedHook( void )\r
252 {\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
257         for( ;; );\r
258 }\r
259 /*-----------------------------------------------------------*/\r
260 \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
264 {\r
265         for( ;; );\r
266 }\r
267 \r
268 \r