]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_IAR/main_full.c
Update FreeRTOS version number to V7.5.3
[freertos] / FreeRTOS / Demo / CORTEX_M4F_Infineon_XMC4000_IAR / main_full.c
1 /*\r
2     FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /******************************************************************************\r
67  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
68  * project, and a more comprehensive test and demo application.  The\r
69  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
70  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
71  * in main.c.  This file implements the comprehensive test and demo version.\r
72  *\r
73  * NOTE 2:  This file only contains the source code that is specific to the\r
74  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
75  * required to configure the hardware, are defined in main.c.\r
76  ******************************************************************************\r
77  *\r
78  * main_full() creates all the demo application tasks and a software timer, then\r
79  * starts the scheduler.  The web documentation provides more details of the\r
80  * standard demo application tasks, which provide no particular functionality,\r
81  * but do provide a good example of how to use the FreeRTOS API.\r
82  *\r
83  * In addition to the standard demo tasks, the following tasks and tests are\r
84  * defined and/or created within this file:\r
85  *\r
86  * "Reg test" tasks - These fill both the core and floating point registers with\r
87  * known values, then check that each register maintains its expected value for\r
88  * the lifetime of the task.  Each task uses a different set of values.  The reg\r
89  * test tasks execute with a very low priority, so get preempted very\r
90  * frequently.  A register containing an unexpected value is indicative of an\r
91  * error in the context switching mechanism.\r
92  *\r
93  * "Check" timer - The check software timer period is initially set to three\r
94  * seconds.  The callback function associated with the check software timer\r
95  * checks that all the standard demo tasks, and the register check tasks, are\r
96  * not only still executing, but are executing without reporting any errors.  If\r
97  * the check software timer discovers that a task has either stalled, or\r
98  * reported an error, then it changes its own execution period from the initial\r
99  * three seconds, to just 200ms.  The check software timer callback function\r
100  * also toggles the single LED each time it is called.  This provides a visual\r
101  * indication of the system status:  If the LED toggles every three seconds,\r
102  * then no issues have been discovered.  If the LED toggles every 200ms, then\r
103  * an issue has been discovered with at least one task.\r
104  */\r
105 \r
106 /* Standard includes. */\r
107 #include <stdio.h>\r
108 \r
109 /* Kernel includes. */\r
110 #include "FreeRTOS.h"\r
111 #include "task.h"\r
112 #include "timers.h"\r
113 #include "semphr.h"\r
114 \r
115 /* Standard demo application includes. */\r
116 #include "flop.h"\r
117 #include "semtest.h"\r
118 #include "dynamic.h"\r
119 #include "blocktim.h"\r
120 #include "countsem.h"\r
121 #include "GenQTest.h"\r
122 #include "recmutex.h"\r
123 #include "QueueSet.h"\r
124 #include "QueueOverwrite.h"\r
125 \r
126 /* Priorities for the demo application tasks. */\r
127 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
128 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
129 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
130 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
131 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
132 \r
133 /* A block time of zero simply means "don't block". */\r
134 #define mainDONT_BLOCK                                          ( 0UL )\r
135 \r
136 /* The period after which the check timer will expire, in ms, provided no errors\r
137 have been reported by any of the standard demo tasks.  ms are converted to the\r
138 equivalent in ticks using the portTICK_RATE_MS constant. */\r
139 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_RATE_MS )\r
140 \r
141 /* The period at which the check timer will expire, in ms, if an error has been\r
142 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
143 in ticks using the portTICK_RATE_MS constant. */\r
144 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_RATE_MS )\r
145 \r
146 /*-----------------------------------------------------------*/\r
147 \r
148 /*\r
149  * The check timer callback function, as described at the top of this file.\r
150  */\r
151 static void prvCheckTimerCallback( xTimerHandle xTimer );\r
152 \r
153 /*\r
154  * Register check tasks, and the tasks used to write over and check the contents\r
155  * of the FPU registers, as described at the top of this file.  The nature of\r
156  * these files necessitates that they are written in an assembly file.\r
157  */\r
158 extern void vRegTest1Task( void *pvParameters );\r
159 extern void vRegTest2Task( void *pvParameters );\r
160 \r
161 /*-----------------------------------------------------------*/\r
162 \r
163 /* The following two variables are used to communicate the status of the\r
164 register check tasks to the check software timer.  If the variables keep\r
165 incrementing, then the register check tasks has not discovered any errors.  If\r
166 a variable stops incrementing, then an error has been found. */\r
167 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
168 \r
169 /*-----------------------------------------------------------*/\r
170 \r
171 void main_full( void )\r
172 {\r
173 xTimerHandle xCheckTimer = NULL;\r
174 \r
175         /* Start all the other standard demo/test tasks.  The have not particular\r
176         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
177         kernel port. */\r
178         vStartQueueSetTasks();\r
179         vStartQueueOverwriteTask( tskIDLE_PRIORITY );\r
180         vStartDynamicPriorityTasks();\r
181         vCreateBlockTimeTasks();\r
182         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
183         vStartRecursiveMutexTasks();\r
184         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
185 \r
186         /* Create the register check tasks, as described at the top of this\r
187         file */\r
188         xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
189         xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );\r
190 \r
191         /* Create the software timer that performs the 'check' functionality,\r
192         as described at the top of this file. */\r
193         xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
194                                                                 ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 3000ms (3s). */\r
195                                                                 pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
196                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
197                                                                 prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
198                                                           );\r
199 \r
200         if( xCheckTimer != NULL )\r
201         {\r
202                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
203         }\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( xTimerHandle xTimer )\r
218 {\r
219 static long lChangedTimerPeriodAlready = pdFALSE;\r
220 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
221 unsigned long ulErrorFound = pdFALSE;\r
222 \r
223         /* Check all the demo tasks (other than the flash tasks) to ensure\r
224         that they are all still running, and that none have detected an error. */\r
225 \r
226         if( xAreMathsTaskStillRunning() != pdTRUE )\r
227         {\r
228                 ulErrorFound = pdTRUE;\r
229         }\r
230 \r
231         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
232         {\r
233                 ulErrorFound = pdTRUE;\r
234         }\r
235 \r
236         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
237         {\r
238                 ulErrorFound = pdTRUE;\r
239         }\r
240 \r
241         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
242         {\r
243                 ulErrorFound = pdTRUE;\r
244         }\r
245 \r
246         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
247         {\r
248                 ulErrorFound = pdTRUE;\r
249         }\r
250 \r
251         if( xAreQueueSetTasksStillRunning() != pdTRUE )\r
252         {\r
253                 ulErrorFound = pdTRUE;\r
254         }\r
255 \r
256         if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )\r
257         {\r
258                 ulErrorFound = pdTRUE;\r
259         }\r
260 \r
261         /* Check that the register test 1 task is still running. */\r
262         if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
263         {\r
264                 ulErrorFound = pdTRUE;\r
265         }\r
266         ulLastRegTest1Value = ulRegTest1LoopCounter;\r
267 \r
268         /* Check that the register test 2 task is still running. */\r
269         if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
270         {\r
271                 ulErrorFound = pdTRUE;\r
272         }\r
273         ulLastRegTest2Value = ulRegTest2LoopCounter;\r
274 \r
275         /* Toggle the check LED to give an indication of the system status.  If\r
276         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
277         everything is ok.  A faster toggle indicates an error. */\r
278         configTOGGLE_LED();\r
279 \r
280         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
281         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
282         This will result in an increase in the rate at which mainCHECK_LED\r
283         toggles. */\r
284         if( ulErrorFound != pdFALSE )\r
285         {\r
286                 if( lChangedTimerPeriodAlready == pdFALSE )\r
287                 {\r
288                         lChangedTimerPeriodAlready = pdTRUE;\r
289 \r
290                         /* This call to xTimerChangePeriod() uses a zero block time.\r
291                         Functions called from inside of a timer callback function must\r
292                         *never* attempt to block. */\r
293                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
294                 }\r
295         }\r
296 }\r
297 /*-----------------------------------------------------------*/\r
298 \r