task.h 134 KB

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