task.h 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef INC_TASK_H
  29. #define INC_TASK_H
  30. #ifndef INC_FREERTOS_H
  31. #error "include FreeRTOS.h must appear in source files before include task.h"
  32. #endif
  33. #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.6"
  50. #define tskKERNEL_VERSION_MAJOR 10
  51. #define tskKERNEL_VERSION_MINOR 4
  52. #define tskKERNEL_VERSION_BUILD 6
  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. configRUN_TIME_COUNTER_TYPE 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. * @code{c}
  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. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  448. * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
  449. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  525. * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
  526. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  614. * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
  615. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  663. * void vTaskDelete( TaskHandle_t xTaskToDelete );
  664. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  708. * void vTaskDelay( const TickType_t xTicksToDelay );
  709. * @endcode
  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 affect 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. * @code{c}
  757. * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  758. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  832. * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  833. * @endcode
  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. * @code{c}
  863. * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  864. * @endcode
  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. * @code{c}
  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. * @endcode
  904. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  905. * \ingroup TaskCtrl
  906. */
  907. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  908. /**
  909. * task. h
  910. * @code{c}
  911. * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  912. * @endcode
  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. * @code{c}
  920. * eTaskState eTaskGetState( TaskHandle_t xTask );
  921. * @endcode
  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. * @code{c}
  939. * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
  940. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  999. * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  1000. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  1043. * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  1044. * @endcode
  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. * @code{c}
  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. * @endcode
  1088. * \defgroup vTaskSuspend vTaskSuspend
  1089. * \ingroup TaskCtrl
  1090. */
  1091. void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
  1092. /**
  1093. * task. h
  1094. * @code{c}
  1095. * void vTaskResume( TaskHandle_t xTaskToResume );
  1096. * @endcode
  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. * @code{c}
  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. * @endcode
  1138. * \defgroup vTaskResume vTaskResume
  1139. * \ingroup TaskCtrl
  1140. */
  1141. void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1142. /**
  1143. * task. h
  1144. * @code{c}
  1145. * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  1146. * @endcode
  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. * @code{c}
  1178. * void vTaskStartScheduler( void );
  1179. * @endcode
  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. * @code{c}
  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. * @endcode
  1200. *
  1201. * \defgroup vTaskStartScheduler vTaskStartScheduler
  1202. * \ingroup SchedulerControl
  1203. */
  1204. void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
  1205. /**
  1206. * task. h
  1207. * @code{c}
  1208. * void vTaskEndScheduler( void );
  1209. * @endcode
  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. * @code{c}
  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. * @endcode
  1257. *
  1258. * \defgroup vTaskEndScheduler vTaskEndScheduler
  1259. * \ingroup SchedulerControl
  1260. */
  1261. void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
  1262. /**
  1263. * task. h
  1264. * @code{c}
  1265. * void vTaskSuspendAll( void );
  1266. * @endcode
  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. * @code{c}
  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. * @endcode
  1310. * \defgroup vTaskSuspendAll vTaskSuspendAll
  1311. * \ingroup SchedulerControl
  1312. */
  1313. void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
  1314. /**
  1315. * task. h
  1316. * @code{c}
  1317. * BaseType_t xTaskResumeAll( void );
  1318. * @endcode
  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. * @code{c}
  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. * @endcode
  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. * @code{c}
  1375. * TickType_t xTaskGetTickCount( void );
  1376. * @endcode
  1377. *
  1378. * @return The count of ticks since vTaskStartScheduler was called.
  1379. *
  1380. * \defgroup xTaskGetTickCount xTaskGetTickCount
  1381. * \ingroup TaskUtils
  1382. */
  1383. TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
  1384. /**
  1385. * task. h
  1386. * @code{c}
  1387. * TickType_t xTaskGetTickCountFromISR( void );
  1388. * @endcode
  1389. *
  1390. * @return The count of ticks since vTaskStartScheduler was called.
  1391. *
  1392. * This is a version of xTaskGetTickCount() that is safe to be called from an
  1393. * ISR - provided that TickType_t is the natural word size of the
  1394. * microcontroller being used or interrupt nesting is either not supported or
  1395. * not being used.
  1396. *
  1397. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  1398. * \ingroup TaskUtils
  1399. */
  1400. TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
  1401. /**
  1402. * task. h
  1403. * @code{c}
  1404. * uint16_t uxTaskGetNumberOfTasks( void );
  1405. * @endcode
  1406. *
  1407. * @return The number of tasks that the real time kernel is currently managing.
  1408. * This includes all ready, blocked and suspended tasks. A task that
  1409. * has been deleted but not yet freed by the idle task will also be
  1410. * included in the count.
  1411. *
  1412. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  1413. * \ingroup TaskUtils
  1414. */
  1415. UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
  1416. /**
  1417. * task. h
  1418. * @code{c}
  1419. * char *pcTaskGetName( TaskHandle_t xTaskToQuery );
  1420. * @endcode
  1421. *
  1422. * @return The text (human readable) name of the task referenced by the handle
  1423. * xTaskToQuery. A task can query its own name by either passing in its own
  1424. * handle, or by setting xTaskToQuery to NULL.
  1425. *
  1426. * \defgroup pcTaskGetName pcTaskGetName
  1427. * \ingroup TaskUtils
  1428. */
  1429. char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1430. /**
  1431. * task. h
  1432. * @code{c}
  1433. * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
  1434. * @endcode
  1435. *
  1436. * NOTE: This function takes a relatively long time to complete and should be
  1437. * used sparingly.
  1438. *
  1439. * @return The handle of the task that has the human readable name pcNameToQuery.
  1440. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1441. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1442. *
  1443. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1444. * \ingroup TaskUtils
  1445. */
  1446. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1447. /**
  1448. * task.h
  1449. * @code{c}
  1450. * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  1451. * @endcode
  1452. *
  1453. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1454. * this function to be available.
  1455. *
  1456. * Returns the high water mark of the stack associated with xTask. That is,
  1457. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1458. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1459. * number the closer the task has come to overflowing its stack.
  1460. *
  1461. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1462. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1463. * user to determine the return type. It gets around the problem of the value
  1464. * overflowing on 8-bit types without breaking backward compatibility for
  1465. * applications that expect an 8-bit return type.
  1466. *
  1467. * @param xTask Handle of the task associated with the stack to be checked.
  1468. * Set xTask to NULL to check the stack of the calling task.
  1469. *
  1470. * @return The smallest amount of free stack space there has been (in words, so
  1471. * actual spaces on the stack rather than bytes) since the task referenced by
  1472. * xTask was created.
  1473. */
  1474. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1475. /**
  1476. * task.h
  1477. * @code{c}
  1478. * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  1479. * @endcode
  1480. *
  1481. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1482. * this function to be available.
  1483. *
  1484. * Returns the high water mark of the stack associated with xTask. That is,
  1485. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1486. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1487. * number the closer the task has come to overflowing its stack.
  1488. *
  1489. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1490. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1491. * user to determine the return type. It gets around the problem of the value
  1492. * overflowing on 8-bit types without breaking backward compatibility for
  1493. * applications that expect an 8-bit return type.
  1494. *
  1495. * @param xTask Handle of the task associated with the stack to be checked.
  1496. * Set xTask to NULL to check the stack of the calling task.
  1497. *
  1498. * @return The smallest amount of free stack space there has been (in words, so
  1499. * actual spaces on the stack rather than bytes) since the task referenced by
  1500. * xTask was created.
  1501. */
  1502. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1503. /* When using trace macros it is sometimes necessary to include task.h before
  1504. * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1505. * so the following two prototypes will cause a compilation error. This can be
  1506. * fixed by simply guarding against the inclusion of these two prototypes unless
  1507. * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1508. * constant. */
  1509. #ifdef configUSE_APPLICATION_TASK_TAG
  1510. #if configUSE_APPLICATION_TASK_TAG == 1
  1511. /**
  1512. * task.h
  1513. * @code{c}
  1514. * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  1515. * @endcode
  1516. *
  1517. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1518. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1519. * function.
  1520. */
  1521. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  1522. TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
  1523. /**
  1524. * task.h
  1525. * @code{c}
  1526. * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1527. * @endcode
  1528. *
  1529. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1530. * call from an interrupt service routine - call
  1531. * xTaskGetApplicationTaskTagFromISR() instead.
  1532. */
  1533. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1534. /**
  1535. * task.h
  1536. * @code{c}
  1537. * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1538. * @endcode
  1539. *
  1540. * Returns the pxHookFunction value assigned to the task xTask. Can
  1541. * be called from an interrupt service routine.
  1542. */
  1543. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1544. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1545. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1546. #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  1547. /* Each task contains an array of pointers that is dimensioned by the
  1548. * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
  1549. * kernel does not use the pointers itself, so the application writer can use
  1550. * the pointers for any purpose they wish. The following two functions are
  1551. * used to set and query a pointer respectively. */
  1552. void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  1553. BaseType_t xIndex,
  1554. void * pvValue ) PRIVILEGED_FUNCTION;
  1555. void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  1556. BaseType_t xIndex ) PRIVILEGED_FUNCTION;
  1557. #endif
  1558. #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
  1559. /**
  1560. * task.h
  1561. * @code{c}
  1562. * void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName);
  1563. * @endcode
  1564. *
  1565. * The application stack overflow hook is called when a stack overflow is detected for a task.
  1566. *
  1567. * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
  1568. *
  1569. * @param xTask the task that just exceeded its stack boundaries.
  1570. * @param pcTaskName A character string containing the name of the offending task.
  1571. */
  1572. void vApplicationStackOverflowHook( TaskHandle_t xTask,
  1573. char * pcTaskName );
  1574. #endif
  1575. #if ( configUSE_TICK_HOOK > 0 )
  1576. /**
  1577. * task.h
  1578. * @code{c}
  1579. * void vApplicationTickHook( void );
  1580. * @endcode
  1581. *
  1582. * This hook function is called in the system tick handler after any OS work is completed.
  1583. */
  1584. void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
  1585. #endif
  1586. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1587. /**
  1588. * task.h
  1589. * @code{c}
  1590. * void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
  1591. * @endcode
  1592. *
  1593. * 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
  1594. * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
  1595. *
  1596. * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
  1597. * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
  1598. * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
  1599. */
  1600. void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
  1601. StackType_t ** ppxIdleTaskStackBuffer,
  1602. uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
  1603. #endif
  1604. /**
  1605. * task.h
  1606. * @code{c}
  1607. * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  1608. * @endcode
  1609. *
  1610. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1611. * the effect of calling the Running tasks (the calling task) hook function.
  1612. *
  1613. * pvParameter is passed to the hook function for the task to interpret as it
  1614. * wants. The return value is the value returned by the task hook function
  1615. * registered by the user.
  1616. */
  1617. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  1618. void * pvParameter ) PRIVILEGED_FUNCTION;
  1619. /**
  1620. * xTaskGetIdleTaskHandle() is only available if
  1621. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1622. *
  1623. * Simply returns the handle of the idle task. It is not valid to call
  1624. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1625. */
  1626. TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
  1627. /**
  1628. * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
  1629. * uxTaskGetSystemState() to be available.
  1630. *
  1631. * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
  1632. * the system. TaskStatus_t structures contain, among other things, members
  1633. * for the task handle, task name, task priority, task state, and total amount
  1634. * of run time consumed by the task. See the TaskStatus_t structure
  1635. * definition in this file for the full member list.
  1636. *
  1637. * NOTE: This function is intended for debugging use only as its use results in
  1638. * the scheduler remaining suspended for an extended period.
  1639. *
  1640. * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
  1641. * The array must contain at least one TaskStatus_t structure for each task
  1642. * that is under the control of the RTOS. The number of tasks under the control
  1643. * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
  1644. *
  1645. * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
  1646. * parameter. The size is specified as the number of indexes in the array, or
  1647. * the number of TaskStatus_t structures contained in the array, not by the
  1648. * number of bytes in the array.
  1649. *
  1650. * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
  1651. * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
  1652. * total run time (as defined by the run time stats clock, see
  1653. * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted.
  1654. * pulTotalRunTime can be set to NULL to omit the total run time information.
  1655. *
  1656. * @return The number of TaskStatus_t structures that were populated by
  1657. * uxTaskGetSystemState(). This should equal the number returned by the
  1658. * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
  1659. * in the uxArraySize parameter was too small.
  1660. *
  1661. * Example usage:
  1662. * @code{c}
  1663. * // This example demonstrates how a human readable table of run time stats
  1664. * // information is generated from raw data provided by uxTaskGetSystemState().
  1665. * // The human readable table is written to pcWriteBuffer
  1666. * void vTaskGetRunTimeStats( char *pcWriteBuffer )
  1667. * {
  1668. * TaskStatus_t *pxTaskStatusArray;
  1669. * volatile UBaseType_t uxArraySize, x;
  1670. * configRUN_TIME_COUNTER_TYPE ulTotalRunTime, ulStatsAsPercentage;
  1671. *
  1672. * // Make sure the write buffer does not contain a string.
  1673. * pcWriteBuffer = 0x00;
  1674. *
  1675. * // Take a snapshot of the number of tasks in case it changes while this
  1676. * // function is executing.
  1677. * uxArraySize = uxTaskGetNumberOfTasks();
  1678. *
  1679. * // Allocate a TaskStatus_t structure for each task. An array could be
  1680. * // allocated statically at compile time.
  1681. * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  1682. *
  1683. * if( pxTaskStatusArray != NULL )
  1684. * {
  1685. * // Generate raw status information about each task.
  1686. * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
  1687. *
  1688. * // For percentage calculations.
  1689. * ulTotalRunTime /= 100UL;
  1690. *
  1691. * // Avoid divide by zero errors.
  1692. * if( ulTotalRunTime > 0 )
  1693. * {
  1694. * // For each populated position in the pxTaskStatusArray array,
  1695. * // format the raw data as human readable ASCII data
  1696. * for( x = 0; x < uxArraySize; x++ )
  1697. * {
  1698. * // What percentage of the total run time has the task used?
  1699. * // This will always be rounded down to the nearest integer.
  1700. * // ulTotalRunTimeDiv100 has already been divided by 100.
  1701. * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
  1702. *
  1703. * if( ulStatsAsPercentage > 0UL )
  1704. * {
  1705. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
  1706. * }
  1707. * else
  1708. * {
  1709. * // If the percentage is zero here then the task has
  1710. * // consumed less than 1% of the total run time.
  1711. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
  1712. * }
  1713. *
  1714. * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
  1715. * }
  1716. * }
  1717. *
  1718. * // The array is no longer needed, free the memory it consumes.
  1719. * vPortFree( pxTaskStatusArray );
  1720. * }
  1721. * }
  1722. * @endcode
  1723. */
  1724. UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
  1725. const UBaseType_t uxArraySize,
  1726. configRUN_TIME_COUNTER_TYPE * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
  1727. /**
  1728. * task. h
  1729. * @code{c}
  1730. * void vTaskList( char *pcWriteBuffer );
  1731. * @endcode
  1732. *
  1733. * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
  1734. * both be defined as 1 for this function to be available. See the
  1735. * configuration section of the FreeRTOS.org website for more information.
  1736. *
  1737. * NOTE 1: This function will disable interrupts for its duration. It is
  1738. * not intended for normal application runtime use but as a debug aid.
  1739. *
  1740. * Lists all the current tasks, along with their current state and stack
  1741. * usage high water mark.
  1742. *
  1743. * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
  1744. * suspended ('S').
  1745. *
  1746. * PLEASE NOTE:
  1747. *
  1748. * This function is provided for convenience only, and is used by many of the
  1749. * demo applications. Do not consider it to be part of the scheduler.
  1750. *
  1751. * vTaskList() calls uxTaskGetSystemState(), then formats part of the
  1752. * uxTaskGetSystemState() output into a human readable table that displays task:
  1753. * names, states, priority, stack usage and task number.
  1754. * Stack usage specified as the number of unused StackType_t words stack can hold
  1755. * on top of stack - not the number of bytes.
  1756. *
  1757. * vTaskList() has a dependency on the sprintf() C library function that might
  1758. * bloat the code size, use a lot of stack, and provide different results on
  1759. * different platforms. An alternative, tiny, third party, and limited
  1760. * functionality implementation of sprintf() is provided in many of the
  1761. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1762. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1763. *
  1764. * It is recommended that production systems call uxTaskGetSystemState()
  1765. * directly to get access to raw stats data, rather than indirectly through a
  1766. * call to vTaskList().
  1767. *
  1768. * @param pcWriteBuffer A buffer into which the above mentioned details
  1769. * will be written, in ASCII form. This buffer is assumed to be large
  1770. * enough to contain the generated report. Approximately 40 bytes per
  1771. * task should be sufficient.
  1772. *
  1773. * \defgroup vTaskList vTaskList
  1774. * \ingroup TaskUtils
  1775. */
  1776. void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1777. /**
  1778. * task. h
  1779. * @code{c}
  1780. * void vTaskGetRunTimeStats( char *pcWriteBuffer );
  1781. * @endcode
  1782. *
  1783. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1784. * must both be defined as 1 for this function to be available. The application
  1785. * must also then provide definitions for
  1786. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1787. * to configure a peripheral timer/counter and return the timers current count
  1788. * value respectively. The counter should be at least 10 times the frequency of
  1789. * the tick count.
  1790. *
  1791. * NOTE 1: This function will disable interrupts for its duration. It is
  1792. * not intended for normal application runtime use but as a debug aid.
  1793. *
  1794. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1795. * accumulated execution time being stored for each task. The resolution
  1796. * of the accumulated time value depends on the frequency of the timer
  1797. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1798. * Calling vTaskGetRunTimeStats() writes the total execution time of each
  1799. * task into a buffer, both as an absolute count value and as a percentage
  1800. * of the total system execution time.
  1801. *
  1802. * NOTE 2:
  1803. *
  1804. * This function is provided for convenience only, and is used by many of the
  1805. * demo applications. Do not consider it to be part of the scheduler.
  1806. *
  1807. * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
  1808. * uxTaskGetSystemState() output into a human readable table that displays the
  1809. * amount of time each task has spent in the Running state in both absolute and
  1810. * percentage terms.
  1811. *
  1812. * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
  1813. * that might bloat the code size, use a lot of stack, and provide different
  1814. * results on different platforms. An alternative, tiny, third party, and
  1815. * limited functionality implementation of sprintf() is provided in many of the
  1816. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1817. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1818. *
  1819. * It is recommended that production systems call uxTaskGetSystemState() directly
  1820. * to get access to raw stats data, rather than indirectly through a call to
  1821. * vTaskGetRunTimeStats().
  1822. *
  1823. * @param pcWriteBuffer A buffer into which the execution times will be
  1824. * written, in ASCII form. This buffer is assumed to be large enough to
  1825. * contain the generated report. Approximately 40 bytes per task should
  1826. * be sufficient.
  1827. *
  1828. * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
  1829. * \ingroup TaskUtils
  1830. */
  1831. void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1832. /**
  1833. * task. h
  1834. * @code{c}
  1835. * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void );
  1836. * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void );
  1837. * @endcode
  1838. *
  1839. * configGENERATE_RUN_TIME_STATS, configUSE_STATS_FORMATTING_FUNCTIONS and
  1840. * INCLUDE_xTaskGetIdleTaskHandle must all be defined as 1 for these functions
  1841. * to be available. The application must also then provide definitions for
  1842. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1843. * to configure a peripheral timer/counter and return the timers current count
  1844. * value respectively. The counter should be at least 10 times the frequency of
  1845. * the tick count.
  1846. *
  1847. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1848. * accumulated execution time being stored for each task. The resolution
  1849. * of the accumulated time value depends on the frequency of the timer
  1850. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1851. * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
  1852. * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
  1853. * returns the total execution time of just the idle task and
  1854. * ulTaskGetIdleRunTimePercent() returns the percentage of the CPU time used by
  1855. * just the idle task.
  1856. *
  1857. * Note the amount of idle time is only a good measure of the slack time in a
  1858. * system if there are no other tasks executing at the idle priority, tickless
  1859. * idle is not used, and configIDLE_SHOULD_YIELD is set to 0.
  1860. *
  1861. * @return The total run time of the idle task or the percentage of the total
  1862. * run time consumed by the idle task. This is the amount of time the
  1863. * idle task has actually been executing. The unit of time is dependent on the
  1864. * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
  1865. * portGET_RUN_TIME_COUNTER_VALUE() macros.
  1866. *
  1867. * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
  1868. * \ingroup TaskUtils
  1869. */
  1870. configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
  1871. configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ) PRIVILEGED_FUNCTION;
  1872. /**
  1873. * task. h
  1874. * @code{c}
  1875. * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
  1876. * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
  1877. * @endcode
  1878. *
  1879. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1880. *
  1881. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1882. * functions to be available.
  1883. *
  1884. * Sends a direct to task notification to a task, with an optional value and
  1885. * action.
  1886. *
  1887. * Each task has a private array of "notification values" (or 'notifications'),
  1888. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1889. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1890. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1891. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1892. *
  1893. * Events can be sent to a task using an intermediary object. Examples of such
  1894. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1895. * are a method of sending an event directly to a task without the need for such
  1896. * an intermediary object.
  1897. *
  1898. * A notification sent to a task can optionally perform an action, such as
  1899. * update, overwrite or increment one of the task's notification values. In
  1900. * that way task notifications can be used to send data to a task, or be used as
  1901. * light weight and fast binary or counting semaphores.
  1902. *
  1903. * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
  1904. * [optionally] block to wait for a notification to be pending. The task does
  1905. * not consume any CPU time while it is in the Blocked state.
  1906. *
  1907. * A notification sent to a task will remain pending until it is cleared by the
  1908. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1909. * un-indexed equivalents). If the task was already in the Blocked state to
  1910. * wait for a notification when the notification arrives then the task will
  1911. * automatically be removed from the Blocked state (unblocked) and the
  1912. * notification cleared.
  1913. *
  1914. * **NOTE** Each notification within the array operates independently - a task
  1915. * can only block on one notification within the array at a time and will not be
  1916. * unblocked by a notification sent to any other array index.
  1917. *
  1918. * Backward compatibility information:
  1919. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1920. * all task notification API functions operated on that value. Replacing the
  1921. * single notification value with an array of notification values necessitated a
  1922. * new set of API functions that could address specific notifications within the
  1923. * array. xTaskNotify() is the original API function, and remains backward
  1924. * compatible by always operating on the notification value at index 0 in the
  1925. * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  1926. * with the uxIndexToNotify parameter set to 0.
  1927. *
  1928. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1929. * task can be returned from the xTaskCreate() API function used to create the
  1930. * task, and the handle of the currently running task can be obtained by calling
  1931. * xTaskGetCurrentTaskHandle().
  1932. *
  1933. * @param uxIndexToNotify The index within the target task's array of
  1934. * notification values to which the notification is to be sent. uxIndexToNotify
  1935. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  1936. * not have this parameter and always sends notifications to index 0.
  1937. *
  1938. * @param ulValue Data that can be sent with the notification. How the data is
  1939. * used depends on the value of the eAction parameter.
  1940. *
  1941. * @param eAction Specifies how the notification updates the task's notification
  1942. * value, if at all. Valid values for eAction are as follows:
  1943. *
  1944. * eSetBits -
  1945. * The target notification value is bitwise ORed with ulValue.
  1946. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1947. *
  1948. * eIncrement -
  1949. * The target notification value is incremented. ulValue is not used and
  1950. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1951. *
  1952. * eSetValueWithOverwrite -
  1953. * The target notification value is set to the value of ulValue, even if the
  1954. * task being notified had not yet processed the previous notification at the
  1955. * same array index (the task already had a notification pending at that index).
  1956. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1957. *
  1958. * eSetValueWithoutOverwrite -
  1959. * If the task being notified did not already have a notification pending at the
  1960. * same array index then the target notification value is set to ulValue and
  1961. * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  1962. * had a notification pending at the same array index then no action is
  1963. * performed and pdFAIL is returned.
  1964. *
  1965. * eNoAction -
  1966. * The task receives a notification at the specified array index without the
  1967. * notification value at that index being updated. ulValue is not used and
  1968. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1969. *
  1970. * pulPreviousNotificationValue -
  1971. * Can be used to pass out the subject task's notification value before any
  1972. * bits are modified by the notify function.
  1973. *
  1974. * @return Dependent on the value of eAction. See the description of the
  1975. * eAction parameter.
  1976. *
  1977. * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  1978. * \ingroup TaskNotifications
  1979. */
  1980. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  1981. UBaseType_t uxIndexToNotify,
  1982. uint32_t ulValue,
  1983. eNotifyAction eAction,
  1984. uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
  1985. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  1986. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  1987. #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  1988. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  1989. /**
  1990. * task. h
  1991. * @code{c}
  1992. * BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  1993. * BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  1994. * @endcode
  1995. *
  1996. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1997. *
  1998. * xTaskNotifyAndQueryIndexed() performs the same operation as
  1999. * xTaskNotifyIndexed() with the addition that it also returns the subject
  2000. * task's prior notification value (the notification value at the time the
  2001. * function is called rather than when the function returns) in the additional
  2002. * pulPreviousNotifyValue parameter.
  2003. *
  2004. * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
  2005. * addition that it also returns the subject task's prior notification value
  2006. * (the notification value as it was at the time the function is called, rather
  2007. * than when the function returns) in the additional pulPreviousNotifyValue
  2008. * parameter.
  2009. *
  2010. * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
  2011. * \ingroup TaskNotifications
  2012. */
  2013. #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  2014. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  2015. #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  2016. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  2017. /**
  2018. * task. h
  2019. * @code{c}
  2020. * BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  2021. * BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  2022. * @endcode
  2023. *
  2024. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2025. *
  2026. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2027. * functions to be available.
  2028. *
  2029. * A version of xTaskNotifyIndexed() that can be used from an interrupt service
  2030. * routine (ISR).
  2031. *
  2032. * Each task has a private array of "notification values" (or 'notifications'),
  2033. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2034. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2035. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2036. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2037. *
  2038. * Events can be sent to a task using an intermediary object. Examples of such
  2039. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2040. * are a method of sending an event directly to a task without the need for such
  2041. * an intermediary object.
  2042. *
  2043. * A notification sent to a task can optionally perform an action, such as
  2044. * update, overwrite or increment one of the task's notification values. In
  2045. * that way task notifications can be used to send data to a task, or be used as
  2046. * light weight and fast binary or counting semaphores.
  2047. *
  2048. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  2049. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  2050. * to wait for a notification value to have a non-zero value. The task does
  2051. * not consume any CPU time while it is in the Blocked state.
  2052. *
  2053. * A notification sent to a task will remain pending until it is cleared by the
  2054. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2055. * un-indexed equivalents). If the task was already in the Blocked state to
  2056. * wait for a notification when the notification arrives then the task will
  2057. * automatically be removed from the Blocked state (unblocked) and the
  2058. * notification cleared.
  2059. *
  2060. * **NOTE** Each notification within the array operates independently - a task
  2061. * can only block on one notification within the array at a time and will not be
  2062. * unblocked by a notification sent to any other array index.
  2063. *
  2064. * Backward compatibility information:
  2065. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2066. * all task notification API functions operated on that value. Replacing the
  2067. * single notification value with an array of notification values necessitated a
  2068. * new set of API functions that could address specific notifications within the
  2069. * array. xTaskNotifyFromISR() is the original API function, and remains
  2070. * backward compatible by always operating on the notification value at index 0
  2071. * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
  2072. * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2073. *
  2074. * @param uxIndexToNotify The index within the target task's array of
  2075. * notification values to which the notification is to be sent. uxIndexToNotify
  2076. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
  2077. * does not have this parameter and always sends notifications to index 0.
  2078. *
  2079. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2080. * task can be returned from the xTaskCreate() API function used to create the
  2081. * task, and the handle of the currently running task can be obtained by calling
  2082. * xTaskGetCurrentTaskHandle().
  2083. *
  2084. * @param ulValue Data that can be sent with the notification. How the data is
  2085. * used depends on the value of the eAction parameter.
  2086. *
  2087. * @param eAction Specifies how the notification updates the task's notification
  2088. * value, if at all. Valid values for eAction are as follows:
  2089. *
  2090. * eSetBits -
  2091. * The task's notification value is bitwise ORed with ulValue. xTaskNotify()
  2092. * always returns pdPASS in this case.
  2093. *
  2094. * eIncrement -
  2095. * The task's notification value is incremented. ulValue is not used and
  2096. * xTaskNotify() always returns pdPASS in this case.
  2097. *
  2098. * eSetValueWithOverwrite -
  2099. * The task's notification value is set to the value of ulValue, even if the
  2100. * task being notified had not yet processed the previous notification (the
  2101. * task already had a notification pending). xTaskNotify() always returns
  2102. * pdPASS in this case.
  2103. *
  2104. * eSetValueWithoutOverwrite -
  2105. * If the task being notified did not already have a notification pending then
  2106. * the task's notification value is set to ulValue and xTaskNotify() will
  2107. * return pdPASS. If the task being notified already had a notification
  2108. * pending then no action is performed and pdFAIL is returned.
  2109. *
  2110. * eNoAction -
  2111. * The task receives a notification without its notification value being
  2112. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  2113. * this case.
  2114. *
  2115. * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  2116. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2117. * task to which the notification was sent to leave the Blocked state, and the
  2118. * unblocked task has a priority higher than the currently running task. If
  2119. * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  2120. * be requested before the interrupt is exited. How a context switch is
  2121. * requested from an ISR is dependent on the port - see the documentation page
  2122. * for the port in use.
  2123. *
  2124. * @return Dependent on the value of eAction. See the description of the
  2125. * eAction parameter.
  2126. *
  2127. * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
  2128. * \ingroup TaskNotifications
  2129. */
  2130. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  2131. UBaseType_t uxIndexToNotify,
  2132. uint32_t ulValue,
  2133. eNotifyAction eAction,
  2134. uint32_t * pulPreviousNotificationValue,
  2135. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2136. #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2137. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2138. #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2139. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2140. /**
  2141. * task. h
  2142. * @code{c}
  2143. * BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  2144. * BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  2145. * @endcode
  2146. *
  2147. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2148. *
  2149. * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
  2150. * xTaskNotifyIndexedFromISR() with the addition that it also returns the
  2151. * subject task's prior notification value (the notification value at the time
  2152. * the function is called rather than at the time the function returns) in the
  2153. * additional pulPreviousNotifyValue parameter.
  2154. *
  2155. * xTaskNotifyAndQueryFromISR() performs the same operation as
  2156. * xTaskNotifyFromISR() with the addition that it also returns the subject
  2157. * task's prior notification value (the notification value at the time the
  2158. * function is called rather than at the time the function returns) in the
  2159. * additional pulPreviousNotifyValue parameter.
  2160. *
  2161. * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
  2162. * \ingroup TaskNotifications
  2163. */
  2164. #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2165. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2166. #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2167. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2168. /**
  2169. * task. h
  2170. * @code{c}
  2171. * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2172. *
  2173. * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2174. * @endcode
  2175. *
  2176. * Waits for a direct to task notification to be pending at a given index within
  2177. * an array of direct to task notifications.
  2178. *
  2179. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2180. *
  2181. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2182. * function to be available.
  2183. *
  2184. * Each task has a private array of "notification values" (or 'notifications'),
  2185. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2186. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2187. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2188. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2189. *
  2190. * Events can be sent to a task using an intermediary object. Examples of such
  2191. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2192. * are a method of sending an event directly to a task without the need for such
  2193. * an intermediary object.
  2194. *
  2195. * A notification sent to a task can optionally perform an action, such as
  2196. * update, overwrite or increment one of the task's notification values. In
  2197. * that way task notifications can be used to send data to a task, or be used as
  2198. * light weight and fast binary or counting semaphores.
  2199. *
  2200. * A notification sent to a task will remain pending until it is cleared by the
  2201. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2202. * un-indexed equivalents). If the task was already in the Blocked state to
  2203. * wait for a notification when the notification arrives then the task will
  2204. * automatically be removed from the Blocked state (unblocked) and the
  2205. * notification cleared.
  2206. *
  2207. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  2208. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  2209. * to wait for a notification value to have a non-zero value. The task does
  2210. * not consume any CPU time while it is in the Blocked state.
  2211. *
  2212. * **NOTE** Each notification within the array operates independently - a task
  2213. * can only block on one notification within the array at a time and will not be
  2214. * unblocked by a notification sent to any other array index.
  2215. *
  2216. * Backward compatibility information:
  2217. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2218. * all task notification API functions operated on that value. Replacing the
  2219. * single notification value with an array of notification values necessitated a
  2220. * new set of API functions that could address specific notifications within the
  2221. * array. xTaskNotifyWait() is the original API function, and remains backward
  2222. * compatible by always operating on the notification value at index 0 in the
  2223. * array. Calling xTaskNotifyWait() is equivalent to calling
  2224. * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  2225. *
  2226. * @param uxIndexToWaitOn The index within the calling task's array of
  2227. * notification values on which the calling task will wait for a notification to
  2228. * be received. uxIndexToWaitOn must be less than
  2229. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  2230. * not have this parameter and always waits for notifications on index 0.
  2231. *
  2232. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  2233. * will be cleared in the calling task's notification value before the task
  2234. * checks to see if any notifications are pending, and optionally blocks if no
  2235. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  2236. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  2237. * the effect of resetting the task's notification value to 0. Setting
  2238. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  2239. *
  2240. * @param ulBitsToClearOnExit If a notification is pending or received before
  2241. * the calling task exits the xTaskNotifyWait() function then the task's
  2242. * notification value (see the xTaskNotify() API function) is passed out using
  2243. * the pulNotificationValue parameter. Then any bits that are set in
  2244. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  2245. * *pulNotificationValue is set before any bits are cleared). Setting
  2246. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  2247. * (if limits.h is not included) will have the effect of resetting the task's
  2248. * notification value to 0 before the function exits. Setting
  2249. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  2250. * when the function exits (in which case the value passed out in
  2251. * pulNotificationValue will match the task's notification value).
  2252. *
  2253. * @param pulNotificationValue Used to pass the task's notification value out
  2254. * of the function. Note the value passed out will not be effected by the
  2255. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  2256. *
  2257. * @param xTicksToWait The maximum amount of time that the task should wait in
  2258. * the Blocked state for a notification to be received, should a notification
  2259. * not already be pending when xTaskNotifyWait() was called. The task
  2260. * will not consume any processing time while it is in the Blocked state. This
  2261. * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
  2262. * used to convert a time specified in milliseconds to a time specified in
  2263. * ticks.
  2264. *
  2265. * @return If a notification was received (including notifications that were
  2266. * already pending when xTaskNotifyWait was called) then pdPASS is
  2267. * returned. Otherwise pdFAIL is returned.
  2268. *
  2269. * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  2270. * \ingroup TaskNotifications
  2271. */
  2272. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  2273. uint32_t ulBitsToClearOnEntry,
  2274. uint32_t ulBitsToClearOnExit,
  2275. uint32_t * pulNotificationValue,
  2276. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2277. #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2278. xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2279. #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2280. xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2281. /**
  2282. * task. h
  2283. * @code{c}
  2284. * BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );
  2285. * BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
  2286. * @endcode
  2287. *
  2288. * Sends a direct to task notification to a particular index in the target
  2289. * task's notification array in a manner similar to giving a counting semaphore.
  2290. *
  2291. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2292. *
  2293. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2294. * macros to be available.
  2295. *
  2296. * Each task has a private array of "notification values" (or 'notifications'),
  2297. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2298. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2299. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2300. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2301. *
  2302. * Events can be sent to a task using an intermediary object. Examples of such
  2303. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2304. * are a method of sending an event directly to a task without the need for such
  2305. * an intermediary object.
  2306. *
  2307. * A notification sent to a task can optionally perform an action, such as
  2308. * update, overwrite or increment one of the task's notification values. In
  2309. * that way task notifications can be used to send data to a task, or be used as
  2310. * light weight and fast binary or counting semaphores.
  2311. *
  2312. * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
  2313. * notifications are used as light weight and faster binary or counting
  2314. * semaphore equivalents. Actual FreeRTOS semaphores are given using the
  2315. * xSemaphoreGive() API function, the equivalent action that instead uses a task
  2316. * notification is xTaskNotifyGiveIndexed().
  2317. *
  2318. * When task notifications are being used as a binary or counting semaphore
  2319. * equivalent then the task being notified should wait for the notification
  2320. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2321. * xTaskNotifyWaitIndexed() API function.
  2322. *
  2323. * **NOTE** Each notification within the array operates independently - a task
  2324. * can only block on one notification within the array at a time and will not be
  2325. * unblocked by a notification sent to any other array index.
  2326. *
  2327. * Backward compatibility information:
  2328. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2329. * all task notification API functions operated on that value. Replacing the
  2330. * single notification value with an array of notification values necessitated a
  2331. * new set of API functions that could address specific notifications within the
  2332. * array. xTaskNotifyGive() is the original API function, and remains backward
  2333. * compatible by always operating on the notification value at index 0 in the
  2334. * array. Calling xTaskNotifyGive() is equivalent to calling
  2335. * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
  2336. *
  2337. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2338. * task can be returned from the xTaskCreate() API function used to create the
  2339. * task, and the handle of the currently running task can be obtained by calling
  2340. * xTaskGetCurrentTaskHandle().
  2341. *
  2342. * @param uxIndexToNotify The index within the target task's array of
  2343. * notification values to which the notification is to be sent. uxIndexToNotify
  2344. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
  2345. * does not have this parameter and always sends notifications to index 0.
  2346. *
  2347. * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  2348. * eAction parameter set to eIncrement - so pdPASS is always returned.
  2349. *
  2350. * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
  2351. * \ingroup TaskNotifications
  2352. */
  2353. #define xTaskNotifyGive( xTaskToNotify ) \
  2354. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
  2355. #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
  2356. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
  2357. /**
  2358. * task. h
  2359. * @code{c}
  2360. * void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );
  2361. * void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
  2362. * @endcode
  2363. *
  2364. * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
  2365. * service routine (ISR).
  2366. *
  2367. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2368. *
  2369. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  2370. * to be available.
  2371. *
  2372. * Each task has a private array of "notification values" (or 'notifications'),
  2373. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2374. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2375. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2376. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2377. *
  2378. * Events can be sent to a task using an intermediary object. Examples of such
  2379. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2380. * are a method of sending an event directly to a task without the need for such
  2381. * an intermediary object.
  2382. *
  2383. * A notification sent to a task can optionally perform an action, such as
  2384. * update, overwrite or increment one of the task's notification values. In
  2385. * that way task notifications can be used to send data to a task, or be used as
  2386. * light weight and fast binary or counting semaphores.
  2387. *
  2388. * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
  2389. * are used as light weight and faster binary or counting semaphore equivalents.
  2390. * Actual FreeRTOS semaphores are given from an ISR using the
  2391. * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  2392. * a task notification is vTaskNotifyGiveIndexedFromISR().
  2393. *
  2394. * When task notifications are being used as a binary or counting semaphore
  2395. * equivalent then the task being notified should wait for the notification
  2396. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2397. * xTaskNotifyWaitIndexed() API function.
  2398. *
  2399. * **NOTE** Each notification within the array operates independently - a task
  2400. * can only block on one notification within the array at a time and will not be
  2401. * unblocked by a notification sent to any other array index.
  2402. *
  2403. * Backward compatibility information:
  2404. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2405. * all task notification API functions operated on that value. Replacing the
  2406. * single notification value with an array of notification values necessitated a
  2407. * new set of API functions that could address specific notifications within the
  2408. * array. xTaskNotifyFromISR() is the original API function, and remains
  2409. * backward compatible by always operating on the notification value at index 0
  2410. * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
  2411. * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2412. *
  2413. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2414. * task can be returned from the xTaskCreate() API function used to create the
  2415. * task, and the handle of the currently running task can be obtained by calling
  2416. * xTaskGetCurrentTaskHandle().
  2417. *
  2418. * @param uxIndexToNotify The index within the target task's array of
  2419. * notification values to which the notification is to be sent. uxIndexToNotify
  2420. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2421. * xTaskNotifyGiveFromISR() does not have this parameter and always sends
  2422. * notifications to index 0.
  2423. *
  2424. * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  2425. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2426. * task to which the notification was sent to leave the Blocked state, and the
  2427. * unblocked task has a priority higher than the currently running task. If
  2428. * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  2429. * should be requested before the interrupt is exited. How a context switch is
  2430. * requested from an ISR is dependent on the port - see the documentation page
  2431. * for the port in use.
  2432. *
  2433. * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
  2434. * \ingroup TaskNotifications
  2435. */
  2436. void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  2437. UBaseType_t uxIndexToNotify,
  2438. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2439. #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
  2440. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
  2441. #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
  2442. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
  2443. /**
  2444. * task. h
  2445. * @code{c}
  2446. * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2447. *
  2448. * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2449. * @endcode
  2450. *
  2451. * Waits for a direct to task notification on a particular index in the calling
  2452. * task's notification array in a manner similar to taking a counting semaphore.
  2453. *
  2454. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2455. *
  2456. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2457. * function to be available.
  2458. *
  2459. * Each task has a private array of "notification values" (or 'notifications'),
  2460. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2461. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2462. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2463. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2464. *
  2465. * Events can be sent to a task using an intermediary object. Examples of such
  2466. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2467. * are a method of sending an event directly to a task without the need for such
  2468. * an intermediary object.
  2469. *
  2470. * A notification sent to a task can optionally perform an action, such as
  2471. * update, overwrite or increment one of the task's notification values. In
  2472. * that way task notifications can be used to send data to a task, or be used as
  2473. * light weight and fast binary or counting semaphores.
  2474. *
  2475. * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
  2476. * used as a faster and lighter weight binary or counting semaphore alternative.
  2477. * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
  2478. * the equivalent action that instead uses a task notification is
  2479. * ulTaskNotifyTakeIndexed().
  2480. *
  2481. * When a task is using its notification value as a binary or counting semaphore
  2482. * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
  2483. * macro, or xTaskNotifyIndex() function with the eAction parameter set to
  2484. * eIncrement.
  2485. *
  2486. * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
  2487. * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
  2488. * in which case the notification value acts like a binary semaphore, or
  2489. * decrement the notification value on exit, in which case the notification
  2490. * value acts like a counting semaphore.
  2491. *
  2492. * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
  2493. * a notification. The task does not consume any CPU time while it is in the
  2494. * Blocked state.
  2495. *
  2496. * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
  2497. * ulTaskNotifyTakeIndexed() will return when the task's notification value is
  2498. * not zero.
  2499. *
  2500. * **NOTE** Each notification within the array operates independently - a task
  2501. * can only block on one notification within the array at a time and will not be
  2502. * unblocked by a notification sent to any other array index.
  2503. *
  2504. * Backward compatibility information:
  2505. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2506. * all task notification API functions operated on that value. Replacing the
  2507. * single notification value with an array of notification values necessitated a
  2508. * new set of API functions that could address specific notifications within the
  2509. * array. ulTaskNotifyTake() is the original API function, and remains backward
  2510. * compatible by always operating on the notification value at index 0 in the
  2511. * array. Calling ulTaskNotifyTake() is equivalent to calling
  2512. * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
  2513. *
  2514. * @param uxIndexToWaitOn The index within the calling task's array of
  2515. * notification values on which the calling task will wait for a notification to
  2516. * be non-zero. uxIndexToWaitOn must be less than
  2517. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
  2518. * not have this parameter and always waits for notifications on index 0.
  2519. *
  2520. * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  2521. * notification value is decremented when the function exits. In this way the
  2522. * notification value acts like a counting semaphore. If xClearCountOnExit is
  2523. * not pdFALSE then the task's notification value is cleared to zero when the
  2524. * function exits. In this way the notification value acts like a binary
  2525. * semaphore.
  2526. *
  2527. * @param xTicksToWait The maximum amount of time that the task should wait in
  2528. * the Blocked state for the task's notification value to be greater than zero,
  2529. * should the count not already be greater than zero when
  2530. * ulTaskNotifyTake() was called. The task will not consume any processing
  2531. * time while it is in the Blocked state. This is specified in kernel ticks,
  2532. * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
  2533. * specified in milliseconds to a time specified in ticks.
  2534. *
  2535. * @return The task's notification count before it is either cleared to zero or
  2536. * decremented (see the xClearCountOnExit parameter).
  2537. *
  2538. * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
  2539. * \ingroup TaskNotifications
  2540. */
  2541. uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
  2542. BaseType_t xClearCountOnExit,
  2543. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2544. #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
  2545. ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2546. #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
  2547. ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2548. /**
  2549. * task. h
  2550. * @code{c}
  2551. * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
  2552. *
  2553. * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  2554. * @endcode
  2555. *
  2556. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2557. *
  2558. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2559. * functions to be available.
  2560. *
  2561. * Each task has a private array of "notification values" (or 'notifications'),
  2562. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2563. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2564. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2565. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2566. *
  2567. * If a notification is sent to an index within the array of notifications then
  2568. * the notification at that index is said to be 'pending' until it is read or
  2569. * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
  2570. * is the function that clears a pending notification without reading the
  2571. * notification value. The notification value at the same array index is not
  2572. * altered. Set xTask to NULL to clear the notification state of the calling
  2573. * task.
  2574. *
  2575. * Backward compatibility information:
  2576. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2577. * all task notification API functions operated on that value. Replacing the
  2578. * single notification value with an array of notification values necessitated a
  2579. * new set of API functions that could address specific notifications within the
  2580. * array. xTaskNotifyStateClear() is the original API function, and remains
  2581. * backward compatible by always operating on the notification value at index 0
  2582. * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
  2583. * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
  2584. *
  2585. * @param xTask The handle of the RTOS task that will have a notification state
  2586. * cleared. Set xTask to NULL to clear a notification state in the calling
  2587. * task. To obtain a task's handle create the task using xTaskCreate() and
  2588. * make use of the pxCreatedTask parameter, or create the task using
  2589. * xTaskCreateStatic() and store the returned value, or use the task's name in
  2590. * a call to xTaskGetHandle().
  2591. *
  2592. * @param uxIndexToClear The index within the target task's array of
  2593. * notification values to act upon. For example, setting uxIndexToClear to 1
  2594. * will clear the state of the notification at index 1 within the array.
  2595. * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2596. * ulTaskNotifyStateClear() does not have this parameter and always acts on the
  2597. * notification at index 0.
  2598. *
  2599. * @return pdTRUE if the task's notification state was set to
  2600. * eNotWaitingNotification, otherwise pdFALSE.
  2601. *
  2602. * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
  2603. * \ingroup TaskNotifications
  2604. */
  2605. BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  2606. UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
  2607. #define xTaskNotifyStateClear( xTask ) \
  2608. xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
  2609. #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
  2610. xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
  2611. /**
  2612. * task. h
  2613. * @code{c}
  2614. * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
  2615. *
  2616. * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
  2617. * @endcode
  2618. *
  2619. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2620. *
  2621. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2622. * functions to be available.
  2623. *
  2624. * Each task has a private array of "notification values" (or 'notifications'),
  2625. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2626. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2627. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2628. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2629. *
  2630. * ulTaskNotifyValueClearIndexed() clears the bits specified by the
  2631. * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
  2632. * of the task referenced by xTask.
  2633. *
  2634. * Backward compatibility information:
  2635. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2636. * all task notification API functions operated on that value. Replacing the
  2637. * single notification value with an array of notification values necessitated a
  2638. * new set of API functions that could address specific notifications within the
  2639. * array. ulTaskNotifyValueClear() is the original API function, and remains
  2640. * backward compatible by always operating on the notification value at index 0
  2641. * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
  2642. * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
  2643. *
  2644. * @param xTask The handle of the RTOS task that will have bits in one of its
  2645. * notification values cleared. Set xTask to NULL to clear bits in a
  2646. * notification value of the calling task. To obtain a task's handle create the
  2647. * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
  2648. * create the task using xTaskCreateStatic() and store the returned value, or
  2649. * use the task's name in a call to xTaskGetHandle().
  2650. *
  2651. * @param uxIndexToClear The index within the target task's array of
  2652. * notification values in which to clear the bits. uxIndexToClear
  2653. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2654. * ulTaskNotifyValueClear() does not have this parameter and always clears bits
  2655. * in the notification value at index 0.
  2656. *
  2657. * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
  2658. * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
  2659. * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
  2660. * the notification value to 0. Set ulBitsToClear to 0 to query the task's
  2661. * notification value without clearing any bits.
  2662. *
  2663. *
  2664. * @return The value of the target task's notification value before the bits
  2665. * specified by ulBitsToClear were cleared.
  2666. * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
  2667. * \ingroup TaskNotifications
  2668. */
  2669. uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  2670. UBaseType_t uxIndexToClear,
  2671. uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
  2672. #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
  2673. ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
  2674. #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
  2675. ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
  2676. /**
  2677. * task.h
  2678. * @code{c}
  2679. * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  2680. * @endcode
  2681. *
  2682. * Capture the current time for future use with xTaskCheckForTimeOut().
  2683. *
  2684. * @param pxTimeOut Pointer to a timeout object into which the current time
  2685. * is to be captured. The captured time includes the tick count and the number
  2686. * of times the tick count has overflowed since the system first booted.
  2687. * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
  2688. * \ingroup TaskCtrl
  2689. */
  2690. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2691. /**
  2692. * task.h
  2693. * @code{c}
  2694. * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
  2695. * @endcode
  2696. *
  2697. * Determines if pxTicksToWait ticks has passed since a time was captured
  2698. * using a call to vTaskSetTimeOutState(). The captured time includes the tick
  2699. * count and the number of times the tick count has overflowed.
  2700. *
  2701. * @param pxTimeOut The time status as captured previously using
  2702. * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
  2703. * to reflect the current time status.
  2704. * @param pxTicksToWait The number of ticks to check for timeout i.e. if
  2705. * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
  2706. * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
  2707. * If the timeout has not occurred, pxTicksToWait is updated to reflect the
  2708. * number of remaining ticks.
  2709. *
  2710. * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
  2711. * returned and pxTicksToWait is updated to reflect the number of remaining
  2712. * ticks.
  2713. *
  2714. * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
  2715. *
  2716. * Example Usage:
  2717. * @code{c}
  2718. * // Driver library function used to receive uxWantedBytes from an Rx buffer
  2719. * // that is filled by a UART interrupt. If there are not enough bytes in the
  2720. * // Rx buffer then the task enters the Blocked state until it is notified that
  2721. * // more data has been placed into the buffer. If there is still not enough
  2722. * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
  2723. * // is used to re-calculate the Block time to ensure the total amount of time
  2724. * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
  2725. * // continues until either the buffer contains at least uxWantedBytes bytes,
  2726. * // or the total amount of time spent in the Blocked state reaches
  2727. * // MAX_TIME_TO_WAIT - at which point the task reads however many bytes are
  2728. * // available up to a maximum of uxWantedBytes.
  2729. *
  2730. * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
  2731. * {
  2732. * size_t uxReceived = 0;
  2733. * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
  2734. * TimeOut_t xTimeOut;
  2735. *
  2736. * // Initialize xTimeOut. This records the time at which this function
  2737. * // was entered.
  2738. * vTaskSetTimeOutState( &xTimeOut );
  2739. *
  2740. * // Loop until the buffer contains the wanted number of bytes, or a
  2741. * // timeout occurs.
  2742. * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
  2743. * {
  2744. * // The buffer didn't contain enough data so this task is going to
  2745. * // enter the Blocked state. Adjusting xTicksToWait to account for
  2746. * // any time that has been spent in the Blocked state within this
  2747. * // function so far to ensure the total amount of time spent in the
  2748. * // Blocked state does not exceed MAX_TIME_TO_WAIT.
  2749. * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
  2750. * {
  2751. * //Timed out before the wanted number of bytes were available,
  2752. * // exit the loop.
  2753. * break;
  2754. * }
  2755. *
  2756. * // Wait for a maximum of xTicksToWait ticks to be notified that the
  2757. * // receive interrupt has placed more data into the buffer.
  2758. * ulTaskNotifyTake( pdTRUE, xTicksToWait );
  2759. * }
  2760. *
  2761. * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
  2762. * // The actual number of bytes read (which might be less than
  2763. * // uxWantedBytes) is returned.
  2764. * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
  2765. * pucBuffer,
  2766. * uxWantedBytes );
  2767. *
  2768. * return uxReceived;
  2769. * }
  2770. * @endcode
  2771. * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
  2772. * \ingroup TaskCtrl
  2773. */
  2774. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  2775. TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
  2776. /**
  2777. * task.h
  2778. * @code{c}
  2779. * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
  2780. * @endcode
  2781. *
  2782. * This function corrects the tick count value after the application code has held
  2783. * interrupts disabled for an extended period resulting in tick interrupts having
  2784. * been missed.
  2785. *
  2786. * This function is similar to vTaskStepTick(), however, unlike
  2787. * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
  2788. * time at which a task should be removed from the blocked state. That means
  2789. * tasks may have to be removed from the blocked state as the tick count is
  2790. * moved.
  2791. *
  2792. * @param xTicksToCatchUp The number of tick interrupts that have been missed due to
  2793. * interrupts being disabled. Its value is not computed automatically, so must be
  2794. * computed by the application writer.
  2795. *
  2796. * @return pdTRUE if moving the tick count forward resulted in a task leaving the
  2797. * blocked state and a context switch being performed. Otherwise pdFALSE.
  2798. *
  2799. * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks
  2800. * \ingroup TaskCtrl
  2801. */
  2802. BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
  2803. /*-----------------------------------------------------------
  2804. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  2805. *----------------------------------------------------------*/
  2806. /*
  2807. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2808. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2809. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2810. *
  2811. * Called from the real time kernel tick (either preemptive or cooperative),
  2812. * this increments the tick count and checks if any tasks that are blocked
  2813. * for a finite period required removing from a blocked list and placing on
  2814. * a ready list. If a non-zero value is returned then a context switch is
  2815. * required because either:
  2816. * + A task was removed from a blocked list because its timeout had expired,
  2817. * or
  2818. * + Time slicing is in use and there is a task of equal priority to the
  2819. * currently running task.
  2820. */
  2821. BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
  2822. /*
  2823. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2824. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2825. *
  2826. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2827. *
  2828. * Removes the calling task from the ready list and places it both
  2829. * on the list of tasks waiting for a particular event, and the
  2830. * list of delayed tasks. The task will be removed from both lists
  2831. * and replaced on the ready list should either the event occur (and
  2832. * there be no higher priority tasks waiting on the same event) or
  2833. * the delay period expires.
  2834. *
  2835. * The 'unordered' version replaces the event list item value with the
  2836. * xItemValue value, and inserts the list item at the end of the list.
  2837. *
  2838. * The 'ordered' version uses the existing event list item value (which is the
  2839. * owning task's priority) to insert the list item into the event list in task
  2840. * priority order.
  2841. *
  2842. * @param pxEventList The list containing tasks that are blocked waiting
  2843. * for the event to occur.
  2844. *
  2845. * @param xItemValue The item value to use for the event list item when the
  2846. * event list is not ordered by task priority.
  2847. *
  2848. * @param xTicksToWait The maximum amount of time that the task should wait
  2849. * for the event to occur. This is specified in kernel ticks, the constant
  2850. * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
  2851. * period.
  2852. */
  2853. void vTaskPlaceOnEventList( List_t * const pxEventList,
  2854. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2855. void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
  2856. const TickType_t xItemValue,
  2857. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2858. /*
  2859. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2860. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2861. *
  2862. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2863. *
  2864. * This function performs nearly the same function as vTaskPlaceOnEventList().
  2865. * The difference being that this function does not permit tasks to block
  2866. * indefinitely, whereas vTaskPlaceOnEventList() does.
  2867. *
  2868. */
  2869. void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
  2870. TickType_t xTicksToWait,
  2871. const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  2872. /*
  2873. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2874. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2875. *
  2876. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2877. *
  2878. * Removes a task from both the specified event list and the list of blocked
  2879. * tasks, and places it on a ready queue.
  2880. *
  2881. * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
  2882. * if either an event occurs to unblock a task, or the block timeout period
  2883. * expires.
  2884. *
  2885. * xTaskRemoveFromEventList() is used when the event list is in task priority
  2886. * order. It removes the list item from the head of the event list as that will
  2887. * have the highest priority owning task of all the tasks on the event list.
  2888. * vTaskRemoveFromUnorderedEventList() is used when the event list is not
  2889. * ordered and the event list items hold something other than the owning tasks
  2890. * priority. In this case the event list item value is updated to the value
  2891. * passed in the xItemValue parameter.
  2892. *
  2893. * @return pdTRUE if the task being removed has a higher priority than the task
  2894. * making the call, otherwise pdFALSE.
  2895. */
  2896. BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
  2897. void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
  2898. const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
  2899. /*
  2900. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2901. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2902. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2903. *
  2904. * Sets the pointer to the current TCB to the TCB of the highest priority task
  2905. * that is ready to run.
  2906. */
  2907. portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
  2908. /*
  2909. * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
  2910. * THE EVENT BITS MODULE.
  2911. */
  2912. TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
  2913. /*
  2914. * Return the handle of the calling task.
  2915. */
  2916. TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
  2917. /*
  2918. * Shortcut used by the queue implementation to prevent unnecessary call to
  2919. * taskYIELD();
  2920. */
  2921. void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
  2922. /*
  2923. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  2924. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  2925. */
  2926. BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  2927. /*
  2928. * Raises the priority of the mutex holder to that of the calling task should
  2929. * the mutex holder have a priority less than the calling task.
  2930. */
  2931. BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2932. /*
  2933. * Set the priority of a task back to its proper priority in the case that it
  2934. * inherited a higher priority while it was holding a semaphore.
  2935. */
  2936. BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2937. /*
  2938. * If a higher priority task attempting to obtain a mutex caused a lower
  2939. * priority task to inherit the higher priority task's priority - but the higher
  2940. * priority task then timed out without obtaining the mutex, then the lower
  2941. * priority task will disinherit the priority again - but only down as far as
  2942. * the highest priority task that is still waiting for the mutex (if there were
  2943. * more than one task waiting for the mutex).
  2944. */
  2945. void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder,
  2946. UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
  2947. /*
  2948. * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
  2949. */
  2950. UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  2951. /*
  2952. * Set the uxTaskNumber of the task referenced by the xTask parameter to
  2953. * uxHandle.
  2954. */
  2955. void vTaskSetTaskNumber( TaskHandle_t xTask,
  2956. const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
  2957. /*
  2958. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2959. * If tickless mode is being used, or a low power mode is implemented, then
  2960. * the tick interrupt will not execute during idle periods. When this is the
  2961. * case, the tick count value maintained by the scheduler needs to be kept up
  2962. * to date with the actual execution time by being skipped forward by a time
  2963. * equal to the idle period.
  2964. */
  2965. void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
  2966. /*
  2967. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2968. * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
  2969. * specific sleep function to determine if it is ok to proceed with the sleep,
  2970. * and if it is ok to proceed, if it is ok to sleep indefinitely.
  2971. *
  2972. * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
  2973. * called with the scheduler suspended, not from within a critical section. It
  2974. * is therefore possible for an interrupt to request a context switch between
  2975. * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
  2976. * entered. eTaskConfirmSleepModeStatus() should be called from a short
  2977. * critical section between the timer being stopped and the sleep mode being
  2978. * entered to ensure it is ok to proceed into the sleep mode.
  2979. */
  2980. eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
  2981. /*
  2982. * For internal use only. Increment the mutex held count when a mutex is
  2983. * taken and return the handle of the task that has taken the mutex.
  2984. */
  2985. TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
  2986. /*
  2987. * For internal use only. Same as vTaskSetTimeOutState(), but without a critical
  2988. * section.
  2989. */
  2990. void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2991. /* *INDENT-OFF* */
  2992. #ifdef __cplusplus
  2993. }
  2994. #endif
  2995. /* *INDENT-ON* */
  2996. #endif /* INC_TASK_H */