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