task.h 94 KB

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