]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/NEC_V850ES_IAR/main.c
Prepare for V7.4.0 release.
[freertos] / FreeRTOS / Demo / NEC_V850ES_IAR / main.c
1 /*\r
2     FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not itcan be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
67     Integrity Systems, who sell the code with commercial support, \r
68     indemnification and middleware, under the OpenRTOS brand.\r
69     \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
71     engineered and independently SIL3 certified version for use in safety and \r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /*\r
76  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
77  * documentation provides more details of the standard demo application tasks.\r
78  * In addition to the standard demo tasks, the following tasks and tests are\r
79  * defined and/or created within this file:\r
80  *\r
81  * "Check" task -  This only executes every three seconds but has a high priority\r
82  * to ensure it gets processor time.  Its main function is to check that all the\r
83  * standard demo tasks are still operational.  If everything is running as\r
84  * expected then the check task will toggle an LED every 3 seconds.  An error\r
85  * being discovered in any task will cause the toggle rate to increase to 500ms.\r
86  *\r
87  * "Reg test" tasks - These fill the registers with known values, then check\r
88  * that each register still contains its expected value.  Each task uses\r
89  * different values.  The tasks run with 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  */\r
94 \r
95 /* Standard include files. */\r
96 #include <stdlib.h>\r
97 #include <string.h>\r
98 \r
99 /* Scheduler include files. */\r
100 #include "FreeRTOS.h"\r
101 #include "task.h"\r
102 \r
103 /* Demo file headers. */\r
104 #include <intrinsics.h>\r
105 #include "BlockQ.h"\r
106 #include "death.h"\r
107 #include "flash.h"\r
108 #include "partest.h"\r
109 #include "semtest.h"\r
110 #include "PollQ.h"\r
111 #include "GenQTest.h"\r
112 #include "QPeek.h"\r
113 #include "recmutex.h"\r
114 #include "comtest2.h"\r
115 \r
116 /*\r
117  * Priority definitions for most of the tasks in the demo application.  Some\r
118  * tasks just use the idle priority.\r
119  */\r
120 #define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )\r
121 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
122 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
123 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
124 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
125 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
126 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
127 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
128 #define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
129 \r
130 /* Passed into the check task just as a test that the parameter passing\r
131 mechanism is working correctly. */\r
132 #define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )\r
133 \r
134 /* The period between executions of the check task. */\r
135 #define mainNO_ERROR_DELAY              ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
136 #define mainERROR_DELAY                 ( ( portTickType ) 500 / portTICK_RATE_MS )\r
137 \r
138 /* There are no spare LEDs for the comtest tasks, so this is just set to an\r
139 invalid number. */\r
140 #define mainCOMTEST_LED                 ( 4 )\r
141 \r
142 /* The baud rate used by the comtest task. */\r
143 #define mainBAUD_RATE                   ( 9600 )\r
144 \r
145 /*-----------------------------------------------------------*/\r
146 \r
147 /* The implementation of the 'check' task as described at the top of this file. */\r
148 static void prvCheckTask( void *pvParameters );\r
149 \r
150 /* Just sets up the LED outputs.  Most generic setup is done in\r
151 __low_level_init(). */\r
152 static void prvSetupHardware( void );\r
153 \r
154 /* The RegTest functions as described at the top of this file. */\r
155 extern void vRegTest1( void *pvParameters );\r
156 extern void vRegTest2( void *pvParameters );\r
157 \r
158 /* A variable that will get set to fail if a RegTest task finds an error.  The\r
159 variable is inspected by the 'Check' task. */\r
160 static volatile portLONG lRegTestStatus = pdPASS;\r
161 \r
162 /*-----------------------------------------------------------*/\r
163 \r
164 /* Create all the demo tasks then start the scheduler. */\r
165 void main( void )\r
166 {\r
167         /* Just sets up the LED outputs. */\r
168         prvSetupHardware();\r
169 \r
170         /* Standard demo tasks. */\r
171         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
172         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
173         vStartQueuePeekTasks();\r
174         \r
175         /* Create the check task as described at the top of this file. */\r
176         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );\r
177 \r
178         /* Create the RegTest tasks as described at the top of this file. */\r
179         xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
180         xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
181 \r
182         #ifdef __IAR_V850ES_Fx3__\r
183         {\r
184                 /* The extra IO required for the com test and led flashing tasks is only\r
185                 available on the application board, not the target boards. */   \r
186                 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );\r
187                 vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
188                 \r
189                 /* The Fx3 also has enough RAM to run loads more tasks. */\r
190                 vStartRecursiveMutexTasks();\r
191                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
192                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                              \r
193         }\r
194         #endif  \r
195         \r
196         /* The suicide tasks must be created last as they need to know how many\r
197         tasks were running prior to their creation in order to ascertain whether\r
198         or not the correct/expected number of tasks are running at any given time. */\r
199     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
200         \r
201         /* Start the scheduler. */\r
202         vTaskStartScheduler();\r
203 \r
204         /* If this line is reached then vTaskStartScheduler() returned because there\r
205         was insufficient heap memory remaining for the idle task to be created. */\r
206         for( ;; );\r
207 }\r
208 /*-----------------------------------------------------------*/\r
209 \r
210 static void prvCheckTask( void *pvParameters )\r
211 {\r
212 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;\r
213 unsigned portBASE_TYPE uxLEDToUse = 0;\r
214 \r
215         /* Ensure parameter is passed in correctly. */\r
216         if( pvParameters != mainCHECK_PARAMETER )\r
217         {\r
218                 xDelayPeriod = mainERROR_DELAY;\r
219         }\r
220         \r
221         /* Initialise xLastWakeTime before it is used.  After this point it is not\r
222         written to directly. */\r
223         xLastWakeTime = xTaskGetTickCount();\r
224         \r
225         /* Cycle for ever, delaying then checking all the other tasks are still\r
226         operating without error. */\r
227         for( ;; )\r
228         {\r
229                 /* Wait until it is time to check all the other tasks again. */\r
230                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
231                 \r
232                 if( lRegTestStatus != pdPASS )\r
233                 {\r
234                         xDelayPeriod = mainERROR_DELAY;\r
235                 }\r
236                 \r
237                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
238                 {\r
239                         xDelayPeriod = mainERROR_DELAY;\r
240                 }\r
241 \r
242                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
243                 {\r
244                         xDelayPeriod = mainERROR_DELAY;\r
245                 }\r
246 \r
247                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
248             {\r
249                 xDelayPeriod = mainERROR_DELAY;\r
250             }\r
251 \r
252                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
253             {\r
254                 xDelayPeriod = mainERROR_DELAY;\r
255             }\r
256 \r
257                 /* The Fx3 runs more tasks, so more checks are performed. */            \r
258                 #ifdef __IAR_V850ES_Fx3__\r
259                 {\r
260                         if( xAreComTestTasksStillRunning() != pdTRUE )\r
261                         {\r
262                                 xDelayPeriod = mainERROR_DELAY;\r
263                         }\r
264                         \r
265                         if( xArePollingQueuesStillRunning() != pdTRUE )\r
266                         {\r
267                                 xDelayPeriod = mainERROR_DELAY;\r
268                         }\r
269 \r
270                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
271                         {\r
272                                 xDelayPeriod = mainERROR_DELAY;\r
273                         }\r
274                         \r
275                         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
276                         {\r
277                                 xDelayPeriod = mainERROR_DELAY;\r
278                         }               \r
279                         \r
280                         /* The application board has more LEDs and uses the flash tasks\r
281                         so the check task instead uses LED3 as LED3 is still spare. */\r
282                         uxLEDToUse = 3;\r
283                 }\r
284                 #endif\r
285 \r
286                 /* Toggle the LED.  The toggle rate will depend on whether or not an\r
287                 error has been found in any tasks. */\r
288                 vParTestToggleLED( uxLEDToUse );\r
289         }\r
290 }\r
291 /*-----------------------------------------------------------*/\r
292 \r
293 static void prvSetupHardware( void )\r
294 {\r
295         /* Setup the LED outputs. */\r
296         vParTestInitialise();\r
297 \r
298         /* Any additional hardware configuration can be added here. */\r
299 }\r
300 /*-----------------------------------------------------------*/\r
301 \r
302 void vApplicationStackOverflowHook( void )\r
303 {\r
304         /* This will be called if a task overflows its stack.  pxCurrentTCB\r
305         can be inspected to see which is the offending task. */\r
306         for( ;; );\r
307 }\r
308 /*-----------------------------------------------------------*/\r
309 \r
310 void vRegTestFailed( void )\r
311 {\r
312         /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
313         inspected by the check task. */\r
314         lRegTestStatus = pdFAIL;\r
315         \r
316         /* Do not return from here as the reg test tasks clobber all registers so\r
317         function calls may not function correctly. */\r
318         for( ;; );\r
319 }\r