2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
69 #ifndef INC_FREERTOS_H
\r
70 #error "include FreeRTOS.h must appear in source files before include task.h"
\r
79 /*-----------------------------------------------------------
\r
80 * MACROS AND DEFINITIONS
\r
81 *----------------------------------------------------------*/
\r
83 #define tskKERNEL_VERSION_NUMBER "V7.5.0"
\r
88 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
89 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
90 * be used as a parameter to vTaskDelete to delete the task.
\r
92 * \defgroup xTaskHandle xTaskHandle
\r
95 typedef void * xTaskHandle;
\r
97 /* Task states returned by eTaskGetState. */
\r
100 eRunning = 0, /* A task is querying the state of itself, so must be running. */
\r
101 eReady, /* The task being queried is in a read or pending ready list. */
\r
102 eBlocked, /* The task being queried is in the Blocked state. */
\r
103 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
\r
104 eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */
\r
108 * Used internally only.
\r
110 typedef struct xTIME_OUT
\r
112 portBASE_TYPE xOverflowCount;
\r
113 portTickType xTimeOnEntering;
\r
117 * Defines the memory ranges allocated to the task when an MPU is used.
\r
119 typedef struct xMEMORY_REGION
\r
121 void *pvBaseAddress;
\r
122 unsigned long ulLengthInBytes;
\r
123 unsigned long ulParameters;
\r
127 * Parameters required to create an MPU protected task.
\r
129 typedef struct xTASK_PARAMTERS
\r
131 pdTASK_CODE pvTaskCode;
\r
132 const signed char * const pcName;
\r
133 unsigned short usStackDepth;
\r
134 void *pvParameters;
\r
135 unsigned portBASE_TYPE uxPriority;
\r
136 portSTACK_TYPE *puxStackBuffer;
\r
137 xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
\r
140 /* Used with the uxTaskGetSystemState() function to return the state of each task
\r
142 typedef struct xTASK_STATUS
\r
144 xTaskHandle xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
\r
145 const signed char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */
\r
146 unsigned portBASE_TYPE xTaskNumber; /* A number unique to the task. */
\r
147 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
\r
148 unsigned portBASE_TYPE uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
\r
149 unsigned portBASE_TYPE uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
\r
150 unsigned long ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
\r
151 unsigned short usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
\r
154 /* Possible return values for eTaskConfirmSleepModeStatus(). */
\r
157 eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
\r
158 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
\r
159 eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
\r
160 } eSleepModeStatus;
\r
164 * Defines the priority used by the idle task. This must not be modified.
\r
166 * \ingroup TaskUtils
\r
168 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0U )
\r
173 * Macro for forcing a context switch.
\r
175 * \defgroup taskYIELD taskYIELD
\r
176 * \ingroup SchedulerControl
\r
178 #define taskYIELD() portYIELD()
\r
183 * Macro to mark the start of a critical code region. Preemptive context
\r
184 * switches cannot occur when in a critical region.
\r
186 * NOTE: This may alter the stack (depending on the portable implementation)
\r
187 * so must be used with care!
\r
189 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
\r
190 * \ingroup SchedulerControl
\r
192 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
197 * Macro to mark the end of a critical code region. Preemptive context
\r
198 * switches cannot occur when in a critical region.
\r
200 * NOTE: This may alter the stack (depending on the portable implementation)
\r
201 * so must be used with care!
\r
203 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
204 * \ingroup SchedulerControl
\r
206 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
211 * Macro to disable all maskable interrupts.
\r
213 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
214 * \ingroup SchedulerControl
\r
216 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
221 * Macro to enable microcontroller interrupts.
\r
223 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
224 * \ingroup SchedulerControl
\r
226 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
228 /* Definitions returned by xTaskGetSchedulerState(). */
\r
229 #define taskSCHEDULER_NOT_STARTED ( ( portBASE_TYPE ) 0 )
\r
230 #define taskSCHEDULER_RUNNING ( ( portBASE_TYPE ) 1 )
\r
231 #define taskSCHEDULER_SUSPENDED ( ( portBASE_TYPE ) 2 )
\r
233 /*-----------------------------------------------------------
\r
234 * TASK CREATION API
\r
235 *----------------------------------------------------------*/
\r
240 portBASE_TYPE xTaskCreate(
\r
241 pdTASK_CODE pvTaskCode,
\r
242 const char * const pcName,
\r
243 unsigned short usStackDepth,
\r
244 void *pvParameters,
\r
245 unsigned portBASE_TYPE uxPriority,
\r
246 xTaskHandle *pvCreatedTask
\r
249 * Create a new task and add it to the list of tasks that are ready to run.
\r
251 * xTaskCreate() can only be used to create a task that has unrestricted
\r
252 * access to the entire microcontroller memory map. Systems that include MPU
\r
253 * support can alternatively create an MPU constrained task using
\r
254 * xTaskCreateRestricted().
\r
256 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
257 * must be implemented to never return (i.e. continuous loop).
\r
259 * @param pcName A descriptive name for the task. This is mainly used to
\r
260 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
263 * @param usStackDepth The size of the task stack specified as the number of
\r
264 * variables the stack can hold - not the number of bytes. For example, if
\r
265 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
266 * will be allocated for stack storage.
\r
268 * @param pvParameters Pointer that will be used as the parameter for the task
\r
271 * @param uxPriority The priority at which the task should run. Systems that
\r
272 * include MPU support can optionally create tasks in a privileged (system)
\r
273 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
\r
274 * example, to create a privileged task at priority 2 the uxPriority parameter
\r
275 * should be set to ( 2 | portPRIVILEGE_BIT ).
\r
277 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
278 * can be referenced.
\r
280 * @return pdPASS if the task was successfully created and added to a ready
\r
281 * list, otherwise an error code defined in the file errors. h
\r
285 // Task to be created.
\r
286 void vTaskCode( void * pvParameters )
\r
290 // Task code goes here.
\r
294 // Function that creates a task.
\r
295 void vOtherFunction( void )
\r
297 static unsigned char ucParameterToPass;
\r
298 xTaskHandle xHandle;
\r
300 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
\r
301 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
\r
302 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
\r
303 // the new task attempts to access it.
\r
304 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
306 // Use the handle to delete the task.
\r
307 vTaskDelete( xHandle );
\r
310 * \defgroup xTaskCreate xTaskCreate
\r
313 #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
\r
318 portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle *pxCreatedTask );</pre>
\r
320 * xTaskCreateRestricted() should only be used in systems that include an MPU
\r
323 * Create a new task and add it to the list of tasks that are ready to run.
\r
324 * The function parameters define the memory regions and associated access
\r
325 * permissions allocated to the task.
\r
327 * @param pxTaskDefinition Pointer to a structure that contains a member
\r
328 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
\r
329 * documentation) plus an optional stack buffer and the memory region
\r
332 * @param pxCreatedTask Used to pass back a handle by which the created task
\r
333 * can be referenced.
\r
335 * @return pdPASS if the task was successfully created and added to a ready
\r
336 * list, otherwise an error code defined in the file errors. h
\r
340 // Create an xTaskParameters structure that defines the task to be created.
\r
341 static const xTaskParameters xCheckTaskParameters =
\r
343 vATask, // pvTaskCode - the function that implements the task.
\r
344 "ATask", // pcName - just a text name for the task to assist debugging.
\r
345 100, // usStackDepth - the stack size DEFINED IN WORDS.
\r
346 NULL, // pvParameters - passed into the task function as the function parameters.
\r
347 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
\r
348 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
\r
350 // xRegions - Allocate up to three separate memory regions for access by
\r
351 // the task, with appropriate access permissions. Different processors have
\r
352 // different memory alignment requirements - refer to the FreeRTOS documentation
\r
353 // for full information.
\r
355 // Base address Length Parameters
\r
356 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
\r
357 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
\r
358 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
\r
364 xTaskHandle xHandle;
\r
366 // Create a task from the const structure defined above. The task handle
\r
367 // is requested (the second parameter is not NULL) but in this case just for
\r
368 // demonstration purposes as its not actually used.
\r
369 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
\r
371 // Start the scheduler.
\r
372 vTaskStartScheduler();
\r
374 // Will only get here if there was insufficient memory to create the idle
\r
379 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
\r
382 #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )
\r
387 void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre>
\r
389 * Memory regions are assigned to a restricted task when the task is created by
\r
390 * a call to xTaskCreateRestricted(). These regions can be redefined using
\r
391 * vTaskAllocateMPURegions().
\r
393 * @param xTask The handle of the task being updated.
\r
395 * @param xRegions A pointer to an xMemoryRegion structure that contains the
\r
396 * new memory region definitions.
\r
400 // Define an array of xMemoryRegion structures that configures an MPU region
\r
401 // allowing read/write access for 1024 bytes starting at the beginning of the
\r
402 // ucOneKByte array. The other two of the maximum 3 definable regions are
\r
403 // unused so set to zero.
\r
404 static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
\r
406 // Base address Length Parameters
\r
407 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
\r
412 void vATask( void *pvParameters )
\r
414 // This task was created such that it has access to certain regions of
\r
415 // memory as defined by the MPU configuration. At some point it is
\r
416 // desired that these MPU regions are replaced with that defined in the
\r
417 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
\r
418 // for this purpose. NULL is used as the task handle to indicate that this
\r
419 // function should modify the MPU regions of the calling task.
\r
420 vTaskAllocateMPURegions( NULL, xAltRegions );
\r
422 // Now the task can continue its function, but from this point on can only
\r
423 // access its stack and the ucOneKByte array (unless any other statically
\r
424 // defined or shared regions have been declared elsewhere).
\r
427 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
\r
430 void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION;
\r
434 * <pre>void vTaskDelete( xTaskHandle xTask );</pre>
\r
436 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
437 * See the configuration section for more information.
\r
439 * Remove a task from the RTOS real time kernels management. The task being
\r
440 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
442 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
443 * memory from tasks that have been deleted. It is therefore important that
\r
444 * the idle task is not starved of microcontroller processing time if your
\r
445 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
446 * task code is not automatically freed, and should be freed before the task
\r
449 * See the demo application file death.c for sample code that utilises
\r
452 * @param xTask The handle of the task to be deleted. Passing NULL will
\r
453 * cause the calling task to be deleted.
\r
457 void vOtherFunction( void )
\r
459 xTaskHandle xHandle;
\r
461 // Create the task, storing the handle.
\r
462 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
464 // Use the handle to delete the task.
\r
465 vTaskDelete( xHandle );
\r
468 * \defgroup vTaskDelete vTaskDelete
\r
471 void vTaskDelete( xTaskHandle xTaskToDelete ) PRIVILEGED_FUNCTION;
\r
473 /*-----------------------------------------------------------
\r
475 *----------------------------------------------------------*/
\r
479 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
481 * Delay a task for a given number of ticks. The actual time that the
\r
482 * task remains blocked depends on the tick rate. The constant
\r
483 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
484 * rate - with the resolution of one tick period.
\r
486 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
487 * See the configuration section for more information.
\r
490 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
\r
491 * the time at which vTaskDelay() is called. For example, specifying a block
\r
492 * period of 100 ticks will cause the task to unblock 100 ticks after
\r
493 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
\r
494 * of controlling the frequency of a cyclical task as the path taken through the
\r
495 * code, as well as other task and interrupt activity, will effect the frequency
\r
496 * at which vTaskDelay() gets called and therefore the time at which the task
\r
497 * next executes. See vTaskDelayUntil() for an alternative API function designed
\r
498 * to facilitate fixed frequency execution. It does this by specifying an
\r
499 * absolute time (rather than a relative time) at which the calling task should
\r
502 * @param xTicksToDelay The amount of time, in tick periods, that
\r
503 * the calling task should block.
\r
507 void vTaskFunction( void * pvParameters )
\r
509 void vTaskFunction( void * pvParameters )
\r
511 // Block for 500ms.
\r
512 const portTickType xDelay = 500 / portTICK_RATE_MS;
\r
516 // Simply toggle the LED every 500ms, blocking between each toggle.
\r
518 vTaskDelay( xDelay );
\r
522 * \defgroup vTaskDelay vTaskDelay
\r
523 * \ingroup TaskCtrl
\r
525 void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION;
\r
529 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
531 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
532 * See the configuration section for more information.
\r
534 * Delay a task until a specified time. This function can be used by cyclical
\r
535 * tasks to ensure a constant execution frequency.
\r
537 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
538 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
539 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
540 * execution frequency as the time between a task starting to execute and that task
\r
541 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
542 * code between calls, or may get interrupted or preempted a different number of times
\r
543 * each time it executes].
\r
545 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
546 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
549 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
550 * rate - with the resolution of one tick period.
\r
552 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
553 * task was last unblocked. The variable must be initialised with the current time
\r
554 * prior to its first use (see the example below). Following this the variable is
\r
555 * automatically updated within vTaskDelayUntil ().
\r
557 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
558 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
559 * same xTimeIncrement parameter value will cause the task to execute with
\r
560 * a fixed interface period.
\r
564 // Perform an action every 10 ticks.
\r
565 void vTaskFunction( void * pvParameters )
\r
567 portTickType xLastWakeTime;
\r
568 const portTickType xFrequency = 10;
\r
570 // Initialise the xLastWakeTime variable with the current time.
\r
571 xLastWakeTime = xTaskGetTickCount ();
\r
574 // Wait for the next cycle.
\r
575 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
577 // Perform action here.
\r
581 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
582 * \ingroup TaskCtrl
\r
584 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION;
\r
588 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask );</pre>
\r
590 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
591 * See the configuration section for more information.
\r
593 * Obtain the priority of any task.
\r
595 * @param xTask Handle of the task to be queried. Passing a NULL
\r
596 * handle results in the priority of the calling task being returned.
\r
598 * @return The priority of xTask.
\r
602 void vAFunction( void )
\r
604 xTaskHandle xHandle;
\r
606 // Create a task, storing the handle.
\r
607 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
611 // Use the handle to obtain the priority of the created task.
\r
612 // It was created with tskIDLE_PRIORITY, but may have changed
\r
614 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
616 // The task has changed it's priority.
\r
621 // Is our priority higher than the created task?
\r
622 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
624 // Our priority (obtained using NULL handle) is higher.
\r
628 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
629 * \ingroup TaskCtrl
\r
631 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
635 * <pre>eTaskState eTaskGetState( xTaskHandle xTask );</pre>
\r
637 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
\r
638 * See the configuration section for more information.
\r
640 * Obtain the state of any task. States are encoded by the eTaskState
\r
643 * @param xTask Handle of the task to be queried.
\r
645 * @return The state of xTask at the time the function was called. Note the
\r
646 * state of the task might change between the function being called, and the
\r
647 * functions return value being tested by the calling task.
\r
649 eTaskState eTaskGetState( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
653 * <pre>void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
655 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
656 * See the configuration section for more information.
\r
658 * Set the priority of any task.
\r
660 * A context switch will occur before the function returns if the priority
\r
661 * being set is higher than the currently executing task.
\r
663 * @param xTask Handle to the task for which the priority is being set.
\r
664 * Passing a NULL handle results in the priority of the calling task being set.
\r
666 * @param uxNewPriority The priority to which the task will be set.
\r
670 void vAFunction( void )
\r
672 xTaskHandle xHandle;
\r
674 // Create a task, storing the handle.
\r
675 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
679 // Use the handle to raise the priority of the created task.
\r
680 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
684 // Use a NULL handle to raise our priority to the same value.
\r
685 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
688 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
689 * \ingroup TaskCtrl
\r
691 void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION;
\r
695 * <pre>void vTaskSuspend( xTaskHandle xTaskToSuspend );</pre>
\r
697 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
698 * See the configuration section for more information.
\r
700 * Suspend any task. When suspended a task will never get any microcontroller
\r
701 * processing time, no matter what its priority.
\r
703 * Calls to vTaskSuspend are not accumulative -
\r
704 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
705 * call to vTaskResume () to ready the suspended task.
\r
707 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
708 * handle will cause the calling task to be suspended.
\r
712 void vAFunction( void )
\r
714 xTaskHandle xHandle;
\r
716 // Create a task, storing the handle.
\r
717 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
721 // Use the handle to suspend the created task.
\r
722 vTaskSuspend( xHandle );
\r
726 // The created task will not run during this period, unless
\r
727 // another task calls vTaskResume( xHandle ).
\r
732 // Suspend ourselves.
\r
733 vTaskSuspend( NULL );
\r
735 // We cannot get here unless another task calls vTaskResume
\r
736 // with our handle as the parameter.
\r
739 * \defgroup vTaskSuspend vTaskSuspend
\r
740 * \ingroup TaskCtrl
\r
742 void vTaskSuspend( xTaskHandle xTaskToSuspend ) PRIVILEGED_FUNCTION;
\r
746 * <pre>void vTaskResume( xTaskHandle xTaskToResume );</pre>
\r
748 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
749 * See the configuration section for more information.
\r
751 * Resumes a suspended task.
\r
753 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
754 * will be made available for running again by a single call to
\r
757 * @param xTaskToResume Handle to the task being readied.
\r
761 void vAFunction( void )
\r
763 xTaskHandle xHandle;
\r
765 // Create a task, storing the handle.
\r
766 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
770 // Use the handle to suspend the created task.
\r
771 vTaskSuspend( xHandle );
\r
775 // The created task will not run during this period, unless
\r
776 // another task calls vTaskResume( xHandle ).
\r
781 // Resume the suspended task ourselves.
\r
782 vTaskResume( xHandle );
\r
784 // The created task will once again get microcontroller processing
\r
785 // time in accordance with it priority within the system.
\r
788 * \defgroup vTaskResume vTaskResume
\r
789 * \ingroup TaskCtrl
\r
791 void vTaskResume( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;
\r
795 * <pre>void xTaskResumeFromISR( xTaskHandle xTaskToResume );</pre>
\r
797 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
798 * available. See the configuration section for more information.
\r
800 * An implementation of vTaskResume() that can be called from within an ISR.
\r
802 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
803 * will be made available for running again by a single call to
\r
804 * xTaskResumeFromISR ().
\r
806 * @param xTaskToResume Handle to the task being readied.
\r
808 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
809 * \ingroup TaskCtrl
\r
811 portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;
\r
813 /*-----------------------------------------------------------
\r
814 * SCHEDULER CONTROL
\r
815 *----------------------------------------------------------*/
\r
819 * <pre>void vTaskStartScheduler( void );</pre>
\r
821 * Starts the real time kernel tick processing. After calling the kernel
\r
822 * has control over which tasks are executed and when. This function
\r
823 * does not return until an executing task calls vTaskEndScheduler ().
\r
825 * At least one task should be created via a call to xTaskCreate ()
\r
826 * before calling vTaskStartScheduler (). The idle task is created
\r
827 * automatically when the first application task is created.
\r
829 * See the demo application file main.c for an example of creating
\r
830 * tasks and starting the kernel.
\r
834 void vAFunction( void )
\r
836 // Create at least one task before starting the kernel.
\r
837 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
839 // Start the real time kernel with preemption.
\r
840 vTaskStartScheduler ();
\r
842 // Will not get here unless a task calls vTaskEndScheduler ()
\r
846 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
847 * \ingroup SchedulerControl
\r
849 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
\r
853 * <pre>void vTaskEndScheduler( void );</pre>
\r
855 * Stops the real time kernel tick. All created tasks will be automatically
\r
856 * deleted and multitasking (either preemptive or cooperative) will
\r
857 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
858 * was called, as if vTaskStartScheduler () had just returned.
\r
860 * See the demo application file main. c in the demo/PC directory for an
\r
861 * example that uses vTaskEndScheduler ().
\r
863 * vTaskEndScheduler () requires an exit function to be defined within the
\r
864 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
865 * performs hardware specific operations such as stopping the kernel tick.
\r
867 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
868 * kernel to be freed - but will not free resources allocated by application
\r
873 void vTaskCode( void * pvParameters )
\r
877 // Task code goes here.
\r
879 // At some point we want to end the real time kernel processing
\r
881 vTaskEndScheduler ();
\r
885 void vAFunction( void )
\r
887 // Create at least one task before starting the kernel.
\r
888 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
890 // Start the real time kernel with preemption.
\r
891 vTaskStartScheduler ();
\r
893 // Will only get here when the vTaskCode () task has called
\r
894 // vTaskEndScheduler (). When we get here we are back to single task
\r
899 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
900 * \ingroup SchedulerControl
\r
902 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
\r
906 * <pre>void vTaskSuspendAll( void );</pre>
\r
908 * Suspends all real time kernel activity while keeping interrupts (including the
\r
909 * kernel tick) enabled.
\r
911 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
912 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
915 * API functions that have the potential to cause a context switch (for example,
\r
916 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
\r
921 void vTask1( void * pvParameters )
\r
925 // Task code goes here.
\r
929 // At some point the task wants to perform a long operation during
\r
930 // which it does not want to get swapped out. It cannot use
\r
931 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
932 // operation may cause interrupts to be missed - including the
\r
935 // Prevent the real time kernel swapping out the task.
\r
936 vTaskSuspendAll ();
\r
938 // Perform the operation here. There is no need to use critical
\r
939 // sections as we have all the microcontroller processing time.
\r
940 // During this time interrupts will still operate and the kernel
\r
941 // tick count will be maintained.
\r
945 // The operation is complete. Restart the kernel.
\r
950 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
951 * \ingroup SchedulerControl
\r
953 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
\r
957 * <pre>char xTaskResumeAll( void );</pre>
\r
959 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
960 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
961 * task is executing at any time.
\r
963 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
964 * returned, otherwise pdFALSE is returned.
\r
968 void vTask1( void * pvParameters )
\r
972 // Task code goes here.
\r
976 // At some point the task wants to perform a long operation during
\r
977 // which it does not want to get swapped out. It cannot use
\r
978 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
979 // operation may cause interrupts to be missed - including the
\r
982 // Prevent the real time kernel swapping out the task.
\r
983 vTaskSuspendAll ();
\r
985 // Perform the operation here. There is no need to use critical
\r
986 // sections as we have all the microcontroller processing time.
\r
987 // During this time interrupts will still operate and the real
\r
988 // time kernel tick count will be maintained.
\r
992 // The operation is complete. Restart the kernel. We want to force
\r
993 // a context switch - but there is no point if resuming the scheduler
\r
994 // caused a context switch already.
\r
995 if( !xTaskResumeAll () )
\r
1002 * \defgroup xTaskResumeAll xTaskResumeAll
\r
1003 * \ingroup SchedulerControl
\r
1005 signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
\r
1009 * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( const xTaskHandle xTask );</pre>
\r
1011 * Utility task that simply returns pdTRUE if the task referenced by xTask is
\r
1012 * currently in the Suspended state, or pdFALSE if the task referenced by xTask
\r
1013 * is in any other state.
\r
1016 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1018 /*-----------------------------------------------------------
\r
1020 *----------------------------------------------------------*/
\r
1024 * <PRE>portTickType xTaskGetTickCount( void );</PRE>
\r
1026 * @return The count of ticks since vTaskStartScheduler was called.
\r
1028 * \defgroup xTaskGetTickCount xTaskGetTickCount
\r
1029 * \ingroup TaskUtils
\r
1031 portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
\r
1035 * <PRE>portTickType xTaskGetTickCountFromISR( void );</PRE>
\r
1037 * @return The count of ticks since vTaskStartScheduler was called.
\r
1039 * This is a version of xTaskGetTickCount() that is safe to be called from an
\r
1040 * ISR - provided that portTickType is the natural word size of the
\r
1041 * microcontroller being used or interrupt nesting is either not supported or
\r
1044 * \defgroup xTaskGetTickCount xTaskGetTickCount
\r
1045 * \ingroup TaskUtils
\r
1047 portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
\r
1051 * <PRE>unsigned short uxTaskGetNumberOfTasks( void );</PRE>
\r
1053 * @return The number of tasks that the real time kernel is currently managing.
\r
1054 * This includes all ready, blocked and suspended tasks. A task that
\r
1055 * has been deleted but not yet freed by the idle task will also be
\r
1056 * included in the count.
\r
1058 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
1059 * \ingroup TaskUtils
\r
1061 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
\r
1065 * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE>
\r
1067 * @return The text (human readable) name of the task referenced by the handle
\r
1068 * xTaskToQueury. A task can query its own name by either passing in its own
\r
1069 * handle, or by setting xTaskToQuery to NULL. INCLUDE_pcTaskGetTaskName must be
\r
1070 * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
\r
1072 * \defgroup pcTaskGetTaskName pcTaskGetTaskName
\r
1073 * \ingroup TaskUtils
\r
1075 signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );
\r
1079 * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
\r
1081 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
\r
1082 * this function to be available.
\r
1084 * Returns the high water mark of the stack associated with xTask. That is,
\r
1085 * the minimum free stack space there has been (in words, so on a 32 bit machine
\r
1086 * a value of 1 means 4 bytes) since the task started. The smaller the returned
\r
1087 * number the closer the task has come to overflowing its stack.
\r
1089 * @param xTask Handle of the task associated with the stack to be checked.
\r
1090 * Set xTask to NULL to check the stack of the calling task.
\r
1092 * @return The smallest amount of free stack space there has been (in bytes)
\r
1093 * since the task referenced by xTask was created.
\r
1095 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1097 /* When using trace macros it is sometimes necessary to include tasks.h before
\r
1098 FreeRTOS.h. When this is done pdTASK_HOOK_CODE will not yet have been defined,
\r
1099 so the following two prototypes will cause a compilation error. This can be
\r
1100 fixed by simply guarding against the inclusion of these two prototypes unless
\r
1101 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
\r
1103 #ifdef configUSE_APPLICATION_TASK_TAG
\r
1104 #if configUSE_APPLICATION_TASK_TAG == 1
\r
1107 * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
1109 * Sets pxHookFunction to be the task hook function used by the task xTask.
\r
1110 * Passing xTask as NULL has the effect of setting the calling tasks hook
\r
1113 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION;
\r
1117 * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre>
\r
1119 * Returns the pxHookFunction value assigned to the task xTask.
\r
1121 pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1122 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
\r
1123 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
\r
1127 * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
1129 * Calls the hook function associated with xTask. Passing xTask as NULL has
\r
1130 * the effect of calling the Running tasks (the calling task) hook function.
\r
1132 * pvParameter is passed to the hook function for the task to interpret as it
\r
1135 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
\r
1138 * xTaskGetIdleTaskHandle() is only available if
\r
1139 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
\r
1141 * Simply returns the handle of the idle task. It is not valid to call
\r
1142 * xTaskGetIdleTaskHandle() before the scheduler has been started.
\r
1144 xTaskHandle xTaskGetIdleTaskHandle( void );
\r
1147 * configUSE_TRACE_FACILITY must bet defined as 1 in FreeRTOSConfig.h for
\r
1148 * uxTaskGetSystemState() to be available.
\r
1150 * uxTaskGetSystemState() populates an xTaskStatusType structure for each task in
\r
1151 * the system. xTaskStatusType structures contain, among other things, members
\r
1152 * for the task handle, task name, task priority, task state, and total amount
\r
1153 * of run time consumed by the task. See the xTaskStatusType structure
\r
1154 * definition in this file for the full member list.
\r
1156 * NOTE: This function is intended for debugging use only as its use results in
\r
1157 * the scheduler remaining suspended for an extended period.
\r
1159 * @param pxTaskStatusArray A pointer to an array of xTaskStatusType structures.
\r
1160 * The array must contain at least one xTaskStatusType structure for each task
\r
1161 * that is under the control of the RTOS. The number of tasks under the control
\r
1162 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
\r
1164 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
\r
1165 * parameter. The size is specified as the number of indexes in the array, or
\r
1166 * the number of xTaskStatusType structures contained in the array, not by the
\r
1167 * number of bytes in the array.
\r
1169 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
\r
1170 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
\r
1171 * total run time (as defined by the run time stats clock, see
\r
1172 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
\r
1173 * pulTotalRunTime can be set to NULL to omit the total run time information.
\r
1175 * @return The number of xTaskStatusType structures that were populated by
\r
1176 * uxTaskGetSystemState(). This should equal the number returned by the
\r
1177 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
\r
1178 * in the uxArraySize parameter was too small.
\r
1182 // This example demonstrates how a human readable table of run time stats
\r
1183 // information is generated from raw data provided by uxTaskGetSystemState().
\r
1184 // The human readable table is written to pcWriteBuffer
\r
1185 void vTaskGetRunTimeStats( signed char *pcWriteBuffer )
\r
1187 xTaskStatusType *pxTaskStatusArray;
\r
1188 volatile unsigned portBASE_TYPE uxArraySize, x;
\r
1189 unsigned long ulTotalRunTime, ulStatsAsPercentage;
\r
1191 // Make sure the write buffer does not contain a string.
\r
1192 *pcWriteBuffer = 0x00;
\r
1194 // Take a snapshot of the number of tasks in case it changes while this
\r
1195 // function is executing.
\r
1196 uxArraySize = uxCurrentNumberOfTasks();
\r
1198 // Allocate a xTaskStatusType structure for each task. An array could be
\r
1199 // allocated statically at compile time.
\r
1200 pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( xTaskStatusType ) );
\r
1202 if( pxTaskStatusArray != NULL )
\r
1204 // Generate raw status information about each task.
\r
1205 uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
\r
1207 // For percentage calculations.
\r
1208 ulTotalRunTime /= 100UL;
\r
1210 // Avoid divide by zero errors.
\r
1211 if( ulTotalRunTime > 0 )
\r
1213 // For each populated position in the pxTaskStatusArray array,
\r
1214 // format the raw data as human readable ASCII data
\r
1215 for( x = 0; x < uxArraySize; x++ )
\r
1217 // What percentage of the total run time has the task used?
\r
1218 // This will always be rounded down to the nearest integer.
\r
1219 // ulTotalRunTimeDiv100 has already been divided by 100.
\r
1220 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
\r
1222 if( ulStatsAsPercentage > 0UL )
\r
1224 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
\r
1228 // If the percentage is zero here then the task has
\r
1229 // consumed less than 1% of the total run time.
\r
1230 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
\r
1233 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
\r
1237 // The array is no longer needed, free the memory it consumes.
\r
1238 vPortFree( pxTaskStatusArray );
\r
1243 unsigned portBASE_TYPE uxTaskGetSystemState( xTaskStatusType *pxTaskStatusArray, unsigned portBASE_TYPE uxArraySize, unsigned long *pulTotalRunTime );
\r
1247 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
\r
1249 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
\r
1250 * both be defined as 1 for this function to be available. See the
\r
1251 * configuration section of the FreeRTOS.org website for more information.
\r
1253 * NOTE 1: This function will disable interrupts for its duration. It is
\r
1254 * not intended for normal application runtime use but as a debug aid.
\r
1256 * Lists all the current tasks, along with their current state and stack
\r
1257 * usage high water mark.
\r
1259 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
1260 * suspended ('S').
\r
1264 * This function is provided for convenience only, and is used by many of the
\r
1265 * demo applications. Do not consider it to be part of the scheduler.
\r
1267 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
\r
1268 * uxTaskGetSystemState() output into a human readable table that displays task
\r
1269 * names, states and stack usage.
\r
1271 * vTaskList() has a dependency on the sprintf() C library function that might
\r
1272 * bloat the code size, use a lot of stack, and provide different results on
\r
1273 * different platforms. An alternative, tiny, third party, and limited
\r
1274 * functionality implementation of sprintf() is provided in many of the
\r
1275 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
\r
1276 * printf-stdarg.c does not provide a full snprintf() implementation!).
\r
1278 * It is recommended that production systems call uxTaskGetSystemState()
\r
1279 * directly to get access to raw stats data, rather than indirectly through a
\r
1280 * call to vTaskList().
\r
1282 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
1283 * will be written, in ascii form. This buffer is assumed to be large
\r
1284 * enough to contain the generated report. Approximately 40 bytes per
\r
1285 * task should be sufficient.
\r
1287 * \defgroup vTaskList vTaskList
\r
1288 * \ingroup TaskUtils
\r
1290 void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
\r
1294 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
\r
1296 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
\r
1297 * must both be defined as 1 for this function to be available. The application
\r
1298 * must also then provide definitions for
\r
1299 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE
\r
1300 * to configure a peripheral timer/counter and return the timers current count
\r
1301 * value respectively. The counter should be at least 10 times the frequency of
\r
1304 * NOTE 1: This function will disable interrupts for its duration. It is
\r
1305 * not intended for normal application runtime use but as a debug aid.
\r
1307 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
\r
1308 * accumulated execution time being stored for each task. The resolution
\r
1309 * of the accumulated time value depends on the frequency of the timer
\r
1310 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
\r
1311 * Calling vTaskGetRunTimeStats() writes the total execution time of each
\r
1312 * task into a buffer, both as an absolute count value and as a percentage
\r
1313 * of the total system execution time.
\r
1317 * This function is provided for convenience only, and is used by many of the
\r
1318 * demo applications. Do not consider it to be part of the scheduler.
\r
1320 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
\r
1321 * uxTaskGetSystemState() output into a human readable table that displays the
\r
1322 * amount of time each task has spent in the Running state in both absolute and
\r
1323 * percentage terms.
\r
1325 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
\r
1326 * that might bloat the code size, use a lot of stack, and provide different
\r
1327 * results on different platforms. An alternative, tiny, third party, and
\r
1328 * limited functionality implementation of sprintf() is provided in many of the
\r
1329 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
\r
1330 * printf-stdarg.c does not provide a full snprintf() implementation!).
\r
1332 * It is recommended that production systems call uxTaskGetSystemState() directly
\r
1333 * to get access to raw stats data, rather than indirectly through a call to
\r
1334 * vTaskGetRunTimeStats().
\r
1336 * @param pcWriteBuffer A buffer into which the execution times will be
\r
1337 * written, in ascii form. This buffer is assumed to be large enough to
\r
1338 * contain the generated report. Approximately 40 bytes per task should
\r
1341 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
\r
1342 * \ingroup TaskUtils
\r
1344 void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
\r
1346 /*-----------------------------------------------------------
\r
1347 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
1348 *----------------------------------------------------------*/
\r
1351 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
1352 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
1353 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1355 * Called from the real time kernel tick (either preemptive or cooperative),
\r
1356 * this increments the tick count and checks if any tasks that are blocked
\r
1357 * for a finite period required removing from a blocked list and placing on
\r
1358 * a ready list. If a non-zero value is returned then a context switch is
\r
1359 * required because either:
\r
1360 * + A task was removed from a blocked list because its timeout had expired,
\r
1362 * + Time slicing is in use and there is a task of equal priority to the
\r
1363 * currently running task.
\r
1365 portBASE_TYPE xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
\r
1368 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1369 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1371 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1373 * Removes the calling task from the ready list and places it both
\r
1374 * on the list of tasks waiting for a particular event, and the
\r
1375 * list of delayed tasks. The task will be removed from both lists
\r
1376 * and replaced on the ready list should either the event occur (and
\r
1377 * there be no higher priority tasks waiting on the same event) or
\r
1378 * the delay period expires.
\r
1380 * @param pxEventList The list containing tasks that are blocked waiting
\r
1381 * for the event to occur.
\r
1383 * @param xTicksToWait The maximum amount of time that the task should wait
\r
1384 * for the event to occur. This is specified in kernel ticks,the constant
\r
1385 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
1388 void vTaskPlaceOnEventList( xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1391 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1392 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1394 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1396 * This function performs nearly the same function as vTaskPlaceOnEventList().
\r
1397 * The difference being that this function does not permit tasks to block
\r
1398 * indefinitely, whereas vTaskPlaceOnEventList() does.
\r
1400 * @return pdTRUE if the task being removed has a higher priority than the task
\r
1401 * making the call, otherwise pdFALSE.
\r
1403 void vTaskPlaceOnEventListRestricted( xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1406 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1407 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1409 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1411 * Removes a task from both the specified event list and the list of blocked
\r
1412 * tasks, and places it on a ready queue.
\r
1414 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
1415 * unblock a task, or the block timeout period expires.
\r
1417 * @return pdTRUE if the task being removed has a higher priority than the task
\r
1418 * making the call, otherwise pdFALSE.
\r
1420 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION;
\r
1423 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
1424 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
1425 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1427 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
1428 * that is ready to run.
\r
1430 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
\r
1433 * Return the handle of the calling task.
\r
1435 xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
\r
1438 * Capture the current time status for future reference.
\r
1440 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION;
\r
1443 * Compare the time status now with that previously captured to see if the
\r
1444 * timeout has expired.
\r
1446 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION;
\r
1449 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
1452 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
\r
1455 * Returns the scheduler state as taskSCHEDULER_RUNNING,
\r
1456 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
\r
1458 portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
\r
1461 * Raises the priority of the mutex holder to that of the calling task should
\r
1462 * the mutex holder have a priority less than the calling task.
\r
1464 void vTaskPriorityInherit( xTaskHandle const pxMutexHolder ) PRIVILEGED_FUNCTION;
\r
1467 * Set the priority of a task back to its proper priority in the case that it
\r
1468 * inherited a higher priority while it was holding a semaphore.
\r
1470 void vTaskPriorityDisinherit( xTaskHandle const pxMutexHolder ) PRIVILEGED_FUNCTION;
\r
1473 * Generic version of the task creation function which is in turn called by the
\r
1474 * xTaskCreate() and xTaskCreateRestricted() macros.
\r
1476 signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) PRIVILEGED_FUNCTION;
\r
1479 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
\r
1481 unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
\r
1484 * Set the uxTCBNumber of the task referenced by the xTask parameter to
\r
1487 void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );
\r
1490 * If tickless mode is being used, or a low power mode is implemented, then
\r
1491 * the tick interrupt will not execute during idle periods. When this is the
\r
1492 * case, the tick count value maintained by the scheduler needs to be kept up
\r
1493 * to date with the actual execution time by being skipped forward by the by
\r
1494 * a time equal to the idle period.
\r
1496 void vTaskStepTick( portTickType xTicksToJump );
\r
1499 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
\r
1500 * specific sleep function to determine if it is ok to proceed with the sleep,
\r
1501 * and if it is ok to proceed, if it is ok to sleep indefinitely.
\r
1503 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
\r
1504 * called with the scheduler suspended, not from within a critical section. It
\r
1505 * is therefore possible for an interrupt to request a context switch between
\r
1506 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
\r
1507 * entered. eTaskConfirmSleepModeStatus() should be called from a short
\r
1508 * critical section between the timer being stopped and the sleep mode being
\r
1509 * entered to ensure it is ok to proceed into the sleep mode.
\r
1511 eSleepModeStatus eTaskConfirmSleepModeStatus( void );
\r
1513 #ifdef __cplusplus
\r
1516 #endif /* INC_TASK_H */
\r