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