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