]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/NEC_V850ES_IAR/main.c
3637dc681b8daeaec63797f8f32aa5d449224d49
[freertos] / FreeRTOS / Demo / NEC_V850ES_IAR / main.c
1 /*\r
2     FreeRTOS V7.6.0 - 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  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
68  * documentation provides more details of the standard demo application tasks.\r
69  * In addition to the standard demo tasks, the following tasks and tests are\r
70  * defined and/or created within this file:\r
71  *\r
72  * "Check" task -  This only executes every three seconds but has a high priority\r
73  * to ensure it gets processor time.  Its main function is to check that all the\r
74  * standard demo tasks are still operational.  If everything is running as\r
75  * expected then the check task will toggle an LED every 3 seconds.  An error\r
76  * being discovered in any task will cause the toggle rate to increase to 500ms.\r
77  *\r
78  * "Reg test" tasks - These fill the registers with known values, then check\r
79  * that each register still contains its expected value.  Each task uses\r
80  * different values.  The tasks run with very low priority so get preempted very\r
81  * frequently.  A register containing an unexpected value is indicative of an\r
82  * error in the context switching mechanism.\r
83  *\r
84  */\r
85 \r
86 /* Standard include files. */\r
87 #include <stdlib.h>\r
88 #include <string.h>\r
89 \r
90 /* Scheduler include files. */\r
91 #include "FreeRTOS.h"\r
92 #include "task.h"\r
93 \r
94 /* Demo file headers. */\r
95 #include <intrinsics.h>\r
96 #include "BlockQ.h"\r
97 #include "death.h"\r
98 #include "flash.h"\r
99 #include "partest.h"\r
100 #include "semtest.h"\r
101 #include "PollQ.h"\r
102 #include "GenQTest.h"\r
103 #include "QPeek.h"\r
104 #include "recmutex.h"\r
105 #include "comtest2.h"\r
106 \r
107 /*\r
108  * Priority definitions for most of the tasks in the demo application.  Some\r
109  * tasks just use the idle priority.\r
110  */\r
111 #define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )\r
112 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
113 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
114 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
115 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
116 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
117 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
118 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
119 #define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
120 \r
121 /* Passed into the check task just as a test that the parameter passing\r
122 mechanism is working correctly. */\r
123 #define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )\r
124 \r
125 /* The period between executions of the check task. */\r
126 #define mainNO_ERROR_DELAY              ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
127 #define mainERROR_DELAY                 ( ( portTickType ) 500 / portTICK_RATE_MS )\r
128 \r
129 /* There are no spare LEDs for the comtest tasks, so this is just set to an\r
130 invalid number. */\r
131 #define mainCOMTEST_LED                 ( 4 )\r
132 \r
133 /* The baud rate used by the comtest task. */\r
134 #define mainBAUD_RATE                   ( 9600 )\r
135 \r
136 /*-----------------------------------------------------------*/\r
137 \r
138 /* The implementation of the 'check' task as described at the top of this file. */\r
139 static void prvCheckTask( void *pvParameters );\r
140 \r
141 /* Just sets up the LED outputs.  Most generic setup is done in\r
142 __low_level_init(). */\r
143 static void prvSetupHardware( void );\r
144 \r
145 /* The RegTest functions as described at the top of this file. */\r
146 extern void vRegTest1( void *pvParameters );\r
147 extern void vRegTest2( void *pvParameters );\r
148 \r
149 /* A variable that will get set to fail if a RegTest task finds an error.  The\r
150 variable is inspected by the 'Check' task. */\r
151 static volatile portLONG lRegTestStatus = pdPASS;\r
152 \r
153 /*-----------------------------------------------------------*/\r
154 \r
155 /* Create all the demo tasks then start the scheduler. */\r
156 void main( void )\r
157 {\r
158         /* Just sets up the LED outputs. */\r
159         prvSetupHardware();\r
160 \r
161         /* Standard demo tasks. */\r
162         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
163         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
164         vStartQueuePeekTasks();\r
165         \r
166         /* Create the check task as described at the top of this file. */\r
167         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );\r
168 \r
169         /* Create the RegTest tasks as described at the top of this file. */\r
170         xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
171         xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
172 \r
173         #ifdef __IAR_V850ES_Fx3__\r
174         {\r
175                 /* The extra IO required for the com test and led flashing tasks is only\r
176                 available on the application board, not the target boards. */   \r
177                 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );\r
178                 vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
179                 \r
180                 /* The Fx3 also has enough RAM to run loads more tasks. */\r
181                 vStartRecursiveMutexTasks();\r
182                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
183                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                              \r
184         }\r
185         #endif  \r
186         \r
187         /* The suicide tasks must be created last as they need to know how many\r
188         tasks were running prior to their creation in order to ascertain whether\r
189         or not the correct/expected number of tasks are running at any given time. */\r
190     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
191         \r
192         /* Start the scheduler. */\r
193         vTaskStartScheduler();\r
194 \r
195         /* If this line is reached then vTaskStartScheduler() returned because there\r
196         was insufficient heap memory remaining for the idle task to be created. */\r
197         for( ;; );\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 static void prvCheckTask( void *pvParameters )\r
202 {\r
203 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;\r
204 unsigned portBASE_TYPE uxLEDToUse = 0;\r
205 \r
206         /* Ensure parameter is passed in correctly. */\r
207         if( pvParameters != mainCHECK_PARAMETER )\r
208         {\r
209                 xDelayPeriod = mainERROR_DELAY;\r
210         }\r
211         \r
212         /* Initialise xLastWakeTime before it is used.  After this point it is not\r
213         written to directly. */\r
214         xLastWakeTime = xTaskGetTickCount();\r
215         \r
216         /* Cycle for ever, delaying then checking all the other tasks are still\r
217         operating without error. */\r
218         for( ;; )\r
219         {\r
220                 /* Wait until it is time to check all the other tasks again. */\r
221                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
222                 \r
223                 if( lRegTestStatus != pdPASS )\r
224                 {\r
225                         xDelayPeriod = mainERROR_DELAY;\r
226                 }\r
227                 \r
228                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
229                 {\r
230                         xDelayPeriod = mainERROR_DELAY;\r
231                 }\r
232 \r
233                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
234                 {\r
235                         xDelayPeriod = mainERROR_DELAY;\r
236                 }\r
237 \r
238                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
239             {\r
240                 xDelayPeriod = mainERROR_DELAY;\r
241             }\r
242 \r
243                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
244             {\r
245                 xDelayPeriod = mainERROR_DELAY;\r
246             }\r
247 \r
248                 /* The Fx3 runs more tasks, so more checks are performed. */            \r
249                 #ifdef __IAR_V850ES_Fx3__\r
250                 {\r
251                         if( xAreComTestTasksStillRunning() != pdTRUE )\r
252                         {\r
253                                 xDelayPeriod = mainERROR_DELAY;\r
254                         }\r
255                         \r
256                         if( xArePollingQueuesStillRunning() != pdTRUE )\r
257                         {\r
258                                 xDelayPeriod = mainERROR_DELAY;\r
259                         }\r
260 \r
261                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
262                         {\r
263                                 xDelayPeriod = mainERROR_DELAY;\r
264                         }\r
265                         \r
266                         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
267                         {\r
268                                 xDelayPeriod = mainERROR_DELAY;\r
269                         }               \r
270                         \r
271                         /* The application board has more LEDs and uses the flash tasks\r
272                         so the check task instead uses LED3 as LED3 is still spare. */\r
273                         uxLEDToUse = 3;\r
274                 }\r
275                 #endif\r
276 \r
277                 /* Toggle the LED.  The toggle rate will depend on whether or not an\r
278                 error has been found in any tasks. */\r
279                 vParTestToggleLED( uxLEDToUse );\r
280         }\r
281 }\r
282 /*-----------------------------------------------------------*/\r
283 \r
284 static void prvSetupHardware( void )\r
285 {\r
286         /* Setup the LED outputs. */\r
287         vParTestInitialise();\r
288 \r
289         /* Any additional hardware configuration can be added here. */\r
290 }\r
291 /*-----------------------------------------------------------*/\r
292 \r
293 void vApplicationStackOverflowHook( void )\r
294 {\r
295         /* This will be called if a task overflows its stack.  pxCurrentTCB\r
296         can be inspected to see which is the offending task. */\r
297         for( ;; );\r
298 }\r
299 /*-----------------------------------------------------------*/\r
300 \r
301 void vRegTestFailed( void )\r
302 {\r
303         /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
304         inspected by the check task. */\r
305         lRegTestStatus = pdFAIL;\r
306         \r
307         /* Do not return from here as the reg test tasks clobber all registers so\r
308         function calls may not function correctly. */\r
309         for( ;; );\r
310 }\r