Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1 | /*
|
Richard Barry | 7818ed5 | 2009-06-21 19:07:47 +0000 | [diff] [blame] | 2 | FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 3 |
|
Richard Barry | 946da76 | 2006-05-28 08:17:56 +0000 | [diff] [blame] | 4 | This file is part of the FreeRTOS.org distribution.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 5 |
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 6 | FreeRTOS.org is free software; you can redistribute it and/or modify it
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 7 | under the terms of the GNU General Public License (version 2) as published
|
| 8 | by the Free Software Foundation and modified by the FreeRTOS exception.
|
Richard Barry | 4bf5521 | 2009-05-30 15:51:41 +0000 | [diff] [blame] | 9 | **NOTE** The exception to the GPL is included to allow you to distribute a
|
| 10 | combined work that includes FreeRTOS.org without being obliged to provide
|
| 11 | the source code for any proprietary components. Alternative commercial
|
| 12 | license and support terms are also available upon request. See the
|
| 13 | licensing section of http://www.FreeRTOS.org for full details.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 14 |
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 15 | FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 18 | more details.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 19 |
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 20 | You should have received a copy of the GNU General Public License along
|
| 21 | with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 22 | Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 23 |
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 24 |
|
| 25 | ***************************************************************************
|
| 26 | * *
|
| 27 | * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
|
Richard Barry | 52ba0e6 | 2009-02-09 20:21:35 +0000 | [diff] [blame] | 28 | * *
|
| 29 | * This is a concise, step by step, 'hands on' guide that describes both *
|
| 30 | * general multitasking concepts and FreeRTOS specifics. It presents and *
|
| 31 | * explains numerous examples that are written using the FreeRTOS API. *
|
| 32 | * Full source code for all the examples is provided in an accompanying *
|
| 33 | * .zip file. *
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 34 | * *
|
| 35 | ***************************************************************************
|
| 36 |
|
| 37 | 1 tab == 4 spaces!
|
Richard Barry | 0a6d59a | 2007-04-01 20:47:49 +0000 | [diff] [blame] | 38 |
|
Richard Barry | 527fb6a | 2008-03-25 21:22:13 +0000 | [diff] [blame] | 39 | Please ensure to read the configuration and relevant port sections of the
|
Richard Barry | c86dcf7 | 2008-02-03 19:45:58 +0000 | [diff] [blame] | 40 | online documentation.
|
| 41 |
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 42 | http://www.FreeRTOS.org - Documentation, latest information, license and
|
Richard Barry | 527fb6a | 2008-03-25 21:22:13 +0000 | [diff] [blame] | 43 | contact details.
|
Richard Barry | c86dcf7 | 2008-02-03 19:45:58 +0000 | [diff] [blame] | 44 |
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 45 | http://www.SafeRTOS.com - A version that is certified for use in safety
|
Richard Barry | 527fb6a | 2008-03-25 21:22:13 +0000 | [diff] [blame] | 46 | critical systems.
|
Richard Barry | c86dcf7 | 2008-02-03 19:45:58 +0000 | [diff] [blame] | 47 |
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 48 | http://www.OpenRTOS.com - Commercial support, development, porting,
|
Richard Barry | 527fb6a | 2008-03-25 21:22:13 +0000 | [diff] [blame] | 49 | licensing and training services.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 50 | */
|
| 51 |
|
Richard Barry | 7a8eb50 | 2007-07-28 16:33:07 +0000 | [diff] [blame] | 52 |
|
Richard Barry | 172114c | 2008-09-01 08:18:50 +0000 | [diff] [blame] | 53 | #ifndef INC_FREERTOS_H
|
| 54 | #error "#include FreeRTOS.h" must appear in source files before "#include task.h"
|
| 55 | #endif
|
| 56 |
|
| 57 |
|
Richard Barry | 7a8eb50 | 2007-07-28 16:33:07 +0000 | [diff] [blame] | 58 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 59 | #ifndef TASK_H
|
| 60 | #define TASK_H
|
| 61 |
|
| 62 | #include "portable.h"
|
| 63 | #include "list.h"
|
| 64 |
|
Richard Barry | 620d399 | 2007-11-05 16:44:39 +0000 | [diff] [blame] | 65 | #ifdef __cplusplus
|
| 66 | extern "C" {
|
| 67 | #endif
|
Richard Barry | 7818ed5 | 2009-06-21 19:07:47 +0000 | [diff] [blame] | 68 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 69 | /*-----------------------------------------------------------
|
| 70 | * MACROS AND DEFINITIONS
|
| 71 | *----------------------------------------------------------*/
|
| 72 |
|
Richard Barry | 7818ed5 | 2009-06-21 19:07:47 +0000 | [diff] [blame] | 73 | #define tskKERNEL_VERSION_NUMBER "V5.3.1"
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 74 |
|
| 75 | /**
|
| 76 | * task. h
|
| 77 | *
|
| 78 | * Type by which tasks are referenced. For example, a call to xTaskCreate
|
| 79 | * returns (via a pointer parameter) an xTaskHandle variable that can then
|
| 80 | * be used as a parameter to vTaskDelete to delete the task.
|
| 81 | *
|
| 82 | * \page xTaskHandle xTaskHandle
|
| 83 | * \ingroup Tasks
|
| 84 | */
|
| 85 | typedef void * xTaskHandle;
|
| 86 |
|
| 87 | /*
|
Richard Barry | b18929e | 2006-08-27 14:09:54 +0000 | [diff] [blame] | 88 | * Used internally only.
|
| 89 | */
|
| 90 | typedef struct xTIME_OUT
|
| 91 | {
|
| 92 | portBASE_TYPE xOverflowCount;
|
| 93 | portTickType xTimeOnEntering;
|
| 94 | } xTimeOutType;
|
| 95 |
|
| 96 | /*
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 97 | * Defines the priority used by the idle task. This must not be modified.
|
| 98 | *
|
| 99 | * \ingroup TaskUtils
|
| 100 | */
|
| 101 | #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0 )
|
| 102 |
|
| 103 | /**
|
| 104 | * task. h
|
| 105 | *
|
| 106 | * Macro for forcing a context switch.
|
| 107 | *
|
| 108 | * \page taskYIELD taskYIELD
|
| 109 | * \ingroup SchedulerControl
|
| 110 | */
|
| 111 | #define taskYIELD() portYIELD()
|
| 112 |
|
| 113 | /**
|
| 114 | * task. h
|
| 115 | *
|
| 116 | * Macro to mark the start of a critical code region. Preemptive context
|
| 117 | * switches cannot occur when in a critical region.
|
| 118 | *
|
| 119 | * NOTE: This may alter the stack (depending on the portable implementation)
|
| 120 | * so must be used with care!
|
| 121 | *
|
| 122 | * \page taskENTER_CRITICAL taskENTER_CRITICAL
|
| 123 | * \ingroup SchedulerControl
|
| 124 | */
|
| 125 | #define taskENTER_CRITICAL() portENTER_CRITICAL()
|
| 126 |
|
| 127 | /**
|
| 128 | * task. h
|
| 129 | *
|
| 130 | * Macro to mark the end of a critical code region. Preemptive context
|
| 131 | * switches cannot occur when in a critical region.
|
| 132 | *
|
| 133 | * NOTE: This may alter the stack (depending on the portable implementation)
|
| 134 | * so must be used with care!
|
| 135 | *
|
| 136 | * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
|
| 137 | * \ingroup SchedulerControl
|
| 138 | */
|
| 139 | #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
|
| 140 |
|
| 141 | /**
|
| 142 | * task. h
|
| 143 | *
|
| 144 | * Macro to disable all maskable interrupts.
|
| 145 | *
|
| 146 | * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
|
| 147 | * \ingroup SchedulerControl
|
| 148 | */
|
| 149 | #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
|
| 150 |
|
| 151 | /**
|
| 152 | * task. h
|
| 153 | *
|
| 154 | * Macro to enable microcontroller interrupts.
|
| 155 | *
|
| 156 | * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
|
| 157 | * \ingroup SchedulerControl
|
| 158 | */
|
| 159 | #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
|
| 160 |
|
Richard Barry | 7a8eb50 | 2007-07-28 16:33:07 +0000 | [diff] [blame] | 161 | /* Definitions returned by xTaskGetSchedulerState(). */
|
| 162 | #define taskSCHEDULER_NOT_STARTED 0
|
| 163 | #define taskSCHEDULER_RUNNING 1
|
| 164 | #define taskSCHEDULER_SUSPENDED 2
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 165 |
|
| 166 | /*-----------------------------------------------------------
|
| 167 | * TASK CREATION API
|
| 168 | *----------------------------------------------------------*/
|
| 169 |
|
| 170 | /**
|
| 171 | * task. h
|
| 172 | *<pre>
|
| 173 | portBASE_TYPE xTaskCreate(
|
| 174 | pdTASK_CODE pvTaskCode,
|
| 175 | const portCHAR * const pcName,
|
| 176 | unsigned portSHORT usStackDepth,
|
| 177 | void *pvParameters,
|
| 178 | unsigned portBASE_TYPE uxPriority,
|
| 179 | xTaskHandle *pvCreatedTask
|
| 180 | );</pre>
|
| 181 | *
|
| 182 | * Create a new task and add it to the list of tasks that are ready to run.
|
| 183 | *
|
| 184 | * @param pvTaskCode Pointer to the task entry function. Tasks
|
| 185 | * must be implemented to never return (i.e. continuous loop).
|
| 186 | *
|
| 187 | * @param pcName A descriptive name for the task. This is mainly used to
|
| 188 | * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
|
| 189 | * is 16.
|
| 190 | *
|
| 191 | * @param usStackDepth The size of the task stack specified as the number of
|
| 192 | * variables the stack can hold - not the number of bytes. For example, if
|
| 193 | * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
|
| 194 | * will be allocated for stack storage.
|
| 195 | *
|
| 196 | * @param pvParameters Pointer that will be used as the parameter for the task
|
| 197 | * being created.
|
| 198 | *
|
| 199 | * @param uxPriority The priority at which the task should run.
|
| 200 | *
|
| 201 | * @param pvCreatedTask Used to pass back a handle by which the created task
|
| 202 | * can be referenced.
|
| 203 | *
|
| 204 | * @return pdPASS if the task was successfully created and added to a ready
|
| 205 | * list, otherwise an error code defined in the file errors. h
|
| 206 | *
|
| 207 | * Example usage:
|
| 208 | <pre>
|
| 209 | // Task to be created.
|
| 210 | void vTaskCode( void * pvParameters )
|
| 211 | {
|
| 212 | for( ;; )
|
| 213 | {
|
| 214 | // Task code goes here.
|
| 215 | }
|
| 216 | }
|
| 217 |
|
| 218 | // Function that creates a task.
|
| 219 | void vOtherFunction( void )
|
| 220 | {
|
Richard Barry | c3a33e5 | 2008-09-22 13:43:07 +0000 | [diff] [blame] | 221 | static unsigned char ucParameterToPass;
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 222 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 223 |
|
Richard Barry | c3a33e5 | 2008-09-22 13:43:07 +0000 | [diff] [blame] | 224 | // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
|
| 225 | // must exist for the lifetime of the task, so in this case is declared static. If it was just an
|
| 226 | // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
|
| 227 | // the new time attempts to access it.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 228 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 229 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 230 | // Use the handle to delete the task.
|
| 231 | vTaskDelete( xHandle );
|
| 232 | }
|
| 233 | </pre>
|
| 234 | * \defgroup xTaskCreate xTaskCreate
|
| 235 | * \ingroup Tasks
|
| 236 | */
|
| 237 | signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );
|
| 238 |
|
| 239 | /**
|
| 240 | * task. h
|
| 241 | * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
|
| 242 | *
|
| 243 | * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
|
| 244 | * See the configuration section for more information.
|
| 245 | *
|
| 246 | * Remove a task from the RTOS real time kernels management. The task being
|
| 247 | * deleted will be removed from all ready, blocked, suspended and event lists.
|
| 248 | *
|
| 249 | * NOTE: The idle task is responsible for freeing the kernel allocated
|
| 250 | * memory from tasks that have been deleted. It is therefore important that
|
| 251 | * the idle task is not starved of microcontroller processing time if your
|
| 252 | * application makes any calls to vTaskDelete (). Memory allocated by the
|
| 253 | * task code is not automatically freed, and should be freed before the task
|
| 254 | * is deleted.
|
| 255 | *
|
| 256 | * See the demo application file death.c for sample code that utilises
|
| 257 | * vTaskDelete ().
|
| 258 | *
|
| 259 | * @param pxTask The handle of the task to be deleted. Passing NULL will
|
| 260 | * cause the calling task to be deleted.
|
| 261 | *
|
| 262 | * Example usage:
|
| 263 | <pre>
|
| 264 | void vOtherFunction( void )
|
| 265 | {
|
| 266 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 267 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 268 | // Create the task, storing the handle.
|
| 269 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 270 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 271 | // Use the handle to delete the task.
|
| 272 | vTaskDelete( xHandle );
|
| 273 | }
|
| 274 | </pre>
|
| 275 | * \defgroup vTaskDelete vTaskDelete
|
| 276 | * \ingroup Tasks
|
| 277 | */
|
| 278 | void vTaskDelete( xTaskHandle pxTask );
|
| 279 |
|
| 280 |
|
| 281 | /*-----------------------------------------------------------
|
| 282 | * TASK CONTROL API
|
| 283 | *----------------------------------------------------------*/
|
| 284 |
|
| 285 | /**
|
| 286 | * task. h
|
| 287 | * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
|
| 288 | *
|
| 289 | * Delay a task for a given number of ticks. The actual time that the
|
| 290 | * task remains blocked depends on the tick rate. The constant
|
| 291 | * portTICK_RATE_MS can be used to calculate real time from the tick
|
| 292 | * rate - with the resolution of one tick period.
|
| 293 | *
|
| 294 | * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
|
| 295 | * See the configuration section for more information.
|
| 296 | *
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 297 | *
|
| 298 | * vTaskDelay() specifies a time at which the task wishes to unblock relative to
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 299 | * the time at which vTaskDelay() is called. For example, specifying a block
|
| 300 | * period of 100 ticks will cause the task to unblock 100 ticks after
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 301 | * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 302 | * of controlling the frequency of a cyclical task as the path taken through the
|
| 303 | * code, as well as other task and interrupt activity, will effect the frequency
|
| 304 | * at which vTaskDelay() gets called and therefore the time at which the task
|
| 305 | * next executes. See vTaskDelayUntil() for an alternative API function designed
|
| 306 | * to facilitate fixed frequency execution. It does this by specifying an
|
| 307 | * absolute time (rather than a relative time) at which the calling task should
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 308 | * unblock.
|
| 309 | *
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 310 | * @param xTicksToDelay The amount of time, in tick periods, that
|
| 311 | * the calling task should block.
|
| 312 | *
|
| 313 | * Example usage:
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 314 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 315 | void vTaskFunction( void * pvParameters )
|
| 316 | {
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 317 | void vTaskFunction( void * pvParameters )
|
| 318 | {
|
| 319 | // Block for 500ms.
|
| 320 | const portTickType xDelay = 500 / portTICK_RATE_MS;
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 321 |
|
| 322 | for( ;; )
|
| 323 | {
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 324 | // Simply toggle the LED every 500ms, blocking between each toggle.
|
| 325 | vToggleLED();
|
| 326 | vTaskDelay( xDelay );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 327 | }
|
| 328 | }
|
Richard Barry | 9006444 | 2008-05-30 15:34:42 +0000 | [diff] [blame] | 329 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 330 | * \defgroup vTaskDelay vTaskDelay
|
| 331 | * \ingroup TaskCtrl
|
| 332 | */
|
| 333 | void vTaskDelay( portTickType xTicksToDelay );
|
| 334 |
|
| 335 | /**
|
| 336 | * task. h
|
| 337 | * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
|
| 338 | *
|
| 339 | * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
|
| 340 | * See the configuration section for more information.
|
| 341 | *
|
| 342 | * Delay a task until a specified time. This function can be used by cyclical
|
| 343 | * tasks to ensure a constant execution frequency.
|
| 344 | *
|
| 345 | * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
|
| 346 | * cause a task to block for the specified number of ticks from the time vTaskDelay () is
|
| 347 | * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
|
| 348 | * execution frequency as the time between a task starting to execute and that task
|
| 349 | * calling vTaskDelay () may not be fixed [the task may take a different path though the
|
| 350 | * code between calls, or may get interrupted or preempted a different number of times
|
| 351 | * each time it executes].
|
| 352 | *
|
| 353 | * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
|
| 354 | * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
|
| 355 | * unblock.
|
| 356 | *
|
| 357 | * The constant portTICK_RATE_MS can be used to calculate real time from the tick
|
| 358 | * rate - with the resolution of one tick period.
|
| 359 | *
|
| 360 | * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
|
| 361 | * task was last unblocked. The variable must be initialised with the current time
|
| 362 | * prior to its first use (see the example below). Following this the variable is
|
| 363 | * automatically updated within vTaskDelayUntil ().
|
| 364 | *
|
| 365 | * @param xTimeIncrement The cycle time period. The task will be unblocked at
|
| 366 | * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
|
| 367 | * same xTimeIncrement parameter value will cause the task to execute with
|
| 368 | * a fixed interface period.
|
| 369 | *
|
| 370 | * Example usage:
|
| 371 | <pre>
|
| 372 | // Perform an action every 10 ticks.
|
| 373 | void vTaskFunction( void * pvParameters )
|
| 374 | {
|
| 375 | portTickType xLastWakeTime;
|
| 376 | const portTickType xFrequency = 10;
|
| 377 |
|
| 378 | // Initialise the xLastWakeTime variable with the current time.
|
| 379 | xLastWakeTime = xTaskGetTickCount ();
|
| 380 | for( ;; )
|
| 381 | {
|
| 382 | // Wait for the next cycle.
|
| 383 | vTaskDelayUntil( &xLastWakeTime, xFrequency );
|
| 384 |
|
| 385 | // Perform action here.
|
| 386 | }
|
| 387 | }
|
| 388 | </pre>
|
| 389 | * \defgroup vTaskDelayUntil vTaskDelayUntil
|
| 390 | * \ingroup TaskCtrl
|
| 391 | */
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 392 | void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 393 |
|
| 394 | /**
|
| 395 | * task. h
|
| 396 | * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
|
| 397 | *
|
| 398 | * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
|
| 399 | * See the configuration section for more information.
|
| 400 | *
|
| 401 | * Obtain the priority of any task.
|
| 402 | *
|
| 403 | * @param pxTask Handle of the task to be queried. Passing a NULL
|
| 404 | * handle results in the priority of the calling task being returned.
|
| 405 | *
|
| 406 | * @return The priority of pxTask.
|
| 407 | *
|
| 408 | * Example usage:
|
| 409 | <pre>
|
| 410 | void vAFunction( void )
|
| 411 | {
|
| 412 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 413 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 414 | // Create a task, storing the handle.
|
| 415 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 416 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 417 | // ...
|
| 418 |
|
| 419 | // Use the handle to obtain the priority of the created task.
|
| 420 | // It was created with tskIDLE_PRIORITY, but may have changed
|
| 421 | // it itself.
|
| 422 | if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
|
| 423 | {
|
| 424 | // The task has changed it's priority.
|
| 425 | }
|
| 426 |
|
| 427 | // ...
|
| 428 |
|
| 429 | // Is our priority higher than the created task?
|
| 430 | if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
|
| 431 | {
|
| 432 | // Our priority (obtained using NULL handle) is higher.
|
| 433 | }
|
| 434 | }
|
| 435 | </pre>
|
| 436 | * \defgroup uxTaskPriorityGet uxTaskPriorityGet
|
| 437 | * \ingroup TaskCtrl
|
| 438 | */
|
| 439 | unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );
|
| 440 |
|
| 441 | /**
|
| 442 | * task. h
|
| 443 | * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
|
| 444 | *
|
| 445 | * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
|
| 446 | * See the configuration section for more information.
|
| 447 | *
|
| 448 | * Set the priority of any task.
|
| 449 | *
|
| 450 | * A context switch will occur before the function returns if the priority
|
| 451 | * being set is higher than the currently executing task.
|
| 452 | *
|
| 453 | * @param pxTask Handle to the task for which the priority is being set.
|
| 454 | * Passing a NULL handle results in the priority of the calling task being set.
|
| 455 | *
|
| 456 | * @param uxNewPriority The priority to which the task will be set.
|
| 457 | *
|
| 458 | * Example usage:
|
| 459 | <pre>
|
| 460 | void vAFunction( void )
|
| 461 | {
|
| 462 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 463 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 464 | // Create a task, storing the handle.
|
| 465 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
|
| 466 |
|
| 467 | // ...
|
| 468 |
|
| 469 | // Use the handle to raise the priority of the created task.
|
| 470 | vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
|
| 471 |
|
| 472 | // ...
|
| 473 |
|
| 474 | // Use a NULL handle to raise our priority to the same value.
|
| 475 | vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
|
| 476 | }
|
| 477 | </pre>
|
| 478 | * \defgroup vTaskPrioritySet vTaskPrioritySet
|
| 479 | * \ingroup TaskCtrl
|
| 480 | */
|
| 481 | void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
|
| 482 |
|
| 483 | /**
|
| 484 | * task. h
|
| 485 | * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
|
| 486 | *
|
| 487 | * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
|
| 488 | * See the configuration section for more information.
|
| 489 | *
|
| 490 | * Suspend any task. When suspended a task will never get any microcontroller
|
| 491 | * processing time, no matter what its priority.
|
| 492 | *
|
| 493 | * Calls to vTaskSuspend are not accumulative -
|
| 494 | * i.e. calling vTaskSuspend () twice on the same task still only requires one
|
| 495 | * call to vTaskResume () to ready the suspended task.
|
| 496 | *
|
| 497 | * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
|
| 498 | * handle will cause the calling task to be suspended.
|
| 499 | *
|
| 500 | * Example usage:
|
| 501 | <pre>
|
| 502 | void vAFunction( void )
|
| 503 | {
|
| 504 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 505 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 506 | // Create a task, storing the handle.
|
| 507 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 508 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 509 | // ...
|
| 510 |
|
| 511 | // Use the handle to suspend the created task.
|
| 512 | vTaskSuspend( xHandle );
|
| 513 |
|
| 514 | // ...
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 515 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 516 | // The created task will not run during this period, unless
|
| 517 | // another task calls vTaskResume( xHandle ).
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 518 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 519 | //...
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 520 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 521 |
|
| 522 | // Suspend ourselves.
|
| 523 | vTaskSuspend( NULL );
|
| 524 |
|
| 525 | // We cannot get here unless another task calls vTaskResume
|
| 526 | // with our handle as the parameter.
|
| 527 | }
|
| 528 | </pre>
|
| 529 | * \defgroup vTaskSuspend vTaskSuspend
|
| 530 | * \ingroup TaskCtrl
|
| 531 | */
|
| 532 | void vTaskSuspend( xTaskHandle pxTaskToSuspend );
|
| 533 |
|
| 534 | /**
|
| 535 | * task. h
|
| 536 | * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
|
| 537 | *
|
| 538 | * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
|
| 539 | * See the configuration section for more information.
|
| 540 | *
|
| 541 | * Resumes a suspended task.
|
| 542 | *
|
| 543 | * A task that has been suspended by one of more calls to vTaskSuspend ()
|
| 544 | * will be made available for running again by a single call to
|
| 545 | * vTaskResume ().
|
| 546 | *
|
| 547 | * @param pxTaskToResume Handle to the task being readied.
|
| 548 | *
|
| 549 | * Example usage:
|
| 550 | <pre>
|
| 551 | void vAFunction( void )
|
| 552 | {
|
| 553 | xTaskHandle xHandle;
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 554 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 555 | // Create a task, storing the handle.
|
| 556 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 557 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 558 | // ...
|
| 559 |
|
| 560 | // Use the handle to suspend the created task.
|
| 561 | vTaskSuspend( xHandle );
|
| 562 |
|
| 563 | // ...
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 564 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 565 | // The created task will not run during this period, unless
|
| 566 | // another task calls vTaskResume( xHandle ).
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 567 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 568 | //...
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 569 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 570 |
|
| 571 | // Resume the suspended task ourselves.
|
| 572 | vTaskResume( xHandle );
|
| 573 |
|
| 574 | // The created task will once again get microcontroller processing
|
| 575 | // time in accordance with it priority within the system.
|
| 576 | }
|
| 577 | </pre>
|
| 578 | * \defgroup vTaskResume vTaskResume
|
| 579 | * \ingroup TaskCtrl
|
| 580 | */
|
| 581 | void vTaskResume( xTaskHandle pxTaskToResume );
|
| 582 |
|
Richard Barry | 58a357e | 2006-08-11 10:02:38 +0000 | [diff] [blame] | 583 | /**
|
| 584 | * task. h
|
| 585 | * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
|
| 586 | *
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 587 | * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
|
Richard Barry | 58a357e | 2006-08-11 10:02:38 +0000 | [diff] [blame] | 588 | * available. See the configuration section for more information.
|
| 589 | *
|
| 590 | * An implementation of vTaskResume() that can be called from within an ISR.
|
| 591 | *
|
| 592 | * A task that has been suspended by one of more calls to vTaskSuspend ()
|
| 593 | * will be made available for running again by a single call to
|
| 594 | * xTaskResumeFromISR ().
|
| 595 | *
|
| 596 | * @param pxTaskToResume Handle to the task being readied.
|
| 597 | *
|
| 598 | * \defgroup vTaskResumeFromISR vTaskResumeFromISR
|
| 599 | * \ingroup TaskCtrl
|
| 600 | */
|
| 601 | portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );
|
| 602 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 603 | /*-----------------------------------------------------------
|
| 604 | * SCHEDULER CONTROL
|
| 605 | *----------------------------------------------------------*/
|
| 606 |
|
| 607 | /**
|
| 608 | * task. h
|
| 609 | * <pre>void vTaskStartScheduler( void );</pre>
|
| 610 | *
|
| 611 | * Starts the real time kernel tick processing. After calling the kernel
|
| 612 | * has control over which tasks are executed and when. This function
|
| 613 | * does not return until an executing task calls vTaskEndScheduler ().
|
| 614 | *
|
| 615 | * At least one task should be created via a call to xTaskCreate ()
|
| 616 | * before calling vTaskStartScheduler (). The idle task is created
|
| 617 | * automatically when the first application task is created.
|
| 618 | *
|
| 619 | * See the demo application file main.c for an example of creating
|
| 620 | * tasks and starting the kernel.
|
| 621 | *
|
| 622 | * Example usage:
|
| 623 | <pre>
|
| 624 | void vAFunction( void )
|
| 625 | {
|
| 626 | // Create at least one task before starting the kernel.
|
| 627 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
| 628 |
|
| 629 | // Start the real time kernel with preemption.
|
| 630 | vTaskStartScheduler ();
|
| 631 |
|
| 632 | // Will not get here unless a task calls vTaskEndScheduler ()
|
| 633 | }
|
| 634 | </pre>
|
| 635 | *
|
| 636 | * \defgroup vTaskStartScheduler vTaskStartScheduler
|
| 637 | * \ingroup SchedulerControl
|
| 638 | */
|
| 639 | void vTaskStartScheduler( void );
|
| 640 |
|
| 641 | /**
|
| 642 | * task. h
|
| 643 | * <pre>void vTaskEndScheduler( void );</pre>
|
| 644 | *
|
| 645 | * Stops the real time kernel tick. All created tasks will be automatically
|
| 646 | * deleted and multitasking (either preemptive or cooperative) will
|
| 647 | * stop. Execution then resumes from the point where vTaskStartScheduler ()
|
| 648 | * was called, as if vTaskStartScheduler () had just returned.
|
| 649 | *
|
| 650 | * See the demo application file main. c in the demo/PC directory for an
|
| 651 | * example that uses vTaskEndScheduler ().
|
| 652 | *
|
| 653 | * vTaskEndScheduler () requires an exit function to be defined within the
|
| 654 | * portable layer (see vPortEndScheduler () in port. c for the PC port). This
|
| 655 | * performs hardware specific operations such as stopping the kernel tick.
|
| 656 | *
|
| 657 | * vTaskEndScheduler () will cause all of the resources allocated by the
|
| 658 | * kernel to be freed - but will not free resources allocated by application
|
| 659 | * tasks.
|
| 660 | *
|
| 661 | * Example usage:
|
| 662 | <pre>
|
| 663 | void vTaskCode( void * pvParameters )
|
| 664 | {
|
| 665 | for( ;; )
|
| 666 | {
|
| 667 | // Task code goes here.
|
| 668 |
|
| 669 | // At some point we want to end the real time kernel processing
|
| 670 | // so call ...
|
| 671 | vTaskEndScheduler ();
|
| 672 | }
|
| 673 | }
|
| 674 |
|
| 675 | void vAFunction( void )
|
| 676 | {
|
| 677 | // Create at least one task before starting the kernel.
|
| 678 | xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
| 679 |
|
| 680 | // Start the real time kernel with preemption.
|
| 681 | vTaskStartScheduler ();
|
| 682 |
|
| 683 | // Will only get here when the vTaskCode () task has called
|
| 684 | // vTaskEndScheduler (). When we get here we are back to single task
|
| 685 | // execution.
|
| 686 | }
|
| 687 | </pre>
|
| 688 | *
|
| 689 | * \defgroup vTaskEndScheduler vTaskEndScheduler
|
| 690 | * \ingroup SchedulerControl
|
| 691 | */
|
| 692 | void vTaskEndScheduler( void );
|
| 693 |
|
| 694 | /**
|
| 695 | * task. h
|
| 696 | * <pre>void vTaskSuspendAll( void );</pre>
|
| 697 | *
|
| 698 | * Suspends all real time kernel activity while keeping interrupts (including the
|
| 699 | * kernel tick) enabled.
|
| 700 | *
|
| 701 | * After calling vTaskSuspendAll () the calling task will continue to execute
|
| 702 | * without risk of being swapped out until a call to xTaskResumeAll () has been
|
| 703 | * made.
|
| 704 | *
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 705 | * API functions that have the potential to cause a context switch (for example,
|
| 706 | * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
|
Richard Barry | a918bd9 | 2008-05-01 15:54:04 +0000 | [diff] [blame] | 707 | * is suspended.
|
| 708 | *
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 709 | * Example usage:
|
| 710 | <pre>
|
| 711 | void vTask1( void * pvParameters )
|
| 712 | {
|
| 713 | for( ;; )
|
| 714 | {
|
| 715 | // Task code goes here.
|
| 716 |
|
| 717 | // ...
|
| 718 |
|
| 719 | // At some point the task wants to perform a long operation during
|
| 720 | // which it does not want to get swapped out. It cannot use
|
| 721 | // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
|
| 722 | // operation may cause interrupts to be missed - including the
|
| 723 | // ticks.
|
| 724 |
|
| 725 | // Prevent the real time kernel swapping out the task.
|
| 726 | vTaskSuspendAll ();
|
| 727 |
|
| 728 | // Perform the operation here. There is no need to use critical
|
| 729 | // sections as we have all the microcontroller processing time.
|
| 730 | // During this time interrupts will still operate and the kernel
|
| 731 | // tick count will be maintained.
|
| 732 |
|
| 733 | // ...
|
| 734 |
|
| 735 | // The operation is complete. Restart the kernel.
|
| 736 | xTaskResumeAll ();
|
| 737 | }
|
| 738 | }
|
| 739 | </pre>
|
| 740 | * \defgroup vTaskSuspendAll vTaskSuspendAll
|
| 741 | * \ingroup SchedulerControl
|
| 742 | */
|
| 743 | void vTaskSuspendAll( void );
|
| 744 |
|
| 745 | /**
|
| 746 | * task. h
|
| 747 | * <pre>portCHAR xTaskResumeAll( void );</pre>
|
| 748 | *
|
| 749 | * Resumes real time kernel activity following a call to vTaskSuspendAll ().
|
| 750 | * After a call to vTaskSuspendAll () the kernel will take control of which
|
| 751 | * task is executing at any time.
|
| 752 | *
|
| 753 | * @return If resuming the scheduler caused a context switch then pdTRUE is
|
| 754 | * returned, otherwise pdFALSE is returned.
|
| 755 | *
|
| 756 | * Example usage:
|
| 757 | <pre>
|
| 758 | void vTask1( void * pvParameters )
|
| 759 | {
|
| 760 | for( ;; )
|
| 761 | {
|
| 762 | // Task code goes here.
|
| 763 |
|
| 764 | // ...
|
| 765 |
|
| 766 | // At some point the task wants to perform a long operation during
|
| 767 | // which it does not want to get swapped out. It cannot use
|
| 768 | // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
|
| 769 | // operation may cause interrupts to be missed - including the
|
| 770 | // ticks.
|
| 771 |
|
| 772 | // Prevent the real time kernel swapping out the task.
|
| 773 | vTaskSuspendAll ();
|
| 774 |
|
| 775 | // Perform the operation here. There is no need to use critical
|
| 776 | // sections as we have all the microcontroller processing time.
|
| 777 | // During this time interrupts will still operate and the real
|
| 778 | // time kernel tick count will be maintained.
|
| 779 |
|
| 780 | // ...
|
| 781 |
|
| 782 | // The operation is complete. Restart the kernel. We want to force
|
| 783 | // a context switch - but there is no point if resuming the scheduler
|
| 784 | // caused a context switch already.
|
| 785 | if( !xTaskResumeAll () )
|
| 786 | {
|
| 787 | taskYIELD ();
|
| 788 | }
|
| 789 | }
|
| 790 | }
|
| 791 | </pre>
|
| 792 | * \defgroup xTaskResumeAll xTaskResumeAll
|
| 793 | * \ingroup SchedulerControl
|
| 794 | */
|
| 795 | signed portBASE_TYPE xTaskResumeAll( void );
|
| 796 |
|
Richard Barry | 4b9fe1e | 2008-05-19 19:15:38 +0000 | [diff] [blame] | 797 | /**
|
| 798 | * task. h
|
| 799 | * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>
|
| 800 | *
|
| 801 | * Utility task that simply returns pdTRUE if the task referenced by xTask is
|
| 802 | * currently in the Suspended state, or pdFALSE if the task referenced by xTask
|
| 803 | * is in any other state.
|
| 804 | *
|
| 805 | */
|
| 806 | signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 807 |
|
| 808 | /*-----------------------------------------------------------
|
| 809 | * TASK UTILITIES
|
| 810 | *----------------------------------------------------------*/
|
| 811 |
|
| 812 | /**
|
| 813 | * task. h
|
| 814 | * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>
|
| 815 | *
|
| 816 | * @return The count of ticks since vTaskStartScheduler was called.
|
| 817 | *
|
| 818 | * \page xTaskGetTickCount xTaskGetTickCount
|
| 819 | * \ingroup TaskUtils
|
| 820 | */
|
| 821 | portTickType xTaskGetTickCount( void );
|
| 822 |
|
| 823 | /**
|
| 824 | * task. h
|
| 825 | * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>
|
| 826 | *
|
| 827 | * @return The number of tasks that the real time kernel is currently managing.
|
| 828 | * This includes all ready, blocked and suspended tasks. A task that
|
| 829 | * has been deleted but not yet freed by the idle task will also be
|
| 830 | * included in the count.
|
| 831 | *
|
| 832 | * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
|
| 833 | * \ingroup TaskUtils
|
| 834 | */
|
| 835 | unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );
|
| 836 |
|
| 837 | /**
|
| 838 | * task. h
|
| 839 | * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>
|
| 840 | *
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 841 | * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
|
Richard Barry | b76158a | 2009-05-19 10:33:12 +0000 | [diff] [blame] | 842 | * available. See the configuration section for more information.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 843 | *
|
| 844 | * NOTE: This function will disable interrupts for its duration. It is
|
| 845 | * not intended for normal application runtime use but as a debug aid.
|
| 846 | *
|
| 847 | * Lists all the current tasks, along with their current state and stack
|
| 848 | * usage high water mark.
|
| 849 | *
|
| 850 | * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
|
| 851 | * suspended ('S').
|
| 852 | *
|
| 853 | * @param pcWriteBuffer A buffer into which the above mentioned details
|
| 854 | * will be written, in ascii form. This buffer is assumed to be large
|
| 855 | * enough to contain the generated report. Approximately 40 bytes per
|
| 856 | * task should be sufficient.
|
| 857 | *
|
| 858 | * \page vTaskList vTaskList
|
| 859 | * \ingroup TaskUtils
|
| 860 | */
|
| 861 | void vTaskList( signed portCHAR *pcWriteBuffer );
|
| 862 |
|
| 863 | /**
|
| 864 | * task. h
|
Richard Barry | b76158a | 2009-05-19 10:33:12 +0000 | [diff] [blame] | 865 | * <PRE>void vTaskGetRunTimeStats( portCHAR *pcWriteBuffer );</PRE>
|
| 866 | *
|
| 867 | * configGENERATE_RUN_TIME_STATS must be defined as 1 for this function
|
| 868 | * to be available. The application must also then provide definitions
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 869 | * for portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
|
Richard Barry | b76158a | 2009-05-19 10:33:12 +0000 | [diff] [blame] | 870 | * portGET_RUN_TIME_COUNTER_VALUE to configure a peripheral timer/counter
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 871 | * and return the timers current count value respectively. The counter
|
| 872 | * should be at least 10 times the frequency of the tick count.
|
Richard Barry | b76158a | 2009-05-19 10:33:12 +0000 | [diff] [blame] | 873 | *
|
| 874 | * NOTE: This function will disable interrupts for its duration. It is
|
| 875 | * not intended for normal application runtime use but as a debug aid.
|
| 876 | *
|
| 877 | * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
|
| 878 | * accumulated execution time being stored for each task. The resolution
|
| 879 | * of the accumulated time value depends on the frequency of the timer
|
| 880 | * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
|
| 881 | * Calling vTaskGetRunTimeStats() writes the total execution time of each
|
| 882 | * task into a buffer, both as an absolute count value and as a percentage
|
| 883 | * of the total system execution time.
|
| 884 | *
|
Richard Barry | 8243645 | 2009-05-21 12:20:31 +0000 | [diff] [blame] | 885 | * @param pcWriteBuffer A buffer into which the execution times will be
|
| 886 | * written, in ascii form. This buffer is assumed to be large enough to
|
| 887 | * contain the generated report. Approximately 40 bytes per task should
|
Richard Barry | b76158a | 2009-05-19 10:33:12 +0000 | [diff] [blame] | 888 | * be sufficient.
|
| 889 | *
|
| 890 | * \page vTaskGetRunTimeStats vTaskGetRunTimeStats
|
| 891 | * \ingroup TaskUtils
|
| 892 | */
|
| 893 | void vTaskGetRunTimeStats( signed portCHAR *pcWriteBuffer );
|
| 894 |
|
| 895 | /**
|
| 896 | * task. h
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 897 | * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>
|
| 898 | *
|
| 899 | * Starts a real time kernel activity trace. The trace logs the identity of
|
| 900 | * which task is running when.
|
| 901 | *
|
| 902 | * The trace file is stored in binary format. A separate DOS utility called
|
| 903 | * convtrce.exe is used to convert this into a tab delimited text file which
|
| 904 | * can be viewed and plotted in a spread sheet.
|
| 905 | *
|
| 906 | * @param pcBuffer The buffer into which the trace will be written.
|
| 907 | *
|
| 908 | * @param ulBufferSize The size of pcBuffer in bytes. The trace will continue
|
| 909 | * until either the buffer in full, or ulTaskEndTrace () is called.
|
| 910 | *
|
| 911 | * \page vTaskStartTrace vTaskStartTrace
|
| 912 | * \ingroup TaskUtils
|
| 913 | */
|
| 914 | void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );
|
| 915 |
|
| 916 | /**
|
| 917 | * task. h
|
| 918 | * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>
|
| 919 | *
|
| 920 | * Stops a kernel activity trace. See vTaskStartTrace ().
|
| 921 | *
|
| 922 | * @return The number of bytes that have been written into the trace buffer.
|
| 923 | *
|
| 924 | * \page usTaskEndTrace usTaskEndTrace
|
| 925 | * \ingroup TaskUtils
|
| 926 | */
|
| 927 | unsigned portLONG ulTaskEndTrace( void );
|
| 928 |
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 929 | /**
|
| 930 | * task.h
|
Richard Barry | 8e85617 | 2008-03-05 10:13:18 +0000 | [diff] [blame] | 931 | * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 932 | *
|
Richard Barry | 39f6b0b | 2008-03-03 20:56:55 +0000 | [diff] [blame] | 933 | * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 934 | * this function to be available.
|
| 935 | *
|
Richard Barry | 8e85617 | 2008-03-05 10:13:18 +0000 | [diff] [blame] | 936 | * Returns the high water mark of the stack associated with xTask. That is,
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 937 | * the minimum free stack space there has been (in bytes) since the task
|
Richard Barry | 8e85617 | 2008-03-05 10:13:18 +0000 | [diff] [blame] | 938 | * started. The smaller the returned number the closer the task has come
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 939 | * to overflowing its stack.
|
Richard Barry | 8e85617 | 2008-03-05 10:13:18 +0000 | [diff] [blame] | 940 | *
|
| 941 | * @param xTask Handle of the task associated with the stack to be checked.
|
| 942 | * Set xTask to NULL to check the stack of the calling task.
|
| 943 | *
|
| 944 | * @return The smallest amount of free stack space there has been (in bytes)
|
| 945 | * since the task referenced by xTask was created.
|
Richard Barry | 71ef315 | 2008-03-03 16:32:37 +0000 | [diff] [blame] | 946 | */
|
Richard Barry | 8e85617 | 2008-03-05 10:13:18 +0000 | [diff] [blame] | 947 | unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 948 |
|
Richard Barry | a9ed428 | 2008-04-12 09:48:40 +0000 | [diff] [blame] | 949 | /**
|
| 950 | * task.h
|
Richard Barry | e939542 | 2008-04-16 07:47:02 +0000 | [diff] [blame] | 951 | * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
|
Richard Barry | a9ed428 | 2008-04-12 09:48:40 +0000 | [diff] [blame] | 952 | *
|
| 953 | * Sets pxHookFunction to be the task hook function used by the task xTask.
|
| 954 | * Passing xTask as NULL has the effect of setting the calling tasks hook
|
| 955 | * function.
|
| 956 | */
|
Richard Barry | e939542 | 2008-04-16 07:47:02 +0000 | [diff] [blame] | 957 | void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );
|
Richard Barry | a9ed428 | 2008-04-12 09:48:40 +0000 | [diff] [blame] | 958 |
|
| 959 | /**
|
| 960 | * task.h
|
Richard Barry | 1ead7d1 | 2009-05-30 13:27:54 +0000 | [diff] [blame] | 961 | * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre>
|
| 962 | *
|
| 963 | * Returns the pxHookFunction value assigned to the task xTask.
|
| 964 | */
|
| 965 | pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask );
|
| 966 |
|
| 967 | /**
|
| 968 | * task.h
|
Richard Barry | a9ed428 | 2008-04-12 09:48:40 +0000 | [diff] [blame] | 969 | * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
|
| 970 | *
|
| 971 | * Calls the hook function associated with xTask. Passing xTask as NULL has
|
| 972 | * the effect of calling the Running tasks (the calling task) hook function.
|
| 973 | *
|
| 974 | * pvParameter is passed to the hook function for the task to interpret as it
|
| 975 | * wants.
|
| 976 | */
|
| 977 | portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );
|
| 978 |
|
| 979 |
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 980 | /*-----------------------------------------------------------
|
| 981 | * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
|
| 982 | *----------------------------------------------------------*/
|
| 983 |
|
| 984 | /*
|
| 985 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
|
| 986 | * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
|
| 987 | * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
|
| 988 | *
|
| 989 | * Called from the real time kernel tick (either preemptive or cooperative),
|
| 990 | * this increments the tick count and checks if any tasks that are blocked
|
| 991 | * for a finite period required removing from a blocked list and placing on
|
| 992 | * a ready list.
|
| 993 | */
|
Richard Barry | 9c87f92 | 2008-05-01 08:58:48 +0000 | [diff] [blame] | 994 | void vTaskIncrementTick( void );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 995 |
|
| 996 | /*
|
| 997 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
|
| 998 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
|
| 999 | *
|
| 1000 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
|
| 1001 | *
|
| 1002 | * Removes the calling task from the ready list and places it both
|
| 1003 | * on the list of tasks waiting for a particular event, and the
|
| 1004 | * list of delayed tasks. The task will be removed from both lists
|
| 1005 | * and replaced on the ready list should either the event occur (and
|
| 1006 | * there be no higher priority tasks waiting on the same event) or
|
| 1007 | * the delay period expires.
|
| 1008 | *
|
| 1009 | * @param pxEventList The list containing tasks that are blocked waiting
|
| 1010 | * for the event to occur.
|
| 1011 | *
|
| 1012 | * @param xTicksToWait The maximum amount of time that the task should wait
|
| 1013 | * for the event to occur. This is specified in kernel ticks,the constant
|
| 1014 | * portTICK_RATE_MS can be used to convert kernel ticks into a real time
|
| 1015 | * period.
|
| 1016 | */
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 1017 | void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1018 |
|
| 1019 | /*
|
| 1020 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
|
| 1021 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
|
| 1022 | *
|
| 1023 | * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
|
| 1024 | *
|
| 1025 | * Removes a task from both the specified event list and the list of blocked
|
| 1026 | * tasks, and places it on a ready queue.
|
| 1027 | *
|
| 1028 | * xTaskRemoveFromEventList () will be called if either an event occurs to
|
| 1029 | * unblock a task, or the block timeout period expires.
|
| 1030 | *
|
| 1031 | * @return pdTRUE if the task being removed has a higher priority than the task
|
| 1032 | * making the call, otherwise pdFALSE.
|
| 1033 | */
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 1034 | signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1035 |
|
| 1036 | /*
|
| 1037 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
|
| 1038 | * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
|
| 1039 | *
|
| 1040 | * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1
|
| 1041 | * for this function to be available.
|
| 1042 | * See the configuration section for more information.
|
| 1043 | *
|
| 1044 | * Empties the ready and delayed queues of task control blocks, freeing the
|
| 1045 | * memory allocated for the task control block and task stacks as it goes.
|
| 1046 | */
|
| 1047 | void vTaskCleanUpResources( void );
|
| 1048 |
|
| 1049 | /*
|
| 1050 | * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
|
| 1051 | * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
|
| 1052 | * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
|
| 1053 | *
|
| 1054 | * Sets the pointer to the current TCB to the TCB of the highest priority task
|
| 1055 | * that is ready to run.
|
| 1056 | */
|
Richard Barry | 9c87f92 | 2008-05-01 08:58:48 +0000 | [diff] [blame] | 1057 | void vTaskSwitchContext( void );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1058 |
|
| 1059 | /*
|
| 1060 | * Return the handle of the calling task.
|
| 1061 | */
|
| 1062 | xTaskHandle xTaskGetCurrentTaskHandle( void );
|
| 1063 |
|
Richard Barry | b18929e | 2006-08-27 14:09:54 +0000 | [diff] [blame] | 1064 | /*
|
| 1065 | * Capture the current time status for future reference.
|
| 1066 | */
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 1067 | void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );
|
Richard Barry | b18929e | 2006-08-27 14:09:54 +0000 | [diff] [blame] | 1068 |
|
| 1069 | /*
|
| 1070 | * Compare the time status now with that previously captured to see if the
|
| 1071 | * timeout has expired.
|
| 1072 | */
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 1073 | portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );
|
Richard Barry | b18929e | 2006-08-27 14:09:54 +0000 | [diff] [blame] | 1074 |
|
| 1075 | /*
|
| 1076 | * Shortcut used by the queue implementation to prevent unnecessary call to
|
| 1077 | * taskYIELD();
|
| 1078 | */
|
| 1079 | void vTaskMissedYield( void );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1080 |
|
Richard Barry | 7a8eb50 | 2007-07-28 16:33:07 +0000 | [diff] [blame] | 1081 | /*
|
| 1082 | * Returns the scheduler state as taskSCHEDULER_RUNNING,
|
| 1083 | * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
|
| 1084 | */
|
| 1085 | portBASE_TYPE xTaskGetSchedulerState( void );
|
| 1086 |
|
Richard Barry | 60338bd | 2007-08-21 16:54:48 +0000 | [diff] [blame] | 1087 | /*
|
| 1088 | * Raises the priority of the mutex holder to that of the calling task should
|
| 1089 | * the mutex holder have a priority less than the calling task.
|
| 1090 | */
|
| 1091 | void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );
|
| 1092 |
|
| 1093 | /*
|
| 1094 | * Set the priority of a task back to its proper priority in the case that it
|
| 1095 | * inherited a higher priority while it was holding a semaphore.
|
| 1096 | */
|
| 1097 | void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );
|
| 1098 |
|
Richard Barry | 620d399 | 2007-11-05 16:44:39 +0000 | [diff] [blame] | 1099 | #ifdef __cplusplus
|
| 1100 | }
|
| 1101 | #endif
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1102 | #endif /* TASK_H */
|
| 1103 |
|
| 1104 |
|
| 1105 |
|