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