Dependents:   frtos_v_8_bluetooth frtos_v_8_pololu frtos_v_8_Final

Committer:
JoaoJardim
Date:
Mon Dec 10 10:04:09 2018 +0000
Revision:
1:2f4de0d9dc8b
Parent:
0:91ad48ad5687
Same implementation as freertos_bluetooth at this time, but with FreeRTOS v_8.2.1

Who changed what in which revision?

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