2 FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
79 #ifndef INC_FREERTOS_H
\r
80 #error "include FreeRTOS.h must appear in source files before include task.h"
\r
83 #include "portable.h"
\r
90 /*-----------------------------------------------------------
\r
91 * MACROS AND DEFINITIONS
\r
92 *----------------------------------------------------------*/
\r
94 #define tskKERNEL_VERSION_NUMBER "V7.4.2"
\r
99 * Type by which tasks are referenced. For example, a call to xTaskCreate
\r
100 * returns (via a pointer parameter) an xTaskHandle variable that can then
\r
101 * be used as a parameter to vTaskDelete to delete the task.
\r
103 * \page xTaskHandle xTaskHandle
\r
106 typedef void * xTaskHandle;
\r
108 /* Task states returned by eTaskGetState. */
\r
111 eRunning = 0, /* A task is querying the state of itself, so must be running. */
\r
112 eReady, /* The task being queried is in a read or pending ready list. */
\r
113 eBlocked, /* The task being queried is in the Blocked state. */
\r
114 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
\r
115 eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */
\r
119 * Used internally only.
\r
121 typedef struct xTIME_OUT
\r
123 portBASE_TYPE xOverflowCount;
\r
124 portTickType xTimeOnEntering;
\r
128 * Defines the memory ranges allocated to the task when an MPU is used.
\r
130 typedef struct xMEMORY_REGION
\r
132 void *pvBaseAddress;
\r
133 unsigned long ulLengthInBytes;
\r
134 unsigned long ulParameters;
\r
138 * Parameters required to create an MPU protected task.
\r
140 typedef struct xTASK_PARAMTERS
\r
142 pdTASK_CODE pvTaskCode;
\r
143 const signed char * const pcName;
\r
144 unsigned short usStackDepth;
\r
145 void *pvParameters;
\r
146 unsigned portBASE_TYPE uxPriority;
\r
147 portSTACK_TYPE *puxStackBuffer;
\r
148 xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
\r
151 /* Used with the xTaskGetSystemState() function to return the state of each task
\r
153 typedef struct xTASK_STATUS
\r
155 xTaskHandle xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
\r
156 const signed char *pcTaskName; /* A pointer to the task's name. This valid will be invalid if the task was deleted since the structure was populated! */
\r
157 unsigned portBASE_TYPE xTaskNumber; /* A number unique to the task. */
\r
158 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
\r
159 unsigned portBASE_TYPE uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
\r
160 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 is configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
\r
161 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
162 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
165 /* Possible return values for eTaskConfirmSleepModeStatus(). */
\r
168 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
169 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
\r
170 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
171 } eSleepModeStatus;
\r
175 * Defines the priority used by the idle task. This must not be modified.
\r
177 * \ingroup TaskUtils
\r
179 #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0U )
\r
184 * Macro for forcing a context switch.
\r
186 * \page taskYIELD taskYIELD
\r
187 * \ingroup SchedulerControl
\r
189 #define taskYIELD() portYIELD()
\r
194 * Macro to mark the start of a critical code region. Preemptive context
\r
195 * switches cannot occur when in a critical region.
\r
197 * NOTE: This may alter the stack (depending on the portable implementation)
\r
198 * so must be used with care!
\r
200 * \page taskENTER_CRITICAL taskENTER_CRITICAL
\r
201 * \ingroup SchedulerControl
\r
203 #define taskENTER_CRITICAL() portENTER_CRITICAL()
\r
208 * Macro to mark the end of a critical code region. Preemptive context
\r
209 * switches cannot occur when in a critical region.
\r
211 * NOTE: This may alter the stack (depending on the portable implementation)
\r
212 * so must be used with care!
\r
214 * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
\r
215 * \ingroup SchedulerControl
\r
217 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
\r
222 * Macro to disable all maskable interrupts.
\r
224 * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
\r
225 * \ingroup SchedulerControl
\r
227 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
\r
232 * Macro to enable microcontroller interrupts.
\r
234 * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
\r
235 * \ingroup SchedulerControl
\r
237 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
\r
239 /* Definitions returned by xTaskGetSchedulerState(). */
\r
240 #define taskSCHEDULER_NOT_STARTED 0
\r
241 #define taskSCHEDULER_RUNNING 1
\r
242 #define taskSCHEDULER_SUSPENDED 2
\r
244 /*-----------------------------------------------------------
\r
245 * TASK CREATION API
\r
246 *----------------------------------------------------------*/
\r
251 portBASE_TYPE xTaskCreate(
\r
252 pdTASK_CODE pvTaskCode,
\r
253 const char * const pcName,
\r
254 unsigned short usStackDepth,
\r
255 void *pvParameters,
\r
256 unsigned portBASE_TYPE uxPriority,
\r
257 xTaskHandle *pvCreatedTask
\r
260 * Create a new task and add it to the list of tasks that are ready to run.
\r
262 * xTaskCreate() can only be used to create a task that has unrestricted
\r
263 * access to the entire microcontroller memory map. Systems that include MPU
\r
264 * support can alternatively create an MPU constrained task using
\r
265 * xTaskCreateRestricted().
\r
267 * @param pvTaskCode Pointer to the task entry function. Tasks
\r
268 * must be implemented to never return (i.e. continuous loop).
\r
270 * @param pcName A descriptive name for the task. This is mainly used to
\r
271 * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
\r
274 * @param usStackDepth The size of the task stack specified as the number of
\r
275 * variables the stack can hold - not the number of bytes. For example, if
\r
276 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
\r
277 * will be allocated for stack storage.
\r
279 * @param pvParameters Pointer that will be used as the parameter for the task
\r
282 * @param uxPriority The priority at which the task should run. Systems that
\r
283 * include MPU support can optionally create tasks in a privileged (system)
\r
284 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
\r
285 * example, to create a privileged task at priority 2 the uxPriority parameter
\r
286 * should be set to ( 2 | portPRIVILEGE_BIT ).
\r
288 * @param pvCreatedTask Used to pass back a handle by which the created task
\r
289 * can be referenced.
\r
291 * @return pdPASS if the task was successfully created and added to a ready
\r
292 * list, otherwise an error code defined in the file errors. h
\r
296 // Task to be created.
\r
297 void vTaskCode( void * pvParameters )
\r
301 // Task code goes here.
\r
305 // Function that creates a task.
\r
306 void vOtherFunction( void )
\r
308 static unsigned char ucParameterToPass;
\r
309 xTaskHandle xHandle;
\r
311 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
\r
312 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
\r
313 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
\r
314 // the new task attempts to access it.
\r
315 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
\r
317 // Use the handle to delete the task.
\r
318 vTaskDelete( xHandle );
\r
321 * \defgroup xTaskCreate xTaskCreate
\r
324 #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
\r
329 portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle *pxCreatedTask );</pre>
\r
331 * xTaskCreateRestricted() should only be used in systems that include an MPU
\r
334 * Create a new task and add it to the list of tasks that are ready to run.
\r
335 * The function parameters define the memory regions and associated access
\r
336 * permissions allocated to the task.
\r
338 * @param pxTaskDefinition Pointer to a structure that contains a member
\r
339 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
\r
340 * documentation) plus an optional stack buffer and the memory region
\r
343 * @param pxCreatedTask Used to pass back a handle by which the created task
\r
344 * can be referenced.
\r
346 * @return pdPASS if the task was successfully created and added to a ready
\r
347 * list, otherwise an error code defined in the file errors. h
\r
351 // Create an xTaskParameters structure that defines the task to be created.
\r
352 static const xTaskParameters xCheckTaskParameters =
\r
354 vATask, // pvTaskCode - the function that implements the task.
\r
355 "ATask", // pcName - just a text name for the task to assist debugging.
\r
356 100, // usStackDepth - the stack size DEFINED IN WORDS.
\r
357 NULL, // pvParameters - passed into the task function as the function parameters.
\r
358 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
\r
359 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
\r
361 // xRegions - Allocate up to three separate memory regions for access by
\r
362 // the task, with appropriate access permissions. Different processors have
\r
363 // different memory alignment requirements - refer to the FreeRTOS documentation
\r
364 // for full information.
\r
366 // Base address Length Parameters
\r
367 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
\r
368 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
\r
369 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
\r
375 xTaskHandle xHandle;
\r
377 // Create a task from the const structure defined above. The task handle
\r
378 // is requested (the second parameter is not NULL) but in this case just for
\r
379 // demonstration purposes as its not actually used.
\r
380 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
\r
382 // Start the scheduler.
\r
383 vTaskStartScheduler();
\r
385 // Will only get here if there was insufficient memory to create the idle
\r
390 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
\r
393 #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )
\r
398 void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre>
\r
400 * Memory regions are assigned to a restricted task when the task is created by
\r
401 * a call to xTaskCreateRestricted(). These regions can be redefined using
\r
402 * vTaskAllocateMPURegions().
\r
404 * @param xTask The handle of the task being updated.
\r
406 * @param xRegions A pointer to an xMemoryRegion structure that contains the
\r
407 * new memory region definitions.
\r
411 // Define an array of xMemoryRegion structures that configures an MPU region
\r
412 // allowing read/write access for 1024 bytes starting at the beginning of the
\r
413 // ucOneKByte array. The other two of the maximum 3 definable regions are
\r
414 // unused so set to zero.
\r
415 static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
\r
417 // Base address Length Parameters
\r
418 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
\r
423 void vATask( void *pvParameters )
\r
425 // This task was created such that it has access to certain regions of
\r
426 // memory as defined by the MPU configuration. At some point it is
\r
427 // desired that these MPU regions are replaced with that defined in the
\r
428 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
\r
429 // for this purpose. NULL is used as the task handle to indicate that this
\r
430 // function should modify the MPU regions of the calling task.
\r
431 vTaskAllocateMPURegions( NULL, xAltRegions );
\r
433 // Now the task can continue its function, but from this point on can only
\r
434 // access its stack and the ucOneKByte array (unless any other statically
\r
435 // defined or shared regions have been declared elsewhere).
\r
438 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
\r
441 void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION;
\r
445 * <pre>void vTaskDelete( xTaskHandle xTask );</pre>
\r
447 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
\r
448 * See the configuration section for more information.
\r
450 * Remove a task from the RTOS real time kernels management. The task being
\r
451 * deleted will be removed from all ready, blocked, suspended and event lists.
\r
453 * NOTE: The idle task is responsible for freeing the kernel allocated
\r
454 * memory from tasks that have been deleted. It is therefore important that
\r
455 * the idle task is not starved of microcontroller processing time if your
\r
456 * application makes any calls to vTaskDelete (). Memory allocated by the
\r
457 * task code is not automatically freed, and should be freed before the task
\r
460 * See the demo application file death.c for sample code that utilises
\r
463 * @param xTask The handle of the task to be deleted. Passing NULL will
\r
464 * cause the calling task to be deleted.
\r
468 void vOtherFunction( void )
\r
470 xTaskHandle xHandle;
\r
472 // Create the task, storing the handle.
\r
473 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
475 // Use the handle to delete the task.
\r
476 vTaskDelete( xHandle );
\r
479 * \defgroup vTaskDelete vTaskDelete
\r
482 void vTaskDelete( xTaskHandle xTaskToDelete ) PRIVILEGED_FUNCTION;
\r
484 /*-----------------------------------------------------------
\r
486 *----------------------------------------------------------*/
\r
490 * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
\r
492 * Delay a task for a given number of ticks. The actual time that the
\r
493 * task remains blocked depends on the tick rate. The constant
\r
494 * portTICK_RATE_MS can be used to calculate real time from the tick
\r
495 * rate - with the resolution of one tick period.
\r
497 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
\r
498 * See the configuration section for more information.
\r
501 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
\r
502 * the time at which vTaskDelay() is called. For example, specifying a block
\r
503 * period of 100 ticks will cause the task to unblock 100 ticks after
\r
504 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
\r
505 * of controlling the frequency of a cyclical task as the path taken through the
\r
506 * code, as well as other task and interrupt activity, will effect the frequency
\r
507 * at which vTaskDelay() gets called and therefore the time at which the task
\r
508 * next executes. See vTaskDelayUntil() for an alternative API function designed
\r
509 * to facilitate fixed frequency execution. It does this by specifying an
\r
510 * absolute time (rather than a relative time) at which the calling task should
\r
513 * @param xTicksToDelay The amount of time, in tick periods, that
\r
514 * the calling task should block.
\r
518 void vTaskFunction( void * pvParameters )
\r
520 void vTaskFunction( void * pvParameters )
\r
522 // Block for 500ms.
\r
523 const portTickType xDelay = 500 / portTICK_RATE_MS;
\r
527 // Simply toggle the LED every 500ms, blocking between each toggle.
\r
529 vTaskDelay( xDelay );
\r
533 * \defgroup vTaskDelay vTaskDelay
\r
534 * \ingroup TaskCtrl
\r
536 void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION;
\r
540 * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
\r
542 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
\r
543 * See the configuration section for more information.
\r
545 * Delay a task until a specified time. This function can be used by cyclical
\r
546 * tasks to ensure a constant execution frequency.
\r
548 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
\r
549 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
\r
550 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
\r
551 * execution frequency as the time between a task starting to execute and that task
\r
552 * calling vTaskDelay () may not be fixed [the task may take a different path though the
\r
553 * code between calls, or may get interrupted or preempted a different number of times
\r
554 * each time it executes].
\r
556 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
\r
557 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
\r
560 * The constant portTICK_RATE_MS can be used to calculate real time from the tick
\r
561 * rate - with the resolution of one tick period.
\r
563 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
\r
564 * task was last unblocked. The variable must be initialised with the current time
\r
565 * prior to its first use (see the example below). Following this the variable is
\r
566 * automatically updated within vTaskDelayUntil ().
\r
568 * @param xTimeIncrement The cycle time period. The task will be unblocked at
\r
569 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
\r
570 * same xTimeIncrement parameter value will cause the task to execute with
\r
571 * a fixed interface period.
\r
575 // Perform an action every 10 ticks.
\r
576 void vTaskFunction( void * pvParameters )
\r
578 portTickType xLastWakeTime;
\r
579 const portTickType xFrequency = 10;
\r
581 // Initialise the xLastWakeTime variable with the current time.
\r
582 xLastWakeTime = xTaskGetTickCount ();
\r
585 // Wait for the next cycle.
\r
586 vTaskDelayUntil( &xLastWakeTime, xFrequency );
\r
588 // Perform action here.
\r
592 * \defgroup vTaskDelayUntil vTaskDelayUntil
\r
593 * \ingroup TaskCtrl
\r
595 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION;
\r
599 * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask );</pre>
\r
601 * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
\r
602 * See the configuration section for more information.
\r
604 * Obtain the priority of any task.
\r
606 * @param xTask Handle of the task to be queried. Passing a NULL
\r
607 * handle results in the priority of the calling task being returned.
\r
609 * @return The priority of xTask.
\r
613 void vAFunction( void )
\r
615 xTaskHandle xHandle;
\r
617 // Create a task, storing the handle.
\r
618 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
622 // Use the handle to obtain the priority of the created task.
\r
623 // It was created with tskIDLE_PRIORITY, but may have changed
\r
625 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
\r
627 // The task has changed it's priority.
\r
632 // Is our priority higher than the created task?
\r
633 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
\r
635 // Our priority (obtained using NULL handle) is higher.
\r
639 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
\r
640 * \ingroup TaskCtrl
\r
642 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
646 * <pre>eTaskState eTaskGetState( xTaskHandle xTask );</pre>
\r
648 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
\r
649 * See the configuration section for more information.
\r
651 * Obtain the state of any task. States are encoded by the eTaskState
\r
654 * @param xTask Handle of the task to be queried.
\r
656 * @return The state of xTask at the time the function was called. Note the
\r
657 * state of the task might change between the function being called, and the
\r
658 * functions return value being tested by the calling task.
\r
660 eTaskState eTaskGetState( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
664 * <pre>void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority );</pre>
\r
666 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
\r
667 * See the configuration section for more information.
\r
669 * Set the priority of any task.
\r
671 * A context switch will occur before the function returns if the priority
\r
672 * being set is higher than the currently executing task.
\r
674 * @param xTask Handle to the task for which the priority is being set.
\r
675 * Passing a NULL handle results in the priority of the calling task being set.
\r
677 * @param uxNewPriority The priority to which the task will be set.
\r
681 void vAFunction( void )
\r
683 xTaskHandle xHandle;
\r
685 // Create a task, storing the handle.
\r
686 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
690 // Use the handle to raise the priority of the created task.
\r
691 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
\r
695 // Use a NULL handle to raise our priority to the same value.
\r
696 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
\r
699 * \defgroup vTaskPrioritySet vTaskPrioritySet
\r
700 * \ingroup TaskCtrl
\r
702 void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION;
\r
706 * <pre>void vTaskSuspend( xTaskHandle xTaskToSuspend );</pre>
\r
708 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
709 * See the configuration section for more information.
\r
711 * Suspend any task. When suspended a task will never get any microcontroller
\r
712 * processing time, no matter what its priority.
\r
714 * Calls to vTaskSuspend are not accumulative -
\r
715 * i.e. calling vTaskSuspend () twice on the same task still only requires one
\r
716 * call to vTaskResume () to ready the suspended task.
\r
718 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
\r
719 * handle will cause the calling task to be suspended.
\r
723 void vAFunction( void )
\r
725 xTaskHandle xHandle;
\r
727 // Create a task, storing the handle.
\r
728 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
732 // Use the handle to suspend the created task.
\r
733 vTaskSuspend( xHandle );
\r
737 // The created task will not run during this period, unless
\r
738 // another task calls vTaskResume( xHandle ).
\r
743 // Suspend ourselves.
\r
744 vTaskSuspend( NULL );
\r
746 // We cannot get here unless another task calls vTaskResume
\r
747 // with our handle as the parameter.
\r
750 * \defgroup vTaskSuspend vTaskSuspend
\r
751 * \ingroup TaskCtrl
\r
753 void vTaskSuspend( xTaskHandle xTaskToSuspend ) PRIVILEGED_FUNCTION;
\r
757 * <pre>void vTaskResume( xTaskHandle xTaskToResume );</pre>
\r
759 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
\r
760 * See the configuration section for more information.
\r
762 * Resumes a suspended task.
\r
764 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
765 * will be made available for running again by a single call to
\r
768 * @param xTaskToResume Handle to the task being readied.
\r
772 void vAFunction( void )
\r
774 xTaskHandle xHandle;
\r
776 // Create a task, storing the handle.
\r
777 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
\r
781 // Use the handle to suspend the created task.
\r
782 vTaskSuspend( xHandle );
\r
786 // The created task will not run during this period, unless
\r
787 // another task calls vTaskResume( xHandle ).
\r
792 // Resume the suspended task ourselves.
\r
793 vTaskResume( xHandle );
\r
795 // The created task will once again get microcontroller processing
\r
796 // time in accordance with it priority within the system.
\r
799 * \defgroup vTaskResume vTaskResume
\r
800 * \ingroup TaskCtrl
\r
802 void vTaskResume( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;
\r
806 * <pre>void xTaskResumeFromISR( xTaskHandle xTaskToResume );</pre>
\r
808 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
\r
809 * available. See the configuration section for more information.
\r
811 * An implementation of vTaskResume() that can be called from within an ISR.
\r
813 * A task that has been suspended by one of more calls to vTaskSuspend ()
\r
814 * will be made available for running again by a single call to
\r
815 * xTaskResumeFromISR ().
\r
817 * @param xTaskToResume Handle to the task being readied.
\r
819 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
\r
820 * \ingroup TaskCtrl
\r
822 portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;
\r
824 /*-----------------------------------------------------------
\r
825 * SCHEDULER CONTROL
\r
826 *----------------------------------------------------------*/
\r
830 * <pre>void vTaskStartScheduler( void );</pre>
\r
832 * Starts the real time kernel tick processing. After calling the kernel
\r
833 * has control over which tasks are executed and when. This function
\r
834 * does not return until an executing task calls vTaskEndScheduler ().
\r
836 * At least one task should be created via a call to xTaskCreate ()
\r
837 * before calling vTaskStartScheduler (). The idle task is created
\r
838 * automatically when the first application task is created.
\r
840 * See the demo application file main.c for an example of creating
\r
841 * tasks and starting the kernel.
\r
845 void vAFunction( void )
\r
847 // Create at least one task before starting the kernel.
\r
848 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
850 // Start the real time kernel with preemption.
\r
851 vTaskStartScheduler ();
\r
853 // Will not get here unless a task calls vTaskEndScheduler ()
\r
857 * \defgroup vTaskStartScheduler vTaskStartScheduler
\r
858 * \ingroup SchedulerControl
\r
860 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
\r
864 * <pre>void vTaskEndScheduler( void );</pre>
\r
866 * Stops the real time kernel tick. All created tasks will be automatically
\r
867 * deleted and multitasking (either preemptive or cooperative) will
\r
868 * stop. Execution then resumes from the point where vTaskStartScheduler ()
\r
869 * was called, as if vTaskStartScheduler () had just returned.
\r
871 * See the demo application file main. c in the demo/PC directory for an
\r
872 * example that uses vTaskEndScheduler ().
\r
874 * vTaskEndScheduler () requires an exit function to be defined within the
\r
875 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
\r
876 * performs hardware specific operations such as stopping the kernel tick.
\r
878 * vTaskEndScheduler () will cause all of the resources allocated by the
\r
879 * kernel to be freed - but will not free resources allocated by application
\r
884 void vTaskCode( void * pvParameters )
\r
888 // Task code goes here.
\r
890 // At some point we want to end the real time kernel processing
\r
892 vTaskEndScheduler ();
\r
896 void vAFunction( void )
\r
898 // Create at least one task before starting the kernel.
\r
899 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
901 // Start the real time kernel with preemption.
\r
902 vTaskStartScheduler ();
\r
904 // Will only get here when the vTaskCode () task has called
\r
905 // vTaskEndScheduler (). When we get here we are back to single task
\r
910 * \defgroup vTaskEndScheduler vTaskEndScheduler
\r
911 * \ingroup SchedulerControl
\r
913 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
\r
917 * <pre>void vTaskSuspendAll( void );</pre>
\r
919 * Suspends all real time kernel activity while keeping interrupts (including the
\r
920 * kernel tick) enabled.
\r
922 * After calling vTaskSuspendAll () the calling task will continue to execute
\r
923 * without risk of being swapped out until a call to xTaskResumeAll () has been
\r
926 * API functions that have the potential to cause a context switch (for example,
\r
927 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
\r
932 void vTask1( void * pvParameters )
\r
936 // Task code goes here.
\r
940 // At some point the task wants to perform a long operation during
\r
941 // which it does not want to get swapped out. It cannot use
\r
942 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
943 // operation may cause interrupts to be missed - including the
\r
946 // Prevent the real time kernel swapping out the task.
\r
947 vTaskSuspendAll ();
\r
949 // Perform the operation here. There is no need to use critical
\r
950 // sections as we have all the microcontroller processing time.
\r
951 // During this time interrupts will still operate and the kernel
\r
952 // tick count will be maintained.
\r
956 // The operation is complete. Restart the kernel.
\r
961 * \defgroup vTaskSuspendAll vTaskSuspendAll
\r
962 * \ingroup SchedulerControl
\r
964 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
\r
968 * <pre>char xTaskResumeAll( void );</pre>
\r
970 * Resumes real time kernel activity following a call to vTaskSuspendAll ().
\r
971 * After a call to vTaskSuspendAll () the kernel will take control of which
\r
972 * task is executing at any time.
\r
974 * @return If resuming the scheduler caused a context switch then pdTRUE is
\r
975 * returned, otherwise pdFALSE is returned.
\r
979 void vTask1( void * pvParameters )
\r
983 // Task code goes here.
\r
987 // At some point the task wants to perform a long operation during
\r
988 // which it does not want to get swapped out. It cannot use
\r
989 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
\r
990 // operation may cause interrupts to be missed - including the
\r
993 // Prevent the real time kernel swapping out the task.
\r
994 vTaskSuspendAll ();
\r
996 // Perform the operation here. There is no need to use critical
\r
997 // sections as we have all the microcontroller processing time.
\r
998 // During this time interrupts will still operate and the real
\r
999 // time kernel tick count will be maintained.
\r
1003 // The operation is complete. Restart the kernel. We want to force
\r
1004 // a context switch - but there is no point if resuming the scheduler
\r
1005 // caused a context switch already.
\r
1006 if( !xTaskResumeAll () )
\r
1013 * \defgroup xTaskResumeAll xTaskResumeAll
\r
1014 * \ingroup SchedulerControl
\r
1016 signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
\r
1020 * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>
\r
1022 * Utility task that simply returns pdTRUE if the task referenced by xTask is
\r
1023 * currently in the Suspended state, or pdFALSE if the task referenced by xTask
\r
1024 * is in any other state.
\r
1027 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1029 /*-----------------------------------------------------------
\r
1031 *----------------------------------------------------------*/
\r
1035 * <PRE>portTickType xTaskGetTickCount( void );</PRE>
\r
1037 * @return The count of ticks since vTaskStartScheduler was called.
\r
1039 * \page xTaskGetTickCount xTaskGetTickCount
\r
1040 * \ingroup TaskUtils
\r
1042 portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
\r
1046 * <PRE>portTickType xTaskGetTickCountFromISR( void );</PRE>
\r
1048 * @return The count of ticks since vTaskStartScheduler was called.
\r
1050 * This is a version of xTaskGetTickCount() that is safe to be called from an
\r
1051 * ISR - provided that portTickType is the natural word size of the
\r
1052 * microcontroller being used or interrupt nesting is either not supported or
\r
1055 * \page xTaskGetTickCount xTaskGetTickCount
\r
1056 * \ingroup TaskUtils
\r
1058 portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
\r
1062 * <PRE>unsigned short uxTaskGetNumberOfTasks( void );</PRE>
\r
1064 * @return The number of tasks that the real time kernel is currently managing.
\r
1065 * This includes all ready, blocked and suspended tasks. A task that
\r
1066 * has been deleted but not yet freed by the idle task will also be
\r
1067 * included in the count.
\r
1069 * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
\r
1070 * \ingroup TaskUtils
\r
1072 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
\r
1076 * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE>
\r
1078 * @return The text (human readable) name of the task referenced by the handle
\r
1079 * xTaskToQueury. A task can query its own name by either passing in its own
\r
1080 * handle, or by setting xTaskToQuery to NULL. INCLUDE_pcTaskGetTaskName must be
\r
1081 * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
\r
1083 * \page pcTaskGetTaskName pcTaskGetTaskName
\r
1084 * \ingroup TaskUtils
\r
1086 signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );
\r
1090 * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
\r
1092 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
\r
1093 * this function to be available.
\r
1095 * Returns the high water mark of the stack associated with xTask. That is,
\r
1096 * the minimum free stack space there has been (in words, so on a 32 bit machine
\r
1097 * a value of 1 means 4 bytes) since the task started. The smaller the returned
\r
1098 * number the closer the task has come to overflowing its stack.
\r
1100 * @param xTask Handle of the task associated with the stack to be checked.
\r
1101 * Set xTask to NULL to check the stack of the calling task.
\r
1103 * @return The smallest amount of free stack space there has been (in bytes)
\r
1104 * since the task referenced by xTask was created.
\r
1106 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1108 /* When using trace macros it is sometimes necessary to include tasks.h before
\r
1109 FreeRTOS.h. When this is done pdTASK_HOOK_CODE will not yet have been defined,
\r
1110 so the following two prototypes will cause a compilation error. This can be
\r
1111 fixed by simply guarding against the inclusion of these two prototypes unless
\r
1112 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
\r
1114 #ifdef configUSE_APPLICATION_TASK_TAG
\r
1115 #if configUSE_APPLICATION_TASK_TAG == 1
\r
1118 * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
1120 * Sets pxHookFunction to be the task hook function used by the task xTask.
\r
1121 * Passing xTask as NULL has the effect of setting the calling tasks hook
\r
1124 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION;
\r
1128 * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre>
\r
1130 * Returns the pxHookFunction value assigned to the task xTask.
\r
1132 pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
\r
1133 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
\r
1134 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
\r
1138 * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
\r
1140 * Calls the hook function associated with xTask. Passing xTask as NULL has
\r
1141 * the effect of calling the Running tasks (the calling task) hook function.
\r
1143 * pvParameter is passed to the hook function for the task to interpret as it
\r
1146 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
\r
1149 * xTaskGetIdleTaskHandle() is only available if
\r
1150 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
\r
1152 * Simply returns the handle of the idle task. It is not valid to call
\r
1153 * xTaskGetIdleTaskHandle() before the scheduler has been started.
\r
1155 xTaskHandle xTaskGetIdleTaskHandle( void );
\r
1158 * configUSE_TRACE_FACILITY must bet defined as 1 in FreeRTOSConfig.h for
\r
1159 * xTaskGetSystemState() to be available.
\r
1161 * xTaskGetSystemState() populates an xTaskStatusType structure for each task in
\r
1162 * the system. xTaskStatusType structures contain, among other things, members
\r
1163 * for the task handle, task name, task priority, task state, and total amount
\r
1164 * of run time consumed by the task. See the xTaskStatusType structure
\r
1165 * definition in this file for the full member list.
\r
1167 * NOTE: This function is intended for debugging use only as its use results in
\r
1168 * the scheduler remaining suspended for an extended period.
\r
1170 * @param pxTaskStatusArray A pointer to an array of xTaskStatusType structures.
\r
1171 * The array contain at least one xTaskStatusType structure for each task that
\r
1172 * is under the control of the RTOS. The number of tasks under the control of
\r
1173 * the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
\r
1175 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
\r
1176 * parameter. The size is specified as the number of indexes in the array, or
\r
1177 * the number of xTaskStatusType structures contained in the array, not by the
\r
1178 * number of bytes in the array.
\r
1180 * @param pultotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
\r
1181 * FreeRTOSConfig.h then *pulTotalRunTime is set by xTaskGetSystemState() to the
\r
1182 * total run time (as defined by the run time stats clock, see
\r
1183 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
\r
1185 * @return The number of xTaskStatusType structures that were populated by
\r
1186 * xTaskGetSystemState(). This should equal the number returned by the
\r
1187 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
\r
1188 * in the uxArraySize parameter was too small.
\r
1192 // This example demonstrates how a human readable table of run time stats
\r
1193 // information is generated from raw data provided by xTaskGetSystemState().
\r
1194 // The human readable table is written to pcWriteBuffer
\r
1195 void vTaskGetRunTimeStats( signed char *pcWriteBuffer )
\r
1197 xTaskStatusType *pxTaskStatusArray;
\r
1198 volatile unsigned portBASE_TYPE uxArraySize, x;
\r
1199 unsigned long ulTotalRunTime, ulStatsAsPercentage;
\r
1201 // Make sure the write buffer does not contain a string.
\r
1202 *pcWriteBuffer = 0x00;
\r
1204 // Take a snapshot of the number of tasks in case it changes while this
\r
1205 // function is executing.
\r
1206 uxArraySize = uxCurrentNumberOfTasks;
\r
1208 // Allocate a xTaskStatusType structure for each task. An array could be
\r
1209 // allocated statically at compile time.
\r
1210 pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( xTaskStatusType ) );
\r
1212 if( pxTaskStatusArray != NULL )
\r
1214 // Generate raw status information about each task.
\r
1215 uxArraySize = xTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
\r
1217 // For percentage calculations.
\r
1218 ulTotalRunTime /= 100UL;
\r
1220 // Avoid divide by zero errors.
\r
1221 if( ulTotalRunTime > 0 )
\r
1223 // For each populated position in the pxTaskStatusArray array,
\r
1224 // format the raw data as human readable ASCII data
\r
1225 for( x = 0; x < uxArraySize; x++ )
\r
1227 // What percentage of the total run time has the task used?
\r
1228 // This will always be rounded down to the nearest integer.
\r
1229 // ulTotalRunTimeDiv100 has already been divided by 100.
\r
1230 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
\r
1232 if( ulStatsAsPercentage > 0UL )
\r
1234 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
\r
1238 // If the percentage is zero here then the task has
\r
1239 // consumed less than 1% of the total run time.
\r
1240 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
\r
1243 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
\r
1247 // The array is no longer needed, free the memory it consumes.
\r
1248 vPortFree( pxTaskStatusArray );
\r
1253 unsigned portBASE_TYPE xTaskGetSystemState( xTaskStatusType *pxTaskStatusArray, unsigned portBASE_TYPE uxArraySize, unsigned long *pulTotalRunTime );
\r
1257 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
\r
1259 * configUSE_TRACE_FACILITY and configINCLUDE_STATS_FORMATTING_FUNCTIONS must
\r
1260 * both be defined as 1 for this function to be available. See the
\r
1261 * configuration section of the FreeRTOS.org website for more information.
\r
1263 * NOTE 1: This function will disable interrupts for its duration. It is
\r
1264 * not intended for normal application runtime use but as a debug aid.
\r
1266 * Lists all the current tasks, along with their current state and stack
\r
1267 * usage high water mark.
\r
1269 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
\r
1270 * suspended ('S').
\r
1274 * This function is provided for convenience only, and is used by many of the
\r
1275 * demo applications. Do not consider it to be part of the scheduler.
\r
1277 * vTaskList() calls xTaskGetSystemState(), then formats part of the
\r
1278 * xTaskGetSystemState() output into a human readable table that displays task
\r
1279 * names, states and stack usage.
\r
1281 * vTaskList() has a dependency on the sprintf() C library function that might
\r
1282 * bloat the code size, use a lot of stack, and provide different results on
\r
1283 * different platforms. An alternative, tiny, third party, and limited
\r
1284 * functionality implementation of sprintf() is provided in many of the
\r
1285 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
\r
1286 * printf-stdarg.c does not provide a full snprintf() implementation!).
\r
1288 * It is recommended that production systems call xTaskGetSystemState()
\r
1289 * directly to get access to raw stats data, rather than indirectly through a
\r
1290 * call to vTaskList().
\r
1292 * @param pcWriteBuffer A buffer into which the above mentioned details
\r
1293 * will be written, in ascii form. This buffer is assumed to be large
\r
1294 * enough to contain the generated report. Approximately 40 bytes per
\r
1295 * task should be sufficient.
\r
1297 * \page vTaskList vTaskList
\r
1298 * \ingroup TaskUtils
\r
1300 void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
\r
1304 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
\r
1306 * configGENERATE_RUN_TIME_STATS and configINCLUDE_STATS_FORMATTING_FUNCTIONS
\r
1307 * must both be defined as 1 for this function to be available. The application
\r
1308 * must also then provide definitions for
\r
1309 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE
\r
1310 * to configure a peripheral timer/counter and return the timers current count
\r
1311 * value respectively. The counter should be at least 10 times the frequency of
\r
1314 * NOTE 1: This function will disable interrupts for its duration. It is
\r
1315 * not intended for normal application runtime use but as a debug aid.
\r
1317 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
\r
1318 * accumulated execution time being stored for each task. The resolution
\r
1319 * of the accumulated time value depends on the frequency of the timer
\r
1320 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
\r
1321 * Calling vTaskGetRunTimeStats() writes the total execution time of each
\r
1322 * task into a buffer, both as an absolute count value and as a percentage
\r
1323 * of the total system execution time.
\r
1327 * This function is provided for convenience only, and is used by many of the
\r
1328 * demo applications. Do not consider it to be part of the scheduler.
\r
1330 * vTaskGetRunTimeStats() calls xTaskGetSystemState(), then formats part of the
\r
1331 * xTaskGetSystemState() output into a human readable table that displays the
\r
1332 * amount of time each task has spent in the Running state in both absolute and
\r
1333 * percentage terms.
\r
1335 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
\r
1336 * that might bloat the code size, use a lot of stack, and provide different
\r
1337 * results on different platforms. An alternative, tiny, third party, and
\r
1338 * limited functionality implementation of sprintf() is provided in many of the
\r
1339 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
\r
1340 * printf-stdarg.c does not provide a full snprintf() implementation!).
\r
1342 * It is recommended that production systems call xTaskGetSystemState() directly
\r
1343 * to get access to raw stats data, rather than indirectly through a call to
\r
1344 * vTaskGetRunTimeStats().
\r
1346 * @param pcWriteBuffer A buffer into which the execution times will be
\r
1347 * written, in ascii form. This buffer is assumed to be large enough to
\r
1348 * contain the generated report. Approximately 40 bytes per task should
\r
1351 * \page vTaskGetRunTimeStats vTaskGetRunTimeStats
\r
1352 * \ingroup TaskUtils
\r
1354 void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
\r
1356 /*-----------------------------------------------------------
\r
1357 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
\r
1358 *----------------------------------------------------------*/
\r
1361 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
1362 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
1363 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1365 * Called from the real time kernel tick (either preemptive or cooperative),
\r
1366 * this increments the tick count and checks if any tasks that are blocked
\r
1367 * for a finite period required removing from a blocked list and placing on
\r
1368 * a ready list. If a non-zero value is returned then a context switch is
\r
1369 * required because either:
\r
1370 * + A task was removed from a blocked list because its timeout had expired,
\r
1372 * + Time slicing is in use and there is a task of equal priority to the
\r
1373 * currently running task.
\r
1375 portBASE_TYPE xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
\r
1378 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1379 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1381 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1383 * Removes the calling task from the ready list and places it both
\r
1384 * on the list of tasks waiting for a particular event, and the
\r
1385 * list of delayed tasks. The task will be removed from both lists
\r
1386 * and replaced on the ready list should either the event occur (and
\r
1387 * there be no higher priority tasks waiting on the same event) or
\r
1388 * the delay period expires.
\r
1390 * @param pxEventList The list containing tasks that are blocked waiting
\r
1391 * for the event to occur.
\r
1393 * @param xTicksToWait The maximum amount of time that the task should wait
\r
1394 * for the event to occur. This is specified in kernel ticks,the constant
\r
1395 * portTICK_RATE_MS can be used to convert kernel ticks into a real time
\r
1398 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1401 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1402 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1404 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1406 * This function performs nearly the same function as vTaskPlaceOnEventList().
\r
1407 * The difference being that this function does not permit tasks to block
\r
1408 * indefinitely, whereas vTaskPlaceOnEventList() does.
\r
1410 * @return pdTRUE if the task being removed has a higher priority than the task
\r
1411 * making the call, otherwise pdFALSE.
\r
1413 void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1416 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
\r
1417 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1419 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
\r
1421 * Removes a task from both the specified event list and the list of blocked
\r
1422 * tasks, and places it on a ready queue.
\r
1424 * xTaskRemoveFromEventList () will be called if either an event occurs to
\r
1425 * unblock a task, or the block timeout period expires.
\r
1427 * @return pdTRUE if the task being removed has a higher priority than the task
\r
1428 * making the call, otherwise pdFALSE.
\r
1430 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION;
\r
1433 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
\r
1434 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
\r
1435 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
\r
1437 * Sets the pointer to the current TCB to the TCB of the highest priority task
\r
1438 * that is ready to run.
\r
1440 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
\r
1443 * Return the handle of the calling task.
\r
1445 xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
\r
1448 * Capture the current time status for future reference.
\r
1450 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION;
\r
1453 * Compare the time status now with that previously captured to see if the
\r
1454 * timeout has expired.
\r
1456 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION;
\r
1459 * Shortcut used by the queue implementation to prevent unnecessary call to
\r
1462 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
\r
1465 * Returns the scheduler state as taskSCHEDULER_RUNNING,
\r
1466 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
\r
1468 portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
\r
1471 * Raises the priority of the mutex holder to that of the calling task should
\r
1472 * the mutex holder have a priority less than the calling task.
\r
1474 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
\r
1477 * Set the priority of a task back to its proper priority in the case that it
\r
1478 * inherited a higher priority while it was holding a semaphore.
\r
1480 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
\r
1483 * Generic version of the task creation function which is in turn called by the
\r
1484 * xTaskCreate() and xTaskCreateRestricted() macros.
\r
1486 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
1489 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
\r
1491 unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
\r
1494 * Set the uxTCBNumber of the task referenced by the xTask parameter to
\r
1497 void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );
\r
1500 * If tickless mode is being used, or a low power mode is implemented, then
\r
1501 * the tick interrupt will not execute during idle periods. When this is the
\r
1502 * case, the tick count value maintained by the scheduler needs to be kept up
\r
1503 * to date with the actual execution time by being skipped forward by the by
\r
1504 * a time equal to the idle period.
\r
1506 void vTaskStepTick( portTickType xTicksToJump );
\r
1509 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
\r
1510 * specific sleep function to determine if it is ok to proceed with the sleep,
\r
1511 * and if it is ok to proceed, if it is ok to sleep indefinitely.
\r
1513 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
\r
1514 * called with the scheduler suspended, not from within a critical section. It
\r
1515 * is therefore possible for an interrupt to request a context switch between
\r
1516 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
\r
1517 * entered. eTaskConfirmSleepModeStatus() should be called from a short
\r
1518 * critical section between the timer being stopped and the sleep mode being
\r
1519 * entered to ensure it is ok to proceed into the sleep mode.
\r
1521 eSleepModeStatus eTaskConfirmSleepModeStatus( void );
\r
1523 #ifdef __cplusplus
\r
1526 #endif /* TASK_H */
\r