2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
70 /******************************************************************************
72 * This project is provided as an example of how to create a FreeRTOS project
73 * that does not need a heap. configSUPPORT_STATIC_ALLOCATION is set to 1 to
74 * allow RTOS objects to be created using statically allocated RAM, and
75 * configSUPPORT_DYNAMIC_ALLOCATION is set to 0 to remove any build dependency
76 * on the FreeRTOS heap. When configSUPPORT_DYNAMIC_ALLOCATION is set to 0
77 * pvPortMalloc() just equates to NULL, and calls to vPortFree() have no
80 * http://www.freertos.org/a00111.html and
81 * http://www.freertos.org/Static_Vs_Dynamic_Memory_Allocation.html
83 *******************************************************************************
86 /* Standard includes. */
91 /* FreeRTOS kernel includes. */
95 /* Standard demo includes. */
96 #include "StaticAllocation.h"
99 /*-----------------------------------------------------------*/
102 * Prototypes for the standard FreeRTOS stack overflow hook (callback)
103 * function. http://www.freertos.org/Stacks-and-stack-overflow-checking.html
105 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
108 * This demo has configSUPPORT_STATIC_ALLOCATION set to 1 so the following
109 * application callback function must be provided to supply the RAM that will
110 * get used for the Idle task data structures and stack.
112 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
115 * This demo has configSUPPORT_STATIC_ALLOCATION set to 1 and configUSE_TIMERS
116 * set to 1 so the following application callback function must be provided to
117 * supply the RAM that will get used for the Timer task data structures and
120 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
122 /* This demo only uses the standard demo tasks that use statically allocated
123 RAM. A 'check' task is also created to periodically inspect the demo tasks to
124 ensure they are still running, and that no errors have been detected. */
125 static void prvStartCheckTask( void );
126 static void prvCheckTask( void *pvParameters );
128 /*-----------------------------------------------------------*/
132 /* This demo has configSUPPORT_STATIC_ALLOCATION set to 1 and
133 configSUPPORT_DYNAMIC_ALLOCATION set to 0, so the only standard temo tasks
134 created are the ones that only use static allocation. This allow the
135 application to be built without including a FreeRTOS heap file (without one
136 of the heap files described on http://www.freertos.org/a00111.html */
137 vStartStaticallyAllocatedTasks();
139 /* Start a task that periodically inspects the tasks created by
140 vStartStaticallyAllocatedTasks() to ensure they are still running, and not
141 reporting any errors. */
144 /* Start the scheduler so the demo tasks start to execute. */
145 vTaskStartScheduler();
147 /* vTaskStartScheduler() would only return if RAM required by the Idle and
148 Timer tasks could not be allocated. As this demo uses statically allocated
149 RAM only, there are no allocations that could fail, and
150 vTaskStartScheduler() cannot return - so there is no need to put the normal
151 infinite loop after the call to vTaskStartScheduler(). */
155 /*-----------------------------------------------------------*/
157 static void prvStartCheckTask( void )
159 /* Allocate the data structure that will hold the task's TCB. NOTE: This is
160 declared static so it still exists after this function has returned. */
161 static StaticTask_t xCheckTask;
163 /* Allocate the stack that will be used by the task. NOTE: This is declared
164 static so it still exists after this function has returned. */
165 static StackType_t ucTaskStack[ configMINIMAL_STACK_SIZE * sizeof( StackType_t ) ];
167 /* Create the task, which will use the RAM allocated by the linker to the
168 variables declared in this function. */
169 xTaskCreateStatic( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, ucTaskStack, &xCheckTask );
171 /*-----------------------------------------------------------*/
173 static void prvCheckTask( void *pvParameters )
175 const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
176 static char *pcStatusMessage = "No errors";
178 /* Just to remove compiler warning. */
179 ( void ) pvParameters;
183 /* Place this task in the blocked state until it is time to run again. */
184 vTaskDelay( xCycleFrequency );
186 /* Check the tasks that use static allocation are still executing. */
187 if( xAreStaticAllocationTasksStillRunning() != pdPASS )
189 pcStatusMessage = "Error: Static allocation";
192 /* This is the only task that uses stdout so its ok to call printf()
194 printf( "%s - tick count %d - number of tasks executing %d\r\n",
197 uxTaskGetNumberOfTasks() );
201 /*-----------------------------------------------------------*/
202 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
207 /* Run time stack overflow checking is performed if
208 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
209 function is called if a stack overflow is detected. This function is
210 provided as an example only as stack overflow checking does not function
211 when running the FreeRTOS Windows port. */
212 vAssertCalled( __LINE__, __FILE__ );
214 /*-----------------------------------------------------------*/
216 void vAssertCalled( unsigned long ulLine, const char * const pcFileName )
218 volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
220 /* Called if an assertion passed to configASSERT() fails. See
221 http://www.freertos.org/a00110.html#configASSERT for more information. */
223 /* Parameters are not used. */
227 printf( "ASSERT! Line %d, file %s\r\n", ulLine, pcFileName );
229 taskENTER_CRITICAL();
231 /* You can step out of this function to debug the assertion by using
232 the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero
234 while( ulSetToNonZeroInDebuggerToContinue == 0 )
242 /*-----------------------------------------------------------*/
244 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
245 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
246 used by the Idle task. */
247 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
249 /* If the buffers to be provided to the Idle task are declared inside this
250 function then they must be declared static - otherwise they will be allocated on
251 the stack and so not exists after this function exits. */
252 static StaticTask_t xIdleTaskTCB;
253 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
255 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
256 state will be stored. */
257 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
259 /* Pass out the array that will be used as the Idle task's stack. */
260 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
262 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
263 Note that, as the array is necessarily of type StackType_t,
264 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
265 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
267 /*-----------------------------------------------------------*/
269 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
270 application must provide an implementation of vApplicationGetTimerTaskMemory()
271 to provide the memory that is used by the Timer service task. */
272 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
274 /* If the buffers to be provided to the Timer task are declared inside this
275 function then they must be declared static - otherwise they will be allocated on
276 the stack and so not exists after this function exits. */
277 static StaticTask_t xTimerTaskTCB;
278 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
280 /* Pass out a pointer to the StaticTask_t structure in which the Timer
281 task's state will be stored. */
282 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
284 /* Pass out the array that will be used as the Timer task's stack. */
285 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
287 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
288 Note that, as the array is necessarily of type StackType_t,
289 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
290 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;