task.h 94 KB

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