task.h 91 KB

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