]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5/main_full.c
Update version numbers ready for release.
[freertos] / FreeRTOS / Demo / CORTEX_R4_RM48_TMS570_CCS5 / main_full.c
1 /*\r
2  * FreeRTOS Kernel V10.1.1\r
3  * Copyright (C) 2018 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  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
30  * project, and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
32  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
33  * in main.c.  This file implements the comprehensive test and demo version.\r
34  *\r
35  * NOTE 2:  This file only contains the source code that is specific to the\r
36  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
37  * required to configure the hardware, are defined in main.c.\r
38  ******************************************************************************\r
39  *\r
40  * main_full() creates all the demo application tasks and software timers,\r
41  * then starts the scheduler.  The web documentation provides more details of\r
42  * the standard demo application tasks, which provide no particular\r
43  * functionality, but do provide a good example of how to use the FreeRTOS API.\r
44  *\r
45  * In addition to the standard demo tasks, the following tasks and tests are\r
46  * defined and/or created within this file:\r
47  *\r
48  * "Check" timer - The check software timer period is set to three seconds.\r
49  * The callback function associated with the check software timer checks that\r
50  * all the standard demo tasks are not only still executing, but are executing\r
51  * without reporting any errors.  If the check software timer discovers that a\r
52  * task has either stalled, or reported an error, then the error is logged and\r
53  * the check software timer toggles the red LEDs.  If an error has never been\r
54  * latched, the check software timer toggles the green LEDs.  Therefore, if the\r
55  * system is executing correctly, the green LEDs will toggle every three\r
56  * seconds, and if an error has ever been detected, the red LEDs will toggle\r
57  * every three seconds.\r
58  *\r
59  * "Reg test" tasks - These fill both the core and floating point registers\r
60  * with known values, then check that each register maintains its expected\r
61  * value for the lifetime of the tasks.  Each task uses a different set of\r
62  * values.  The reg test tasks execute with a very low priority, so get\r
63  * preempted very frequently.  A register containing an unexpected value is\r
64  * indicative of an error in the context switching mechanism.\r
65  *\r
66  * "LED" software timer - The callback function associated with the LED\r
67  * software time maintains a pattern of spinning white LEDs.\r
68  *\r
69  * See the documentation page for this demo on the FreeRTOS.org web site for\r
70  * full information, including hardware setup requirements.\r
71  */\r
72 \r
73 /* Standard includes. */\r
74 #include <stdio.h>\r
75 \r
76 /* Kernel includes. */\r
77 #include "FreeRTOS.h"\r
78 #include "task.h"\r
79 #include "timers.h"\r
80 #include "semphr.h"\r
81 \r
82 /* Standard demo application includes. */\r
83 #include "integer.h"\r
84 #include "PollQ.h"\r
85 #include "semtest.h"\r
86 #include "dynamic.h"\r
87 #include "BlockQ.h"\r
88 #include "blocktim.h"\r
89 #include "countsem.h"\r
90 #include "GenQTest.h"\r
91 #include "recmutex.h"\r
92 #include "death.h"\r
93 #include "partest.h"\r
94 #include "flop.h"\r
95 #include "serial.h"\r
96 #include "comtest.h"\r
97 \r
98 /* Priorities for the demo application tasks. */\r
99 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
100 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
101 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
102 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
103 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
104 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
105 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
106 \r
107 /* A block time of zero simply means "don't block". */\r
108 #define mainDONT_BLOCK                                          ( 0UL )\r
109 \r
110 /* The period after which the check timer will expire, converted to ticks. */\r
111 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
112 \r
113 /* The period after which the LED timer will expire, converted to ticks. */\r
114 #define mainLED_TIMER_PERIOD_MS                         ( 75UL / portTICK_PERIOD_MS )\r
115 \r
116 /* Constants for the ComTest tasks. */\r
117 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned long ) 19200 )\r
118 #define mainCOM_TEST_LED                                        ( 100 )\r
119 \r
120 /*-----------------------------------------------------------*/\r
121 \r
122 /*\r
123  * The check timer callback function, as described at the top of this file.\r
124  */\r
125 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
126 \r
127 /*\r
128  * The LED timer callback function, as described at the top of this file.\r
129  */\r
130 static void prvLEDTimerCallback( TimerHandle_t xTimer );\r
131 \r
132 /*\r
133  * The reg test tasks, as described at the top of this file.\r
134  */\r
135 extern void vRegTestTask1( void *pvParameters );\r
136 extern void vRegTestTask2( void *pvParameters );\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 /* Variables that are incremented on each iteration of the reg test tasks -\r
141 provided the tasks have not reported any errors.  The check task inspects these\r
142 variables to ensure they are still incrementing as expected.  If a variable\r
143 stops incrementing then it is likely that its associate task has stalled. */\r
144 volatile unsigned long ulRegTest1Counter = 0, ulRegTest2Counter = 0;\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 void main_full( void )\r
149 {\r
150 TimerHandle_t xTimer = NULL;\r
151 \r
152         /* Start all the standard demo/test tasks.  These have not particular\r
153         functionality, but do demonstrate how to use the FreeRTOS API, and test the\r
154         kernel port. */\r
155         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
156         vStartDynamicPriorityTasks();\r
157         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
158         vCreateBlockTimeTasks();\r
159         vStartCountingSemaphoreTasks();\r
160         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
161         vStartRecursiveMutexTasks();\r
162         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
163         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
164         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
165         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
166 \r
167         /* Create the register test tasks, as described at the top of this file. */\r
168         xTaskCreate( vRegTestTask1, "Reg1...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
169         xTaskCreate( vRegTestTask2, "Reg2...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
170 \r
171 \r
172         /* Create the software timer that performs the 'check' functionality,\r
173         as described at the top of this file. */\r
174         xTimer = xTimerCreate( "CheckTimer",                                    /* A text name, purely to help debugging. */\r
175                                                         ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
176                                                         pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
177                                                         ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
178                                                         prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
179                                                  );\r
180 \r
181         if( xTimer != NULL )\r
182         {\r
183                 xTimerStart( xTimer, mainDONT_BLOCK );\r
184         }\r
185 \r
186         /* Create the software timer that performs the 'LED spin' functionality,\r
187         as described at the top of this file. */\r
188         xTimer = xTimerCreate( "LEDTimer",                                      /* A text name, purely to help debugging. */\r
189                                                         ( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 75ms. */\r
190                                                         pdTRUE,                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
191                                                         ( void * ) 0,                           /* The ID is not used, so can be set to anything. */\r
192                                                         prvLEDTimerCallback                     /* The callback function that toggles the white LEDs. */\r
193                                                  );\r
194 \r
195         if( xTimer != NULL )\r
196         {\r
197                 xTimerStart( xTimer, mainDONT_BLOCK );\r
198         }\r
199 \r
200         /* The set of tasks created by the following function call have to be\r
201         created last as they keep account of the number of tasks they expect to see\r
202         running. */\r
203         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
204 \r
205         /* Start the scheduler. */\r
206         vTaskStartScheduler();\r
207 \r
208         /* If all is well, the scheduler will now be running, and the following line\r
209         will never be reached.  If the following line does execute, then there was\r
210         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
211         to be created.  See the memory management section on the FreeRTOS web site\r
212         for more details. */\r
213         for( ;; );\r
214 }\r
215 /*-----------------------------------------------------------*/\r
216 \r
217 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
218 {\r
219 static long lChangeToRedLEDsAlready = pdFALSE;\r
220 static unsigned long ulLastRegTest1Counter = 0, ulLastRegTest2Counter = 0;\r
221 unsigned long ulErrorFound = pdFALSE;\r
222 /* LEDs are defaulted to use the Green LEDs.  The Red LEDs are used if an error\r
223 is found. */\r
224 static unsigned long ulLED1 = 8, ulLED2 = 11;\r
225 const unsigned long ulRedLED1 = 6, ulRedLED2 = 9;\r
226 \r
227         /* Check all the demo tasks (other than the flash tasks) to ensure\r
228         they are all still running, and that none have detected an error. */\r
229 \r
230         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
231         {\r
232                 ulErrorFound = pdTRUE;\r
233         }\r
234 \r
235         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
236         {\r
237                 ulErrorFound = pdTRUE;\r
238         }\r
239 \r
240         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
241         {\r
242                 ulErrorFound = pdTRUE;\r
243         }\r
244 \r
245         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
246         {\r
247                 ulErrorFound = pdTRUE;\r
248         }\r
249 \r
250         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
251         {\r
252                 ulErrorFound = pdTRUE;\r
253         }\r
254 \r
255         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
256         {\r
257                 ulErrorFound = pdTRUE;\r
258         }\r
259 \r
260         if( xIsCreateTaskStillRunning() != pdTRUE )\r
261         {\r
262                 ulErrorFound = pdTRUE;\r
263         }\r
264 \r
265         if( xArePollingQueuesStillRunning() != pdTRUE )\r
266         {\r
267                 ulErrorFound = pdTRUE;\r
268         }\r
269 \r
270         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
271         {\r
272                 ulErrorFound = pdTRUE;\r
273         }\r
274 \r
275         if( xAreMathsTaskStillRunning() != pdTRUE )\r
276         {\r
277                 ulErrorFound = pdTRUE;\r
278         }\r
279 \r
280         if( xAreComTestTasksStillRunning() != pdTRUE )\r
281         {\r
282                 ulErrorFound = pdTRUE;\r
283         }\r
284 \r
285         /* Check the reg test tasks are still cycling.  They will stop\r
286         incrementing their loop counters if they encounter an error. */\r
287         if( ulRegTest1Counter == ulLastRegTest1Counter )\r
288         {\r
289                 ulErrorFound = pdTRUE;\r
290         }\r
291 \r
292         if( ulRegTest2Counter == ulLastRegTest2Counter )\r
293         {\r
294                 ulErrorFound = pdTRUE;\r
295         }\r
296 \r
297         ulLastRegTest1Counter = ulRegTest1Counter;\r
298         ulLastRegTest2Counter = ulRegTest2Counter;\r
299 \r
300         /* Toggle the check LEDs to give an indication of the system status.  If\r
301         the green LEDs are toggling, then no errors have been detected.  If the red\r
302         LEDs are toggling, then an error has been reported in at least one task. */\r
303         vParTestToggleLED( ulLED1 );\r
304         vParTestToggleLED( ulLED2 );\r
305 \r
306         /* Have any errors been latch in ulErrorFound?  If so, ensure the gree LEDs\r
307         are off, then switch to using the red LEDs. */\r
308         if( ulErrorFound != pdFALSE )\r
309         {\r
310                 if( lChangeToRedLEDsAlready == pdFALSE )\r
311                 {\r
312                         lChangeToRedLEDsAlready = pdTRUE;\r
313 \r
314                         /* An error has been found.  Switch to use the red LEDs. */\r
315                         vParTestSetLED( ulLED1, pdFALSE );\r
316                         vParTestSetLED( ulLED2, pdFALSE );\r
317                         ulLED1 = ulRedLED1;\r
318                         ulLED2 = ulRedLED2;\r
319                 }\r
320         }\r
321 }\r
322 /*-----------------------------------------------------------*/\r
323 \r
324 static void prvLEDTimerCallback( TimerHandle_t xTimer )\r
325 {\r
326 const unsigned long ulNumWhiteLEDs = 6;\r
327 static unsigned long ulLit1 = 2, ulLit2 = 1;\r
328 \r
329         vParTestSetLED( ulLit2, pdFALSE );\r
330 \r
331         ulLit2 = ulLit1;\r
332         ulLit1++;\r
333 \r
334         if( ulLit1 >= ulNumWhiteLEDs )\r
335         {\r
336                 ulLit1 = 0;\r
337         }\r
338 \r
339         vParTestSetLED( ulLit1, pdTRUE );\r
340 }\r
341 /*-----------------------------------------------------------*/\r
342 \r