task.h 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. /*
  2. * FreeRTOS Kernel V10.2.1
  3. * Copyright (C) 2019 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. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */
  27. #ifndef INC_TASK_H
  28. #define INC_TASK_H
  29. #ifndef INC_FREERTOS_H
  30. #error "include FreeRTOS.h must appear in source files before include task.h"
  31. #endif
  32. #include "list.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /*-----------------------------------------------------------
  37. * MACROS AND DEFINITIONS
  38. *----------------------------------------------------------*/
  39. #define tskKERNEL_VERSION_NUMBER "V10.2.0"
  40. #define tskKERNEL_VERSION_MAJOR 10
  41. #define tskKERNEL_VERSION_MINOR 2
  42. #define tskKERNEL_VERSION_BUILD 0
  43. /* MPU region parameters passed in ulParameters
  44. * of MemoryRegion_t struct. */
  45. #define tskMPU_REGION_READ_ONLY ( 1UL << 0UL )
  46. #define tskMPU_REGION_READ_WRITE ( 1UL << 1UL )
  47. #define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL )
  48. #define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL )
  49. #define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL )
  50. /**
  51. * task. h
  52. *
  53. * Type by which tasks are referenced. For example, a call to xTaskCreate
  54. * returns (via a pointer parameter) an TaskHandle_t variable that can then
  55. * be used as a parameter to vTaskDelete to delete the task.
  56. *
  57. * \defgroup TaskHandle_t TaskHandle_t
  58. * \ingroup Tasks
  59. */
  60. struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  61. typedef struct tskTaskControlBlock* TaskHandle_t;
  62. /*
  63. * Defines the prototype to which the application task hook function must
  64. * conform.
  65. */
  66. typedef BaseType_t (*TaskHookFunction_t)( void * );
  67. /* Task states returned by eTaskGetState. */
  68. typedef enum
  69. {
  70. eRunning = 0, /* A task is querying the state of itself, so must be running. */
  71. eReady, /* The task being queried is in a read or pending ready list. */
  72. eBlocked, /* The task being queried is in the Blocked state. */
  73. eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  74. eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
  75. eInvalid /* Used as an 'invalid state' value. */
  76. } eTaskState;
  77. /* Actions that can be performed when vTaskNotify() is called. */
  78. typedef enum
  79. {
  80. eNoAction = 0, /* Notify the task without updating its notify value. */
  81. eSetBits, /* Set bits in the task's notification value. */
  82. eIncrement, /* Increment the task's notification value. */
  83. eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
  84. eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
  85. } eNotifyAction;
  86. /*
  87. * Used internally only.
  88. */
  89. typedef struct xTIME_OUT
  90. {
  91. BaseType_t xOverflowCount;
  92. TickType_t xTimeOnEntering;
  93. } TimeOut_t;
  94. /*
  95. * Defines the memory ranges allocated to the task when an MPU is used.
  96. */
  97. typedef struct xMEMORY_REGION
  98. {
  99. void *pvBaseAddress;
  100. uint32_t ulLengthInBytes;
  101. uint32_t ulParameters;
  102. } MemoryRegion_t;
  103. /*
  104. * Parameters required to create an MPU protected task.
  105. */
  106. typedef struct xTASK_PARAMETERS
  107. {
  108. TaskFunction_t pvTaskCode;
  109. const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  110. configSTACK_DEPTH_TYPE usStackDepth;
  111. void *pvParameters;
  112. UBaseType_t uxPriority;
  113. StackType_t *puxStackBuffer;
  114. MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
  115. #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  116. StaticTask_t * const pxTaskBuffer;
  117. #endif
  118. } TaskParameters_t;
  119. /* Used with the uxTaskGetSystemState() function to return the state of each task
  120. in the system. */
  121. typedef struct xTASK_STATUS
  122. {
  123. TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
  124. 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. */
  125. UBaseType_t xTaskNumber; /* A number unique to the task. */
  126. eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
  127. UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
  128. 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. */
  129. uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
  130. StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
  131. 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. */
  132. } TaskStatus_t;
  133. /* Possible return values for eTaskConfirmSleepModeStatus(). */
  134. typedef enum
  135. {
  136. 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. */
  137. eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
  138. 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. */
  139. } eSleepModeStatus;
  140. /**
  141. * Defines the priority used by the idle task. This must not be modified.
  142. *
  143. * \ingroup TaskUtils
  144. */
  145. #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
  146. /**
  147. * task. h
  148. *
  149. * Macro for forcing a context switch.
  150. *
  151. * \defgroup taskYIELD taskYIELD
  152. * \ingroup SchedulerControl
  153. */
  154. #define taskYIELD() portYIELD()
  155. /**
  156. * task. h
  157. *
  158. * Macro to mark the start of a critical code region. Preemptive context
  159. * switches cannot occur when in a critical region.
  160. *
  161. * NOTE: This may alter the stack (depending on the portable implementation)
  162. * so must be used with care!
  163. *
  164. * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  165. * \ingroup SchedulerControl
  166. */
  167. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  168. #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  169. /**
  170. * task. h
  171. *
  172. * Macro to mark the end of a critical code region. Preemptive context
  173. * switches cannot occur when in a critical region.
  174. *
  175. * NOTE: This may alter the stack (depending on the portable implementation)
  176. * so must be used with care!
  177. *
  178. * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  179. * \ingroup SchedulerControl
  180. */
  181. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  182. #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  183. /**
  184. * task. h
  185. *
  186. * Macro to disable all maskable interrupts.
  187. *
  188. * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  189. * \ingroup SchedulerControl
  190. */
  191. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  192. /**
  193. * task. h
  194. *
  195. * Macro to enable microcontroller interrupts.
  196. *
  197. * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  198. * \ingroup SchedulerControl
  199. */
  200. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  201. /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
  202. 0 to generate more optimal code when configASSERT() is defined as the constant
  203. is used in assert() statements. */
  204. #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
  205. #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
  206. #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
  207. /*-----------------------------------------------------------
  208. * TASK CREATION API
  209. *----------------------------------------------------------*/
  210. /**
  211. * task. h
  212. *<pre>
  213. BaseType_t xTaskCreate(
  214. TaskFunction_t pvTaskCode,
  215. const char * const pcName,
  216. configSTACK_DEPTH_TYPE usStackDepth,
  217. void *pvParameters,
  218. UBaseType_t uxPriority,
  219. TaskHandle_t *pvCreatedTask
  220. );</pre>
  221. *
  222. * Create a new task and add it to the list of tasks that are ready to run.
  223. *
  224. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  225. * memory. The first block is used to hold the task's data structures. The
  226. * second block is used by the task as its stack. If a task is created using
  227. * xTaskCreate() then both blocks of memory are automatically dynamically
  228. * allocated inside the xTaskCreate() function. (see
  229. * http://www.freertos.org/a00111.html). If a task is created using
  230. * xTaskCreateStatic() then the application writer must provide the required
  231. * memory. xTaskCreateStatic() therefore allows a task to be created without
  232. * using any dynamic memory allocation.
  233. *
  234. * See xTaskCreateStatic() for a version that does not use any dynamic memory
  235. * allocation.
  236. *
  237. * xTaskCreate() can only be used to create a task that has unrestricted
  238. * access to the entire microcontroller memory map. Systems that include MPU
  239. * support can alternatively create an MPU constrained task using
  240. * xTaskCreateRestricted().
  241. *
  242. * @param pvTaskCode Pointer to the task entry function. Tasks
  243. * must be implemented to never return (i.e. continuous loop).
  244. *
  245. * @param pcName A descriptive name for the task. This is mainly used to
  246. * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
  247. * is 16.
  248. *
  249. * @param usStackDepth The size of the task stack specified as the number of
  250. * variables the stack can hold - not the number of bytes. For example, if
  251. * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  252. * will be allocated for stack storage.
  253. *
  254. * @param pvParameters Pointer that will be used as the parameter for the task
  255. * being created.
  256. *
  257. * @param uxPriority The priority at which the task should run. Systems that
  258. * include MPU support can optionally create tasks in a privileged (system)
  259. * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  260. * example, to create a privileged task at priority 2 the uxPriority parameter
  261. * should be set to ( 2 | portPRIVILEGE_BIT ).
  262. *
  263. * @param pvCreatedTask Used to pass back a handle by which the created task
  264. * can be referenced.
  265. *
  266. * @return pdPASS if the task was successfully created and added to a ready
  267. * list, otherwise an error code defined in the file projdefs.h
  268. *
  269. * Example usage:
  270. <pre>
  271. // Task to be created.
  272. void vTaskCode( void * pvParameters )
  273. {
  274. for( ;; )
  275. {
  276. // Task code goes here.
  277. }
  278. }
  279. // Function that creates a task.
  280. void vOtherFunction( void )
  281. {
  282. static uint8_t ucParameterToPass;
  283. TaskHandle_t xHandle = NULL;
  284. // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  285. // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  286. // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  287. // the new task attempts to access it.
  288. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  289. configASSERT( xHandle );
  290. // Use the handle to delete the task.
  291. if( xHandle != NULL )
  292. {
  293. vTaskDelete( xHandle );
  294. }
  295. }
  296. </pre>
  297. * \defgroup xTaskCreate xTaskCreate
  298. * \ingroup Tasks
  299. */
  300. #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  301. BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  302. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  303. const configSTACK_DEPTH_TYPE usStackDepth,
  304. void * const pvParameters,
  305. UBaseType_t uxPriority,
  306. TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
  307. #endif
  308. /**
  309. * task. h
  310. *<pre>
  311. TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
  312. const char * const pcName,
  313. uint32_t ulStackDepth,
  314. void *pvParameters,
  315. UBaseType_t uxPriority,
  316. StackType_t *pxStackBuffer,
  317. StaticTask_t *pxTaskBuffer );</pre>
  318. *
  319. * Create a new task and add it to the list of tasks that are ready to run.
  320. *
  321. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  322. * memory. The first block is used to hold the task's data structures. The
  323. * second block is used by the task as its stack. If a task is created using
  324. * xTaskCreate() then both blocks of memory are automatically dynamically
  325. * allocated inside the xTaskCreate() function. (see
  326. * http://www.freertos.org/a00111.html). If a task is created using
  327. * xTaskCreateStatic() then the application writer must provide the required
  328. * memory. xTaskCreateStatic() therefore allows a task to be created without
  329. * using any dynamic memory allocation.
  330. *
  331. * @param pvTaskCode Pointer to the task entry function. Tasks
  332. * must be implemented to never return (i.e. continuous loop).
  333. *
  334. * @param pcName A descriptive name for the task. This is mainly used to
  335. * facilitate debugging. The maximum length of the string is defined by
  336. * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  337. *
  338. * @param ulStackDepth The size of the task stack specified as the number of
  339. * variables the stack can hold - not the number of bytes. For example, if
  340. * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
  341. * will be allocated for stack storage.
  342. *
  343. * @param pvParameters Pointer that will be used as the parameter for the task
  344. * being created.
  345. *
  346. * @param uxPriority The priority at which the task will run.
  347. *
  348. * @param pxStackBuffer Must point to a StackType_t array that has at least
  349. * ulStackDepth indexes - the array will then be used as the task's stack,
  350. * removing the need for the stack to be allocated dynamically.
  351. *
  352. * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
  353. * then be used to hold the task's data structures, removing the need for the
  354. * memory to be allocated dynamically.
  355. *
  356. * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
  357. * be created and a handle to the created task is returned. If either
  358. * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
  359. * NULL is returned.
  360. *
  361. * Example usage:
  362. <pre>
  363. // Dimensions the buffer that the task being created will use as its stack.
  364. // NOTE: This is the number of words the stack will hold, not the number of
  365. // bytes. For example, if each stack item is 32-bits, and this is set to 100,
  366. // then 400 bytes (100 * 32-bits) will be allocated.
  367. #define STACK_SIZE 200
  368. // Structure that will hold the TCB of the task being created.
  369. StaticTask_t xTaskBuffer;
  370. // Buffer that the task being created will use as its stack. Note this is
  371. // an array of StackType_t variables. The size of StackType_t is dependent on
  372. // the RTOS port.
  373. StackType_t xStack[ STACK_SIZE ];
  374. // Function that implements the task being created.
  375. void vTaskCode( void * pvParameters )
  376. {
  377. // The parameter value is expected to be 1 as 1 is passed in the
  378. // pvParameters value in the call to xTaskCreateStatic().
  379. configASSERT( ( uint32_t ) pvParameters == 1UL );
  380. for( ;; )
  381. {
  382. // Task code goes here.
  383. }
  384. }
  385. // Function that creates a task.
  386. void vOtherFunction( void )
  387. {
  388. TaskHandle_t xHandle = NULL;
  389. // Create the task without using any dynamic memory allocation.
  390. xHandle = xTaskCreateStatic(
  391. vTaskCode, // Function that implements the task.
  392. "NAME", // Text name for the task.
  393. STACK_SIZE, // Stack size in words, not bytes.
  394. ( void * ) 1, // Parameter passed into the task.
  395. tskIDLE_PRIORITY,// Priority at which the task is created.
  396. xStack, // Array to use as the task's stack.
  397. &xTaskBuffer ); // Variable to hold the task's data structure.
  398. // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
  399. // been created, and xHandle will be the task's handle. Use the handle
  400. // to suspend the task.
  401. vTaskSuspend( xHandle );
  402. }
  403. </pre>
  404. * \defgroup xTaskCreateStatic xTaskCreateStatic
  405. * \ingroup Tasks
  406. */
  407. #if( configSUPPORT_STATIC_ALLOCATION == 1 )
  408. TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  409. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  410. const uint32_t ulStackDepth,
  411. void * const pvParameters,
  412. UBaseType_t uxPriority,
  413. StackType_t * const puxStackBuffer,
  414. StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
  415. #endif /* configSUPPORT_STATIC_ALLOCATION */
  416. /**
  417. * task. h
  418. *<pre>
  419. BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
  420. *
  421. * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
  422. *
  423. * xTaskCreateRestricted() should only be used in systems that include an MPU
  424. * implementation.
  425. *
  426. * Create a new task and add it to the list of tasks that are ready to run.
  427. * The function parameters define the memory regions and associated access
  428. * permissions allocated to the task.
  429. *
  430. * See xTaskCreateRestrictedStatic() for a version that does not use any
  431. * dynamic memory allocation.
  432. *
  433. * @param pxTaskDefinition Pointer to a structure that contains a member
  434. * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
  435. * documentation) plus an optional stack buffer and the memory region
  436. * definitions.
  437. *
  438. * @param pxCreatedTask Used to pass back a handle by which the created task
  439. * can be referenced.
  440. *
  441. * @return pdPASS if the task was successfully created and added to a ready
  442. * list, otherwise an error code defined in the file projdefs.h
  443. *
  444. * Example usage:
  445. <pre>
  446. // Create an TaskParameters_t structure that defines the task to be created.
  447. static const TaskParameters_t xCheckTaskParameters =
  448. {
  449. vATask, // pvTaskCode - the function that implements the task.
  450. "ATask", // pcName - just a text name for the task to assist debugging.
  451. 100, // usStackDepth - the stack size DEFINED IN WORDS.
  452. NULL, // pvParameters - passed into the task function as the function parameters.
  453. ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
  454. cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
  455. // xRegions - Allocate up to three separate memory regions for access by
  456. // the task, with appropriate access permissions. Different processors have
  457. // different memory alignment requirements - refer to the FreeRTOS documentation
  458. // for full information.
  459. {
  460. // Base address Length Parameters
  461. { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
  462. { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
  463. { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
  464. }
  465. };
  466. int main( void )
  467. {
  468. TaskHandle_t xHandle;
  469. // Create a task from the const structure defined above. The task handle
  470. // is requested (the second parameter is not NULL) but in this case just for
  471. // demonstration purposes as its not actually used.
  472. xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
  473. // Start the scheduler.
  474. vTaskStartScheduler();
  475. // Will only get here if there was insufficient memory to create the idle
  476. // and/or timer task.
  477. for( ;; );
  478. }
  479. </pre>
  480. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  481. * \ingroup Tasks
  482. */
  483. #if( portUSING_MPU_WRAPPERS == 1 )
  484. BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
  485. #endif
  486. /**
  487. * task. h
  488. *<pre>
  489. BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );</pre>
  490. *
  491. * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
  492. *
  493. * xTaskCreateRestrictedStatic() should only be used in systems that include an
  494. * MPU implementation.
  495. *
  496. * Internally, within the FreeRTOS implementation, tasks use two blocks of
  497. * memory. The first block is used to hold the task's data structures. The
  498. * second block is used by the task as its stack. If a task is created using
  499. * xTaskCreateRestricted() then the stack is provided by the application writer,
  500. * and the memory used to hold the task's data structure is automatically
  501. * dynamically allocated inside the xTaskCreateRestricted() function. If a task
  502. * is created using xTaskCreateRestrictedStatic() then the application writer
  503. * must provide the memory used to hold the task's data structures too.
  504. * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
  505. * created without using any dynamic memory allocation.
  506. *
  507. * @param pxTaskDefinition Pointer to a structure that contains a member
  508. * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
  509. * documentation) plus an optional stack buffer and the memory region
  510. * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
  511. * contains an additional member, which is used to point to a variable of type
  512. * StaticTask_t - which is then used to hold the task's data structure.
  513. *
  514. * @param pxCreatedTask Used to pass back a handle by which the created task
  515. * can be referenced.
  516. *
  517. * @return pdPASS if the task was successfully created and added to a ready
  518. * list, otherwise an error code defined in the file projdefs.h
  519. *
  520. * Example usage:
  521. <pre>
  522. // Create an TaskParameters_t structure that defines the task to be created.
  523. // The StaticTask_t variable is only included in the structure when
  524. // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
  525. // be used to force the variable into the RTOS kernel's privileged data area.
  526. static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
  527. static const TaskParameters_t xCheckTaskParameters =
  528. {
  529. vATask, // pvTaskCode - the function that implements the task.
  530. "ATask", // pcName - just a text name for the task to assist debugging.
  531. 100, // usStackDepth - the stack size DEFINED IN WORDS.
  532. NULL, // pvParameters - passed into the task function as the function parameters.
  533. ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
  534. cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
  535. // xRegions - Allocate up to three separate memory regions for access by
  536. // the task, with appropriate access permissions. Different processors have
  537. // different memory alignment requirements - refer to the FreeRTOS documentation
  538. // for full information.
  539. {
  540. // Base address Length Parameters
  541. { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
  542. { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
  543. { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
  544. }
  545. &xTaskBuffer; // Holds the task's data structure.
  546. };
  547. int main( void )
  548. {
  549. TaskHandle_t xHandle;
  550. // Create a task from the const structure defined above. The task handle
  551. // is requested (the second parameter is not NULL) but in this case just for
  552. // demonstration purposes as its not actually used.
  553. xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
  554. // Start the scheduler.
  555. vTaskStartScheduler();
  556. // Will only get here if there was insufficient memory to create the idle
  557. // and/or timer task.
  558. for( ;; );
  559. }
  560. </pre>
  561. * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
  562. * \ingroup Tasks
  563. */
  564. #if( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  565. BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
  566. #endif
  567. /**
  568. * task. h
  569. *<pre>
  570. void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );</pre>
  571. *
  572. * Memory regions are assigned to a restricted task when the task is created by
  573. * a call to xTaskCreateRestricted(). These regions can be redefined using
  574. * vTaskAllocateMPURegions().
  575. *
  576. * @param xTask The handle of the task being updated.
  577. *
  578. * @param xRegions A pointer to an MemoryRegion_t structure that contains the
  579. * new memory region definitions.
  580. *
  581. * Example usage:
  582. <pre>
  583. // Define an array of MemoryRegion_t structures that configures an MPU region
  584. // allowing read/write access for 1024 bytes starting at the beginning of the
  585. // ucOneKByte array. The other two of the maximum 3 definable regions are
  586. // unused so set to zero.
  587. static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
  588. {
  589. // Base address Length Parameters
  590. { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
  591. { 0, 0, 0 },
  592. { 0, 0, 0 }
  593. };
  594. void vATask( void *pvParameters )
  595. {
  596. // This task was created such that it has access to certain regions of
  597. // memory as defined by the MPU configuration. At some point it is
  598. // desired that these MPU regions are replaced with that defined in the
  599. // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
  600. // for this purpose. NULL is used as the task handle to indicate that this
  601. // function should modify the MPU regions of the calling task.
  602. vTaskAllocateMPURegions( NULL, xAltRegions );
  603. // Now the task can continue its function, but from this point on can only
  604. // access its stack and the ucOneKByte array (unless any other statically
  605. // defined or shared regions have been declared elsewhere).
  606. }
  607. </pre>
  608. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  609. * \ingroup Tasks
  610. */
  611. void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
  612. /**
  613. * task. h
  614. * <pre>void vTaskDelete( TaskHandle_t xTask );</pre>
  615. *
  616. * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  617. * See the configuration section for more information.
  618. *
  619. * Remove a task from the RTOS real time kernel's management. The task being
  620. * deleted will be removed from all ready, blocked, suspended and event lists.
  621. *
  622. * NOTE: The idle task is responsible for freeing the kernel allocated
  623. * memory from tasks that have been deleted. It is therefore important that
  624. * the idle task is not starved of microcontroller processing time if your
  625. * application makes any calls to vTaskDelete (). Memory allocated by the
  626. * task code is not automatically freed, and should be freed before the task
  627. * is deleted.
  628. *
  629. * See the demo application file death.c for sample code that utilises
  630. * vTaskDelete ().
  631. *
  632. * @param xTask The handle of the task to be deleted. Passing NULL will
  633. * cause the calling task to be deleted.
  634. *
  635. * Example usage:
  636. <pre>
  637. void vOtherFunction( void )
  638. {
  639. TaskHandle_t xHandle;
  640. // Create the task, storing the handle.
  641. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  642. // Use the handle to delete the task.
  643. vTaskDelete( xHandle );
  644. }
  645. </pre>
  646. * \defgroup vTaskDelete vTaskDelete
  647. * \ingroup Tasks
  648. */
  649. void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
  650. /*-----------------------------------------------------------
  651. * TASK CONTROL API
  652. *----------------------------------------------------------*/
  653. /**
  654. * task. h
  655. * <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
  656. *
  657. * Delay a task for a given number of ticks. The actual time that the
  658. * task remains blocked depends on the tick rate. The constant
  659. * portTICK_PERIOD_MS can be used to calculate real time from the tick
  660. * rate - with the resolution of one tick period.
  661. *
  662. * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  663. * See the configuration section for more information.
  664. *
  665. *
  666. * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  667. * the time at which vTaskDelay() is called. For example, specifying a block
  668. * period of 100 ticks will cause the task to unblock 100 ticks after
  669. * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  670. * of controlling the frequency of a periodic task as the path taken through the
  671. * code, as well as other task and interrupt activity, will effect the frequency
  672. * at which vTaskDelay() gets called and therefore the time at which the task
  673. * next executes. See vTaskDelayUntil() for an alternative API function designed
  674. * to facilitate fixed frequency execution. It does this by specifying an
  675. * absolute time (rather than a relative time) at which the calling task should
  676. * unblock.
  677. *
  678. * @param xTicksToDelay The amount of time, in tick periods, that
  679. * the calling task should block.
  680. *
  681. * Example usage:
  682. void vTaskFunction( void * pvParameters )
  683. {
  684. // Block for 500ms.
  685. const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
  686. for( ;; )
  687. {
  688. // Simply toggle the LED every 500ms, blocking between each toggle.
  689. vToggleLED();
  690. vTaskDelay( xDelay );
  691. }
  692. }
  693. * \defgroup vTaskDelay vTaskDelay
  694. * \ingroup TaskCtrl
  695. */
  696. void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
  697. /**
  698. * task. h
  699. * <pre>void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );</pre>
  700. *
  701. * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
  702. * See the configuration section for more information.
  703. *
  704. * Delay a task until a specified time. This function can be used by periodic
  705. * tasks to ensure a constant execution frequency.
  706. *
  707. * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  708. * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  709. * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  710. * execution frequency as the time between a task starting to execute and that task
  711. * calling vTaskDelay () may not be fixed [the task may take a different path though the
  712. * code between calls, or may get interrupted or preempted a different number of times
  713. * each time it executes].
  714. *
  715. * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  716. * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  717. * unblock.
  718. *
  719. * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
  720. * rate - with the resolution of one tick period.
  721. *
  722. * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  723. * task was last unblocked. The variable must be initialised with the current time
  724. * prior to its first use (see the example below). Following this the variable is
  725. * automatically updated within vTaskDelayUntil ().
  726. *
  727. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  728. * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
  729. * same xTimeIncrement parameter value will cause the task to execute with
  730. * a fixed interface period.
  731. *
  732. * Example usage:
  733. <pre>
  734. // Perform an action every 10 ticks.
  735. void vTaskFunction( void * pvParameters )
  736. {
  737. TickType_t xLastWakeTime;
  738. const TickType_t xFrequency = 10;
  739. // Initialise the xLastWakeTime variable with the current time.
  740. xLastWakeTime = xTaskGetTickCount ();
  741. for( ;; )
  742. {
  743. // Wait for the next cycle.
  744. vTaskDelayUntil( &xLastWakeTime, xFrequency );
  745. // Perform action here.
  746. }
  747. }
  748. </pre>
  749. * \defgroup vTaskDelayUntil vTaskDelayUntil
  750. * \ingroup TaskCtrl
  751. */
  752. void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
  753. /**
  754. * task. h
  755. * <pre>BaseType_t xTaskAbortDelay( TaskHandle_t xTask );</pre>
  756. *
  757. * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  758. * function to be available.
  759. *
  760. * A task will enter the Blocked state when it is waiting for an event. The
  761. * event it is waiting for can be a temporal event (waiting for a time), such
  762. * as when vTaskDelay() is called, or an event on an object, such as when
  763. * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  764. * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  765. * task will leave the Blocked state, and return from whichever function call
  766. * placed the task into the Blocked state.
  767. *
  768. * @param xTask The handle of the task to remove from the Blocked state.
  769. *
  770. * @return If the task referenced by xTask was not in the Blocked state then
  771. * pdFAIL is returned. Otherwise pdPASS is returned.
  772. *
  773. * \defgroup xTaskAbortDelay xTaskAbortDelay
  774. * \ingroup TaskCtrl
  775. */
  776. BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  777. /**
  778. * task. h
  779. * <pre>UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );</pre>
  780. *
  781. * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  782. * See the configuration section for more information.
  783. *
  784. * Obtain the priority of any task.
  785. *
  786. * @param xTask Handle of the task to be queried. Passing a NULL
  787. * handle results in the priority of the calling task being returned.
  788. *
  789. * @return The priority of xTask.
  790. *
  791. * Example usage:
  792. <pre>
  793. void vAFunction( void )
  794. {
  795. TaskHandle_t xHandle;
  796. // Create a task, storing the handle.
  797. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  798. // ...
  799. // Use the handle to obtain the priority of the created task.
  800. // It was created with tskIDLE_PRIORITY, but may have changed
  801. // it itself.
  802. if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  803. {
  804. // The task has changed it's priority.
  805. }
  806. // ...
  807. // Is our priority higher than the created task?
  808. if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  809. {
  810. // Our priority (obtained using NULL handle) is higher.
  811. }
  812. }
  813. </pre>
  814. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  815. * \ingroup TaskCtrl
  816. */
  817. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  818. /**
  819. * task. h
  820. * <pre>UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );</pre>
  821. *
  822. * A version of uxTaskPriorityGet() that can be used from an ISR.
  823. */
  824. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  825. /**
  826. * task. h
  827. * <pre>eTaskState eTaskGetState( TaskHandle_t xTask );</pre>
  828. *
  829. * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  830. * See the configuration section for more information.
  831. *
  832. * Obtain the state of any task. States are encoded by the eTaskState
  833. * enumerated type.
  834. *
  835. * @param xTask Handle of the task to be queried.
  836. *
  837. * @return The state of xTask at the time the function was called. Note the
  838. * state of the task might change between the function being called, and the
  839. * functions return value being tested by the calling task.
  840. */
  841. eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  842. /**
  843. * task. h
  844. * <pre>void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );</pre>
  845. *
  846. * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
  847. * available. See the configuration section for more information.
  848. *
  849. * Populates a TaskStatus_t structure with information about a task.
  850. *
  851. * @param xTask Handle of the task being queried. If xTask is NULL then
  852. * information will be returned about the calling task.
  853. *
  854. * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
  855. * filled with information about the task referenced by the handle passed using
  856. * the xTask parameter.
  857. *
  858. * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
  859. * the stack high water mark of the task being queried. Calculating the stack
  860. * high water mark takes a relatively long time, and can make the system
  861. * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
  862. * allow the high water mark checking to be skipped. The high watermark value
  863. * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
  864. * not set to pdFALSE;
  865. *
  866. * @param eState The TaskStatus_t structure contains a member to report the
  867. * state of the task being queried. Obtaining the task state is not as fast as
  868. * a simple assignment - so the eState parameter is provided to allow the state
  869. * information to be omitted from the TaskStatus_t structure. To obtain state
  870. * information then set eState to eInvalid - otherwise the value passed in
  871. * eState will be reported as the task state in the TaskStatus_t structure.
  872. *
  873. * Example usage:
  874. <pre>
  875. void vAFunction( void )
  876. {
  877. TaskHandle_t xHandle;
  878. TaskStatus_t xTaskDetails;
  879. // Obtain the handle of a task from its name.
  880. xHandle = xTaskGetHandle( "Task_Name" );
  881. // Check the handle is not NULL.
  882. configASSERT( xHandle );
  883. // Use the handle to obtain further information about the task.
  884. vTaskGetInfo( xHandle,
  885. &xTaskDetails,
  886. pdTRUE, // Include the high water mark in xTaskDetails.
  887. eInvalid ); // Include the task state in xTaskDetails.
  888. }
  889. </pre>
  890. * \defgroup vTaskGetInfo vTaskGetInfo
  891. * \ingroup TaskCtrl
  892. */
  893. void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) PRIVILEGED_FUNCTION;
  894. /**
  895. * task. h
  896. * <pre>void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );</pre>
  897. *
  898. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  899. * See the configuration section for more information.
  900. *
  901. * Set the priority of any task.
  902. *
  903. * A context switch will occur before the function returns if the priority
  904. * being set is higher than the currently executing task.
  905. *
  906. * @param xTask Handle to the task for which the priority is being set.
  907. * Passing a NULL handle results in the priority of the calling task being set.
  908. *
  909. * @param uxNewPriority The priority to which the task will be set.
  910. *
  911. * Example usage:
  912. <pre>
  913. void vAFunction( void )
  914. {
  915. TaskHandle_t xHandle;
  916. // Create a task, storing the handle.
  917. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  918. // ...
  919. // Use the handle to raise the priority of the created task.
  920. vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  921. // ...
  922. // Use a NULL handle to raise our priority to the same value.
  923. vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  924. }
  925. </pre>
  926. * \defgroup vTaskPrioritySet vTaskPrioritySet
  927. * \ingroup TaskCtrl
  928. */
  929. void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
  930. /**
  931. * task. h
  932. * <pre>void vTaskSuspend( TaskHandle_t xTaskToSuspend );</pre>
  933. *
  934. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  935. * See the configuration section for more information.
  936. *
  937. * Suspend any task. When suspended a task will never get any microcontroller
  938. * processing time, no matter what its priority.
  939. *
  940. * Calls to vTaskSuspend are not accumulative -
  941. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  942. * call to vTaskResume () to ready the suspended task.
  943. *
  944. * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  945. * handle will cause the calling task to be suspended.
  946. *
  947. * Example usage:
  948. <pre>
  949. void vAFunction( void )
  950. {
  951. TaskHandle_t xHandle;
  952. // Create a task, storing the handle.
  953. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  954. // ...
  955. // Use the handle to suspend the created task.
  956. vTaskSuspend( xHandle );
  957. // ...
  958. // The created task will not run during this period, unless
  959. // another task calls vTaskResume( xHandle ).
  960. //...
  961. // Suspend ourselves.
  962. vTaskSuspend( NULL );
  963. // We cannot get here unless another task calls vTaskResume
  964. // with our handle as the parameter.
  965. }
  966. </pre>
  967. * \defgroup vTaskSuspend vTaskSuspend
  968. * \ingroup TaskCtrl
  969. */
  970. void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
  971. /**
  972. * task. h
  973. * <pre>void vTaskResume( TaskHandle_t xTaskToResume );</pre>
  974. *
  975. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  976. * See the configuration section for more information.
  977. *
  978. * Resumes a suspended task.
  979. *
  980. * A task that has been suspended by one or more calls to vTaskSuspend ()
  981. * will be made available for running again by a single call to
  982. * vTaskResume ().
  983. *
  984. * @param xTaskToResume Handle to the task being readied.
  985. *
  986. * Example usage:
  987. <pre>
  988. void vAFunction( void )
  989. {
  990. TaskHandle_t xHandle;
  991. // Create a task, storing the handle.
  992. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  993. // ...
  994. // Use the handle to suspend the created task.
  995. vTaskSuspend( xHandle );
  996. // ...
  997. // The created task will not run during this period, unless
  998. // another task calls vTaskResume( xHandle ).
  999. //...
  1000. // Resume the suspended task ourselves.
  1001. vTaskResume( xHandle );
  1002. // The created task will once again get microcontroller processing
  1003. // time in accordance with its priority within the system.
  1004. }
  1005. </pre>
  1006. * \defgroup vTaskResume vTaskResume
  1007. * \ingroup TaskCtrl
  1008. */
  1009. void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1010. /**
  1011. * task. h
  1012. * <pre>void xTaskResumeFromISR( TaskHandle_t xTaskToResume );</pre>
  1013. *
  1014. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  1015. * available. See the configuration section for more information.
  1016. *
  1017. * An implementation of vTaskResume() that can be called from within an ISR.
  1018. *
  1019. * A task that has been suspended by one or more calls to vTaskSuspend ()
  1020. * will be made available for running again by a single call to
  1021. * xTaskResumeFromISR ().
  1022. *
  1023. * xTaskResumeFromISR() should not be used to synchronise a task with an
  1024. * interrupt if there is a chance that the interrupt could arrive prior to the
  1025. * task being suspended - as this can lead to interrupts being missed. Use of a
  1026. * semaphore as a synchronisation mechanism would avoid this eventuality.
  1027. *
  1028. * @param xTaskToResume Handle to the task being readied.
  1029. *
  1030. * @return pdTRUE if resuming the task should result in a context switch,
  1031. * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  1032. * may be required following the ISR.
  1033. *
  1034. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  1035. * \ingroup TaskCtrl
  1036. */
  1037. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
  1038. /*-----------------------------------------------------------
  1039. * SCHEDULER CONTROL
  1040. *----------------------------------------------------------*/
  1041. /**
  1042. * task. h
  1043. * <pre>void vTaskStartScheduler( void );</pre>
  1044. *
  1045. * Starts the real time kernel tick processing. After calling the kernel
  1046. * has control over which tasks are executed and when.
  1047. *
  1048. * See the demo application file main.c for an example of creating
  1049. * tasks and starting the kernel.
  1050. *
  1051. * Example usage:
  1052. <pre>
  1053. void vAFunction( void )
  1054. {
  1055. // Create at least one task before starting the kernel.
  1056. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1057. // Start the real time kernel with preemption.
  1058. vTaskStartScheduler ();
  1059. // Will not get here unless a task calls vTaskEndScheduler ()
  1060. }
  1061. </pre>
  1062. *
  1063. * \defgroup vTaskStartScheduler vTaskStartScheduler
  1064. * \ingroup SchedulerControl
  1065. */
  1066. void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
  1067. /**
  1068. * task. h
  1069. * <pre>void vTaskEndScheduler( void );</pre>
  1070. *
  1071. * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
  1072. * in place of DOS, implements this function.
  1073. *
  1074. * Stops the real time kernel tick. All created tasks will be automatically
  1075. * deleted and multitasking (either preemptive or cooperative) will
  1076. * stop. Execution then resumes from the point where vTaskStartScheduler ()
  1077. * was called, as if vTaskStartScheduler () had just returned.
  1078. *
  1079. * See the demo application file main. c in the demo/PC directory for an
  1080. * example that uses vTaskEndScheduler ().
  1081. *
  1082. * vTaskEndScheduler () requires an exit function to be defined within the
  1083. * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  1084. * performs hardware specific operations such as stopping the kernel tick.
  1085. *
  1086. * vTaskEndScheduler () will cause all of the resources allocated by the
  1087. * kernel to be freed - but will not free resources allocated by application
  1088. * tasks.
  1089. *
  1090. * Example usage:
  1091. <pre>
  1092. void vTaskCode( void * pvParameters )
  1093. {
  1094. for( ;; )
  1095. {
  1096. // Task code goes here.
  1097. // At some point we want to end the real time kernel processing
  1098. // so call ...
  1099. vTaskEndScheduler ();
  1100. }
  1101. }
  1102. void vAFunction( void )
  1103. {
  1104. // Create at least one task before starting the kernel.
  1105. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  1106. // Start the real time kernel with preemption.
  1107. vTaskStartScheduler ();
  1108. // Will only get here when the vTaskCode () task has called
  1109. // vTaskEndScheduler (). When we get here we are back to single task
  1110. // execution.
  1111. }
  1112. </pre>
  1113. *
  1114. * \defgroup vTaskEndScheduler vTaskEndScheduler
  1115. * \ingroup SchedulerControl
  1116. */
  1117. void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
  1118. /**
  1119. * task. h
  1120. * <pre>void vTaskSuspendAll( void );</pre>
  1121. *
  1122. * Suspends the scheduler without disabling interrupts. Context switches will
  1123. * not occur while the scheduler is suspended.
  1124. *
  1125. * After calling vTaskSuspendAll () the calling task will continue to execute
  1126. * without risk of being swapped out until a call to xTaskResumeAll () has been
  1127. * made.
  1128. *
  1129. * API functions that have the potential to cause a context switch (for example,
  1130. * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  1131. * is suspended.
  1132. *
  1133. * Example usage:
  1134. <pre>
  1135. void vTask1( void * pvParameters )
  1136. {
  1137. for( ;; )
  1138. {
  1139. // Task code goes here.
  1140. // ...
  1141. // At some point the task wants to perform a long operation during
  1142. // which it does not want to get swapped out. It cannot use
  1143. // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1144. // operation may cause interrupts to be missed - including the
  1145. // ticks.
  1146. // Prevent the real time kernel swapping out the task.
  1147. vTaskSuspendAll ();
  1148. // Perform the operation here. There is no need to use critical
  1149. // sections as we have all the microcontroller processing time.
  1150. // During this time interrupts will still operate and the kernel
  1151. // tick count will be maintained.
  1152. // ...
  1153. // The operation is complete. Restart the kernel.
  1154. xTaskResumeAll ();
  1155. }
  1156. }
  1157. </pre>
  1158. * \defgroup vTaskSuspendAll vTaskSuspendAll
  1159. * \ingroup SchedulerControl
  1160. */
  1161. void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
  1162. /**
  1163. * task. h
  1164. * <pre>BaseType_t xTaskResumeAll( void );</pre>
  1165. *
  1166. * Resumes scheduler activity after it was suspended by a call to
  1167. * vTaskSuspendAll().
  1168. *
  1169. * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  1170. * that were previously suspended by a call to vTaskSuspend().
  1171. *
  1172. * @return If resuming the scheduler caused a context switch then pdTRUE is
  1173. * returned, otherwise pdFALSE is returned.
  1174. *
  1175. * Example usage:
  1176. <pre>
  1177. void vTask1( void * pvParameters )
  1178. {
  1179. for( ;; )
  1180. {
  1181. // Task code goes here.
  1182. // ...
  1183. // At some point the task wants to perform a long operation during
  1184. // which it does not want to get swapped out. It cannot use
  1185. // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  1186. // operation may cause interrupts to be missed - including the
  1187. // ticks.
  1188. // Prevent the real time kernel swapping out the task.
  1189. vTaskSuspendAll ();
  1190. // Perform the operation here. There is no need to use critical
  1191. // sections as we have all the microcontroller processing time.
  1192. // During this time interrupts will still operate and the real
  1193. // time kernel tick count will be maintained.
  1194. // ...
  1195. // The operation is complete. Restart the kernel. We want to force
  1196. // a context switch - but there is no point if resuming the scheduler
  1197. // caused a context switch already.
  1198. if( !xTaskResumeAll () )
  1199. {
  1200. taskYIELD ();
  1201. }
  1202. }
  1203. }
  1204. </pre>
  1205. * \defgroup xTaskResumeAll xTaskResumeAll
  1206. * \ingroup SchedulerControl
  1207. */
  1208. BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
  1209. /*-----------------------------------------------------------
  1210. * TASK UTILITIES
  1211. *----------------------------------------------------------*/
  1212. /**
  1213. * task. h
  1214. * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
  1215. *
  1216. * @return The count of ticks since vTaskStartScheduler was called.
  1217. *
  1218. * \defgroup xTaskGetTickCount xTaskGetTickCount
  1219. * \ingroup TaskUtils
  1220. */
  1221. TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
  1222. /**
  1223. * task. h
  1224. * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
  1225. *
  1226. * @return The count of ticks since vTaskStartScheduler was called.
  1227. *
  1228. * This is a version of xTaskGetTickCount() that is safe to be called from an
  1229. * ISR - provided that TickType_t is the natural word size of the
  1230. * microcontroller being used or interrupt nesting is either not supported or
  1231. * not being used.
  1232. *
  1233. * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  1234. * \ingroup TaskUtils
  1235. */
  1236. TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
  1237. /**
  1238. * task. h
  1239. * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
  1240. *
  1241. * @return The number of tasks that the real time kernel is currently managing.
  1242. * This includes all ready, blocked and suspended tasks. A task that
  1243. * has been deleted but not yet freed by the idle task will also be
  1244. * included in the count.
  1245. *
  1246. * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  1247. * \ingroup TaskUtils
  1248. */
  1249. UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
  1250. /**
  1251. * task. h
  1252. * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
  1253. *
  1254. * @return The text (human readable) name of the task referenced by the handle
  1255. * xTaskToQuery. A task can query its own name by either passing in its own
  1256. * handle, or by setting xTaskToQuery to NULL.
  1257. *
  1258. * \defgroup pcTaskGetName pcTaskGetName
  1259. * \ingroup TaskUtils
  1260. */
  1261. char *pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1262. /**
  1263. * task. h
  1264. * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
  1265. *
  1266. * NOTE: This function takes a relatively long time to complete and should be
  1267. * used sparingly.
  1268. *
  1269. * @return The handle of the task that has the human readable name pcNameToQuery.
  1270. * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  1271. * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  1272. *
  1273. * \defgroup pcTaskGetHandle pcTaskGetHandle
  1274. * \ingroup TaskUtils
  1275. */
  1276. TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1277. /**
  1278. * task.h
  1279. * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
  1280. *
  1281. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1282. * this function to be available.
  1283. *
  1284. * Returns the high water mark of the stack associated with xTask. That is,
  1285. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1286. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1287. * number the closer the task has come to overflowing its stack.
  1288. *
  1289. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1290. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1291. * user to determine the return type. It gets around the problem of the value
  1292. * overflowing on 8-bit types without breaking backward compatibility for
  1293. * applications that expect an 8-bit return type.
  1294. *
  1295. * @param xTask Handle of the task associated with the stack to be checked.
  1296. * Set xTask to NULL to check the stack of the calling task.
  1297. *
  1298. * @return The smallest amount of free stack space there has been (in words, so
  1299. * actual spaces on the stack rather than bytes) since the task referenced by
  1300. * xTask was created.
  1301. */
  1302. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1303. /**
  1304. * task.h
  1305. * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
  1306. *
  1307. * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  1308. * this function to be available.
  1309. *
  1310. * Returns the high water mark of the stack associated with xTask. That is,
  1311. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1312. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1313. * number the closer the task has come to overflowing its stack.
  1314. *
  1315. * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  1316. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  1317. * user to determine the return type. It gets around the problem of the value
  1318. * overflowing on 8-bit types without breaking backward compatibility for
  1319. * applications that expect an 8-bit return type.
  1320. *
  1321. * @param xTask Handle of the task associated with the stack to be checked.
  1322. * Set xTask to NULL to check the stack of the calling task.
  1323. *
  1324. * @return The smallest amount of free stack space there has been (in words, so
  1325. * actual spaces on the stack rather than bytes) since the task referenced by
  1326. * xTask was created.
  1327. */
  1328. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1329. /* When using trace macros it is sometimes necessary to include task.h before
  1330. FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  1331. so the following two prototypes will cause a compilation error. This can be
  1332. fixed by simply guarding against the inclusion of these two prototypes unless
  1333. they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1334. constant. */
  1335. #ifdef configUSE_APPLICATION_TASK_TAG
  1336. #if configUSE_APPLICATION_TASK_TAG == 1
  1337. /**
  1338. * task.h
  1339. * <pre>void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );</pre>
  1340. *
  1341. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1342. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1343. * function.
  1344. */
  1345. void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
  1346. /**
  1347. * task.h
  1348. * <pre>void xTaskGetApplicationTaskTag( TaskHandle_t xTask );</pre>
  1349. *
  1350. * Returns the pxHookFunction value assigned to the task xTask. Do not
  1351. * call from an interrupt service routine - call
  1352. * xTaskGetApplicationTaskTagFromISR() instead.
  1353. */
  1354. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1355. /**
  1356. * task.h
  1357. * <pre>void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );</pre>
  1358. *
  1359. * Returns the pxHookFunction value assigned to the task xTask. Can
  1360. * be called from an interrupt service routine.
  1361. */
  1362. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  1363. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1364. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1365. #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  1366. /* Each task contains an array of pointers that is dimensioned by the
  1367. configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
  1368. kernel does not use the pointers itself, so the application writer can use
  1369. the pointers for any purpose they wish. The following two functions are
  1370. used to set and query a pointer respectively. */
  1371. void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
  1372. void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
  1373. #endif
  1374. /**
  1375. * task.h
  1376. * <pre>BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );</pre>
  1377. *
  1378. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1379. * the effect of calling the Running tasks (the calling task) hook function.
  1380. *
  1381. * pvParameter is passed to the hook function for the task to interpret as it
  1382. * wants. The return value is the value returned by the task hook function
  1383. * registered by the user.
  1384. */
  1385. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
  1386. /**
  1387. * xTaskGetIdleTaskHandle() is only available if
  1388. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1389. *
  1390. * Simply returns the handle of the idle task. It is not valid to call
  1391. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1392. */
  1393. TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
  1394. /**
  1395. * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
  1396. * uxTaskGetSystemState() to be available.
  1397. *
  1398. * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
  1399. * the system. TaskStatus_t structures contain, among other things, members
  1400. * for the task handle, task name, task priority, task state, and total amount
  1401. * of run time consumed by the task. See the TaskStatus_t structure
  1402. * definition in this file for the full member list.
  1403. *
  1404. * NOTE: This function is intended for debugging use only as its use results in
  1405. * the scheduler remaining suspended for an extended period.
  1406. *
  1407. * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
  1408. * The array must contain at least one TaskStatus_t structure for each task
  1409. * that is under the control of the RTOS. The number of tasks under the control
  1410. * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
  1411. *
  1412. * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
  1413. * parameter. The size is specified as the number of indexes in the array, or
  1414. * the number of TaskStatus_t structures contained in the array, not by the
  1415. * number of bytes in the array.
  1416. *
  1417. * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
  1418. * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
  1419. * total run time (as defined by the run time stats clock, see
  1420. * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
  1421. * pulTotalRunTime can be set to NULL to omit the total run time information.
  1422. *
  1423. * @return The number of TaskStatus_t structures that were populated by
  1424. * uxTaskGetSystemState(). This should equal the number returned by the
  1425. * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
  1426. * in the uxArraySize parameter was too small.
  1427. *
  1428. * Example usage:
  1429. <pre>
  1430. // This example demonstrates how a human readable table of run time stats
  1431. // information is generated from raw data provided by uxTaskGetSystemState().
  1432. // The human readable table is written to pcWriteBuffer
  1433. void vTaskGetRunTimeStats( char *pcWriteBuffer )
  1434. {
  1435. TaskStatus_t *pxTaskStatusArray;
  1436. volatile UBaseType_t uxArraySize, x;
  1437. uint32_t ulTotalRunTime, ulStatsAsPercentage;
  1438. // Make sure the write buffer does not contain a string.
  1439. *pcWriteBuffer = 0x00;
  1440. // Take a snapshot of the number of tasks in case it changes while this
  1441. // function is executing.
  1442. uxArraySize = uxTaskGetNumberOfTasks();
  1443. // Allocate a TaskStatus_t structure for each task. An array could be
  1444. // allocated statically at compile time.
  1445. pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  1446. if( pxTaskStatusArray != NULL )
  1447. {
  1448. // Generate raw status information about each task.
  1449. uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
  1450. // For percentage calculations.
  1451. ulTotalRunTime /= 100UL;
  1452. // Avoid divide by zero errors.
  1453. if( ulTotalRunTime > 0 )
  1454. {
  1455. // For each populated position in the pxTaskStatusArray array,
  1456. // format the raw data as human readable ASCII data
  1457. for( x = 0; x < uxArraySize; x++ )
  1458. {
  1459. // What percentage of the total run time has the task used?
  1460. // This will always be rounded down to the nearest integer.
  1461. // ulTotalRunTimeDiv100 has already been divided by 100.
  1462. ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
  1463. if( ulStatsAsPercentage > 0UL )
  1464. {
  1465. sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
  1466. }
  1467. else
  1468. {
  1469. // If the percentage is zero here then the task has
  1470. // consumed less than 1% of the total run time.
  1471. sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
  1472. }
  1473. pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
  1474. }
  1475. }
  1476. // The array is no longer needed, free the memory it consumes.
  1477. vPortFree( pxTaskStatusArray );
  1478. }
  1479. }
  1480. </pre>
  1481. */
  1482. UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
  1483. /**
  1484. * task. h
  1485. * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
  1486. *
  1487. * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
  1488. * both be defined as 1 for this function to be available. See the
  1489. * configuration section of the FreeRTOS.org website for more information.
  1490. *
  1491. * NOTE 1: This function will disable interrupts for its duration. It is
  1492. * not intended for normal application runtime use but as a debug aid.
  1493. *
  1494. * Lists all the current tasks, along with their current state and stack
  1495. * usage high water mark.
  1496. *
  1497. * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
  1498. * suspended ('S').
  1499. *
  1500. * PLEASE NOTE:
  1501. *
  1502. * This function is provided for convenience only, and is used by many of the
  1503. * demo applications. Do not consider it to be part of the scheduler.
  1504. *
  1505. * vTaskList() calls uxTaskGetSystemState(), then formats part of the
  1506. * uxTaskGetSystemState() output into a human readable table that displays task
  1507. * names, states and stack usage.
  1508. *
  1509. * vTaskList() has a dependency on the sprintf() C library function that might
  1510. * bloat the code size, use a lot of stack, and provide different results on
  1511. * different platforms. An alternative, tiny, third party, and limited
  1512. * functionality implementation of sprintf() is provided in many of the
  1513. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1514. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1515. *
  1516. * It is recommended that production systems call uxTaskGetSystemState()
  1517. * directly to get access to raw stats data, rather than indirectly through a
  1518. * call to vTaskList().
  1519. *
  1520. * @param pcWriteBuffer A buffer into which the above mentioned details
  1521. * will be written, in ASCII form. This buffer is assumed to be large
  1522. * enough to contain the generated report. Approximately 40 bytes per
  1523. * task should be sufficient.
  1524. *
  1525. * \defgroup vTaskList vTaskList
  1526. * \ingroup TaskUtils
  1527. */
  1528. void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1529. /**
  1530. * task. h
  1531. * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
  1532. *
  1533. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1534. * must both be defined as 1 for this function to be available. The application
  1535. * must also then provide definitions for
  1536. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1537. * to configure a peripheral timer/counter and return the timers current count
  1538. * value respectively. The counter should be at least 10 times the frequency of
  1539. * the tick count.
  1540. *
  1541. * NOTE 1: This function will disable interrupts for its duration. It is
  1542. * not intended for normal application runtime use but as a debug aid.
  1543. *
  1544. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1545. * accumulated execution time being stored for each task. The resolution
  1546. * of the accumulated time value depends on the frequency of the timer
  1547. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1548. * Calling vTaskGetRunTimeStats() writes the total execution time of each
  1549. * task into a buffer, both as an absolute count value and as a percentage
  1550. * of the total system execution time.
  1551. *
  1552. * NOTE 2:
  1553. *
  1554. * This function is provided for convenience only, and is used by many of the
  1555. * demo applications. Do not consider it to be part of the scheduler.
  1556. *
  1557. * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
  1558. * uxTaskGetSystemState() output into a human readable table that displays the
  1559. * amount of time each task has spent in the Running state in both absolute and
  1560. * percentage terms.
  1561. *
  1562. * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
  1563. * that might bloat the code size, use a lot of stack, and provide different
  1564. * results on different platforms. An alternative, tiny, third party, and
  1565. * limited functionality implementation of sprintf() is provided in many of the
  1566. * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
  1567. * printf-stdarg.c does not provide a full snprintf() implementation!).
  1568. *
  1569. * It is recommended that production systems call uxTaskGetSystemState() directly
  1570. * to get access to raw stats data, rather than indirectly through a call to
  1571. * vTaskGetRunTimeStats().
  1572. *
  1573. * @param pcWriteBuffer A buffer into which the execution times will be
  1574. * written, in ASCII form. This buffer is assumed to be large enough to
  1575. * contain the generated report. Approximately 40 bytes per task should
  1576. * be sufficient.
  1577. *
  1578. * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
  1579. * \ingroup TaskUtils
  1580. */
  1581. void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  1582. /**
  1583. * task. h
  1584. * <PRE>TickType_t xTaskGetIdleRunTimeCounter( void );</PRE>
  1585. *
  1586. * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
  1587. * must both be defined as 1 for this function to be available. The application
  1588. * must also then provide definitions for
  1589. * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
  1590. * to configure a peripheral timer/counter and return the timers current count
  1591. * value respectively. The counter should be at least 10 times the frequency of
  1592. * the tick count.
  1593. *
  1594. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  1595. * accumulated execution time being stored for each task. The resolution
  1596. * of the accumulated time value depends on the frequency of the timer
  1597. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  1598. * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
  1599. * execution time of each task into a buffer, xTaskGetIdleRunTimeCounter()
  1600. * returns the total execution time of just the idle task.
  1601. *
  1602. * @return The total run time of the idle task. This is the amount of time the
  1603. * idle task has actually been executing. The unit of time is dependent on the
  1604. * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
  1605. * portGET_RUN_TIME_COUNTER_VALUE() macros.
  1606. *
  1607. * \defgroup xTaskGetIdleRunTimeCounter xTaskGetIdleRunTimeCounter
  1608. * \ingroup TaskUtils
  1609. */
  1610. TickType_t xTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
  1611. /**
  1612. * task. h
  1613. * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
  1614. *
  1615. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1616. * function to be available.
  1617. *
  1618. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1619. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1620. *
  1621. * Events can be sent to a task using an intermediary object. Examples of such
  1622. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1623. * are a method of sending an event directly to a task without the need for such
  1624. * an intermediary object.
  1625. *
  1626. * A notification sent to a task can optionally perform an action, such as
  1627. * update, overwrite or increment the task's notification value. In that way
  1628. * task notifications can be used to send data to a task, or be used as light
  1629. * weight and fast binary or counting semaphores.
  1630. *
  1631. * A notification sent to a task will remain pending until it is cleared by the
  1632. * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
  1633. * already in the Blocked state to wait for a notification when the notification
  1634. * arrives then the task will automatically be removed from the Blocked state
  1635. * (unblocked) and the notification cleared.
  1636. *
  1637. * A task can use xTaskNotifyWait() to [optionally] block to wait for a
  1638. * notification to be pending, or ulTaskNotifyTake() to [optionally] block
  1639. * to wait for its notification value to have a non-zero value. The task does
  1640. * not consume any CPU time while it is in the Blocked state.
  1641. *
  1642. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1643. *
  1644. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1645. * task can be returned from the xTaskCreate() API function used to create the
  1646. * task, and the handle of the currently running task can be obtained by calling
  1647. * xTaskGetCurrentTaskHandle().
  1648. *
  1649. * @param ulValue Data that can be sent with the notification. How the data is
  1650. * used depends on the value of the eAction parameter.
  1651. *
  1652. * @param eAction Specifies how the notification updates the task's notification
  1653. * value, if at all. Valid values for eAction are as follows:
  1654. *
  1655. * eSetBits -
  1656. * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
  1657. * always returns pdPASS in this case.
  1658. *
  1659. * eIncrement -
  1660. * The task's notification value is incremented. ulValue is not used and
  1661. * xTaskNotify() always returns pdPASS in this case.
  1662. *
  1663. * eSetValueWithOverwrite -
  1664. * The task's notification value is set to the value of ulValue, even if the
  1665. * task being notified had not yet processed the previous notification (the
  1666. * task already had a notification pending). xTaskNotify() always returns
  1667. * pdPASS in this case.
  1668. *
  1669. * eSetValueWithoutOverwrite -
  1670. * If the task being notified did not already have a notification pending then
  1671. * the task's notification value is set to ulValue and xTaskNotify() will
  1672. * return pdPASS. If the task being notified already had a notification
  1673. * pending then no action is performed and pdFAIL is returned.
  1674. *
  1675. * eNoAction -
  1676. * The task receives a notification without its notification value being
  1677. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  1678. * this case.
  1679. *
  1680. * pulPreviousNotificationValue -
  1681. * Can be used to pass out the subject task's notification value before any
  1682. * bits are modified by the notify function.
  1683. *
  1684. * @return Dependent on the value of eAction. See the description of the
  1685. * eAction parameter.
  1686. *
  1687. * \defgroup xTaskNotify xTaskNotify
  1688. * \ingroup TaskNotifications
  1689. */
  1690. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
  1691. #define xTaskNotify( xTaskToNotify, ulValue, eAction ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )
  1692. #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) xTaskGenericNotify( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  1693. /**
  1694. * task. h
  1695. * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
  1696. *
  1697. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1698. * function to be available.
  1699. *
  1700. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1701. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1702. *
  1703. * A version of xTaskNotify() that can be used from an interrupt service routine
  1704. * (ISR).
  1705. *
  1706. * Events can be sent to a task using an intermediary object. Examples of such
  1707. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1708. * are a method of sending an event directly to a task without the need for such
  1709. * an intermediary object.
  1710. *
  1711. * A notification sent to a task can optionally perform an action, such as
  1712. * update, overwrite or increment the task's notification value. In that way
  1713. * task notifications can be used to send data to a task, or be used as light
  1714. * weight and fast binary or counting semaphores.
  1715. *
  1716. * A notification sent to a task will remain pending until it is cleared by the
  1717. * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
  1718. * already in the Blocked state to wait for a notification when the notification
  1719. * arrives then the task will automatically be removed from the Blocked state
  1720. * (unblocked) and the notification cleared.
  1721. *
  1722. * A task can use xTaskNotifyWait() to [optionally] block to wait for a
  1723. * notification to be pending, or ulTaskNotifyTake() to [optionally] block
  1724. * to wait for its notification value to have a non-zero value. The task does
  1725. * not consume any CPU time while it is in the Blocked state.
  1726. *
  1727. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1728. *
  1729. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1730. * task can be returned from the xTaskCreate() API function used to create the
  1731. * task, and the handle of the currently running task can be obtained by calling
  1732. * xTaskGetCurrentTaskHandle().
  1733. *
  1734. * @param ulValue Data that can be sent with the notification. How the data is
  1735. * used depends on the value of the eAction parameter.
  1736. *
  1737. * @param eAction Specifies how the notification updates the task's notification
  1738. * value, if at all. Valid values for eAction are as follows:
  1739. *
  1740. * eSetBits -
  1741. * The task's notification value is bitwise ORed with ulValue. xTaskNofify()
  1742. * always returns pdPASS in this case.
  1743. *
  1744. * eIncrement -
  1745. * The task's notification value is incremented. ulValue is not used and
  1746. * xTaskNotify() always returns pdPASS in this case.
  1747. *
  1748. * eSetValueWithOverwrite -
  1749. * The task's notification value is set to the value of ulValue, even if the
  1750. * task being notified had not yet processed the previous notification (the
  1751. * task already had a notification pending). xTaskNotify() always returns
  1752. * pdPASS in this case.
  1753. *
  1754. * eSetValueWithoutOverwrite -
  1755. * If the task being notified did not already have a notification pending then
  1756. * the task's notification value is set to ulValue and xTaskNotify() will
  1757. * return pdPASS. If the task being notified already had a notification
  1758. * pending then no action is performed and pdFAIL is returned.
  1759. *
  1760. * eNoAction -
  1761. * The task receives a notification without its notification value being
  1762. * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  1763. * this case.
  1764. *
  1765. * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  1766. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  1767. * task to which the notification was sent to leave the Blocked state, and the
  1768. * unblocked task has a priority higher than the currently running task. If
  1769. * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  1770. * be requested before the interrupt is exited. How a context switch is
  1771. * requested from an ISR is dependent on the port - see the documentation page
  1772. * for the port in use.
  1773. *
  1774. * @return Dependent on the value of eAction. See the description of the
  1775. * eAction parameter.
  1776. *
  1777. * \defgroup xTaskNotify xTaskNotify
  1778. * \ingroup TaskNotifications
  1779. */
  1780. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1781. #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  1782. #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  1783. /**
  1784. * task. h
  1785. * <PRE>BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );</pre>
  1786. *
  1787. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1788. * function to be available.
  1789. *
  1790. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1791. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1792. *
  1793. * Events can be sent to a task using an intermediary object. Examples of such
  1794. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1795. * are a method of sending an event directly to a task without the need for such
  1796. * an intermediary object.
  1797. *
  1798. * A notification sent to a task can optionally perform an action, such as
  1799. * update, overwrite or increment the task's notification value. In that way
  1800. * task notifications can be used to send data to a task, or be used as light
  1801. * weight and fast binary or counting semaphores.
  1802. *
  1803. * A notification sent to a task will remain pending until it is cleared by the
  1804. * task calling xTaskNotifyWait() or ulTaskNotifyTake(). If the task was
  1805. * already in the Blocked state to wait for a notification when the notification
  1806. * arrives then the task will automatically be removed from the Blocked state
  1807. * (unblocked) and the notification cleared.
  1808. *
  1809. * A task can use xTaskNotifyWait() to [optionally] block to wait for a
  1810. * notification to be pending, or ulTaskNotifyTake() to [optionally] block
  1811. * to wait for its notification value to have a non-zero value. The task does
  1812. * not consume any CPU time while it is in the Blocked state.
  1813. *
  1814. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  1815. *
  1816. * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  1817. * will be cleared in the calling task's notification value before the task
  1818. * checks to see if any notifications are pending, and optionally blocks if no
  1819. * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  1820. * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  1821. * the effect of resetting the task's notification value to 0. Setting
  1822. * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  1823. *
  1824. * @param ulBitsToClearOnExit If a notification is pending or received before
  1825. * the calling task exits the xTaskNotifyWait() function then the task's
  1826. * notification value (see the xTaskNotify() API function) is passed out using
  1827. * the pulNotificationValue parameter. Then any bits that are set in
  1828. * ulBitsToClearOnExit will be cleared in the task's notification value (note
  1829. * *pulNotificationValue is set before any bits are cleared). Setting
  1830. * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  1831. * (if limits.h is not included) will have the effect of resetting the task's
  1832. * notification value to 0 before the function exits. Setting
  1833. * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  1834. * when the function exits (in which case the value passed out in
  1835. * pulNotificationValue will match the task's notification value).
  1836. *
  1837. * @param pulNotificationValue Used to pass the task's notification value out
  1838. * of the function. Note the value passed out will not be effected by the
  1839. * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  1840. *
  1841. * @param xTicksToWait The maximum amount of time that the task should wait in
  1842. * the Blocked state for a notification to be received, should a notification
  1843. * not already be pending when xTaskNotifyWait() was called. The task
  1844. * will not consume any processing time while it is in the Blocked state. This
  1845. * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
  1846. * used to convert a time specified in milliseconds to a time specified in
  1847. * ticks.
  1848. *
  1849. * @return If a notification was received (including notifications that were
  1850. * already pending when xTaskNotifyWait was called) then pdPASS is
  1851. * returned. Otherwise pdFAIL is returned.
  1852. *
  1853. * \defgroup xTaskNotifyWait xTaskNotifyWait
  1854. * \ingroup TaskNotifications
  1855. */
  1856. BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  1857. /**
  1858. * task. h
  1859. * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
  1860. *
  1861. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  1862. * to be available.
  1863. *
  1864. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1865. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1866. *
  1867. * Events can be sent to a task using an intermediary object. Examples of such
  1868. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1869. * are a method of sending an event directly to a task without the need for such
  1870. * an intermediary object.
  1871. *
  1872. * A notification sent to a task can optionally perform an action, such as
  1873. * update, overwrite or increment the task's notification value. In that way
  1874. * task notifications can be used to send data to a task, or be used as light
  1875. * weight and fast binary or counting semaphores.
  1876. *
  1877. * xTaskNotifyGive() is a helper macro intended for use when task notifications
  1878. * are used as light weight and faster binary or counting semaphore equivalents.
  1879. * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
  1880. * the equivalent action that instead uses a task notification is
  1881. * xTaskNotifyGive().
  1882. *
  1883. * When task notifications are being used as a binary or counting semaphore
  1884. * equivalent then the task being notified should wait for the notification
  1885. * using the ulTaskNotificationTake() API function rather than the
  1886. * xTaskNotifyWait() API function.
  1887. *
  1888. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  1889. *
  1890. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1891. * task can be returned from the xTaskCreate() API function used to create the
  1892. * task, and the handle of the currently running task can be obtained by calling
  1893. * xTaskGetCurrentTaskHandle().
  1894. *
  1895. * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  1896. * eAction parameter set to eIncrement - so pdPASS is always returned.
  1897. *
  1898. * \defgroup xTaskNotifyGive xTaskNotifyGive
  1899. * \ingroup TaskNotifications
  1900. */
  1901. #define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
  1902. /**
  1903. * task. h
  1904. * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
  1905. *
  1906. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  1907. * to be available.
  1908. *
  1909. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1910. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1911. *
  1912. * A version of xTaskNotifyGive() that can be called from an interrupt service
  1913. * routine (ISR).
  1914. *
  1915. * Events can be sent to a task using an intermediary object. Examples of such
  1916. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1917. * are a method of sending an event directly to a task without the need for such
  1918. * an intermediary object.
  1919. *
  1920. * A notification sent to a task can optionally perform an action, such as
  1921. * update, overwrite or increment the task's notification value. In that way
  1922. * task notifications can be used to send data to a task, or be used as light
  1923. * weight and fast binary or counting semaphores.
  1924. *
  1925. * vTaskNotifyGiveFromISR() is intended for use when task notifications are
  1926. * used as light weight and faster binary or counting semaphore equivalents.
  1927. * Actual FreeRTOS semaphores are given from an ISR using the
  1928. * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  1929. * a task notification is vTaskNotifyGiveFromISR().
  1930. *
  1931. * When task notifications are being used as a binary or counting semaphore
  1932. * equivalent then the task being notified should wait for the notification
  1933. * using the ulTaskNotificationTake() API function rather than the
  1934. * xTaskNotifyWait() API function.
  1935. *
  1936. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  1937. *
  1938. * @param xTaskToNotify The handle of the task being notified. The handle to a
  1939. * task can be returned from the xTaskCreate() API function used to create the
  1940. * task, and the handle of the currently running task can be obtained by calling
  1941. * xTaskGetCurrentTaskHandle().
  1942. *
  1943. * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  1944. * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  1945. * task to which the notification was sent to leave the Blocked state, and the
  1946. * unblocked task has a priority higher than the currently running task. If
  1947. * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  1948. * should be requested before the interrupt is exited. How a context switch is
  1949. * requested from an ISR is dependent on the port - see the documentation page
  1950. * for the port in use.
  1951. *
  1952. * \defgroup xTaskNotifyWait xTaskNotifyWait
  1953. * \ingroup TaskNotifications
  1954. */
  1955. void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
  1956. /**
  1957. * task. h
  1958. * <PRE>uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );</pre>
  1959. *
  1960. * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  1961. * function to be available.
  1962. *
  1963. * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
  1964. * "notification value", which is a 32-bit unsigned integer (uint32_t).
  1965. *
  1966. * Events can be sent to a task using an intermediary object. Examples of such
  1967. * objects are queues, semaphores, mutexes and event groups. Task notifications
  1968. * are a method of sending an event directly to a task without the need for such
  1969. * an intermediary object.
  1970. *
  1971. * A notification sent to a task can optionally perform an action, such as
  1972. * update, overwrite or increment the task's notification value. In that way
  1973. * task notifications can be used to send data to a task, or be used as light
  1974. * weight and fast binary or counting semaphores.
  1975. *
  1976. * ulTaskNotifyTake() is intended for use when a task notification is used as a
  1977. * faster and lighter weight binary or counting semaphore alternative. Actual
  1978. * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
  1979. * equivalent action that instead uses a task notification is
  1980. * ulTaskNotifyTake().
  1981. *
  1982. * When a task is using its notification value as a binary or counting semaphore
  1983. * other tasks should send notifications to it using the xTaskNotifyGive()
  1984. * macro, or xTaskNotify() function with the eAction parameter set to
  1985. * eIncrement.
  1986. *
  1987. * ulTaskNotifyTake() can either clear the task's notification value to
  1988. * zero on exit, in which case the notification value acts like a binary
  1989. * semaphore, or decrement the task's notification value on exit, in which case
  1990. * the notification value acts like a counting semaphore.
  1991. *
  1992. * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
  1993. * the task's notification value to be non-zero. The task does not consume any
  1994. * CPU time while it is in the Blocked state.
  1995. *
  1996. * Where as xTaskNotifyWait() will return when a notification is pending,
  1997. * ulTaskNotifyTake() will return when the task's notification value is
  1998. * not zero.
  1999. *
  2000. * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  2001. *
  2002. * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  2003. * notification value is decremented when the function exits. In this way the
  2004. * notification value acts like a counting semaphore. If xClearCountOnExit is
  2005. * not pdFALSE then the task's notification value is cleared to zero when the
  2006. * function exits. In this way the notification value acts like a binary
  2007. * semaphore.
  2008. *
  2009. * @param xTicksToWait The maximum amount of time that the task should wait in
  2010. * the Blocked state for the task's notification value to be greater than zero,
  2011. * should the count not already be greater than zero when
  2012. * ulTaskNotifyTake() was called. The task will not consume any processing
  2013. * time while it is in the Blocked state. This is specified in kernel ticks,
  2014. * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
  2015. * specified in milliseconds to a time specified in ticks.
  2016. *
  2017. * @return The task's notification count before it is either cleared to zero or
  2018. * decremented (see the xClearCountOnExit parameter).
  2019. *
  2020. * \defgroup ulTaskNotifyTake ulTaskNotifyTake
  2021. * \ingroup TaskNotifications
  2022. */
  2023. uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2024. /**
  2025. * task. h
  2026. * <PRE>BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );</pre>
  2027. *
  2028. * If the notification state of the task referenced by the handle xTask is
  2029. * eNotified, then set the task's notification state to eNotWaitingNotification.
  2030. * The task's notification value is not altered. Set xTask to NULL to clear the
  2031. * notification state of the calling task.
  2032. *
  2033. * @return pdTRUE if the task's notification state was set to
  2034. * eNotWaitingNotification, otherwise pdFALSE.
  2035. * \defgroup xTaskNotifyStateClear xTaskNotifyStateClear
  2036. * \ingroup TaskNotifications
  2037. */
  2038. BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  2039. /*-----------------------------------------------------------
  2040. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  2041. *----------------------------------------------------------*/
  2042. /*
  2043. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2044. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2045. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2046. *
  2047. * Called from the real time kernel tick (either preemptive or cooperative),
  2048. * this increments the tick count and checks if any tasks that are blocked
  2049. * for a finite period required removing from a blocked list and placing on
  2050. * a ready list. If a non-zero value is returned then a context switch is
  2051. * required because either:
  2052. * + A task was removed from a blocked list because its timeout had expired,
  2053. * or
  2054. * + Time slicing is in use and there is a task of equal priority to the
  2055. * currently running task.
  2056. */
  2057. BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
  2058. /*
  2059. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2060. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2061. *
  2062. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2063. *
  2064. * Removes the calling task from the ready list and places it both
  2065. * on the list of tasks waiting for a particular event, and the
  2066. * list of delayed tasks. The task will be removed from both lists
  2067. * and replaced on the ready list should either the event occur (and
  2068. * there be no higher priority tasks waiting on the same event) or
  2069. * the delay period expires.
  2070. *
  2071. * The 'unordered' version replaces the event list item value with the
  2072. * xItemValue value, and inserts the list item at the end of the list.
  2073. *
  2074. * The 'ordered' version uses the existing event list item value (which is the
  2075. * owning tasks priority) to insert the list item into the event list is task
  2076. * priority order.
  2077. *
  2078. * @param pxEventList The list containing tasks that are blocked waiting
  2079. * for the event to occur.
  2080. *
  2081. * @param xItemValue The item value to use for the event list item when the
  2082. * event list is not ordered by task priority.
  2083. *
  2084. * @param xTicksToWait The maximum amount of time that the task should wait
  2085. * for the event to occur. This is specified in kernel ticks,the constant
  2086. * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
  2087. * period.
  2088. */
  2089. void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2090. void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
  2091. /*
  2092. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2093. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2094. *
  2095. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2096. *
  2097. * This function performs nearly the same function as vTaskPlaceOnEventList().
  2098. * The difference being that this function does not permit tasks to block
  2099. * indefinitely, whereas vTaskPlaceOnEventList() does.
  2100. *
  2101. */
  2102. void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
  2103. /*
  2104. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  2105. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2106. *
  2107. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  2108. *
  2109. * Removes a task from both the specified event list and the list of blocked
  2110. * tasks, and places it on a ready queue.
  2111. *
  2112. * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
  2113. * if either an event occurs to unblock a task, or the block timeout period
  2114. * expires.
  2115. *
  2116. * xTaskRemoveFromEventList() is used when the event list is in task priority
  2117. * order. It removes the list item from the head of the event list as that will
  2118. * have the highest priority owning task of all the tasks on the event list.
  2119. * vTaskRemoveFromUnorderedEventList() is used when the event list is not
  2120. * ordered and the event list items hold something other than the owning tasks
  2121. * priority. In this case the event list item value is updated to the value
  2122. * passed in the xItemValue parameter.
  2123. *
  2124. * @return pdTRUE if the task being removed has a higher priority than the task
  2125. * making the call, otherwise pdFALSE.
  2126. */
  2127. BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
  2128. void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
  2129. /*
  2130. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  2131. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  2132. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  2133. *
  2134. * Sets the pointer to the current TCB to the TCB of the highest priority task
  2135. * that is ready to run.
  2136. */
  2137. portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
  2138. /*
  2139. * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
  2140. * THE EVENT BITS MODULE.
  2141. */
  2142. TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
  2143. /*
  2144. * Return the handle of the calling task.
  2145. */
  2146. TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
  2147. /*
  2148. * Capture the current time status for future reference.
  2149. */
  2150. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2151. /*
  2152. * Compare the time status now with that previously captured to see if the
  2153. * timeout has expired.
  2154. */
  2155. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
  2156. /*
  2157. * Shortcut used by the queue implementation to prevent unnecessary call to
  2158. * taskYIELD();
  2159. */
  2160. void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
  2161. /*
  2162. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  2163. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  2164. */
  2165. BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  2166. /*
  2167. * Raises the priority of the mutex holder to that of the calling task should
  2168. * the mutex holder have a priority less than the calling task.
  2169. */
  2170. BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2171. /*
  2172. * Set the priority of a task back to its proper priority in the case that it
  2173. * inherited a higher priority while it was holding a semaphore.
  2174. */
  2175. BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
  2176. /*
  2177. * If a higher priority task attempting to obtain a mutex caused a lower
  2178. * priority task to inherit the higher priority task's priority - but the higher
  2179. * priority task then timed out without obtaining the mutex, then the lower
  2180. * priority task will disinherit the priority again - but only down as far as
  2181. * the highest priority task that is still waiting for the mutex (if there were
  2182. * more than one task waiting for the mutex).
  2183. */
  2184. void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
  2185. /*
  2186. * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
  2187. */
  2188. UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
  2189. /*
  2190. * Set the uxTaskNumber of the task referenced by the xTask parameter to
  2191. * uxHandle.
  2192. */
  2193. void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
  2194. /*
  2195. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2196. * If tickless mode is being used, or a low power mode is implemented, then
  2197. * the tick interrupt will not execute during idle periods. When this is the
  2198. * case, the tick count value maintained by the scheduler needs to be kept up
  2199. * to date with the actual execution time by being skipped forward by a time
  2200. * equal to the idle period.
  2201. */
  2202. void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
  2203. /*
  2204. * Only available when configUSE_TICKLESS_IDLE is set to 1.
  2205. * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
  2206. * specific sleep function to determine if it is ok to proceed with the sleep,
  2207. * and if it is ok to proceed, if it is ok to sleep indefinitely.
  2208. *
  2209. * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
  2210. * called with the scheduler suspended, not from within a critical section. It
  2211. * is therefore possible for an interrupt to request a context switch between
  2212. * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
  2213. * entered. eTaskConfirmSleepModeStatus() should be called from a short
  2214. * critical section between the timer being stopped and the sleep mode being
  2215. * entered to ensure it is ok to proceed into the sleep mode.
  2216. */
  2217. eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
  2218. /*
  2219. * For internal use only. Increment the mutex held count when a mutex is
  2220. * taken and return the handle of the task that has taken the mutex.
  2221. */
  2222. TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
  2223. /*
  2224. * For internal use only. Same as vTaskSetTimeOutState(), but without a critial
  2225. * section.
  2226. */
  2227. void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
  2228. #ifdef __cplusplus
  2229. }
  2230. #endif
  2231. #endif /* INC_TASK_H */