task.h 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063
  1. /*
  2. * FreeRTOS Kernel V10.4.4
  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. #include "list.h"
  34. /* *INDENT-OFF* */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* *INDENT-ON* */
  39. /*-----------------------------------------------------------
  40. * MACROS AND DEFINITIONS
  41. *----------------------------------------------------------*/
  42. /*
  43. * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development
  44. * after the numbered release.
  45. *
  46. * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD
  47. * values will reflect the last released version number.
  48. */
  49. #define tskKERNEL_VERSION_NUMBER "V10.4.4"
  50. #define tskKERNEL_VERSION_MAJOR 10
  51. #define tskKERNEL_VERSION_MINOR 4
  52. #define tskKERNEL_VERSION_BUILD 4
  53. /* MPU region parameters passed in ulParameters
  54. * of MemoryRegion_t struct. */
  55. #define tskMPU_REGION_READ_ONLY ( 1UL << 0UL )
  56. #define tskMPU_REGION_READ_WRITE ( 1UL << 1UL )
  57. #define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL )
  58. #define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL )
  59. #define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL )
  60. /* The direct to task notification feature used to have only a single notification
  61. * per task. Now there is an array of notifications per task that is dimensioned by
  62. * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
  63. * original direct to task notification defaults to using the first index in the
  64. * array. */
  65. #define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
  66. /**
  67. * task. h
  68. *
  69. * Type by which tasks are referenced. For example, a call to xTaskCreate
  70. * returns (via a pointer parameter) an TaskHandle_t variable that can then
  71. * be used as a parameter to vTaskDelete to delete the task.
  72. *
  73. * \defgroup TaskHandle_t TaskHandle_t
  74. * \ingroup Tasks
  75. */
  76. struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  77. typedef struct tskTaskControlBlock * TaskHandle_t;
  78. /*
  79. * Defines the prototype to which the application task hook function must
  80. * conform.
  81. */
  82. typedef BaseType_t (* TaskHookFunction_t)( void * );
  83. /* Task states returned by eTaskGetState. */
  84. typedef enum
  85. {
  86. eRunning = 0, /* A task is querying the state of itself, so must be running. */
  87. eReady, /* The task being queried is in a ready or pending ready list. */
  88. eBlocked, /* The task being queried is in the Blocked state. */
  89. eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  90. eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
  91. eInvalid /* Used as an 'invalid state' value. */
  92. } eTaskState;
  93. /* Actions that can be performed when vTaskNotify() is called. */
  94. typedef enum
  95. {
  96. eNoAction = 0, /* Notify the task without updating its notify value. */
  97. eSetBits, /* Set bits in the task's notification value. */
  98. eIncrement, /* Increment the task's notification value. */
  99. eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
  100. eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
  101. } eNotifyAction;
  102. /*
  103. * Used internally only.
  104. */
  105. typedef struct xTIME_OUT
  106. {
  107. BaseType_t xOverflowCount;
  108. TickType_t xTimeOnEntering;
  109. } TimeOut_t;
  110. /*
  111. * Defines the memory ranges allocated to the task when an MPU is used.
  112. */
  113. typedef struct xMEMORY_REGION
  114. {
  115. void * pvBaseAddress;
  116. uint32_t ulLengthInBytes;
  117. uint32_t ulParameters;
  118. } MemoryRegion_t;
  119. /*
  120. * Parameters required to create an MPU protected task.
  121. */
  122. typedef struct xTASK_PARAMETERS
  123. {
  124. TaskFunction_t pvTaskCode;
  125. const char * pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  126. configSTACK_DEPTH_TYPE usStackDepth;
  127. void * pvParameters;
  128. UBaseType_t uxPriority;
  129. StackType_t * puxStackBuffer;
  130. MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
  131. #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  132. StaticTask_t * const pxTaskBuffer;
  133. #endif
  134. } TaskParameters_t;
  135. /* Used with the uxTaskGetSystemState() function to return the state of each task
  136. * in the system. */
  137. typedef struct xTASK_STATUS
  138. {
  139. TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
  140. const char * pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  141. UBaseType_t xTaskNumber; /* A number unique to the task. */
  142. eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
  143. UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
  144. UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
  145. uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
  146. StackType_t * pxStackBase; /* Points to the lowest address of the task's stack area. */
  147. configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
  148. } TaskStatus_t;
  149. /* Possible return values for eTaskConfirmSleepModeStatus(). */
  150. typedef enum
  151. {
  152. eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
  153. eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
  154. eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
  155. } eSleepModeStatus;
  156. /**
  157. * Defines the priority used by the idle task. This must not be modified.
  158. *
  159. * \ingroup TaskUtils
  160. */
  161. #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
  162. /**
  163. * task. h
  164. *
  165. * Macro for forcing a context switch.
  166. *
  167. * \defgroup taskYIELD taskYIELD
  168. * \ingroup SchedulerControl
  169. */
  170. #define taskYIELD() portYIELD()
  171. /**
  172. * task. h
  173. *
  174. * Macro to mark the start of a critical code region. Preemptive context
  175. * switches cannot occur when in a critical region.
  176. *
  177. * NOTE: This may alter the stack (depending on the portable implementation)
  178. * so must be used with care!
  179. *
  180. * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  181. * \ingroup SchedulerControl
  182. */
  183. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  184. #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  185. /**
  186. * task. h
  187. *
  188. * Macro to mark the end of a critical code region. Preemptive context
  189. * switches cannot occur when in a critical region.
  190. *
  191. * NOTE: This may alter the stack (depending on the portable implementation)
  192. * so must be used with care!
  193. *
  194. * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  195. * \ingroup SchedulerControl
  196. */
  197. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  198. #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  199. /**
  200. * task. h
  201. *
  202. * Macro to disable all maskable interrupts.
  203. *
  204. * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  205. * \ingroup SchedulerControl
  206. */
  207. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  208. /**
  209. * task. h
  210. *
  211. * Macro to enable microcontroller interrupts.
  212. *
  213. * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  214. * \ingroup SchedulerControl
  215. */
  216. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  217. /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
  218. * 0 to generate more optimal code when configASSERT() is defined as the constant
  219. * is used in assert() statements. */
  220. #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
  221. #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
  222. #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
  223. /*-----------------------------------------------------------
  224. * TASK CREATION API
  225. *----------------------------------------------------------*/
  226. /**
  227. * task. h
  228. * <pre>
  229. * BaseType_t xTaskCreate(
  230. * TaskFunction_t pxTaskCode,
  231. * const char *pcName,
  232. * configSTACK_DEPTH_TYPE usStackDepth,
  233. * void *pvParameters,
  234. * UBaseType_t uxPriority,
  235. * TaskHandle_t *pxCreatedTask
  236. * );
  237. * </pre>
  238. *
  239. * Create a new task and add it to the list of tasks that are ready to run.
  240. *
  241. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  242. * memory. The first block is used to hold the task's data structures. The
  243. * second block is used by the task as its stack. If a task is created using
  244. * xTaskCreate() then both blocks of memory are automatically dynamically
  245. * allocated inside the xTaskCreate() function. (see
  246. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  247. * xTaskCreateStatic() then the application writer must provide the required
  248. * memory. xTaskCreateStatic() therefore allows a task to be created without
  249. * using any dynamic memory allocation.
  250. *
  251. * See xTaskCreateStatic() for a version that does not use any dynamic memory
  252. * allocation.
  253. *
  254. * xTaskCreate() can only be used to create a task that has unrestricted
  255. * access to the entire microcontroller memory map. Systems that include MPU
  256. * support can alternatively create an MPU constrained task using
  257. * xTaskCreateRestricted().
  258. *
  259. * @param pxTaskCode Pointer to the task entry function. Tasks
  260. * must be implemented to never return (i.e. continuous loop).
  261. *
  262. * @param pcName A descriptive name for the task. This is mainly used to
  263. * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
  264. * is 16.
  265. *
  266. * @param usStackDepth The size of the task stack specified as the number of
  267. * variables the stack can hold - not the number of bytes. For example, if
  268. * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  269. * will be allocated for stack storage.
  270. *
  271. * @param pvParameters Pointer that will be used as the parameter for the task
  272. * being created.
  273. *
  274. * @param uxPriority The priority at which the task should run. Systems that
  275. * include MPU support can optionally create tasks in a privileged (system)
  276. * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  277. * example, to create a privileged task at priority 2 the uxPriority parameter
  278. * should be set to ( 2 | portPRIVILEGE_BIT ).
  279. *
  280. * @param pxCreatedTask Used to pass back a handle by which the created task
  281. * can be referenced.
  282. *
  283. * @return pdPASS if the task was successfully created and added to a ready
  284. * list, otherwise an error code defined in the file projdefs.h
  285. *
  286. * Example usage:
  287. * <pre>
  288. * // Task to be created.
  289. * void vTaskCode( void * pvParameters )
  290. * {
  291. * for( ;; )
  292. * {
  293. * // Task code goes here.
  294. * }
  295. * }
  296. *
  297. * // Function that creates a task.
  298. * void vOtherFunction( void )
  299. * {
  300. * static uint8_t ucParameterToPass;
  301. * TaskHandle_t xHandle = NULL;
  302. *
  303. * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  304. * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  305. * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  306. * // the new task attempts to access it.
  307. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  308. * configASSERT( xHandle );
  309. *
  310. * // Use the handle to delete the task.
  311. * if( xHandle != NULL )
  312. * {
  313. * vTaskDelete( xHandle );
  314. * }
  315. * }
  316. * </pre>
  317. * \defgroup xTaskCreate xTaskCreate
  318. * \ingroup Tasks
  319. */
  320. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  321. BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  322. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  323. const configSTACK_DEPTH_TYPE usStackDepth,
  324. void * const pvParameters,
  325. UBaseType_t uxPriority,
  326. TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
  327. #endif
  328. /**
  329. * task. h
  330. * <pre>
  331. * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  332. * const char *pcName,
  333. * uint32_t ulStackDepth,
  334. * void *pvParameters,
  335. * UBaseType_t uxPriority,
  336. * StackType_t *puxStackBuffer,
  337. * StaticTask_t *pxTaskBuffer );
  338. * </pre>
  339. *
  340. * Create a new task and add it to the list of tasks that are ready to run.
  341. *
  342. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  343. * memory. The first block is used to hold the task's data structures. The
  344. * second block is used by the task as its stack. If a task is created using
  345. * xTaskCreate() then both blocks of memory are automatically dynamically
  346. * allocated inside the xTaskCreate() function. (see
  347. * https://www.FreeRTOS.org/a00111.html). If a task is created using
  348. * xTaskCreateStatic() then the application writer must provide the required
  349. * memory. xTaskCreateStatic() therefore allows a task to be created without
  350. * using any dynamic memory allocation.
  351. *
  352. * @param pxTaskCode Pointer to the task entry function. Tasks
  353. * must be implemented to never return (i.e. continuous loop).
  354. *
  355. * @param pcName A descriptive name for the task. This is mainly used to
  356. * facilitate debugging. The maximum length of the string is defined by
  357. * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  358. *
  359. * @param ulStackDepth The size of the task stack specified as the number of
  360. * variables the stack can hold - not the number of bytes. For example, if
  361. * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
  362. * will be allocated for stack storage.
  363. *
  364. * @param pvParameters Pointer that will be used as the parameter for the task
  365. * being created.
  366. *
  367. * @param uxPriority The priority at which the task will run.
  368. *
  369. * @param puxStackBuffer Must point to a StackType_t array that has at least
  370. * ulStackDepth indexes - the array will then be used as the task's stack,
  371. * removing the need for the stack to be allocated dynamically.
  372. *
  373. * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
  374. * then be used to hold the task's data structures, removing the need for the
  375. * memory to be allocated dynamically.
  376. *
  377. * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
  378. * will be created and a handle to the created task is returned. If either
  379. * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
  380. * NULL is returned.
  381. *
  382. * Example usage:
  383. * <pre>
  384. *
  385. * // Dimensions of the buffer that the task being created will use as its stack.
  386. * // NOTE: This is the number of words the stack will hold, not the number of
  387. * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
  388. * // then 400 bytes (100 * 32-bits) will be allocated.
  389. #define STACK_SIZE 200
  390. *
  391. * // Structure that will hold the TCB of the task being created.
  392. * StaticTask_t xTaskBuffer;
  393. *
  394. * // Buffer that the task being created will use as its stack. Note this is
  395. * // an array of StackType_t variables. The size of StackType_t is dependent on
  396. * // the RTOS port.
  397. * StackType_t xStack[ STACK_SIZE ];
  398. *
  399. * // Function that implements the task being created.
  400. * void vTaskCode( void * pvParameters )
  401. * {
  402. * // The parameter value is expected to be 1 as 1 is passed in the
  403. * // pvParameters value in the call to xTaskCreateStatic().
  404. * configASSERT( ( uint32_t ) pvParameters == 1UL );
  405. *
  406. * for( ;; )
  407. * {
  408. * // Task code goes here.
  409. * }
  410. * }
  411. *
  412. * // Function that creates a task.
  413. * void vOtherFunction( void )
  414. * {
  415. * TaskHandle_t xHandle = NULL;
  416. *
  417. * // Create the task without using any dynamic memory allocation.
  418. * xHandle = xTaskCreateStatic(
  419. * vTaskCode, // Function that implements the task.
  420. * "NAME", // Text name for the task.
  421. * STACK_SIZE, // Stack size in words, not bytes.
  422. * ( void * ) 1, // Parameter passed into the task.
  423. * tskIDLE_PRIORITY,// Priority at which the task is created.
  424. * xStack, // Array to use as the task's stack.
  425. * &xTaskBuffer ); // Variable to hold the task's data structure.
  426. *
  427. * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
  428. * // been created, and xHandle will be the task's handle. Use the handle
  429. * // to suspend the task.
  430. * vTaskSuspend( xHandle );
  431. * }
  432. * </pre>
  433. * \defgroup xTaskCreateStatic xTaskCreateStatic
  434. * \ingroup Tasks
  435. */
  436. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  437. TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  438. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  439. const uint32_t ulStackDepth,
  440. void * const pvParameters,
  441. UBaseType_t uxPriority,
  442. StackType_t * const puxStackBuffer,
  443. StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
  444. #endif /* configSUPPORT_STATIC_ALLOCATION */
  445. /**
  446. * task. h
  447. * <pre>
  448. * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
  449. * </pre>
  450. *
  451. * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
  452. *
  453. * xTaskCreateRestricted() should only be used in systems that include an MPU
  454. * implementation.
  455. *
  456. * Create a new task and add it to the list of tasks that are ready to run.
  457. * The function parameters define the memory regions and associated access
  458. * permissions allocated to the task.
  459. *
  460. * See xTaskCreateRestrictedStatic() for a version that does not use any
  461. * dynamic memory allocation.
  462. *
  463. * @param pxTaskDefinition Pointer to a structure that contains a member
  464. * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
  465. * documentation) plus an optional stack buffer and the memory region
  466. * definitions.
  467. *
  468. * @param pxCreatedTask Used to pass back a handle by which the created task
  469. * can be referenced.
  470. *
  471. * @return pdPASS if the task was successfully created and added to a ready
  472. * list, otherwise an error code defined in the file projdefs.h
  473. *
  474. * Example usage:
  475. * <pre>
  476. * // Create an TaskParameters_t structure that defines the task to be created.
  477. * static const TaskParameters_t xCheckTaskParameters =
  478. * {
  479. * vATask, // pvTaskCode - the function that implements the task.
  480. * "ATask", // pcName - just a text name for the task to assist debugging.
  481. * 100, // usStackDepth - the stack size DEFINED IN WORDS.
  482. * NULL, // pvParameters - passed into the task function as the function parameters.
  483. * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
  484. * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
  485. *
  486. * // xRegions - Allocate up to three separate memory regions for access by
  487. * // the task, with appropriate access permissions. Different processors have
  488. * // different memory alignment requirements - refer to the FreeRTOS documentation
  489. * // for full information.
  490. * {
  491. * // Base address Length Parameters
  492. * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
  493. * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
  494. * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
  495. * }
  496. * };
  497. *
  498. * int main( void )
  499. * {
  500. * TaskHandle_t xHandle;
  501. *
  502. * // Create a task from the const structure defined above. The task handle
  503. * // is requested (the second parameter is not NULL) but in this case just for
  504. * // demonstration purposes as its not actually used.
  505. * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
  506. *
  507. * // Start the scheduler.
  508. * vTaskStartScheduler();
  509. *
  510. * // Will only get here if there was insufficient memory to create the idle
  511. * // and/or timer task.
  512. * for( ;; );
  513. * }
  514. * </pre>
  515. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  516. * \ingroup Tasks
  517. */
  518. #if ( portUSING_MPU_WRAPPERS == 1 )
  519. BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition,
  520. TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
  521. #endif
  522. /**
  523. * task. h
  524. * <pre>
  525. * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
  526. * </pre>
  527. *
  528. * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
  529. *
  530. * xTaskCreateRestrictedStatic() should only be used in systems that include an
  531. * MPU implementation.
  532. *
  533. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  534. * memory. The first block is used to hold the task's data structures. The
  535. * second block is used by the task as its stack. If a task is created using
  536. * xTaskCreateRestricted() then the stack is provided by the application writer,
  537. * and the memory used to hold the task's data structure is automatically
  538. * dynamically allocated inside the xTaskCreateRestricted() function. If a task
  539. * is created using xTaskCreateRestrictedStatic() then the application writer
  540. * must provide the memory used to hold the task's data structures too.
  541. * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
  542. * created without using any dynamic memory allocation.
  543. *
  544. * @param pxTaskDefinition Pointer to a structure that contains a member
  545. * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
  546. * documentation) plus an optional stack buffer and the memory region
  547. * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
  548. * contains an additional member, which is used to point to a variable of type
  549. * StaticTask_t - which is then used to hold the task's data structure.
  550. *
  551. * @param pxCreatedTask Used to pass back a handle by which the created task
  552. * can be referenced.
  553. *
  554. * @return pdPASS if the task was successfully created and added to a ready
  555. * list, otherwise an error code defined in the file projdefs.h
  556. *
  557. * Example usage:
  558. * <pre>
  559. * // Create an TaskParameters_t structure that defines the task to be created.
  560. * // The StaticTask_t variable is only included in the structure when
  561. * // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
  562. * // be used to force the variable into the RTOS kernel's privileged data area.
  563. * static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
  564. * static const TaskParameters_t xCheckTaskParameters =
  565. * {
  566. * vATask, // pvTaskCode - the function that implements the task.
  567. * "ATask", // pcName - just a text name for the task to assist debugging.
  568. * 100, // usStackDepth - the stack size DEFINED IN WORDS.
  569. * NULL, // pvParameters - passed into the task function as the function parameters.
  570. * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
  571. * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
  572. *
  573. * // xRegions - Allocate up to three separate memory regions for access by
  574. * // the task, with appropriate access permissions. Different processors have
  575. * // different memory alignment requirements - refer to the FreeRTOS documentation
  576. * // for full information.
  577. * {
  578. * // Base address Length Parameters
  579. * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
  580. * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
  581. * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
  582. * }
  583. *
  584. * &xTaskBuffer; // Holds the task's data structure.
  585. * };
  586. *
  587. * int main( void )
  588. * {
  589. * TaskHandle_t xHandle;
  590. *
  591. * // Create a task from the const structure defined above. The task handle
  592. * // is requested (the second parameter is not NULL) but in this case just for
  593. * // demonstration purposes as its not actually used.
  594. * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
  595. *
  596. * // Start the scheduler.
  597. * vTaskStartScheduler();
  598. *
  599. * // Will only get here if there was insufficient memory to create the idle
  600. * // and/or timer task.
  601. * for( ;; );
  602. * }
  603. * </pre>
  604. * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
  605. * \ingroup Tasks
  606. */
  607. #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  608. BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition,
  609. TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
  610. #endif
  611. /**
  612. * task. h
  613. * <pre>
  614. * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
  615. * </pre>
  616. *
  617. * Memory regions are assigned to a restricted task when the task is created by
  618. * a call to xTaskCreateRestricted(). These regions can be redefined using
  619. * vTaskAllocateMPURegions().
  620. *
  621. * @param xTask The handle of the task being updated.
  622. *
  623. * @param xRegions A pointer to a MemoryRegion_t structure that contains the
  624. * new memory region definitions.
  625. *
  626. * Example usage:
  627. * <pre>
  628. * // Define an array of MemoryRegion_t structures that configures an MPU region
  629. * // allowing read/write access for 1024 bytes starting at the beginning of the
  630. * // ucOneKByte array. The other two of the maximum 3 definable regions are
  631. * // unused so set to zero.
  632. * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
  633. * {
  634. * // Base address Length Parameters
  635. * { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
  636. * { 0, 0, 0 },
  637. * { 0, 0, 0 }
  638. * };
  639. *
  640. * void vATask( void *pvParameters )
  641. * {
  642. * // This task was created such that it has access to certain regions of
  643. * // memory as defined by the MPU configuration. At some point it is
  644. * // desired that these MPU regions are replaced with that defined in the
  645. * // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
  646. * // for this purpose. NULL is used as the task handle to indicate that this
  647. * // function should modify the MPU regions of the calling task.
  648. * vTaskAllocateMPURegions( NULL, xAltRegions );
  649. *
  650. * // Now the task can continue its function, but from this point on can only
  651. * // access its stack and the ucOneKByte array (unless any other statically
  652. * // defined or shared regions have been declared elsewhere).
  653. * }
  654. * </pre>
  655. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  656. * \ingroup Tasks
  657. */
  658. void vTaskAllocateMPURegions( TaskHandle_t xTask,
  659. const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
  660. /**
  661. * task. h
  662. * <pre>
  663. * void vTaskDelete( TaskHandle_t xTaskToDelete );
  664. * </pre>
  665. *
  666. * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  667. * See the configuration section for more information.
  668. *
  669. * Remove a task from the RTOS real time kernel's management. The task being
  670. * deleted will be removed from all ready, blocked, suspended and event lists.
  671. *
  672. * NOTE: The idle task is responsible for freeing the kernel allocated
  673. * memory from tasks that have been deleted. It is therefore important that
  674. * the idle task is not starved of microcontroller processing time if your
  675. * application makes any calls to vTaskDelete (). Memory allocated by the
  676. * task code is not automatically freed, and should be freed before the task
  677. * is deleted.
  678. *
  679. * See the demo application file death.c for sample code that utilises
  680. * vTaskDelete ().
  681. *
  682. * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
  683. * cause the calling task to be deleted.
  684. *
  685. * Example usage:
  686. * <pre>
  687. * void vOtherFunction( void )
  688. * {
  689. * TaskHandle_t xHandle;
  690. *
  691. * // Create the task, storing the handle.
  692. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  693. *
  694. * // Use the handle to delete the task.
  695. * vTaskDelete( xHandle );
  696. * }
  697. * </pre>
  698. * \defgroup vTaskDelete vTaskDelete
  699. * \ingroup Tasks
  700. */
  701. void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
  702. /*-----------------------------------------------------------
  703. * TASK CONTROL API
  704. *----------------------------------------------------------*/
  705. /**
  706. * task. h
  707. * <pre>
  708. * void vTaskDelay( const TickType_t xTicksToDelay );
  709. * </pre>
  710. *
  711. * Delay a task for a given number of ticks. The actual time that the
  712. * task remains blocked depends on the tick rate. The constant
  713. * portTICK_PERIOD_MS can be used to calculate real time from the tick
  714. * rate - with the resolution of one tick period.
  715. *
  716. * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  717. * See the configuration section for more information.
  718. *
  719. *
  720. * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  721. * the time at which vTaskDelay() is called. For example, specifying a block
  722. * period of 100 ticks will cause the task to unblock 100 ticks after
  723. * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  724. * of controlling the frequency of a periodic task as the path taken through the
  725. * code, as well as other task and interrupt activity, will effect the frequency
  726. * at which vTaskDelay() gets called and therefore the time at which the task
  727. * next executes. See xTaskDelayUntil() for an alternative API function designed
  728. * to facilitate fixed frequency execution. It does this by specifying an
  729. * absolute time (rather than a relative time) at which the calling task should
  730. * unblock.
  731. *
  732. * @param xTicksToDelay The amount of time, in tick periods, that
  733. * the calling task should block.
  734. *
  735. * Example usage:
  736. *
  737. * void vTaskFunction( void * pvParameters )
  738. * {
  739. * // Block for 500ms.
  740. * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
  741. *
  742. * for( ;; )
  743. * {
  744. * // Simply toggle the LED every 500ms, blocking between each toggle.
  745. * vToggleLED();
  746. * vTaskDelay( xDelay );
  747. * }
  748. * }
  749. *
  750. * \defgroup vTaskDelay vTaskDelay
  751. * \ingroup TaskCtrl
  752. */
  753. void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
  754. /**
  755. * task. h
  756. * <pre>
  757. * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  758. * </pre>
  759. *
  760. * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
  761. * See the configuration section for more information.
  762. *
  763. * Delay a task until a specified time. This function can be used by periodic
  764. * tasks to ensure a constant execution frequency.
  765. *
  766. * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  767. * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  768. * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  769. * execution frequency as the time between a task starting to execute and that task
  770. * calling vTaskDelay () may not be fixed [the task may take a different path though the
  771. * code between calls, or may get interrupted or preempted a different number of times
  772. * each time it executes].
  773. *
  774. * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  775. * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  776. * unblock.
  777. *
  778. * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
  779. * time specified in milliseconds with a resolution of one tick period.
  780. *
  781. * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  782. * task was last unblocked. The variable must be initialised with the current time
  783. * prior to its first use (see the example below). Following this the variable is
  784. * automatically updated within xTaskDelayUntil ().
  785. *
  786. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  787. * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
  788. * same xTimeIncrement parameter value will cause the task to execute with
  789. * a fixed interface period.
  790. *
  791. * @return Value which can be used to check whether the task was actually delayed.
  792. * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
  793. * be delayed if the next expected wake time is in the past.
  794. *
  795. * Example usage:
  796. * <pre>
  797. * // Perform an action every 10 ticks.
  798. * void vTaskFunction( void * pvParameters )
  799. * {
  800. * TickType_t xLastWakeTime;
  801. * const TickType_t xFrequency = 10;
  802. * BaseType_t xWasDelayed;
  803. *
  804. * // Initialise the xLastWakeTime variable with the current time.
  805. * xLastWakeTime = xTaskGetTickCount ();
  806. * for( ;; )
  807. * {
  808. * // Wait for the next cycle.
  809. * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  810. *
  811. * // Perform action here. xWasDelayed value can be used to determine
  812. * // whether a deadline was missed if the code here took too long.
  813. * }
  814. * }
  815. * </pre>
  816. * \defgroup xTaskDelayUntil xTaskDelayUntil
  817. * \ingroup TaskCtrl
  818. */
  819. BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  820. const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
  821. /*
  822. * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
  823. * return a value.
  824. */
  825. #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
  826. { \
  827. ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
  828. }
  829. /**
  830. * task. h
  831. * <pre>
  832. * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  833. * </pre>
  834. *
  835. * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  836. * function to be available.
  837. *
  838. * A task will enter the Blocked state when it is waiting for an event. The
  839. * event it is waiting for can be a temporal event (waiting for a time), such
  840. * as when vTaskDelay() is called, or an event on an object, such as when
  841. * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  842. * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  843. * task will leave the Blocked state, and return from whichever function call
  844. * placed the task into the Blocked state.
  845. *
  846. * There is no 'FromISR' version of this function as an interrupt would need to
  847. * know which object a task was blocked on in order to know which actions to
  848. * take. For example, if the task was blocked on a queue the interrupt handler
  849. * would then need to know if the queue was locked.
  850. *
  851. * @param xTask The handle of the task to remove from the Blocked state.
  852. *
  853. * @return If the task referenced by xTask was not in the Blocked state then
  854. * pdFAIL is returned. Otherwise pdPASS is returned.
  855. *
  856. * \defgroup xTaskAbortDelay xTaskAbortDelay
  857. * \ingroup TaskCtrl
  858. */
  859. BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  860. /**
  861. * task. h
  862. * <pre>
  863. * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  864. * </pre>
  865. *
  866. * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  867. * See the configuration section for more information.
  868. *
  869. * Obtain the priority of any task.
  870. *
  871. * @param xTask Handle of the task to be queried. Passing a NULL
  872. * handle results in the priority of the calling task being returned.
  873. *
  874. * @return The priority of xTask.
  875. *
  876. * Example usage:
  877. * <pre>
  878. * void vAFunction( void )
  879. * {
  880. * TaskHandle_t xHandle;
  881. *
  882. * // Create a task, storing the handle.
  883. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  884. *
  885. * // ...
  886. *
  887. * // Use the handle to obtain the priority of the created task.
  888. * // It was created with tskIDLE_PRIORITY, but may have changed
  889. * // it itself.
  890. * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  891. * {
  892. * // The task has changed it's priority.
  893. * }
  894. *
  895. * // ...
  896. *
  897. * // Is our priority higher than the created task?
  898. * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  899. * {
  900. * // Our priority (obtained using NULL handle) is higher.
  901. * }
  902. * }
  903. * </pre>
  904. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  905. * \ingroup TaskCtrl
  906. */
  907. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  908. /**
  909. * task. h
  910. * <pre>
  911. * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  912. * </pre>
  913. *
  914. * A version of uxTaskPriorityGet() that can be used from an ISR.
  915. */
  916. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  917. /**
  918. * task. h
  919. * <pre>
  920. * eTaskState eTaskGetState( TaskHandle_t xTask );
  921. * </pre>
  922. *
  923. * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  924. * See the configuration section for more information.
  925. *
  926. * Obtain the state of any task. States are encoded by the eTaskState
  927. * enumerated type.
  928. *
  929. * @param xTask Handle of the task to be queried.
  930. *
  931. * @return The state of xTask at the time the function was called. Note the
  932. * state of the task might change between the function being called, and the
  933. * functions return value being tested by the calling task.
  934. */
  935. eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  936. /**
  937. * task. h
  938. * <pre>
  939. * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
  940. * </pre>
  941. *
  942. * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
  943. * available. See the configuration section for more information.
  944. *
  945. * Populates a TaskStatus_t structure with information about a task.
  946. *
  947. * @param xTask Handle of the task being queried. If xTask is NULL then
  948. * information will be returned about the calling task.
  949. *
  950. * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
  951. * filled with information about the task referenced by the handle passed using
  952. * the xTask parameter.
  953. *
  954. * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
  955. * the stack high water mark of the task being queried. Calculating the stack
  956. * high water mark takes a relatively long time, and can make the system
  957. * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
  958. * allow the high water mark checking to be skipped. The high watermark value
  959. * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
  960. * not set to pdFALSE;
  961. *
  962. * @param eState The TaskStatus_t structure contains a member to report the
  963. * state of the task being queried. Obtaining the task state is not as fast as
  964. * a simple assignment - so the eState parameter is provided to allow the state
  965. * information to be omitted from the TaskStatus_t structure. To obtain state
  966. * information then set eState to eInvalid - otherwise the value passed in
  967. * eState will be reported as the task state in the TaskStatus_t structure.
  968. *
  969. * Example usage:
  970. * <pre>
  971. * void vAFunction( void )
  972. * {
  973. * TaskHandle_t xHandle;
  974. * TaskStatus_t xTaskDetails;
  975. *
  976. * // Obtain the handle of a task from its name.
  977. * xHandle = xTaskGetHandle( "Task_Name" );
  978. *
  979. * // Check the handle is not NULL.
  980. * configASSERT( xHandle );
  981. *
  982. * // Use the handle to obtain further information about the task.
  983. * vTaskGetInfo( xHandle,
  984. * &xTaskDetails,
  985. * pdTRUE, // Include the high water mark in xTaskDetails.
  986. * eInvalid ); // Include the task state in xTaskDetails.
  987. * }
  988. * </pre>
  989. * \defgroup vTaskGetInfo vTaskGetInfo
  990. * \ingroup TaskCtrl
  991. */
  992. void vTaskGetInfo( TaskHandle_t xTask,
  993. TaskStatus_t * pxTaskStatus,
  994. BaseType_t xGetFreeStackSpace,
  995. eTaskState eState ) PRIVILEGED_FUNCTION;
  996. /**
  997. * task. h
  998. * <pre>
  999. * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  1000. * </pre>
  1001. *
  1002. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  1003. * See the configuration section for more information.
  1004. *
  1005. * Set the priority of any task.
  1006. *
  1007. * A context switch will occur before the function returns if the priority
  1008. * being set is higher than the currently executing task.
  1009. *
  1010. * @param xTask Handle to the task for which the priority is being set.
  1011. * Passing a NULL handle results in the priority of the calling task being set.
  1012. *
  1013. * @param uxNewPriority The priority to which the task will be set.
  1014. *
  1015. * Example usage:
  1016. * <pre>
  1017. * void vAFunction( void )
  1018. * {
  1019. * TaskHandle_t xHandle;
  1020. *
  1021. * // Create a task, storing the handle.
  1022. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1023. *
  1024. * // ...
  1025. *
  1026. * // Use the handle to raise the priority of the created task.
  1027. * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  1028. *
  1029. * // ...
  1030. *
  1031. * // Use a NULL handle to raise our priority to the same value.
  1032. * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  1033. * }
  1034. * </pre>
  1035. * \defgroup vTaskPrioritySet vTaskPrioritySet
  1036. * \ingroup TaskCtrl
  1037. */
  1038. void vTaskPrioritySet( TaskHandle_t xTask,
  1039. UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
  1040. /**
  1041. * task. h
  1042. * <pre>
  1043. * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  1044. * </pre>
  1045. *
  1046. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  1047. * See the configuration section for more information.
  1048. *
  1049. * Suspend any task. When suspended a task will never get any microcontroller
  1050. * processing time, no matter what its priority.
  1051. *
  1052. * Calls to vTaskSuspend are not accumulative -
  1053. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  1054. * call to vTaskResume () to ready the suspended task.
  1055. *
  1056. * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  1057. * handle will cause the calling task to be suspended.
  1058. *
  1059. * Example usage:
  1060. * <pre>
  1061. * void vAFunction( void )
  1062. * {
  1063. * TaskHandle_t xHandle;
  1064. *
  1065. * // Create a task, storing the handle.
  1066. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1067. *
  1068. * // ...
  1069. *
  1070. * // Use the handle to suspend the created task.
  1071. * vTaskSuspend( xHandle );
  1072. *
  1073. * // ...
  1074. *
  1075. * // The created task will not run during this period, unless
  1076. * // another task calls vTaskResume( xHandle ).
  1077. *
  1078. * //...
  1079. *
  1080. *
  1081. * // Suspend ourselves.
  1082. * vTaskSuspend( NULL );
  1083. *
  1084. * // We cannot get here unless another task calls vTaskResume
  1085. * // with our handle as the parameter.
  1086. * }
  1087. * </pre>
  1088. * \defgroup vTaskSuspend vTaskSuspend
  1089. * \ingroup TaskCtrl
  1090. */
  1091. void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
  1092. /**
  1093. * task. h
  1094. * <pre>
  1095. * void vTaskResume( TaskHandle_t xTaskToResume );
  1096. * </pre>
  1097. *
  1098. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  1099. * See the configuration section for more information.
  1100. *
  1101. * Resumes a suspended task.
  1102. *
  1103. * A task that has been suspended by one or more calls to vTaskSuspend ()
  1104. * will be made available for running again by a single call to
  1105. * vTaskResume ().
  1106. *
  1107. * @param xTaskToResume Handle to the task being readied.
  1108. *
  1109. * Example usage:
  1110. * <pre>
  1111. * void vAFunction( void )
  1112. * {
  1113. * TaskHandle_t xHandle;
  1114. *
  1115. * // Create a task, storing the handle.
  1116. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1117. *
  1118. * // ...
  1119. *
  1120. * // Use the handle to suspend the created task.
  1121. * vTaskSuspend( xHandle );
  1122. *
  1123. * // ...
  1124. *
  1125. * // The created task will not run during this period, unless
  1126. * // another task calls vTaskResume( xHandle ).
  1127. *
  1128. * //...
  1129. *
  1130. *
  1131. * // Resume the suspended task ourselves.
  1132. * vTaskResume( xHandle );
  1133. *
  1134. * // The created task will once again get microcontroller processing
  1135. * // time in accordance with its priority within the system.
  1136. * }
  1137. * </pre>
  1138. * \defgroup vTaskResume vTaskResume
  1139. * \ingroup TaskCtrl
  1140. */
  1141. void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1142. /**
  1143. * task. h
  1144. * <pre>
  1145. * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  1146. * </pre>
  1147. *
  1148. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  1149. * available. See the configuration section for more information.
  1150. *
  1151. * An implementation of vTaskResume() that can be called from within an ISR.
  1152. *
  1153. * A task that has been suspended by one or more calls to vTaskSuspend ()
  1154. * will be made available for running again by a single call to
  1155. * xTaskResumeFromISR ().
  1156. *
  1157. * xTaskResumeFromISR() should not be used to synchronise a task with an
  1158. * interrupt if there is a chance that the interrupt could arrive prior to the
  1159. * task being suspended - as this can lead to interrupts being missed. Use of a
  1160. * semaphore as a synchronisation mechanism would avoid this eventuality.
  1161. *
  1162. * @param xTaskToResume Handle to the task being readied.
  1163. *
  1164. * @return pdTRUE if resuming the task should result in a context switch,
  1165. * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  1166. * may be required following the ISR.
  1167. *
  1168. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  1169. * \ingroup TaskCtrl
  1170. */
  1171. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1172. /*-----------------------------------------------------------
  1173. * SCHEDULER CONTROL
  1174. *----------------------------------------------------------*/
  1175. /**
  1176. * task. h
  1177. * <pre>
  1178. * void vTaskStartScheduler( void );
  1179. * </pre>
  1180. *
  1181. * Starts the real time kernel tick processing. After calling the kernel
  1182. * has control over which tasks are executed and when.
  1183. *
  1184. * See the demo application file main.c for an example of creating
  1185. * tasks and starting the kernel.
  1186. *
  1187. * Example usage:
  1188. * <pre>
  1189. * void vAFunction( void )
  1190. * {
  1191. * // Create at least one task before starting the kernel.
  1192. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1193. *
  1194. * // Start the real time kernel with preemption.
  1195. * vTaskStartScheduler ();
  1196. *
  1197. * // Will not get here unless a task calls vTaskEndScheduler ()
  1198. * }
  1199. * </pre>
  1200. *
  1201. * \defgroup vTaskStartScheduler vTaskStartScheduler
  1202. * \ingroup SchedulerControl
  1203. */
  1204. void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
  1205. /**
  1206. * task. h
  1207. * <pre>
  1208. * void vTaskEndScheduler( void );
  1209. * </pre>
  1210. *
  1211. * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
  1212. * in place of DOS, implements this function.
  1213. *
  1214. * Stops the real time kernel tick. All created tasks will be automatically
  1215. * deleted and multitasking (either preemptive or cooperative) will
  1216. * stop. Execution then resumes from the point where vTaskStartScheduler ()
  1217. * was called, as if vTaskStartScheduler () had just returned.
  1218. *
  1219. * See the demo application file main. c in the demo/PC directory for an
  1220. * example that uses vTaskEndScheduler ().
  1221. *
  1222. * vTaskEndScheduler () requires an exit function to be defined within the
  1223. * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  1224. * performs hardware specific operations such as stopping the kernel tick.
  1225. *
  1226. * vTaskEndScheduler () will cause all of the resources allocated by the
  1227. * kernel to be freed - but will not free resources allocated by application
  1228. * tasks.
  1229. *
  1230. * Example usage:
  1231. * <pre>
  1232. * void vTaskCode( void * pvParameters )
  1233. * {
  1234. * for( ;; )
  1235. * {
  1236. * // Task code goes here.
  1237. *
  1238. * // At some point we want to end the real time kernel processing
  1239. * // so call ...
  1240. * vTaskEndScheduler ();
  1241. * }
  1242. * }
  1243. *
  1244. * void vAFunction( void )
  1245. * {
  1246. * // Create at least one task before starting the kernel.
  1247. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1248. *
  1249. * // Start the real time kernel with preemption.
  1250. * vTaskStartScheduler ();
  1251. *
  1252. * // Will only get here when the vTaskCode () task has called
  1253. * // vTaskEndScheduler (). When we get here we are back to single task
  1254. * // execution.
  1255. * }
  1256. * </pre>
  1257. *
  1258. * \defgroup vTaskEndScheduler vTaskEndScheduler
  1259. * \ingroup SchedulerControl
  1260. */
  1261. void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
  1262. /**
  1263. * task. h
  1264. * <pre>
  1265. * void vTaskSuspendAll( void );
  1266. * </pre>
  1267. *
  1268. * Suspends the scheduler without disabling interrupts. Context switches will
  1269. * not occur while the scheduler is suspended.
  1270. *
  1271. * After calling vTaskSuspendAll () the calling task will continue to execute
  1272. * without risk of being swapped out until a call to xTaskResumeAll () has been
  1273. * made.
  1274. *
  1275. * API functions that have the potential to cause a context switch (for example,
  1276. * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  1277. * is suspended.
  1278. *
  1279. * Example usage:
  1280. * <pre>
  1281. * void vTask1( void * pvParameters )
  1282. * {
  1283. * for( ;; )
  1284. * {
  1285. * // Task code goes here.
  1286. *
  1287. * // ...
  1288. *
  1289. * // At some point the task wants to perform a long operation during
  1290. * // which it does not want to get swapped out. It cannot use
  1291. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1292. * // operation may cause interrupts to be missed - including the
  1293. * // ticks.
  1294. *
  1295. * // Prevent the real time kernel swapping out the task.
  1296. * vTaskSuspendAll ();
  1297. *
  1298. * // Perform the operation here. There is no need to use critical
  1299. * // sections as we have all the microcontroller processing time.
  1300. * // During this time interrupts will still operate and the kernel
  1301. * // tick count will be maintained.
  1302. *
  1303. * // ...
  1304. *
  1305. * // The operation is complete. Restart the kernel.
  1306. * xTaskResumeAll ();
  1307. * }
  1308. * }
  1309. * </pre>
  1310. * \defgroup vTaskSuspendAll vTaskSuspendAll
  1311. * \ingroup SchedulerControl
  1312. */
  1313. void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
  1314. /**
  1315. * task. h
  1316. * <pre>
  1317. * BaseType_t xTaskResumeAll( void );
  1318. * </pre>
  1319. *
  1320. * Resumes scheduler activity after it was suspended by a call to
  1321. * vTaskSuspendAll().
  1322. *
  1323. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  1324. * that were previously suspended by a call to vTaskSuspend().
  1325. *
  1326. * @return If resuming the scheduler caused a context switch then pdTRUE is
  1327. * returned, otherwise pdFALSE is returned.
  1328. *
  1329. * Example usage:
  1330. * <pre>
  1331. * void vTask1( void * pvParameters )
  1332. * {
  1333. * for( ;; )
  1334. * {
  1335. * // Task code goes here.
  1336. *
  1337. * // ...
  1338. *
  1339. * // At some point the task wants to perform a long operation during
  1340. * // which it does not want to get swapped out. It cannot use
  1341. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1342. * // operation may cause interrupts to be missed - including the
  1343. * // ticks.
  1344. *
  1345. * // Prevent the real time kernel swapping out the task.
  1346. * vTaskSuspendAll ();
  1347. *
  1348. * // Perform the operation here. There is no need to use critical
  1349. * // sections as we have all the microcontroller processing time.
  1350. * // During this time interrupts will still operate and the real
  1351. * // time kernel tick count will be maintained.
  1352. *
  1353. * // ...
  1354. *
  1355. * // The operation is complete. Restart the kernel. We want to force
  1356. * // a context switch - but there is no point if resuming the scheduler
  1357. * // caused a context switch already.
  1358. * if( !xTaskResumeAll () )
  1359. * {
  1360. * taskYIELD ();
  1361. * }
  1362. * }
  1363. * }
  1364. * </pre>
  1365. * \defgroup xTaskResumeAll xTaskResumeAll
  1366. * \ingroup SchedulerControl
  1367. */
  1368. BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
  1369. /*-----------------------------------------------------------
  1370. * TASK UTILITIES
  1371. *----------------------------------------------------------*/
  1372. /**
  1373. * task. h
  1374. * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
  1375. *
  1376. * @return The count of ticks since vTaskStartScheduler was called.
  1377. *
  1378. * \defgroup xTaskGetTickCount xTaskGetTickCount
  1379. * \ingroup TaskUtils
  1380. */
  1381. TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
  1382. /**
  1383. * task. h
  1384. * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
  1385. *
  1386. * @return The count of ticks since vTaskStartScheduler was called.
  1387. *
  1388. * This is a version of xTaskGetTickCount() that is safe to be called from an
  1389. * ISR - provided that TickType_t is the natural word size of the
  1390. * microcontroller being used or interrupt nesting is either not supported or
  1391. * not being used.
  1392. *
  1393. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  1394. * \ingroup TaskUtils
  1395. */
  1396. TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
  1397. /**
  1398. * task. h
  1399. * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
  1400. *
  1401. * @return The number of tasks that the real time kernel is currently managing.
  1402. * This includes all ready, blocked and suspended tasks. A task that
  1403. * has been deleted but not yet freed by the idle task will also be
  1404. * included in the count.
  1405. *
  1406. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  1407. * \ingroup TaskUtils
  1408. */
  1409. UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
  1410. /**
  1411. * task. h
  1412. * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
  1413. *
  1414. * @return The text (human readable) name of the task referenced by the handle
  1415. * xTaskToQuery. A task can query its own name by either passing in its own
  1416. * handle, or by setting xTaskToQuery to NULL.
  1417. *
  1418. * \defgroup pcTaskGetName pcTaskGetName
  1419. * \ingroup TaskUtils
  1420. */
  1421. char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1422. /**
  1423. * task. h
  1424. * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
  1425. *
  1426. * NOTE: This function takes a relatively long time to complete and should be
  1427. * used sparingly.
  1428. *
  1429. * @return The handle of the task that has the human readable name pcNameToQuery.
  1430. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1431. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1432. *
  1433. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1434. * \ingroup TaskUtils
  1435. */
  1436. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1437. /**
  1438. * task.h
  1439. * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
  1440. *
  1441. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1442. * this function to be available.
  1443. *
  1444. * Returns the high water mark of the stack associated with xTask. That is,
  1445. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1446. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1447. * number the closer the task has come to overflowing its stack.
  1448. *
  1449. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1450. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1451. * user to determine the return type. It gets around the problem of the value
  1452. * overflowing on 8-bit types without breaking backward compatibility for
  1453. * applications that expect an 8-bit return type.
  1454. *
  1455. * @param xTask Handle of the task associated with the stack to be checked.
  1456. * Set xTask to NULL to check the stack of the calling task.
  1457. *
  1458. * @return The smallest amount of free stack space there has been (in words, so
  1459. * actual spaces on the stack rather than bytes) since the task referenced by
  1460. * xTask was created.
  1461. */
  1462. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1463. /**
  1464. * task.h
  1465. * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
  1466. *
  1467. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1468. * this function to be available.
  1469. *
  1470. * Returns the high water mark of the stack associated with xTask. That is,
  1471. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1472. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1473. * number the closer the task has come to overflowing its stack.
  1474. *
  1475. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1476. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1477. * user to determine the return type. It gets around the problem of the value
  1478. * overflowing on 8-bit types without breaking backward compatibility for
  1479. * applications that expect an 8-bit return type.
  1480. *
  1481. * @param xTask Handle of the task associated with the stack to be checked.
  1482. * Set xTask to NULL to check the stack of the calling task.
  1483. *
  1484. * @return The smallest amount of free stack space there has been (in words, so
  1485. * actual spaces on the stack rather than bytes) since the task referenced by
  1486. * xTask was created.
  1487. */
  1488. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1489. /* When using trace macros it is sometimes necessary to include task.h before
  1490. * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1491. * so the following two prototypes will cause a compilation error. This can be
  1492. * fixed by simply guarding against the inclusion of these two prototypes unless
  1493. * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1494. * constant. */
  1495. #ifdef configUSE_APPLICATION_TASK_TAG
  1496. #if configUSE_APPLICATION_TASK_TAG == 1
  1497. /**
  1498. * task.h
  1499. * <pre>
  1500. * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  1501. * </pre>
  1502. *
  1503. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1504. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1505. * function.
  1506. */
  1507. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  1508. TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
  1509. /**
  1510. * task.h
  1511. * <pre>
  1512. * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1513. * </pre>
  1514. *
  1515. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1516. * call from an interrupt service routine - call
  1517. * xTaskGetApplicationTaskTagFromISR() instead.
  1518. */
  1519. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1520. /**
  1521. * task.h
  1522. * <pre>
  1523. * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1524. * </pre>
  1525. *
  1526. * Returns the pxHookFunction value assigned to the task xTask. Can
  1527. * be called from an interrupt service routine.
  1528. */
  1529. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1530. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1531. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1532. #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  1533. /* Each task contains an array of pointers that is dimensioned by the
  1534. * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
  1535. * kernel does not use the pointers itself, so the application writer can use
  1536. * the pointers for any purpose they wish. The following two functions are
  1537. * used to set and query a pointer respectively. */
  1538. void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  1539. BaseType_t xIndex,
  1540. void * pvValue ) PRIVILEGED_FUNCTION;
  1541. void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  1542. BaseType_t xIndex ) PRIVILEGED_FUNCTION;
  1543. #endif
  1544. #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
  1545. /**
  1546. * task.h
  1547. * <pre>void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName); </pre>
  1548. *
  1549. * The application stack overflow hook is called when a stack overflow is detected for a task.
  1550. *
  1551. * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
  1552. *
  1553. * @param xTask the task that just exceeded its stack boundaries.
  1554. * @param pcTaskName A character string containing the name of the offending task.
  1555. */
  1556. void vApplicationStackOverflowHook( TaskHandle_t xTask,
  1557. char * pcTaskName );
  1558. #endif
  1559. #if ( configUSE_TICK_HOOK > 0 )
  1560. /**
  1561. * task.h
  1562. * <pre>void vApplicationTickHook( void ); </pre>
  1563. *
  1564. * This hook function is called in the system tick handler after any OS work is completed.
  1565. */
  1566. void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
  1567. #endif
  1568. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1569. /**
  1570. * task.h
  1571. * <pre>void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) </pre>
  1572. *
  1573. * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Task TCB. This function is required when
  1574. * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
  1575. *
  1576. * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
  1577. * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
  1578. * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
  1579. */
  1580. void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
  1581. StackType_t ** ppxIdleTaskStackBuffer,
  1582. uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
  1583. #endif
  1584. /**
  1585. * task.h
  1586. * <pre>
  1587. * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  1588. * </pre>
  1589. *
  1590. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1591. * the effect of calling the Running tasks (the calling task) hook function.
  1592. *
  1593. * pvParameter is passed to the hook function for the task to interpret as it
  1594. * wants. The return value is the value returned by the task hook function
  1595. * registered by the user.
  1596. */
  1597. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  1598. void * pvParameter ) PRIVILEGED_FUNCTION;
  1599. /**
  1600. * xTaskGetIdleTaskHandle() is only available if
  1601. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1602. *
  1603. * Simply returns the handle of the idle task. It is not valid to call
  1604. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1605. */
  1606. TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
  1607. /**
  1608. * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
  1609. * uxTaskGetSystemState() to be available.
  1610. *
  1611. * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
  1612. * the system. TaskStatus_t structures contain, among other things, members
  1613. * for the task handle, task name, task priority, task state, and total amount
  1614. * of run time consumed by the task. See the TaskStatus_t structure
  1615. * definition in this file for the full member list.
  1616. *
  1617. * NOTE: This function is intended for debugging use only as its use results in
  1618. * the scheduler remaining suspended for an extended period.
  1619. *
  1620. * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
  1621. * The array must contain at least one TaskStatus_t structure for each task
  1622. * that is under the control of the RTOS. The number of tasks under the control
  1623. * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
  1624. *
  1625. * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
  1626. * parameter. The size is specified as the number of indexes in the array, or
  1627. * the number of TaskStatus_t structures contained in the array, not by the
  1628. * number of bytes in the array.
  1629. *
  1630. * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
  1631. * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
  1632. * total run time (as defined by the run time stats clock, see
  1633. * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted.
  1634. * pulTotalRunTime can be set to NULL to omit the total run time information.
  1635. *
  1636. * @return The number of TaskStatus_t structures that were populated by
  1637. * uxTaskGetSystemState(). This should equal the number returned by the
  1638. * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
  1639. * in the uxArraySize parameter was too small.
  1640. *
  1641. * Example usage:
  1642. * <pre>
  1643. * // This example demonstrates how a human readable table of run time stats
  1644. * // information is generated from raw data provided by uxTaskGetSystemState().
  1645. * // The human readable table is written to pcWriteBuffer
  1646. * void vTaskGetRunTimeStats( char *pcWriteBuffer )
  1647. * {
  1648. * TaskStatus_t *pxTaskStatusArray;
  1649. * volatile UBaseType_t uxArraySize, x;
  1650. * uint32_t ulTotalRunTime, ulStatsAsPercentage;
  1651. *
  1652. * // Make sure the write buffer does not contain a string.
  1653. * pcWriteBuffer = 0x00;
  1654. *
  1655. * // Take a snapshot of the number of tasks in case it changes while this
  1656. * // function is executing.
  1657. * uxArraySize = uxTaskGetNumberOfTasks();
  1658. *
  1659. * // Allocate a TaskStatus_t structure for each task. An array could be
  1660. * // allocated statically at compile time.
  1661. * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  1662. *
  1663. * if( pxTaskStatusArray != NULL )
  1664. * {
  1665. * // Generate raw status information about each task.
  1666. * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
  1667. *
  1668. * // For percentage calculations.
  1669. * ulTotalRunTime /= 100UL;
  1670. *
  1671. * // Avoid divide by zero errors.
  1672. * if( ulTotalRunTime > 0 )
  1673. * {
  1674. * // For each populated position in the pxTaskStatusArray array,
  1675. * // format the raw data as human readable ASCII data
  1676. * for( x = 0; x < uxArraySize; x++ )
  1677. * {
  1678. * // What percentage of the total run time has the task used?
  1679. * // This will always be rounded down to the nearest integer.
  1680. * // ulTotalRunTimeDiv100 has already been divided by 100.
  1681. * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
  1682. *
  1683. * if( ulStatsAsPercentage > 0UL )
  1684. * {
  1685. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
  1686. * }
  1687. * else
  1688. * {
  1689. * // If the percentage is zero here then the task has
  1690. * // consumed less than 1% of the total run time.
  1691. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
  1692. * }
  1693. *
  1694. * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
  1695. * }
  1696. * }
  1697. *
  1698. * // The array is no longer needed, free the memory it consumes.
  1699. * vPortFree( pxTaskStatusArray );
  1700. * }
  1701. * }
  1702. * </pre>
  1703. */
  1704. UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
  1705. const UBaseType_t uxArraySize,
  1706. uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
  1707. /**
  1708. * task. h
  1709. * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
  1710. *
  1711. * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
  1712. * both be defined as 1 for this function to be available. See the
  1713. * configuration section of the FreeRTOS.org website for more information.
  1714. *
  1715. * NOTE 1: This function will disable interrupts for its duration. It is
  1716. * not intended for normal application runtime use but as a debug aid.
  1717. *
  1718. * Lists all the current tasks, along with their current state and stack
  1719. * usage high water mark.
  1720. *
  1721. * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
  1722. * suspended ('S').
  1723. *
  1724. * PLEASE NOTE:
  1725. *
  1726. * This function is provided for convenience only, and is used by many of the
  1727. * demo applications. Do not consider it to be part of the scheduler.
  1728. *
  1729. * vTaskList() calls uxTaskGetSystemState(), then formats part of the
  1730. * uxTaskGetSystemState() output into a human readable table that displays task:
  1731. * names, states, priority, stack usage and task number.
  1732. * Stack usage specified as the number of unused StackType_t words stack can hold
  1733. * on top of stack - not the number of bytes.
  1734. *
  1735. * vTaskList() has a dependency on the sprintf() C library function that might
  1736. * bloat the code size, use a lot of stack, and provide different results on
  1737. * different platforms. An alternative, tiny, third party, and limited
  1738. * functionality implementation of sprintf() is provided in many of the
  1739. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1740. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1741. *
  1742. * It is recommended that production systems call uxTaskGetSystemState()
  1743. * directly to get access to raw stats data, rather than indirectly through a
  1744. * call to vTaskList().
  1745. *
  1746. * @param pcWriteBuffer A buffer into which the above mentioned details
  1747. * will be written, in ASCII form. This buffer is assumed to be large
  1748. * enough to contain the generated report. Approximately 40 bytes per
  1749. * task should be sufficient.
  1750. *
  1751. * \defgroup vTaskList vTaskList
  1752. * \ingroup TaskUtils
  1753. */
  1754. void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1755. /**
  1756. * task. h
  1757. * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
  1758. *
  1759. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1760. * must both be defined as 1 for this function to be available. The application
  1761. * must also then provide definitions for
  1762. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1763. * to configure a peripheral timer/counter and return the timers current count
  1764. * value respectively. The counter should be at least 10 times the frequency of
  1765. * the tick count.
  1766. *
  1767. * NOTE 1: This function will disable interrupts for its duration. It is
  1768. * not intended for normal application runtime use but as a debug aid.
  1769. *
  1770. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1771. * accumulated execution time being stored for each task. The resolution
  1772. * of the accumulated time value depends on the frequency of the timer
  1773. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1774. * Calling vTaskGetRunTimeStats() writes the total execution time of each
  1775. * task into a buffer, both as an absolute count value and as a percentage
  1776. * of the total system execution time.
  1777. *
  1778. * NOTE 2:
  1779. *
  1780. * This function is provided for convenience only, and is used by many of the
  1781. * demo applications. Do not consider it to be part of the scheduler.
  1782. *
  1783. * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
  1784. * uxTaskGetSystemState() output into a human readable table that displays the
  1785. * amount of time each task has spent in the Running state in both absolute and
  1786. * percentage terms.
  1787. *
  1788. * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
  1789. * that might bloat the code size, use a lot of stack, and provide different
  1790. * results on different platforms. An alternative, tiny, third party, and
  1791. * limited functionality implementation of sprintf() is provided in many of the
  1792. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1793. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1794. *
  1795. * It is recommended that production systems call uxTaskGetSystemState() directly
  1796. * to get access to raw stats data, rather than indirectly through a call to
  1797. * vTaskGetRunTimeStats().
  1798. *
  1799. * @param pcWriteBuffer A buffer into which the execution times will be
  1800. * written, in ASCII form. This buffer is assumed to be large enough to
  1801. * contain the generated report. Approximately 40 bytes per task should
  1802. * be sufficient.
  1803. *
  1804. * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
  1805. * \ingroup TaskUtils
  1806. */
  1807. void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1808. /**
  1809. * task. h
  1810. * <PRE>uint32_t ulTaskGetIdleRunTimeCounter( void );</PRE>
  1811. *
  1812. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1813. * must both be defined as 1 for this function to be available. The application
  1814. * must also then provide definitions for
  1815. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1816. * to configure a peripheral timer/counter and return the timers current count
  1817. * value respectively. The counter should be at least 10 times the frequency of
  1818. * the tick count.
  1819. *
  1820. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1821. * accumulated execution time being stored for each task. The resolution
  1822. * of the accumulated time value depends on the frequency of the timer
  1823. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1824. * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
  1825. * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
  1826. * returns the total execution time of just the idle task.
  1827. *
  1828. * @return The total run time of the idle task. This is the amount of time the
  1829. * idle task has actually been executing. The unit of time is dependent on the
  1830. * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
  1831. * portGET_RUN_TIME_COUNTER_VALUE() macros.
  1832. *
  1833. * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
  1834. * \ingroup TaskUtils
  1835. */
  1836. uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
  1837. /**
  1838. * task. h
  1839. * <PRE>BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
  1840. * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
  1841. *
  1842. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1843. *
  1844. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1845. * functions to be available.
  1846. *
  1847. * Sends a direct to task notification to a task, with an optional value and
  1848. * action.
  1849. *
  1850. * Each task has a private array of "notification values" (or 'notifications'),
  1851. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1852. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1853. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1854. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1855. *
  1856. * Events can be sent to a task using an intermediary object. Examples of such
  1857. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1858. * are a method of sending an event directly to a task without the need for such
  1859. * an intermediary object.
  1860. *
  1861. * A notification sent to a task can optionally perform an action, such as
  1862. * update, overwrite or increment one of the task's notification values. In
  1863. * that way task notifications can be used to send data to a task, or be used as
  1864. * light weight and fast binary or counting semaphores.
  1865. *
  1866. * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
  1867. * [optionally] block to wait for a notification to be pending. The task does
  1868. * not consume any CPU time while it is in the Blocked state.
  1869. *
  1870. * A notification sent to a task will remain pending until it is cleared by the
  1871. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1872. * un-indexed equivalents). If the task was already in the Blocked state to
  1873. * wait for a notification when the notification arrives then the task will
  1874. * automatically be removed from the Blocked state (unblocked) and the
  1875. * notification cleared.
  1876. *
  1877. * **NOTE** Each notification within the array operates independently - a task
  1878. * can only block on one notification within the array at a time and will not be
  1879. * unblocked by a notification sent to any other array index.
  1880. *
  1881. * Backward compatibility information:
  1882. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1883. * all task notification API functions operated on that value. Replacing the
  1884. * single notification value with an array of notification values necessitated a
  1885. * new set of API functions that could address specific notifications within the
  1886. * array. xTaskNotify() is the original API function, and remains backward
  1887. * compatible by always operating on the notification value at index 0 in the
  1888. * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  1889. * with the uxIndexToNotify parameter set to 0.
  1890. *
  1891. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1892. * task can be returned from the xTaskCreate() API function used to create the
  1893. * task, and the handle of the currently running task can be obtained by calling
  1894. * xTaskGetCurrentTaskHandle().
  1895. *
  1896. * @param uxIndexToNotify The index within the target task's array of
  1897. * notification values to which the notification is to be sent. uxIndexToNotify
  1898. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  1899. * not have this parameter and always sends notifications to index 0.
  1900. *
  1901. * @param ulValue Data that can be sent with the notification. How the data is
  1902. * used depends on the value of the eAction parameter.
  1903. *
  1904. * @param eAction Specifies how the notification updates the task's notification
  1905. * value, if at all. Valid values for eAction are as follows:
  1906. *
  1907. * eSetBits -
  1908. * The target notification value is bitwise ORed with ulValue.
  1909. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1910. *
  1911. * eIncrement -
  1912. * The target notification value is incremented. ulValue is not used and
  1913. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1914. *
  1915. * eSetValueWithOverwrite -
  1916. * The target notification value is set to the value of ulValue, even if the
  1917. * task being notified had not yet processed the previous notification at the
  1918. * same array index (the task already had a notification pending at that index).
  1919. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1920. *
  1921. * eSetValueWithoutOverwrite -
  1922. * If the task being notified did not already have a notification pending at the
  1923. * same array index then the target notification value is set to ulValue and
  1924. * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  1925. * had a notification pending at the same array index then no action is
  1926. * performed and pdFAIL is returned.
  1927. *
  1928. * eNoAction -
  1929. * The task receives a notification at the specified array index without the
  1930. * notification value at that index being updated. ulValue is not used and
  1931. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1932. *
  1933. * pulPreviousNotificationValue -
  1934. * Can be used to pass out the subject task's notification value before any
  1935. * bits are modified by the notify function.
  1936. *
  1937. * @return Dependent on the value of eAction. See the description of the
  1938. * eAction parameter.
  1939. *
  1940. * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  1941. * \ingroup TaskNotifications
  1942. */
  1943. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  1944. UBaseType_t uxIndexToNotify,
  1945. uint32_t ulValue,
  1946. eNotifyAction eAction,
  1947. uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
  1948. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  1949. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  1950. #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  1951. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  1952. /**
  1953. * task. h
  1954. * <PRE>BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
  1955. * <PRE>BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
  1956. *
  1957. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1958. *
  1959. * xTaskNotifyAndQueryIndexed() performs the same operation as
  1960. * xTaskNotifyIndexed() with the addition that it also returns the subject
  1961. * task's prior notification value (the notification value at the time the
  1962. * function is called rather than when the function returns) in the additional
  1963. * pulPreviousNotifyValue parameter.
  1964. *
  1965. * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
  1966. * addition that it also returns the subject task's prior notification value
  1967. * (the notification value as it was at the time the function is called, rather
  1968. * than when the function returns) in the additional pulPreviousNotifyValue
  1969. * parameter.
  1970. *
  1971. * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
  1972. * \ingroup TaskNotifications
  1973. */
  1974. #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1975. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1976. #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1977. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1978. /**
  1979. * task. h
  1980. * <PRE>BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  1981. * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  1982. *
  1983. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1984. *
  1985. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1986. * functions to be available.
  1987. *
  1988. * A version of xTaskNotifyIndexed() that can be used from an interrupt service
  1989. * routine (ISR).
  1990. *
  1991. * Each task has a private array of "notification values" (or 'notifications'),
  1992. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1993. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1994. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1995. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1996. *
  1997. * Events can be sent to a task using an intermediary object. Examples of such
  1998. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1999. * are a method of sending an event directly to a task without the need for such
  2000. * an intermediary object.
  2001. *
  2002. * A notification sent to a task can optionally perform an action, such as
  2003. * update, overwrite or increment one of the task's notification values. In
  2004. * that way task notifications can be used to send data to a task, or be used as
  2005. * light weight and fast binary or counting semaphores.
  2006. *
  2007. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  2008. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  2009. * to wait for a notification value to have a non-zero value. The task does
  2010. * not consume any CPU time while it is in the Blocked state.
  2011. *
  2012. * A notification sent to a task will remain pending until it is cleared by the
  2013. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2014. * un-indexed equivalents). If the task was already in the Blocked state to
  2015. * wait for a notification when the notification arrives then the task will
  2016. * automatically be removed from the Blocked state (unblocked) and the
  2017. * notification cleared.
  2018. *
  2019. * **NOTE** Each notification within the array operates independently - a task
  2020. * can only block on one notification within the array at a time and will not be
  2021. * unblocked by a notification sent to any other array index.
  2022. *
  2023. * Backward compatibility information:
  2024. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2025. * all task notification API functions operated on that value. Replacing the
  2026. * single notification value with an array of notification values necessitated a
  2027. * new set of API functions that could address specific notifications within the
  2028. * array. xTaskNotifyFromISR() is the original API function, and remains
  2029. * backward compatible by always operating on the notification value at index 0
  2030. * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
  2031. * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2032. *
  2033. * @param uxIndexToNotify The index within the target task's array of
  2034. * notification values to which the notification is to be sent. uxIndexToNotify
  2035. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
  2036. * does not have this parameter and always sends notifications to index 0.
  2037. *
  2038. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2039. * task can be returned from the xTaskCreate() API function used to create the
  2040. * task, and the handle of the currently running task can be obtained by calling
  2041. * xTaskGetCurrentTaskHandle().
  2042. *
  2043. * @param ulValue Data that can be sent with the notification. How the data is
  2044. * used depends on the value of the eAction parameter.
  2045. *
  2046. * @param eAction Specifies how the notification updates the task's notification
  2047. * value, if at all. Valid values for eAction are as follows:
  2048. *
  2049. * eSetBits -
  2050. * The task's notification value is bitwise ORed with ulValue. xTaskNotify()
  2051. * always returns pdPASS in this case.
  2052. *
  2053. * eIncrement -
  2054. * The task's notification value is incremented. ulValue is not used and
  2055. * xTaskNotify() always returns pdPASS in this case.
  2056. *
  2057. * eSetValueWithOverwrite -
  2058. * The task's notification value is set to the value of ulValue, even if the
  2059. * task being notified had not yet processed the previous notification (the
  2060. * task already had a notification pending). xTaskNotify() always returns
  2061. * pdPASS in this case.
  2062. *
  2063. * eSetValueWithoutOverwrite -
  2064. * If the task being notified did not already have a notification pending then
  2065. * the task's notification value is set to ulValue and xTaskNotify() will
  2066. * return pdPASS. If the task being notified already had a notification
  2067. * pending then no action is performed and pdFAIL is returned.
  2068. *
  2069. * eNoAction -
  2070. * The task receives a notification without its notification value being
  2071. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  2072. * this case.
  2073. *
  2074. * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  2075. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2076. * task to which the notification was sent to leave the Blocked state, and the
  2077. * unblocked task has a priority higher than the currently running task. If
  2078. * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  2079. * be requested before the interrupt is exited. How a context switch is
  2080. * requested from an ISR is dependent on the port - see the documentation page
  2081. * for the port in use.
  2082. *
  2083. * @return Dependent on the value of eAction. See the description of the
  2084. * eAction parameter.
  2085. *
  2086. * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
  2087. * \ingroup TaskNotifications
  2088. */
  2089. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  2090. UBaseType_t uxIndexToNotify,
  2091. uint32_t ulValue,
  2092. eNotifyAction eAction,
  2093. uint32_t * pulPreviousNotificationValue,
  2094. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2095. #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2096. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2097. #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2098. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2099. /**
  2100. * task. h
  2101. * <PRE>BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2102. * <PRE>BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2103. *
  2104. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2105. *
  2106. * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
  2107. * xTaskNotifyIndexedFromISR() with the addition that it also returns the
  2108. * subject task's prior notification value (the notification value at the time
  2109. * the function is called rather than at the time the function returns) in the
  2110. * additional pulPreviousNotifyValue parameter.
  2111. *
  2112. * xTaskNotifyAndQueryFromISR() performs the same operation as
  2113. * xTaskNotifyFromISR() with the addition that it also returns the subject
  2114. * task's prior notification value (the notification value at the time the
  2115. * function is called rather than at the time the function returns) in the
  2116. * additional pulPreviousNotifyValue parameter.
  2117. *
  2118. * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
  2119. * \ingroup TaskNotifications
  2120. */
  2121. #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2122. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2123. #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2124. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2125. /**
  2126. * task. h
  2127. * <pre>
  2128. * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2129. *
  2130. * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2131. * </pre>
  2132. *
  2133. * Waits for a direct to task notification to be pending at a given index within
  2134. * an array of direct to task notifications.
  2135. *
  2136. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2137. *
  2138. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2139. * function to be available.
  2140. *
  2141. * Each task has a private array of "notification values" (or 'notifications'),
  2142. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2143. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2144. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2145. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2146. *
  2147. * Events can be sent to a task using an intermediary object. Examples of such
  2148. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2149. * are a method of sending an event directly to a task without the need for such
  2150. * an intermediary object.
  2151. *
  2152. * A notification sent to a task can optionally perform an action, such as
  2153. * update, overwrite or increment one of the task's notification values. In
  2154. * that way task notifications can be used to send data to a task, or be used as
  2155. * light weight and fast binary or counting semaphores.
  2156. *
  2157. * A notification sent to a task will remain pending until it is cleared by the
  2158. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2159. * un-indexed equivalents). If the task was already in the Blocked state to
  2160. * wait for a notification when the notification arrives then the task will
  2161. * automatically be removed from the Blocked state (unblocked) and the
  2162. * notification cleared.
  2163. *
  2164. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  2165. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  2166. * to wait for a notification value to have a non-zero value. The task does
  2167. * not consume any CPU time while it is in the Blocked state.
  2168. *
  2169. * **NOTE** Each notification within the array operates independently - a task
  2170. * can only block on one notification within the array at a time and will not be
  2171. * unblocked by a notification sent to any other array index.
  2172. *
  2173. * Backward compatibility information:
  2174. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2175. * all task notification API functions operated on that value. Replacing the
  2176. * single notification value with an array of notification values necessitated a
  2177. * new set of API functions that could address specific notifications within the
  2178. * array. xTaskNotifyWait() is the original API function, and remains backward
  2179. * compatible by always operating on the notification value at index 0 in the
  2180. * array. Calling xTaskNotifyWait() is equivalent to calling
  2181. * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  2182. *
  2183. * @param uxIndexToWaitOn The index within the calling task's array of
  2184. * notification values on which the calling task will wait for a notification to
  2185. * be received. uxIndexToWaitOn must be less than
  2186. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  2187. * not have this parameter and always waits for notifications on index 0.
  2188. *
  2189. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  2190. * will be cleared in the calling task's notification value before the task
  2191. * checks to see if any notifications are pending, and optionally blocks if no
  2192. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  2193. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  2194. * the effect of resetting the task's notification value to 0. Setting
  2195. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  2196. *
  2197. * @param ulBitsToClearOnExit If a notification is pending or received before
  2198. * the calling task exits the xTaskNotifyWait() function then the task's
  2199. * notification value (see the xTaskNotify() API function) is passed out using
  2200. * the pulNotificationValue parameter. Then any bits that are set in
  2201. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  2202. * *pulNotificationValue is set before any bits are cleared). Setting
  2203. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  2204. * (if limits.h is not included) will have the effect of resetting the task's
  2205. * notification value to 0 before the function exits. Setting
  2206. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  2207. * when the function exits (in which case the value passed out in
  2208. * pulNotificationValue will match the task's notification value).
  2209. *
  2210. * @param pulNotificationValue Used to pass the task's notification value out
  2211. * of the function. Note the value passed out will not be effected by the
  2212. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  2213. *
  2214. * @param xTicksToWait The maximum amount of time that the task should wait in
  2215. * the Blocked state for a notification to be received, should a notification
  2216. * not already be pending when xTaskNotifyWait() was called. The task
  2217. * will not consume any processing time while it is in the Blocked state. This
  2218. * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
  2219. * used to convert a time specified in milliseconds to a time specified in
  2220. * ticks.
  2221. *
  2222. * @return If a notification was received (including notifications that were
  2223. * already pending when xTaskNotifyWait was called) then pdPASS is
  2224. * returned. Otherwise pdFAIL is returned.
  2225. *
  2226. * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  2227. * \ingroup TaskNotifications
  2228. */
  2229. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  2230. uint32_t ulBitsToClearOnEntry,
  2231. uint32_t ulBitsToClearOnExit,
  2232. uint32_t * pulNotificationValue,
  2233. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2234. #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2235. xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2236. #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2237. xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2238. /**
  2239. * task. h
  2240. * <PRE>BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );</PRE>
  2241. * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
  2242. *
  2243. * Sends a direct to task notification to a particular index in the target
  2244. * task's notification array in a manner similar to giving a counting semaphore.
  2245. *
  2246. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2247. *
  2248. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2249. * macros to be available.
  2250. *
  2251. * Each task has a private array of "notification values" (or 'notifications'),
  2252. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2253. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2254. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2255. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2256. *
  2257. * Events can be sent to a task using an intermediary object. Examples of such
  2258. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2259. * are a method of sending an event directly to a task without the need for such
  2260. * an intermediary object.
  2261. *
  2262. * A notification sent to a task can optionally perform an action, such as
  2263. * update, overwrite or increment one of the task's notification values. In
  2264. * that way task notifications can be used to send data to a task, or be used as
  2265. * light weight and fast binary or counting semaphores.
  2266. *
  2267. * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
  2268. * notifications are used as light weight and faster binary or counting
  2269. * semaphore equivalents. Actual FreeRTOS semaphores are given using the
  2270. * xSemaphoreGive() API function, the equivalent action that instead uses a task
  2271. * notification is xTaskNotifyGiveIndexed().
  2272. *
  2273. * When task notifications are being used as a binary or counting semaphore
  2274. * equivalent then the task being notified should wait for the notification
  2275. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2276. * xTaskNotifyWaitIndexed() API function.
  2277. *
  2278. * **NOTE** Each notification within the array operates independently - a task
  2279. * can only block on one notification within the array at a time and will not be
  2280. * unblocked by a notification sent to any other array index.
  2281. *
  2282. * Backward compatibility information:
  2283. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2284. * all task notification API functions operated on that value. Replacing the
  2285. * single notification value with an array of notification values necessitated a
  2286. * new set of API functions that could address specific notifications within the
  2287. * array. xTaskNotifyGive() is the original API function, and remains backward
  2288. * compatible by always operating on the notification value at index 0 in the
  2289. * array. Calling xTaskNotifyGive() is equivalent to calling
  2290. * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
  2291. *
  2292. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2293. * task can be returned from the xTaskCreate() API function used to create the
  2294. * task, and the handle of the currently running task can be obtained by calling
  2295. * xTaskGetCurrentTaskHandle().
  2296. *
  2297. * @param uxIndexToNotify The index within the target task's array of
  2298. * notification values to which the notification is to be sent. uxIndexToNotify
  2299. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
  2300. * does not have this parameter and always sends notifications to index 0.
  2301. *
  2302. * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  2303. * eAction parameter set to eIncrement - so pdPASS is always returned.
  2304. *
  2305. * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
  2306. * \ingroup TaskNotifications
  2307. */
  2308. #define xTaskNotifyGive( xTaskToNotify ) \
  2309. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
  2310. #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
  2311. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
  2312. /**
  2313. * task. h
  2314. * <PRE>void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2315. * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2316. *
  2317. * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
  2318. * service routine (ISR).
  2319. *
  2320. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2321. *
  2322. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  2323. * to be available.
  2324. *
  2325. * Each task has a private array of "notification values" (or 'notifications'),
  2326. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2327. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2328. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2329. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2330. *
  2331. * Events can be sent to a task using an intermediary object. Examples of such
  2332. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2333. * are a method of sending an event directly to a task without the need for such
  2334. * an intermediary object.
  2335. *
  2336. * A notification sent to a task can optionally perform an action, such as
  2337. * update, overwrite or increment one of the task's notification values. In
  2338. * that way task notifications can be used to send data to a task, or be used as
  2339. * light weight and fast binary or counting semaphores.
  2340. *
  2341. * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
  2342. * are used as light weight and faster binary or counting semaphore equivalents.
  2343. * Actual FreeRTOS semaphores are given from an ISR using the
  2344. * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  2345. * a task notification is vTaskNotifyGiveIndexedFromISR().
  2346. *
  2347. * When task notifications are being used as a binary or counting semaphore
  2348. * equivalent then the task being notified should wait for the notification
  2349. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2350. * xTaskNotifyWaitIndexed() API function.
  2351. *
  2352. * **NOTE** Each notification within the array operates independently - a task
  2353. * can only block on one notification within the array at a time and will not be
  2354. * unblocked by a notification sent to any other array index.
  2355. *
  2356. * Backward compatibility information:
  2357. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2358. * all task notification API functions operated on that value. Replacing the
  2359. * single notification value with an array of notification values necessitated a
  2360. * new set of API functions that could address specific notifications within the
  2361. * array. xTaskNotifyFromISR() is the original API function, and remains
  2362. * backward compatible by always operating on the notification value at index 0
  2363. * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
  2364. * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2365. *
  2366. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2367. * task can be returned from the xTaskCreate() API function used to create the
  2368. * task, and the handle of the currently running task can be obtained by calling
  2369. * xTaskGetCurrentTaskHandle().
  2370. *
  2371. * @param uxIndexToNotify The index within the target task's array of
  2372. * notification values to which the notification is to be sent. uxIndexToNotify
  2373. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2374. * xTaskNotifyGiveFromISR() does not have this parameter and always sends
  2375. * notifications to index 0.
  2376. *
  2377. * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  2378. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2379. * task to which the notification was sent to leave the Blocked state, and the
  2380. * unblocked task has a priority higher than the currently running task. If
  2381. * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  2382. * should be requested before the interrupt is exited. How a context switch is
  2383. * requested from an ISR is dependent on the port - see the documentation page
  2384. * for the port in use.
  2385. *
  2386. * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
  2387. * \ingroup TaskNotifications
  2388. */
  2389. void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  2390. UBaseType_t uxIndexToNotify,
  2391. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2392. #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
  2393. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
  2394. #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
  2395. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
  2396. /**
  2397. * task. h
  2398. * <pre>
  2399. * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2400. *
  2401. * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2402. * </pre>
  2403. *
  2404. * Waits for a direct to task notification on a particular index in the calling
  2405. * task's notification array in a manner similar to taking a counting semaphore.
  2406. *
  2407. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2408. *
  2409. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2410. * function to be available.
  2411. *
  2412. * Each task has a private array of "notification values" (or 'notifications'),
  2413. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2414. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2415. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2416. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2417. *
  2418. * Events can be sent to a task using an intermediary object. Examples of such
  2419. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2420. * are a method of sending an event directly to a task without the need for such
  2421. * an intermediary object.
  2422. *
  2423. * A notification sent to a task can optionally perform an action, such as
  2424. * update, overwrite or increment one of the task's notification values. In
  2425. * that way task notifications can be used to send data to a task, or be used as
  2426. * light weight and fast binary or counting semaphores.
  2427. *
  2428. * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
  2429. * used as a faster and lighter weight binary or counting semaphore alternative.
  2430. * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
  2431. * the equivalent action that instead uses a task notification is
  2432. * ulTaskNotifyTakeIndexed().
  2433. *
  2434. * When a task is using its notification value as a binary or counting semaphore
  2435. * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
  2436. * macro, or xTaskNotifyIndex() function with the eAction parameter set to
  2437. * eIncrement.
  2438. *
  2439. * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
  2440. * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
  2441. * in which case the notification value acts like a binary semaphore, or
  2442. * decrement the notification value on exit, in which case the notification
  2443. * value acts like a counting semaphore.
  2444. *
  2445. * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
  2446. * a notification. The task does not consume any CPU time while it is in the
  2447. * Blocked state.
  2448. *
  2449. * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
  2450. * ulTaskNotifyTakeIndexed() will return when the task's notification value is
  2451. * not zero.
  2452. *
  2453. * **NOTE** Each notification within the array operates independently - a task
  2454. * can only block on one notification within the array at a time and will not be
  2455. * unblocked by a notification sent to any other array index.
  2456. *
  2457. * Backward compatibility information:
  2458. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2459. * all task notification API functions operated on that value. Replacing the
  2460. * single notification value with an array of notification values necessitated a
  2461. * new set of API functions that could address specific notifications within the
  2462. * array. ulTaskNotifyTake() is the original API function, and remains backward
  2463. * compatible by always operating on the notification value at index 0 in the
  2464. * array. Calling ulTaskNotifyTake() is equivalent to calling
  2465. * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
  2466. *
  2467. * @param uxIndexToWaitOn The index within the calling task's array of
  2468. * notification values on which the calling task will wait for a notification to
  2469. * be non-zero. uxIndexToWaitOn must be less than
  2470. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
  2471. * not have this parameter and always waits for notifications on index 0.
  2472. *
  2473. * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  2474. * notification value is decremented when the function exits. In this way the
  2475. * notification value acts like a counting semaphore. If xClearCountOnExit is
  2476. * not pdFALSE then the task's notification value is cleared to zero when the
  2477. * function exits. In this way the notification value acts like a binary
  2478. * semaphore.
  2479. *
  2480. * @param xTicksToWait The maximum amount of time that the task should wait in
  2481. * the Blocked state for the task's notification value to be greater than zero,
  2482. * should the count not already be greater than zero when
  2483. * ulTaskNotifyTake() was called. The task will not consume any processing
  2484. * time while it is in the Blocked state. This is specified in kernel ticks,
  2485. * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
  2486. * specified in milliseconds to a time specified in ticks.
  2487. *
  2488. * @return The task's notification count before it is either cleared to zero or
  2489. * decremented (see the xClearCountOnExit parameter).
  2490. *
  2491. * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
  2492. * \ingroup TaskNotifications
  2493. */
  2494. uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
  2495. BaseType_t xClearCountOnExit,
  2496. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2497. #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
  2498. ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2499. #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
  2500. ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2501. /**
  2502. * task. h
  2503. * <pre>
  2504. * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
  2505. *
  2506. * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  2507. * </pre>
  2508. *
  2509. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2510. *
  2511. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2512. * functions to be available.
  2513. *
  2514. * Each task has a private array of "notification values" (or 'notifications'),
  2515. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2516. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2517. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2518. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2519. *
  2520. * If a notification is sent to an index within the array of notifications then
  2521. * the notification at that index is said to be 'pending' until it is read or
  2522. * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
  2523. * is the function that clears a pending notification without reading the
  2524. * notification value. The notification value at the same array index is not
  2525. * altered. Set xTask to NULL to clear the notification state of the calling
  2526. * task.
  2527. *
  2528. * Backward compatibility information:
  2529. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2530. * all task notification API functions operated on that value. Replacing the
  2531. * single notification value with an array of notification values necessitated a
  2532. * new set of API functions that could address specific notifications within the
  2533. * array. xTaskNotifyStateClear() is the original API function, and remains
  2534. * backward compatible by always operating on the notification value at index 0
  2535. * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
  2536. * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
  2537. *
  2538. * @param xTask The handle of the RTOS task that will have a notification state
  2539. * cleared. Set xTask to NULL to clear a notification state in the calling
  2540. * task. To obtain a task's handle create the task using xTaskCreate() and
  2541. * make use of the pxCreatedTask parameter, or create the task using
  2542. * xTaskCreateStatic() and store the returned value, or use the task's name in
  2543. * a call to xTaskGetHandle().
  2544. *
  2545. * @param uxIndexToClear The index within the target task's array of
  2546. * notification values to act upon. For example, setting uxIndexToClear to 1
  2547. * will clear the state of the notification at index 1 within the array.
  2548. * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2549. * ulTaskNotifyStateClear() does not have this parameter and always acts on the
  2550. * notification at index 0.
  2551. *
  2552. * @return pdTRUE if the task's notification state was set to
  2553. * eNotWaitingNotification, otherwise pdFALSE.
  2554. *
  2555. * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
  2556. * \ingroup TaskNotifications
  2557. */
  2558. BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  2559. UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
  2560. #define xTaskNotifyStateClear( xTask ) \
  2561. xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
  2562. #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
  2563. xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
  2564. /**
  2565. * task. h
  2566. * <pre>
  2567. * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
  2568. *
  2569. * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
  2570. * </pre>
  2571. *
  2572. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2573. *
  2574. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2575. * functions to be available.
  2576. *
  2577. * Each task has a private array of "notification values" (or 'notifications'),
  2578. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2579. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2580. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2581. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2582. *
  2583. * ulTaskNotifyValueClearIndexed() clears the bits specified by the
  2584. * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
  2585. * of the task referenced by xTask.
  2586. *
  2587. * Backward compatibility information:
  2588. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2589. * all task notification API functions operated on that value. Replacing the
  2590. * single notification value with an array of notification values necessitated a
  2591. * new set of API functions that could address specific notifications within the
  2592. * array. ulTaskNotifyValueClear() is the original API function, and remains
  2593. * backward compatible by always operating on the notification value at index 0
  2594. * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
  2595. * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
  2596. *
  2597. * @param xTask The handle of the RTOS task that will have bits in one of its
  2598. * notification values cleared. Set xTask to NULL to clear bits in a
  2599. * notification value of the calling task. To obtain a task's handle create the
  2600. * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
  2601. * create the task using xTaskCreateStatic() and store the returned value, or
  2602. * use the task's name in a call to xTaskGetHandle().
  2603. *
  2604. * @param uxIndexToClear The index within the target task's array of
  2605. * notification values in which to clear the bits. uxIndexToClear
  2606. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2607. * ulTaskNotifyValueClear() does not have this parameter and always clears bits
  2608. * in the notification value at index 0.
  2609. *
  2610. * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
  2611. * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
  2612. * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
  2613. * the notification value to 0. Set ulBitsToClear to 0 to query the task's
  2614. * notification value without clearing any bits.
  2615. *
  2616. *
  2617. * @return The value of the target task's notification value before the bits
  2618. * specified by ulBitsToClear were cleared.
  2619. * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
  2620. * \ingroup TaskNotifications
  2621. */
  2622. uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  2623. UBaseType_t uxIndexToClear,
  2624. uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
  2625. #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
  2626. ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
  2627. #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
  2628. ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
  2629. /**
  2630. * task.h
  2631. * <pre>
  2632. * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  2633. * </pre>
  2634. *
  2635. * Capture the current time for future use with xTaskCheckForTimeOut().
  2636. *
  2637. * @param pxTimeOut Pointer to a timeout object into which the current time
  2638. * is to be captured. The captured time includes the tick count and the number
  2639. * of times the tick count has overflowed since the system first booted.
  2640. * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
  2641. * \ingroup TaskCtrl
  2642. */
  2643. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2644. /**
  2645. * task.h
  2646. * <pre>
  2647. * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
  2648. * </pre>
  2649. *
  2650. * Determines if pxTicksToWait ticks has passed since a time was captured
  2651. * using a call to vTaskSetTimeOutState(). The captured time includes the tick
  2652. * count and the number of times the tick count has overflowed.
  2653. *
  2654. * @param pxTimeOut The time status as captured previously using
  2655. * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
  2656. * to reflect the current time status.
  2657. * @param pxTicksToWait The number of ticks to check for timeout i.e. if
  2658. * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
  2659. * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
  2660. * If the timeout has not occurred, pxTicksToWait is updated to reflect the
  2661. * number of remaining ticks.
  2662. *
  2663. * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
  2664. * returned and pxTicksToWait is updated to reflect the number of remaining
  2665. * ticks.
  2666. *
  2667. * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
  2668. *
  2669. * Example Usage:
  2670. * <pre>
  2671. * // Driver library function used to receive uxWantedBytes from an Rx buffer
  2672. * // that is filled by a UART interrupt. If there are not enough bytes in the
  2673. * // Rx buffer then the task enters the Blocked state until it is notified that
  2674. * // more data has been placed into the buffer. If there is still not enough
  2675. * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
  2676. * // is used to re-calculate the Block time to ensure the total amount of time
  2677. * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
  2678. * // continues until either the buffer contains at least uxWantedBytes bytes,
  2679. * // or the total amount of time spent in the Blocked state reaches
  2680. * // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are
  2681. * // available up to a maximum of uxWantedBytes.
  2682. *
  2683. * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
  2684. * {
  2685. * size_t uxReceived = 0;
  2686. * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
  2687. * TimeOut_t xTimeOut;
  2688. *
  2689. * // Initialize xTimeOut. This records the time at which this function
  2690. * // was entered.
  2691. * vTaskSetTimeOutState( &xTimeOut );
  2692. *
  2693. * // Loop until the buffer contains the wanted number of bytes, or a
  2694. * // timeout occurs.
  2695. * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
  2696. * {
  2697. * // The buffer didn't contain enough data so this task is going to
  2698. * // enter the Blocked state. Adjusting xTicksToWait to account for
  2699. * // any time that has been spent in the Blocked state within this
  2700. * // function so far to ensure the total amount of time spent in the
  2701. * // Blocked state does not exceed MAX_TIME_TO_WAIT.
  2702. * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
  2703. * {
  2704. * //Timed out before the wanted number of bytes were available,
  2705. * // exit the loop.
  2706. * break;
  2707. * }
  2708. *
  2709. * // Wait for a maximum of xTicksToWait ticks to be notified that the
  2710. * // receive interrupt has placed more data into the buffer.
  2711. * ulTaskNotifyTake( pdTRUE, xTicksToWait );
  2712. * }
  2713. *
  2714. * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
  2715. * // The actual number of bytes read (which might be less than
  2716. * // uxWantedBytes) is returned.
  2717. * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
  2718. * pucBuffer,
  2719. * uxWantedBytes );
  2720. *
  2721. * return uxReceived;
  2722. * }
  2723. * </pre>
  2724. * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
  2725. * \ingroup TaskCtrl
  2726. */
  2727. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  2728. TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
  2729. /**
  2730. * task.h
  2731. * <pre>
  2732. * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
  2733. * </pre>
  2734. *
  2735. * This function corrects the tick count value after the application code has held
  2736. * interrupts disabled for an extended period resulting in tick interrupts having
  2737. * been missed.
  2738. *
  2739. * This function is similar to vTaskStepTick(), however, unlike
  2740. * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
  2741. * time at which a task should be removed from the blocked state. That means
  2742. * tasks may have to be removed from the blocked state as the tick count is
  2743. * moved.
  2744. *
  2745. * @param xTicksToCatchUp The number of tick interrupts that have been missed due to
  2746. * interrupts being disabled. Its value is not computed automatically, so must be
  2747. * computed by the application writer.
  2748. *
  2749. * @return pdTRUE if moving the tick count forward resulted in a task leaving the
  2750. * blocked state and a context switch being performed. Otherwise pdFALSE.
  2751. *
  2752. * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks
  2753. * \ingroup TaskCtrl
  2754. */
  2755. BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
  2756. /*-----------------------------------------------------------
  2757. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  2758. *----------------------------------------------------------*/
  2759. /*
  2760. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2761. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2762. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2763. *
  2764. * Called from the real time kernel tick (either preemptive or cooperative),
  2765. * this increments the tick count and checks if any tasks that are blocked
  2766. * for a finite period required removing from a blocked list and placing on
  2767. * a ready list. If a non-zero value is returned then a context switch is
  2768. * required because either:
  2769. * + A task was removed from a blocked list because its timeout had expired,
  2770. * or
  2771. * + Time slicing is in use and there is a task of equal priority to the
  2772. * currently running task.
  2773. */
  2774. BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
  2775. /*
  2776. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2777. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2778. *
  2779. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2780. *
  2781. * Removes the calling task from the ready list and places it both
  2782. * on the list of tasks waiting for a particular event, and the
  2783. * list of delayed tasks. The task will be removed from both lists
  2784. * and replaced on the ready list should either the event occur (and
  2785. * there be no higher priority tasks waiting on the same event) or
  2786. * the delay period expires.
  2787. *
  2788. * The 'unordered' version replaces the event list item value with the
  2789. * xItemValue value, and inserts the list item at the end of the list.
  2790. *
  2791. * The 'ordered' version uses the existing event list item value (which is the
  2792. * owning task's priority) to insert the list item into the event list in task
  2793. * priority order.
  2794. *
  2795. * @param pxEventList The list containing tasks that are blocked waiting
  2796. * for the event to occur.
  2797. *
  2798. * @param xItemValue The item value to use for the event list item when the
  2799. * event list is not ordered by task priority.
  2800. *
  2801. * @param xTicksToWait The maximum amount of time that the task should wait
  2802. * for the event to occur. This is specified in kernel ticks, the constant
  2803. * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
  2804. * period.
  2805. */
  2806. void vTaskPlaceOnEventList( List_t * const pxEventList,
  2807. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2808. void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
  2809. const TickType_t xItemValue,
  2810. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2811. /*
  2812. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2813. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2814. *
  2815. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2816. *
  2817. * This function performs nearly the same function as vTaskPlaceOnEventList().
  2818. * The difference being that this function does not permit tasks to block
  2819. * indefinitely, whereas vTaskPlaceOnEventList() does.
  2820. *
  2821. */
  2822. void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
  2823. TickType_t xTicksToWait,
  2824. const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  2825. /*
  2826. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2827. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2828. *
  2829. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2830. *
  2831. * Removes a task from both the specified event list and the list of blocked
  2832. * tasks, and places it on a ready queue.
  2833. *
  2834. * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
  2835. * if either an event occurs to unblock a task, or the block timeout period
  2836. * expires.
  2837. *
  2838. * xTaskRemoveFromEventList() is used when the event list is in task priority
  2839. * order. It removes the list item from the head of the event list as that will
  2840. * have the highest priority owning task of all the tasks on the event list.
  2841. * vTaskRemoveFromUnorderedEventList() is used when the event list is not
  2842. * ordered and the event list items hold something other than the owning tasks
  2843. * priority. In this case the event list item value is updated to the value
  2844. * passed in the xItemValue parameter.
  2845. *
  2846. * @return pdTRUE if the task being removed has a higher priority than the task
  2847. * making the call, otherwise pdFALSE.
  2848. */
  2849. BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
  2850. void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
  2851. const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
  2852. /*
  2853. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2854. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2855. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2856. *
  2857. * Sets the pointer to the current TCB to the TCB of the highest priority task
  2858. * that is ready to run.
  2859. */
  2860. portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
  2861. /*
  2862. * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
  2863. * THE EVENT BITS MODULE.
  2864. */
  2865. TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
  2866. /*
  2867. * Return the handle of the calling task.
  2868. */
  2869. TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
  2870. /*
  2871. * Shortcut used by the queue implementation to prevent unnecessary call to
  2872. * taskYIELD();
  2873. */
  2874. void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
  2875. /*
  2876. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  2877. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  2878. */
  2879. BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  2880. /*
  2881. * Raises the priority of the mutex holder to that of the calling task should
  2882. * the mutex holder have a priority less than the calling task.
  2883. */
  2884. BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2885. /*
  2886. * Set the priority of a task back to its proper priority in the case that it
  2887. * inherited a higher priority while it was holding a semaphore.
  2888. */
  2889. BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2890. /*
  2891. * If a higher priority task attempting to obtain a mutex caused a lower
  2892. * priority task to inherit the higher priority task's priority - but the higher
  2893. * priority task then timed out without obtaining the mutex, then the lower
  2894. * priority task will disinherit the priority again - but only down as far as
  2895. * the highest priority task that is still waiting for the mutex (if there were
  2896. * more than one task waiting for the mutex).
  2897. */
  2898. void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder,
  2899. UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
  2900. /*
  2901. * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
  2902. */
  2903. UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  2904. /*
  2905. * Set the uxTaskNumber of the task referenced by the xTask parameter to
  2906. * uxHandle.
  2907. */
  2908. void vTaskSetTaskNumber( TaskHandle_t xTask,
  2909. const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
  2910. /*
  2911. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2912. * If tickless mode is being used, or a low power mode is implemented, then
  2913. * the tick interrupt will not execute during idle periods. When this is the
  2914. * case, the tick count value maintained by the scheduler needs to be kept up
  2915. * to date with the actual execution time by being skipped forward by a time
  2916. * equal to the idle period.
  2917. */
  2918. void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
  2919. /*
  2920. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2921. * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
  2922. * specific sleep function to determine if it is ok to proceed with the sleep,
  2923. * and if it is ok to proceed, if it is ok to sleep indefinitely.
  2924. *
  2925. * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
  2926. * called with the scheduler suspended, not from within a critical section. It
  2927. * is therefore possible for an interrupt to request a context switch between
  2928. * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
  2929. * entered. eTaskConfirmSleepModeStatus() should be called from a short
  2930. * critical section between the timer being stopped and the sleep mode being
  2931. * entered to ensure it is ok to proceed into the sleep mode.
  2932. */
  2933. eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
  2934. /*
  2935. * For internal use only. Increment the mutex held count when a mutex is
  2936. * taken and return the handle of the task that has taken the mutex.
  2937. */
  2938. TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
  2939. /*
  2940. * For internal use only. Same as vTaskSetTimeOutState(), but without a critical
  2941. * section.
  2942. */
  2943. void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2944. /* *INDENT-OFF* */
  2945. #ifdef __cplusplus
  2946. }
  2947. #endif
  2948. /* *INDENT-ON* */
  2949. #endif /* INC_TASK_H */