task.h 91 KB

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