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