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