]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/NEC_V850ES_IAR/main.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / NEC_V850ES_IAR / main.c
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 /*\r
97  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
98  * documentation provides more details of the standard demo application tasks.\r
99  * In addition to the standard demo tasks, the following tasks and tests are\r
100  * defined and/or created within this file:\r
101  *\r
102  * "Check" task -  This only executes every three seconds but has a high priority\r
103  * to ensure it gets processor time.  Its main function is to check that all the\r
104  * standard demo tasks are still operational.  If everything is running as\r
105  * expected then the check task will toggle an LED every 3 seconds.  An error\r
106  * being discovered in any task will cause the toggle rate to increase to 500ms.\r
107  *\r
108  * "Reg test" tasks - These fill the registers with known values, then check\r
109  * that each register still contains its expected value.  Each task uses\r
110  * different values.  The tasks run with very low priority so get preempted very\r
111  * frequently.  A register containing an unexpected value is indicative of an\r
112  * error in the context switching mechanism.\r
113  *\r
114  */\r
115 \r
116 /* Standard include files. */\r
117 #include <stdlib.h>\r
118 #include <string.h>\r
119 \r
120 /* Scheduler include files. */\r
121 #include "FreeRTOS.h"\r
122 #include "task.h"\r
123 \r
124 /* Demo file headers. */\r
125 #include <intrinsics.h>\r
126 #include "BlockQ.h"\r
127 #include "death.h"\r
128 #include "flash.h"\r
129 #include "partest.h"\r
130 #include "semtest.h"\r
131 #include "PollQ.h"\r
132 #include "GenQTest.h"\r
133 #include "QPeek.h"\r
134 #include "recmutex.h"\r
135 #include "comtest2.h"\r
136 \r
137 /*\r
138  * Priority definitions for most of the tasks in the demo application.  Some\r
139  * tasks just use the idle priority.\r
140  */\r
141 #define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )\r
142 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
143 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
144 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
145 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
146 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
147 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
148 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
149 #define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
150 \r
151 /* Passed into the check task just as a test that the parameter passing\r
152 mechanism is working correctly. */\r
153 #define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )\r
154 \r
155 /* The period between executions of the check task. */\r
156 #define mainNO_ERROR_DELAY              ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
157 #define mainERROR_DELAY                 ( ( TickType_t ) 500 / portTICK_PERIOD_MS )\r
158 \r
159 /* There are no spare LEDs for the comtest tasks, so this is just set to an\r
160 invalid number. */\r
161 #define mainCOMTEST_LED                 ( 4 )\r
162 \r
163 /* The baud rate used by the comtest task. */\r
164 #define mainBAUD_RATE                   ( 9600 )\r
165 \r
166 /*-----------------------------------------------------------*/\r
167 \r
168 /* The implementation of the 'check' task as described at the top of this file. */\r
169 static void prvCheckTask( void *pvParameters );\r
170 \r
171 /* Just sets up the LED outputs.  Most generic setup is done in\r
172 __low_level_init(). */\r
173 static void prvSetupHardware( void );\r
174 \r
175 /* The RegTest functions as described at the top of this file. */\r
176 extern void vRegTest1( void *pvParameters );\r
177 extern void vRegTest2( void *pvParameters );\r
178 \r
179 /* A variable that will get set to fail if a RegTest task finds an error.  The\r
180 variable is inspected by the 'Check' task. */\r
181 static volatile long lRegTestStatus = pdPASS;\r
182 \r
183 /*-----------------------------------------------------------*/\r
184 \r
185 /* Create all the demo tasks then start the scheduler. */\r
186 void main( void )\r
187 {\r
188         /* Just sets up the LED outputs. */\r
189         prvSetupHardware();\r
190 \r
191         /* Standard demo tasks. */\r
192         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
193         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
194         vStartQueuePeekTasks();\r
195         \r
196         /* Create the check task as described at the top of this file. */\r
197         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );\r
198 \r
199         /* Create the RegTest tasks as described at the top of this file. */\r
200         xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
201         xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
202 \r
203         #ifdef __IAR_V850ES_Fx3__\r
204         {\r
205                 /* The extra IO required for the com test and led flashing tasks is only\r
206                 available on the application board, not the target boards. */   \r
207                 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );\r
208                 vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
209                 \r
210                 /* The Fx3 also has enough RAM to run loads more tasks. */\r
211                 vStartRecursiveMutexTasks();\r
212                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
213                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                              \r
214         }\r
215         #endif  \r
216         \r
217         /* The suicide tasks must be created last as they need to know how many\r
218         tasks were running prior to their creation in order to ascertain whether\r
219         or not the correct/expected number of tasks are running at any given time. */\r
220     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
221         \r
222         /* Start the scheduler. */\r
223         vTaskStartScheduler();\r
224 \r
225         /* If this line is reached then vTaskStartScheduler() returned because there\r
226         was insufficient heap memory remaining for the idle task to be created. */\r
227         for( ;; );\r
228 }\r
229 /*-----------------------------------------------------------*/\r
230 \r
231 static void prvCheckTask( void *pvParameters )\r
232 {\r
233 TickType_t xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;\r
234 unsigned portBASE_TYPE uxLEDToUse = 0;\r
235 \r
236         /* Ensure parameter is passed in correctly. */\r
237         if( pvParameters != mainCHECK_PARAMETER )\r
238         {\r
239                 xDelayPeriod = mainERROR_DELAY;\r
240         }\r
241         \r
242         /* Initialise xLastWakeTime before it is used.  After this point it is not\r
243         written to directly. */\r
244         xLastWakeTime = xTaskGetTickCount();\r
245         \r
246         /* Cycle for ever, delaying then checking all the other tasks are still\r
247         operating without error. */\r
248         for( ;; )\r
249         {\r
250                 /* Wait until it is time to check all the other tasks again. */\r
251                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
252                 \r
253                 if( lRegTestStatus != pdPASS )\r
254                 {\r
255                         xDelayPeriod = mainERROR_DELAY;\r
256                 }\r
257                 \r
258                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
259                 {\r
260                         xDelayPeriod = mainERROR_DELAY;\r
261                 }\r
262 \r
263                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
264                 {\r
265                         xDelayPeriod = mainERROR_DELAY;\r
266                 }\r
267 \r
268                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
269             {\r
270                 xDelayPeriod = mainERROR_DELAY;\r
271             }\r
272 \r
273                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
274             {\r
275                 xDelayPeriod = mainERROR_DELAY;\r
276             }\r
277 \r
278                 /* The Fx3 runs more tasks, so more checks are performed. */            \r
279                 #ifdef __IAR_V850ES_Fx3__\r
280                 {\r
281                         if( xAreComTestTasksStillRunning() != pdTRUE )\r
282                         {\r
283                                 xDelayPeriod = mainERROR_DELAY;\r
284                         }\r
285                         \r
286                         if( xArePollingQueuesStillRunning() != pdTRUE )\r
287                         {\r
288                                 xDelayPeriod = mainERROR_DELAY;\r
289                         }\r
290 \r
291                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
292                         {\r
293                                 xDelayPeriod = mainERROR_DELAY;\r
294                         }\r
295                         \r
296                         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
297                         {\r
298                                 xDelayPeriod = mainERROR_DELAY;\r
299                         }               \r
300                         \r
301                         /* The application board has more LEDs and uses the flash tasks\r
302                         so the check task instead uses LED3 as LED3 is still spare. */\r
303                         uxLEDToUse = 3;\r
304                 }\r
305                 #endif\r
306 \r
307                 /* Toggle the LED.  The toggle rate will depend on whether or not an\r
308                 error has been found in any tasks. */\r
309                 vParTestToggleLED( uxLEDToUse );\r
310         }\r
311 }\r
312 /*-----------------------------------------------------------*/\r
313 \r
314 static void prvSetupHardware( void )\r
315 {\r
316         /* Setup the LED outputs. */\r
317         vParTestInitialise();\r
318 \r
319         /* Any additional hardware configuration can be added here. */\r
320 }\r
321 /*-----------------------------------------------------------*/\r
322 \r
323 void vApplicationStackOverflowHook( void )\r
324 {\r
325         /* This will be called if a task overflows its stack.  pxCurrentTCB\r
326         can be inspected to see which is the offending task. */\r
327         for( ;; );\r
328 }\r
329 /*-----------------------------------------------------------*/\r
330 \r
331 void vRegTestFailed( void )\r
332 {\r
333         /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
334         inspected by the check task. */\r
335         lRegTestStatus = pdFAIL;\r
336         \r
337         /* Do not return from here as the reg test tasks clobber all registers so\r
338         function calls may not function correctly. */\r
339         for( ;; );\r
340 }\r