]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_IAR/main_full.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_M4F_Infineon_XMC4000_IAR / main_full.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  * 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 a software timer, then\r
41  * starts the scheduler.  The web documentation provides more details of the\r
42  * standard demo application tasks, which provide no particular functionality,\r
43  * 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  * "Reg test" tasks - These fill both the core and floating point registers with\r
49  * known values, then check that each register maintains its expected value for\r
50  * the lifetime of the task.  Each task uses a different set of values.  The reg\r
51  * test tasks execute with a very low priority, so get preempted very\r
52  * frequently.  A register containing an unexpected value is indicative of an\r
53  * error in the context switching mechanism.\r
54  *\r
55  * "Check" timer - The check software timer period is initially set to three\r
56  * seconds.  The callback function associated with the check software timer\r
57  * checks that all the standard demo tasks, and the register check tasks, are\r
58  * not only still executing, but are executing without reporting any errors.  If\r
59  * the check software timer discovers that a task has either stalled, or\r
60  * reported an error, then it changes its own execution period from the initial\r
61  * three seconds, to just 200ms.  The check software timer callback function\r
62  * also toggles the single LED each time it is called.  This provides a visual\r
63  * indication of the system status:  If the LED toggles every three seconds,\r
64  * then no issues have been discovered.  If the LED toggles every 200ms, then\r
65  * an issue has been discovered with at least one task.\r
66  */\r
67 \r
68 /* Standard includes. */\r
69 #include <stdio.h>\r
70 \r
71 /* Kernel includes. */\r
72 #include "FreeRTOS.h"\r
73 #include "task.h"\r
74 #include "timers.h"\r
75 #include "semphr.h"\r
76 \r
77 /* Standard demo application includes. */\r
78 #include "flop.h"\r
79 #include "semtest.h"\r
80 #include "dynamic.h"\r
81 #include "blocktim.h"\r
82 #include "countsem.h"\r
83 #include "GenQTest.h"\r
84 #include "recmutex.h"\r
85 #include "QueueSet.h"\r
86 #include "QueueOverwrite.h"\r
87 \r
88 /* Priorities for the demo application tasks. */\r
89 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
90 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
91 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
92 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
93 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
94 \r
95 /* A block time of zero simply means "don't block". */\r
96 #define mainDONT_BLOCK                                          ( 0UL )\r
97 \r
98 /* The period after which the check timer will expire, in ms, provided no errors\r
99 have been reported by any of the standard demo tasks.  ms are converted to the\r
100 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
101 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
102 \r
103 /* The period at which the check timer will expire, in ms, if an error has been\r
104 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
105 in ticks using the portTICK_PERIOD_MS constant. */\r
106 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 /*\r
111  * The check timer callback function, as described at the top of this file.\r
112  */\r
113 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
114 \r
115 /*\r
116  * Register check tasks, and the tasks used to write over and check the contents\r
117  * of the FPU registers, as described at the top of this file.  The nature of\r
118  * these files necessitates that they are written in an assembly file.\r
119  */\r
120 extern void vRegTest1Task( void *pvParameters );\r
121 extern void vRegTest2Task( void *pvParameters );\r
122 \r
123 /*-----------------------------------------------------------*/\r
124 \r
125 /* The following two variables are used to communicate the status of the\r
126 register check tasks to the check software timer.  If the variables keep\r
127 incrementing, then the register check tasks have not discovered any errors.  If\r
128 a variable stops incrementing, then an error has been found. */\r
129 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
130 \r
131 /*-----------------------------------------------------------*/\r
132 \r
133 void main_full( void )\r
134 {\r
135 TimerHandle_t xCheckTimer = NULL;\r
136 \r
137         /* Start all the other standard demo/test tasks.  The have not particular\r
138         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
139         kernel port. */\r
140         vStartQueueSetTasks();\r
141         vStartQueueOverwriteTask( tskIDLE_PRIORITY );\r
142         vStartDynamicPriorityTasks();\r
143         vCreateBlockTimeTasks();\r
144         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
145         vStartRecursiveMutexTasks();\r
146         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
147 \r
148         /* Create the register check tasks, as described at the top of this\r
149         file */\r
150         xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
151         xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
152 \r
153         /* Create the software timer that performs the 'check' functionality,\r
154         as described at the top of this file. */\r
155         xCheckTimer = xTimerCreate( "CheckTimer",                                               /* A text name, purely to help debugging. */\r
156                                                                 ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 3000ms (3s). */\r
157                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
158                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
159                                                                 prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
160                                                           );\r
161 \r
162         if( xCheckTimer != NULL )\r
163         {\r
164                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
165         }\r
166 \r
167         /* Start the scheduler. */\r
168         vTaskStartScheduler();\r
169 \r
170         /* If all is well, the scheduler will now be running, and the following line\r
171         will never be reached.  If the following line does execute, then there was\r
172         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
173         to be created.  See the memory management section on the FreeRTOS web site\r
174         for more details. */\r
175         for( ;; );\r
176 }\r
177 /*-----------------------------------------------------------*/\r
178 \r
179 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
180 {\r
181 static long lChangedTimerPeriodAlready = pdFALSE;\r
182 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
183 unsigned long ulErrorFound = pdFALSE;\r
184 \r
185         /* Check all the demo tasks (other than the flash tasks) to ensure\r
186         that they are all still running, and that none have detected an error. */\r
187 \r
188         if( xAreMathsTaskStillRunning() != pdTRUE )\r
189         {\r
190                 ulErrorFound = pdTRUE;\r
191         }\r
192 \r
193         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
194         {\r
195                 ulErrorFound = pdTRUE;\r
196         }\r
197 \r
198         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
199         {\r
200                 ulErrorFound = pdTRUE;\r
201         }\r
202 \r
203         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
204         {\r
205                 ulErrorFound = pdTRUE;\r
206         }\r
207 \r
208         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
209         {\r
210                 ulErrorFound = pdTRUE;\r
211         }\r
212 \r
213         if( xAreQueueSetTasksStillRunning() != pdTRUE )\r
214         {\r
215                 ulErrorFound = pdTRUE;\r
216         }\r
217 \r
218         if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )\r
219         {\r
220                 ulErrorFound = pdTRUE;\r
221         }\r
222 \r
223         /* Check that the register test 1 task is still running. */\r
224         if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
225         {\r
226                 ulErrorFound = pdTRUE;\r
227         }\r
228         ulLastRegTest1Value = ulRegTest1LoopCounter;\r
229 \r
230         /* Check that the register test 2 task is still running. */\r
231         if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
232         {\r
233                 ulErrorFound = pdTRUE;\r
234         }\r
235         ulLastRegTest2Value = ulRegTest2LoopCounter;\r
236 \r
237         /* Toggle the check LED to give an indication of the system status.  If\r
238         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
239         everything is ok.  A faster toggle indicates an error. */\r
240         configTOGGLE_LED();\r
241 \r
242         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
243         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
244         This will result in an increase in the rate at which mainCHECK_LED\r
245         toggles. */\r
246         if( ulErrorFound != pdFALSE )\r
247         {\r
248                 if( lChangedTimerPeriodAlready == pdFALSE )\r
249                 {\r
250                         lChangedTimerPeriodAlready = pdTRUE;\r
251 \r
252                         /* This call to xTimerChangePeriod() uses a zero block time.\r
253                         Functions called from inside of a timer callback function must\r
254                         *never* attempt to block. */\r
255                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
256                 }\r
257         }\r
258 }\r
259 /*-----------------------------------------------------------*/\r
260 \r