task.h 86 KB

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