]> git.sur5r.net Git - freertos/blob - Demo/NEC_V850ES_IAR/main.c
Update to V5.1.2.
[freertos] / Demo / NEC_V850ES_IAR / main.c
1 /*\r
2         FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26     ***************************************************************************\r
27     ***************************************************************************\r
28     *                                                                         *\r
29     * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
30         *                                                                         *\r
31         * This is a concise, step by step, 'hands on' guide that describes both   *\r
32         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
33         * explains numerous examples that are written using the FreeRTOS API.     *\r
34         * Full source code for all the examples is provided in an accompanying    *\r
35         * .zip file.                                                              *\r
36     *                                                                         *\r
37     ***************************************************************************\r
38     ***************************************************************************\r
39 \r
40         Please ensure to read the configuration and relevant port sections of the\r
41         online documentation.\r
42 \r
43         http://www.FreeRTOS.org - Documentation, latest information, license and\r
44         contact details.\r
45 \r
46         http://www.SafeRTOS.com - A version that is certified for use in safety\r
47         critical systems.\r
48 \r
49         http://www.OpenRTOS.com - Commercial support, development, porting,\r
50         licensing and training services.\r
51 */\r
52 \r
53 /*\r
54  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
55  * documentation provides more details of the standard demo application tasks.\r
56  * In addition to the standard demo tasks, the following tasks and tests are\r
57  * defined and/or created within this file:\r
58  *\r
59  * "Check" task -  This only executes every three seconds but has a high priority\r
60  * to ensure it gets processor time.  Its main function is to check that all the\r
61  * standard demo tasks are still operational.  If everything is running as\r
62  * expected then the check task will toggle an LED every 3 seconds.  An error\r
63  * being discovered in any task will cause the toggle rate to increase to 500ms.\r
64  *\r
65  * "Reg test" tasks - These fill the registers with known values, then check\r
66  * that each register still contains its expected value.  Each task uses\r
67  * different values.  The tasks run with very low priority so get preempted very\r
68  * frequently.  A register containing an unexpected value is indicative of an\r
69  * error in the context switching mechanism.\r
70  *\r
71  */\r
72 \r
73 /* Standard include files. */\r
74 #include <stdlib.h>\r
75 #include <string.h>\r
76 \r
77 /* Scheduler include files. */\r
78 #include "FreeRTOS.h"\r
79 #include "task.h"\r
80 \r
81 /* Demo file headers. */\r
82 #include <intrinsics.h>\r
83 #include "BlockQ.h"\r
84 #include "death.h"\r
85 #include "flash.h"\r
86 #include "partest.h"\r
87 #include "semtest.h"\r
88 #include "PollQ.h"\r
89 #include "GenQTest.h"\r
90 #include "QPeek.h"\r
91 #include "recmutex.h"\r
92 #include "comtest2.h"\r
93 \r
94 /*\r
95  * Priority definitions for most of the tasks in the demo application.  Some\r
96  * tasks just use the idle priority.\r
97  */\r
98 #define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )\r
99 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
100 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
101 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
102 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
103 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
104 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
105 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
106 #define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
107 \r
108 /* Passed into the check task just as a test that the parameter passing\r
109 mechanism is working correctly. */\r
110 #define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )\r
111 \r
112 /* The period between executions of the check task. */\r
113 #define mainNO_ERROR_DELAY              ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
114 #define mainERROR_DELAY                 ( ( portTickType ) 500 / portTICK_RATE_MS )\r
115 \r
116 /* There are no spare LEDs for the comtest tasks, so this is just set to an\r
117 invalid number. */\r
118 #define mainCOMTEST_LED                 ( 4 )\r
119 \r
120 /* The baud rate used by the comtest task. */\r
121 #define mainBAUD_RATE                   ( 9600 )\r
122 \r
123 /*-----------------------------------------------------------*/\r
124 \r
125 /* The implementation of the 'check' task as described at the top of this file. */\r
126 static void prvCheckTask( void *pvParameters );\r
127 \r
128 /* Just sets up the LED outputs.  Most generic setup is done in\r
129 __low_level_init(). */\r
130 static void prvSetupHardware( void );\r
131 \r
132 /* The RegTest functions as described at the top of this file. */\r
133 extern void vRegTest1( void *pvParameters );\r
134 extern void vRegTest2( void *pvParameters );\r
135 \r
136 /* A variable that will get set to fail if a RegTest task finds an error.  The\r
137 variable is inspected by the 'Check' task. */\r
138 static volatile portLONG lRegTestStatus = pdPASS;\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 \r
142 /* Create all the demo tasks then start the scheduler. */\r
143 void main( void )\r
144 {\r
145         /* Just sets up the LED outputs. */\r
146         prvSetupHardware();\r
147 \r
148         /* Standard demo tasks. */\r
149         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
150         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
151         vStartQueuePeekTasks();\r
152         \r
153         /* Create the check task as described at the top of this file. */\r
154         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );\r
155 \r
156         /* Create the RegTest tasks as described at the top of this file. */\r
157         xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
158         xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
159 \r
160         #ifdef __IAR_V850ES_Fx3__\r
161         {\r
162                 /* The extra IO required for the com test and led flashing tasks is only\r
163                 available on the application board, not the target boards. */   \r
164                 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );\r
165                 vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
166                 \r
167                 /* The Fx3 also has enough RAM to run loads more tasks. */\r
168                 vStartRecursiveMutexTasks();\r
169                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
170                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                              \r
171         }\r
172         #endif  \r
173         \r
174         /* The suicide tasks must be created last as they need to know how many\r
175         tasks were running prior to their creation in order to ascertain whether\r
176         or not the correct/expected number of tasks are running at any given time. */\r
177     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
178         \r
179         /* Start the scheduler. */\r
180         vTaskStartScheduler();\r
181 \r
182         /* If this line is reached then vTaskStartScheduler() returned because there\r
183         was insufficient heap memory remaining for the idle task to be created. */\r
184         for( ;; );\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvCheckTask( void *pvParameters )\r
189 {\r
190 portTickType xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;\r
191 unsigned portBASE_TYPE uxLEDToUse = 0;\r
192 \r
193         /* Ensure parameter is passed in correctly. */\r
194         if( pvParameters != mainCHECK_PARAMETER )\r
195         {\r
196                 xDelayPeriod = mainERROR_DELAY;\r
197         }\r
198         \r
199         /* Initialise xLastWakeTime before it is used.  After this point it is not\r
200         written to directly. */\r
201         xLastWakeTime = xTaskGetTickCount();\r
202         \r
203         /* Cycle for ever, delaying then checking all the other tasks are still\r
204         operating without error. */\r
205         for( ;; )\r
206         {\r
207                 /* Wait until it is time to check all the other tasks again. */\r
208                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
209                 \r
210                 if( lRegTestStatus != pdPASS )\r
211                 {\r
212                         xDelayPeriod = mainERROR_DELAY;\r
213                 }\r
214                 \r
215                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
216                 {\r
217                         xDelayPeriod = mainERROR_DELAY;\r
218                 }\r
219 \r
220                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
221                 {\r
222                         xDelayPeriod = mainERROR_DELAY;\r
223                 }\r
224 \r
225                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
226             {\r
227                 xDelayPeriod = mainERROR_DELAY;\r
228             }\r
229 \r
230                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
231             {\r
232                 xDelayPeriod = mainERROR_DELAY;\r
233             }\r
234 \r
235                 /* The Fx3 runs more tasks, so more checks are performed. */            \r
236                 #ifdef __IAR_V850ES_Fx3__\r
237                 {\r
238                         if( xAreComTestTasksStillRunning() != pdTRUE )\r
239                         {\r
240                                 xDelayPeriod = mainERROR_DELAY;\r
241                         }\r
242                         \r
243                         if( xArePollingQueuesStillRunning() != pdTRUE )\r
244                         {\r
245                                 xDelayPeriod = mainERROR_DELAY;\r
246                         }\r
247 \r
248                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
249                         {\r
250                                 xDelayPeriod = mainERROR_DELAY;\r
251                         }\r
252                         \r
253                         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
254                         {\r
255                                 xDelayPeriod = mainERROR_DELAY;\r
256                         }               \r
257                         \r
258                         /* The application board has more LEDs and uses the flash tasks\r
259                         so the check task instead uses LED3 as LED3 is still spare. */\r
260                         uxLEDToUse = 3;\r
261                 }\r
262                 #endif\r
263 \r
264                 /* Toggle the LED.  The toggle rate will depend on whether or not an\r
265                 error has been found in any tasks. */\r
266                 vParTestToggleLED( uxLEDToUse );\r
267         }\r
268 }\r
269 /*-----------------------------------------------------------*/\r
270 \r
271 static void prvSetupHardware( void )\r
272 {\r
273         /* Setup the LED outputs. */\r
274         vParTestInitialise();\r
275 \r
276         /* Any additional hardware configuration can be added here. */\r
277 }\r
278 /*-----------------------------------------------------------*/\r
279 \r
280 void vApplicationStackOverflowHook( void )\r
281 {\r
282         /* This will be called if a task overflows its stack.  pxCurrentTCB\r
283         can be inspected to see which is the offending task. */\r
284         for( ;; );\r
285 }\r
286 /*-----------------------------------------------------------*/\r
287 \r
288 void vRegTestFailed( void )\r
289 {\r
290         /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
291         inspected by the check task. */\r
292         lRegTestStatus = pdFAIL;\r
293         \r
294         /* Do not return from here as the reg test tasks clobber all registers so\r
295         function calls may not function correctly. */\r
296         for( ;; );\r
297 }\r