task.h 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053
  1. /*
  2. * FreeRTOS Kernel V10.4.3
  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.3"
  41. #define tskKERNEL_VERSION_MAJOR 10
  42. #define tskKERNEL_VERSION_MINOR 4
  43. #define tskKERNEL_VERSION_BUILD 3
  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 * 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 xTaskDelayUntil() 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. * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  749. * </pre>
  750. *
  751. * INCLUDE_xTaskDelayUntil 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, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  767. * unblock.
  768. *
  769. * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
  770. * time specified in milliseconds with a 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 xTaskDelayUntil ().
  776. *
  777. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  778. * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
  779. * same xTimeIncrement parameter value will cause the task to execute with
  780. * a fixed interface period.
  781. *
  782. * @return Value which can be used to check whether the task was actually delayed.
  783. * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
  784. * be delayed if the next expected wake time is in the past.
  785. *
  786. * Example usage:
  787. * <pre>
  788. * // Perform an action every 10 ticks.
  789. * void vTaskFunction( void * pvParameters )
  790. * {
  791. * TickType_t xLastWakeTime;
  792. * const TickType_t xFrequency = 10;
  793. * BaseType_t xWasDelayed;
  794. *
  795. * // Initialise the xLastWakeTime variable with the current time.
  796. * xLastWakeTime = xTaskGetTickCount ();
  797. * for( ;; )
  798. * {
  799. * // Wait for the next cycle.
  800. * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  801. *
  802. * // Perform action here. xWasDelayed value can be used to determine
  803. * // whether a deadline was missed if the code here took too long.
  804. * }
  805. * }
  806. * </pre>
  807. * \defgroup xTaskDelayUntil xTaskDelayUntil
  808. * \ingroup TaskCtrl
  809. */
  810. BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  811. const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
  812. /*
  813. * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
  814. * return a value.
  815. */
  816. #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
  817. { \
  818. ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
  819. }
  820. /**
  821. * task. h
  822. * <pre>
  823. * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  824. * </pre>
  825. *
  826. * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  827. * function to be available.
  828. *
  829. * A task will enter the Blocked state when it is waiting for an event. The
  830. * event it is waiting for can be a temporal event (waiting for a time), such
  831. * as when vTaskDelay() is called, or an event on an object, such as when
  832. * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  833. * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  834. * task will leave the Blocked state, and return from whichever function call
  835. * placed the task into the Blocked state.
  836. *
  837. * There is no 'FromISR' version of this function as an interrupt would need to
  838. * know which object a task was blocked on in order to know which actions to
  839. * take. For example, if the task was blocked on a queue the interrupt handler
  840. * would then need to know if the queue was locked.
  841. *
  842. * @param xTask The handle of the task to remove from the Blocked state.
  843. *
  844. * @return If the task referenced by xTask was not in the Blocked state then
  845. * pdFAIL is returned. Otherwise pdPASS is returned.
  846. *
  847. * \defgroup xTaskAbortDelay xTaskAbortDelay
  848. * \ingroup TaskCtrl
  849. */
  850. BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  851. /**
  852. * task. h
  853. * <pre>
  854. * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  855. * </pre>
  856. *
  857. * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  858. * See the configuration section for more information.
  859. *
  860. * Obtain the priority of any task.
  861. *
  862. * @param xTask Handle of the task to be queried. Passing a NULL
  863. * handle results in the priority of the calling task being returned.
  864. *
  865. * @return The priority of xTask.
  866. *
  867. * Example usage:
  868. * <pre>
  869. * void vAFunction( void )
  870. * {
  871. * TaskHandle_t xHandle;
  872. *
  873. * // Create a task, storing the handle.
  874. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  875. *
  876. * // ...
  877. *
  878. * // Use the handle to obtain the priority of the created task.
  879. * // It was created with tskIDLE_PRIORITY, but may have changed
  880. * // it itself.
  881. * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  882. * {
  883. * // The task has changed it's priority.
  884. * }
  885. *
  886. * // ...
  887. *
  888. * // Is our priority higher than the created task?
  889. * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  890. * {
  891. * // Our priority (obtained using NULL handle) is higher.
  892. * }
  893. * }
  894. * </pre>
  895. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  896. * \ingroup TaskCtrl
  897. */
  898. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  899. /**
  900. * task. h
  901. * <pre>
  902. * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  903. * </pre>
  904. *
  905. * A version of uxTaskPriorityGet() that can be used from an ISR.
  906. */
  907. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  908. /**
  909. * task. h
  910. * <pre>
  911. * eTaskState eTaskGetState( TaskHandle_t xTask );
  912. * </pre>
  913. *
  914. * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  915. * See the configuration section for more information.
  916. *
  917. * Obtain the state of any task. States are encoded by the eTaskState
  918. * enumerated type.
  919. *
  920. * @param xTask Handle of the task to be queried.
  921. *
  922. * @return The state of xTask at the time the function was called. Note the
  923. * state of the task might change between the function being called, and the
  924. * functions return value being tested by the calling task.
  925. */
  926. eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  927. /**
  928. * task. h
  929. * <pre>
  930. * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
  931. * </pre>
  932. *
  933. * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
  934. * available. See the configuration section for more information.
  935. *
  936. * Populates a TaskStatus_t structure with information about a task.
  937. *
  938. * @param xTask Handle of the task being queried. If xTask is NULL then
  939. * information will be returned about the calling task.
  940. *
  941. * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
  942. * filled with information about the task referenced by the handle passed using
  943. * the xTask parameter.
  944. *
  945. * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
  946. * the stack high water mark of the task being queried. Calculating the stack
  947. * high water mark takes a relatively long time, and can make the system
  948. * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
  949. * allow the high water mark checking to be skipped. The high watermark value
  950. * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
  951. * not set to pdFALSE;
  952. *
  953. * @param eState The TaskStatus_t structure contains a member to report the
  954. * state of the task being queried. Obtaining the task state is not as fast as
  955. * a simple assignment - so the eState parameter is provided to allow the state
  956. * information to be omitted from the TaskStatus_t structure. To obtain state
  957. * information then set eState to eInvalid - otherwise the value passed in
  958. * eState will be reported as the task state in the TaskStatus_t structure.
  959. *
  960. * Example usage:
  961. * <pre>
  962. * void vAFunction( void )
  963. * {
  964. * TaskHandle_t xHandle;
  965. * TaskStatus_t xTaskDetails;
  966. *
  967. * // Obtain the handle of a task from its name.
  968. * xHandle = xTaskGetHandle( "Task_Name" );
  969. *
  970. * // Check the handle is not NULL.
  971. * configASSERT( xHandle );
  972. *
  973. * // Use the handle to obtain further information about the task.
  974. * vTaskGetInfo( xHandle,
  975. * &xTaskDetails,
  976. * pdTRUE, // Include the high water mark in xTaskDetails.
  977. * eInvalid ); // Include the task state in xTaskDetails.
  978. * }
  979. * </pre>
  980. * \defgroup vTaskGetInfo vTaskGetInfo
  981. * \ingroup TaskCtrl
  982. */
  983. void vTaskGetInfo( TaskHandle_t xTask,
  984. TaskStatus_t * pxTaskStatus,
  985. BaseType_t xGetFreeStackSpace,
  986. eTaskState eState ) PRIVILEGED_FUNCTION;
  987. /**
  988. * task. h
  989. * <pre>
  990. * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  991. * </pre>
  992. *
  993. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  994. * See the configuration section for more information.
  995. *
  996. * Set the priority of any task.
  997. *
  998. * A context switch will occur before the function returns if the priority
  999. * being set is higher than the currently executing task.
  1000. *
  1001. * @param xTask Handle to the task for which the priority is being set.
  1002. * Passing a NULL handle results in the priority of the calling task being set.
  1003. *
  1004. * @param uxNewPriority The priority to which the task will be set.
  1005. *
  1006. * Example usage:
  1007. * <pre>
  1008. * void vAFunction( void )
  1009. * {
  1010. * TaskHandle_t xHandle;
  1011. *
  1012. * // Create a task, storing the handle.
  1013. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1014. *
  1015. * // ...
  1016. *
  1017. * // Use the handle to raise the priority of the created task.
  1018. * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  1019. *
  1020. * // ...
  1021. *
  1022. * // Use a NULL handle to raise our priority to the same value.
  1023. * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  1024. * }
  1025. * </pre>
  1026. * \defgroup vTaskPrioritySet vTaskPrioritySet
  1027. * \ingroup TaskCtrl
  1028. */
  1029. void vTaskPrioritySet( TaskHandle_t xTask,
  1030. UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
  1031. /**
  1032. * task. h
  1033. * <pre>
  1034. * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  1035. * </pre>
  1036. *
  1037. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  1038. * See the configuration section for more information.
  1039. *
  1040. * Suspend any task. When suspended a task will never get any microcontroller
  1041. * processing time, no matter what its priority.
  1042. *
  1043. * Calls to vTaskSuspend are not accumulative -
  1044. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  1045. * call to vTaskResume () to ready the suspended task.
  1046. *
  1047. * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  1048. * handle will cause the calling task to be suspended.
  1049. *
  1050. * Example usage:
  1051. * <pre>
  1052. * void vAFunction( void )
  1053. * {
  1054. * TaskHandle_t xHandle;
  1055. *
  1056. * // Create a task, storing the handle.
  1057. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1058. *
  1059. * // ...
  1060. *
  1061. * // Use the handle to suspend the created task.
  1062. * vTaskSuspend( xHandle );
  1063. *
  1064. * // ...
  1065. *
  1066. * // The created task will not run during this period, unless
  1067. * // another task calls vTaskResume( xHandle ).
  1068. *
  1069. * //...
  1070. *
  1071. *
  1072. * // Suspend ourselves.
  1073. * vTaskSuspend( NULL );
  1074. *
  1075. * // We cannot get here unless another task calls vTaskResume
  1076. * // with our handle as the parameter.
  1077. * }
  1078. * </pre>
  1079. * \defgroup vTaskSuspend vTaskSuspend
  1080. * \ingroup TaskCtrl
  1081. */
  1082. void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
  1083. /**
  1084. * task. h
  1085. * <pre>
  1086. * void vTaskResume( TaskHandle_t xTaskToResume );
  1087. * </pre>
  1088. *
  1089. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  1090. * See the configuration section for more information.
  1091. *
  1092. * Resumes a suspended task.
  1093. *
  1094. * A task that has been suspended by one or more calls to vTaskSuspend ()
  1095. * will be made available for running again by a single call to
  1096. * vTaskResume ().
  1097. *
  1098. * @param xTaskToResume Handle to the task being readied.
  1099. *
  1100. * Example usage:
  1101. * <pre>
  1102. * void vAFunction( void )
  1103. * {
  1104. * TaskHandle_t xHandle;
  1105. *
  1106. * // Create a task, storing the handle.
  1107. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  1108. *
  1109. * // ...
  1110. *
  1111. * // Use the handle to suspend the created task.
  1112. * vTaskSuspend( xHandle );
  1113. *
  1114. * // ...
  1115. *
  1116. * // The created task will not run during this period, unless
  1117. * // another task calls vTaskResume( xHandle ).
  1118. *
  1119. * //...
  1120. *
  1121. *
  1122. * // Resume the suspended task ourselves.
  1123. * vTaskResume( xHandle );
  1124. *
  1125. * // The created task will once again get microcontroller processing
  1126. * // time in accordance with its priority within the system.
  1127. * }
  1128. * </pre>
  1129. * \defgroup vTaskResume vTaskResume
  1130. * \ingroup TaskCtrl
  1131. */
  1132. void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1133. /**
  1134. * task. h
  1135. * <pre>
  1136. * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  1137. * </pre>
  1138. *
  1139. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  1140. * available. See the configuration section for more information.
  1141. *
  1142. * An implementation of vTaskResume() that can be called from within an ISR.
  1143. *
  1144. * A task that has been suspended by one or more calls to vTaskSuspend ()
  1145. * will be made available for running again by a single call to
  1146. * xTaskResumeFromISR ().
  1147. *
  1148. * xTaskResumeFromISR() should not be used to synchronise a task with an
  1149. * interrupt if there is a chance that the interrupt could arrive prior to the
  1150. * task being suspended - as this can lead to interrupts being missed. Use of a
  1151. * semaphore as a synchronisation mechanism would avoid this eventuality.
  1152. *
  1153. * @param xTaskToResume Handle to the task being readied.
  1154. *
  1155. * @return pdTRUE if resuming the task should result in a context switch,
  1156. * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  1157. * may be required following the ISR.
  1158. *
  1159. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  1160. * \ingroup TaskCtrl
  1161. */
  1162. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1163. /*-----------------------------------------------------------
  1164. * SCHEDULER CONTROL
  1165. *----------------------------------------------------------*/
  1166. /**
  1167. * task. h
  1168. * <pre>
  1169. * void vTaskStartScheduler( void );
  1170. * </pre>
  1171. *
  1172. * Starts the real time kernel tick processing. After calling the kernel
  1173. * has control over which tasks are executed and when.
  1174. *
  1175. * See the demo application file main.c for an example of creating
  1176. * tasks and starting the kernel.
  1177. *
  1178. * Example usage:
  1179. * <pre>
  1180. * void vAFunction( void )
  1181. * {
  1182. * // Create at least one task before starting the kernel.
  1183. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1184. *
  1185. * // Start the real time kernel with preemption.
  1186. * vTaskStartScheduler ();
  1187. *
  1188. * // Will not get here unless a task calls vTaskEndScheduler ()
  1189. * }
  1190. * </pre>
  1191. *
  1192. * \defgroup vTaskStartScheduler vTaskStartScheduler
  1193. * \ingroup SchedulerControl
  1194. */
  1195. void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
  1196. /**
  1197. * task. h
  1198. * <pre>
  1199. * void vTaskEndScheduler( void );
  1200. * </pre>
  1201. *
  1202. * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
  1203. * in place of DOS, implements this function.
  1204. *
  1205. * Stops the real time kernel tick. All created tasks will be automatically
  1206. * deleted and multitasking (either preemptive or cooperative) will
  1207. * stop. Execution then resumes from the point where vTaskStartScheduler ()
  1208. * was called, as if vTaskStartScheduler () had just returned.
  1209. *
  1210. * See the demo application file main. c in the demo/PC directory for an
  1211. * example that uses vTaskEndScheduler ().
  1212. *
  1213. * vTaskEndScheduler () requires an exit function to be defined within the
  1214. * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  1215. * performs hardware specific operations such as stopping the kernel tick.
  1216. *
  1217. * vTaskEndScheduler () will cause all of the resources allocated by the
  1218. * kernel to be freed - but will not free resources allocated by application
  1219. * tasks.
  1220. *
  1221. * Example usage:
  1222. * <pre>
  1223. * void vTaskCode( void * pvParameters )
  1224. * {
  1225. * for( ;; )
  1226. * {
  1227. * // Task code goes here.
  1228. *
  1229. * // At some point we want to end the real time kernel processing
  1230. * // so call ...
  1231. * vTaskEndScheduler ();
  1232. * }
  1233. * }
  1234. *
  1235. * void vAFunction( void )
  1236. * {
  1237. * // Create at least one task before starting the kernel.
  1238. * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1239. *
  1240. * // Start the real time kernel with preemption.
  1241. * vTaskStartScheduler ();
  1242. *
  1243. * // Will only get here when the vTaskCode () task has called
  1244. * // vTaskEndScheduler (). When we get here we are back to single task
  1245. * // execution.
  1246. * }
  1247. * </pre>
  1248. *
  1249. * \defgroup vTaskEndScheduler vTaskEndScheduler
  1250. * \ingroup SchedulerControl
  1251. */
  1252. void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
  1253. /**
  1254. * task. h
  1255. * <pre>
  1256. * void vTaskSuspendAll( void );
  1257. * </pre>
  1258. *
  1259. * Suspends the scheduler without disabling interrupts. Context switches will
  1260. * not occur while the scheduler is suspended.
  1261. *
  1262. * After calling vTaskSuspendAll () the calling task will continue to execute
  1263. * without risk of being swapped out until a call to xTaskResumeAll () has been
  1264. * made.
  1265. *
  1266. * API functions that have the potential to cause a context switch (for example,
  1267. * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  1268. * is suspended.
  1269. *
  1270. * Example usage:
  1271. * <pre>
  1272. * void vTask1( void * pvParameters )
  1273. * {
  1274. * for( ;; )
  1275. * {
  1276. * // Task code goes here.
  1277. *
  1278. * // ...
  1279. *
  1280. * // At some point the task wants to perform a long operation during
  1281. * // which it does not want to get swapped out. It cannot use
  1282. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1283. * // operation may cause interrupts to be missed - including the
  1284. * // ticks.
  1285. *
  1286. * // Prevent the real time kernel swapping out the task.
  1287. * vTaskSuspendAll ();
  1288. *
  1289. * // Perform the operation here. There is no need to use critical
  1290. * // sections as we have all the microcontroller processing time.
  1291. * // During this time interrupts will still operate and the kernel
  1292. * // tick count will be maintained.
  1293. *
  1294. * // ...
  1295. *
  1296. * // The operation is complete. Restart the kernel.
  1297. * xTaskResumeAll ();
  1298. * }
  1299. * }
  1300. * </pre>
  1301. * \defgroup vTaskSuspendAll vTaskSuspendAll
  1302. * \ingroup SchedulerControl
  1303. */
  1304. void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
  1305. /**
  1306. * task. h
  1307. * <pre>
  1308. * BaseType_t xTaskResumeAll( void );
  1309. * </pre>
  1310. *
  1311. * Resumes scheduler activity after it was suspended by a call to
  1312. * vTaskSuspendAll().
  1313. *
  1314. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  1315. * that were previously suspended by a call to vTaskSuspend().
  1316. *
  1317. * @return If resuming the scheduler caused a context switch then pdTRUE is
  1318. * returned, otherwise pdFALSE is returned.
  1319. *
  1320. * Example usage:
  1321. * <pre>
  1322. * void vTask1( void * pvParameters )
  1323. * {
  1324. * for( ;; )
  1325. * {
  1326. * // Task code goes here.
  1327. *
  1328. * // ...
  1329. *
  1330. * // At some point the task wants to perform a long operation during
  1331. * // which it does not want to get swapped out. It cannot use
  1332. * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1333. * // operation may cause interrupts to be missed - including the
  1334. * // ticks.
  1335. *
  1336. * // Prevent the real time kernel swapping out the task.
  1337. * vTaskSuspendAll ();
  1338. *
  1339. * // Perform the operation here. There is no need to use critical
  1340. * // sections as we have all the microcontroller processing time.
  1341. * // During this time interrupts will still operate and the real
  1342. * // time kernel tick count will be maintained.
  1343. *
  1344. * // ...
  1345. *
  1346. * // The operation is complete. Restart the kernel. We want to force
  1347. * // a context switch - but there is no point if resuming the scheduler
  1348. * // caused a context switch already.
  1349. * if( !xTaskResumeAll () )
  1350. * {
  1351. * taskYIELD ();
  1352. * }
  1353. * }
  1354. * }
  1355. * </pre>
  1356. * \defgroup xTaskResumeAll xTaskResumeAll
  1357. * \ingroup SchedulerControl
  1358. */
  1359. BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
  1360. /*-----------------------------------------------------------
  1361. * TASK UTILITIES
  1362. *----------------------------------------------------------*/
  1363. /**
  1364. * task. h
  1365. * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
  1366. *
  1367. * @return The count of ticks since vTaskStartScheduler was called.
  1368. *
  1369. * \defgroup xTaskGetTickCount xTaskGetTickCount
  1370. * \ingroup TaskUtils
  1371. */
  1372. TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
  1373. /**
  1374. * task. h
  1375. * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
  1376. *
  1377. * @return The count of ticks since vTaskStartScheduler was called.
  1378. *
  1379. * This is a version of xTaskGetTickCount() that is safe to be called from an
  1380. * ISR - provided that TickType_t is the natural word size of the
  1381. * microcontroller being used or interrupt nesting is either not supported or
  1382. * not being used.
  1383. *
  1384. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  1385. * \ingroup TaskUtils
  1386. */
  1387. TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
  1388. /**
  1389. * task. h
  1390. * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
  1391. *
  1392. * @return The number of tasks that the real time kernel is currently managing.
  1393. * This includes all ready, blocked and suspended tasks. A task that
  1394. * has been deleted but not yet freed by the idle task will also be
  1395. * included in the count.
  1396. *
  1397. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  1398. * \ingroup TaskUtils
  1399. */
  1400. UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
  1401. /**
  1402. * task. h
  1403. * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
  1404. *
  1405. * @return The text (human readable) name of the task referenced by the handle
  1406. * xTaskToQuery. A task can query its own name by either passing in its own
  1407. * handle, or by setting xTaskToQuery to NULL.
  1408. *
  1409. * \defgroup pcTaskGetName pcTaskGetName
  1410. * \ingroup TaskUtils
  1411. */
  1412. char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1413. /**
  1414. * task. h
  1415. * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
  1416. *
  1417. * NOTE: This function takes a relatively long time to complete and should be
  1418. * used sparingly.
  1419. *
  1420. * @return The handle of the task that has the human readable name pcNameToQuery.
  1421. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1422. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1423. *
  1424. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1425. * \ingroup TaskUtils
  1426. */
  1427. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1428. /**
  1429. * task.h
  1430. * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
  1431. *
  1432. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1433. * this function to be available.
  1434. *
  1435. * Returns the high water mark of the stack associated with xTask. That is,
  1436. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1437. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1438. * number the closer the task has come to overflowing its stack.
  1439. *
  1440. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1441. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1442. * user to determine the return type. It gets around the problem of the value
  1443. * overflowing on 8-bit types without breaking backward compatibility for
  1444. * applications that expect an 8-bit return type.
  1445. *
  1446. * @param xTask Handle of the task associated with the stack to be checked.
  1447. * Set xTask to NULL to check the stack of the calling task.
  1448. *
  1449. * @return The smallest amount of free stack space there has been (in words, so
  1450. * actual spaces on the stack rather than bytes) since the task referenced by
  1451. * xTask was created.
  1452. */
  1453. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1454. /**
  1455. * task.h
  1456. * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
  1457. *
  1458. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1459. * this function to be available.
  1460. *
  1461. * Returns the high water mark of the stack associated with xTask. That is,
  1462. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1463. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1464. * number the closer the task has come to overflowing its stack.
  1465. *
  1466. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1467. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1468. * user to determine the return type. It gets around the problem of the value
  1469. * overflowing on 8-bit types without breaking backward compatibility for
  1470. * applications that expect an 8-bit return type.
  1471. *
  1472. * @param xTask Handle of the task associated with the stack to be checked.
  1473. * Set xTask to NULL to check the stack of the calling task.
  1474. *
  1475. * @return The smallest amount of free stack space there has been (in words, so
  1476. * actual spaces on the stack rather than bytes) since the task referenced by
  1477. * xTask was created.
  1478. */
  1479. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1480. /* When using trace macros it is sometimes necessary to include task.h before
  1481. * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1482. * so the following two prototypes will cause a compilation error. This can be
  1483. * fixed by simply guarding against the inclusion of these two prototypes unless
  1484. * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1485. * constant. */
  1486. #ifdef configUSE_APPLICATION_TASK_TAG
  1487. #if configUSE_APPLICATION_TASK_TAG == 1
  1488. /**
  1489. * task.h
  1490. * <pre>
  1491. * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  1492. * </pre>
  1493. *
  1494. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1495. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1496. * function.
  1497. */
  1498. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  1499. TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
  1500. /**
  1501. * task.h
  1502. * <pre>
  1503. * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  1504. * </pre>
  1505. *
  1506. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1507. * call from an interrupt service routine - call
  1508. * xTaskGetApplicationTaskTagFromISR() instead.
  1509. */
  1510. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1511. /**
  1512. * task.h
  1513. * <pre>
  1514. * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  1515. * </pre>
  1516. *
  1517. * Returns the pxHookFunction value assigned to the task xTask. Can
  1518. * be called from an interrupt service routine.
  1519. */
  1520. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1521. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1522. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1523. #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  1524. /* Each task contains an array of pointers that is dimensioned by the
  1525. * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
  1526. * kernel does not use the pointers itself, so the application writer can use
  1527. * the pointers for any purpose they wish. The following two functions are
  1528. * used to set and query a pointer respectively. */
  1529. void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  1530. BaseType_t xIndex,
  1531. void * pvValue ) PRIVILEGED_FUNCTION;
  1532. void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  1533. BaseType_t xIndex ) PRIVILEGED_FUNCTION;
  1534. #endif
  1535. #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
  1536. /**
  1537. * task.h
  1538. * <pre>void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName); </pre>
  1539. *
  1540. * The application stack overflow hook is called when a stack overflow is detected for a task.
  1541. *
  1542. * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
  1543. *
  1544. * @param xTask the task that just exceeded its stack boundaries.
  1545. * @param pcTaskName A character string containing the name of the offending task.
  1546. */
  1547. void vApplicationStackOverflowHook( TaskHandle_t xTask,
  1548. char * pcTaskName );
  1549. #endif
  1550. #if ( configUSE_TICK_HOOK > 0 )
  1551. /**
  1552. * task.h
  1553. * <pre>void vApplicationTickHook( void ); </pre>
  1554. *
  1555. * This hook function is called in the system tick handler after any OS work is completed.
  1556. */
  1557. void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
  1558. #endif
  1559. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1560. /**
  1561. * task.h
  1562. * <pre>void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) </pre>
  1563. *
  1564. * 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
  1565. * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
  1566. *
  1567. * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
  1568. * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for thie idle task
  1569. * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
  1570. */
  1571. void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
  1572. StackType_t ** ppxIdleTaskStackBuffer,
  1573. uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
  1574. #endif
  1575. /**
  1576. * task.h
  1577. * <pre>
  1578. * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  1579. * </pre>
  1580. *
  1581. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1582. * the effect of calling the Running tasks (the calling task) hook function.
  1583. *
  1584. * pvParameter is passed to the hook function for the task to interpret as it
  1585. * wants. The return value is the value returned by the task hook function
  1586. * registered by the user.
  1587. */
  1588. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  1589. void * pvParameter ) PRIVILEGED_FUNCTION;
  1590. /**
  1591. * xTaskGetIdleTaskHandle() is only available if
  1592. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1593. *
  1594. * Simply returns the handle of the idle task. It is not valid to call
  1595. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1596. */
  1597. TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
  1598. /**
  1599. * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
  1600. * uxTaskGetSystemState() to be available.
  1601. *
  1602. * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
  1603. * the system. TaskStatus_t structures contain, among other things, members
  1604. * for the task handle, task name, task priority, task state, and total amount
  1605. * of run time consumed by the task. See the TaskStatus_t structure
  1606. * definition in this file for the full member list.
  1607. *
  1608. * NOTE: This function is intended for debugging use only as its use results in
  1609. * the scheduler remaining suspended for an extended period.
  1610. *
  1611. * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
  1612. * The array must contain at least one TaskStatus_t structure for each task
  1613. * that is under the control of the RTOS. The number of tasks under the control
  1614. * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
  1615. *
  1616. * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
  1617. * parameter. The size is specified as the number of indexes in the array, or
  1618. * the number of TaskStatus_t structures contained in the array, not by the
  1619. * number of bytes in the array.
  1620. *
  1621. * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
  1622. * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
  1623. * total run time (as defined by the run time stats clock, see
  1624. * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted.
  1625. * pulTotalRunTime can be set to NULL to omit the total run time information.
  1626. *
  1627. * @return The number of TaskStatus_t structures that were populated by
  1628. * uxTaskGetSystemState(). This should equal the number returned by the
  1629. * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
  1630. * in the uxArraySize parameter was too small.
  1631. *
  1632. * Example usage:
  1633. * <pre>
  1634. * // This example demonstrates how a human readable table of run time stats
  1635. * // information is generated from raw data provided by uxTaskGetSystemState().
  1636. * // The human readable table is written to pcWriteBuffer
  1637. * void vTaskGetRunTimeStats( char *pcWriteBuffer )
  1638. * {
  1639. * TaskStatus_t *pxTaskStatusArray;
  1640. * volatile UBaseType_t uxArraySize, x;
  1641. * uint32_t ulTotalRunTime, ulStatsAsPercentage;
  1642. *
  1643. * // Make sure the write buffer does not contain a string.
  1644. * pcWriteBuffer = 0x00;
  1645. *
  1646. * // Take a snapshot of the number of tasks in case it changes while this
  1647. * // function is executing.
  1648. * uxArraySize = uxTaskGetNumberOfTasks();
  1649. *
  1650. * // Allocate a TaskStatus_t structure for each task. An array could be
  1651. * // allocated statically at compile time.
  1652. * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  1653. *
  1654. * if( pxTaskStatusArray != NULL )
  1655. * {
  1656. * // Generate raw status information about each task.
  1657. * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
  1658. *
  1659. * // For percentage calculations.
  1660. * ulTotalRunTime /= 100UL;
  1661. *
  1662. * // Avoid divide by zero errors.
  1663. * if( ulTotalRunTime > 0 )
  1664. * {
  1665. * // For each populated position in the pxTaskStatusArray array,
  1666. * // format the raw data as human readable ASCII data
  1667. * for( x = 0; x < uxArraySize; x++ )
  1668. * {
  1669. * // What percentage of the total run time has the task used?
  1670. * // This will always be rounded down to the nearest integer.
  1671. * // ulTotalRunTimeDiv100 has already been divided by 100.
  1672. * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
  1673. *
  1674. * if( ulStatsAsPercentage > 0UL )
  1675. * {
  1676. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
  1677. * }
  1678. * else
  1679. * {
  1680. * // If the percentage is zero here then the task has
  1681. * // consumed less than 1% of the total run time.
  1682. * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
  1683. * }
  1684. *
  1685. * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
  1686. * }
  1687. * }
  1688. *
  1689. * // The array is no longer needed, free the memory it consumes.
  1690. * vPortFree( pxTaskStatusArray );
  1691. * }
  1692. * }
  1693. * </pre>
  1694. */
  1695. UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
  1696. const UBaseType_t uxArraySize,
  1697. uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
  1698. /**
  1699. * task. h
  1700. * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
  1701. *
  1702. * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
  1703. * both be defined as 1 for this function to be available. See the
  1704. * configuration section of the FreeRTOS.org website for more information.
  1705. *
  1706. * NOTE 1: This function will disable interrupts for its duration. It is
  1707. * not intended for normal application runtime use but as a debug aid.
  1708. *
  1709. * Lists all the current tasks, along with their current state and stack
  1710. * usage high water mark.
  1711. *
  1712. * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
  1713. * suspended ('S').
  1714. *
  1715. * PLEASE NOTE:
  1716. *
  1717. * This function is provided for convenience only, and is used by many of the
  1718. * demo applications. Do not consider it to be part of the scheduler.
  1719. *
  1720. * vTaskList() calls uxTaskGetSystemState(), then formats part of the
  1721. * uxTaskGetSystemState() output into a human readable table that displays task
  1722. * names, states and stack usage.
  1723. *
  1724. * vTaskList() has a dependency on the sprintf() C library function that might
  1725. * bloat the code size, use a lot of stack, and provide different results on
  1726. * different platforms. An alternative, tiny, third party, and limited
  1727. * functionality implementation of sprintf() is provided in many of the
  1728. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1729. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1730. *
  1731. * It is recommended that production systems call uxTaskGetSystemState()
  1732. * directly to get access to raw stats data, rather than indirectly through a
  1733. * call to vTaskList().
  1734. *
  1735. * @param pcWriteBuffer A buffer into which the above mentioned details
  1736. * will be written, in ASCII form. This buffer is assumed to be large
  1737. * enough to contain the generated report. Approximately 40 bytes per
  1738. * task should be sufficient.
  1739. *
  1740. * \defgroup vTaskList vTaskList
  1741. * \ingroup TaskUtils
  1742. */
  1743. void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1744. /**
  1745. * task. h
  1746. * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
  1747. *
  1748. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1749. * must both be defined as 1 for this function to be available. The application
  1750. * must also then provide definitions for
  1751. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1752. * to configure a peripheral timer/counter and return the timers current count
  1753. * value respectively. The counter should be at least 10 times the frequency of
  1754. * the tick count.
  1755. *
  1756. * NOTE 1: This function will disable interrupts for its duration. It is
  1757. * not intended for normal application runtime use but as a debug aid.
  1758. *
  1759. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1760. * accumulated execution time being stored for each task. The resolution
  1761. * of the accumulated time value depends on the frequency of the timer
  1762. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1763. * Calling vTaskGetRunTimeStats() writes the total execution time of each
  1764. * task into a buffer, both as an absolute count value and as a percentage
  1765. * of the total system execution time.
  1766. *
  1767. * NOTE 2:
  1768. *
  1769. * This function is provided for convenience only, and is used by many of the
  1770. * demo applications. Do not consider it to be part of the scheduler.
  1771. *
  1772. * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
  1773. * uxTaskGetSystemState() output into a human readable table that displays the
  1774. * amount of time each task has spent in the Running state in both absolute and
  1775. * percentage terms.
  1776. *
  1777. * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
  1778. * that might bloat the code size, use a lot of stack, and provide different
  1779. * results on different platforms. An alternative, tiny, third party, and
  1780. * limited functionality implementation of sprintf() is provided in many of the
  1781. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1782. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1783. *
  1784. * It is recommended that production systems call uxTaskGetSystemState() directly
  1785. * to get access to raw stats data, rather than indirectly through a call to
  1786. * vTaskGetRunTimeStats().
  1787. *
  1788. * @param pcWriteBuffer A buffer into which the execution times will be
  1789. * written, in ASCII form. This buffer is assumed to be large enough to
  1790. * contain the generated report. Approximately 40 bytes per task should
  1791. * be sufficient.
  1792. *
  1793. * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
  1794. * \ingroup TaskUtils
  1795. */
  1796. void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1797. /**
  1798. * task. h
  1799. * <PRE>uint32_t ulTaskGetIdleRunTimeCounter( void );</PRE>
  1800. *
  1801. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1802. * must both be defined as 1 for this function to be available. The application
  1803. * must also then provide definitions for
  1804. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1805. * to configure a peripheral timer/counter and return the timers current count
  1806. * value respectively. The counter should be at least 10 times the frequency of
  1807. * the tick count.
  1808. *
  1809. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1810. * accumulated execution time being stored for each task. The resolution
  1811. * of the accumulated time value depends on the frequency of the timer
  1812. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1813. * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
  1814. * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
  1815. * returns the total execution time of just the idle task.
  1816. *
  1817. * @return The total run time of the idle task. This is the amount of time the
  1818. * idle task has actually been executing. The unit of time is dependent on the
  1819. * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
  1820. * portGET_RUN_TIME_COUNTER_VALUE() macros.
  1821. *
  1822. * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
  1823. * \ingroup TaskUtils
  1824. */
  1825. uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
  1826. /**
  1827. * task. h
  1828. * <PRE>BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
  1829. * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
  1830. *
  1831. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1832. *
  1833. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1834. * functions to be available.
  1835. *
  1836. * Sends a direct to task notification to a task, with an optional value and
  1837. * action.
  1838. *
  1839. * Each task has a private array of "notification values" (or 'notifications'),
  1840. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1841. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1842. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1843. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1844. *
  1845. * Events can be sent to a task using an intermediary object. Examples of such
  1846. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1847. * are a method of sending an event directly to a task without the need for such
  1848. * an intermediary object.
  1849. *
  1850. * A notification sent to a task can optionally perform an action, such as
  1851. * update, overwrite or increment one of the task's notification values. In
  1852. * that way task notifications can be used to send data to a task, or be used as
  1853. * light weight and fast binary or counting semaphores.
  1854. *
  1855. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  1856. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  1857. * to wait for a notification value to have a non-zero value. The task does
  1858. * not consume any CPU time while it is in the Blocked state.
  1859. *
  1860. * A notification sent to a task will remain pending until it is cleared by the
  1861. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  1862. * un-indexed equivalents). If the task was already in the Blocked state to
  1863. * wait for a notification when the notification arrives then the task will
  1864. * automatically be removed from the Blocked state (unblocked) and the
  1865. * notification cleared.
  1866. *
  1867. * **NOTE** Each notification within the array operates independently - a task
  1868. * can only block on one notification within the array at a time and will not be
  1869. * unblocked by a notification sent to any other array index.
  1870. *
  1871. * Backward compatibility information:
  1872. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  1873. * all task notification API functions operated on that value. Replacing the
  1874. * single notification value with an array of notification values necessitated a
  1875. * new set of API functions that could address specific notifications within the
  1876. * array. xTaskNotify() is the original API function, and remains backward
  1877. * compatible by always operating on the notification value at index 0 in the
  1878. * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  1879. * with the uxIndexToNotify parameter set to 0.
  1880. *
  1881. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1882. * task can be returned from the xTaskCreate() API function used to create the
  1883. * task, and the handle of the currently running task can be obtained by calling
  1884. * xTaskGetCurrentTaskHandle().
  1885. *
  1886. * @param uxIndexToNotify The index within the target task's array of
  1887. * notification values to which the notification is to be sent. uxIndexToNotify
  1888. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  1889. * not have this parameter and always sends notifications to index 0.
  1890. *
  1891. * @param ulValue Data that can be sent with the notification. How the data is
  1892. * used depends on the value of the eAction parameter.
  1893. *
  1894. * @param eAction Specifies how the notification updates the task's notification
  1895. * value, if at all. Valid values for eAction are as follows:
  1896. *
  1897. * eSetBits -
  1898. * The target notification value is bitwise ORed with ulValue.
  1899. * xTaskNofifyIndexed() always returns pdPASS in this case.
  1900. *
  1901. * eIncrement -
  1902. * The target notification value is incremented. ulValue is not used and
  1903. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1904. *
  1905. * eSetValueWithOverwrite -
  1906. * The target notification value is set to the value of ulValue, even if the
  1907. * task being notified had not yet processed the previous notification at the
  1908. * same array index (the task already had a notification pending at that index).
  1909. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1910. *
  1911. * eSetValueWithoutOverwrite -
  1912. * If the task being notified did not already have a notification pending at the
  1913. * same array index then the target notification value is set to ulValue and
  1914. * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  1915. * had a notification pending at the same array index then no action is
  1916. * performed and pdFAIL is returned.
  1917. *
  1918. * eNoAction -
  1919. * The task receives a notification at the specified array index without the
  1920. * notification value at that index being updated. ulValue is not used and
  1921. * xTaskNotifyIndexed() always returns pdPASS in this case.
  1922. *
  1923. * pulPreviousNotificationValue -
  1924. * Can be used to pass out the subject task's notification value before any
  1925. * bits are modified by the notify function.
  1926. *
  1927. * @return Dependent on the value of eAction. See the description of the
  1928. * eAction parameter.
  1929. *
  1930. * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  1931. * \ingroup TaskNotifications
  1932. */
  1933. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  1934. UBaseType_t uxIndexToNotify,
  1935. uint32_t ulValue,
  1936. eNotifyAction eAction,
  1937. uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
  1938. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  1939. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  1940. #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  1941. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  1942. /**
  1943. * task. h
  1944. * <PRE>BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
  1945. * <PRE>BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
  1946. *
  1947. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1948. *
  1949. * xTaskNotifyAndQueryIndexed() performs the same operation as
  1950. * xTaskNotifyIndexed() with the addition that it also returns the subject
  1951. * task's prior notification value (the notification value at the time the
  1952. * function is called rather than when the function returns) in the additional
  1953. * pulPreviousNotifyValue parameter.
  1954. *
  1955. * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
  1956. * addition that it also returns the subject task's prior notification value
  1957. * (the notification value as it was at the time the function is called, rather
  1958. * than when the function returns) in the additional pulPreviousNotifyValue
  1959. * parameter.
  1960. *
  1961. * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
  1962. * \ingroup TaskNotifications
  1963. */
  1964. #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1965. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1966. #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  1967. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1968. /**
  1969. * task. h
  1970. * <PRE>BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  1971. * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  1972. *
  1973. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1974. *
  1975. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  1976. * functions to be available.
  1977. *
  1978. * A version of xTaskNotifyIndexed() that can be used from an interrupt service
  1979. * routine (ISR).
  1980. *
  1981. * Each task has a private array of "notification values" (or 'notifications'),
  1982. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  1983. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  1984. * array, and (for backward compatibility) defaults to 1 if left undefined.
  1985. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  1986. *
  1987. * Events can be sent to a task using an intermediary object. Examples of such
  1988. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1989. * are a method of sending an event directly to a task without the need for such
  1990. * an intermediary object.
  1991. *
  1992. * A notification sent to a task can optionally perform an action, such as
  1993. * update, overwrite or increment one of the task's notification values. In
  1994. * that way task notifications can be used to send data to a task, or be used as
  1995. * light weight and fast binary or counting semaphores.
  1996. *
  1997. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  1998. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  1999. * to wait for a notification value to have a non-zero value. The task does
  2000. * not consume any CPU time while it is in the Blocked state.
  2001. *
  2002. * A notification sent to a task will remain pending until it is cleared by the
  2003. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2004. * un-indexed equivalents). If the task was already in the Blocked state to
  2005. * wait for a notification when the notification arrives then the task will
  2006. * automatically be removed from the Blocked state (unblocked) and the
  2007. * notification cleared.
  2008. *
  2009. * **NOTE** Each notification within the array operates independently - a task
  2010. * can only block on one notification within the array at a time and will not be
  2011. * unblocked by a notification sent to any other array index.
  2012. *
  2013. * Backward compatibility information:
  2014. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2015. * all task notification API functions operated on that value. Replacing the
  2016. * single notification value with an array of notification values necessitated a
  2017. * new set of API functions that could address specific notifications within the
  2018. * array. xTaskNotifyFromISR() is the original API function, and remains
  2019. * backward compatible by always operating on the notification value at index 0
  2020. * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
  2021. * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2022. *
  2023. * @param uxIndexToNotify The index within the target task's array of
  2024. * notification values to which the notification is to be sent. uxIndexToNotify
  2025. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
  2026. * does not have this parameter and always sends notifications to index 0.
  2027. *
  2028. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2029. * task can be returned from the xTaskCreate() API function used to create the
  2030. * task, and the handle of the currently running task can be obtained by calling
  2031. * xTaskGetCurrentTaskHandle().
  2032. *
  2033. * @param ulValue Data that can be sent with the notification. How the data is
  2034. * used depends on the value of the eAction parameter.
  2035. *
  2036. * @param eAction Specifies how the notification updates the task's notification
  2037. * value, if at all. Valid values for eAction are as follows:
  2038. *
  2039. * eSetBits -
  2040. * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
  2041. * always returns pdPASS in this case.
  2042. *
  2043. * eIncrement -
  2044. * The task's notification value is incremented. ulValue is not used and
  2045. * xTaskNotify() always returns pdPASS in this case.
  2046. *
  2047. * eSetValueWithOverwrite -
  2048. * The task's notification value is set to the value of ulValue, even if the
  2049. * task being notified had not yet processed the previous notification (the
  2050. * task already had a notification pending). xTaskNotify() always returns
  2051. * pdPASS in this case.
  2052. *
  2053. * eSetValueWithoutOverwrite -
  2054. * If the task being notified did not already have a notification pending then
  2055. * the task's notification value is set to ulValue and xTaskNotify() will
  2056. * return pdPASS. If the task being notified already had a notification
  2057. * pending then no action is performed and pdFAIL is returned.
  2058. *
  2059. * eNoAction -
  2060. * The task receives a notification without its notification value being
  2061. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  2062. * this case.
  2063. *
  2064. * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  2065. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2066. * task to which the notification was sent to leave the Blocked state, and the
  2067. * unblocked task has a priority higher than the currently running task. If
  2068. * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  2069. * be requested before the interrupt is exited. How a context switch is
  2070. * requested from an ISR is dependent on the port - see the documentation page
  2071. * for the port in use.
  2072. *
  2073. * @return Dependent on the value of eAction. See the description of the
  2074. * eAction parameter.
  2075. *
  2076. * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
  2077. * \ingroup TaskNotifications
  2078. */
  2079. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  2080. UBaseType_t uxIndexToNotify,
  2081. uint32_t ulValue,
  2082. eNotifyAction eAction,
  2083. uint32_t * pulPreviousNotificationValue,
  2084. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2085. #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2086. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2087. #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  2088. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  2089. /**
  2090. * task. h
  2091. * <PRE>BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2092. * <PRE>BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2093. *
  2094. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2095. *
  2096. * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
  2097. * xTaskNotifyIndexedFromISR() with the addition that it also returns the
  2098. * subject task's prior notification value (the notification value at the time
  2099. * the function is called rather than at the time the function returns) in the
  2100. * additional pulPreviousNotifyValue parameter.
  2101. *
  2102. * xTaskNotifyAndQueryFromISR() performs the same operation as
  2103. * xTaskNotifyFromISR() with the addition that it also returns the subject
  2104. * task's prior notification value (the notification value at the time the
  2105. * function is called rather than at the time the function returns) in the
  2106. * additional pulPreviousNotifyValue parameter.
  2107. *
  2108. * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
  2109. * \ingroup TaskNotifications
  2110. */
  2111. #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2112. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2113. #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  2114. xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  2115. /**
  2116. * task. h
  2117. * <pre>
  2118. * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2119. *
  2120. * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  2121. * </pre>
  2122. *
  2123. * Waits for a direct to task notification to be pending at a given index within
  2124. * an array of direct to task notifications.
  2125. *
  2126. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2127. *
  2128. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2129. * function to be available.
  2130. *
  2131. * Each task has a private array of "notification values" (or 'notifications'),
  2132. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2133. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2134. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2135. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2136. *
  2137. * Events can be sent to a task using an intermediary object. Examples of such
  2138. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2139. * are a method of sending an event directly to a task without the need for such
  2140. * an intermediary object.
  2141. *
  2142. * A notification sent to a task can optionally perform an action, such as
  2143. * update, overwrite or increment one of the task's notification values. In
  2144. * that way task notifications can be used to send data to a task, or be used as
  2145. * light weight and fast binary or counting semaphores.
  2146. *
  2147. * A notification sent to a task will remain pending until it is cleared by the
  2148. * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  2149. * un-indexed equivalents). If the task was already in the Blocked state to
  2150. * wait for a notification when the notification arrives then the task will
  2151. * automatically be removed from the Blocked state (unblocked) and the
  2152. * notification cleared.
  2153. *
  2154. * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  2155. * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  2156. * to wait for a notification value to have a non-zero value. The task does
  2157. * not consume any CPU time while it is in the Blocked state.
  2158. *
  2159. * **NOTE** Each notification within the array operates independently - a task
  2160. * can only block on one notification within the array at a time and will not be
  2161. * unblocked by a notification sent to any other array index.
  2162. *
  2163. * Backward compatibility information:
  2164. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2165. * all task notification API functions operated on that value. Replacing the
  2166. * single notification value with an array of notification values necessitated a
  2167. * new set of API functions that could address specific notifications within the
  2168. * array. xTaskNotifyWait() is the original API function, and remains backward
  2169. * compatible by always operating on the notification value at index 0 in the
  2170. * array. Calling xTaskNotifyWait() is equivalent to calling
  2171. * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  2172. *
  2173. * @param uxIndexToWaitOn The index within the calling task's array of
  2174. * notification values on which the calling task will wait for a notification to
  2175. * be received. uxIndexToWaitOn must be less than
  2176. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  2177. * not have this parameter and always waits for notifications on index 0.
  2178. *
  2179. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  2180. * will be cleared in the calling task's notification value before the task
  2181. * checks to see if any notifications are pending, and optionally blocks if no
  2182. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  2183. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  2184. * the effect of resetting the task's notification value to 0. Setting
  2185. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  2186. *
  2187. * @param ulBitsToClearOnExit If a notification is pending or received before
  2188. * the calling task exits the xTaskNotifyWait() function then the task's
  2189. * notification value (see the xTaskNotify() API function) is passed out using
  2190. * the pulNotificationValue parameter. Then any bits that are set in
  2191. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  2192. * *pulNotificationValue is set before any bits are cleared). Setting
  2193. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  2194. * (if limits.h is not included) will have the effect of resetting the task's
  2195. * notification value to 0 before the function exits. Setting
  2196. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  2197. * when the function exits (in which case the value passed out in
  2198. * pulNotificationValue will match the task's notification value).
  2199. *
  2200. * @param pulNotificationValue Used to pass the task's notification value out
  2201. * of the function. Note the value passed out will not be effected by the
  2202. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  2203. *
  2204. * @param xTicksToWait The maximum amount of time that the task should wait in
  2205. * the Blocked state for a notification to be received, should a notification
  2206. * not already be pending when xTaskNotifyWait() was called. The task
  2207. * will not consume any processing time while it is in the Blocked state. This
  2208. * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
  2209. * used to convert a time specified in milliseconds to a time specified in
  2210. * ticks.
  2211. *
  2212. * @return If a notification was received (including notifications that were
  2213. * already pending when xTaskNotifyWait was called) then pdPASS is
  2214. * returned. Otherwise pdFAIL is returned.
  2215. *
  2216. * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  2217. * \ingroup TaskNotifications
  2218. */
  2219. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  2220. uint32_t ulBitsToClearOnEntry,
  2221. uint32_t ulBitsToClearOnExit,
  2222. uint32_t * pulNotificationValue,
  2223. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2224. #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2225. xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2226. #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  2227. xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  2228. /**
  2229. * task. h
  2230. * <PRE>BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );</PRE>
  2231. * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
  2232. *
  2233. * Sends a direct to task notification to a particular index in the target
  2234. * task's notification array in a manner similar to giving a counting semaphore.
  2235. *
  2236. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2237. *
  2238. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2239. * macros to be available.
  2240. *
  2241. * Each task has a private array of "notification values" (or 'notifications'),
  2242. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2243. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2244. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2245. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2246. *
  2247. * Events can be sent to a task using an intermediary object. Examples of such
  2248. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2249. * are a method of sending an event directly to a task without the need for such
  2250. * an intermediary object.
  2251. *
  2252. * A notification sent to a task can optionally perform an action, such as
  2253. * update, overwrite or increment one of the task's notification values. In
  2254. * that way task notifications can be used to send data to a task, or be used as
  2255. * light weight and fast binary or counting semaphores.
  2256. *
  2257. * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
  2258. * notifications are used as light weight and faster binary or counting
  2259. * semaphore equivalents. Actual FreeRTOS semaphores are given using the
  2260. * xSemaphoreGive() API function, the equivalent action that instead uses a task
  2261. * notification is xTaskNotifyGiveIndexed().
  2262. *
  2263. * When task notifications are being used as a binary or counting semaphore
  2264. * equivalent then the task being notified should wait for the notification
  2265. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2266. * xTaskNotifyWaitIndexed() API function.
  2267. *
  2268. * **NOTE** Each notification within the array operates independently - a task
  2269. * can only block on one notification within the array at a time and will not be
  2270. * unblocked by a notification sent to any other array index.
  2271. *
  2272. * Backward compatibility information:
  2273. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2274. * all task notification API functions operated on that value. Replacing the
  2275. * single notification value with an array of notification values necessitated a
  2276. * new set of API functions that could address specific notifications within the
  2277. * array. xTaskNotifyGive() is the original API function, and remains backward
  2278. * compatible by always operating on the notification value at index 0 in the
  2279. * array. Calling xTaskNotifyGive() is equivalent to calling
  2280. * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
  2281. *
  2282. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2283. * task can be returned from the xTaskCreate() API function used to create the
  2284. * task, and the handle of the currently running task can be obtained by calling
  2285. * xTaskGetCurrentTaskHandle().
  2286. *
  2287. * @param uxIndexToNotify The index within the target task's array of
  2288. * notification values to which the notification is to be sent. uxIndexToNotify
  2289. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
  2290. * does not have this parameter and always sends notifications to index 0.
  2291. *
  2292. * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  2293. * eAction parameter set to eIncrement - so pdPASS is always returned.
  2294. *
  2295. * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
  2296. * \ingroup TaskNotifications
  2297. */
  2298. #define xTaskNotifyGive( xTaskToNotify ) \
  2299. xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
  2300. #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
  2301. xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
  2302. /**
  2303. * task. h
  2304. * <PRE>void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2305. * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  2306. *
  2307. * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
  2308. * service routine (ISR).
  2309. *
  2310. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  2311. *
  2312. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  2313. * to be available.
  2314. *
  2315. * Each task has a private array of "notification values" (or 'notifications'),
  2316. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2317. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2318. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2319. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2320. *
  2321. * Events can be sent to a task using an intermediary object. Examples of such
  2322. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2323. * are a method of sending an event directly to a task without the need for such
  2324. * an intermediary object.
  2325. *
  2326. * A notification sent to a task can optionally perform an action, such as
  2327. * update, overwrite or increment one of the task's notification values. In
  2328. * that way task notifications can be used to send data to a task, or be used as
  2329. * light weight and fast binary or counting semaphores.
  2330. *
  2331. * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
  2332. * are used as light weight and faster binary or counting semaphore equivalents.
  2333. * Actual FreeRTOS semaphores are given from an ISR using the
  2334. * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  2335. * a task notification is vTaskNotifyGiveIndexedFromISR().
  2336. *
  2337. * When task notifications are being used as a binary or counting semaphore
  2338. * equivalent then the task being notified should wait for the notification
  2339. * using the ulTaskNotificationTakeIndexed() API function rather than the
  2340. * xTaskNotifyWaitIndexed() API function.
  2341. *
  2342. * **NOTE** Each notification within the array operates independently - a task
  2343. * can only block on one notification within the array at a time and will not be
  2344. * unblocked by a notification sent to any other array index.
  2345. *
  2346. * Backward compatibility information:
  2347. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2348. * all task notification API functions operated on that value. Replacing the
  2349. * single notification value with an array of notification values necessitated a
  2350. * new set of API functions that could address specific notifications within the
  2351. * array. xTaskNotifyFromISR() is the original API function, and remains
  2352. * backward compatible by always operating on the notification value at index 0
  2353. * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
  2354. * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  2355. *
  2356. * @param xTaskToNotify The handle of the task being notified. The handle to a
  2357. * task can be returned from the xTaskCreate() API function used to create the
  2358. * task, and the handle of the currently running task can be obtained by calling
  2359. * xTaskGetCurrentTaskHandle().
  2360. *
  2361. * @param uxIndexToNotify The index within the target task's array of
  2362. * notification values to which the notification is to be sent. uxIndexToNotify
  2363. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2364. * xTaskNotifyGiveFromISR() does not have this parameter and always sends
  2365. * notifications to index 0.
  2366. *
  2367. * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  2368. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  2369. * task to which the notification was sent to leave the Blocked state, and the
  2370. * unblocked task has a priority higher than the currently running task. If
  2371. * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  2372. * should be requested before the interrupt is exited. How a context switch is
  2373. * requested from an ISR is dependent on the port - see the documentation page
  2374. * for the port in use.
  2375. *
  2376. * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
  2377. * \ingroup TaskNotifications
  2378. */
  2379. void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  2380. UBaseType_t uxIndexToNotify,
  2381. BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  2382. #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
  2383. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
  2384. #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
  2385. vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
  2386. /**
  2387. * task. h
  2388. * <pre>
  2389. * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2390. *
  2391. * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  2392. * </pre>
  2393. *
  2394. * Waits for a direct to task notification on a particular index in the calling
  2395. * task's notification array in a manner similar to taking a counting semaphore.
  2396. *
  2397. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2398. *
  2399. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  2400. * function to be available.
  2401. *
  2402. * Each task has a private array of "notification values" (or 'notifications'),
  2403. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2404. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2405. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2406. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2407. *
  2408. * Events can be sent to a task using an intermediary object. Examples of such
  2409. * objects are queues, semaphores, mutexes and event groups. Task notifications
  2410. * are a method of sending an event directly to a task without the need for such
  2411. * an intermediary object.
  2412. *
  2413. * A notification sent to a task can optionally perform an action, such as
  2414. * update, overwrite or increment one of the task's notification values. In
  2415. * that way task notifications can be used to send data to a task, or be used as
  2416. * light weight and fast binary or counting semaphores.
  2417. *
  2418. * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
  2419. * used as a faster and lighter weight binary or counting semaphore alternative.
  2420. * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
  2421. * the equivalent action that instead uses a task notification is
  2422. * ulTaskNotifyTakeIndexed().
  2423. *
  2424. * When a task is using its notification value as a binary or counting semaphore
  2425. * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
  2426. * macro, or xTaskNotifyIndex() function with the eAction parameter set to
  2427. * eIncrement.
  2428. *
  2429. * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
  2430. * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
  2431. * in which case the notification value acts like a binary semaphore, or
  2432. * decrement the notification value on exit, in which case the notification
  2433. * value acts like a counting semaphore.
  2434. *
  2435. * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
  2436. * the task's notification value to be non-zero. The task does not consume any
  2437. * CPU time while it is in the Blocked state.
  2438. *
  2439. * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
  2440. * ulTaskNotifyTakeIndexed() will return when the task's notification value is
  2441. * not zero.
  2442. *
  2443. * **NOTE** Each notification within the array operates independently - a task
  2444. * can only block on one notification within the array at a time and will not be
  2445. * unblocked by a notification sent to any other array index.
  2446. *
  2447. * Backward compatibility information:
  2448. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2449. * all task notification API functions operated on that value. Replacing the
  2450. * single notification value with an array of notification values necessitated a
  2451. * new set of API functions that could address specific notifications within the
  2452. * array. ulTaskNotifyTake() is the original API function, and remains backward
  2453. * compatible by always operating on the notification value at index 0 in the
  2454. * array. Calling ulTaskNotifyTake() is equivalent to calling
  2455. * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
  2456. *
  2457. * @param uxIndexToWaitOn The index within the calling task's array of
  2458. * notification values on which the calling task will wait for a notification to
  2459. * be non-zero. uxIndexToWaitOn must be less than
  2460. * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
  2461. * not have this parameter and always waits for notifications on index 0.
  2462. *
  2463. * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  2464. * notification value is decremented when the function exits. In this way the
  2465. * notification value acts like a counting semaphore. If xClearCountOnExit is
  2466. * not pdFALSE then the task's notification value is cleared to zero when the
  2467. * function exits. In this way the notification value acts like a binary
  2468. * semaphore.
  2469. *
  2470. * @param xTicksToWait The maximum amount of time that the task should wait in
  2471. * the Blocked state for the task's notification value to be greater than zero,
  2472. * should the count not already be greater than zero when
  2473. * ulTaskNotifyTake() was called. The task will not consume any processing
  2474. * time while it is in the Blocked state. This is specified in kernel ticks,
  2475. * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
  2476. * specified in milliseconds to a time specified in ticks.
  2477. *
  2478. * @return The task's notification count before it is either cleared to zero or
  2479. * decremented (see the xClearCountOnExit parameter).
  2480. *
  2481. * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
  2482. * \ingroup TaskNotifications
  2483. */
  2484. uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
  2485. BaseType_t xClearCountOnExit,
  2486. TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2487. #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
  2488. ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2489. #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
  2490. ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
  2491. /**
  2492. * task. h
  2493. * <pre>
  2494. * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
  2495. *
  2496. * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  2497. * </pre>
  2498. *
  2499. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2500. *
  2501. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2502. * functions to be available.
  2503. *
  2504. * Each task has a private array of "notification values" (or 'notifications'),
  2505. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2506. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2507. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2508. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2509. *
  2510. * If a notification is sent to an index within the array of notifications then
  2511. * the notification at that index is said to be 'pending' until it is read or
  2512. * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
  2513. * is the function that clears a pending notification without reading the
  2514. * notification value. The notification value at the same array index is not
  2515. * altered. Set xTask to NULL to clear the notification state of the calling
  2516. * task.
  2517. *
  2518. * Backward compatibility information:
  2519. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2520. * all task notification API functions operated on that value. Replacing the
  2521. * single notification value with an array of notification values necessitated a
  2522. * new set of API functions that could address specific notifications within the
  2523. * array. xTaskNotifyStateClear() is the original API function, and remains
  2524. * backward compatible by always operating on the notification value at index 0
  2525. * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
  2526. * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
  2527. *
  2528. * @param xTask The handle of the RTOS task that will have a notification state
  2529. * cleared. Set xTask to NULL to clear a notification state in the calling
  2530. * task. To obtain a task's handle create the task using xTaskCreate() and
  2531. * make use of the pxCreatedTask parameter, or create the task using
  2532. * xTaskCreateStatic() and store the returned value, or use the task's name in
  2533. * a call to xTaskGetHandle().
  2534. *
  2535. * @param uxIndexToClear The index within the target task's array of
  2536. * notification values to act upon. For example, setting uxIndexToClear to 1
  2537. * will clear the state of the notification at index 1 within the array.
  2538. * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2539. * ulTaskNotifyStateClear() does not have this parameter and always acts on the
  2540. * notification at index 0.
  2541. *
  2542. * @return pdTRUE if the task's notification state was set to
  2543. * eNotWaitingNotification, otherwise pdFALSE.
  2544. *
  2545. * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
  2546. * \ingroup TaskNotifications
  2547. */
  2548. BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  2549. UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
  2550. #define xTaskNotifyStateClear( xTask ) \
  2551. xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
  2552. #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
  2553. xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
  2554. /**
  2555. * task. h
  2556. * <pre>
  2557. * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
  2558. *
  2559. * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
  2560. * </pre>
  2561. *
  2562. * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2563. *
  2564. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  2565. * functions to be available.
  2566. *
  2567. * Each task has a private array of "notification values" (or 'notifications'),
  2568. * each of which is a 32-bit unsigned integer (uint32_t). The constant
  2569. * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  2570. * array, and (for backward compatibility) defaults to 1 if left undefined.
  2571. * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  2572. *
  2573. * ulTaskNotifyValueClearIndexed() clears the bits specified by the
  2574. * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
  2575. * of the task referenced by xTask.
  2576. *
  2577. * Backward compatibility information:
  2578. * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  2579. * all task notification API functions operated on that value. Replacing the
  2580. * single notification value with an array of notification values necessitated a
  2581. * new set of API functions that could address specific notifications within the
  2582. * array. ulTaskNotifyValueClear() is the original API function, and remains
  2583. * backward compatible by always operating on the notification value at index 0
  2584. * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
  2585. * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
  2586. *
  2587. * @param xTask The handle of the RTOS task that will have bits in one of its
  2588. * notification values cleared. Set xTask to NULL to clear bits in a
  2589. * notification value of the calling task. To obtain a task's handle create the
  2590. * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
  2591. * create the task using xTaskCreateStatic() and store the returned value, or
  2592. * use the task's name in a call to xTaskGetHandle().
  2593. *
  2594. * @param uxIndexToClear The index within the target task's array of
  2595. * notification values in which to clear the bits. uxIndexToClear
  2596. * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  2597. * ulTaskNotifyValueClear() does not have this parameter and always clears bits
  2598. * in the notification value at index 0.
  2599. *
  2600. * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
  2601. * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
  2602. * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
  2603. * the notification value to 0. Set ulBitsToClear to 0 to query the task's
  2604. * notification value without clearing any bits.
  2605. *
  2606. *
  2607. * @return The value of the target task's notification value before the bits
  2608. * specified by ulBitsToClear were cleared.
  2609. * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
  2610. * \ingroup TaskNotifications
  2611. */
  2612. uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  2613. UBaseType_t uxIndexToClear,
  2614. uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
  2615. #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
  2616. ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
  2617. #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
  2618. ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
  2619. /**
  2620. * task.h
  2621. * <pre>
  2622. * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  2623. * </pre>
  2624. *
  2625. * Capture the current time for future use with xTaskCheckForTimeOut().
  2626. *
  2627. * @param pxTimeOut Pointer to a timeout object into which the current time
  2628. * is to be captured. The captured time includes the tick count and the number
  2629. * of times the tick count has overflowed since the system first booted.
  2630. * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
  2631. * \ingroup TaskCtrl
  2632. */
  2633. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2634. /**
  2635. * task.h
  2636. * <pre>
  2637. * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
  2638. * </pre>
  2639. *
  2640. * Determines if pxTicksToWait ticks has passed since a time was captured
  2641. * using a call to vTaskSetTimeOutState(). The captured time includes the tick
  2642. * count and the number of times the tick count has overflowed.
  2643. *
  2644. * @param pxTimeOut The time status as captured previously using
  2645. * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
  2646. * to reflect the current time status.
  2647. * @param pxTicksToWait The number of ticks to check for timeout i.e. if
  2648. * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
  2649. * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
  2650. * If the timeout has not occurred, pxTIcksToWait is updated to reflect the
  2651. * number of remaining ticks.
  2652. *
  2653. * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
  2654. * returned and pxTicksToWait is updated to reflect the number of remaining
  2655. * ticks.
  2656. *
  2657. * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
  2658. *
  2659. * Example Usage:
  2660. * <pre>
  2661. * // Driver library function used to receive uxWantedBytes from an Rx buffer
  2662. * // that is filled by a UART interrupt. If there are not enough bytes in the
  2663. * // Rx buffer then the task enters the Blocked state until it is notified that
  2664. * // more data has been placed into the buffer. If there is still not enough
  2665. * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
  2666. * // is used to re-calculate the Block time to ensure the total amount of time
  2667. * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
  2668. * // continues until either the buffer contains at least uxWantedBytes bytes,
  2669. * // or the total amount of time spent in the Blocked state reaches
  2670. * // MAX_TIME_TO_WAIT �at which point the task reads however many bytes are
  2671. * // available up to a maximum of uxWantedBytes.
  2672. *
  2673. * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
  2674. * {
  2675. * size_t uxReceived = 0;
  2676. * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
  2677. * TimeOut_t xTimeOut;
  2678. *
  2679. * // Initialize xTimeOut. This records the time at which this function
  2680. * // was entered.
  2681. * vTaskSetTimeOutState( &xTimeOut );
  2682. *
  2683. * // Loop until the buffer contains the wanted number of bytes, or a
  2684. * // timeout occurs.
  2685. * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
  2686. * {
  2687. * // The buffer didn't contain enough data so this task is going to
  2688. * // enter the Blocked state. Adjusting xTicksToWait to account for
  2689. * // any time that has been spent in the Blocked state within this
  2690. * // function so far to ensure the total amount of time spent in the
  2691. * // Blocked state does not exceed MAX_TIME_TO_WAIT.
  2692. * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
  2693. * {
  2694. * //Timed out before the wanted number of bytes were available,
  2695. * // exit the loop.
  2696. * break;
  2697. * }
  2698. *
  2699. * // Wait for a maximum of xTicksToWait ticks to be notified that the
  2700. * // receive interrupt has placed more data into the buffer.
  2701. * ulTaskNotifyTake( pdTRUE, xTicksToWait );
  2702. * }
  2703. *
  2704. * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
  2705. * // The actual number of bytes read (which might be less than
  2706. * // uxWantedBytes) is returned.
  2707. * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
  2708. * pucBuffer,
  2709. * uxWantedBytes );
  2710. *
  2711. * return uxReceived;
  2712. * }
  2713. * </pre>
  2714. * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
  2715. * \ingroup TaskCtrl
  2716. */
  2717. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  2718. TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
  2719. /**
  2720. * task.h
  2721. * <pre>
  2722. * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
  2723. * </pre>
  2724. *
  2725. * This function corrects the tick count value after the application code has held
  2726. * interrupts disabled for an extended period resulting in tick interrupts having
  2727. * been missed.
  2728. *
  2729. * This function is similar to vTaskStepTick(), however, unlike
  2730. * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
  2731. * time at which a task should be removed from the blocked state. That means
  2732. * tasks may have to be removed from the blocked state as the tick count is
  2733. * moved.
  2734. *
  2735. * @param xTicksToCatchUp The number of tick interrupts that have been missed due to
  2736. * interrupts being disabled. Its value is not computed automatically, so must be
  2737. * computed by the application writer.
  2738. *
  2739. * @return pdTRUE if moving the tick count forward resulted in a task leaving the
  2740. * blocked state and a context switch being performed. Otherwise pdFALSE.
  2741. *
  2742. * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks
  2743. * \ingroup TaskCtrl
  2744. */
  2745. BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
  2746. /*-----------------------------------------------------------
  2747. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  2748. *----------------------------------------------------------*/
  2749. /*
  2750. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2751. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2752. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2753. *
  2754. * Called from the real time kernel tick (either preemptive or cooperative),
  2755. * this increments the tick count and checks if any tasks that are blocked
  2756. * for a finite period required removing from a blocked list and placing on
  2757. * a ready list. If a non-zero value is returned then a context switch is
  2758. * required because either:
  2759. * + A task was removed from a blocked list because its timeout had expired,
  2760. * or
  2761. * + Time slicing is in use and there is a task of equal priority to the
  2762. * currently running task.
  2763. */
  2764. BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
  2765. /*
  2766. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2767. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2768. *
  2769. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2770. *
  2771. * Removes the calling task from the ready list and places it both
  2772. * on the list of tasks waiting for a particular event, and the
  2773. * list of delayed tasks. The task will be removed from both lists
  2774. * and replaced on the ready list should either the event occur (and
  2775. * there be no higher priority tasks waiting on the same event) or
  2776. * the delay period expires.
  2777. *
  2778. * The 'unordered' version replaces the event list item value with the
  2779. * xItemValue value, and inserts the list item at the end of the list.
  2780. *
  2781. * The 'ordered' version uses the existing event list item value (which is the
  2782. * owning tasks priority) to insert the list item into the event list is task
  2783. * priority order.
  2784. *
  2785. * @param pxEventList The list containing tasks that are blocked waiting
  2786. * for the event to occur.
  2787. *
  2788. * @param xItemValue The item value to use for the event list item when the
  2789. * event list is not ordered by task priority.
  2790. *
  2791. * @param xTicksToWait The maximum amount of time that the task should wait
  2792. * for the event to occur. This is specified in kernel ticks,the constant
  2793. * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
  2794. * period.
  2795. */
  2796. void vTaskPlaceOnEventList( List_t * const pxEventList,
  2797. const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2798. void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
  2799. const TickType_t xItemValue,
  2800. const TickType_t xTicksToWait ) 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. * This function performs nearly the same function as vTaskPlaceOnEventList().
  2808. * The difference being that this function does not permit tasks to block
  2809. * indefinitely, whereas vTaskPlaceOnEventList() does.
  2810. *
  2811. */
  2812. void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
  2813. TickType_t xTicksToWait,
  2814. const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  2815. /*
  2816. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2817. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2818. *
  2819. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2820. *
  2821. * Removes a task from both the specified event list and the list of blocked
  2822. * tasks, and places it on a ready queue.
  2823. *
  2824. * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
  2825. * if either an event occurs to unblock a task, or the block timeout period
  2826. * expires.
  2827. *
  2828. * xTaskRemoveFromEventList() is used when the event list is in task priority
  2829. * order. It removes the list item from the head of the event list as that will
  2830. * have the highest priority owning task of all the tasks on the event list.
  2831. * vTaskRemoveFromUnorderedEventList() is used when the event list is not
  2832. * ordered and the event list items hold something other than the owning tasks
  2833. * priority. In this case the event list item value is updated to the value
  2834. * passed in the xItemValue parameter.
  2835. *
  2836. * @return pdTRUE if the task being removed has a higher priority than the task
  2837. * making the call, otherwise pdFALSE.
  2838. */
  2839. BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
  2840. void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
  2841. const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
  2842. /*
  2843. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2844. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2845. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2846. *
  2847. * Sets the pointer to the current TCB to the TCB of the highest priority task
  2848. * that is ready to run.
  2849. */
  2850. portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
  2851. /*
  2852. * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
  2853. * THE EVENT BITS MODULE.
  2854. */
  2855. TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
  2856. /*
  2857. * Return the handle of the calling task.
  2858. */
  2859. TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
  2860. /*
  2861. * Shortcut used by the queue implementation to prevent unnecessary call to
  2862. * taskYIELD();
  2863. */
  2864. void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
  2865. /*
  2866. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  2867. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  2868. */
  2869. BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  2870. /*
  2871. * Raises the priority of the mutex holder to that of the calling task should
  2872. * the mutex holder have a priority less than the calling task.
  2873. */
  2874. BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2875. /*
  2876. * Set the priority of a task back to its proper priority in the case that it
  2877. * inherited a higher priority while it was holding a semaphore.
  2878. */
  2879. BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2880. /*
  2881. * If a higher priority task attempting to obtain a mutex caused a lower
  2882. * priority task to inherit the higher priority task's priority - but the higher
  2883. * priority task then timed out without obtaining the mutex, then the lower
  2884. * priority task will disinherit the priority again - but only down as far as
  2885. * the highest priority task that is still waiting for the mutex (if there were
  2886. * more than one task waiting for the mutex).
  2887. */
  2888. void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder,
  2889. UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
  2890. /*
  2891. * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
  2892. */
  2893. UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  2894. /*
  2895. * Set the uxTaskNumber of the task referenced by the xTask parameter to
  2896. * uxHandle.
  2897. */
  2898. void vTaskSetTaskNumber( TaskHandle_t xTask,
  2899. const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
  2900. /*
  2901. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2902. * If tickless mode is being used, or a low power mode is implemented, then
  2903. * the tick interrupt will not execute during idle periods. When this is the
  2904. * case, the tick count value maintained by the scheduler needs to be kept up
  2905. * to date with the actual execution time by being skipped forward by a time
  2906. * equal to the idle period.
  2907. */
  2908. void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
  2909. /*
  2910. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2911. * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
  2912. * specific sleep function to determine if it is ok to proceed with the sleep,
  2913. * and if it is ok to proceed, if it is ok to sleep indefinitely.
  2914. *
  2915. * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
  2916. * called with the scheduler suspended, not from within a critical section. It
  2917. * is therefore possible for an interrupt to request a context switch between
  2918. * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
  2919. * entered. eTaskConfirmSleepModeStatus() should be called from a short
  2920. * critical section between the timer being stopped and the sleep mode being
  2921. * entered to ensure it is ok to proceed into the sleep mode.
  2922. */
  2923. eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
  2924. /*
  2925. * For internal use only. Increment the mutex held count when a mutex is
  2926. * taken and return the handle of the task that has taken the mutex.
  2927. */
  2928. TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
  2929. /*
  2930. * For internal use only. Same as vTaskSetTimeOutState(), but without a critical
  2931. * section.
  2932. */
  2933. void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2934. /* *INDENT-OFF* */
  2935. #ifdef __cplusplus
  2936. }
  2937. #endif
  2938. /* *INDENT-ON* */
  2939. #endif /* INC_TASK_H */