task.h 132 KB

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