]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Tensilica_Simulator_Xplorer_XCC/main_full.c
d8e2561f9a2a41bfcae50fdfe1583f61a8aee9db
[freertos] / FreeRTOS / Demo / Tensilica_Simulator_Xplorer_XCC / main_full.c
1 /*\r
2  * FreeRTOS Kernel V10.1.1\r
3  * Copyright (C) 2018 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  * main() creates all the demo application tasks, then starts the scheduler.\r
30  * The web documentation provides more details of the standard demo application\r
31  * tasks, which provide no particular functionality but do provide a good\r
32  * example of how to use the FreeRTOS API.\r
33  *\r
34  * In addition to the standard demo tasks, the following tasks and tests are\r
35  * defined and/or created within this file:\r
36  *\r
37  * "Check" task - This only executes every five seconds but has a high priority\r
38  * to ensure it gets processor time.  Its main function is to check that all the\r
39  * standard demo tasks are still operational.  While no errors have been\r
40  * discovered the check task will print out "OK" and the current simulated tick\r
41  * time.  If an error is discovered in the execution of a task then the check\r
42  * task will print out an appropriate error message.\r
43  *\r
44  */\r
45 \r
46 \r
47 /* Standard includes. */\r
48 #include <stdio.h>\r
49 #include <stdlib.h>\r
50 \r
51 /* Kernel includes. */\r
52 #include <FreeRTOS.h>\r
53 #include <task.h>\r
54 #include <queue.h>\r
55 #include <timers.h>\r
56 #include <semphr.h>\r
57 \r
58 /* Standard demo includes. */\r
59 #include "BlockQ.h"\r
60 #include "integer.h"\r
61 #include "semtest.h"\r
62 #include "PollQ.h"\r
63 #include "GenQTest.h"\r
64 #include "QPeek.h"\r
65 #include "recmutex.h"\r
66 #include "flop.h"\r
67 #include "TimerDemo.h"\r
68 #include "countsem.h"\r
69 #include "death.h"\r
70 #include "dynamic.h"\r
71 #include "QueueSet.h"\r
72 #include "QueueOverwrite.h"\r
73 #include "EventGroupsDemo.h"\r
74 #include "IntSemTest.h"\r
75 #include "TaskNotify.h"\r
76 #include "QueueSetPolling.h"\r
77 #include "StaticAllocation.h"\r
78 #include "blocktim.h"\r
79 #include "AbortDelay.h"\r
80 #include "MessageBufferDemo.h"\r
81 #include "StreamBufferDemo.h"\r
82 #include "StreamBufferInterrupt.h"\r
83 \r
84 /* Priorities at which the tasks are created. */\r
85 #define mainCHECK_TASK_PRIORITY                 ( configMAX_PRIORITIES - 2 )\r
86 #define mainQUEUE_POLL_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
87 #define mainSEM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
88 #define mainBLOCK_Q_PRIORITY                    ( tskIDLE_PRIORITY + 2 )\r
89 #define mainCREATOR_TASK_PRIORITY               ( tskIDLE_PRIORITY + 3 )\r
90 #define mainFLASH_TASK_PRIORITY                 ( tskIDLE_PRIORITY + 1 )\r
91 #define mainINTEGER_TASK_PRIORITY               ( tskIDLE_PRIORITY )\r
92 #define mainGEN_QUEUE_TASK_PRIORITY             ( tskIDLE_PRIORITY )\r
93 #define mainFLOP_TASK_PRIORITY                  ( tskIDLE_PRIORITY )\r
94 #define mainQUEUE_OVERWRITE_PRIORITY    ( tskIDLE_PRIORITY )\r
95 \r
96 #define mainTIMER_TEST_PERIOD                   ( 50 )\r
97 \r
98 /* The task that periodically checks that all the standard demo tasks are\r
99  * still executing and error free.\r
100  */\r
101 static void prvCheckTask( void *pvParameters );\r
102 \r
103 /*-----------------------------------------------------------*/\r
104 \r
105 /* The variable into which error messages are latched. */\r
106 static char *pcStatusMessage = "No errors";\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 int main_full( void )\r
111 {\r
112         /* Start the check task as described at the top of this file. */\r
113         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
114 \r
115         /* Create the standard demo tasks. */\r
116         vStartTaskNotifyTask();\r
117         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
118         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
119         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
120         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
121         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
122 \r
123         vStartQueuePeekTasks();\r
124         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
125         vStartRecursiveMutexTasks();\r
126         vStartCountingSemaphoreTasks();\r
127         vStartDynamicPriorityTasks();\r
128         vStartQueueSetTasks();\r
129 \r
130         vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
131         vStartEventGroupTasks();\r
132         vStartInterruptSemaphoreTasks();\r
133         vStartQueueSetPollingTask();\r
134         vCreateBlockTimeTasks();\r
135 \r
136         vCreateAbortDelayTasks();\r
137         vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );\r
138 \r
139         vStartStreamBufferTasks();\r
140         vStartStreamBufferInterruptDemo();\r
141 \r
142         #if( configUSE_PREEMPTION != 0  )\r
143         {\r
144                 /* Don't expect these tasks to pass when preemption is not used. */\r
145                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\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.  This then allows them to\r
151         ascertain whether or not the correct/expected number of tasks are running at\r
152         any given time. */\r
153         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
154 \r
155         /* Start the scheduler itself. */\r
156         vTaskStartScheduler();\r
157 \r
158         /* Should never get here unless there was not enough heap space to create\r
159         the idle and other system tasks. */\r
160         return 0;\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 static void prvCheckTask( void *pvParameters )\r
165 {\r
166 TickType_t xNextWakeTime;\r
167 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 5000UL );\r
168 \r
169         /* Just to remove compiler warning. */\r
170         ( void ) pvParameters;\r
171 \r
172         /* Initialise xNextWakeTime - this only needs to be done once. */\r
173         xNextWakeTime = xTaskGetTickCount();\r
174 \r
175         for( ;; )\r
176         {\r
177                 /* Place this task in the blocked state until it is time to run again. */\r
178                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
179 \r
180                 /* Check the standard demo tasks are running without error. */\r
181                 #if( configUSE_PREEMPTION != 0 )\r
182                 {\r
183                         /* These tasks are only created when preemption is used. */\r
184                         if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
185                         {\r
186                                 pcStatusMessage = "Error: TimerDemo";\r
187                         }\r
188                 }\r
189                 #endif\r
190 \r
191                 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
192                 {\r
193                         pcStatusMessage = "Error:  Notification";\r
194                 }\r
195                 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
196                 {\r
197                         pcStatusMessage = "Error: IntMath";\r
198                 }\r
199                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
200                 {\r
201                         pcStatusMessage = "Error: GenQueue";\r
202                 }\r
203                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
204                 {\r
205                         pcStatusMessage = "Error: BlockQueue";\r
206                 }\r
207                 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
208                 {\r
209                         pcStatusMessage = "Error: SemTest";\r
210                 }\r
211                 else if( xArePollingQueuesStillRunning() != pdTRUE )\r
212                 {\r
213                         pcStatusMessage = "Error: PollQueue";\r
214                 }\r
215                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
216                 {\r
217                         pcStatusMessage = "Error: QueuePeek";\r
218                 }\r
219                 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
220                 {\r
221                         pcStatusMessage = "Error: RecMutex";\r
222                 }\r
223                 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
224                 {\r
225                         pcStatusMessage = "Error: CountSem";\r
226                 }\r
227                 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
228                 {\r
229                         pcStatusMessage = "Error: Dynamic";\r
230                 }\r
231                 else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
232                 {\r
233                         pcStatusMessage = "Error: Queue set";\r
234                 }\r
235                 else if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
236                 {\r
237                         pcStatusMessage = "Error: EventGroup";\r
238                 }\r
239                 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
240                 {\r
241                         pcStatusMessage = "Error: Queue overwrite";\r
242                 }\r
243                 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )\r
244                 {\r
245                         pcStatusMessage = "Error: Queue set polling";\r
246                 }\r
247                 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )\r
248                 {\r
249                         pcStatusMessage = "Error: Block time";\r
250                 }\r
251                 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )\r
252                 {\r
253                         pcStatusMessage = "Error:  MessageBuffer";\r
254                 }\r
255                 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )\r
256                 {\r
257                         pcStatusMessage = "Error: Abort delay";\r
258                 }\r
259                 else if( xAreStreamBufferTasksStillRunning() != pdTRUE )\r
260                 {\r
261                         pcStatusMessage = "Error:  StreamBuffer";\r
262                 }\r
263                 else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )\r
264                 {\r
265                         pcStatusMessage = "Error: Stream buffer interrupt";\r
266                 }\r
267                 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )\r
268                 {\r
269                         pcStatusMessage = "Error: IntSem";\r
270                 }\r
271                 else if( xIsCreateTaskStillRunning() != pdTRUE )\r
272                 {\r
273                         pcStatusMessage = "Error: Death";\r
274                 }\r
275                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
276                 {\r
277                         pcStatusMessage = "Error: Flop";\r
278                 }\r
279 \r
280                 /* This is the only task that uses stdout so its ok to call printf()\r
281                 directly. */\r
282                 printf( "%s - tick count %zu - free heap %zu - min free heap %zu\r\n", pcStatusMessage,\r
283                                                                                                                                                            xTaskGetTickCount(),\r
284                                                                                                                                                            xPortGetFreeHeapSize(),\r
285                                                                                                                                                            xPortGetMinimumEverFreeHeapSize() );\r
286         }\r
287 }\r
288 /*-----------------------------------------------------------*/\r
289 \r
290 /* Called by vApplicationTickHook(), which is defined in main.c. */\r
291 void vFullDemoTickHookFunction( void )\r
292 {\r
293 TaskHandle_t xTimerTask;\r
294 \r
295         /* Call the periodic timer test, which tests the timer API functions that\r
296         can be called from an ISR. */\r
297         #if( configUSE_PREEMPTION != 0 )\r
298         {\r
299                 /* Only created when preemption is used. */\r
300                 vTimerPeriodicISRTests();\r
301         }\r
302         #endif\r
303 \r
304         /* Call the periodic queue overwrite from ISR demo. */\r
305         vQueueOverwritePeriodicISRDemo();\r
306 \r
307         /* Write to a queue that is in use as part of the queue set demo to\r
308         demonstrate using queue sets from an ISR. */\r
309         vQueueSetAccessQueueSetFromISR();\r
310         vQueueSetPollingInterruptAccess();\r
311 \r
312         /* Exercise event groups from interrupts. */\r
313         vPeriodicEventGroupsProcessing();\r
314 \r
315         /* Exercise giving mutexes from an interrupt. */\r
316         vInterruptSemaphorePeriodicTest();\r
317 \r
318         /* Exercise using task notifications from an interrupt. */\r
319         xNotifyTaskFromISR();\r
320 \r
321         /* Writes to stream buffer byte by byte to test the stream buffer trigger\r
322         level functionality. */\r
323         vPeriodicStreamBufferProcessing();\r
324 \r
325         /* Writes a string to a string buffer four bytes at a time to demonstrate\r
326         a stream being sent from an interrupt to a task. */\r
327         vBasicStreamBufferSendFromISR();\r
328 }\r
329 /*-----------------------------------------------------------*/\r
330 \r