task.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /*
  2. FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
  3. ***************************************************************************
  4. * *
  5. * FreeRTOS tutorial books are available in pdf and paperback. *
  6. * Complete, revised, and edited pdf reference manuals are also *
  7. * available. *
  8. * *
  9. * Purchasing FreeRTOS documentation will not only help you, by *
  10. * ensuring you get running as quickly as possible and with an *
  11. * in-depth knowledge of how to use FreeRTOS, it will also help *
  12. * the FreeRTOS project to continue with its mission of providing *
  13. * professional grade, cross platform, de facto standard solutions *
  14. * for microcontrollers - completely free of charge! *
  15. * *
  16. * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
  17. * *
  18. * Thank you for using FreeRTOS, and thank you for your support! *
  19. * *
  20. ***************************************************************************
  21. This file is part of the FreeRTOS distribution.
  22. FreeRTOS is free software; you can redistribute it and/or modify it under
  23. the terms of the GNU General Public License (version 2) as published by the
  24. Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
  25. >>>NOTE<<< The modification to the GPL is included to allow you to
  26. distribute a combined work that includes FreeRTOS without being obliged to
  27. provide the source code for proprietary components outside of the FreeRTOS
  28. kernel. FreeRTOS is distributed in the hope that it will be useful, but
  29. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  30. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  31. more details. You should have received a copy of the GNU General Public
  32. License and the FreeRTOS license exception along with FreeRTOS; if not it
  33. can be viewed here: http://www.freertos.org/a00114.html and also obtained
  34. by writing to Richard Barry, contact details for whom are available on the
  35. FreeRTOS WEB site.
  36. 1 tab == 4 spaces!
  37. ***************************************************************************
  38. * *
  39. * Having a problem? Start by reading the FAQ "My application does *
  40. * not run, what could be wrong? *
  41. * *
  42. * http://www.FreeRTOS.org/FAQHelp.html *
  43. * *
  44. ***************************************************************************
  45. http://www.FreeRTOS.org - Documentation, training, latest information,
  46. license and contact details.
  47. http://www.FreeRTOS.org/plus - Selection of FreeRTOS ecosystem products,
  48. including FreeRTOS+Trace - an indispensable productivity tool.
  49. Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
  50. the code with commercial support, indemnification, and middleware, under
  51. the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
  52. provide a safety engineered and independently SIL3 certified version under
  53. the SafeRTOS brand: http://www.SafeRTOS.com.
  54. */
  55. #ifndef TASK_H
  56. #define 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 "FreeRTOS.h"
  61. #include "portable.h"
  62. #include "list.h"
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66. /*-----------------------------------------------------------
  67. * MACROS AND DEFINITIONS
  68. *----------------------------------------------------------*/
  69. #define tskKERNEL_VERSION_NUMBER "V7.3.0"
  70. /**
  71. * task. h
  72. *
  73. * Type by which tasks are referenced. For example, a call to xTaskCreate
  74. * returns (via a pointer parameter) an xTaskHandle variable that can then
  75. * be used as a parameter to vTaskDelete to delete the task.
  76. *
  77. * \page xTaskHandle xTaskHandle
  78. * \ingroup Tasks
  79. */
  80. typedef void * xTaskHandle;
  81. /*
  82. * Used internally only.
  83. */
  84. typedef struct xTIME_OUT
  85. {
  86. portBASE_TYPE xOverflowCount;
  87. portTickType xTimeOnEntering;
  88. } xTimeOutType;
  89. /*
  90. * Defines the memory ranges allocated to the task when an MPU is used.
  91. */
  92. typedef struct xMEMORY_REGION
  93. {
  94. void *pvBaseAddress;
  95. unsigned long ulLengthInBytes;
  96. unsigned long ulParameters;
  97. } xMemoryRegion;
  98. /*
  99. * Parameters required to create an MPU protected task.
  100. */
  101. typedef struct xTASK_PARAMTERS
  102. {
  103. pdTASK_CODE pvTaskCode;
  104. const signed char * const pcName;
  105. unsigned short usStackDepth;
  106. void *pvParameters;
  107. unsigned portBASE_TYPE uxPriority;
  108. portSTACK_TYPE *puxStackBuffer;
  109. xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
  110. } xTaskParameters;
  111. /* Task states returned by eTaskStateGet. */
  112. typedef enum
  113. {
  114. eRunning = 0, /* A task is querying the state of itself, so must be running. */
  115. eReady, /* The task being queried is in a read or pending ready list. */
  116. eBlocked, /* The task being queried is in the Blocked state. */
  117. eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  118. eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */
  119. } eTaskState;
  120. /*
  121. * Defines the priority used by the idle task. This must not be modified.
  122. *
  123. * \ingroup TaskUtils
  124. */
  125. #define tskIDLE_PRIORITY ( ( unsigned portBASE_TYPE ) 0U )
  126. /**
  127. * task. h
  128. *
  129. * Macro for forcing a context switch.
  130. *
  131. * \page taskYIELD taskYIELD
  132. * \ingroup SchedulerControl
  133. */
  134. #define taskYIELD() portYIELD()
  135. /**
  136. * task. h
  137. *
  138. * Macro to mark the start of a critical code region. Preemptive context
  139. * switches cannot occur when in a critical region.
  140. *
  141. * NOTE: This may alter the stack (depending on the portable implementation)
  142. * so must be used with care!
  143. *
  144. * \page taskENTER_CRITICAL taskENTER_CRITICAL
  145. * \ingroup SchedulerControl
  146. */
  147. #define taskENTER_CRITICAL() portENTER_CRITICAL()
  148. /**
  149. * task. h
  150. *
  151. * Macro to mark the end of a critical code region. Preemptive context
  152. * switches cannot occur when in a critical region.
  153. *
  154. * NOTE: This may alter the stack (depending on the portable implementation)
  155. * so must be used with care!
  156. *
  157. * \page taskEXIT_CRITICAL taskEXIT_CRITICAL
  158. * \ingroup SchedulerControl
  159. */
  160. #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  161. /**
  162. * task. h
  163. *
  164. * Macro to disable all maskable interrupts.
  165. *
  166. * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  167. * \ingroup SchedulerControl
  168. */
  169. #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  170. /**
  171. * task. h
  172. *
  173. * Macro to enable microcontroller interrupts.
  174. *
  175. * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  176. * \ingroup SchedulerControl
  177. */
  178. #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  179. /* Definitions returned by xTaskGetSchedulerState(). */
  180. #define taskSCHEDULER_NOT_STARTED 0
  181. #define taskSCHEDULER_RUNNING 1
  182. #define taskSCHEDULER_SUSPENDED 2
  183. /*-----------------------------------------------------------
  184. * TASK CREATION API
  185. *----------------------------------------------------------*/
  186. /**
  187. * task. h
  188. *<pre>
  189. portBASE_TYPE xTaskCreate(
  190. pdTASK_CODE pvTaskCode,
  191. const char * const pcName,
  192. unsigned short usStackDepth,
  193. void *pvParameters,
  194. unsigned portBASE_TYPE uxPriority,
  195. xTaskHandle *pvCreatedTask
  196. );</pre>
  197. *
  198. * Create a new task and add it to the list of tasks that are ready to run.
  199. *
  200. * xTaskCreate() can only be used to create a task that has unrestricted
  201. * access to the entire microcontroller memory map. Systems that include MPU
  202. * support can alternatively create an MPU constrained task using
  203. * xTaskCreateRestricted().
  204. *
  205. * @param pvTaskCode Pointer to the task entry function. Tasks
  206. * must be implemented to never return (i.e. continuous loop).
  207. *
  208. * @param pcName A descriptive name for the task. This is mainly used to
  209. * facilitate debugging. Max length defined by tskMAX_TASK_NAME_LEN - default
  210. * is 16.
  211. *
  212. * @param usStackDepth The size of the task stack specified as the number of
  213. * variables the stack can hold - not the number of bytes. For example, if
  214. * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  215. * will be allocated for stack storage.
  216. *
  217. * @param pvParameters Pointer that will be used as the parameter for the task
  218. * being created.
  219. *
  220. * @param uxPriority The priority at which the task should run. Systems that
  221. * include MPU support can optionally create tasks in a privileged (system)
  222. * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  223. * example, to create a privileged task at priority 2 the uxPriority parameter
  224. * should be set to ( 2 | portPRIVILEGE_BIT ).
  225. *
  226. * @param pvCreatedTask Used to pass back a handle by which the created task
  227. * can be referenced.
  228. *
  229. * @return pdPASS if the task was successfully created and added to a ready
  230. * list, otherwise an error code defined in the file errors. h
  231. *
  232. * Example usage:
  233. <pre>
  234. // Task to be created.
  235. void vTaskCode( void * pvParameters )
  236. {
  237. for( ;; )
  238. {
  239. // Task code goes here.
  240. }
  241. }
  242. // Function that creates a task.
  243. void vOtherFunction( void )
  244. {
  245. static unsigned char ucParameterToPass;
  246. xTaskHandle xHandle;
  247. // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  248. // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  249. // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  250. // the new task attempts to access it.
  251. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  252. // Use the handle to delete the task.
  253. vTaskDelete( xHandle );
  254. }
  255. </pre>
  256. * \defgroup xTaskCreate xTaskCreate
  257. * \ingroup Tasks
  258. */
  259. #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )
  260. /**
  261. * task. h
  262. *<pre>
  263. portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle *pxCreatedTask );</pre>
  264. *
  265. * xTaskCreateRestricted() should only be used in systems that include an MPU
  266. * implementation.
  267. *
  268. * Create a new task and add it to the list of tasks that are ready to run.
  269. * The function parameters define the memory regions and associated access
  270. * permissions allocated to the task.
  271. *
  272. * @param pxTaskDefinition Pointer to a structure that contains a member
  273. * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
  274. * documentation) plus an optional stack buffer and the memory region
  275. * definitions.
  276. *
  277. * @param pxCreatedTask Used to pass back a handle by which the created task
  278. * can be referenced.
  279. *
  280. * @return pdPASS if the task was successfully created and added to a ready
  281. * list, otherwise an error code defined in the file errors. h
  282. *
  283. * Example usage:
  284. <pre>
  285. // Create an xTaskParameters structure that defines the task to be created.
  286. static const xTaskParameters xCheckTaskParameters =
  287. {
  288. vATask, // pvTaskCode - the function that implements the task.
  289. "ATask", // pcName - just a text name for the task to assist debugging.
  290. 100, // usStackDepth - the stack size DEFINED IN WORDS.
  291. NULL, // pvParameters - passed into the task function as the function parameters.
  292. ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
  293. cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
  294. // xRegions - Allocate up to three separate memory regions for access by
  295. // the task, with appropriate access permissions. Different processors have
  296. // different memory alignment requirements - refer to the FreeRTOS documentation
  297. // for full information.
  298. {
  299. // Base address Length Parameters
  300. { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
  301. { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
  302. { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
  303. }
  304. };
  305. int main( void )
  306. {
  307. xTaskHandle xHandle;
  308. // Create a task from the const structure defined above. The task handle
  309. // is requested (the second parameter is not NULL) but in this case just for
  310. // demonstration purposes as its not actually used.
  311. xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
  312. // Start the scheduler.
  313. vTaskStartScheduler();
  314. // Will only get here if there was insufficient memory to create the idle
  315. // task.
  316. for( ;; );
  317. }
  318. </pre>
  319. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  320. * \ingroup Tasks
  321. */
  322. #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )
  323. /**
  324. * task. h
  325. *<pre>
  326. void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre>
  327. *
  328. * Memory regions are assigned to a restricted task when the task is created by
  329. * a call to xTaskCreateRestricted(). These regions can be redefined using
  330. * vTaskAllocateMPURegions().
  331. *
  332. * @param xTask The handle of the task being updated.
  333. *
  334. * @param xRegions A pointer to an xMemoryRegion structure that contains the
  335. * new memory region definitions.
  336. *
  337. * Example usage:
  338. <pre>
  339. // Define an array of xMemoryRegion structures that configures an MPU region
  340. // allowing read/write access for 1024 bytes starting at the beginning of the
  341. // ucOneKByte array. The other two of the maximum 3 definable regions are
  342. // unused so set to zero.
  343. static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
  344. {
  345. // Base address Length Parameters
  346. { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
  347. { 0, 0, 0 },
  348. { 0, 0, 0 }
  349. };
  350. void vATask( void *pvParameters )
  351. {
  352. // This task was created such that it has access to certain regions of
  353. // memory as defined by the MPU configuration. At some point it is
  354. // desired that these MPU regions are replaced with that defined in the
  355. // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
  356. // for this purpose. NULL is used as the task handle to indicate that this
  357. // function should modify the MPU regions of the calling task.
  358. vTaskAllocateMPURegions( NULL, xAltRegions );
  359. // Now the task can continue its function, but from this point on can only
  360. // access its stack and the ucOneKByte array (unless any other statically
  361. // defined or shared regions have been declared elsewhere).
  362. }
  363. </pre>
  364. * \defgroup xTaskCreateRestricted xTaskCreateRestricted
  365. * \ingroup Tasks
  366. */
  367. void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION;
  368. /**
  369. * task. h
  370. * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>
  371. *
  372. * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  373. * See the configuration section for more information.
  374. *
  375. * Remove a task from the RTOS real time kernels management. The task being
  376. * deleted will be removed from all ready, blocked, suspended and event lists.
  377. *
  378. * NOTE: The idle task is responsible for freeing the kernel allocated
  379. * memory from tasks that have been deleted. It is therefore important that
  380. * the idle task is not starved of microcontroller processing time if your
  381. * application makes any calls to vTaskDelete (). Memory allocated by the
  382. * task code is not automatically freed, and should be freed before the task
  383. * is deleted.
  384. *
  385. * See the demo application file death.c for sample code that utilises
  386. * vTaskDelete ().
  387. *
  388. * @param pxTask The handle of the task to be deleted. Passing NULL will
  389. * cause the calling task to be deleted.
  390. *
  391. * Example usage:
  392. <pre>
  393. void vOtherFunction( void )
  394. {
  395. xTaskHandle xHandle;
  396. // Create the task, storing the handle.
  397. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  398. // Use the handle to delete the task.
  399. vTaskDelete( xHandle );
  400. }
  401. </pre>
  402. * \defgroup vTaskDelete vTaskDelete
  403. * \ingroup Tasks
  404. */
  405. void vTaskDelete( xTaskHandle pxTaskToDelete ) PRIVILEGED_FUNCTION;
  406. /*-----------------------------------------------------------
  407. * TASK CONTROL API
  408. *----------------------------------------------------------*/
  409. /**
  410. * task. h
  411. * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>
  412. *
  413. * Delay a task for a given number of ticks. The actual time that the
  414. * task remains blocked depends on the tick rate. The constant
  415. * portTICK_RATE_MS can be used to calculate real time from the tick
  416. * rate - with the resolution of one tick period.
  417. *
  418. * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  419. * See the configuration section for more information.
  420. *
  421. *
  422. * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  423. * the time at which vTaskDelay() is called. For example, specifying a block
  424. * period of 100 ticks will cause the task to unblock 100 ticks after
  425. * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  426. * of controlling the frequency of a cyclical task as the path taken through the
  427. * code, as well as other task and interrupt activity, will effect the frequency
  428. * at which vTaskDelay() gets called and therefore the time at which the task
  429. * next executes. See vTaskDelayUntil() for an alternative API function designed
  430. * to facilitate fixed frequency execution. It does this by specifying an
  431. * absolute time (rather than a relative time) at which the calling task should
  432. * unblock.
  433. *
  434. * @param xTicksToDelay The amount of time, in tick periods, that
  435. * the calling task should block.
  436. *
  437. * Example usage:
  438. void vTaskFunction( void * pvParameters )
  439. {
  440. void vTaskFunction( void * pvParameters )
  441. {
  442. // Block for 500ms.
  443. const portTickType xDelay = 500 / portTICK_RATE_MS;
  444. for( ;; )
  445. {
  446. // Simply toggle the LED every 500ms, blocking between each toggle.
  447. vToggleLED();
  448. vTaskDelay( xDelay );
  449. }
  450. }
  451. * \defgroup vTaskDelay vTaskDelay
  452. * \ingroup TaskCtrl
  453. */
  454. void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION;
  455. /**
  456. * task. h
  457. * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>
  458. *
  459. * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
  460. * See the configuration section for more information.
  461. *
  462. * Delay a task until a specified time. This function can be used by cyclical
  463. * tasks to ensure a constant execution frequency.
  464. *
  465. * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  466. * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  467. * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  468. * execution frequency as the time between a task starting to execute and that task
  469. * calling vTaskDelay () may not be fixed [the task may take a different path though the
  470. * code between calls, or may get interrupted or preempted a different number of times
  471. * each time it executes].
  472. *
  473. * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  474. * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  475. * unblock.
  476. *
  477. * The constant portTICK_RATE_MS can be used to calculate real time from the tick
  478. * rate - with the resolution of one tick period.
  479. *
  480. * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  481. * task was last unblocked. The variable must be initialised with the current time
  482. * prior to its first use (see the example below). Following this the variable is
  483. * automatically updated within vTaskDelayUntil ().
  484. *
  485. * @param xTimeIncrement The cycle time period. The task will be unblocked at
  486. * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the
  487. * same xTimeIncrement parameter value will cause the task to execute with
  488. * a fixed interface period.
  489. *
  490. * Example usage:
  491. <pre>
  492. // Perform an action every 10 ticks.
  493. void vTaskFunction( void * pvParameters )
  494. {
  495. portTickType xLastWakeTime;
  496. const portTickType xFrequency = 10;
  497. // Initialise the xLastWakeTime variable with the current time.
  498. xLastWakeTime = xTaskGetTickCount ();
  499. for( ;; )
  500. {
  501. // Wait for the next cycle.
  502. vTaskDelayUntil( &xLastWakeTime, xFrequency );
  503. // Perform action here.
  504. }
  505. }
  506. </pre>
  507. * \defgroup vTaskDelayUntil vTaskDelayUntil
  508. * \ingroup TaskCtrl
  509. */
  510. void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION;
  511. /**
  512. * task. h
  513. * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>
  514. *
  515. * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.
  516. * See the configuration section for more information.
  517. *
  518. * Obtain the priority of any task.
  519. *
  520. * @param pxTask Handle of the task to be queried. Passing a NULL
  521. * handle results in the priority of the calling task being returned.
  522. *
  523. * @return The priority of pxTask.
  524. *
  525. * Example usage:
  526. <pre>
  527. void vAFunction( void )
  528. {
  529. xTaskHandle xHandle;
  530. // Create a task, storing the handle.
  531. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  532. // ...
  533. // Use the handle to obtain the priority of the created task.
  534. // It was created with tskIDLE_PRIORITY, but may have changed
  535. // it itself.
  536. if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  537. {
  538. // The task has changed it's priority.
  539. }
  540. // ...
  541. // Is our priority higher than the created task?
  542. if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  543. {
  544. // Our priority (obtained using NULL handle) is higher.
  545. }
  546. }
  547. </pre>
  548. * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  549. * \ingroup TaskCtrl
  550. */
  551. unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
  552. /**
  553. * task. h
  554. * <pre>eTaskState eTaskStateGet( xTaskHandle pxTask );</pre>
  555. *
  556. * INCLUDE_eTaskStateGet must be defined as 1 for this function to be available.
  557. * See the configuration section for more information.
  558. *
  559. * Obtain the state of any task. States are encoded by the eTaskState
  560. * enumerated type.
  561. *
  562. * @param pxTask Handle of the task to be queried.
  563. *
  564. * @return The state of pxTask at the time the function was called. Note the
  565. * state of the task might change between the function being called, and the
  566. * functions return value being tested by the calling task.
  567. */
  568. eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
  569. /**
  570. * task. h
  571. * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
  572. *
  573. * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  574. * See the configuration section for more information.
  575. *
  576. * Set the priority of any task.
  577. *
  578. * A context switch will occur before the function returns if the priority
  579. * being set is higher than the currently executing task.
  580. *
  581. * @param pxTask Handle to the task for which the priority is being set.
  582. * Passing a NULL handle results in the priority of the calling task being set.
  583. *
  584. * @param uxNewPriority The priority to which the task will be set.
  585. *
  586. * Example usage:
  587. <pre>
  588. void vAFunction( void )
  589. {
  590. xTaskHandle xHandle;
  591. // Create a task, storing the handle.
  592. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  593. // ...
  594. // Use the handle to raise the priority of the created task.
  595. vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  596. // ...
  597. // Use a NULL handle to raise our priority to the same value.
  598. vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  599. }
  600. </pre>
  601. * \defgroup vTaskPrioritySet vTaskPrioritySet
  602. * \ingroup TaskCtrl
  603. */
  604. void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION;
  605. /**
  606. * task. h
  607. * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>
  608. *
  609. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  610. * See the configuration section for more information.
  611. *
  612. * Suspend any task. When suspended a task will never get any microcontroller
  613. * processing time, no matter what its priority.
  614. *
  615. * Calls to vTaskSuspend are not accumulative -
  616. * i.e. calling vTaskSuspend () twice on the same task still only requires one
  617. * call to vTaskResume () to ready the suspended task.
  618. *
  619. * @param pxTaskToSuspend Handle to the task being suspended. Passing a NULL
  620. * handle will cause the calling task to be suspended.
  621. *
  622. * Example usage:
  623. <pre>
  624. void vAFunction( void )
  625. {
  626. xTaskHandle xHandle;
  627. // Create a task, storing the handle.
  628. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  629. // ...
  630. // Use the handle to suspend the created task.
  631. vTaskSuspend( xHandle );
  632. // ...
  633. // The created task will not run during this period, unless
  634. // another task calls vTaskResume( xHandle ).
  635. //...
  636. // Suspend ourselves.
  637. vTaskSuspend( NULL );
  638. // We cannot get here unless another task calls vTaskResume
  639. // with our handle as the parameter.
  640. }
  641. </pre>
  642. * \defgroup vTaskSuspend vTaskSuspend
  643. * \ingroup TaskCtrl
  644. */
  645. void vTaskSuspend( xTaskHandle pxTaskToSuspend ) PRIVILEGED_FUNCTION;
  646. /**
  647. * task. h
  648. * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>
  649. *
  650. * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  651. * See the configuration section for more information.
  652. *
  653. * Resumes a suspended task.
  654. *
  655. * A task that has been suspended by one of more calls to vTaskSuspend ()
  656. * will be made available for running again by a single call to
  657. * vTaskResume ().
  658. *
  659. * @param pxTaskToResume Handle to the task being readied.
  660. *
  661. * Example usage:
  662. <pre>
  663. void vAFunction( void )
  664. {
  665. xTaskHandle xHandle;
  666. // Create a task, storing the handle.
  667. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  668. // ...
  669. // Use the handle to suspend the created task.
  670. vTaskSuspend( xHandle );
  671. // ...
  672. // The created task will not run during this period, unless
  673. // another task calls vTaskResume( xHandle ).
  674. //...
  675. // Resume the suspended task ourselves.
  676. vTaskResume( xHandle );
  677. // The created task will once again get microcontroller processing
  678. // time in accordance with it priority within the system.
  679. }
  680. </pre>
  681. * \defgroup vTaskResume vTaskResume
  682. * \ingroup TaskCtrl
  683. */
  684. void vTaskResume( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION;
  685. /**
  686. * task. h
  687. * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>
  688. *
  689. * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  690. * available. See the configuration section for more information.
  691. *
  692. * An implementation of vTaskResume() that can be called from within an ISR.
  693. *
  694. * A task that has been suspended by one of more calls to vTaskSuspend ()
  695. * will be made available for running again by a single call to
  696. * xTaskResumeFromISR ().
  697. *
  698. * @param pxTaskToResume Handle to the task being readied.
  699. *
  700. * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  701. * \ingroup TaskCtrl
  702. */
  703. portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume ) PRIVILEGED_FUNCTION;
  704. /*-----------------------------------------------------------
  705. * SCHEDULER CONTROL
  706. *----------------------------------------------------------*/
  707. /**
  708. * task. h
  709. * <pre>void vTaskStartScheduler( void );</pre>
  710. *
  711. * Starts the real time kernel tick processing. After calling the kernel
  712. * has control over which tasks are executed and when. This function
  713. * does not return until an executing task calls vTaskEndScheduler ().
  714. *
  715. * At least one task should be created via a call to xTaskCreate ()
  716. * before calling vTaskStartScheduler (). The idle task is created
  717. * automatically when the first application task is created.
  718. *
  719. * See the demo application file main.c for an example of creating
  720. * tasks and starting the kernel.
  721. *
  722. * Example usage:
  723. <pre>
  724. void vAFunction( void )
  725. {
  726. // Create at least one task before starting the kernel.
  727. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  728. // Start the real time kernel with preemption.
  729. vTaskStartScheduler ();
  730. // Will not get here unless a task calls vTaskEndScheduler ()
  731. }
  732. </pre>
  733. *
  734. * \defgroup vTaskStartScheduler vTaskStartScheduler
  735. * \ingroup SchedulerControl
  736. */
  737. void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
  738. /**
  739. * task. h
  740. * <pre>void vTaskEndScheduler( void );</pre>
  741. *
  742. * Stops the real time kernel tick. All created tasks will be automatically
  743. * deleted and multitasking (either preemptive or cooperative) will
  744. * stop. Execution then resumes from the point where vTaskStartScheduler ()
  745. * was called, as if vTaskStartScheduler () had just returned.
  746. *
  747. * See the demo application file main. c in the demo/PC directory for an
  748. * example that uses vTaskEndScheduler ().
  749. *
  750. * vTaskEndScheduler () requires an exit function to be defined within the
  751. * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  752. * performs hardware specific operations such as stopping the kernel tick.
  753. *
  754. * vTaskEndScheduler () will cause all of the resources allocated by the
  755. * kernel to be freed - but will not free resources allocated by application
  756. * tasks.
  757. *
  758. * Example usage:
  759. <pre>
  760. void vTaskCode( void * pvParameters )
  761. {
  762. for( ;; )
  763. {
  764. // Task code goes here.
  765. // At some point we want to end the real time kernel processing
  766. // so call ...
  767. vTaskEndScheduler ();
  768. }
  769. }
  770. void vAFunction( void )
  771. {
  772. // Create at least one task before starting the kernel.
  773. xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  774. // Start the real time kernel with preemption.
  775. vTaskStartScheduler ();
  776. // Will only get here when the vTaskCode () task has called
  777. // vTaskEndScheduler (). When we get here we are back to single task
  778. // execution.
  779. }
  780. </pre>
  781. *
  782. * \defgroup vTaskEndScheduler vTaskEndScheduler
  783. * \ingroup SchedulerControl
  784. */
  785. void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
  786. /**
  787. * task. h
  788. * <pre>void vTaskSuspendAll( void );</pre>
  789. *
  790. * Suspends all real time kernel activity while keeping interrupts (including the
  791. * kernel tick) enabled.
  792. *
  793. * After calling vTaskSuspendAll () the calling task will continue to execute
  794. * without risk of being swapped out until a call to xTaskResumeAll () has been
  795. * made.
  796. *
  797. * API functions that have the potential to cause a context switch (for example,
  798. * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  799. * is suspended.
  800. *
  801. * Example usage:
  802. <pre>
  803. void vTask1( void * pvParameters )
  804. {
  805. for( ;; )
  806. {
  807. // Task code goes here.
  808. // ...
  809. // At some point the task wants to perform a long operation during
  810. // which it does not want to get swapped out. It cannot use
  811. // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  812. // operation may cause interrupts to be missed - including the
  813. // ticks.
  814. // Prevent the real time kernel swapping out the task.
  815. vTaskSuspendAll ();
  816. // Perform the operation here. There is no need to use critical
  817. // sections as we have all the microcontroller processing time.
  818. // During this time interrupts will still operate and the kernel
  819. // tick count will be maintained.
  820. // ...
  821. // The operation is complete. Restart the kernel.
  822. xTaskResumeAll ();
  823. }
  824. }
  825. </pre>
  826. * \defgroup vTaskSuspendAll vTaskSuspendAll
  827. * \ingroup SchedulerControl
  828. */
  829. void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
  830. /**
  831. * task. h
  832. * <pre>char xTaskResumeAll( void );</pre>
  833. *
  834. * Resumes real time kernel activity following a call to vTaskSuspendAll ().
  835. * After a call to vTaskSuspendAll () the kernel will take control of which
  836. * task is executing at any time.
  837. *
  838. * @return If resuming the scheduler caused a context switch then pdTRUE is
  839. * returned, otherwise pdFALSE is returned.
  840. *
  841. * Example usage:
  842. <pre>
  843. void vTask1( void * pvParameters )
  844. {
  845. for( ;; )
  846. {
  847. // Task code goes here.
  848. // ...
  849. // At some point the task wants to perform a long operation during
  850. // which it does not want to get swapped out. It cannot use
  851. // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  852. // operation may cause interrupts to be missed - including the
  853. // ticks.
  854. // Prevent the real time kernel swapping out the task.
  855. vTaskSuspendAll ();
  856. // Perform the operation here. There is no need to use critical
  857. // sections as we have all the microcontroller processing time.
  858. // During this time interrupts will still operate and the real
  859. // time kernel tick count will be maintained.
  860. // ...
  861. // The operation is complete. Restart the kernel. We want to force
  862. // a context switch - but there is no point if resuming the scheduler
  863. // caused a context switch already.
  864. if( !xTaskResumeAll () )
  865. {
  866. taskYIELD ();
  867. }
  868. }
  869. }
  870. </pre>
  871. * \defgroup xTaskResumeAll xTaskResumeAll
  872. * \ingroup SchedulerControl
  873. */
  874. signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
  875. /**
  876. * task. h
  877. * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>
  878. *
  879. * Utility task that simply returns pdTRUE if the task referenced by xTask is
  880. * currently in the Suspended state, or pdFALSE if the task referenced by xTask
  881. * is in any other state.
  882. *
  883. */
  884. signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
  885. /*-----------------------------------------------------------
  886. * TASK UTILITIES
  887. *----------------------------------------------------------*/
  888. /**
  889. * task. h
  890. * <PRE>portTickType xTaskGetTickCount( void );</PRE>
  891. *
  892. * @return The count of ticks since vTaskStartScheduler was called.
  893. *
  894. * \page xTaskGetTickCount xTaskGetTickCount
  895. * \ingroup TaskUtils
  896. */
  897. portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
  898. /**
  899. * task. h
  900. * <PRE>portTickType xTaskGetTickCountFromISR( void );</PRE>
  901. *
  902. * @return The count of ticks since vTaskStartScheduler was called.
  903. *
  904. * This is a version of xTaskGetTickCount() that is safe to be called from an
  905. * ISR - provided that portTickType is the natural word size of the
  906. * microcontroller being used or interrupt nesting is either not supported or
  907. * not being used.
  908. *
  909. * \page xTaskGetTickCount xTaskGetTickCount
  910. * \ingroup TaskUtils
  911. */
  912. portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
  913. /**
  914. * task. h
  915. * <PRE>unsigned short uxTaskGetNumberOfTasks( void );</PRE>
  916. *
  917. * @return The number of tasks that the real time kernel is currently managing.
  918. * This includes all ready, blocked and suspended tasks. A task that
  919. * has been deleted but not yet freed by the idle task will also be
  920. * included in the count.
  921. *
  922. * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  923. * \ingroup TaskUtils
  924. */
  925. unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
  926. /**
  927. * task. h
  928. * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE>
  929. *
  930. * @return The text (human readable) name of the task referenced by the handle
  931. * xTaskToQueury. A task can query its own name by either passing in its own
  932. * handle, or by setting xTaskToQuery to NULL. INCLUDE_pcTaskGetTaskName must be
  933. * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
  934. *
  935. * \page pcTaskGetTaskName pcTaskGetTaskName
  936. * \ingroup TaskUtils
  937. */
  938. signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );
  939. /**
  940. * task. h
  941. * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
  942. *
  943. * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
  944. * available. See the configuration section for more information.
  945. *
  946. * NOTE: This function will disable interrupts for its duration. It is
  947. * not intended for normal application runtime use but as a debug aid.
  948. *
  949. * Lists all the current tasks, along with their current state and stack
  950. * usage high water mark.
  951. *
  952. * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
  953. * suspended ('S').
  954. *
  955. * @param pcWriteBuffer A buffer into which the above mentioned details
  956. * will be written, in ascii form. This buffer is assumed to be large
  957. * enough to contain the generated report. Approximately 40 bytes per
  958. * task should be sufficient.
  959. *
  960. * \page vTaskList vTaskList
  961. * \ingroup TaskUtils
  962. */
  963. void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
  964. /**
  965. * task. h
  966. * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
  967. *
  968. * configGENERATE_RUN_TIME_STATS must be defined as 1 for this function
  969. * to be available. The application must also then provide definitions
  970. * for portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
  971. * portGET_RUN_TIME_COUNTER_VALUE to configure a peripheral timer/counter
  972. * and return the timers current count value respectively. The counter
  973. * should be at least 10 times the frequency of the tick count.
  974. *
  975. * NOTE: This function will disable interrupts for its duration. It is
  976. * not intended for normal application runtime use but as a debug aid.
  977. *
  978. * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
  979. * accumulated execution time being stored for each task. The resolution
  980. * of the accumulated time value depends on the frequency of the timer
  981. * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
  982. * Calling vTaskGetRunTimeStats() writes the total execution time of each
  983. * task into a buffer, both as an absolute count value and as a percentage
  984. * of the total system execution time.
  985. *
  986. * @param pcWriteBuffer A buffer into which the execution times will be
  987. * written, in ascii form. This buffer is assumed to be large enough to
  988. * contain the generated report. Approximately 40 bytes per task should
  989. * be sufficient.
  990. *
  991. * \page vTaskGetRunTimeStats vTaskGetRunTimeStats
  992. * \ingroup TaskUtils
  993. */
  994. void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;
  995. /**
  996. * task.h
  997. * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>
  998. *
  999. * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  1000. * this function to be available.
  1001. *
  1002. * Returns the high water mark of the stack associated with xTask. That is,
  1003. * the minimum free stack space there has been (in words, so on a 32 bit machine
  1004. * a value of 1 means 4 bytes) since the task started. The smaller the returned
  1005. * number the closer the task has come to overflowing its stack.
  1006. *
  1007. * @param xTask Handle of the task associated with the stack to be checked.
  1008. * Set xTask to NULL to check the stack of the calling task.
  1009. *
  1010. * @return The smallest amount of free stack space there has been (in bytes)
  1011. * since the task referenced by xTask was created.
  1012. */
  1013. unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
  1014. /* When using trace macros it is sometimes necessary to include tasks.h before
  1015. FreeRTOS.h. When this is done pdTASK_HOOK_CODE will not yet have been defined,
  1016. so the following two prototypes will cause a compilation error. This can be
  1017. fixed by simply guarding against the inclusion of these two prototypes unless
  1018. they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  1019. constant. */
  1020. #ifdef configUSE_APPLICATION_TASK_TAG
  1021. #if configUSE_APPLICATION_TASK_TAG == 1
  1022. /**
  1023. * task.h
  1024. * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
  1025. *
  1026. * Sets pxHookFunction to be the task hook function used by the task xTask.
  1027. * Passing xTask as NULL has the effect of setting the calling tasks hook
  1028. * function.
  1029. */
  1030. void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION;
  1031. /**
  1032. * task.h
  1033. * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre>
  1034. *
  1035. * Returns the pxHookFunction value assigned to the task xTask.
  1036. */
  1037. pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION;
  1038. #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  1039. #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  1040. /**
  1041. * task.h
  1042. * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>
  1043. *
  1044. * Calls the hook function associated with xTask. Passing xTask as NULL has
  1045. * the effect of calling the Running tasks (the calling task) hook function.
  1046. *
  1047. * pvParameter is passed to the hook function for the task to interpret as it
  1048. * wants.
  1049. */
  1050. portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
  1051. /**
  1052. * xTaskGetIdleTaskHandle() is only available if
  1053. * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  1054. *
  1055. * Simply returns the handle of the idle task. It is not valid to call
  1056. * xTaskGetIdleTaskHandle() before the scheduler has been started.
  1057. */
  1058. xTaskHandle xTaskGetIdleTaskHandle( void );
  1059. /*-----------------------------------------------------------
  1060. * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  1061. *----------------------------------------------------------*/
  1062. /*
  1063. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  1064. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  1065. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  1066. *
  1067. * Called from the real time kernel tick (either preemptive or cooperative),
  1068. * this increments the tick count and checks if any tasks that are blocked
  1069. * for a finite period required removing from a blocked list and placing on
  1070. * a ready list.
  1071. */
  1072. void vTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
  1073. /*
  1074. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  1075. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  1076. *
  1077. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  1078. *
  1079. * Removes the calling task from the ready list and places it both
  1080. * on the list of tasks waiting for a particular event, and the
  1081. * list of delayed tasks. The task will be removed from both lists
  1082. * and replaced on the ready list should either the event occur (and
  1083. * there be no higher priority tasks waiting on the same event) or
  1084. * the delay period expires.
  1085. *
  1086. * @param pxEventList The list containing tasks that are blocked waiting
  1087. * for the event to occur.
  1088. *
  1089. * @param xTicksToWait The maximum amount of time that the task should wait
  1090. * for the event to occur. This is specified in kernel ticks,the constant
  1091. * portTICK_RATE_MS can be used to convert kernel ticks into a real time
  1092. * period.
  1093. */
  1094. void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
  1095. /*
  1096. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  1097. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  1098. *
  1099. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  1100. *
  1101. * This function performs nearly the same function as vTaskPlaceOnEventList().
  1102. * The difference being that this function does not permit tasks to block
  1103. * indefinitely, whereas vTaskPlaceOnEventList() does.
  1104. *
  1105. * @return pdTRUE if the task being removed has a higher priority than the task
  1106. * making the call, otherwise pdFALSE.
  1107. */
  1108. void vTaskPlaceOnEventListRestricted( const xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
  1109. /*
  1110. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
  1111. * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  1112. *
  1113. * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
  1114. *
  1115. * Removes a task from both the specified event list and the list of blocked
  1116. * tasks, and places it on a ready queue.
  1117. *
  1118. * xTaskRemoveFromEventList () will be called if either an event occurs to
  1119. * unblock a task, or the block timeout period expires.
  1120. *
  1121. * @return pdTRUE if the task being removed has a higher priority than the task
  1122. * making the call, otherwise pdFALSE.
  1123. */
  1124. signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION;
  1125. /*
  1126. * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
  1127. * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
  1128. * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
  1129. *
  1130. * Sets the pointer to the current TCB to the TCB of the highest priority task
  1131. * that is ready to run.
  1132. */
  1133. void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
  1134. /*
  1135. * Return the handle of the calling task.
  1136. */
  1137. xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
  1138. /*
  1139. * Capture the current time status for future reference.
  1140. */
  1141. void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION;
  1142. /*
  1143. * Compare the time status now with that previously captured to see if the
  1144. * timeout has expired.
  1145. */
  1146. portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION;
  1147. /*
  1148. * Shortcut used by the queue implementation to prevent unnecessary call to
  1149. * taskYIELD();
  1150. */
  1151. void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
  1152. /*
  1153. * Returns the scheduler state as taskSCHEDULER_RUNNING,
  1154. * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  1155. */
  1156. portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  1157. /*
  1158. * Raises the priority of the mutex holder to that of the calling task should
  1159. * the mutex holder have a priority less than the calling task.
  1160. */
  1161. void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
  1162. /*
  1163. * Set the priority of a task back to its proper priority in the case that it
  1164. * inherited a higher priority while it was holding a semaphore.
  1165. */
  1166. void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder ) PRIVILEGED_FUNCTION;
  1167. /*
  1168. * Generic version of the task creation function which is in turn called by the
  1169. * xTaskCreate() and xTaskCreateRestricted() macros.
  1170. */
  1171. signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) PRIVILEGED_FUNCTION;
  1172. /*
  1173. * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
  1174. */
  1175. unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
  1176. /*
  1177. * Set the uxTCBNumber of the task referenced by the xTask parameter to
  1178. * ucHandle.
  1179. */
  1180. void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );
  1181. /*
  1182. * If tickless mode is being used, or a low power mode is implemented, then
  1183. * the tick interrupt will not execute during idle periods. When this is the
  1184. * case, the tick count value maintained by the scheduler needs to be kept up
  1185. * to date with the actual execution time by being skipped forward by the by
  1186. * a time equal to the idle period.
  1187. */
  1188. void vTaskStepTick( portTickType xTicksToJump );
  1189. #ifdef __cplusplus
  1190. }
  1191. #endif
  1192. #endif /* TASK_H */