source: S-port/trunk/Middlewares/Third_Party/FreeRTOS/Source/include/task.h

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 105.3 KB
Line 
1/*
2 * FreeRTOS Kernel V10.3.1
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
24 *
25 * 1 tab == 4 spaces!
26 */
27
28
29#ifndef INC_TASK_H
30#define INC_TASK_H
31
32#ifndef INC_FREERTOS_H
33 #error "include FreeRTOS.h must appear in source files before include task.h"
34#endif
35
36#include "list.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*-----------------------------------------------------------
43 * MACROS AND DEFINITIONS
44 *----------------------------------------------------------*/
45
46#define tskKERNEL_VERSION_NUMBER "V10.3.1"
47#define tskKERNEL_VERSION_MAJOR 10
48#define tskKERNEL_VERSION_MINOR 3
49#define tskKERNEL_VERSION_BUILD 1
50
51/* MPU region parameters passed in ulParameters
52 * of MemoryRegion_t struct. */
53#define tskMPU_REGION_READ_ONLY ( 1UL << 0UL )
54#define tskMPU_REGION_READ_WRITE ( 1UL << 1UL )
55#define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL )
56#define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL )
57#define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL )
58
59/**
60 * task. h
61 *
62 * Type by which tasks are referenced. For example, a call to xTaskCreate
63 * returns (via a pointer parameter) an TaskHandle_t variable that can then
64 * be used as a parameter to vTaskDelete to delete the task.
65 *
66 * \defgroup TaskHandle_t TaskHandle_t
67 * \ingroup Tasks
68 */
69struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
70typedef struct tskTaskControlBlock* TaskHandle_t;
71
72/*
73 * Defines the prototype to which the application task hook function must
74 * conform.
75 */
76typedef BaseType_t (*TaskHookFunction_t)( void * );
77
78/* Task states returned by eTaskGetState. */
79typedef enum
80{
81 eRunning = 0, /* A task is querying the state of itself, so must be running. */
82 eReady, /* The task being queried is in a read or pending ready list. */
83 eBlocked, /* The task being queried is in the Blocked state. */
84 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
85 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
86 eInvalid /* Used as an 'invalid state' value. */
87} eTaskState;
88
89/* Actions that can be performed when vTaskNotify() is called. */
90typedef enum
91{
92 eNoAction = 0, /* Notify the task without updating its notify value. */
93 eSetBits, /* Set bits in the task's notification value. */
94 eIncrement, /* Increment the task's notification value. */
95 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
96 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
97} eNotifyAction;
98
99/*
100 * Used internally only.
101 */
102typedef struct xTIME_OUT
103{
104 BaseType_t xOverflowCount;
105 TickType_t xTimeOnEntering;
106} TimeOut_t;
107
108/*
109 * Defines the memory ranges allocated to the task when an MPU is used.
110 */
111typedef struct xMEMORY_REGION
112{
113 void *pvBaseAddress;
114 uint32_t ulLengthInBytes;
115 uint32_t ulParameters;
116} MemoryRegion_t;
117
118/*
119 * Parameters required to create an MPU protected task.
120 */
121typedef struct xTASK_PARAMETERS
122{
123 TaskFunction_t pvTaskCode;
124 const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
125 configSTACK_DEPTH_TYPE usStackDepth;
126 void *pvParameters;
127 UBaseType_t uxPriority;
128 StackType_t *puxStackBuffer;
129 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
130 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
131 StaticTask_t * const pxTaskBuffer;
132 #endif
133} TaskParameters_t;
134
135/* Used with the uxTaskGetSystemState() function to return the state of each task
136in the system. */
137typedef struct xTASK_STATUS
138{
139 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
140 const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
141 UBaseType_t xTaskNumber; /* A number unique to the task. */
142 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
143 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
144 UBaseType_t 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. */
145 uint32_t 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. */
146 StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
147 configSTACK_DEPTH_TYPE 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. */
148} TaskStatus_t;
149
150/* Possible return values for eTaskConfirmSleepModeStatus(). */
151typedef enum
152{
153 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. */
154 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
155 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. */
156} eSleepModeStatus;
157
158/**
159 * Defines the priority used by the idle task. This must not be modified.
160 *
161 * \ingroup TaskUtils
162 */
163#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
164
165/**
166 * task. h
167 *
168 * Macro for forcing a context switch.
169 *
170 * \defgroup taskYIELD taskYIELD
171 * \ingroup SchedulerControl
172 */
173#define taskYIELD() portYIELD()
174
175/**
176 * task. h
177 *
178 * Macro to mark the start of a critical code region. Preemptive context
179 * switches cannot occur when in a critical region.
180 *
181 * NOTE: This may alter the stack (depending on the portable implementation)
182 * so must be used with care!
183 *
184 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
185 * \ingroup SchedulerControl
186 */
187#define taskENTER_CRITICAL() portENTER_CRITICAL()
188#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
189
190/**
191 * task. h
192 *
193 * Macro to mark the end of a critical code region. Preemptive context
194 * switches cannot occur when in a critical region.
195 *
196 * NOTE: This may alter the stack (depending on the portable implementation)
197 * so must be used with care!
198 *
199 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
200 * \ingroup SchedulerControl
201 */
202#define taskEXIT_CRITICAL() portEXIT_CRITICAL()
203#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
204/**
205 * task. h
206 *
207 * Macro to disable all maskable interrupts.
208 *
209 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
210 * \ingroup SchedulerControl
211 */
212#define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
213
214/**
215 * task. h
216 *
217 * Macro to enable microcontroller interrupts.
218 *
219 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
220 * \ingroup SchedulerControl
221 */
222#define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
223
224/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
2250 to generate more optimal code when configASSERT() is defined as the constant
226is used in assert() statements. */
227#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
228#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
229#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
230
231
232/*-----------------------------------------------------------
233 * TASK CREATION API
234 *----------------------------------------------------------*/
235
236/**
237 * task. h
238 *<pre>
239 BaseType_t xTaskCreate(
240 TaskFunction_t pvTaskCode,
241 const char * const pcName,
242 configSTACK_DEPTH_TYPE usStackDepth,
243 void *pvParameters,
244 UBaseType_t uxPriority,
245 TaskHandle_t *pvCreatedTask
246 );</pre>
247 *
248 * Create a new task and add it to the list of tasks that are ready to run.
249 *
250 * Internally, within the FreeRTOS implementation, tasks use two blocks of
251 * memory. The first block is used to hold the task's data structures. The
252 * second block is used by the task as its stack. If a task is created using
253 * xTaskCreate() then both blocks of memory are automatically dynamically
254 * allocated inside the xTaskCreate() function. (see
255 * http://www.freertos.org/a00111.html). If a task is created using
256 * xTaskCreateStatic() then the application writer must provide the required
257 * memory. xTaskCreateStatic() therefore allows a task to be created without
258 * using any dynamic memory allocation.
259 *
260 * See xTaskCreateStatic() for a version that does not use any dynamic memory
261 * allocation.
262 *
263 * xTaskCreate() can only be used to create a task that has unrestricted
264 * access to the entire microcontroller memory map. Systems that include MPU
265 * support can alternatively create an MPU constrained task using
266 * xTaskCreateRestricted().
267 *
268 * @param pvTaskCode Pointer to the task entry function. Tasks
269 * must be implemented to never return (i.e. continuous loop).
270 *
271 * @param pcName A descriptive name for the task. This is mainly used to
272 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
273 * is 16.
274 *
275 * @param usStackDepth The size of the task stack specified as the number of
276 * variables the stack can hold - not the number of bytes. For example, if
277 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
278 * will be allocated for stack storage.
279 *
280 * @param pvParameters Pointer that will be used as the parameter for the task
281 * being created.
282 *
283 * @param uxPriority The priority at which the task should run. Systems that
284 * include MPU support can optionally create tasks in a privileged (system)
285 * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
286 * example, to create a privileged task at priority 2 the uxPriority parameter
287 * should be set to ( 2 | portPRIVILEGE_BIT ).
288 *
289 * @param pvCreatedTask Used to pass back a handle by which the created task
290 * can be referenced.
291 *
292 * @return pdPASS if the task was successfully created and added to a ready
293 * list, otherwise an error code defined in the file projdefs.h
294 *
295 * Example usage:
296 <pre>
297 // Task to be created.
298 void vTaskCode( void * pvParameters )
299 {
300 for( ;; )
301 {
302 // Task code goes here.
303 }
304 }
305
306 // Function that creates a task.
307 void vOtherFunction( void )
308 {
309 static uint8_t ucParameterToPass;
310 TaskHandle_t xHandle = NULL;
311
312 // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
313 // must exist for the lifetime of the task, so in this case is declared static. If it was just an
314 // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
315 // the new task attempts to access it.
316 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
317 configASSERT( xHandle );
318
319 // Use the handle to delete the task.
320 if( xHandle != NULL )
321 {
322 vTaskDelete( xHandle );
323 }
324 }
325 </pre>
326 * \defgroup xTaskCreate xTaskCreate
327 * \ingroup Tasks
328 */
329#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
330 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
331 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
332 const configSTACK_DEPTH_TYPE usStackDepth,
333 void * const pvParameters,
334 UBaseType_t uxPriority,
335 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
336#endif
337
338/**
339 * task. h
340 *<pre>
341 TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
342 const char * const pcName,
343 uint32_t ulStackDepth,
344 void *pvParameters,
345 UBaseType_t uxPriority,
346 StackType_t *pxStackBuffer,
347 StaticTask_t *pxTaskBuffer );</pre>
348 *
349 * Create a new task and add it to the list of tasks that are ready to run.
350 *
351 * Internally, within the FreeRTOS implementation, tasks use two blocks of
352 * memory. The first block is used to hold the task's data structures. The
353 * second block is used by the task as its stack. If a task is created using
354 * xTaskCreate() then both blocks of memory are automatically dynamically
355 * allocated inside the xTaskCreate() function. (see
356 * http://www.freertos.org/a00111.html). If a task is created using
357 * xTaskCreateStatic() then the application writer must provide the required
358 * memory. xTaskCreateStatic() therefore allows a task to be created without
359 * using any dynamic memory allocation.
360 *
361 * @param pvTaskCode Pointer to the task entry function. Tasks
362 * must be implemented to never return (i.e. continuous loop).
363 *
364 * @param pcName A descriptive name for the task. This is mainly used to
365 * facilitate debugging. The maximum length of the string is defined by
366 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
367 *
368 * @param ulStackDepth The size of the task stack specified as the number of
369 * variables the stack can hold - not the number of bytes. For example, if
370 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
371 * will be allocated for stack storage.
372 *
373 * @param pvParameters Pointer that will be used as the parameter for the task
374 * being created.
375 *
376 * @param uxPriority The priority at which the task will run.
377 *
378 * @param pxStackBuffer Must point to a StackType_t array that has at least
379 * ulStackDepth indexes - the array will then be used as the task's stack,
380 * removing the need for the stack to be allocated dynamically.
381 *
382 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
383 * then be used to hold the task's data structures, removing the need for the
384 * memory to be allocated dynamically.
385 *
386 * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
387 * be created and a handle to the created task is returned. If either
388 * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
389 * NULL is returned.
390 *
391 * Example usage:
392 <pre>
393
394 // Dimensions the buffer that the task being created will use as its stack.
395 // NOTE: This is the number of words the stack will hold, not the number of
396 // bytes. For example, if each stack item is 32-bits, and this is set to 100,
397 // then 400 bytes (100 * 32-bits) will be allocated.
398 #define STACK_SIZE 200
399
400 // Structure that will hold the TCB of the task being created.
401 StaticTask_t xTaskBuffer;
402
403 // Buffer that the task being created will use as its stack. Note this is
404 // an array of StackType_t variables. The size of StackType_t is dependent on
405 // the RTOS port.
406 StackType_t xStack[ STACK_SIZE ];
407
408 // Function that implements the task being created.
409 void vTaskCode( void * pvParameters )
410 {
411 // The parameter value is expected to be 1 as 1 is passed in the
412 // pvParameters value in the call to xTaskCreateStatic().
413 configASSERT( ( uint32_t ) pvParameters == 1UL );
414
415 for( ;; )
416 {
417 // Task code goes here.
418 }
419 }
420
421 // Function that creates a task.
422 void vOtherFunction( void )
423 {
424 TaskHandle_t xHandle = NULL;
425
426 // Create the task without using any dynamic memory allocation.
427 xHandle = xTaskCreateStatic(
428 vTaskCode, // Function that implements the task.
429 "NAME", // Text name for the task.
430 STACK_SIZE, // Stack size in words, not bytes.
431 ( void * ) 1, // Parameter passed into the task.
432 tskIDLE_PRIORITY,// Priority at which the task is created.
433 xStack, // Array to use as the task's stack.
434 &xTaskBuffer ); // Variable to hold the task's data structure.
435
436 // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
437 // been created, and xHandle will be the task's handle. Use the handle
438 // to suspend the task.
439 vTaskSuspend( xHandle );
440 }
441 </pre>
442 * \defgroup xTaskCreateStatic xTaskCreateStatic
443 * \ingroup Tasks
444 */
445#if( configSUPPORT_STATIC_ALLOCATION == 1 )
446 TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
447 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
448 const uint32_t ulStackDepth,
449 void * const pvParameters,
450 UBaseType_t uxPriority,
451 StackType_t * const puxStackBuffer,
452 StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
453#endif /* configSUPPORT_STATIC_ALLOCATION */
454
455/**
456 * task. h
457 *<pre>
458 BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
459 *
460 * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
461 *
462 * xTaskCreateRestricted() should only be used in systems that include an MPU
463 * implementation.
464 *
465 * Create a new task and add it to the list of tasks that are ready to run.
466 * The function parameters define the memory regions and associated access
467 * permissions allocated to the task.
468 *
469 * See xTaskCreateRestrictedStatic() for a version that does not use any
470 * dynamic memory allocation.
471 *
472 * @param pxTaskDefinition Pointer to a structure that contains a member
473 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
474 * documentation) plus an optional stack buffer and the memory region
475 * definitions.
476 *
477 * @param pxCreatedTask Used to pass back a handle by which the created task
478 * can be referenced.
479 *
480 * @return pdPASS if the task was successfully created and added to a ready
481 * list, otherwise an error code defined in the file projdefs.h
482 *
483 * Example usage:
484 <pre>
485// Create an TaskParameters_t structure that defines the task to be created.
486static const TaskParameters_t xCheckTaskParameters =
487{
488 vATask, // pvTaskCode - the function that implements the task.
489 "ATask", // pcName - just a text name for the task to assist debugging.
490 100, // usStackDepth - the stack size DEFINED IN WORDS.
491 NULL, // pvParameters - passed into the task function as the function parameters.
492 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
493 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
494
495 // xRegions - Allocate up to three separate memory regions for access by
496 // the task, with appropriate access permissions. Different processors have
497 // different memory alignment requirements - refer to the FreeRTOS documentation
498 // for full information.
499 {
500 // Base address Length Parameters
501 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
502 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
503 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
504 }
505};
506
507int main( void )
508{
509TaskHandle_t xHandle;
510
511 // Create a task from the const structure defined above. The task handle
512 // is requested (the second parameter is not NULL) but in this case just for
513 // demonstration purposes as its not actually used.
514 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
515
516 // Start the scheduler.
517 vTaskStartScheduler();
518
519 // Will only get here if there was insufficient memory to create the idle
520 // and/or timer task.
521 for( ;; );
522}
523 </pre>
524 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
525 * \ingroup Tasks
526 */
527#if( portUSING_MPU_WRAPPERS == 1 )
528 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
529#endif
530
531/**
532 * task. h
533 *<pre>
534 BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
535 *
536 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
537 *
538 * xTaskCreateRestrictedStatic() should only be used in systems that include an
539 * MPU implementation.
540 *
541 * Internally, within the FreeRTOS implementation, tasks use two blocks of
542 * memory. The first block is used to hold the task's data structures. The
543 * second block is used by the task as its stack. If a task is created using
544 * xTaskCreateRestricted() then the stack is provided by the application writer,
545 * and the memory used to hold the task's data structure is automatically
546 * dynamically allocated inside the xTaskCreateRestricted() function. If a task
547 * is created using xTaskCreateRestrictedStatic() then the application writer
548 * must provide the memory used to hold the task's data structures too.
549 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
550 * created without using any dynamic memory allocation.
551 *
552 * @param pxTaskDefinition Pointer to a structure that contains a member
553 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
554 * documentation) plus an optional stack buffer and the memory region
555 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
556 * contains an additional member, which is used to point to a variable of type
557 * StaticTask_t - which is then used to hold the task's data structure.
558 *
559 * @param pxCreatedTask Used to pass back a handle by which the created task
560 * can be referenced.
561 *
562 * @return pdPASS if the task was successfully created and added to a ready
563 * list, otherwise an error code defined in the file projdefs.h
564 *
565 * Example usage:
566 <pre>
567// Create an TaskParameters_t structure that defines the task to be created.
568// The StaticTask_t variable is only included in the structure when
569// configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
570// be used to force the variable into the RTOS kernel's privileged data area.
571static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
572static const TaskParameters_t xCheckTaskParameters =
573{
574 vATask, // pvTaskCode - the function that implements the task.
575 "ATask", // pcName - just a text name for the task to assist debugging.
576 100, // usStackDepth - the stack size DEFINED IN WORDS.
577 NULL, // pvParameters - passed into the task function as the function parameters.
578 ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
579 cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
580
581 // xRegions - Allocate up to three separate memory regions for access by
582 // the task, with appropriate access permissions. Different processors have
583 // different memory alignment requirements - refer to the FreeRTOS documentation
584 // for full information.
585 {
586 // Base address Length Parameters
587 { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
588 { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
589 { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
590 }
591
592 &xTaskBuffer; // Holds the task's data structure.
593};
594
595int main( void )
596{
597TaskHandle_t xHandle;
598
599 // Create a task from the const structure defined above. The task handle
600 // is requested (the second parameter is not NULL) but in this case just for
601 // demonstration purposes as its not actually used.
602 xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
603
604 // Start the scheduler.
605 vTaskStartScheduler();
606
607 // Will only get here if there was insufficient memory to create the idle
608 // and/or timer task.
609 for( ;; );
610}
611 </pre>
612 * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
613 * \ingroup Tasks
614 */
615#if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
616 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
617#endif
618
619/**
620 * task. h
621 *<pre>
622 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
623 *
624 * Memory regions are assigned to a restricted task when the task is created by
625 * a call to xTaskCreateRestricted(). These regions can be redefined using
626 * vTaskAllocateMPURegions().
627 *
628 * @param xTask The handle of the task being updated.
629 *
630 * @param xRegions A pointer to an MemoryRegion_t structure that contains the
631 * new memory region definitions.
632 *
633 * Example usage:
634 <pre>
635// Define an array of MemoryRegion_t structures that configures an MPU region
636// allowing read/write access for 1024 bytes starting at the beginning of the
637// ucOneKByte array. The other two of the maximum 3 definable regions are
638// unused so set to zero.
639static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
640{
641 // Base address Length Parameters
642 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
643 { 0, 0, 0 },
644 { 0, 0, 0 }
645};
646
647void vATask( void *pvParameters )
648{
649 // This task was created such that it has access to certain regions of
650 // memory as defined by the MPU configuration. At some point it is
651 // desired that these MPU regions are replaced with that defined in the
652 // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
653 // for this purpose. NULL is used as the task handle to indicate that this
654 // function should modify the MPU regions of the calling task.
655 vTaskAllocateMPURegions( NULL, xAltRegions );
656
657 // Now the task can continue its function, but from this point on can only
658 // access its stack and the ucOneKByte array (unless any other statically
659 // defined or shared regions have been declared elsewhere).
660}
661 </pre>
662 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
663 * \ingroup Tasks
664 */
665void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
666
667/**
668 * task. h
669 * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
670 *
671 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
672 * See the configuration section for more information.
673 *
674 * Remove a task from the RTOS real time kernel's management. The task being
675 * deleted will be removed from all ready, blocked, suspended and event lists.
676 *
677 * NOTE: The idle task is responsible for freeing the kernel allocated
678 * memory from tasks that have been deleted. It is therefore important that
679 * the idle task is not starved of microcontroller processing time if your
680 * application makes any calls to vTaskDelete (). Memory allocated by the
681 * task code is not automatically freed, and should be freed before the task
682 * is deleted.
683 *
684 * See the demo application file death.c for sample code that utilises
685 * vTaskDelete ().
686 *
687 * @param xTask The handle of the task to be deleted. Passing NULL will
688 * cause the calling task to be deleted.
689 *
690 * Example usage:
691 <pre>
692 void vOtherFunction( void )
693 {
694 TaskHandle_t xHandle;
695
696 // Create the task, storing the handle.
697 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
698
699 // Use the handle to delete the task.
700 vTaskDelete( xHandle );
701 }
702 </pre>
703 * \defgroup vTaskDelete vTaskDelete
704 * \ingroup Tasks
705 */
706void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
707
708/*-----------------------------------------------------------
709 * TASK CONTROL API
710 *----------------------------------------------------------*/
711
712/**
713 * task. h
714 * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
715 *
716 * Delay a task for a given number of ticks. The actual time that the
717 * task remains blocked depends on the tick rate. The constant
718 * portTICK_PERIOD_MS can be used to calculate real time from the tick
719 * rate - with the resolution of one tick period.
720 *
721 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
722 * See the configuration section for more information.
723 *
724 *
725 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
726 * the time at which vTaskDelay() is called. For example, specifying a block
727 * period of 100 ticks will cause the task to unblock 100 ticks after
728 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
729 * of controlling the frequency of a periodic task as the path taken through the
730 * code, as well as other task and interrupt activity, will effect the frequency
731 * at which vTaskDelay() gets called and therefore the time at which the task
732 * next executes. See vTaskDelayUntil() for an alternative API function designed
733 * to facilitate fixed frequency execution. It does this by specifying an
734 * absolute time (rather than a relative time) at which the calling task should
735 * unblock.
736 *
737 * @param xTicksToDelay The amount of time, in tick periods, that
738 * the calling task should block.
739 *
740 * Example usage:
741
742 void vTaskFunction( void * pvParameters )
743 {
744 // Block for 500ms.
745 const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
746
747 for( ;; )
748 {
749 // Simply toggle the LED every 500ms, blocking between each toggle.
750 vToggleLED();
751 vTaskDelay( xDelay );
752 }
753 }
754
755 * \defgroup vTaskDelay vTaskDelay
756 * \ingroup TaskCtrl
757 */
758void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
759
760/**
761 * task. h
762 * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
763 *
764 * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
765 * See the configuration section for more information.
766 *
767 * Delay a task until a specified time. This function can be used by periodic
768 * tasks to ensure a constant execution frequency.
769 *
770 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
771 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
772 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
773 * execution frequency as the time between a task starting to execute and that task
774 * calling vTaskDelay () may not be fixed [the task may take a different path though the
775 * code between calls, or may get interrupted or preempted a different number of times
776 * each time it executes].
777 *
778 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
779 * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
780 * unblock.
781 *
782 * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
783 * rate - with the resolution of one tick period.
784 *
785 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
786 * task was last unblocked. The variable must be initialised with the current time
787 * prior to its first use (see the example below). Following this the variable is
788 * automatically updated within vTaskDelayUntil ().
789 *
790 * @param xTimeIncrement The cycle time period. The task will be unblocked at
791 * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
792 * same xTimeIncrement parameter value will cause the task to execute with
793 * a fixed interface period.
794 *
795 * Example usage:
796 <pre>
797 // Perform an action every 10 ticks.
798 void vTaskFunction( void * pvParameters )
799 {
800 TickType_t xLastWakeTime;
801 const TickType_t xFrequency = 10;
802
803 // Initialise the xLastWakeTime variable with the current time.
804 xLastWakeTime = xTaskGetTickCount ();
805 for( ;; )
806 {
807 // Wait for the next cycle.
808 vTaskDelayUntil( &xLastWakeTime, xFrequency );
809
810 // Perform action here.
811 }
812 }
813 </pre>
814 * \defgroup vTaskDelayUntil vTaskDelayUntil
815 * \ingroup TaskCtrl
816 */
817void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
818
819/**
820 * task. h
821 * <pre>BaseType_t xTaskAbortDelay( TaskHandle_t xTask );</pre>
822 *
823 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
824 * function to be available.
825 *
826 * A task will enter the Blocked state when it is waiting for an event. The
827 * event it is waiting for can be a temporal event (waiting for a time), such
828 * as when vTaskDelay() is called, or an event on an object, such as when
829 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
830 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
831 * task will leave the Blocked state, and return from whichever function call
832 * placed the task into the Blocked state.
833 *
834 * There is no 'FromISR' version of this function as an interrupt would need to
835 * know which object a task was blocked on in order to know which actions to
836 * take. For example, if the task was blocked on a queue the interrupt handler
837 * would then need to know if the queue was locked.
838 *
839 * @param xTask The handle of the task to remove from the Blocked state.
840 *
841 * @return If the task referenced by xTask was not in the Blocked state then
842 * pdFAIL is returned. Otherwise pdPASS is returned.
843 *
844 * \defgroup xTaskAbortDelay xTaskAbortDelay
845 * \ingroup TaskCtrl
846 */
847BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
848
849/**
850 * task. h
851 * <pre>UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );</pre>
852 *
853 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
854 * See the configuration section for more information.
855 *
856 * Obtain the priority of any task.
857 *
858 * @param xTask Handle of the task to be queried. Passing a NULL
859 * handle results in the priority of the calling task being returned.
860 *
861 * @return The priority of xTask.
862 *
863 * Example usage:
864 <pre>
865 void vAFunction( void )
866 {
867 TaskHandle_t xHandle;
868
869 // Create a task, storing the handle.
870 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
871
872 // ...
873
874 // Use the handle to obtain the priority of the created task.
875 // It was created with tskIDLE_PRIORITY, but may have changed
876 // it itself.
877 if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
878 {
879 // The task has changed it's priority.
880 }
881
882 // ...
883
884 // Is our priority higher than the created task?
885 if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
886 {
887 // Our priority (obtained using NULL handle) is higher.
888 }
889 }
890 </pre>
891 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
892 * \ingroup TaskCtrl
893 */
894UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
895
896/**
897 * task. h
898 * <pre>UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );</pre>
899 *
900 * A version of uxTaskPriorityGet() that can be used from an ISR.
901 */
902UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
903
904/**
905 * task. h
906 * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
907 *
908 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
909 * See the configuration section for more information.
910 *
911 * Obtain the state of any task. States are encoded by the eTaskState
912 * enumerated type.
913 *
914 * @param xTask Handle of the task to be queried.
915 *
916 * @return The state of xTask at the time the function was called. Note the
917 * state of the task might change between the function being called, and the
918 * functions return value being tested by the calling task.
919 */
920eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
921
922/**
923 * task. h
924 * <pre>void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );</pre>
925 *
926 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
927 * available. See the configuration section for more information.
928 *
929 * Populates a TaskStatus_t structure with information about a task.
930 *
931 * @param xTask Handle of the task being queried. If xTask is NULL then
932 * information will be returned about the calling task.
933 *
934 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
935 * filled with information about the task referenced by the handle passed using
936 * the xTask parameter.
937 *
938 * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
939 * the stack high water mark of the task being queried. Calculating the stack
940 * high water mark takes a relatively long time, and can make the system
941 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
942 * allow the high water mark checking to be skipped. The high watermark value
943 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
944 * not set to pdFALSE;
945 *
946 * @param eState The TaskStatus_t structure contains a member to report the
947 * state of the task being queried. Obtaining the task state is not as fast as
948 * a simple assignment - so the eState parameter is provided to allow the state
949 * information to be omitted from the TaskStatus_t structure. To obtain state
950 * information then set eState to eInvalid - otherwise the value passed in
951 * eState will be reported as the task state in the TaskStatus_t structure.
952 *
953 * Example usage:
954 <pre>
955 void vAFunction( void )
956 {
957 TaskHandle_t xHandle;
958 TaskStatus_t xTaskDetails;
959
960 // Obtain the handle of a task from its name.
961 xHandle = xTaskGetHandle( "Task_Name" );
962
963 // Check the handle is not NULL.
964 configASSERT( xHandle );
965
966 // Use the handle to obtain further information about the task.
967 vTaskGetInfo( xHandle,
968 &xTaskDetails,
969 pdTRUE, // Include the high water mark in xTaskDetails.
970 eInvalid ); // Include the task state in xTaskDetails.
971 }
972 </pre>
973 * \defgroup vTaskGetInfo vTaskGetInfo
974 * \ingroup TaskCtrl
975 */
976void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION;
977
978/**
979 * task. h
980 * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
981 *
982 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
983 * See the configuration section for more information.
984 *
985 * Set the priority of any task.
986 *
987 * A context switch will occur before the function returns if the priority
988 * being set is higher than the currently executing task.
989 *
990 * @param xTask Handle to the task for which the priority is being set.
991 * Passing a NULL handle results in the priority of the calling task being set.
992 *
993 * @param uxNewPriority The priority to which the task will be set.
994 *
995 * Example usage:
996 <pre>
997 void vAFunction( void )
998 {
999 TaskHandle_t xHandle;
1000
1001 // Create a task, storing the handle.
1002 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1003
1004 // ...
1005
1006 // Use the handle to raise the priority of the created task.
1007 vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
1008
1009 // ...
1010
1011 // Use a NULL handle to raise our priority to the same value.
1012 vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1013 }
1014 </pre>
1015 * \defgroup vTaskPrioritySet vTaskPrioritySet
1016 * \ingroup TaskCtrl
1017 */
1018void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
1019
1020/**
1021 * task. h
1022 * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
1023 *
1024 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1025 * See the configuration section for more information.
1026 *
1027 * Suspend any task. When suspended a task will never get any microcontroller
1028 * processing time, no matter what its priority.
1029 *
1030 * Calls to vTaskSuspend are not accumulative -
1031 * i.e. calling vTaskSuspend () twice on the same task still only requires one
1032 * call to vTaskResume () to ready the suspended task.
1033 *
1034 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
1035 * handle will cause the calling task to be suspended.
1036 *
1037 * Example usage:
1038 <pre>
1039 void vAFunction( void )
1040 {
1041 TaskHandle_t xHandle;
1042
1043 // Create a task, storing the handle.
1044 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1045
1046 // ...
1047
1048 // Use the handle to suspend the created task.
1049 vTaskSuspend( xHandle );
1050
1051 // ...
1052
1053 // The created task will not run during this period, unless
1054 // another task calls vTaskResume( xHandle ).
1055
1056 //...
1057
1058
1059 // Suspend ourselves.
1060 vTaskSuspend( NULL );
1061
1062 // We cannot get here unless another task calls vTaskResume
1063 // with our handle as the parameter.
1064 }
1065 </pre>
1066 * \defgroup vTaskSuspend vTaskSuspend
1067 * \ingroup TaskCtrl
1068 */
1069void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1070
1071/**
1072 * task. h
1073 * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
1074 *
1075 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1076 * See the configuration section for more information.
1077 *
1078 * Resumes a suspended task.
1079 *
1080 * A task that has been suspended by one or more calls to vTaskSuspend ()
1081 * will be made available for running again by a single call to
1082 * vTaskResume ().
1083 *
1084 * @param xTaskToResume Handle to the task being readied.
1085 *
1086 * Example usage:
1087 <pre>
1088 void vAFunction( void )
1089 {
1090 TaskHandle_t xHandle;
1091
1092 // Create a task, storing the handle.
1093 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1094
1095 // ...
1096
1097 // Use the handle to suspend the created task.
1098 vTaskSuspend( xHandle );
1099
1100 // ...
1101
1102 // The created task will not run during this period, unless
1103 // another task calls vTaskResume( xHandle ).
1104
1105 //...
1106
1107
1108 // Resume the suspended task ourselves.
1109 vTaskResume( xHandle );
1110
1111 // The created task will once again get microcontroller processing
1112 // time in accordance with its priority within the system.
1113 }
1114 </pre>
1115 * \defgroup vTaskResume vTaskResume
1116 * \ingroup TaskCtrl
1117 */
1118void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1119
1120/**
1121 * task. h
1122 * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
1123 *
1124 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1125 * available. See the configuration section for more information.
1126 *
1127 * An implementation of vTaskResume() that can be called from within an ISR.
1128 *
1129 * A task that has been suspended by one or more calls to vTaskSuspend ()
1130 * will be made available for running again by a single call to
1131 * xTaskResumeFromISR ().
1132 *
1133 * xTaskResumeFromISR() should not be used to synchronise a task with an
1134 * interrupt if there is a chance that the interrupt could arrive prior to the
1135 * task being suspended - as this can lead to interrupts being missed. Use of a
1136 * semaphore as a synchronisation mechanism would avoid this eventuality.
1137 *
1138 * @param xTaskToResume Handle to the task being readied.
1139 *
1140 * @return pdTRUE if resuming the task should result in a context switch,
1141 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1142 * may be required following the ISR.
1143 *
1144 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1145 * \ingroup TaskCtrl
1146 */
1147BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1148
1149/*-----------------------------------------------------------
1150 * SCHEDULER CONTROL
1151 *----------------------------------------------------------*/
1152
1153/**
1154 * task. h
1155 * <pre>void vTaskStartScheduler( void );</pre>
1156 *
1157 * Starts the real time kernel tick processing. After calling the kernel
1158 * has control over which tasks are executed and when.
1159 *
1160 * See the demo application file main.c for an example of creating
1161 * tasks and starting the kernel.
1162 *
1163 * Example usage:
1164 <pre>
1165 void vAFunction( void )
1166 {
1167 // Create at least one task before starting the kernel.
1168 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1169
1170 // Start the real time kernel with preemption.
1171 vTaskStartScheduler ();
1172
1173 // Will not get here unless a task calls vTaskEndScheduler ()
1174 }
1175 </pre>
1176 *
1177 * \defgroup vTaskStartScheduler vTaskStartScheduler
1178 * \ingroup SchedulerControl
1179 */
1180void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1181
1182/**
1183 * task. h
1184 * <pre>void vTaskEndScheduler( void );</pre>
1185 *
1186 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
1187 * in place of DOS, implements this function.
1188 *
1189 * Stops the real time kernel tick. All created tasks will be automatically
1190 * deleted and multitasking (either preemptive or cooperative) will
1191 * stop. Execution then resumes from the point where vTaskStartScheduler ()
1192 * was called, as if vTaskStartScheduler () had just returned.
1193 *
1194 * See the demo application file main. c in the demo/PC directory for an
1195 * example that uses vTaskEndScheduler ().
1196 *
1197 * vTaskEndScheduler () requires an exit function to be defined within the
1198 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1199 * performs hardware specific operations such as stopping the kernel tick.
1200 *
1201 * vTaskEndScheduler () will cause all of the resources allocated by the
1202 * kernel to be freed - but will not free resources allocated by application
1203 * tasks.
1204 *
1205 * Example usage:
1206 <pre>
1207 void vTaskCode( void * pvParameters )
1208 {
1209 for( ;; )
1210 {
1211 // Task code goes here.
1212
1213 // At some point we want to end the real time kernel processing
1214 // so call ...
1215 vTaskEndScheduler ();
1216 }
1217 }
1218
1219 void vAFunction( void )
1220 {
1221 // Create at least one task before starting the kernel.
1222 xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1223
1224 // Start the real time kernel with preemption.
1225 vTaskStartScheduler ();
1226
1227 // Will only get here when the vTaskCode () task has called
1228 // vTaskEndScheduler (). When we get here we are back to single task
1229 // execution.
1230 }
1231 </pre>
1232 *
1233 * \defgroup vTaskEndScheduler vTaskEndScheduler
1234 * \ingroup SchedulerControl
1235 */
1236void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1237
1238/**
1239 * task. h
1240 * <pre>void vTaskSuspendAll( void );</pre>
1241 *
1242 * Suspends the scheduler without disabling interrupts. Context switches will
1243 * not occur while the scheduler is suspended.
1244 *
1245 * After calling vTaskSuspendAll () the calling task will continue to execute
1246 * without risk of being swapped out until a call to xTaskResumeAll () has been
1247 * made.
1248 *
1249 * API functions that have the potential to cause a context switch (for example,
1250 * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1251 * is suspended.
1252 *
1253 * Example usage:
1254 <pre>
1255 void vTask1( void * pvParameters )
1256 {
1257 for( ;; )
1258 {
1259 // Task code goes here.
1260
1261 // ...
1262
1263 // At some point the task wants to perform a long operation during
1264 // which it does not want to get swapped out. It cannot use
1265 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1266 // operation may cause interrupts to be missed - including the
1267 // ticks.
1268
1269 // Prevent the real time kernel swapping out the task.
1270 vTaskSuspendAll ();
1271
1272 // Perform the operation here. There is no need to use critical
1273 // sections as we have all the microcontroller processing time.
1274 // During this time interrupts will still operate and the kernel
1275 // tick count will be maintained.
1276
1277 // ...
1278
1279 // The operation is complete. Restart the kernel.
1280 xTaskResumeAll ();
1281 }
1282 }
1283 </pre>
1284 * \defgroup vTaskSuspendAll vTaskSuspendAll
1285 * \ingroup SchedulerControl
1286 */
1287void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1288
1289/**
1290 * task. h
1291 * <pre>BaseType_t xTaskResumeAll( void );</pre>
1292 *
1293 * Resumes scheduler activity after it was suspended by a call to
1294 * vTaskSuspendAll().
1295 *
1296 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1297 * that were previously suspended by a call to vTaskSuspend().
1298 *
1299 * @return If resuming the scheduler caused a context switch then pdTRUE is
1300 * returned, otherwise pdFALSE is returned.
1301 *
1302 * Example usage:
1303 <pre>
1304 void vTask1( void * pvParameters )
1305 {
1306 for( ;; )
1307 {
1308 // Task code goes here.
1309
1310 // ...
1311
1312 // At some point the task wants to perform a long operation during
1313 // which it does not want to get swapped out. It cannot use
1314 // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1315 // operation may cause interrupts to be missed - including the
1316 // ticks.
1317
1318 // Prevent the real time kernel swapping out the task.
1319 vTaskSuspendAll ();
1320
1321 // Perform the operation here. There is no need to use critical
1322 // sections as we have all the microcontroller processing time.
1323 // During this time interrupts will still operate and the real
1324 // time kernel tick count will be maintained.
1325
1326 // ...
1327
1328 // The operation is complete. Restart the kernel. We want to force
1329 // a context switch - but there is no point if resuming the scheduler
1330 // caused a context switch already.
1331 if( !xTaskResumeAll () )
1332 {
1333 taskYIELD ();
1334 }
1335 }
1336 }
1337 </pre>
1338 * \defgroup xTaskResumeAll xTaskResumeAll
1339 * \ingroup SchedulerControl
1340 */
1341BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1342
1343/*-----------------------------------------------------------
1344 * TASK UTILITIES
1345 *----------------------------------------------------------*/
1346
1347/**
1348 * task. h
1349 * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
1350 *
1351 * @return The count of ticks since vTaskStartScheduler was called.
1352 *
1353 * \defgroup xTaskGetTickCount xTaskGetTickCount
1354 * \ingroup TaskUtils
1355 */
1356TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1357
1358/**
1359 * task. h
1360 * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
1361 *
1362 * @return The count of ticks since vTaskStartScheduler was called.
1363 *
1364 * This is a version of xTaskGetTickCount() that is safe to be called from an
1365 * ISR - provided that TickType_t is the natural word size of the
1366 * microcontroller being used or interrupt nesting is either not supported or
1367 * not being used.
1368 *
1369 * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1370 * \ingroup TaskUtils
1371 */
1372TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1373
1374/**
1375 * task. h
1376 * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
1377 *
1378 * @return The number of tasks that the real time kernel is currently managing.
1379 * This includes all ready, blocked and suspended tasks. A task that
1380 * has been deleted but not yet freed by the idle task will also be
1381 * included in the count.
1382 *
1383 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1384 * \ingroup TaskUtils
1385 */
1386UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1387
1388/**
1389 * task. h
1390 * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
1391 *
1392 * @return The text (human readable) name of the task referenced by the handle
1393 * xTaskToQuery. A task can query its own name by either passing in its own
1394 * handle, or by setting xTaskToQuery to NULL.
1395 *
1396 * \defgroup pcTaskGetName pcTaskGetName
1397 * \ingroup TaskUtils
1398 */
1399char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1400
1401/**
1402 * task. h
1403 * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
1404 *
1405 * NOTE: This function takes a relatively long time to complete and should be
1406 * used sparingly.
1407 *
1408 * @return The handle of the task that has the human readable name pcNameToQuery.
1409 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
1410 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1411 *
1412 * \defgroup pcTaskGetHandle pcTaskGetHandle
1413 * \ingroup TaskUtils
1414 */
1415TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1416
1417/**
1418 * task.h
1419 * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
1420 *
1421 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1422 * this function to be available.
1423 *
1424 * Returns the high water mark of the stack associated with xTask. That is,
1425 * the minimum free stack space there has been (in words, so on a 32 bit machine
1426 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1427 * number the closer the task has come to overflowing its stack.
1428 *
1429 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1430 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1431 * user to determine the return type. It gets around the problem of the value
1432 * overflowing on 8-bit types without breaking backward compatibility for
1433 * applications that expect an 8-bit return type.
1434 *
1435 * @param xTask Handle of the task associated with the stack to be checked.
1436 * Set xTask to NULL to check the stack of the calling task.
1437 *
1438 * @return The smallest amount of free stack space there has been (in words, so
1439 * actual spaces on the stack rather than bytes) since the task referenced by
1440 * xTask was created.
1441 */
1442UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1443
1444/**
1445 * task.h
1446 * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
1447 *
1448 * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1449 * this function to be available.
1450 *
1451 * Returns the high water mark of the stack associated with xTask. That is,
1452 * the minimum free stack space there has been (in words, so on a 32 bit machine
1453 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1454 * number the closer the task has come to overflowing its stack.
1455 *
1456 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1457 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1458 * user to determine the return type. It gets around the problem of the value
1459 * overflowing on 8-bit types without breaking backward compatibility for
1460 * applications that expect an 8-bit return type.
1461 *
1462 * @param xTask Handle of the task associated with the stack to be checked.
1463 * Set xTask to NULL to check the stack of the calling task.
1464 *
1465 * @return The smallest amount of free stack space there has been (in words, so
1466 * actual spaces on the stack rather than bytes) since the task referenced by
1467 * xTask was created.
1468 */
1469configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1470
1471/* When using trace macros it is sometimes necessary to include task.h before
1472FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1473so the following two prototypes will cause a compilation error. This can be
1474fixed by simply guarding against the inclusion of these two prototypes unless
1475they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1476constant. */
1477#ifdef configUSE_APPLICATION_TASK_TAG
1478 #if configUSE_APPLICATION_TASK_TAG == 1
1479 /**
1480 * task.h
1481 * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
1482 *
1483 * Sets pxHookFunction to be the task hook function used by the task xTask.
1484 * Passing xTask as NULL has the effect of setting the calling tasks hook
1485 * function.
1486 */
1487 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1488
1489 /**
1490 * task.h
1491 * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
1492 *
1493 * Returns the pxHookFunction value assigned to the task xTask. Do not
1494 * call from an interrupt service routine - call
1495 * xTaskGetApplicationTaskTagFromISR() instead.
1496 */
1497 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1498
1499 /**
1500 * task.h
1501 * <pre>void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );</pre>
1502 *
1503 * Returns the pxHookFunction value assigned to the task xTask. Can
1504 * be called from an interrupt service routine.
1505 */
1506 TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1507 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1508#endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1509
1510#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1511
1512 /* Each task contains an array of pointers that is dimensioned by the
1513 configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
1514 kernel does not use the pointers itself, so the application writer can use
1515 the pointers for any purpose they wish. The following two functions are
1516 used to set and query a pointer respectively. */
1517 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1518 void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1519
1520#endif
1521
1522/**
1523 * task.h
1524 * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
1525 *
1526 * Calls the hook function associated with xTask. Passing xTask as NULL has
1527 * the effect of calling the Running tasks (the calling task) hook function.
1528 *
1529 * pvParameter is passed to the hook function for the task to interpret as it
1530 * wants. The return value is the value returned by the task hook function
1531 * registered by the user.
1532 */
1533BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
1534
1535/**
1536 * xTaskGetIdleTaskHandle() is only available if
1537 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1538 *
1539 * Simply returns the handle of the idle task. It is not valid to call
1540 * xTaskGetIdleTaskHandle() before the scheduler has been started.
1541 */
1542TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
1543
1544/**
1545 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1546 * uxTaskGetSystemState() to be available.
1547 *
1548 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1549 * the system. TaskStatus_t structures contain, among other things, members
1550 * for the task handle, task name, task priority, task state, and total amount
1551 * of run time consumed by the task. See the TaskStatus_t structure
1552 * definition in this file for the full member list.
1553 *
1554 * NOTE: This function is intended for debugging use only as its use results in
1555 * the scheduler remaining suspended for an extended period.
1556 *
1557 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1558 * The array must contain at least one TaskStatus_t structure for each task
1559 * that is under the control of the RTOS. The number of tasks under the control
1560 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1561 *
1562 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1563 * parameter. The size is specified as the number of indexes in the array, or
1564 * the number of TaskStatus_t structures contained in the array, not by the
1565 * number of bytes in the array.
1566 *
1567 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1568 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1569 * total run time (as defined by the run time stats clock, see
1570 * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
1571 * pulTotalRunTime can be set to NULL to omit the total run time information.
1572 *
1573 * @return The number of TaskStatus_t structures that were populated by
1574 * uxTaskGetSystemState(). This should equal the number returned by the
1575 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1576 * in the uxArraySize parameter was too small.
1577 *
1578 * Example usage:
1579 <pre>
1580 // This example demonstrates how a human readable table of run time stats
1581 // information is generated from raw data provided by uxTaskGetSystemState().
1582 // The human readable table is written to pcWriteBuffer
1583 void vTaskGetRunTimeStats( char *pcWriteBuffer )
1584 {
1585 TaskStatus_t *pxTaskStatusArray;
1586 volatile UBaseType_t uxArraySize, x;
1587 uint32_t ulTotalRunTime, ulStatsAsPercentage;
1588
1589 // Make sure the write buffer does not contain a string.
1590 *pcWriteBuffer = 0x00;
1591
1592 // Take a snapshot of the number of tasks in case it changes while this
1593 // function is executing.
1594 uxArraySize = uxTaskGetNumberOfTasks();
1595
1596 // Allocate a TaskStatus_t structure for each task. An array could be
1597 // allocated statically at compile time.
1598 pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1599
1600 if( pxTaskStatusArray != NULL )
1601 {
1602 // Generate raw status information about each task.
1603 uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1604
1605 // For percentage calculations.
1606 ulTotalRunTime /= 100UL;
1607
1608 // Avoid divide by zero errors.
1609 if( ulTotalRunTime > 0 )
1610 {
1611 // For each populated position in the pxTaskStatusArray array,
1612 // format the raw data as human readable ASCII data
1613 for( x = 0; x < uxArraySize; x++ )
1614 {
1615 // What percentage of the total run time has the task used?
1616 // This will always be rounded down to the nearest integer.
1617 // ulTotalRunTimeDiv100 has already been divided by 100.
1618 ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1619
1620 if( ulStatsAsPercentage > 0UL )
1621 {
1622 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1623 }
1624 else
1625 {
1626 // If the percentage is zero here then the task has
1627 // consumed less than 1% of the total run time.
1628 sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1629 }
1630
1631 pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1632 }
1633 }
1634
1635 // The array is no longer needed, free the memory it consumes.
1636 vPortFree( pxTaskStatusArray );
1637 }
1638 }
1639 </pre>
1640 */
1641UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
1642
1643/**
1644 * task. h
1645 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
1646 *
1647 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1648 * both be defined as 1 for this function to be available. See the
1649 * configuration section of the FreeRTOS.org website for more information.
1650 *
1651 * NOTE 1: This function will disable interrupts for its duration. It is
1652 * not intended for normal application runtime use but as a debug aid.
1653 *
1654 * Lists all the current tasks, along with their current state and stack
1655 * usage high water mark.
1656 *
1657 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
1658 * suspended ('S').
1659 *
1660 * PLEASE NOTE:
1661 *
1662 * This function is provided for convenience only, and is used by many of the
1663 * demo applications. Do not consider it to be part of the scheduler.
1664 *
1665 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
1666 * uxTaskGetSystemState() output into a human readable table that displays task
1667 * names, states and stack usage.
1668 *
1669 * vTaskList() has a dependency on the sprintf() C library function that might
1670 * bloat the code size, use a lot of stack, and provide different results on
1671 * different platforms. An alternative, tiny, third party, and limited
1672 * functionality implementation of sprintf() is provided in many of the
1673 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1674 * printf-stdarg.c does not provide a full snprintf() implementation!).
1675 *
1676 * It is recommended that production systems call uxTaskGetSystemState()
1677 * directly to get access to raw stats data, rather than indirectly through a
1678 * call to vTaskList().
1679 *
1680 * @param pcWriteBuffer A buffer into which the above mentioned details
1681 * will be written, in ASCII form. This buffer is assumed to be large
1682 * enough to contain the generated report. Approximately 40 bytes per
1683 * task should be sufficient.
1684 *
1685 * \defgroup vTaskList vTaskList
1686 * \ingroup TaskUtils
1687 */
1688void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1689
1690/**
1691 * task. h
1692 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
1693 *
1694 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1695 * must both be defined as 1 for this function to be available. The application
1696 * must also then provide definitions for
1697 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1698 * to configure a peripheral timer/counter and return the timers current count
1699 * value respectively. The counter should be at least 10 times the frequency of
1700 * the tick count.
1701 *
1702 * NOTE 1: This function will disable interrupts for its duration. It is
1703 * not intended for normal application runtime use but as a debug aid.
1704 *
1705 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1706 * accumulated execution time being stored for each task. The resolution
1707 * of the accumulated time value depends on the frequency of the timer
1708 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1709 * Calling vTaskGetRunTimeStats() writes the total execution time of each
1710 * task into a buffer, both as an absolute count value and as a percentage
1711 * of the total system execution time.
1712 *
1713 * NOTE 2:
1714 *
1715 * This function is provided for convenience only, and is used by many of the
1716 * demo applications. Do not consider it to be part of the scheduler.
1717 *
1718 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1719 * uxTaskGetSystemState() output into a human readable table that displays the
1720 * amount of time each task has spent in the Running state in both absolute and
1721 * percentage terms.
1722 *
1723 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1724 * that might bloat the code size, use a lot of stack, and provide different
1725 * results on different platforms. An alternative, tiny, third party, and
1726 * limited functionality implementation of sprintf() is provided in many of the
1727 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1728 * printf-stdarg.c does not provide a full snprintf() implementation!).
1729 *
1730 * It is recommended that production systems call uxTaskGetSystemState() directly
1731 * to get access to raw stats data, rather than indirectly through a call to
1732 * vTaskGetRunTimeStats().
1733 *
1734 * @param pcWriteBuffer A buffer into which the execution times will be
1735 * written, in ASCII form. This buffer is assumed to be large enough to
1736 * contain the generated report. Approximately 40 bytes per task should
1737 * be sufficient.
1738 *
1739 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
1740 * \ingroup TaskUtils
1741 */
1742void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1743
1744/**
1745* task. h
1746* <PRE>uint32_t ulTaskGetIdleRunTimeCounter( void );</PRE>
1747*
1748* configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1749* must both be defined as 1 for this function to be available. The application
1750* must also then provide definitions for
1751* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1752* to configure a peripheral timer/counter and return the timers current count
1753* value respectively. The counter should be at least 10 times the frequency of
1754* the tick count.
1755*
1756* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1757* accumulated execution time being stored for each task. The resolution
1758* of the accumulated time value depends on the frequency of the timer
1759* configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1760* While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
1761* execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
1762* returns the total execution time of just the idle task.
1763*
1764* @return The total run time of the idle task. This is the amount of time the
1765* idle task has actually been executing. The unit of time is dependent on the
1766* frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1767* portGET_RUN_TIME_COUNTER_VALUE() macros.
1768*
1769* \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
1770* \ingroup TaskUtils
1771*/
1772uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
1773
1774/**
1775 * task. h
1776 * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
1777 *
1778 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1779 * function to be available.
1780 *
1781 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1782 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1783 *
1784 * Events can be sent to a task using an intermediary object. Examples of such
1785 * objects are queues, semaphores, mutexes and event groups. Task notifications
1786 * are a method of sending an event directly to a task without the need for such
1787 * an intermediary object.
1788 *
1789 * A notification sent to a task can optionally perform an action, such as
1790 * update, overwrite or increment the task's notification value. In that way
1791 * task notifications can be used to send data to a task, or be used as light
1792 * weight and fast binary or counting semaphores.
1793 *
1794 * A notification sent to a task will remain pending until it is cleared by the
1795 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1796 * already in the Blocked state to wait for a notification when the notification
1797 * arrives then the task will automatically be removed from the Blocked state
1798 * (unblocked) and the notification cleared.
1799 *
1800 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1801 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1802 * to wait for its notification value to have a non-zero value. The task does
1803 * not consume any CPU time while it is in the Blocked state.
1804 *
1805 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1806 *
1807 * @param xTaskToNotify The handle of the task being notified. The handle to a
1808 * task can be returned from the xTaskCreate() API function used to create the
1809 * task, and the handle of the currently running task can be obtained by calling
1810 * xTaskGetCurrentTaskHandle().
1811 *
1812 * @param ulValue Data that can be sent with the notification. How the data is
1813 * used depends on the value of the eAction parameter.
1814 *
1815 * @param eAction Specifies how the notification updates the task's notification
1816 * value, if at all. Valid values for eAction are as follows:
1817 *
1818 * eSetBits -
1819 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1820 * always returns pdPASS in this case.
1821 *
1822 * eIncrement -
1823 * The task's notification value is incremented. ulValue is not used and
1824 * xTaskNotify() always returns pdPASS in this case.
1825 *
1826 * eSetValueWithOverwrite -
1827 * The task's notification value is set to the value of ulValue, even if the
1828 * task being notified had not yet processed the previous notification (the
1829 * task already had a notification pending). xTaskNotify() always returns
1830 * pdPASS in this case.
1831 *
1832 * eSetValueWithoutOverwrite -
1833 * If the task being notified did not already have a notification pending then
1834 * the task's notification value is set to ulValue and xTaskNotify() will
1835 * return pdPASS. If the task being notified already had a notification
1836 * pending then no action is performed and pdFAIL is returned.
1837 *
1838 * eNoAction -
1839 * The task receives a notification without its notification value being
1840 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1841 * this case.
1842 *
1843 * pulPreviousNotificationValue -
1844 * Can be used to pass out the subject task's notification value before any
1845 * bits are modified by the notify function.
1846 *
1847 * @return Dependent on the value of eAction. See the description of the
1848 * eAction parameter.
1849 *
1850 * \defgroup xTaskNotify xTaskNotify
1851 * \ingroup TaskNotifications
1852 */
1853BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
1854#define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
1855#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
1856
1857/**
1858 * task. h
1859 * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
1860 *
1861 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1862 * function to be available.
1863 *
1864 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1865 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1866 *
1867 * A version of xTaskNotify() that can be used from an interrupt service routine
1868 * (ISR).
1869 *
1870 * Events can be sent to a task using an intermediary object. Examples of such
1871 * objects are queues, semaphores, mutexes and event groups. Task notifications
1872 * are a method of sending an event directly to a task without the need for such
1873 * an intermediary object.
1874 *
1875 * A notification sent to a task can optionally perform an action, such as
1876 * update, overwrite or increment the task's notification value. In that way
1877 * task notifications can be used to send data to a task, or be used as light
1878 * weight and fast binary or counting semaphores.
1879 *
1880 * A notification sent to a task will remain pending until it is cleared by the
1881 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1882 * already in the Blocked state to wait for a notification when the notification
1883 * arrives then the task will automatically be removed from the Blocked state
1884 * (unblocked) and the notification cleared.
1885 *
1886 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1887 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1888 * to wait for its notification value to have a non-zero value. The task does
1889 * not consume any CPU time while it is in the Blocked state.
1890 *
1891 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1892 *
1893 * @param xTaskToNotify The handle of the task being notified. The handle to a
1894 * task can be returned from the xTaskCreate() API function used to create the
1895 * task, and the handle of the currently running task can be obtained by calling
1896 * xTaskGetCurrentTaskHandle().
1897 *
1898 * @param ulValue Data that can be sent with the notification. How the data is
1899 * used depends on the value of the eAction parameter.
1900 *
1901 * @param eAction Specifies how the notification updates the task's notification
1902 * value, if at all. Valid values for eAction are as follows:
1903 *
1904 * eSetBits -
1905 * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
1906 * always returns pdPASS in this case.
1907 *
1908 * eIncrement -
1909 * The task's notification value is incremented. ulValue is not used and
1910 * xTaskNotify() always returns pdPASS in this case.
1911 *
1912 * eSetValueWithOverwrite -
1913 * The task's notification value is set to the value of ulValue, even if the
1914 * task being notified had not yet processed the previous notification (the
1915 * task already had a notification pending). xTaskNotify() always returns
1916 * pdPASS in this case.
1917 *
1918 * eSetValueWithoutOverwrite -
1919 * If the task being notified did not already have a notification pending then
1920 * the task's notification value is set to ulValue and xTaskNotify() will
1921 * return pdPASS. If the task being notified already had a notification
1922 * pending then no action is performed and pdFAIL is returned.
1923 *
1924 * eNoAction -
1925 * The task receives a notification without its notification value being
1926 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
1927 * this case.
1928 *
1929 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
1930 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1931 * task to which the notification was sent to leave the Blocked state, and the
1932 * unblocked task has a priority higher than the currently running task. If
1933 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1934 * be requested before the interrupt is exited. How a context switch is
1935 * requested from an ISR is dependent on the port - see the documentation page
1936 * for the port in use.
1937 *
1938 * @return Dependent on the value of eAction. See the description of the
1939 * eAction parameter.
1940 *
1941 * \defgroup xTaskNotify xTaskNotify
1942 * \ingroup TaskNotifications
1943 */
1944BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1945#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
1946#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
1947
1948/**
1949 * task. h
1950 * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
1951 *
1952 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1953 * function to be available.
1954 *
1955 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1956 * "notification value", which is a 32-bit unsigned integer (uint32_t).
1957 *
1958 * Events can be sent to a task using an intermediary object. Examples of such
1959 * objects are queues, semaphores, mutexes and event groups. Task notifications
1960 * are a method of sending an event directly to a task without the need for such
1961 * an intermediary object.
1962 *
1963 * A notification sent to a task can optionally perform an action, such as
1964 * update, overwrite or increment the task's notification value. In that way
1965 * task notifications can be used to send data to a task, or be used as light
1966 * weight and fast binary or counting semaphores.
1967 *
1968 * A notification sent to a task will remain pending until it is cleared by the
1969 * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
1970 * already in the Blocked state to wait for a notification when the notification
1971 * arrives then the task will automatically be removed from the Blocked state
1972 * (unblocked) and the notification cleared.
1973 *
1974 * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1975 * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1976 * to wait for its notification value to have a non-zero value. The task does
1977 * not consume any CPU time while it is in the Blocked state.
1978 *
1979 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1980 *
1981 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1982 * will be cleared in the calling task's notification value before the task
1983 * checks to see if any notifications are pending, and optionally blocks if no
1984 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
1985 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1986 * the effect of resetting the task's notification value to 0. Setting
1987 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1988 *
1989 * @param ulBitsToClearOnExit If a notification is pending or received before
1990 * the calling task exits the xTaskNotifyWait() function then the task's
1991 * notification value (see the xTaskNotify() API function) is passed out using
1992 * the pulNotificationValue parameter. Then any bits that are set in
1993 * ulBitsToClearOnExit will be cleared in the task's notification value (note
1994 * *pulNotificationValue is set before any bits are cleared). Setting
1995 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1996 * (if limits.h is not included) will have the effect of resetting the task's
1997 * notification value to 0 before the function exits. Setting
1998 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1999 * when the function exits (in which case the value passed out in
2000 * pulNotificationValue will match the task's notification value).
2001 *
2002 * @param pulNotificationValue Used to pass the task's notification value out
2003 * of the function. Note the value passed out will not be effected by the
2004 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
2005 *
2006 * @param xTicksToWait The maximum amount of time that the task should wait in
2007 * the Blocked state for a notification to be received, should a notification
2008 * not already be pending when xTaskNotifyWait() was called. The task
2009 * will not consume any processing time while it is in the Blocked state. This
2010 * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
2011 * used to convert a time specified in milliseconds to a time specified in
2012 * ticks.
2013 *
2014 * @return If a notification was received (including notifications that were
2015 * already pending when xTaskNotifyWait was called) then pdPASS is
2016 * returned. Otherwise pdFAIL is returned.
2017 *
2018 * \defgroup xTaskNotifyWait xTaskNotifyWait
2019 * \ingroup TaskNotifications
2020 */
2021BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2022
2023/**
2024 * task. h
2025 * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
2026 *
2027 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2028 * to be available.
2029 *
2030 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2031 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2032 *
2033 * Events can be sent to a task using an intermediary object. Examples of such
2034 * objects are queues, semaphores, mutexes and event groups. Task notifications
2035 * are a method of sending an event directly to a task without the need for such
2036 * an intermediary object.
2037 *
2038 * A notification sent to a task can optionally perform an action, such as
2039 * update, overwrite or increment the task's notification value. In that way
2040 * task notifications can be used to send data to a task, or be used as light
2041 * weight and fast binary or counting semaphores.
2042 *
2043 * xTaskNotifyGive() is a helper macro intended for use when task notifications
2044 * are used as light weight and faster binary or counting semaphore equivalents.
2045 * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
2046 * the equivalent action that instead uses a task notification is
2047 * xTaskNotifyGive().
2048 *
2049 * When task notifications are being used as a binary or counting semaphore
2050 * equivalent then the task being notified should wait for the notification
2051 * using the ulTaskNotificationTake() API function rather than the
2052 * xTaskNotifyWait() API function.
2053 *
2054 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2055 *
2056 * @param xTaskToNotify The handle of the task being notified. The handle to a
2057 * task can be returned from the xTaskCreate() API function used to create the
2058 * task, and the handle of the currently running task can be obtained by calling
2059 * xTaskGetCurrentTaskHandle().
2060 *
2061 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
2062 * eAction parameter set to eIncrement - so pdPASS is always returned.
2063 *
2064 * \defgroup xTaskNotifyGive xTaskNotifyGive
2065 * \ingroup TaskNotifications
2066 */
2067#define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
2068
2069/**
2070 * task. h
2071 * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
2072 *
2073 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2074 * to be available.
2075 *
2076 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2077 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2078 *
2079 * A version of xTaskNotifyGive() that can be called from an interrupt service
2080 * routine (ISR).
2081 *
2082 * Events can be sent to a task using an intermediary object. Examples of such
2083 * objects are queues, semaphores, mutexes and event groups. Task notifications
2084 * are a method of sending an event directly to a task without the need for such
2085 * an intermediary object.
2086 *
2087 * A notification sent to a task can optionally perform an action, such as
2088 * update, overwrite or increment the task's notification value. In that way
2089 * task notifications can be used to send data to a task, or be used as light
2090 * weight and fast binary or counting semaphores.
2091 *
2092 * vTaskNotifyGiveFromISR() is intended for use when task notifications are
2093 * used as light weight and faster binary or counting semaphore equivalents.
2094 * Actual FreeRTOS semaphores are given from an ISR using the
2095 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
2096 * a task notification is vTaskNotifyGiveFromISR().
2097 *
2098 * When task notifications are being used as a binary or counting semaphore
2099 * equivalent then the task being notified should wait for the notification
2100 * using the ulTaskNotificationTake() API function rather than the
2101 * xTaskNotifyWait() API function.
2102 *
2103 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2104 *
2105 * @param xTaskToNotify The handle of the task being notified. The handle to a
2106 * task can be returned from the xTaskCreate() API function used to create the
2107 * task, and the handle of the currently running task can be obtained by calling
2108 * xTaskGetCurrentTaskHandle().
2109 *
2110 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2111 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2112 * task to which the notification was sent to leave the Blocked state, and the
2113 * unblocked task has a priority higher than the currently running task. If
2114 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2115 * should be requested before the interrupt is exited. How a context switch is
2116 * requested from an ISR is dependent on the port - see the documentation page
2117 * for the port in use.
2118 *
2119 * \defgroup xTaskNotifyWait xTaskNotifyWait
2120 * \ingroup TaskNotifications
2121 */
2122void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2123
2124/**
2125 * task. h
2126 * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
2127 *
2128 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2129 * function to be available.
2130 *
2131 * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2132 * "notification value", which is a 32-bit unsigned integer (uint32_t).
2133 *
2134 * Events can be sent to a task using an intermediary object. Examples of such
2135 * objects are queues, semaphores, mutexes and event groups. Task notifications
2136 * are a method of sending an event directly to a task without the need for such
2137 * an intermediary object.
2138 *
2139 * A notification sent to a task can optionally perform an action, such as
2140 * update, overwrite or increment the task's notification value. In that way
2141 * task notifications can be used to send data to a task, or be used as light
2142 * weight and fast binary or counting semaphores.
2143 *
2144 * ulTaskNotifyTake() is intended for use when a task notification is used as a
2145 * faster and lighter weight binary or counting semaphore alternative. Actual
2146 * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2147 * equivalent action that instead uses a task notification is
2148 * ulTaskNotifyTake().
2149 *
2150 * When a task is using its notification value as a binary or counting semaphore
2151 * other tasks should send notifications to it using the xTaskNotifyGive()
2152 * macro, or xTaskNotify() function with the eAction parameter set to
2153 * eIncrement.
2154 *
2155 * ulTaskNotifyTake() can either clear the task's notification value to
2156 * zero on exit, in which case the notification value acts like a binary
2157 * semaphore, or decrement the task's notification value on exit, in which case
2158 * the notification value acts like a counting semaphore.
2159 *
2160 * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2161 * the task's notification value to be non-zero. The task does not consume any
2162 * CPU time while it is in the Blocked state.
2163 *
2164 * Where as xTaskNotifyWait() will return when a notification is pending,
2165 * ulTaskNotifyTake() will return when the task's notification value is
2166 * not zero.
2167 *
2168 * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2169 *
2170 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2171 * notification value is decremented when the function exits. In this way the
2172 * notification value acts like a counting semaphore. If xClearCountOnExit is
2173 * not pdFALSE then the task's notification value is cleared to zero when the
2174 * function exits. In this way the notification value acts like a binary
2175 * semaphore.
2176 *
2177 * @param xTicksToWait The maximum amount of time that the task should wait in
2178 * the Blocked state for the task's notification value to be greater than zero,
2179 * should the count not already be greater than zero when
2180 * ulTaskNotifyTake() was called. The task will not consume any processing
2181 * time while it is in the Blocked state. This is specified in kernel ticks,
2182 * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
2183 * specified in milliseconds to a time specified in ticks.
2184 *
2185 * @return The task's notification count before it is either cleared to zero or
2186 * decremented (see the xClearCountOnExit parameter).
2187 *
2188 * \defgroup ulTaskNotifyTake ulTaskNotifyTake
2189 * \ingroup TaskNotifications
2190 */
2191uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2192
2193/**
2194 * task. h
2195 * <PRE>BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );</pre>
2196 *
2197 * If the notification state of the task referenced by the handle xTask is
2198 * eNotified, then set the task's notification state to eNotWaitingNotification.
2199 * The task's notification value is not altered. Set xTask to NULL to clear the
2200 * notification state of the calling task.
2201 *
2202 * @return pdTRUE if the task's notification state was set to
2203 * eNotWaitingNotification, otherwise pdFALSE.
2204 * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear
2205 * \ingroup TaskNotifications
2206 */
2207BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
2208
2209/**
2210* task. h
2211* <PRE>uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );</pre>
2212*
2213* Clears the bits specified by the ulBitsToClear bit mask in the notification
2214* value of the task referenced by xTask.
2215*
2216* Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
2217* the notification value to 0. Set ulBitsToClear to 0 to query the task's
2218* notification value without clearing any bits.
2219*
2220* @return The value of the target task's notification value before the bits
2221* specified by ulBitsToClear were cleared.
2222* \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
2223* \ingroup TaskNotifications
2224*/
2225uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
2226
2227/**
2228 * task.h
2229 * <pre>void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )</pre>
2230 *
2231 * Capture the current time for future use with xTaskCheckForTimeOut().
2232 *
2233 * @param pxTimeOut Pointer to a timeout object into which the current time
2234 * is to be captured. The captured time includes the tick count and the number
2235 * of times the tick count has overflowed since the system first booted.
2236 * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
2237 * \ingroup TaskCtrl
2238 */
2239void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2240
2241/**
2242 * task.h
2243 * <pre>BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );</pre>
2244 *
2245 * Determines if pxTicksToWait ticks has passed since a time was captured
2246 * using a call to vTaskSetTimeOutState(). The captured time includes the tick
2247 * count and the number of times the tick count has overflowed.
2248 *
2249 * @param pxTimeOut The time status as captured previously using
2250 * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
2251 * to reflect the current time status.
2252 * @param pxTicksToWait The number of ticks to check for timeout i.e. if
2253 * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
2254 * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
2255 * If the timeout has not occurred, pxTIcksToWait is updated to reflect the
2256 * number of remaining ticks.
2257 *
2258 * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
2259 * returned and pxTicksToWait is updated to reflect the number of remaining
2260 * ticks.
2261 *
2262 * @see https://www.freertos.org/xTaskCheckForTimeOut.html
2263 *
2264 * Example Usage:
2265 * <pre>
2266 // Driver library function used to receive uxWantedBytes from an Rx buffer
2267 // that is filled by a UART interrupt. If there are not enough bytes in the
2268 // Rx buffer then the task enters the Blocked state until it is notified that
2269 // more data has been placed into the buffer. If there is still not enough
2270 // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
2271 // is used to re-calculate the Block time to ensure the total amount of time
2272 // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
2273 // continues until either the buffer contains at least uxWantedBytes bytes,
2274 // or the total amount of time spent in the Blocked state reaches
2275 // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are
2276 // available up to a maximum of uxWantedBytes.
2277
2278 size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
2279 {
2280 size_t uxReceived = 0;
2281 TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
2282 TimeOut_t xTimeOut;
2283
2284 // Initialize xTimeOut. This records the time at which this function
2285 // was entered.
2286 vTaskSetTimeOutState( &xTimeOut );
2287
2288 // Loop until the buffer contains the wanted number of bytes, or a
2289 // timeout occurs.
2290 while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
2291 {
2292 // The buffer didn't contain enough data so this task is going to
2293 // enter the Blocked state. Adjusting xTicksToWait to account for
2294 // any time that has been spent in the Blocked state within this
2295 // function so far to ensure the total amount of time spent in the
2296 // Blocked state does not exceed MAX_TIME_TO_WAIT.
2297 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
2298 {
2299 //Timed out before the wanted number of bytes were available,
2300 // exit the loop.
2301 break;
2302 }
2303
2304 // Wait for a maximum of xTicksToWait ticks to be notified that the
2305 // receive interrupt has placed more data into the buffer.
2306 ulTaskNotifyTake( pdTRUE, xTicksToWait );
2307 }
2308
2309 // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
2310 // The actual number of bytes read (which might be less than
2311 // uxWantedBytes) is returned.
2312 uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
2313 pucBuffer,
2314 uxWantedBytes );
2315
2316 return uxReceived;
2317 }
2318 </pre>
2319 * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
2320 * \ingroup TaskCtrl
2321 */
2322BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2323
2324/*-----------------------------------------------------------
2325 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2326 *----------------------------------------------------------*/
2327
2328/*
2329 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2330 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2331 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2332 *
2333 * Called from the real time kernel tick (either preemptive or cooperative),
2334 * this increments the tick count and checks if any tasks that are blocked
2335 * for a finite period required removing from a blocked list and placing on
2336 * a ready list. If a non-zero value is returned then a context switch is
2337 * required because either:
2338 * + A task was removed from a blocked list because its timeout had expired,
2339 * or
2340 * + Time slicing is in use and there is a task of equal priority to the
2341 * currently running task.
2342 */
2343BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2344
2345/*
2346 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2347 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2348 *
2349 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2350 *
2351 * Removes the calling task from the ready list and places it both
2352 * on the list of tasks waiting for a particular event, and the
2353 * list of delayed tasks. The task will be removed from both lists
2354 * and replaced on the ready list should either the event occur (and
2355 * there be no higher priority tasks waiting on the same event) or
2356 * the delay period expires.
2357 *
2358 * The 'unordered' version replaces the event list item value with the
2359 * xItemValue value, and inserts the list item at the end of the list.
2360 *
2361 * The 'ordered' version uses the existing event list item value (which is the
2362 * owning tasks priority) to insert the list item into the event list is task
2363 * priority order.
2364 *
2365 * @param pxEventList The list containing tasks that are blocked waiting
2366 * for the event to occur.
2367 *
2368 * @param xItemValue The item value to use for the event list item when the
2369 * event list is not ordered by task priority.
2370 *
2371 * @param xTicksToWait The maximum amount of time that the task should wait
2372 * for the event to occur. This is specified in kernel ticks,the constant
2373 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2374 * period.
2375 */
2376void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2377void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2378
2379/*
2380 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2381 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2382 *
2383 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2384 *
2385 * This function performs nearly the same function as vTaskPlaceOnEventList().
2386 * The difference being that this function does not permit tasks to block
2387 * indefinitely, whereas vTaskPlaceOnEventList() does.
2388 *
2389 */
2390void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
2391
2392/*
2393 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
2394 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2395 *
2396 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2397 *
2398 * Removes a task from both the specified event list and the list of blocked
2399 * tasks, and places it on a ready queue.
2400 *
2401 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
2402 * if either an event occurs to unblock a task, or the block timeout period
2403 * expires.
2404 *
2405 * xTaskRemoveFromEventList() is used when the event list is in task priority
2406 * order. It removes the list item from the head of the event list as that will
2407 * have the highest priority owning task of all the tasks on the event list.
2408 * vTaskRemoveFromUnorderedEventList() is used when the event list is not
2409 * ordered and the event list items hold something other than the owning tasks
2410 * priority. In this case the event list item value is updated to the value
2411 * passed in the xItemValue parameter.
2412 *
2413 * @return pdTRUE if the task being removed has a higher priority than the task
2414 * making the call, otherwise pdFALSE.
2415 */
2416BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
2417void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
2418
2419/*
2420 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
2421 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2422 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2423 *
2424 * Sets the pointer to the current TCB to the TCB of the highest priority task
2425 * that is ready to run.
2426 */
2427portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2428
2429/*
2430 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
2431 * THE EVENT BITS MODULE.
2432 */
2433TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2434
2435/*
2436 * Return the handle of the calling task.
2437 */
2438TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2439
2440/*
2441 * Shortcut used by the queue implementation to prevent unnecessary call to
2442 * taskYIELD();
2443 */
2444void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2445
2446/*
2447 * Returns the scheduler state as taskSCHEDULER_RUNNING,
2448 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2449 */
2450BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2451
2452/*
2453 * Raises the priority of the mutex holder to that of the calling task should
2454 * the mutex holder have a priority less than the calling task.
2455 */
2456BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2457
2458/*
2459 * Set the priority of a task back to its proper priority in the case that it
2460 * inherited a higher priority while it was holding a semaphore.
2461 */
2462BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2463
2464/*
2465 * If a higher priority task attempting to obtain a mutex caused a lower
2466 * priority task to inherit the higher priority task's priority - but the higher
2467 * priority task then timed out without obtaining the mutex, then the lower
2468 * priority task will disinherit the priority again - but only down as far as
2469 * the highest priority task that is still waiting for the mutex (if there were
2470 * more than one task waiting for the mutex).
2471 */
2472void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
2473
2474/*
2475 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
2476 */
2477UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2478
2479/*
2480 * Set the uxTaskNumber of the task referenced by the xTask parameter to
2481 * uxHandle.
2482 */
2483void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
2484
2485/*
2486 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2487 * If tickless mode is being used, or a low power mode is implemented, then
2488 * the tick interrupt will not execute during idle periods. When this is the
2489 * case, the tick count value maintained by the scheduler needs to be kept up
2490 * to date with the actual execution time by being skipped forward by a time
2491 * equal to the idle period.
2492 */
2493void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
2494
2495/* Correct the tick count value after the application code has held
2496interrupts disabled for an extended period. xTicksToCatchUp is the number
2497of tick interrupts that have been missed due to interrupts being disabled.
2498Its value is not computed automatically, so must be computed by the
2499application writer.
2500
2501This function is similar to vTaskStepTick(), however, unlike
2502vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
2503time at which a task should be removed from the blocked state. That means
2504tasks may have to be removed from the blocked state as the tick count is
2505moved. */
2506BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
2507
2508/*
2509 * Only available when configUSE_TICKLESS_IDLE is set to 1.
2510 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2511 * specific sleep function to determine if it is ok to proceed with the sleep,
2512 * and if it is ok to proceed, if it is ok to sleep indefinitely.
2513 *
2514 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2515 * called with the scheduler suspended, not from within a critical section. It
2516 * is therefore possible for an interrupt to request a context switch between
2517 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2518 * entered. eTaskConfirmSleepModeStatus() should be called from a short
2519 * critical section between the timer being stopped and the sleep mode being
2520 * entered to ensure it is ok to proceed into the sleep mode.
2521 */
2522eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2523
2524/*
2525 * For internal use only. Increment the mutex held count when a mutex is
2526 * taken and return the handle of the task that has taken the mutex.
2527 */
2528TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
2529
2530/*
2531 * For internal use only. Same as vTaskSetTimeOutState(), but without a critial
2532 * section.
2533 */
2534void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2535
2536
2537#ifdef __cplusplus
2538}
2539#endif
2540#endif /* INC_TASK_H */
2541
2542
2543
Note: See TracBrowser for help on using the repository browser.