task.h 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  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. /* Task states returned by eTaskGetState. */
  76. typedef enum
  77. {
  78. eRunning = 0, /* A task is querying the state of itself, so must be running. */
  79. eReady, /* The task being queried is in a ready or pending ready list. */
  80. eBlocked, /* The task being queried is in the Blocked state. */
  81. eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  82. eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
  83. eInvalid /* Used as an 'invalid state' value. */
  84. } eTaskState;
  85. /* Actions that can be performed when vTaskNotify() is called. */
  86. typedef enum
  87. {
  88. eNoAction = 0, /* Notify the task without updating its notify value. */
  89. eSetBits, /* Set bits in the task's notification value. */
  90. eIncrement, /* Increment the task's notification value. */
  91. eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
  92. eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
  93. } eNotifyAction;
  94. /*
  95. * Used internally only.
  96. */
  97. typedef struct xTIME_OUT
  98. {
  99. BaseType_t xOverflowCount;
  100. TickType_t xTimeOnEntering;
  101. } TimeOut_t;
  102. /**
  103. * task. h
  104. *
  105. * Macro for forcing a context switch.
  106. *
  107. * \defgroup taskYIELD taskYIELD
  108. * \ingroup SchedulerControl
  109. */
  110. #define taskYIELD() portYIELD()
  111. /**
  112. * task. h
  113. *
  114. * Macro to mark the start of a critical code region. Preemptive context
  115. * switches cannot occur when in a critical region.
  116. *
  117. * NOTE: This may alter the stack (depending on the portable implementation)
  118. * so must be used with care!
  119. *
  120. * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  121. * \ingroup SchedulerControl
  122. */
  123. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  124. #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  125. /**
  126. * task. h
  127. *
  128. * Macro to mark the end of a critical code region. Preemptive context
  129. * switches cannot occur when in a critical region.
  130. *
  131. * NOTE: This may alter the stack (depending on the portable implementation)
  132. * so must be used with care!
  133. *
  134. * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  135. * \ingroup SchedulerControl
  136. */
  137. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  138. #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  139. /**
  140. * task. h
  141. *
  142. * Macro to disable all maskable interrupts.
  143. *
  144. * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  145. * \ingroup SchedulerControl
  146. */
  147. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  148. /**
  149. * task. h
  150. *
  151. * Macro to enable microcontroller interrupts.
  152. *
  153. * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  154. * \ingroup SchedulerControl
  155. */
  156. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  157. /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
  158. * 0 to generate more optimal code when configASSERT() is defined as the constant
  159. * is used in assert() statements. */
  160. #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
  161. #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
  162. #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
  163. /*-----------------------------------------------------------
  164. * TASK CREATION API
  165. *----------------------------------------------------------*/
  166. /**
  167. * task. h
  168. * @code{c}
  169. * BaseType_t xTaskCreate(
  170. * TaskFunction_t pxTaskCode,
  171. * const char *pcName,
  172. * configSTACK_DEPTH_TYPE usStackDepth,
  173. * void *pvParameters,
  174. * UBaseType_t uxPriority,
  175. * TaskHandle_t *pxCreatedTask
  176. * );
  177. * @endcode
  178. *
  179. * Create a new task and add it to the list of tasks that are ready to run.
  180. *
  181. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  182. * memory. The first block is used to hold the task's data structures. The
  183. * second block is used by the task as its stack. If a task is created using
  184. * xTaskCreate() then both blocks of memory are automatically dynamically
  185. * allocated inside the xTaskCreate() function. (see
  186. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  187. * xTaskCreateStatic() then the application writer must provide the required
  188. * memory. xTaskCreateStatic() therefore allows a task to be created without
  189. * using any dynamic memory allocation.
  190. *
  191. * See xTaskCreateStatic() for a version that does not use any dynamic memory
  192. * allocation.
  193. *
  194. * xTaskCreate() can only be used to create a task that has unrestricted
  195. * access to the entire microcontroller memory map. Systems that include MPU
  196. * support can alternatively create an MPU constrained task using
  197. * xTaskCreateRestricted().
  198. *
  199. * @param pxTaskCode Pointer to the task entry function. Tasks
  200. * must be implemented to never return (i.e. continuous loop).
  201. *
  202. * @param pcName A descriptive name for the task. This is mainly used to
  203. * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
  204. * is 16.
  205. *
  206. * @param usStackDepth The size of the task stack specified as the number of
  207. * variables the stack can hold - not the number of bytes. For example, if
  208. * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  209. * will be allocated for stack storage.
  210. *
  211. * @param pvParameters Pointer that will be used as the parameter for the task
  212. * being created.
  213. *
  214. * @param uxPriority The priority at which the task should run. Systems that
  215. * include MPU support can optionally create tasks in a privileged (system)
  216. * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  217. * example, to create a privileged task at priority 2 the uxPriority parameter
  218. * should be set to ( 2 | portPRIVILEGE_BIT ).
  219. *
  220. * @param pxCreatedTask Used to pass back a handle by which the created task
  221. * can be referenced.
  222. *
  223. * @return pdPASS if the task was successfully created and added to a ready
  224. * list, otherwise an error code defined in the file projdefs.h
  225. *
  226. * Example usage:
  227. * @code{c}
  228. * // Task to be created.
  229. * void vTaskCode( void * pvParameters )
  230. * {
  231. * for( ;; )
  232. * {
  233. * // Task code goes here.
  234. * }
  235. * }
  236. *
  237. * // Function that creates a task.
  238. * void vOtherFunction( void )
  239. * {
  240. * static uint8_t ucParameterToPass;
  241. * TaskHandle_t xHandle = NULL;
  242. *
  243. * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  244. * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  245. * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  246. * // the new task attempts to access it.
  247. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  248. * configASSERT( xHandle );
  249. *
  250. * // Use the handle to delete the task.
  251. * if( xHandle != NULL )
  252. * {
  253. * vTaskDelete( xHandle );
  254. * }
  255. * }
  256. * @endcode
  257. * \defgroup xTaskCreate xTaskCreate
  258. * \ingroup Tasks
  259. */
  260. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  261. BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  262. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  263. const configSTACK_DEPTH_TYPE usStackDepth,
  264. void * const pvParameters,
  265. UBaseType_t uxPriority,
  266. TaskHandle_t * const pxCreatedTask );
  267. #endif
  268. /**
  269. * task. h
  270. * @code{c}
  271. * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  272. * const char *pcName,
  273. * uint32_t ulStackDepth,
  274. * void *pvParameters,
  275. * UBaseType_t uxPriority,
  276. * StackType_t *puxStackBuffer,
  277. * StaticTask_t *pxTaskBuffer );
  278. * @endcode
  279. *
  280. * Create a new task and add it to the list of tasks that are ready to run.
  281. *
  282. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  283. * memory. The first block is used to hold the task's data structures. The
  284. * second block is used by the task as its stack. If a task is created using
  285. * xTaskCreate() then both blocks of memory are automatically dynamically
  286. * allocated inside the xTaskCreate() function. (see
  287. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  288. * xTaskCreateStatic() then the application writer must provide the required
  289. * memory. xTaskCreateStatic() therefore allows a task to be created without
  290. * using any dynamic memory allocation.
  291. *
  292. * @param pxTaskCode Pointer to the task entry function. Tasks
  293. * must be implemented to never return (i.e. continuous loop).
  294. *
  295. * @param pcName A descriptive name for the task. This is mainly used to
  296. * facilitate debugging. The maximum length of the string is defined by
  297. * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  298. *
  299. * @param ulStackDepth The size of the task stack specified as the number of
  300. * variables the stack can hold - not the number of bytes. For example, if
  301. * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
  302. * will be allocated for stack storage.
  303. *
  304. * @param pvParameters Pointer that will be used as the parameter for the task
  305. * being created.
  306. *
  307. * @param uxPriority The priority at which the task will run.
  308. *
  309. * @param puxStackBuffer Must point to a StackType_t array that has at least
  310. * ulStackDepth indexes - the array will then be used as the task's stack,
  311. * removing the need for the stack to be allocated dynamically.
  312. *
  313. * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
  314. * then be used to hold the task's data structures, removing the need for the
  315. * memory to be allocated dynamically.
  316. *
  317. * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
  318. * will be created and a handle to the created task is returned. If either
  319. * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
  320. * NULL is returned.
  321. *
  322. * Example usage:
  323. * @code{c}
  324. *
  325. * // Dimensions of the buffer that the task being created will use as its stack.
  326. * // NOTE: This is the number of words the stack will hold, not the number of
  327. * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
  328. * // then 400 bytes (100 * 32-bits) will be allocated.
  329. #define STACK_SIZE 200
  330. *
  331. * // Structure that will hold the TCB of the task being created.
  332. * StaticTask_t xTaskBuffer;
  333. *
  334. * // Buffer that the task being created will use as its stack. Note this is
  335. * // an array of StackType_t variables. The size of StackType_t is dependent on
  336. * // the RTOS port.
  337. * StackType_t xStack[ STACK_SIZE ];
  338. *
  339. * // Function that implements the task being created.
  340. * void vTaskCode( void * pvParameters )
  341. * {
  342. * // The parameter value is expected to be 1 as 1 is passed in the
  343. * // pvParameters value in the call to xTaskCreateStatic().
  344. * configASSERT( ( uint32_t ) pvParameters == 1UL );
  345. *
  346. * for( ;; )
  347. * {
  348. * // Task code goes here.
  349. * }
  350. * }
  351. *
  352. * // Function that creates a task.
  353. * void vOtherFunction( void )
  354. * {
  355. * TaskHandle_t xHandle = NULL;
  356. *
  357. * // Create the task without using any dynamic memory allocation.
  358. * xHandle = xTaskCreateStatic(
  359. * vTaskCode, // Function that implements the task.
  360. * "NAME", // Text name for the task.
  361. * STACK_SIZE, // Stack size in words, not bytes.
  362. * ( void * ) 1, // Parameter passed into the task.
  363. * tskIDLE_PRIORITY,// Priority at which the task is created.
  364. * xStack, // Array to use as the task's stack.
  365. * &xTaskBuffer ); // Variable to hold the task's data structure.
  366. *
  367. * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
  368. * // been created, and xHandle will be the task's handle. Use the handle
  369. * // to suspend the task.
  370. * vTaskSuspend( xHandle );
  371. * }
  372. * @endcode
  373. * \defgroup xTaskCreateStatic xTaskCreateStatic
  374. * \ingroup Tasks
  375. */
  376. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  377. TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  378. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  379. const uint32_t ulStackDepth,
  380. void * const pvParameters,
  381. UBaseType_t uxPriority,
  382. StackType_t * const puxStackBuffer,
  383. StaticTask_t * const pxTaskBuffer );
  384. #endif /* configSUPPORT_STATIC_ALLOCATION */
  385. /**
  386. * task. h
  387. * @code{c}
  388. * void vTaskDelete( TaskHandle_t xTaskToDelete );
  389. * @endcode
  390. *
  391. * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  392. * See the configuration section for more information.
  393. *
  394. * Remove a task from the RTOS real time kernel's management. The task being
  395. * deleted will be removed from all ready, blocked, suspended and event lists.
  396. *
  397. * NOTE: The idle task is responsible for freeing the kernel allocated
  398. * memory from tasks that have been deleted. It is therefore important that
  399. * the idle task is not starved of microcontroller processing time if your
  400. * application makes any calls to vTaskDelete (). Memory allocated by the
  401. * task code is not automatically freed, and should be freed before the task
  402. * is deleted.
  403. *
  404. * See the demo application file death.c for sample code that utilises
  405. * vTaskDelete ().
  406. *
  407. * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
  408. * cause the calling task to be deleted.
  409. *
  410. * Example usage:
  411. * @code{c}
  412. * void vOtherFunction( void )
  413. * {
  414. * TaskHandle_t xHandle;
  415. *
  416. * // Create the task, storing the handle.
  417. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  418. *
  419. * // Use the handle to delete the task.
  420. * vTaskDelete( xHandle );
  421. * }
  422. * @endcode
  423. * \defgroup vTaskDelete vTaskDelete
  424. * \ingroup Tasks
  425. */
  426. void vTaskDelete( TaskHandle_t xTaskToDelete );
  427. /*-----------------------------------------------------------
  428. * TASK CONTROL API
  429. *----------------------------------------------------------*/
  430. /**
  431. * task. h
  432. * @code{c}
  433. * void vTaskDelay( const TickType_t xTicksToDelay );
  434. * @endcode
  435. *
  436. * Delay a task for a given number of ticks. The actual time that the
  437. * task remains blocked depends on the tick rate. The constant
  438. * portTICK_PERIOD_MS can be used to calculate real time from the tick
  439. * rate - with the resolution of one tick period.
  440. *
  441. * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  442. * See the configuration section for more information.
  443. *
  444. *
  445. * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  446. * the time at which vTaskDelay() is called. For example, specifying a block
  447. * period of 100 ticks will cause the task to unblock 100 ticks after
  448. * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  449. * of controlling the frequency of a periodic task as the path taken through the
  450. * code, as well as other task and interrupt activity, will affect the frequency
  451. * at which vTaskDelay() gets called and therefore the time at which the task
  452. * next executes. See xTaskDelayUntil() for an alternative API function designed
  453. * to facilitate fixed frequency execution. It does this by specifying an
  454. * absolute time (rather than a relative time) at which the calling task should
  455. * unblock.
  456. *
  457. * @param xTicksToDelay The amount of time, in tick periods, that
  458. * the calling task should block.
  459. *
  460. * Example usage:
  461. *
  462. * void vTaskFunction( void * pvParameters )
  463. * {
  464. * // Block for 500ms.
  465. * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
  466. *
  467. * for( ;; )
  468. * {
  469. * // Simply toggle the LED every 500ms, blocking between each toggle.
  470. * vToggleLED();
  471. * vTaskDelay( xDelay );
  472. * }
  473. * }
  474. *
  475. * \defgroup vTaskDelay vTaskDelay
  476. * \ingroup TaskCtrl
  477. */
  478. void vTaskDelay( const TickType_t xTicksToDelay );
  479. /**
  480. * task. h
  481. * @code{c}
  482. * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  483. * @endcode
  484. *
  485. * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
  486. * See the configuration section for more information.
  487. *
  488. * Delay a task until a specified time. This function can be used by periodic
  489. * tasks to ensure a constant execution frequency.
  490. *
  491. * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  492. * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  493. * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  494. * execution frequency as the time between a task starting to execute and that task
  495. * calling vTaskDelay () may not be fixed [the task may take a different path though the
  496. * code between calls, or may get interrupted or preempted a different number of times
  497. * each time it executes].
  498. *
  499. * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  500. * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  501. * unblock.
  502. *
  503. * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
  504. * time specified in milliseconds with a resolution of one tick period.
  505. *
  506. * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  507. * task was last unblocked. The variable must be initialised with the current time
  508. * prior to its first use (see the example below). Following this the variable is
  509. * automatically updated within xTaskDelayUntil ().
  510. *
  511. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  512. * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
  513. * same xTimeIncrement parameter value will cause the task to execute with
  514. * a fixed interface period.
  515. *
  516. * @return Value which can be used to check whether the task was actually delayed.
  517. * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
  518. * be delayed if the next expected wake time is in the past.
  519. *
  520. * Example usage:
  521. * @code{c}
  522. * // Perform an action every 10 ticks.
  523. * void vTaskFunction( void * pvParameters )
  524. * {
  525. * TickType_t xLastWakeTime;
  526. * const TickType_t xFrequency = 10;
  527. * BaseType_t xWasDelayed;
  528. *
  529. * // Initialise the xLastWakeTime variable with the current time.
  530. * xLastWakeTime = xTaskGetTickCount ();
  531. * for( ;; )
  532. * {
  533. * // Wait for the next cycle.
  534. * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  535. *
  536. * // Perform action here. xWasDelayed value can be used to determine
  537. * // whether a deadline was missed if the code here took too long.
  538. * }
  539. * }
  540. * @endcode
  541. * \defgroup xTaskDelayUntil xTaskDelayUntil
  542. * \ingroup TaskCtrl
  543. */
  544. BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  545. const TickType_t xTimeIncrement );
  546. /*
  547. * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
  548. * return a value.
  549. */
  550. #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
  551. { \
  552. ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
  553. }
  554. /**
  555. * task. h
  556. * @code{c}
  557. * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  558. * @endcode
  559. *
  560. * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  561. * function to be available.
  562. *
  563. * A task will enter the Blocked state when it is waiting for an event. The
  564. * event it is waiting for can be a temporal event (waiting for a time), such
  565. * as when vTaskDelay() is called, or an event on an object, such as when
  566. * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  567. * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  568. * task will leave the Blocked state, and return from whichever function call
  569. * placed the task into the Blocked state.
  570. *
  571. * There is no 'FromISR' version of this function as an interrupt would need to
  572. * know which object a task was blocked on in order to know which actions to
  573. * take. For example, if the task was blocked on a queue the interrupt handler
  574. * would then need to know if the queue was locked.
  575. *
  576. * @param xTask The handle of the task to remove from the Blocked state.
  577. *
  578. * @return If the task referenced by xTask was not in the Blocked state then
  579. * pdFAIL is returned. Otherwise pdPASS is returned.
  580. *
  581. * \defgroup xTaskAbortDelay xTaskAbortDelay
  582. * \ingroup TaskCtrl
  583. */
  584. BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  585. /**
  586. * task. h
  587. * @code{c}
  588. * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  589. * @endcode
  590. *
  591. * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  592. * See the configuration section for more information.
  593. *
  594. * Obtain the priority of any task.
  595. *
  596. * @param xTask Handle of the task to be queried. Passing a NULL
  597. * handle results in the priority of the calling task being returned.
  598. *
  599. * @return The priority of xTask.
  600. *
  601. * Example usage:
  602. * @code{c}
  603. * void vAFunction( void )
  604. * {
  605. * TaskHandle_t xHandle;
  606. *
  607. * // Create a task, storing the handle.
  608. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  609. *
  610. * // ...
  611. *
  612. * // Use the handle to obtain the priority of the created task.
  613. * // It was created with tskIDLE_PRIORITY, but may have changed
  614. * // it itself.
  615. * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  616. * {
  617. * // The task has changed it's priority.
  618. * }
  619. *
  620. * // ...
  621. *
  622. * // Is our priority higher than the created task?
  623. * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  624. * {
  625. * // Our priority (obtained using NULL handle) is higher.
  626. * }
  627. * }
  628. * @endcode
  629. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  630. * \ingroup TaskCtrl
  631. */
  632. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  633. /**
  634. * task. h
  635. * @code{c}
  636. * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  637. * @endcode
  638. *
  639. * A version of uxTaskPriorityGet() that can be used from an ISR.
  640. */
  641. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  642. /**
  643. * task. h
  644. * @code{c}
  645. * eTaskState eTaskGetState( TaskHandle_t xTask );
  646. * @endcode
  647. *
  648. * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  649. * See the configuration section for more information.
  650. *
  651. * Obtain the state of any task. States are encoded by the eTaskState
  652. * enumerated type.
  653. *
  654. * @param xTask Handle of the task to be queried.
  655. *
  656. * @return The state of xTask at the time the function was called. Note the
  657. * state of the task might change between the function being called, and the
  658. * functions return value being tested by the calling task.
  659. */
  660. eTaskState eTaskGetState( TaskHandle_t xTask );
  661. /**
  662. * task. h
  663. * @code{c}
  664. * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  665. * @endcode
  666. *
  667. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  668. * See the configuration section for more information.
  669. *
  670. * Set the priority of any task.
  671. *
  672. * A context switch will occur before the function returns if the priority
  673. * being set is higher than the currently executing task.
  674. *
  675. * @param xTask Handle to the task for which the priority is being set.
  676. * Passing a NULL handle results in the priority of the calling task being set.
  677. *
  678. * @param uxNewPriority The priority to which the task will be set.
  679. *
  680. * Example usage:
  681. * @code{c}
  682. * void vAFunction( void )
  683. * {
  684. * TaskHandle_t xHandle;
  685. *
  686. * // Create a task, storing the handle.
  687. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  688. *
  689. * // ...
  690. *
  691. * // Use the handle to raise the priority of the created task.
  692. * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  693. *
  694. * // ...
  695. *
  696. * // Use a NULL handle to raise our priority to the same value.
  697. * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  698. * }
  699. * @endcode
  700. * \defgroup vTaskPrioritySet vTaskPrioritySet
  701. * \ingroup TaskCtrl
  702. */
  703. void vTaskPrioritySet( TaskHandle_t xTask,
  704. UBaseType_t uxNewPriority );
  705. /**
  706. * task. h
  707. * @code{c}
  708. * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  709. * @endcode
  710. *
  711. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  712. * See the configuration section for more information.
  713. *
  714. * Suspend any task. When suspended a task will never get any microcontroller
  715. * processing time, no matter what its priority.
  716. *
  717. * Calls to vTaskSuspend are not accumulative -
  718. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  719. * call to vTaskResume () to ready the suspended task.
  720. *
  721. * RT-Thread only supports suspending the current running thread.
  722. * This function must be called with NULL as the parameter.
  723. *
  724. * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  725. * handle will cause the calling task to be suspended.
  726. *
  727. * Example usage:
  728. * @code{c}
  729. * void vAFunction( void )
  730. * {
  731. * TaskHandle_t xHandle;
  732. *
  733. * // Create a task, storing the handle.
  734. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  735. *
  736. * // ...
  737. *
  738. * // Use the handle to suspend the created task.
  739. * vTaskSuspend( xHandle );
  740. *
  741. * // ...
  742. *
  743. * // The created task will not run during this period, unless
  744. * // another task calls vTaskResume( xHandle ).
  745. *
  746. * //...
  747. *
  748. *
  749. * // Suspend ourselves.
  750. * vTaskSuspend( NULL );
  751. *
  752. * // We cannot get here unless another task calls vTaskResume
  753. * // with our handle as the parameter.
  754. * }
  755. * @endcode
  756. * \defgroup vTaskSuspend vTaskSuspend
  757. * \ingroup TaskCtrl
  758. */
  759. void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  760. /**
  761. * task. h
  762. * @code{c}
  763. * void vTaskResume( TaskHandle_t xTaskToResume );
  764. * @endcode
  765. *
  766. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  767. * See the configuration section for more information.
  768. *
  769. * Resumes a suspended task.
  770. *
  771. * A task that has been suspended by one or more calls to vTaskSuspend ()
  772. * will be made available for running again by a single call to
  773. * vTaskResume ().
  774. *
  775. * @param xTaskToResume Handle to the task being readied.
  776. *
  777. * Example usage:
  778. * @code{c}
  779. * void vAFunction( void )
  780. * {
  781. * TaskHandle_t xHandle;
  782. *
  783. * // Create a task, storing the handle.
  784. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  785. *
  786. * // ...
  787. *
  788. * // Use the handle to suspend the created task.
  789. * vTaskSuspend( xHandle );
  790. *
  791. * // ...
  792. *
  793. * // The created task will not run during this period, unless
  794. * // another task calls vTaskResume( xHandle ).
  795. *
  796. * //...
  797. *
  798. *
  799. * // Resume the suspended task ourselves.
  800. * vTaskResume( xHandle );
  801. *
  802. * // The created task will once again get microcontroller processing
  803. * // time in accordance with its priority within the system.
  804. * }
  805. * @endcode
  806. * \defgroup vTaskResume vTaskResume
  807. * \ingroup TaskCtrl
  808. */
  809. void vTaskResume( TaskHandle_t xTaskToResume );
  810. /**
  811. * task. h
  812. * @code{c}
  813. * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  814. * @endcode
  815. *
  816. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  817. * available. See the configuration section for more information.
  818. *
  819. * An implementation of vTaskResume() that can be called from within an ISR.
  820. *
  821. * A task that has been suspended by one or more calls to vTaskSuspend ()
  822. * will be made available for running again by a single call to
  823. * xTaskResumeFromISR ().
  824. *
  825. * xTaskResumeFromISR() should not be used to synchronise a task with an
  826. * interrupt if there is a chance that the interrupt could arrive prior to the
  827. * task being suspended - as this can lead to interrupts being missed. Use of a
  828. * semaphore as a synchronisation mechanism would avoid this eventuality.
  829. *
  830. * @param xTaskToResume Handle to the task being readied.
  831. *
  832. * @return pdTRUE if resuming the task should result in a context switch,
  833. * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  834. * may be required following the ISR.
  835. *
  836. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  837. * \ingroup TaskCtrl
  838. */
  839. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  840. /*-----------------------------------------------------------
  841. * SCHEDULER CONTROL
  842. *----------------------------------------------------------*/
  843. /**
  844. * task. h
  845. * @code{c}
  846. * void vTaskStartScheduler( void );
  847. * @endcode
  848. *
  849. * Starts the real time kernel tick processing. After calling the kernel
  850. * has control over which tasks are executed and when.
  851. *
  852. * See the demo application file main.c for an example of creating
  853. * tasks and starting the kernel.
  854. *
  855. * Example usage:
  856. * @code{c}
  857. * void vAFunction( void )
  858. * {
  859. * // Create at least one task before starting the kernel.
  860. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  861. *
  862. * // Start the real time kernel with preemption.
  863. * vTaskStartScheduler ();
  864. *
  865. * // Will not get here unless a task calls vTaskEndScheduler ()
  866. * }
  867. * @endcode
  868. *
  869. * \defgroup vTaskStartScheduler vTaskStartScheduler
  870. * \ingroup SchedulerControl
  871. */
  872. void vTaskStartScheduler( void );
  873. /**
  874. * task. h
  875. * @code{c}
  876. * void vTaskEndScheduler( void );
  877. * @endcode
  878. *
  879. * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
  880. * in place of DOS, implements this function.
  881. *
  882. * Stops the real time kernel tick. All created tasks will be automatically
  883. * deleted and multitasking (either preemptive or cooperative) will
  884. * stop. Execution then resumes from the point where vTaskStartScheduler ()
  885. * was called, as if vTaskStartScheduler () had just returned.
  886. *
  887. * See the demo application file main. c in the demo/PC directory for an
  888. * example that uses vTaskEndScheduler ().
  889. *
  890. * vTaskEndScheduler () requires an exit function to be defined within the
  891. * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  892. * performs hardware specific operations such as stopping the kernel tick.
  893. *
  894. * vTaskEndScheduler () will cause all of the resources allocated by the
  895. * kernel to be freed - but will not free resources allocated by application
  896. * tasks.
  897. *
  898. * Example usage:
  899. * @code{c}
  900. * void vTaskCode( void * pvParameters )
  901. * {
  902. * for( ;; )
  903. * {
  904. * // Task code goes here.
  905. *
  906. * // At some point we want to end the real time kernel processing
  907. * // so call ...
  908. * vTaskEndScheduler ();
  909. * }
  910. * }
  911. *
  912. * void vAFunction( void )
  913. * {
  914. * // Create at least one task before starting the kernel.
  915. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  916. *
  917. * // Start the real time kernel with preemption.
  918. * vTaskStartScheduler ();
  919. *
  920. * // Will only get here when the vTaskCode () task has called
  921. * // vTaskEndScheduler (). When we get here we are back to single task
  922. * // execution.
  923. * }
  924. * @endcode
  925. *
  926. * \defgroup vTaskEndScheduler vTaskEndScheduler
  927. * \ingroup SchedulerControl
  928. */
  929. void vTaskEndScheduler( void );
  930. /**
  931. * task. h
  932. * @code{c}
  933. * void vTaskSuspendAll( void );
  934. * @endcode
  935. *
  936. * Suspends the scheduler without disabling interrupts. Context switches will
  937. * not occur while the scheduler is suspended.
  938. *
  939. * After calling vTaskSuspendAll () the calling task will continue to execute
  940. * without risk of being swapped out until a call to xTaskResumeAll () has been
  941. * made.
  942. *
  943. * API functions that have the potential to cause a context switch (for example,
  944. * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  945. * is suspended.
  946. *
  947. * Example usage:
  948. * @code{c}
  949. * void vTask1( void * pvParameters )
  950. * {
  951. * for( ;; )
  952. * {
  953. * // Task code goes here.
  954. *
  955. * // ...
  956. *
  957. * // At some point the task wants to perform a long operation during
  958. * // which it does not want to get swapped out. It cannot use
  959. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  960. * // operation may cause interrupts to be missed - including the
  961. * // ticks.
  962. *
  963. * // Prevent the real time kernel swapping out the task.
  964. * vTaskSuspendAll ();
  965. *
  966. * // Perform the operation here. There is no need to use critical
  967. * // sections as we have all the microcontroller processing time.
  968. * // During this time interrupts will still operate and the kernel
  969. * // tick count will be maintained.
  970. *
  971. * // ...
  972. *
  973. * // The operation is complete. Restart the kernel.
  974. * xTaskResumeAll ();
  975. * }
  976. * }
  977. * @endcode
  978. * \defgroup vTaskSuspendAll vTaskSuspendAll
  979. * \ingroup SchedulerControl
  980. */
  981. void vTaskSuspendAll( void );
  982. /**
  983. * task. h
  984. * @code{c}
  985. * BaseType_t xTaskResumeAll( void );
  986. * @endcode
  987. *
  988. * Resumes scheduler activity after it was suspended by a call to
  989. * vTaskSuspendAll().
  990. *
  991. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  992. * that were previously suspended by a call to vTaskSuspend().
  993. *
  994. * @return If resuming the scheduler caused a context switch then pdTRUE is
  995. * returned, otherwise pdFALSE is returned.
  996. *
  997. * Example usage:
  998. * @code{c}
  999. * void vTask1( void * pvParameters )
  1000. * {
  1001. * for( ;; )
  1002. * {
  1003. * // Task code goes here.
  1004. *
  1005. * // ...
  1006. *
  1007. * // At some point the task wants to perform a long operation during
  1008. * // which it does not want to get swapped out. It cannot use
  1009. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1010. * // operation may cause interrupts to be missed - including the
  1011. * // ticks.
  1012. *
  1013. * // Prevent the real time kernel swapping out the task.
  1014. * vTaskSuspendAll ();
  1015. *
  1016. * // Perform the operation here. There is no need to use critical
  1017. * // sections as we have all the microcontroller processing time.
  1018. * // During this time interrupts will still operate and the real
  1019. * // time kernel tick count will be maintained.
  1020. *
  1021. * // ...
  1022. *
  1023. * // The operation is complete. Restart the kernel. We want to force
  1024. * // a context switch - but there is no point if resuming the scheduler
  1025. * // caused a context switch already.
  1026. * if( !xTaskResumeAll () )
  1027. * {
  1028. * taskYIELD ();
  1029. * }
  1030. * }
  1031. * }
  1032. * @endcode
  1033. * \defgroup xTaskResumeAll xTaskResumeAll
  1034. * \ingroup SchedulerControl
  1035. */
  1036. BaseType_t xTaskResumeAll( void );
  1037. /*-----------------------------------------------------------
  1038. * TASK UTILITIES
  1039. *----------------------------------------------------------*/
  1040. /**
  1041. * task. h
  1042. * @code{c}
  1043. * TickType_t xTaskGetTickCount( void );
  1044. * @endcode
  1045. *
  1046. * @return The count of ticks since vTaskStartScheduler was called.
  1047. *
  1048. * \defgroup xTaskGetTickCount xTaskGetTickCount
  1049. * \ingroup TaskUtils
  1050. */
  1051. TickType_t xTaskGetTickCount( void );
  1052. /**
  1053. * task. h
  1054. * @code{c}
  1055. * TickType_t xTaskGetTickCountFromISR( void );
  1056. * @endcode
  1057. *
  1058. * @return The count of ticks since vTaskStartScheduler was called.
  1059. *
  1060. * This is a version of xTaskGetTickCount() that is safe to be called from an
  1061. * ISR - provided that TickType_t is the natural word size of the
  1062. * microcontroller being used or interrupt nesting is either not supported or
  1063. * not being used.
  1064. *
  1065. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  1066. * \ingroup TaskUtils
  1067. */
  1068. TickType_t xTaskGetTickCountFromISR( void );
  1069. /**
  1070. * task. h
  1071. * @code{c}
  1072. * uint16_t uxTaskGetNumberOfTasks( void );
  1073. * @endcode
  1074. *
  1075. * @return The number of tasks that the real time kernel is currently managing.
  1076. * This includes all ready, blocked and suspended tasks. A task that
  1077. * has been deleted but not yet freed by the idle task will also be
  1078. * included in the count.
  1079. *
  1080. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  1081. * \ingroup TaskUtils
  1082. */
  1083. UBaseType_t uxTaskGetNumberOfTasks( void );
  1084. /**
  1085. * task. h
  1086. * @code{c}
  1087. * char *pcTaskGetName( TaskHandle_t xTaskToQuery );
  1088. * @endcode
  1089. *
  1090. * @return The text (human readable) name of the task referenced by the handle
  1091. * xTaskToQuery. A task can query its own name by either passing in its own
  1092. * handle, or by setting xTaskToQuery to NULL.
  1093. *
  1094. * \defgroup pcTaskGetName pcTaskGetName
  1095. * \ingroup TaskUtils
  1096. */
  1097. char * pcTaskGetName( TaskHandle_t xTaskToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1098. /**
  1099. * task. h
  1100. * @code{c}
  1101. * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
  1102. * @endcode
  1103. *
  1104. * NOTE: This function takes a relatively long time to complete and should be
  1105. * used sparingly.
  1106. *
  1107. * @return The handle of the task that has the human readable name pcNameToQuery.
  1108. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1109. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1110. *
  1111. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1112. * \ingroup TaskUtils
  1113. */
  1114. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1115. /**
  1116. * task.h
  1117. * @code{c}
  1118. * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  1119. * @endcode
  1120. *
  1121. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1122. * this function to be available.
  1123. *
  1124. * Returns the high water mark of the stack associated with xTask. That is,
  1125. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1126. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1127. * number the closer the task has come to overflowing its stack.
  1128. *
  1129. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1130. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1131. * user to determine the return type. It gets around the problem of the value
  1132. * overflowing on 8-bit types without breaking backward compatibility for
  1133. * applications that expect an 8-bit return type.
  1134. *
  1135. * @param xTask Handle of the task associated with the stack to be checked.
  1136. * Set xTask to NULL to check the stack of the calling task.
  1137. *
  1138. * @return The smallest amount of free stack space there has been (in words, so
  1139. * actual spaces on the stack rather than bytes) since the task referenced by
  1140. * xTask was created.
  1141. */
  1142. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  1143. /**
  1144. * task.h
  1145. * @code{c}
  1146. * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  1147. * @endcode
  1148. *
  1149. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1150. * this function to be available.
  1151. *
  1152. * Returns the high water mark of the stack associated with xTask. That is,
  1153. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1154. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1155. * number the closer the task has come to overflowing its stack.
  1156. *
  1157. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1158. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1159. * user to determine the return type. It gets around the problem of the value
  1160. * overflowing on 8-bit types without breaking backward compatibility for
  1161. * applications that expect an 8-bit return type.
  1162. *
  1163. * @param xTask Handle of the task associated with the stack to be checked.
  1164. * Set xTask to NULL to check the stack of the calling task.
  1165. *
  1166. * @return The smallest amount of free stack space there has been (in words, so
  1167. * actual spaces on the stack rather than bytes) since the task referenced by
  1168. * xTask was created.
  1169. */
  1170. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  1171. /* When using trace macros it is sometimes necessary to include task.h before
  1172. * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1173. * so the following two prototypes will cause a compilation error. This can be
  1174. * fixed by simply guarding against the inclusion of these two prototypes unless
  1175. * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1176. * constant. */
  1177. #ifdef configUSE_APPLICATION_TASK_TAG
  1178. #if configUSE_APPLICATION_TASK_TAG == 1
  1179. /**
  1180. * task.h
  1181. * @code{c}
  1182. * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  1183. * @endcode
  1184. *
  1185. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1186. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1187. * function.
  1188. */
  1189. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  1190. TaskHookFunction_t pxHookFunction );
  1191. /**
  1192. * task.h
  1193. * @code{c}
  1194. * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1195. * @endcode
  1196. *
  1197. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1198. * call from an interrupt service routine - call
  1199. * xTaskGetApplicationTaskTagFromISR() instead.
  1200. */
  1201. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1202. /**
  1203. * task.h
  1204. * @code{c}
  1205. * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1206. * @endcode
  1207. *
  1208. * Returns the pxHookFunction value assigned to the task xTask. Can
  1209. * be called from an interrupt service routine.
  1210. */
  1211. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1212. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1213. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1214. /**
  1215. * task.h
  1216. * @code{c}
  1217. * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  1218. * @endcode
  1219. *
  1220. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1221. * the effect of calling the Running tasks (the calling task) hook function.
  1222. *
  1223. * pvParameter is passed to the hook function for the task to interpret as it
  1224. * wants. The return value is the value returned by the task hook function
  1225. * registered by the user.
  1226. */
  1227. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  1228. void * pvParameter );
  1229. /**
  1230. * xTaskGetIdleTaskHandle() is only available if
  1231. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1232. *
  1233. * Simply returns the handle of the idle task. It is not valid to call
  1234. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1235. */
  1236. TaskHandle_t xTaskGetIdleTaskHandle( void );
  1237. /**
  1238. * task. h
  1239. * @code{c}
  1240. * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
  1241. * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
  1242. * @endcode
  1243. *
  1244. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1245. *
  1246. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1247. * functions to be available.
  1248. *
  1249. * Sends a direct to task notification to a task, with an optional value and
  1250. * action.
  1251. *
  1252. * Each task has a private array of "notification values" (or 'notifications'),
  1253. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1254. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1255. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1256. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1257. *
  1258. * Events can be sent to a task using an intermediary object. Examples of such
  1259. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1260. * are a method of sending an event directly to a task without the need for such
  1261. * an intermediary object.
  1262. *
  1263. * A notification sent to a task can optionally perform an action, such as
  1264. * update, overwrite or increment one of the task's notification values. In
  1265. * that way task notifications can be used to send data to a task, or be used as
  1266. * light weight and fast binary or counting semaphores.
  1267. *
  1268. * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
  1269. * [optionally] block to wait for a notification to be pending. The task does
  1270. * not consume any CPU time while it is in the Blocked state.
  1271. *
  1272. * A notification sent to a task will remain pending until it is cleared by the
  1273. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1274. * un-indexed equivalents). If the task was already in the Blocked state to
  1275. * wait for a notification when the notification arrives then the task will
  1276. * automatically be removed from the Blocked state (unblocked) and the
  1277. * notification cleared.
  1278. *
  1279. * **NOTE** Each notification within the array operates independently - a task
  1280. * can only block on one notification within the array at a time and will not be
  1281. * unblocked by a notification sent to any other array index.
  1282. *
  1283. * Backward compatibility information:
  1284. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1285. * all task notification API functions operated on that value. Replacing the
  1286. * single notification value with an array of notification values necessitated a
  1287. * new set of API functions that could address specific notifications within the
  1288. * array. xTaskNotify() is the original API function, and remains backward
  1289. * compatible by always operating on the notification value at index 0 in the
  1290. * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  1291. * with the uxIndexToNotify parameter set to 0.
  1292. *
  1293. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1294. * task can be returned from the xTaskCreate() API function used to create the
  1295. * task, and the handle of the currently running task can be obtained by calling
  1296. * xTaskGetCurrentTaskHandle().
  1297. *
  1298. * @param uxIndexToNotify The index within the target task's array of
  1299. * notification values to which the notification is to be sent. uxIndexToNotify
  1300. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  1301. * not have this parameter and always sends notifications to index 0.
  1302. *
  1303. * @param ulValue Data that can be sent with the notification. How the data is
  1304. * used depends on the value of the eAction parameter.
  1305. *
  1306. * @param eAction Specifies how the notification updates the task's notification
  1307. * value, if at all. Valid values for eAction are as follows:
  1308. *
  1309. * eSetBits -
  1310. * The target notification value is bitwise ORed with ulValue.
  1311. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1312. *
  1313. * eIncrement -
  1314. * The target notification value is incremented. ulValue is not used and
  1315. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1316. *
  1317. * eSetValueWithOverwrite -
  1318. * The target notification value is set to the value of ulValue, even if the
  1319. * task being notified had not yet processed the previous notification at the
  1320. * same array index (the task already had a notification pending at that index).
  1321. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1322. *
  1323. * eSetValueWithoutOverwrite -
  1324. * If the task being notified did not already have a notification pending at the
  1325. * same array index then the target notification value is set to ulValue and
  1326. * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  1327. * had a notification pending at the same array index then no action is
  1328. * performed and pdFAIL is returned.
  1329. *
  1330. * eNoAction -
  1331. * The task receives a notification at the specified array index without the
  1332. * notification value at that index being updated. ulValue is not used and
  1333. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1334. *
  1335. * pulPreviousNotificationValue -
  1336. * Can be used to pass out the subject task's notification value before any
  1337. * bits are modified by the notify function.
  1338. *
  1339. * @return Dependent on the value of eAction. See the description of the
  1340. * eAction parameter.
  1341. *
  1342. * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  1343. * \ingroup TaskNotifications
  1344. */
  1345. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  1346. UBaseType_t uxIndexToNotify,
  1347. uint32_t ulValue,
  1348. eNotifyAction eAction,
  1349. uint32_t * pulPreviousNotificationValue );
  1350. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  1351. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  1352. #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  1353. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  1354. /**
  1355. * task. h
  1356. * @code{c}
  1357. * BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  1358. * BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  1359. * @endcode
  1360. *
  1361. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1362. *
  1363. * xTaskNotifyAndQueryIndexed() performs the same operation as
  1364. * xTaskNotifyIndexed() with the addition that it also returns the subject
  1365. * task's prior notification value (the notification value at the time the
  1366. * function is called rather than when the function returns) in the additional
  1367. * pulPreviousNotifyValue parameter.
  1368. *
  1369. * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
  1370. * addition that it also returns the subject task's prior notification value
  1371. * (the notification value as it was at the time the function is called, rather
  1372. * than when the function returns) in the additional pulPreviousNotifyValue
  1373. * parameter.
  1374. *
  1375. * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
  1376. * \ingroup TaskNotifications
  1377. */
  1378. #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1379. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1380. #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1381. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1382. /**
  1383. * task. h
  1384. * @code{c}
  1385. * BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  1386. * BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  1387. * @endcode
  1388. *
  1389. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1390. *
  1391. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1392. * functions to be available.
  1393. *
  1394. * A version of xTaskNotifyIndexed() that can be used from an interrupt service
  1395. * routine (ISR).
  1396. *
  1397. * Each task has a private array of "notification values" (or 'notifications'),
  1398. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1399. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1400. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1401. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1402. *
  1403. * Events can be sent to a task using an intermediary object. Examples of such
  1404. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1405. * are a method of sending an event directly to a task without the need for such
  1406. * an intermediary object.
  1407. *
  1408. * A notification sent to a task can optionally perform an action, such as
  1409. * update, overwrite or increment one of the task's notification values. In
  1410. * that way task notifications can be used to send data to a task, or be used as
  1411. * light weight and fast binary or counting semaphores.
  1412. *
  1413. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  1414. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  1415. * to wait for a notification value to have a non-zero value. The task does
  1416. * not consume any CPU time while it is in the Blocked state.
  1417. *
  1418. * A notification sent to a task will remain pending until it is cleared by the
  1419. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1420. * un-indexed equivalents). If the task was already in the Blocked state to
  1421. * wait for a notification when the notification arrives then the task will
  1422. * automatically be removed from the Blocked state (unblocked) and the
  1423. * notification cleared.
  1424. *
  1425. * **NOTE** Each notification within the array operates independently - a task
  1426. * can only block on one notification within the array at a time and will not be
  1427. * unblocked by a notification sent to any other array index.
  1428. *
  1429. * Backward compatibility information:
  1430. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1431. * all task notification API functions operated on that value. Replacing the
  1432. * single notification value with an array of notification values necessitated a
  1433. * new set of API functions that could address specific notifications within the
  1434. * array. xTaskNotifyFromISR() is the original API function, and remains
  1435. * backward compatible by always operating on the notification value at index 0
  1436. * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
  1437. * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  1438. *
  1439. * @param uxIndexToNotify The index within the target task's array of
  1440. * notification values to which the notification is to be sent. uxIndexToNotify
  1441. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
  1442. * does not have this parameter and always sends notifications to index 0.
  1443. *
  1444. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1445. * task can be returned from the xTaskCreate() API function used to create the
  1446. * task, and the handle of the currently running task can be obtained by calling
  1447. * xTaskGetCurrentTaskHandle().
  1448. *
  1449. * @param ulValue Data that can be sent with the notification. How the data is
  1450. * used depends on the value of the eAction parameter.
  1451. *
  1452. * @param eAction Specifies how the notification updates the task's notification
  1453. * value, if at all. Valid values for eAction are as follows:
  1454. *
  1455. * eSetBits -
  1456. * The task's notification value is bitwise ORed with ulValue. xTaskNotify()
  1457. * always returns pdPASS in this case.
  1458. *
  1459. * eIncrement -
  1460. * The task's notification value is incremented. ulValue is not used and
  1461. * xTaskNotify() always returns pdPASS in this case.
  1462. *
  1463. * eSetValueWithOverwrite -
  1464. * The task's notification value is set to the value of ulValue, even if the
  1465. * task being notified had not yet processed the previous notification (the
  1466. * task already had a notification pending). xTaskNotify() always returns
  1467. * pdPASS in this case.
  1468. *
  1469. * eSetValueWithoutOverwrite -
  1470. * If the task being notified did not already have a notification pending then
  1471. * the task's notification value is set to ulValue and xTaskNotify() will
  1472. * return pdPASS. If the task being notified already had a notification
  1473. * pending then no action is performed and pdFAIL is returned.
  1474. *
  1475. * eNoAction -
  1476. * The task receives a notification without its notification value being
  1477. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  1478. * this case.
  1479. *
  1480. * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  1481. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  1482. * task to which the notification was sent to leave the Blocked state, and the
  1483. * unblocked task has a priority higher than the currently running task. If
  1484. * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  1485. * be requested before the interrupt is exited. How a context switch is
  1486. * requested from an ISR is dependent on the port - see the documentation page
  1487. * for the port in use.
  1488. *
  1489. * @return Dependent on the value of eAction. See the description of the
  1490. * eAction parameter.
  1491. *
  1492. * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
  1493. * \ingroup TaskNotifications
  1494. */
  1495. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  1496. UBaseType_t uxIndexToNotify,
  1497. uint32_t ulValue,
  1498. eNotifyAction eAction,
  1499. uint32_t * pulPreviousNotificationValue,
  1500. BaseType_t * pxHigherPriorityTaskWoken );
  1501. #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  1502. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  1503. #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  1504. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  1505. /**
  1506. * task. h
  1507. * @code{c}
  1508. * BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  1509. * BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  1510. * @endcode
  1511. *
  1512. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1513. *
  1514. * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
  1515. * xTaskNotifyIndexedFromISR() with the addition that it also returns the
  1516. * subject task's prior notification value (the notification value at the time
  1517. * the function is called rather than at the time the function returns) in the
  1518. * additional pulPreviousNotifyValue parameter.
  1519. *
  1520. * xTaskNotifyAndQueryFromISR() performs the same operation as
  1521. * xTaskNotifyFromISR() with the addition that it also returns the subject
  1522. * task's prior notification value (the notification value at the time the
  1523. * function is called rather than at the time the function returns) in the
  1524. * additional pulPreviousNotifyValue parameter.
  1525. *
  1526. * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
  1527. * \ingroup TaskNotifications
  1528. */
  1529. #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  1530. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  1531. #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  1532. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  1533. /**
  1534. * task. h
  1535. * @code{c}
  1536. * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  1537. *
  1538. * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  1539. * @endcode
  1540. *
  1541. * Waits for a direct to task notification to be pending at a given index within
  1542. * an array of direct to task notifications.
  1543. *
  1544. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1545. *
  1546. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1547. * function to be available.
  1548. *
  1549. * Each task has a private array of "notification values" (or 'notifications'),
  1550. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1551. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1552. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1553. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1554. *
  1555. * Events can be sent to a task using an intermediary object. Examples of such
  1556. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1557. * are a method of sending an event directly to a task without the need for such
  1558. * an intermediary object.
  1559. *
  1560. * A notification sent to a task can optionally perform an action, such as
  1561. * update, overwrite or increment one of the task's notification values. In
  1562. * that way task notifications can be used to send data to a task, or be used as
  1563. * light weight and fast binary or counting semaphores.
  1564. *
  1565. * A notification sent to a task will remain pending until it is cleared by the
  1566. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1567. * un-indexed equivalents). If the task was already in the Blocked state to
  1568. * wait for a notification when the notification arrives then the task will
  1569. * automatically be removed from the Blocked state (unblocked) and the
  1570. * notification cleared.
  1571. *
  1572. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  1573. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  1574. * to wait for a notification value to have a non-zero value. The task does
  1575. * not consume any CPU time while it is in the Blocked state.
  1576. *
  1577. * **NOTE** Each notification within the array operates independently - a task
  1578. * can only block on one notification within the array at a time and will not be
  1579. * unblocked by a notification sent to any other array index.
  1580. *
  1581. * Backward compatibility information:
  1582. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1583. * all task notification API functions operated on that value. Replacing the
  1584. * single notification value with an array of notification values necessitated a
  1585. * new set of API functions that could address specific notifications within the
  1586. * array. xTaskNotifyWait() is the original API function, and remains backward
  1587. * compatible by always operating on the notification value at index 0 in the
  1588. * array. Calling xTaskNotifyWait() is equivalent to calling
  1589. * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  1590. *
  1591. * @param uxIndexToWaitOn The index within the calling task's array of
  1592. * notification values on which the calling task will wait for a notification to
  1593. * be received. uxIndexToWaitOn must be less than
  1594. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  1595. * not have this parameter and always waits for notifications on index 0.
  1596. *
  1597. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  1598. * will be cleared in the calling task's notification value before the task
  1599. * checks to see if any notifications are pending, and optionally blocks if no
  1600. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  1601. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  1602. * the effect of resetting the task's notification value to 0. Setting
  1603. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  1604. *
  1605. * @param ulBitsToClearOnExit If a notification is pending or received before
  1606. * the calling task exits the xTaskNotifyWait() function then the task's
  1607. * notification value (see the xTaskNotify() API function) is passed out using
  1608. * the pulNotificationValue parameter. Then any bits that are set in
  1609. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  1610. * *pulNotificationValue is set before any bits are cleared). Setting
  1611. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  1612. * (if limits.h is not included) will have the effect of resetting the task's
  1613. * notification value to 0 before the function exits. Setting
  1614. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  1615. * when the function exits (in which case the value passed out in
  1616. * pulNotificationValue will match the task's notification value).
  1617. *
  1618. * @param pulNotificationValue Used to pass the task's notification value out
  1619. * of the function. Note the value passed out will not be effected by the
  1620. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  1621. *
  1622. * @param xTicksToWait The maximum amount of time that the task should wait in
  1623. * the Blocked state for a notification to be received, should a notification
  1624. * not already be pending when xTaskNotifyWait() was called. The task
  1625. * will not consume any processing time while it is in the Blocked state. This
  1626. * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
  1627. * used to convert a time specified in milliseconds to a time specified in
  1628. * ticks.
  1629. *
  1630. * @return If a notification was received (including notifications that were
  1631. * already pending when xTaskNotifyWait was called) then pdPASS is
  1632. * returned. Otherwise pdFAIL is returned.
  1633. *
  1634. * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  1635. * \ingroup TaskNotifications
  1636. */
  1637. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  1638. uint32_t ulBitsToClearOnEntry,
  1639. uint32_t ulBitsToClearOnExit,
  1640. uint32_t * pulNotificationValue,
  1641. TickType_t xTicksToWait );
  1642. #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  1643. xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  1644. #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  1645. xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  1646. /**
  1647. * task. h
  1648. * @code{c}
  1649. * BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );
  1650. * BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
  1651. * @endcode
  1652. *
  1653. * Sends a direct to task notification to a particular index in the target
  1654. * task's notification array in a manner similar to giving a counting semaphore.
  1655. *
  1656. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  1657. *
  1658. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1659. * macros to be available.
  1660. *
  1661. * Each task has a private array of "notification values" (or 'notifications'),
  1662. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1663. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1664. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1665. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1666. *
  1667. * Events can be sent to a task using an intermediary object. Examples of such
  1668. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1669. * are a method of sending an event directly to a task without the need for such
  1670. * an intermediary object.
  1671. *
  1672. * A notification sent to a task can optionally perform an action, such as
  1673. * update, overwrite or increment one of the task's notification values. In
  1674. * that way task notifications can be used to send data to a task, or be used as
  1675. * light weight and fast binary or counting semaphores.
  1676. *
  1677. * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
  1678. * notifications are used as light weight and faster binary or counting
  1679. * semaphore equivalents. Actual FreeRTOS semaphores are given using the
  1680. * xSemaphoreGive() API function, the equivalent action that instead uses a task
  1681. * notification is xTaskNotifyGiveIndexed().
  1682. *
  1683. * When task notifications are being used as a binary or counting semaphore
  1684. * equivalent then the task being notified should wait for the notification
  1685. * using the ulTaskNotificationTakeIndexed() API function rather than the
  1686. * xTaskNotifyWaitIndexed() API function.
  1687. *
  1688. * **NOTE** Each notification within the array operates independently - a task
  1689. * can only block on one notification within the array at a time and will not be
  1690. * unblocked by a notification sent to any other array index.
  1691. *
  1692. * Backward compatibility information:
  1693. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1694. * all task notification API functions operated on that value. Replacing the
  1695. * single notification value with an array of notification values necessitated a
  1696. * new set of API functions that could address specific notifications within the
  1697. * array. xTaskNotifyGive() is the original API function, and remains backward
  1698. * compatible by always operating on the notification value at index 0 in the
  1699. * array. Calling xTaskNotifyGive() is equivalent to calling
  1700. * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
  1701. *
  1702. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1703. * task can be returned from the xTaskCreate() API function used to create the
  1704. * task, and the handle of the currently running task can be obtained by calling
  1705. * xTaskGetCurrentTaskHandle().
  1706. *
  1707. * @param uxIndexToNotify The index within the target task's array of
  1708. * notification values to which the notification is to be sent. uxIndexToNotify
  1709. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
  1710. * does not have this parameter and always sends notifications to index 0.
  1711. *
  1712. * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  1713. * eAction parameter set to eIncrement - so pdPASS is always returned.
  1714. *
  1715. * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
  1716. * \ingroup TaskNotifications
  1717. */
  1718. #define xTaskNotifyGive( xTaskToNotify ) \
  1719. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
  1720. #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
  1721. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
  1722. /**
  1723. * task. h
  1724. * @code{c}
  1725. * void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );
  1726. * void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
  1727. * @endcode
  1728. *
  1729. * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
  1730. * service routine (ISR).
  1731. *
  1732. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  1733. *
  1734. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  1735. * to be available.
  1736. *
  1737. * Each task has a private array of "notification values" (or 'notifications'),
  1738. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1739. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1740. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1741. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1742. *
  1743. * Events can be sent to a task using an intermediary object. Examples of such
  1744. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1745. * are a method of sending an event directly to a task without the need for such
  1746. * an intermediary object.
  1747. *
  1748. * A notification sent to a task can optionally perform an action, such as
  1749. * update, overwrite or increment one of the task's notification values. In
  1750. * that way task notifications can be used to send data to a task, or be used as
  1751. * light weight and fast binary or counting semaphores.
  1752. *
  1753. * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
  1754. * are used as light weight and faster binary or counting semaphore equivalents.
  1755. * Actual FreeRTOS semaphores are given from an ISR using the
  1756. * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  1757. * a task notification is vTaskNotifyGiveIndexedFromISR().
  1758. *
  1759. * When task notifications are being used as a binary or counting semaphore
  1760. * equivalent then the task being notified should wait for the notification
  1761. * using the ulTaskNotificationTakeIndexed() API function rather than the
  1762. * xTaskNotifyWaitIndexed() API function.
  1763. *
  1764. * **NOTE** Each notification within the array operates independently - a task
  1765. * can only block on one notification within the array at a time and will not be
  1766. * unblocked by a notification sent to any other array index.
  1767. *
  1768. * Backward compatibility information:
  1769. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1770. * all task notification API functions operated on that value. Replacing the
  1771. * single notification value with an array of notification values necessitated a
  1772. * new set of API functions that could address specific notifications within the
  1773. * array. xTaskNotifyFromISR() is the original API function, and remains
  1774. * backward compatible by always operating on the notification value at index 0
  1775. * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
  1776. * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  1777. *
  1778. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1779. * task can be returned from the xTaskCreate() API function used to create the
  1780. * task, and the handle of the currently running task can be obtained by calling
  1781. * xTaskGetCurrentTaskHandle().
  1782. *
  1783. * @param uxIndexToNotify The index within the target task's array of
  1784. * notification values to which the notification is to be sent. uxIndexToNotify
  1785. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  1786. * xTaskNotifyGiveFromISR() does not have this parameter and always sends
  1787. * notifications to index 0.
  1788. *
  1789. * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  1790. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  1791. * task to which the notification was sent to leave the Blocked state, and the
  1792. * unblocked task has a priority higher than the currently running task. If
  1793. * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  1794. * should be requested before the interrupt is exited. How a context switch is
  1795. * requested from an ISR is dependent on the port - see the documentation page
  1796. * for the port in use.
  1797. *
  1798. * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
  1799. * \ingroup TaskNotifications
  1800. */
  1801. void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  1802. UBaseType_t uxIndexToNotify,
  1803. BaseType_t * pxHigherPriorityTaskWoken );
  1804. #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
  1805. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
  1806. #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
  1807. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
  1808. /**
  1809. * task. h
  1810. * @code{c}
  1811. * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  1812. *
  1813. * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  1814. * @endcode
  1815. *
  1816. * Waits for a direct to task notification on a particular index in the calling
  1817. * task's notification array in a manner similar to taking a counting semaphore.
  1818. *
  1819. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1820. *
  1821. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1822. * function to be available.
  1823. *
  1824. * Each task has a private array of "notification values" (or 'notifications'),
  1825. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1826. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1827. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1828. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1829. *
  1830. * Events can be sent to a task using an intermediary object. Examples of such
  1831. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1832. * are a method of sending an event directly to a task without the need for such
  1833. * an intermediary object.
  1834. *
  1835. * A notification sent to a task can optionally perform an action, such as
  1836. * update, overwrite or increment one of the task's notification values. In
  1837. * that way task notifications can be used to send data to a task, or be used as
  1838. * light weight and fast binary or counting semaphores.
  1839. *
  1840. * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
  1841. * used as a faster and lighter weight binary or counting semaphore alternative.
  1842. * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
  1843. * the equivalent action that instead uses a task notification is
  1844. * ulTaskNotifyTakeIndexed().
  1845. *
  1846. * When a task is using its notification value as a binary or counting semaphore
  1847. * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
  1848. * macro, or xTaskNotifyIndex() function with the eAction parameter set to
  1849. * eIncrement.
  1850. *
  1851. * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
  1852. * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
  1853. * in which case the notification value acts like a binary semaphore, or
  1854. * decrement the notification value on exit, in which case the notification
  1855. * value acts like a counting semaphore.
  1856. *
  1857. * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
  1858. * a notification. The task does not consume any CPU time while it is in the
  1859. * Blocked state.
  1860. *
  1861. * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
  1862. * ulTaskNotifyTakeIndexed() will return when the task's notification value is
  1863. * not zero.
  1864. *
  1865. * **NOTE** Each notification within the array operates independently - a task
  1866. * can only block on one notification within the array at a time and will not be
  1867. * unblocked by a notification sent to any other array index.
  1868. *
  1869. * Backward compatibility information:
  1870. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1871. * all task notification API functions operated on that value. Replacing the
  1872. * single notification value with an array of notification values necessitated a
  1873. * new set of API functions that could address specific notifications within the
  1874. * array. ulTaskNotifyTake() is the original API function, and remains backward
  1875. * compatible by always operating on the notification value at index 0 in the
  1876. * array. Calling ulTaskNotifyTake() is equivalent to calling
  1877. * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
  1878. *
  1879. * @param uxIndexToWaitOn The index within the calling task's array of
  1880. * notification values on which the calling task will wait for a notification to
  1881. * be non-zero. uxIndexToWaitOn must be less than
  1882. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
  1883. * not have this parameter and always waits for notifications on index 0.
  1884. *
  1885. * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  1886. * notification value is decremented when the function exits. In this way the
  1887. * notification value acts like a counting semaphore. If xClearCountOnExit is
  1888. * not pdFALSE then the task's notification value is cleared to zero when the
  1889. * function exits. In this way the notification value acts like a binary
  1890. * semaphore.
  1891. *
  1892. * @param xTicksToWait The maximum amount of time that the task should wait in
  1893. * the Blocked state for the task's notification value to be greater than zero,
  1894. * should the count not already be greater than zero when
  1895. * ulTaskNotifyTake() was called. The task will not consume any processing
  1896. * time while it is in the Blocked state. This is specified in kernel ticks,
  1897. * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
  1898. * specified in milliseconds to a time specified in ticks.
  1899. *
  1900. * @return The task's notification count before it is either cleared to zero or
  1901. * decremented (see the xClearCountOnExit parameter).
  1902. *
  1903. * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
  1904. * \ingroup TaskNotifications
  1905. */
  1906. uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
  1907. BaseType_t xClearCountOnExit,
  1908. TickType_t xTicksToWait );
  1909. #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
  1910. ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
  1911. #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
  1912. ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
  1913. /**
  1914. * task. h
  1915. * @code{c}
  1916. * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
  1917. *
  1918. * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  1919. * @endcode
  1920. *
  1921. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1922. *
  1923. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1924. * functions to be available.
  1925. *
  1926. * Each task has a private array of "notification values" (or 'notifications'),
  1927. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1928. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1929. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1930. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1931. *
  1932. * If a notification is sent to an index within the array of notifications then
  1933. * the notification at that index is said to be 'pending' until it is read or
  1934. * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
  1935. * is the function that clears a pending notification without reading the
  1936. * notification value. The notification value at the same array index is not
  1937. * altered. Set xTask to NULL to clear the notification state of the calling
  1938. * task.
  1939. *
  1940. * Backward compatibility information:
  1941. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1942. * all task notification API functions operated on that value. Replacing the
  1943. * single notification value with an array of notification values necessitated a
  1944. * new set of API functions that could address specific notifications within the
  1945. * array. xTaskNotifyStateClear() is the original API function, and remains
  1946. * backward compatible by always operating on the notification value at index 0
  1947. * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
  1948. * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
  1949. *
  1950. * @param xTask The handle of the RTOS task that will have a notification state
  1951. * cleared. Set xTask to NULL to clear a notification state in the calling
  1952. * task. To obtain a task's handle create the task using xTaskCreate() and
  1953. * make use of the pxCreatedTask parameter, or create the task using
  1954. * xTaskCreateStatic() and store the returned value, or use the task's name in
  1955. * a call to xTaskGetHandle().
  1956. *
  1957. * @param uxIndexToClear The index within the target task's array of
  1958. * notification values to act upon. For example, setting uxIndexToClear to 1
  1959. * will clear the state of the notification at index 1 within the array.
  1960. * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  1961. * ulTaskNotifyStateClear() does not have this parameter and always acts on the
  1962. * notification at index 0.
  1963. *
  1964. * @return pdTRUE if the task's notification state was set to
  1965. * eNotWaitingNotification, otherwise pdFALSE.
  1966. *
  1967. * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
  1968. * \ingroup TaskNotifications
  1969. */
  1970. BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  1971. UBaseType_t uxIndexToClear );
  1972. #define xTaskNotifyStateClear( xTask ) \
  1973. xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
  1974. #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
  1975. xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
  1976. /**
  1977. * task. h
  1978. * @code{c}
  1979. * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
  1980. *
  1981. * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
  1982. * @endcode
  1983. *
  1984. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1985. *
  1986. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1987. * functions to be available.
  1988. *
  1989. * Each task has a private array of "notification values" (or 'notifications'),
  1990. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1991. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1992. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1993. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1994. *
  1995. * ulTaskNotifyValueClearIndexed() clears the bits specified by the
  1996. * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
  1997. * of the task referenced by xTask.
  1998. *
  1999. * Backward compatibility information:
  2000. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2001. * all task notification API functions operated on that value. Replacing the
  2002. * single notification value with an array of notification values necessitated a
  2003. * new set of API functions that could address specific notifications within the
  2004. * array. ulTaskNotifyValueClear() is the original API function, and remains
  2005. * backward compatible by always operating on the notification value at index 0
  2006. * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
  2007. * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
  2008. *
  2009. * @param xTask The handle of the RTOS task that will have bits in one of its
  2010. * notification values cleared. Set xTask to NULL to clear bits in a
  2011. * notification value of the calling task. To obtain a task's handle create the
  2012. * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
  2013. * create the task using xTaskCreateStatic() and store the returned value, or
  2014. * use the task's name in a call to xTaskGetHandle().
  2015. *
  2016. * @param uxIndexToClear The index within the target task's array of
  2017. * notification values in which to clear the bits. uxIndexToClear
  2018. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2019. * ulTaskNotifyValueClear() does not have this parameter and always clears bits
  2020. * in the notification value at index 0.
  2021. *
  2022. * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
  2023. * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
  2024. * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
  2025. * the notification value to 0. Set ulBitsToClear to 0 to query the task's
  2026. * notification value without clearing any bits.
  2027. *
  2028. *
  2029. * @return The value of the target task's notification value before the bits
  2030. * specified by ulBitsToClear were cleared.
  2031. * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
  2032. * \ingroup TaskNotifications
  2033. */
  2034. uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  2035. UBaseType_t uxIndexToClear,
  2036. uint32_t ulBitsToClear );
  2037. #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
  2038. ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
  2039. #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
  2040. ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
  2041. /**
  2042. * task.h
  2043. * @code{c}
  2044. * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  2045. * @endcode
  2046. *
  2047. * Capture the current time for future use with xTaskCheckForTimeOut().
  2048. *
  2049. * @param pxTimeOut Pointer to a timeout object into which the current time
  2050. * is to be captured. The captured time includes the tick count and the number
  2051. * of times the tick count has overflowed since the system first booted.
  2052. * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
  2053. * \ingroup TaskCtrl
  2054. */
  2055. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  2056. /**
  2057. * task.h
  2058. * @code{c}
  2059. * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
  2060. * @endcode
  2061. *
  2062. * Determines if pxTicksToWait ticks has passed since a time was captured
  2063. * using a call to vTaskSetTimeOutState(). The captured time includes the tick
  2064. * count and the number of times the tick count has overflowed.
  2065. *
  2066. * @param pxTimeOut The time status as captured previously using
  2067. * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
  2068. * to reflect the current time status.
  2069. * @param pxTicksToWait The number of ticks to check for timeout i.e. if
  2070. * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
  2071. * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
  2072. * If the timeout has not occurred, pxTicksToWait is updated to reflect the
  2073. * number of remaining ticks.
  2074. *
  2075. * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
  2076. * returned and pxTicksToWait is updated to reflect the number of remaining
  2077. * ticks.
  2078. *
  2079. * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
  2080. *
  2081. * Example Usage:
  2082. * @code{c}
  2083. * // Driver library function used to receive uxWantedBytes from an Rx buffer
  2084. * // that is filled by a UART interrupt. If there are not enough bytes in the
  2085. * // Rx buffer then the task enters the Blocked state until it is notified that
  2086. * // more data has been placed into the buffer. If there is still not enough
  2087. * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
  2088. * // is used to re-calculate the Block time to ensure the total amount of time
  2089. * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
  2090. * // continues until either the buffer contains at least uxWantedBytes bytes,
  2091. * // or the total amount of time spent in the Blocked state reaches
  2092. * // MAX_TIME_TO_WAIT - at which point the task reads however many bytes are
  2093. * // available up to a maximum of uxWantedBytes.
  2094. *
  2095. * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
  2096. * {
  2097. * size_t uxReceived = 0;
  2098. * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
  2099. * TimeOut_t xTimeOut;
  2100. *
  2101. * // Initialize xTimeOut. This records the time at which this function
  2102. * // was entered.
  2103. * vTaskSetTimeOutState( &xTimeOut );
  2104. *
  2105. * // Loop until the buffer contains the wanted number of bytes, or a
  2106. * // timeout occurs.
  2107. * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
  2108. * {
  2109. * // The buffer didn't contain enough data so this task is going to
  2110. * // enter the Blocked state. Adjusting xTicksToWait to account for
  2111. * // any time that has been spent in the Blocked state within this
  2112. * // function so far to ensure the total amount of time spent in the
  2113. * // Blocked state does not exceed MAX_TIME_TO_WAIT.
  2114. * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
  2115. * {
  2116. * //Timed out before the wanted number of bytes were available,
  2117. * // exit the loop.
  2118. * break;
  2119. * }
  2120. *
  2121. * // Wait for a maximum of xTicksToWait ticks to be notified that the
  2122. * // receive interrupt has placed more data into the buffer.
  2123. * ulTaskNotifyTake( pdTRUE, xTicksToWait );
  2124. * }
  2125. *
  2126. * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
  2127. * // The actual number of bytes read (which might be less than
  2128. * // uxWantedBytes) is returned.
  2129. * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
  2130. * pucBuffer,
  2131. * uxWantedBytes );
  2132. *
  2133. * return uxReceived;
  2134. * }
  2135. * @endcode
  2136. * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
  2137. * \ingroup TaskCtrl
  2138. */
  2139. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  2140. TickType_t * const pxTicksToWait );
  2141. /*-----------------------------------------------------------
  2142. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  2143. *----------------------------------------------------------*/
  2144. /*
  2145. * Return the handle of the calling task.
  2146. */
  2147. TaskHandle_t xTaskGetCurrentTaskHandle( void );
  2148. /*
  2149. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  2150. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  2151. */
  2152. BaseType_t xTaskGetSchedulerState( void );
  2153. /* *INDENT-OFF* */
  2154. #ifdef __cplusplus
  2155. }
  2156. #endif
  2157. /* *INDENT-ON* */
  2158. #endif /* INC_TASK_H */