2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
34 * In addition to the standard demo tasks, the following tasks and tests are
\r
35 * defined and/or created within this file:
\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
47 /* Standard includes. */
\r
51 /* Kernel includes. */
\r
52 #include <FreeRTOS.h>
\r
58 /* Standard demo includes. */
\r
60 #include "integer.h"
\r
61 #include "semtest.h"
\r
63 #include "GenQTest.h"
\r
65 #include "recmutex.h"
\r
67 #include "TimerDemo.h"
\r
68 #include "countsem.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
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
96 #define mainTIMER_TEST_PERIOD ( 50 )
\r
98 /* The task that periodically checks that all the standard demo tasks are
\r
99 * still executing and error free.
\r
101 static void prvCheckTask( void *pvParameters );
\r
103 /*-----------------------------------------------------------*/
\r
105 /* The variable into which error messages are latched. */
\r
106 static char *pcStatusMessage = "No errors";
\r
108 /*-----------------------------------------------------------*/
\r
110 int main_full( void )
\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
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
123 vStartQueuePeekTasks();
\r
124 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
125 vStartRecursiveMutexTasks();
\r
126 vStartCountingSemaphoreTasks();
\r
127 vStartDynamicPriorityTasks();
\r
128 vStartQueueSetTasks();
\r
130 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
131 vStartEventGroupTasks();
\r
132 vStartInterruptSemaphoreTasks();
\r
133 vStartQueueSetPollingTask();
\r
134 vCreateBlockTimeTasks();
\r
136 vCreateAbortDelayTasks();
\r
137 vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );
\r
139 vStartStreamBufferTasks();
\r
140 vStartStreamBufferInterruptDemo();
\r
142 #if( configUSE_PREEMPTION != 0 )
\r
144 /* Don't expect these tasks to pass when preemption is not used. */
\r
145 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\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
153 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
155 /* Start the scheduler itself. */
\r
156 vTaskStartScheduler();
\r
158 /* Should never get here unless there was not enough heap space to create
\r
159 the idle and other system tasks. */
\r
162 /*-----------------------------------------------------------*/
\r
164 static void prvCheckTask( void *pvParameters )
\r
166 TickType_t xNextWakeTime;
\r
167 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 5000UL );
\r
169 /* Just to remove compiler warning. */
\r
170 ( void ) pvParameters;
\r
172 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
173 xNextWakeTime = xTaskGetTickCount();
\r
177 /* Place this task in the blocked state until it is time to run again. */
\r
178 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );
\r
180 /* Check the standard demo tasks are running without error. */
\r
181 #if( configUSE_PREEMPTION != 0 )
\r
183 /* These tasks are only created when preemption is used. */
\r
184 if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )
\r
186 pcStatusMessage = "Error: TimerDemo";
\r
191 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
193 pcStatusMessage = "Error: Notification";
\r
195 else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
197 pcStatusMessage = "Error: IntMath";
\r
199 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
201 pcStatusMessage = "Error: GenQueue";
\r
203 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
205 pcStatusMessage = "Error: BlockQueue";
\r
207 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
209 pcStatusMessage = "Error: SemTest";
\r
211 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
213 pcStatusMessage = "Error: PollQueue";
\r
215 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
217 pcStatusMessage = "Error: QueuePeek";
\r
219 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
221 pcStatusMessage = "Error: RecMutex";
\r
223 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
225 pcStatusMessage = "Error: CountSem";
\r
227 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
229 pcStatusMessage = "Error: Dynamic";
\r
231 else if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
233 pcStatusMessage = "Error: Queue set";
\r
235 else if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
237 pcStatusMessage = "Error: EventGroup";
\r
239 else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
241 pcStatusMessage = "Error: Queue overwrite";
\r
243 else if( xAreQueueSetPollTasksStillRunning() != pdPASS )
\r
245 pcStatusMessage = "Error: Queue set polling";
\r
247 else if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
249 pcStatusMessage = "Error: Block time";
\r
251 else if( xAreMessageBufferTasksStillRunning() != pdTRUE )
\r
253 pcStatusMessage = "Error: MessageBuffer";
\r
255 else if( xAreAbortDelayTestTasksStillRunning() != pdPASS )
\r
257 pcStatusMessage = "Error: Abort delay";
\r
259 else if( xAreStreamBufferTasksStillRunning() != pdTRUE )
\r
261 pcStatusMessage = "Error: StreamBuffer";
\r
263 else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )
\r
265 pcStatusMessage = "Error: Stream buffer interrupt";
\r
267 else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
269 pcStatusMessage = "Error: IntSem";
\r
271 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
273 pcStatusMessage = "Error: Death";
\r
275 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
277 pcStatusMessage = "Error: Flop";
\r
280 /* This is the only task that uses stdout so its ok to call printf()
\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
288 /*-----------------------------------------------------------*/
\r
290 /* Called by vApplicationTickHook(), which is defined in main.c. */
\r
291 void vFullDemoTickHookFunction( void )
\r
293 TaskHandle_t xTimerTask;
\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
299 /* Only created when preemption is used. */
\r
300 vTimerPeriodicISRTests();
\r
304 /* Call the periodic queue overwrite from ISR demo. */
\r
305 vQueueOverwritePeriodicISRDemo();
\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
312 /* Exercise event groups from interrupts. */
\r
313 vPeriodicEventGroupsProcessing();
\r
315 /* Exercise giving mutexes from an interrupt. */
\r
316 vInterruptSemaphorePeriodicTest();
\r
318 /* Exercise using task notifications from an interrupt. */
\r
319 xNotifyTaskFromISR();
\r
321 /* Writes to stream buffer byte by byte to test the stream buffer trigger
\r
322 level functionality. */
\r
323 vPeriodicStreamBufferProcessing();
\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
329 /*-----------------------------------------------------------*/
\r