task.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef INC_TASK_H
  29. #define INC_TASK_H
  30. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h must appear in source files before include task.h"
  32. #endif
  33. /* *INDENT-OFF* */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* *INDENT-ON* */
  38. /*-----------------------------------------------------------
  39. * MACROS AND DEFINITIONS
  40. *----------------------------------------------------------*/
  41. /*
  42. * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development
  43. * after the numbered release.
  44. *
  45. * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD
  46. * values will reflect the last released version number.
  47. */
  48. #define tskKERNEL_VERSION_NUMBER "V10.4.6"
  49. #define tskKERNEL_VERSION_MAJOR 10
  50. #define tskKERNEL_VERSION_MINOR 4
  51. #define tskKERNEL_VERSION_BUILD 6
  52. /* The direct to task notification feature used to have only a single notification
  53. * per task. Now there is an array of notifications per task that is dimensioned by
  54. * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
  55. * original direct to task notification defaults to using the first index in the
  56. * array. */
  57. #define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
  58. /**
  59. * task. h
  60. *
  61. * Type by which tasks are referenced. For example, a call to xTaskCreate
  62. * returns (via a pointer parameter) an TaskHandle_t variable that can then
  63. * be used as a parameter to vTaskDelete to delete the task.
  64. *
  65. * \defgroup TaskHandle_t TaskHandle_t
  66. * \ingroup Tasks
  67. */
  68. struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  69. typedef struct tskTaskControlBlock * TaskHandle_t;
  70. /*
  71. * Defines the prototype to which the application task hook function must
  72. * conform.
  73. */
  74. typedef BaseType_t (* TaskHookFunction_t)( void * );
  75. /* Actions that can be performed when vTaskNotify() is called. */
  76. typedef enum
  77. {
  78. eNoAction = 0, /* Notify the task without updating its notify value. */
  79. eSetBits, /* Set bits in the task's notification value. */
  80. eIncrement, /* Increment the task's notification value. */
  81. eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
  82. eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
  83. } eNotifyAction;
  84. /* Task states returned by eTaskGetState. */
  85. typedef enum
  86. {
  87. eRunning = 0, /* A task is querying the state of itself, so must be running. */
  88. eReady, /* The task being queried is in a ready or pending ready list. */
  89. eBlocked, /* The task being queried is in the Blocked state. */
  90. eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  91. eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
  92. eInvalid /* Used as an 'invalid state' value. */
  93. } eTaskState;
  94. /**
  95. * task. h
  96. *
  97. * Macro for forcing a context switch.
  98. *
  99. * \defgroup taskYIELD taskYIELD
  100. * \ingroup SchedulerControl
  101. */
  102. #define taskYIELD() portYIELD()
  103. /**
  104. * task. h
  105. *
  106. * Macro to mark the start of a critical code region. Preemptive context
  107. * switches cannot occur when in a critical region.
  108. *
  109. * NOTE: This may alter the stack (depending on the portable implementation)
  110. * so must be used with care!
  111. *
  112. * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  113. * \ingroup SchedulerControl
  114. */
  115. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  116. #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  117. /**
  118. * task. h
  119. *
  120. * Macro to mark the end of a critical code region. Preemptive context
  121. * switches cannot occur when in a critical region.
  122. *
  123. * NOTE: This may alter the stack (depending on the portable implementation)
  124. * so must be used with care!
  125. *
  126. * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  127. * \ingroup SchedulerControl
  128. */
  129. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  130. #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  131. /**
  132. * task. h
  133. *
  134. * Macro to disable all maskable interrupts.
  135. *
  136. * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  137. * \ingroup SchedulerControl
  138. */
  139. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  140. /**
  141. * task. h
  142. *
  143. * Macro to enable microcontroller interrupts.
  144. *
  145. * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  146. * \ingroup SchedulerControl
  147. */
  148. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  149. /*-----------------------------------------------------------
  150. * TASK CREATION API
  151. *----------------------------------------------------------*/
  152. /**
  153. * task. h
  154. * @code{c}
  155. * BaseType_t xTaskCreate(
  156. * TaskFunction_t pxTaskCode,
  157. * const char *pcName,
  158. * configSTACK_DEPTH_TYPE usStackDepth,
  159. * void *pvParameters,
  160. * UBaseType_t uxPriority,
  161. * TaskHandle_t *pxCreatedTask
  162. * );
  163. * @endcode
  164. *
  165. * Create a new task and add it to the list of tasks that are ready to run.
  166. *
  167. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  168. * memory. The first block is used to hold the task's data structures. The
  169. * second block is used by the task as its stack. If a task is created using
  170. * xTaskCreate() then both blocks of memory are automatically dynamically
  171. * allocated inside the xTaskCreate() function. (see
  172. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  173. * xTaskCreateStatic() then the application writer must provide the required
  174. * memory. xTaskCreateStatic() therefore allows a task to be created without
  175. * using any dynamic memory allocation.
  176. *
  177. * See xTaskCreateStatic() for a version that does not use any dynamic memory
  178. * allocation.
  179. *
  180. * xTaskCreate() can only be used to create a task that has unrestricted
  181. * access to the entire microcontroller memory map. Systems that include MPU
  182. * support can alternatively create an MPU constrained task using
  183. * xTaskCreateRestricted().
  184. *
  185. * @param pxTaskCode Pointer to the task entry function. Tasks
  186. * must be implemented to never return (i.e. continuous loop).
  187. *
  188. * @param pcName A descriptive name for the task. This is mainly used to
  189. * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
  190. * is 16.
  191. *
  192. * @param usStackDepth The size of the task stack specified as the number of
  193. * variables the stack can hold - not the number of bytes. For example, if
  194. * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  195. * will be allocated for stack storage.
  196. *
  197. * @param pvParameters Pointer that will be used as the parameter for the task
  198. * being created.
  199. *
  200. * @param uxPriority The priority at which the task should run. Systems that
  201. * include MPU support can optionally create tasks in a privileged (system)
  202. * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  203. * example, to create a privileged task at priority 2 the uxPriority parameter
  204. * should be set to ( 2 | portPRIVILEGE_BIT ).
  205. *
  206. * @param pxCreatedTask Used to pass back a handle by which the created task
  207. * can be referenced.
  208. *
  209. * @return pdPASS if the task was successfully created and added to a ready
  210. * list, otherwise an error code defined in the file projdefs.h
  211. *
  212. * Example usage:
  213. * @code{c}
  214. * // Task to be created.
  215. * void vTaskCode( void * pvParameters )
  216. * {
  217. * for( ;; )
  218. * {
  219. * // Task code goes here.
  220. * }
  221. * }
  222. *
  223. * // Function that creates a task.
  224. * void vOtherFunction( void )
  225. * {
  226. * static uint8_t ucParameterToPass;
  227. * TaskHandle_t xHandle = NULL;
  228. *
  229. * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  230. * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  231. * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  232. * // the new task attempts to access it.
  233. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  234. * configASSERT( xHandle );
  235. *
  236. * // Use the handle to delete the task.
  237. * if( xHandle != NULL )
  238. * {
  239. * vTaskDelete( xHandle );
  240. * }
  241. * }
  242. * @endcode
  243. * \defgroup xTaskCreate xTaskCreate
  244. * \ingroup Tasks
  245. */
  246. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  247. BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  248. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  249. const configSTACK_DEPTH_TYPE usStackDepth,
  250. void * const pvParameters,
  251. UBaseType_t uxPriority,
  252. TaskHandle_t * const pxCreatedTask );
  253. #endif
  254. /**
  255. * task. h
  256. * @code{c}
  257. * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  258. * const char *pcName,
  259. * uint32_t ulStackDepth,
  260. * void *pvParameters,
  261. * UBaseType_t uxPriority,
  262. * StackType_t *puxStackBuffer,
  263. * StaticTask_t *pxTaskBuffer );
  264. * @endcode
  265. *
  266. * Create a new task and add it to the list of tasks that are ready to run.
  267. *
  268. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  269. * memory. The first block is used to hold the task's data structures. The
  270. * second block is used by the task as its stack. If a task is created using
  271. * xTaskCreate() then both blocks of memory are automatically dynamically
  272. * allocated inside the xTaskCreate() function. (see
  273. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  274. * xTaskCreateStatic() then the application writer must provide the required
  275. * memory. xTaskCreateStatic() therefore allows a task to be created without
  276. * using any dynamic memory allocation.
  277. *
  278. * @param pxTaskCode Pointer to the task entry function. Tasks
  279. * must be implemented to never return (i.e. continuous loop).
  280. *
  281. * @param pcName A descriptive name for the task. This is mainly used to
  282. * facilitate debugging. The maximum length of the string is defined by
  283. * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  284. *
  285. * @param ulStackDepth The size of the task stack specified as the number of
  286. * variables the stack can hold - not the number of bytes. For example, if
  287. * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
  288. * will be allocated for stack storage.
  289. *
  290. * @param pvParameters Pointer that will be used as the parameter for the task
  291. * being created.
  292. *
  293. * @param uxPriority The priority at which the task will run.
  294. *
  295. * @param puxStackBuffer Must point to a StackType_t array that has at least
  296. * ulStackDepth indexes - the array will then be used as the task's stack,
  297. * removing the need for the stack to be allocated dynamically.
  298. *
  299. * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
  300. * then be used to hold the task's data structures, removing the need for the
  301. * memory to be allocated dynamically.
  302. *
  303. * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
  304. * will be created and a handle to the created task is returned. If either
  305. * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
  306. * NULL is returned.
  307. *
  308. * Example usage:
  309. * @code{c}
  310. *
  311. * // Dimensions of the buffer that the task being created will use as its stack.
  312. * // NOTE: This is the number of words the stack will hold, not the number of
  313. * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
  314. * // then 400 bytes (100 * 32-bits) will be allocated.
  315. #define STACK_SIZE 200
  316. *
  317. * // Structure that will hold the TCB of the task being created.
  318. * StaticTask_t xTaskBuffer;
  319. *
  320. * // Buffer that the task being created will use as its stack. Note this is
  321. * // an array of StackType_t variables. The size of StackType_t is dependent on
  322. * // the RTOS port.
  323. * StackType_t xStack[ STACK_SIZE ];
  324. *
  325. * // Function that implements the task being created.
  326. * void vTaskCode( void * pvParameters )
  327. * {
  328. * // The parameter value is expected to be 1 as 1 is passed in the
  329. * // pvParameters value in the call to xTaskCreateStatic().
  330. * configASSERT( ( uint32_t ) pvParameters == 1UL );
  331. *
  332. * for( ;; )
  333. * {
  334. * // Task code goes here.
  335. * }
  336. * }
  337. *
  338. * // Function that creates a task.
  339. * void vOtherFunction( void )
  340. * {
  341. * TaskHandle_t xHandle = NULL;
  342. *
  343. * // Create the task without using any dynamic memory allocation.
  344. * xHandle = xTaskCreateStatic(
  345. * vTaskCode, // Function that implements the task.
  346. * "NAME", // Text name for the task.
  347. * STACK_SIZE, // Stack size in words, not bytes.
  348. * ( void * ) 1, // Parameter passed into the task.
  349. * tskIDLE_PRIORITY,// Priority at which the task is created.
  350. * xStack, // Array to use as the task's stack.
  351. * &xTaskBuffer ); // Variable to hold the task's data structure.
  352. *
  353. * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
  354. * // been created, and xHandle will be the task's handle. Use the handle
  355. * // to suspend the task.
  356. * vTaskSuspend( xHandle );
  357. * }
  358. * @endcode
  359. * \defgroup xTaskCreateStatic xTaskCreateStatic
  360. * \ingroup Tasks
  361. */
  362. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  363. TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  364. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  365. const uint32_t ulStackDepth,
  366. void * const pvParameters,
  367. UBaseType_t uxPriority,
  368. StackType_t * const puxStackBuffer,
  369. StaticTask_t * const pxTaskBuffer );
  370. #endif /* configSUPPORT_STATIC_ALLOCATION */
  371. /**
  372. * task. h
  373. * @code{c}
  374. * void vTaskDelete( TaskHandle_t xTaskToDelete );
  375. * @endcode
  376. *
  377. * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  378. * See the configuration section for more information.
  379. *
  380. * Remove a task from the RTOS real time kernel's management. The task being
  381. * deleted will be removed from all ready, blocked, suspended and event lists.
  382. *
  383. * NOTE: The idle task is responsible for freeing the kernel allocated
  384. * memory from tasks that have been deleted. It is therefore important that
  385. * the idle task is not starved of microcontroller processing time if your
  386. * application makes any calls to vTaskDelete (). Memory allocated by the
  387. * task code is not automatically freed, and should be freed before the task
  388. * is deleted.
  389. *
  390. * See the demo application file death.c for sample code that utilises
  391. * vTaskDelete ().
  392. *
  393. * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
  394. * cause the calling task to be deleted.
  395. *
  396. * Example usage:
  397. * @code{c}
  398. * void vOtherFunction( void )
  399. * {
  400. * TaskHandle_t xHandle;
  401. *
  402. * // Create the task, storing the handle.
  403. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  404. *
  405. * // Use the handle to delete the task.
  406. * vTaskDelete( xHandle );
  407. * }
  408. * @endcode
  409. * \defgroup vTaskDelete vTaskDelete
  410. * \ingroup Tasks
  411. */
  412. void vTaskDelete( TaskHandle_t xTaskToDelete );
  413. /*-----------------------------------------------------------
  414. * TASK CONTROL API
  415. *----------------------------------------------------------*/
  416. /**
  417. * task. h
  418. * @code{c}
  419. * void vTaskDelay( const TickType_t xTicksToDelay );
  420. * @endcode
  421. *
  422. * Delay a task for a given number of ticks. The actual time that the
  423. * task remains blocked depends on the tick rate. The constant
  424. * portTICK_PERIOD_MS can be used to calculate real time from the tick
  425. * rate - with the resolution of one tick period.
  426. *
  427. * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  428. * See the configuration section for more information.
  429. *
  430. *
  431. * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  432. * the time at which vTaskDelay() is called. For example, specifying a block
  433. * period of 100 ticks will cause the task to unblock 100 ticks after
  434. * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  435. * of controlling the frequency of a periodic task as the path taken through the
  436. * code, as well as other task and interrupt activity, will affect the frequency
  437. * at which vTaskDelay() gets called and therefore the time at which the task
  438. * next executes. See xTaskDelayUntil() for an alternative API function designed
  439. * to facilitate fixed frequency execution. It does this by specifying an
  440. * absolute time (rather than a relative time) at which the calling task should
  441. * unblock.
  442. *
  443. * @param xTicksToDelay The amount of time, in tick periods, that
  444. * the calling task should block.
  445. *
  446. * Example usage:
  447. *
  448. * void vTaskFunction( void * pvParameters )
  449. * {
  450. * // Block for 500ms.
  451. * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
  452. *
  453. * for( ;; )
  454. * {
  455. * // Simply toggle the LED every 500ms, blocking between each toggle.
  456. * vToggleLED();
  457. * vTaskDelay( xDelay );
  458. * }
  459. * }
  460. *
  461. * \defgroup vTaskDelay vTaskDelay
  462. * \ingroup TaskCtrl
  463. */
  464. void vTaskDelay( const TickType_t xTicksToDelay );
  465. /**
  466. * task. h
  467. * @code{c}
  468. * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  469. * @endcode
  470. *
  471. * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
  472. * See the configuration section for more information.
  473. *
  474. * Delay a task until a specified time. This function can be used by periodic
  475. * tasks to ensure a constant execution frequency.
  476. *
  477. * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  478. * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  479. * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  480. * execution frequency as the time between a task starting to execute and that task
  481. * calling vTaskDelay () may not be fixed [the task may take a different path though the
  482. * code between calls, or may get interrupted or preempted a different number of times
  483. * each time it executes].
  484. *
  485. * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  486. * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  487. * unblock.
  488. *
  489. * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
  490. * time specified in milliseconds with a resolution of one tick period.
  491. *
  492. * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  493. * task was last unblocked. The variable must be initialised with the current time
  494. * prior to its first use (see the example below). Following this the variable is
  495. * automatically updated within xTaskDelayUntil ().
  496. *
  497. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  498. * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
  499. * same xTimeIncrement parameter value will cause the task to execute with
  500. * a fixed interface period.
  501. *
  502. * @return Value which can be used to check whether the task was actually delayed.
  503. * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
  504. * be delayed if the next expected wake time is in the past.
  505. *
  506. * Example usage:
  507. * @code{c}
  508. * // Perform an action every 10 ticks.
  509. * void vTaskFunction( void * pvParameters )
  510. * {
  511. * TickType_t xLastWakeTime;
  512. * const TickType_t xFrequency = 10;
  513. * BaseType_t xWasDelayed;
  514. *
  515. * // Initialise the xLastWakeTime variable with the current time.
  516. * xLastWakeTime = xTaskGetTickCount ();
  517. * for( ;; )
  518. * {
  519. * // Wait for the next cycle.
  520. * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  521. *
  522. * // Perform action here. xWasDelayed value can be used to determine
  523. * // whether a deadline was missed if the code here took too long.
  524. * }
  525. * }
  526. * @endcode
  527. * \defgroup xTaskDelayUntil xTaskDelayUntil
  528. * \ingroup TaskCtrl
  529. */
  530. BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  531. const TickType_t xTimeIncrement );
  532. /*
  533. * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
  534. * return a value.
  535. */
  536. #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
  537. { \
  538. ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
  539. }
  540. /**
  541. * task. h
  542. * @code{c}
  543. * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  544. * @endcode
  545. *
  546. * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  547. * function to be available.
  548. *
  549. * A task will enter the Blocked state when it is waiting for an event. The
  550. * event it is waiting for can be a temporal event (waiting for a time), such
  551. * as when vTaskDelay() is called, or an event on an object, such as when
  552. * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  553. * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  554. * task will leave the Blocked state, and return from whichever function call
  555. * placed the task into the Blocked state.
  556. *
  557. * There is no 'FromISR' version of this function as an interrupt would need to
  558. * know which object a task was blocked on in order to know which actions to
  559. * take. For example, if the task was blocked on a queue the interrupt handler
  560. * would then need to know if the queue was locked.
  561. *
  562. * @param xTask The handle of the task to remove from the Blocked state.
  563. *
  564. * @return If the task referenced by xTask was not in the Blocked state then
  565. * pdFAIL is returned. Otherwise pdPASS is returned.
  566. *
  567. * \defgroup xTaskAbortDelay xTaskAbortDelay
  568. * \ingroup TaskCtrl
  569. */
  570. BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  571. /**
  572. * task. h
  573. * @code{c}
  574. * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  575. * @endcode
  576. *
  577. * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  578. * See the configuration section for more information.
  579. *
  580. * Obtain the priority of any task.
  581. *
  582. * @param xTask Handle of the task to be queried. Passing a NULL
  583. * handle results in the priority of the calling task being returned.
  584. *
  585. * @return The priority of xTask.
  586. *
  587. * Example usage:
  588. * @code{c}
  589. * void vAFunction( void )
  590. * {
  591. * TaskHandle_t xHandle;
  592. *
  593. * // Create a task, storing the handle.
  594. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  595. *
  596. * // ...
  597. *
  598. * // Use the handle to obtain the priority of the created task.
  599. * // It was created with tskIDLE_PRIORITY, but may have changed
  600. * // it itself.
  601. * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  602. * {
  603. * // The task has changed it's priority.
  604. * }
  605. *
  606. * // ...
  607. *
  608. * // Is our priority higher than the created task?
  609. * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  610. * {
  611. * // Our priority (obtained using NULL handle) is higher.
  612. * }
  613. * }
  614. * @endcode
  615. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  616. * \ingroup TaskCtrl
  617. */
  618. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  619. /**
  620. * task. h
  621. * @code{c}
  622. * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  623. * @endcode
  624. *
  625. * A version of uxTaskPriorityGet() that can be used from an ISR.
  626. */
  627. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  628. /**
  629. * task. h
  630. * @code{c}
  631. * eTaskState eTaskGetState( TaskHandle_t xTask );
  632. * @endcode
  633. *
  634. * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  635. * See the configuration section for more information.
  636. *
  637. * Obtain the state of any task. States are encoded by the eTaskState
  638. * enumerated type.
  639. *
  640. * @param xTask Handle of the task to be queried.
  641. *
  642. * @return The state of xTask at the time the function was called. Note the
  643. * state of the task might change between the function being called, and the
  644. * functions return value being tested by the calling task.
  645. */
  646. eTaskState eTaskGetState( TaskHandle_t xTask );
  647. /**
  648. * task. h
  649. * @code{c}
  650. * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  651. * @endcode
  652. *
  653. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  654. * See the configuration section for more information.
  655. *
  656. * Set the priority of any task.
  657. *
  658. * A context switch will occur before the function returns if the priority
  659. * being set is higher than the currently executing task.
  660. *
  661. * @param xTask Handle to the task for which the priority is being set.
  662. * Passing a NULL handle results in the priority of the calling task being set.
  663. *
  664. * @param uxNewPriority The priority to which the task will be set.
  665. *
  666. * Example usage:
  667. * @code{c}
  668. * void vAFunction( void )
  669. * {
  670. * TaskHandle_t xHandle;
  671. *
  672. * // Create a task, storing the handle.
  673. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  674. *
  675. * // ...
  676. *
  677. * // Use the handle to raise the priority of the created task.
  678. * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  679. *
  680. * // ...
  681. *
  682. * // Use a NULL handle to raise our priority to the same value.
  683. * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  684. * }
  685. * @endcode
  686. * \defgroup vTaskPrioritySet vTaskPrioritySet
  687. * \ingroup TaskCtrl
  688. */
  689. void vTaskPrioritySet( TaskHandle_t xTask,
  690. UBaseType_t uxNewPriority );
  691. /**
  692. * task. h
  693. * @code{c}
  694. * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  695. * @endcode
  696. *
  697. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  698. * See the configuration section for more information.
  699. *
  700. * Suspend any task. When suspended a task will never get any microcontroller
  701. * processing time, no matter what its priority.
  702. *
  703. * Calls to vTaskSuspend are not accumulative -
  704. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  705. * call to vTaskResume () to ready the suspended task.
  706. *
  707. * RT-Thread only supports suspending the current running thread.
  708. * This function must be called with NULL as the parameter.
  709. *
  710. * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  711. * handle will cause the calling task to be suspended.
  712. *
  713. * Example usage:
  714. * @code{c}
  715. * void vAFunction( void )
  716. * {
  717. * TaskHandle_t xHandle;
  718. *
  719. * // Create a task, storing the handle.
  720. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  721. *
  722. * // ...
  723. *
  724. * // Use the handle to suspend the created task.
  725. * vTaskSuspend( xHandle );
  726. *
  727. * // ...
  728. *
  729. * // The created task will not run during this period, unless
  730. * // another task calls vTaskResume( xHandle ).
  731. *
  732. * //...
  733. *
  734. *
  735. * // Suspend ourselves.
  736. * vTaskSuspend( NULL );
  737. *
  738. * // We cannot get here unless another task calls vTaskResume
  739. * // with our handle as the parameter.
  740. * }
  741. * @endcode
  742. * \defgroup vTaskSuspend vTaskSuspend
  743. * \ingroup TaskCtrl
  744. */
  745. void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  746. /**
  747. * task. h
  748. * @code{c}
  749. * void vTaskResume( TaskHandle_t xTaskToResume );
  750. * @endcode
  751. *
  752. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  753. * See the configuration section for more information.
  754. *
  755. * Resumes a suspended task.
  756. *
  757. * A task that has been suspended by one or more calls to vTaskSuspend ()
  758. * will be made available for running again by a single call to
  759. * vTaskResume ().
  760. *
  761. * @param xTaskToResume Handle to the task being readied.
  762. *
  763. * Example usage:
  764. * @code{c}
  765. * void vAFunction( void )
  766. * {
  767. * TaskHandle_t xHandle;
  768. *
  769. * // Create a task, storing the handle.
  770. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  771. *
  772. * // ...
  773. *
  774. * // Use the handle to suspend the created task.
  775. * vTaskSuspend( xHandle );
  776. *
  777. * // ...
  778. *
  779. * // The created task will not run during this period, unless
  780. * // another task calls vTaskResume( xHandle ).
  781. *
  782. * //...
  783. *
  784. *
  785. * // Resume the suspended task ourselves.
  786. * vTaskResume( xHandle );
  787. *
  788. * // The created task will once again get microcontroller processing
  789. * // time in accordance with its priority within the system.
  790. * }
  791. * @endcode
  792. * \defgroup vTaskResume vTaskResume
  793. * \ingroup TaskCtrl
  794. */
  795. void vTaskResume( TaskHandle_t xTaskToResume );
  796. /**
  797. * task. h
  798. * @code{c}
  799. * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  800. * @endcode
  801. *
  802. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  803. * available. See the configuration section for more information.
  804. *
  805. * An implementation of vTaskResume() that can be called from within an ISR.
  806. *
  807. * A task that has been suspended by one or more calls to vTaskSuspend ()
  808. * will be made available for running again by a single call to
  809. * xTaskResumeFromISR ().
  810. *
  811. * xTaskResumeFromISR() should not be used to synchronise a task with an
  812. * interrupt if there is a chance that the interrupt could arrive prior to the
  813. * task being suspended - as this can lead to interrupts being missed. Use of a
  814. * semaphore as a synchronisation mechanism would avoid this eventuality.
  815. *
  816. * @param xTaskToResume Handle to the task being readied.
  817. *
  818. * @return pdTRUE if resuming the task should result in a context switch,
  819. * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  820. * may be required following the ISR.
  821. *
  822. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  823. * \ingroup TaskCtrl
  824. */
  825. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  826. /*-----------------------------------------------------------
  827. * SCHEDULER CONTROL
  828. *----------------------------------------------------------*/
  829. /**
  830. * task. h
  831. * @code{c}
  832. * void vTaskSuspendAll( void );
  833. * @endcode
  834. *
  835. * Suspends the scheduler without disabling interrupts. Context switches will
  836. * not occur while the scheduler is suspended.
  837. *
  838. * After calling vTaskSuspendAll () the calling task will continue to execute
  839. * without risk of being swapped out until a call to xTaskResumeAll () has been
  840. * made.
  841. *
  842. * API functions that have the potential to cause a context switch (for example,
  843. * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  844. * is suspended.
  845. *
  846. * Example usage:
  847. * @code{c}
  848. * void vTask1( void * pvParameters )
  849. * {
  850. * for( ;; )
  851. * {
  852. * // Task code goes here.
  853. *
  854. * // ...
  855. *
  856. * // At some point the task wants to perform a long operation during
  857. * // which it does not want to get swapped out. It cannot use
  858. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  859. * // operation may cause interrupts to be missed - including the
  860. * // ticks.
  861. *
  862. * // Prevent the real time kernel swapping out the task.
  863. * vTaskSuspendAll ();
  864. *
  865. * // Perform the operation here. There is no need to use critical
  866. * // sections as we have all the microcontroller processing time.
  867. * // During this time interrupts will still operate and the kernel
  868. * // tick count will be maintained.
  869. *
  870. * // ...
  871. *
  872. * // The operation is complete. Restart the kernel.
  873. * xTaskResumeAll ();
  874. * }
  875. * }
  876. * @endcode
  877. * \defgroup vTaskSuspendAll vTaskSuspendAll
  878. * \ingroup SchedulerControl
  879. */
  880. void vTaskSuspendAll( void );
  881. /**
  882. * task. h
  883. * @code{c}
  884. * BaseType_t xTaskResumeAll( void );
  885. * @endcode
  886. *
  887. * Resumes scheduler activity after it was suspended by a call to
  888. * vTaskSuspendAll().
  889. *
  890. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  891. * that were previously suspended by a call to vTaskSuspend().
  892. *
  893. * @return If resuming the scheduler caused a context switch then pdTRUE is
  894. * returned, otherwise pdFALSE is returned.
  895. *
  896. * Example usage:
  897. * @code{c}
  898. * void vTask1( void * pvParameters )
  899. * {
  900. * for( ;; )
  901. * {
  902. * // Task code goes here.
  903. *
  904. * // ...
  905. *
  906. * // At some point the task wants to perform a long operation during
  907. * // which it does not want to get swapped out. It cannot use
  908. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  909. * // operation may cause interrupts to be missed - including the
  910. * // ticks.
  911. *
  912. * // Prevent the real time kernel swapping out the task.
  913. * vTaskSuspendAll ();
  914. *
  915. * // Perform the operation here. There is no need to use critical
  916. * // sections as we have all the microcontroller processing time.
  917. * // During this time interrupts will still operate and the real
  918. * // time kernel tick count will be maintained.
  919. *
  920. * // ...
  921. *
  922. * // The operation is complete. Restart the kernel. We want to force
  923. * // a context switch - but there is no point if resuming the scheduler
  924. * // caused a context switch already.
  925. * if( !xTaskResumeAll () )
  926. * {
  927. * taskYIELD ();
  928. * }
  929. * }
  930. * }
  931. * @endcode
  932. * \defgroup xTaskResumeAll xTaskResumeAll
  933. * \ingroup SchedulerControl
  934. */
  935. BaseType_t xTaskResumeAll( void );
  936. /*-----------------------------------------------------------
  937. * TASK UTILITIES
  938. *----------------------------------------------------------*/
  939. /**
  940. * task. h
  941. * @code{c}
  942. * TickType_t xTaskGetTickCount( void );
  943. * @endcode
  944. *
  945. * @return The count of ticks since vTaskStartScheduler was called.
  946. *
  947. * \defgroup xTaskGetTickCount xTaskGetTickCount
  948. * \ingroup TaskUtils
  949. */
  950. TickType_t xTaskGetTickCount( void );
  951. /**
  952. * task. h
  953. * @code{c}
  954. * TickType_t xTaskGetTickCountFromISR( void );
  955. * @endcode
  956. *
  957. * @return The count of ticks since vTaskStartScheduler was called.
  958. *
  959. * This is a version of xTaskGetTickCount() that is safe to be called from an
  960. * ISR - provided that TickType_t is the natural word size of the
  961. * microcontroller being used or interrupt nesting is either not supported or
  962. * not being used.
  963. *
  964. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  965. * \ingroup TaskUtils
  966. */
  967. TickType_t xTaskGetTickCountFromISR( void );
  968. /**
  969. * task. h
  970. * @code{c}
  971. * uint16_t uxTaskGetNumberOfTasks( void );
  972. * @endcode
  973. *
  974. * @return The number of tasks that the real time kernel is currently managing.
  975. * This includes all ready, blocked and suspended tasks. A task that
  976. * has been deleted but not yet freed by the idle task will also be
  977. * included in the count.
  978. *
  979. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  980. * \ingroup TaskUtils
  981. */
  982. UBaseType_t uxTaskGetNumberOfTasks( void );
  983. /**
  984. * task. h
  985. * @code{c}
  986. * char *pcTaskGetName( TaskHandle_t xTaskToQuery );
  987. * @endcode
  988. *
  989. * @return The text (human readable) name of the task referenced by the handle
  990. * xTaskToQuery. A task can query its own name by either passing in its own
  991. * handle, or by setting xTaskToQuery to NULL.
  992. *
  993. * \defgroup pcTaskGetName pcTaskGetName
  994. * \ingroup TaskUtils
  995. */
  996. char * pcTaskGetName( TaskHandle_t xTaskToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  997. /**
  998. * task. h
  999. * @code{c}
  1000. * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
  1001. * @endcode
  1002. *
  1003. * NOTE: This function takes a relatively long time to complete and should be
  1004. * used sparingly.
  1005. *
  1006. * @return The handle of the task that has the human readable name pcNameToQuery.
  1007. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1008. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1009. *
  1010. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1011. * \ingroup TaskUtils
  1012. */
  1013. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1014. /**
  1015. * task.h
  1016. * @code{c}
  1017. * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  1018. * @endcode
  1019. *
  1020. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1021. * this function to be available.
  1022. *
  1023. * Returns the high water mark of the stack associated with xTask. That is,
  1024. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1025. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1026. * number the closer the task has come to overflowing its stack.
  1027. *
  1028. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1029. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1030. * user to determine the return type. It gets around the problem of the value
  1031. * overflowing on 8-bit types without breaking backward compatibility for
  1032. * applications that expect an 8-bit return type.
  1033. *
  1034. * @param xTask Handle of the task associated with the stack to be checked.
  1035. * Set xTask to NULL to check the stack of the calling task.
  1036. *
  1037. * @return The smallest amount of free stack space there has been (in words, so
  1038. * actual spaces on the stack rather than bytes) since the task referenced by
  1039. * xTask was created.
  1040. */
  1041. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  1042. /**
  1043. * task.h
  1044. * @code{c}
  1045. * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  1046. * @endcode
  1047. *
  1048. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1049. * this function to be available.
  1050. *
  1051. * Returns the high water mark of the stack associated with xTask. That is,
  1052. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1053. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1054. * number the closer the task has come to overflowing its stack.
  1055. *
  1056. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1057. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1058. * user to determine the return type. It gets around the problem of the value
  1059. * overflowing on 8-bit types without breaking backward compatibility for
  1060. * applications that expect an 8-bit return type.
  1061. *
  1062. * @param xTask Handle of the task associated with the stack to be checked.
  1063. * Set xTask to NULL to check the stack of the calling task.
  1064. *
  1065. * @return The smallest amount of free stack space there has been (in words, so
  1066. * actual spaces on the stack rather than bytes) since the task referenced by
  1067. * xTask was created.
  1068. */
  1069. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  1070. /* When using trace macros it is sometimes necessary to include task.h before
  1071. * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1072. * so the following two prototypes will cause a compilation error. This can be
  1073. * fixed by simply guarding against the inclusion of these two prototypes unless
  1074. * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1075. * constant. */
  1076. #ifdef configUSE_APPLICATION_TASK_TAG
  1077. #if configUSE_APPLICATION_TASK_TAG == 1
  1078. /**
  1079. * task.h
  1080. * @code{c}
  1081. * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  1082. * @endcode
  1083. *
  1084. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1085. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1086. * function.
  1087. */
  1088. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  1089. TaskHookFunction_t pxHookFunction );
  1090. /**
  1091. * task.h
  1092. * @code{c}
  1093. * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1094. * @endcode
  1095. *
  1096. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1097. * call from an interrupt service routine - call
  1098. * xTaskGetApplicationTaskTagFromISR() instead.
  1099. */
  1100. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1101. /**
  1102. * task.h
  1103. * @code{c}
  1104. * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1105. * @endcode
  1106. *
  1107. * Returns the pxHookFunction value assigned to the task xTask. Can
  1108. * be called from an interrupt service routine.
  1109. */
  1110. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1111. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1112. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1113. /**
  1114. * task.h
  1115. * @code{c}
  1116. * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  1117. * @endcode
  1118. *
  1119. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1120. * the effect of calling the Running tasks (the calling task) hook function.
  1121. *
  1122. * pvParameter is passed to the hook function for the task to interpret as it
  1123. * wants. The return value is the value returned by the task hook function
  1124. * registered by the user.
  1125. */
  1126. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  1127. void * pvParameter );
  1128. /**
  1129. * xTaskGetIdleTaskHandle() is only available if
  1130. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1131. *
  1132. * Simply returns the handle of the idle task. It is not valid to call
  1133. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1134. */
  1135. TaskHandle_t xTaskGetIdleTaskHandle( void );
  1136. /**
  1137. * task. h
  1138. * @code{c}
  1139. * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
  1140. * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
  1141. * @endcode
  1142. *
  1143. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1144. *
  1145. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1146. * functions to be available.
  1147. *
  1148. * Sends a direct to task notification to a task, with an optional value and
  1149. * action.
  1150. *
  1151. * Each task has a private array of "notification values" (or 'notifications'),
  1152. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1153. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1154. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1155. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1156. *
  1157. * Events can be sent to a task using an intermediary object. Examples of such
  1158. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1159. * are a method of sending an event directly to a task without the need for such
  1160. * an intermediary object.
  1161. *
  1162. * A notification sent to a task can optionally perform an action, such as
  1163. * update, overwrite or increment one of the task's notification values. In
  1164. * that way task notifications can be used to send data to a task, or be used as
  1165. * light weight and fast binary or counting semaphores.
  1166. *
  1167. * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
  1168. * [optionally] block to wait for a notification to be pending. The task does
  1169. * not consume any CPU time while it is in the Blocked state.
  1170. *
  1171. * A notification sent to a task will remain pending until it is cleared by the
  1172. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1173. * un-indexed equivalents). If the task was already in the Blocked state to
  1174. * wait for a notification when the notification arrives then the task will
  1175. * automatically be removed from the Blocked state (unblocked) and the
  1176. * notification cleared.
  1177. *
  1178. * **NOTE** Each notification within the array operates independently - a task
  1179. * can only block on one notification within the array at a time and will not be
  1180. * unblocked by a notification sent to any other array index.
  1181. *
  1182. * Backward compatibility information:
  1183. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1184. * all task notification API functions operated on that value. Replacing the
  1185. * single notification value with an array of notification values necessitated a
  1186. * new set of API functions that could address specific notifications within the
  1187. * array. xTaskNotify() is the original API function, and remains backward
  1188. * compatible by always operating on the notification value at index 0 in the
  1189. * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  1190. * with the uxIndexToNotify parameter set to 0.
  1191. *
  1192. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1193. * task can be returned from the xTaskCreate() API function used to create the
  1194. * task, and the handle of the currently running task can be obtained by calling
  1195. * xTaskGetCurrentTaskHandle().
  1196. *
  1197. * @param uxIndexToNotify The index within the target task's array of
  1198. * notification values to which the notification is to be sent. uxIndexToNotify
  1199. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  1200. * not have this parameter and always sends notifications to index 0.
  1201. *
  1202. * @param ulValue Data that can be sent with the notification. How the data is
  1203. * used depends on the value of the eAction parameter.
  1204. *
  1205. * @param eAction Specifies how the notification updates the task's notification
  1206. * value, if at all. Valid values for eAction are as follows:
  1207. *
  1208. * eSetBits -
  1209. * The target notification value is bitwise ORed with ulValue.
  1210. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1211. *
  1212. * eIncrement -
  1213. * The target notification value is incremented. ulValue is not used and
  1214. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1215. *
  1216. * eSetValueWithOverwrite -
  1217. * The target notification value is set to the value of ulValue, even if the
  1218. * task being notified had not yet processed the previous notification at the
  1219. * same array index (the task already had a notification pending at that index).
  1220. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1221. *
  1222. * eSetValueWithoutOverwrite -
  1223. * If the task being notified did not already have a notification pending at the
  1224. * same array index then the target notification value is set to ulValue and
  1225. * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  1226. * had a notification pending at the same array index then no action is
  1227. * performed and pdFAIL is returned.
  1228. *
  1229. * eNoAction -
  1230. * The task receives a notification at the specified array index without the
  1231. * notification value at that index being updated. ulValue is not used and
  1232. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1233. *
  1234. * pulPreviousNotificationValue -
  1235. * Can be used to pass out the subject task's notification value before any
  1236. * bits are modified by the notify function.
  1237. *
  1238. * @return Dependent on the value of eAction. See the description of the
  1239. * eAction parameter.
  1240. *
  1241. * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  1242. * \ingroup TaskNotifications
  1243. */
  1244. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  1245. UBaseType_t uxIndexToNotify,
  1246. uint32_t ulValue,
  1247. eNotifyAction eAction,
  1248. uint32_t * pulPreviousNotificationValue );
  1249. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  1250. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  1251. #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  1252. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  1253. /**
  1254. * task. h
  1255. * @code{c}
  1256. * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  1257. *
  1258. * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  1259. * @endcode
  1260. *
  1261. * Waits for a direct to task notification to be pending at a given index within
  1262. * an array of direct to task notifications.
  1263. *
  1264. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1265. *
  1266. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1267. * function to be available.
  1268. *
  1269. * Each task has a private array of "notification values" (or 'notifications'),
  1270. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1271. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1272. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1273. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1274. *
  1275. * Events can be sent to a task using an intermediary object. Examples of such
  1276. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1277. * are a method of sending an event directly to a task without the need for such
  1278. * an intermediary object.
  1279. *
  1280. * A notification sent to a task can optionally perform an action, such as
  1281. * update, overwrite or increment one of the task's notification values. In
  1282. * that way task notifications can be used to send data to a task, or be used as
  1283. * light weight and fast binary or counting semaphores.
  1284. *
  1285. * A notification sent to a task will remain pending until it is cleared by the
  1286. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1287. * un-indexed equivalents). If the task was already in the Blocked state to
  1288. * wait for a notification when the notification arrives then the task will
  1289. * automatically be removed from the Blocked state (unblocked) and the
  1290. * notification cleared.
  1291. *
  1292. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  1293. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  1294. * to wait for a notification value to have a non-zero value. The task does
  1295. * not consume any CPU time while it is in the Blocked state.
  1296. *
  1297. * **NOTE** Each notification within the array operates independently - a task
  1298. * can only block on one notification within the array at a time and will not be
  1299. * unblocked by a notification sent to any other array index.
  1300. *
  1301. * Backward compatibility information:
  1302. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1303. * all task notification API functions operated on that value. Replacing the
  1304. * single notification value with an array of notification values necessitated a
  1305. * new set of API functions that could address specific notifications within the
  1306. * array. xTaskNotifyWait() is the original API function, and remains backward
  1307. * compatible by always operating on the notification value at index 0 in the
  1308. * array. Calling xTaskNotifyWait() is equivalent to calling
  1309. * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  1310. *
  1311. * @param uxIndexToWaitOn The index within the calling task's array of
  1312. * notification values on which the calling task will wait for a notification to
  1313. * be received. uxIndexToWaitOn must be less than
  1314. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  1315. * not have this parameter and always waits for notifications on index 0.
  1316. *
  1317. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  1318. * will be cleared in the calling task's notification value before the task
  1319. * checks to see if any notifications are pending, and optionally blocks if no
  1320. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  1321. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  1322. * the effect of resetting the task's notification value to 0. Setting
  1323. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  1324. *
  1325. * @param ulBitsToClearOnExit If a notification is pending or received before
  1326. * the calling task exits the xTaskNotifyWait() function then the task's
  1327. * notification value (see the xTaskNotify() API function) is passed out using
  1328. * the pulNotificationValue parameter. Then any bits that are set in
  1329. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  1330. * *pulNotificationValue is set before any bits are cleared). Setting
  1331. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  1332. * (if limits.h is not included) will have the effect of resetting the task's
  1333. * notification value to 0 before the function exits. Setting
  1334. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  1335. * when the function exits (in which case the value passed out in
  1336. * pulNotificationValue will match the task's notification value).
  1337. *
  1338. * @param pulNotificationValue Used to pass the task's notification value out
  1339. * of the function. Note the value passed out will not be effected by the
  1340. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  1341. *
  1342. * @param xTicksToWait The maximum amount of time that the task should wait in
  1343. * the Blocked state for a notification to be received, should a notification
  1344. * not already be pending when xTaskNotifyWait() was called. The task
  1345. * will not consume any processing time while it is in the Blocked state. This
  1346. * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
  1347. * used to convert a time specified in milliseconds to a time specified in
  1348. * ticks.
  1349. *
  1350. * @return If a notification was received (including notifications that were
  1351. * already pending when xTaskNotifyWait was called) then pdPASS is
  1352. * returned. Otherwise pdFAIL is returned.
  1353. *
  1354. * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  1355. * \ingroup TaskNotifications
  1356. */
  1357. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  1358. uint32_t ulBitsToClearOnEntry,
  1359. uint32_t ulBitsToClearOnExit,
  1360. uint32_t * pulNotificationValue,
  1361. TickType_t xTicksToWait );
  1362. #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  1363. xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  1364. #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  1365. xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  1366. /*
  1367. * Return the handle of the calling task.
  1368. */
  1369. TaskHandle_t xTaskGetCurrentTaskHandle( void );
  1370. /* *INDENT-OFF* */
  1371. #ifdef __cplusplus
  1372. }
  1373. #endif
  1374. /* *INDENT-ON* */
  1375. #endif /* INC_TASK_H */