task.h 95 KB

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