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