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