]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/NEC_V850ES_IAR/main.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / NEC_V850ES_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
30  * documentation provides more details of the standard demo application tasks.\r
31  * In addition to the standard demo tasks, the following tasks and tests are\r
32  * defined and/or created within this file:\r
33  *\r
34  * "Check" task -  This only executes every three seconds but has a high priority\r
35  * to ensure it gets processor time.  Its main function is to check that all the\r
36  * standard demo tasks are still operational.  If everything is running as\r
37  * expected then the check task will toggle an LED every 3 seconds.  An error\r
38  * being discovered in any task will cause the toggle rate to increase to 500ms.\r
39  *\r
40  * "Reg test" tasks - These fill the registers with known values, then check\r
41  * that each register still contains its expected value.  Each task uses\r
42  * different values.  The tasks run with very low priority so get preempted very\r
43  * frequently.  A register containing an unexpected value is indicative of an\r
44  * error in the context switching mechanism.\r
45  *\r
46  */\r
47 \r
48 /* Standard include files. */\r
49 #include <stdlib.h>\r
50 #include <string.h>\r
51 \r
52 /* Scheduler include files. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 \r
56 /* Demo file headers. */\r
57 #include <intrinsics.h>\r
58 #include "BlockQ.h"\r
59 #include "death.h"\r
60 #include "flash.h"\r
61 #include "partest.h"\r
62 #include "semtest.h"\r
63 #include "PollQ.h"\r
64 #include "GenQTest.h"\r
65 #include "QPeek.h"\r
66 #include "recmutex.h"\r
67 #include "comtest2.h"\r
68 \r
69 /*\r
70  * Priority definitions for most of the tasks in the demo application.  Some\r
71  * tasks just use the idle priority.\r
72  */\r
73 #define mainFLASH_PRIORITY                                      ( tskIDLE_PRIORITY + 1 )\r
74 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
75 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
76 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
77 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
78 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
79 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
80 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
81 #define mainCOMTEST_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
82 \r
83 /* Passed into the check task just as a test that the parameter passing\r
84 mechanism is working correctly. */\r
85 #define mainCHECK_PARAMETER                                     ( ( void * ) 0x12345678 )\r
86 \r
87 /* The period between executions of the check task. */\r
88 #define mainNO_ERROR_DELAY              ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
89 #define mainERROR_DELAY                 ( ( TickType_t ) 500 / portTICK_PERIOD_MS )\r
90 \r
91 /* There are no spare LEDs for the comtest tasks, so this is just set to an\r
92 invalid number. */\r
93 #define mainCOMTEST_LED                 ( 4 )\r
94 \r
95 /* The baud rate used by the comtest task. */\r
96 #define mainBAUD_RATE                   ( 9600 )\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /* The implementation of the 'check' task as described at the top of this file. */\r
101 static void prvCheckTask( void *pvParameters );\r
102 \r
103 /* Just sets up the LED outputs.  Most generic setup is done in\r
104 __low_level_init(). */\r
105 static void prvSetupHardware( void );\r
106 \r
107 /* The RegTest functions as described at the top of this file. */\r
108 extern void vRegTest1( void *pvParameters );\r
109 extern void vRegTest2( void *pvParameters );\r
110 \r
111 /* A variable that will get set to fail if a RegTest task finds an error.  The\r
112 variable is inspected by the 'Check' task. */\r
113 static volatile long lRegTestStatus = pdPASS;\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /* Create all the demo tasks then start the scheduler. */\r
118 void main( void )\r
119 {\r
120         /* Just sets up the LED outputs. */\r
121         prvSetupHardware();\r
122 \r
123         /* Standard demo tasks. */\r
124         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
125         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
126         vStartQueuePeekTasks();\r
127         \r
128         /* Create the check task as described at the top of this file. */\r
129         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );\r
130 \r
131         /* Create the RegTest tasks as described at the top of this file. */\r
132         xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
133         xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
134 \r
135         #ifdef __IAR_V850ES_Fx3__\r
136         {\r
137                 /* The extra IO required for the com test and led flashing tasks is only\r
138                 available on the application board, not the target boards. */   \r
139                 vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );\r
140                 vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
141                 \r
142                 /* The Fx3 also has enough RAM to run loads more tasks. */\r
143                 vStartRecursiveMutexTasks();\r
144                 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
145                 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );                              \r
146         }\r
147         #endif  \r
148         \r
149         /* The suicide tasks must be created last as they need to know how many\r
150         tasks were running prior to their creation in order to ascertain whether\r
151         or not the correct/expected number of tasks are running at any given time. */\r
152     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
153         \r
154         /* Start the scheduler. */\r
155         vTaskStartScheduler();\r
156 \r
157         /* If this line is reached then vTaskStartScheduler() returned because there\r
158         was insufficient heap memory remaining for the idle task to be created. */\r
159         for( ;; );\r
160 }\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 static void prvCheckTask( void *pvParameters )\r
164 {\r
165 TickType_t xDelayPeriod = mainNO_ERROR_DELAY, xLastWakeTime;\r
166 unsigned portBASE_TYPE uxLEDToUse = 0;\r
167 \r
168         /* Ensure parameter is passed in correctly. */\r
169         if( pvParameters != mainCHECK_PARAMETER )\r
170         {\r
171                 xDelayPeriod = mainERROR_DELAY;\r
172         }\r
173         \r
174         /* Initialise xLastWakeTime before it is used.  After this point it is not\r
175         written to directly. */\r
176         xLastWakeTime = xTaskGetTickCount();\r
177         \r
178         /* Cycle for ever, delaying then checking all the other tasks are still\r
179         operating without error. */\r
180         for( ;; )\r
181         {\r
182                 /* Wait until it is time to check all the other tasks again. */\r
183                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
184                 \r
185                 if( lRegTestStatus != pdPASS )\r
186                 {\r
187                         xDelayPeriod = mainERROR_DELAY;\r
188                 }\r
189                 \r
190                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
191                 {\r
192                         xDelayPeriod = mainERROR_DELAY;\r
193                 }\r
194 \r
195                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
196                 {\r
197                         xDelayPeriod = mainERROR_DELAY;\r
198                 }\r
199 \r
200                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
201             {\r
202                 xDelayPeriod = mainERROR_DELAY;\r
203             }\r
204 \r
205                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
206             {\r
207                 xDelayPeriod = mainERROR_DELAY;\r
208             }\r
209 \r
210                 /* The Fx3 runs more tasks, so more checks are performed. */            \r
211                 #ifdef __IAR_V850ES_Fx3__\r
212                 {\r
213                         if( xAreComTestTasksStillRunning() != pdTRUE )\r
214                         {\r
215                                 xDelayPeriod = mainERROR_DELAY;\r
216                         }\r
217                         \r
218                         if( xArePollingQueuesStillRunning() != pdTRUE )\r
219                         {\r
220                                 xDelayPeriod = mainERROR_DELAY;\r
221                         }\r
222 \r
223                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
224                         {\r
225                                 xDelayPeriod = mainERROR_DELAY;\r
226                         }\r
227                         \r
228                         if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
229                         {\r
230                                 xDelayPeriod = mainERROR_DELAY;\r
231                         }               \r
232                         \r
233                         /* The application board has more LEDs and uses the flash tasks\r
234                         so the check task instead uses LED3 as LED3 is still spare. */\r
235                         uxLEDToUse = 3;\r
236                 }\r
237                 #endif\r
238 \r
239                 /* Toggle the LED.  The toggle rate will depend on whether or not an\r
240                 error has been found in any tasks. */\r
241                 vParTestToggleLED( uxLEDToUse );\r
242         }\r
243 }\r
244 /*-----------------------------------------------------------*/\r
245 \r
246 static void prvSetupHardware( void )\r
247 {\r
248         /* Setup the LED outputs. */\r
249         vParTestInitialise();\r
250 \r
251         /* Any additional hardware configuration can be added here. */\r
252 }\r
253 /*-----------------------------------------------------------*/\r
254 \r
255 void vApplicationStackOverflowHook( void )\r
256 {\r
257         /* This will be called if a task overflows its stack.  pxCurrentTCB\r
258         can be inspected to see which is the offending task. */\r
259         for( ;; );\r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 void vRegTestFailed( void )\r
264 {\r
265         /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
266         inspected by the check task. */\r
267         lRegTestStatus = pdFAIL;\r
268         \r
269         /* Do not return from here as the reg test tasks clobber all registers so\r
270         function calls may not function correctly. */\r
271         for( ;; );\r
272 }\r