task.h 79 KB

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