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