task.h 93 KB

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