los_task.h 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /* ----------------------------------------------------------------------------
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
  3. * Description: LiteOS Task Module Implementation HeadFile
  4. * Author: Huawei LiteOS Team
  5. * Create: 2013-01-01
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. * 1. Redistributions of source code must retain the above copyright notice, this list of
  9. * conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  11. * of conditions and the following disclaimer in the documentation and/or other materials
  12. * provided with the distribution.
  13. * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  14. * to endorse or promote products derived from this software without specific prior written
  15. * permission.
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  25. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. * --------------------------------------------------------------------------- */
  28. /**
  29. * @defgroup los_task Task
  30. * @ingroup kernel
  31. */
  32. #ifndef _LOS_TASK_H
  33. #define _LOS_TASK_H
  34. #include "los_base.h"
  35. #include "los_errno.h"
  36. #define LOSCFG_TASK_STATIC_ALLOCATION
  37. #ifdef __cplusplus
  38. #if __cplusplus
  39. extern "C" {
  40. #endif /* __cplusplus */
  41. #endif /* __cplusplus */
  42. #define CPUID_TO_AFFI_MASK(cpuid) (0x1u << (cpuid))
  43. /**
  44. * @ingroup los_task
  45. * Flag that indicates the task or task control block status. LOS_TASK_STATUS_DETACHED
  46. * means the task is in the auto-deleted state. In this state, the task will be deleted
  47. * automatically after the task is done.
  48. */
  49. #define LOS_TASK_STATUS_DETACHED 0x0100U
  50. /**
  51. * @ingroup los_task
  52. * Task error code: Insufficient memory for task creation.
  53. *
  54. * Value: 0x03000200.
  55. *
  56. * Solution: Allocate bigger memory partition to task creation.
  57. */
  58. #define LOS_ERRNO_TSK_NO_MEMORY LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x00)
  59. /**
  60. * @ingroup los_task
  61. * Task error code: Null parameter.
  62. *
  63. * Value: 0x02000201.
  64. *
  65. * Solution: Check the parameter.
  66. */
  67. #define LOS_ERRNO_TSK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x01)
  68. /**
  69. * @ingroup los_task
  70. * Task error code: The task stack is not aligned.
  71. *
  72. * Value: 0x02000202.
  73. *
  74. * Solution: Align the task stack.
  75. */
  76. #define LOS_ERRNO_TSK_STKSZ_NOT_ALIGN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x02)
  77. /**
  78. * @ingroup los_task
  79. * Task error code: Incorrect task priority.
  80. *
  81. * Value: 0x02000203.
  82. *
  83. * Solution: Re-configure the task priority by referring to the priority range.
  84. */
  85. #define LOS_ERRNO_TSK_PRIOR_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x03)
  86. /**
  87. * @ingroup los_task
  88. * Task error code: The task entrance is NULL.
  89. *
  90. * Value: 0x02000204.
  91. *
  92. * Solution: Define the task entrance function.
  93. */
  94. #define LOS_ERRNO_TSK_ENTRY_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x04)
  95. /**
  96. * @ingroup los_task
  97. * Task error code: The task name is NULL.
  98. *
  99. * Value: 0x02000205.
  100. *
  101. * Solution: Set the task name.
  102. */
  103. #define LOS_ERRNO_TSK_NAME_EMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x05)
  104. /**
  105. * @ingroup los_task
  106. * Task error code: The task stack size is too small.
  107. *
  108. * Value: 0x02000206.
  109. *
  110. * Solution: Expand the task stack.
  111. */
  112. #define LOS_ERRNO_TSK_STKSZ_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x06)
  113. /**
  114. * @ingroup los_task
  115. * Task error code: Invalid task ID.
  116. *
  117. * Value: 0x02000207.
  118. *
  119. * Solution: Check the task ID.
  120. */
  121. #define LOS_ERRNO_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x07)
  122. /**
  123. * @ingroup los_task
  124. * Task error code: The task is already suspended.
  125. *
  126. * Value: 0x02000208.
  127. *
  128. * Solution: Suspend the task after it is resumed.
  129. */
  130. #define LOS_ERRNO_TSK_ALREADY_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x08)
  131. /**
  132. * @ingroup los_task
  133. * Task error code: The task is not suspended.
  134. *
  135. * Value: 0x02000209.
  136. *
  137. * Solution: Suspend the task.
  138. */
  139. #define LOS_ERRNO_TSK_NOT_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x09)
  140. /**
  141. * @ingroup los_task
  142. * Task error code: The task is not created.
  143. *
  144. * Value: 0x0200020a.
  145. *
  146. * Solution: Create the task.
  147. */
  148. #define LOS_ERRNO_TSK_NOT_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0a)
  149. /**
  150. * @ingroup los_task
  151. * Task error code: The task is locked when it is being deleted.
  152. *
  153. * Value: 0x0300020b.
  154. *
  155. * Solution: Unlock the task.
  156. */
  157. #define LOS_ERRNO_TSK_DELETE_LOCKED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x0b)
  158. /**
  159. * @ingroup los_task
  160. * Task error code: The task message is nonzero.
  161. *
  162. * Value: 0x0200020c.
  163. *
  164. * Solution: This error code is not in use temporarily.
  165. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  166. */
  167. #define LOS_ERRNO_TSK_MSG_NONZERO LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0c)
  168. /**
  169. * @ingroup los_task
  170. * Task error code: The task delay occurs during an interrupt.
  171. *
  172. * Value: 0x0300020d.
  173. *
  174. * Solution: Perform this operation after exiting from the interrupt.
  175. */
  176. #define LOS_ERRNO_TSK_DELAY_IN_INT LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x0d)
  177. /**
  178. * @ingroup los_task
  179. * Task error code: The task delay occurs when the task is locked.
  180. *
  181. * Value: 0x0200020e.
  182. *
  183. * Solution: Perform this operation after unlocking the task.
  184. */
  185. #define LOS_ERRNO_TSK_DELAY_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0e)
  186. /**
  187. * @ingroup los_task
  188. * Task error code: The task yield occurs when the task is locked.
  189. *
  190. * Value: 0x0200020f.
  191. *
  192. * Solution: Check the task.
  193. */
  194. #define LOS_ERRNO_TSK_YIELD_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0f)
  195. /**
  196. * @ingroup los_task
  197. * Task error code: Only one task or no task is available for scheduling.
  198. *
  199. * Value: 0x02000210.
  200. *
  201. * Solution: Increase the number of tasks.
  202. */
  203. #define LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x10)
  204. /**
  205. * @ingroup los_task
  206. * Task error code: No free task control block is available.
  207. *
  208. * Value: 0x02000211.
  209. *
  210. * Solution: Increase the number of task control blocks.
  211. */
  212. #define LOS_ERRNO_TSK_TCB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x11)
  213. /**
  214. * @ingroup los_task
  215. * Task error code: The task hook function is not matchable.
  216. *
  217. * Value: 0x02000212.
  218. *
  219. * Solution: This error code is not in use temporarily.
  220. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  221. */
  222. #define LOS_ERRNO_TSK_HOOK_NOT_MATCH LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x12)
  223. /**
  224. * @ingroup los_task
  225. * Task error code: The number of task hook functions exceeds the permitted upper limit.
  226. *
  227. * Value: 0x02000213.
  228. *
  229. * Solution: This error code is not in use temporarily.
  230. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  231. */
  232. #define LOS_ERRNO_TSK_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x13)
  233. /**
  234. * @ingroup los_task
  235. * Task error code: The operation is performed on the system-level task.
  236. * old usage: The operation is performed on the idle task (LOS_ERRNO_TSK_OPERATE_IDLE)
  237. *
  238. * Value: 0x02000214.
  239. *
  240. * Solution: Check the task ID and do not operate the system-level task.
  241. */
  242. #define LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x14)
  243. /**
  244. * @ingroup los_task
  245. * Task error code: The task that is being suspended is locked.
  246. *
  247. * Value: 0x03000215.
  248. *
  249. * Solution: Suspend the task after unlocking the task.
  250. */
  251. #define LOS_ERRNO_TSK_SUSPEND_LOCKED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x15)
  252. /**
  253. * @ingroup los_task
  254. * Task error code: The task stack fails to be freed.
  255. *
  256. * Value: 0x02000217
  257. *
  258. * Solution: This error code is not in use temporarily.
  259. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  260. */
  261. #define LOS_ERRNO_TSK_FREE_STACK_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x17)
  262. /**
  263. * @ingroup los_task
  264. * Task error code: The task stack area is too small.
  265. *
  266. * Value: 0x02000218
  267. *
  268. * Solution: This error code is not in use temporarily.
  269. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  270. */
  271. #define LOS_ERRNO_TSK_STKAREA_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x18)
  272. /**
  273. * @ingroup los_task
  274. * Task error code: The task fails to be activated.
  275. *
  276. * Value: 0x03000219.
  277. *
  278. * Solution: Perform task switching after creating an idle task.
  279. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  280. */
  281. #define LOS_ERRNO_TSK_ACTIVE_FAILED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x19)
  282. /**
  283. * @ingroup los_task
  284. * Task error code: Too many task configuration items.
  285. *
  286. * Value: 0x0200021a
  287. *
  288. * Solution: This error code is not in use temporarily.
  289. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  290. */
  291. #define LOS_ERRNO_TSK_CONFIG_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1a)
  292. /**
  293. * @ingroup los_task
  294. * Task error code: This error code is not in use temporarily.
  295. *
  296. * Value: 0x0200021b
  297. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  298. */
  299. #define LOS_ERRNO_TSK_CP_SAVE_AREA_NOT_ALIGN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1b)
  300. /**
  301. * @ingroup los_task
  302. * Task error code: This error code is not in use temporarily.
  303. *
  304. * Value: 0x0200021d
  305. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  306. */
  307. #define LOS_ERRNO_TSK_MSG_Q_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1d)
  308. /**
  309. * @ingroup los_task
  310. * Task error code: This error code is not in use temporarily.
  311. *
  312. * Value: 0x0200021e
  313. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  314. */
  315. #define LOS_ERRNO_TSK_CP_SAVE_AREA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1e)
  316. /**
  317. * @ingroup los_task
  318. * Task error code: This error code is not in use temporarily.
  319. *
  320. * Value: 0x0200021f
  321. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  322. */
  323. #define LOS_ERRNO_TSK_SELF_DELETE_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1f)
  324. /**
  325. * @ingroup los_task
  326. * Task error code: The task stack size is too large.
  327. *
  328. * Value: 0x02000220.
  329. *
  330. * Solution: shrink the task stack size parameter.
  331. */
  332. #define LOS_ERRNO_TSK_STKSZ_TOO_LARGE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x20)
  333. /**
  334. * @ingroup los_task
  335. * Task error code: Suspending software timer task is not allowed.
  336. *
  337. * Value: 0x02000221.
  338. *
  339. * Solution: Check the task ID and do not suspend software timer task.
  340. * @deprecated This error code is obsolete since LiteOS 5.0.0.
  341. */
  342. #define LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x21)
  343. /**
  344. * @ingroup los_task
  345. * Task error code: The cpu affinity mask is incorrect.
  346. *
  347. * Value: 0x03000223.
  348. *
  349. * Solution: Please set the correct cpu affinity mask.
  350. */
  351. #define LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x23)
  352. /**
  353. * @ingroup los_task
  354. * Task error code: Task yield in interrupt is not permited, which will result in an unexpected result.
  355. *
  356. * Value: 0x02000224.
  357. *
  358. * Solution: Don't call LOS_TaskYield in Interrupt.
  359. */
  360. #define LOS_ERRNO_TSK_YIELD_IN_INT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x24)
  361. /**
  362. * @ingroup los_task
  363. * Task error code: Task sync resource (semaphore) allocated failed.
  364. *
  365. * Value: 0x02000225.
  366. *
  367. * Solution: Expand LOSCFG_BASE_IPC_SEM_LIMIT.
  368. */
  369. #define LOS_ERRNO_TSK_MP_SYNC_RESOURCE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x25)
  370. /**
  371. * @ingroup los_task
  372. * Task error code: Task sync failed on operating running task across cores.
  373. *
  374. * Value: 0x02000226.
  375. *
  376. * Solution: Check task delete can be handled in user's scenario.
  377. */
  378. #define LOS_ERRNO_TSK_MP_SYNC_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x26)
  379. /**
  380. * @ingroup los_task
  381. * Minimum stack size.
  382. *
  383. * LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE bytes, configured in menuconfig.
  384. * LOS_TASK_MIN_STACK_SIZE bytes, aligned on a boundary of LOSCFG_STACK_POINT_ALIGN_SIZE.
  385. */
  386. #define LOS_TASK_MIN_STACK_SIZE (ALIGN(KERNEL_TSK_MIN_STACK_SIZE, LOSCFG_STACK_POINT_ALIGN_SIZE))
  387. #ifdef LOSCFG_BASE_CORE_TSK_MONITOR
  388. /**
  389. * @ingroup los_task
  390. * @brief Define the type of the task switching hook function.
  391. *
  392. * @par Description:
  393. * This API is used to define the type of the task switching hook function.
  394. * @attention The function type is defined only when #LOSCFG_BASE_CORE_TSK_MONITOR is set to YES.
  395. *
  396. * @param None.
  397. *
  398. * @retval None.
  399. * @par Dependency:
  400. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  401. * @since Huawei LiteOS V100R001C00
  402. */
  403. typedef VOID (*TSKSWITCHHOOK)(VOID);
  404. /**
  405. * @ingroup los_task
  406. * @brief User task switching hook function.
  407. *
  408. * @par Description:
  409. * This API is a user task switching hook register function.
  410. * @attention The function is used only when #LOSCFG_BASE_CORE_TSK_MONITOR is set to YES.
  411. *
  412. * @param hook [IN] Type #TSKSWITCHHOOK. The user defined hook for task switch.
  413. * @retval None.
  414. * @par Dependency:
  415. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  416. * @since Huawei LiteOS V200R005C10
  417. */
  418. extern VOID LOS_TaskSwitchHookReg(TSKSWITCHHOOK hook);
  419. #endif
  420. /**
  421. * @ingroup los_task
  422. * @brief Define the type of a task entrance function.
  423. *
  424. * @par Description:
  425. * This API is used to define the type of a task entrance function and call it after a task is created and triggered.
  426. * @attention If LOSCFG_OBSOLETE_API is not defined, one parameter which its type is VOID * will be instead of these
  427. * four parameters of the API.
  428. *
  429. * @param param1 [IN] Type #UINTPTR The first parameter passed to the task handling function.
  430. * @param param2 [IN] Type #UINTPTR The second parameter passed to the task handling function.
  431. * @param param3 [IN] Type #UINTPTR The third parameter passed to the task handling function.
  432. * @param param4 [IN] Type #UINTPTR The fourth parameter passed to the task handling function.
  433. *
  434. * @retval #VOID* This API will return the return value of task function.
  435. * @par Dependency:
  436. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  437. * @since Huawei LiteOS V100R001C00
  438. */
  439. #ifdef LOSCFG_OBSOLETE_API
  440. typedef VOID *(*TSK_ENTRY_FUNC)(UINTPTR param1,
  441. UINTPTR param2,
  442. UINTPTR param3,
  443. UINTPTR param4);
  444. #else
  445. typedef VOID *(*TSK_ENTRY_FUNC)(VOID *param);
  446. #endif
  447. /**
  448. * @ingroup los_task
  449. * Define the structure of the parameters used for task creation.
  450. *
  451. * Information of specified parameters passed in during task creation.
  452. */
  453. typedef struct tagTskInitParam {
  454. TSK_ENTRY_FUNC pfnTaskEntry; /**< Task entrance function */
  455. UINT16 usTaskPrio; /**< Task priority */
  456. #ifdef LOSCFG_OBSOLETE_API
  457. UINTPTR auwArgs[4]; /**< Task parameters, of which the maximum number is four.
  458. If LOSCFG_OBSOLETE_API is not defined, auwArgs[4] will
  459. be replaced by pArgs which its type is void *. */
  460. #else
  461. VOID *pArgs; /**< Task Parameter, of which the type is void * */
  462. #endif
  463. UINT32 uwStackSize; /**< Task stack size */
  464. CHAR *pcName; /**< Task name */
  465. #ifdef LOSCFG_KERNEL_SMP
  466. UINT16 usCpuAffiMask; /**< Task cpu affinity mask. It is defined only when LOSCFG_KERNEL_SMP is defined. */
  467. #endif
  468. UINT32 uwResved; /**< Task is automatically deleted if uwResved is set to #LOS_TASK_STATUS_DETACHED.
  469. Task will not be deleted automatically if it is set to 0. */
  470. } TSK_INIT_PARAM_S;
  471. /**
  472. * @ingroup los_task
  473. * Task name length
  474. *
  475. */
  476. #define LOS_TASK_NAMELEN 32
  477. /**
  478. * @ingroup los_task
  479. * Task information structure.
  480. *
  481. */
  482. typedef struct tagTskInfo {
  483. CHAR acName[LOS_TASK_NAMELEN]; /**< Task name, the default value of
  484. #LOS_TASK_NAMELEN is 32 */
  485. UINT32 uwTaskID; /**< Task ID */
  486. UINT16 usTaskStatus; /**< Task status */
  487. UINT16 usTaskPrio; /**< Task priority */
  488. VOID *pTaskSem; /**< Semaphore pointer */
  489. VOID *pTaskMux; /**< Mutex pointer */
  490. // EVENT_CB_S uwEvent; /**< Event */
  491. UINT32 uwEventMask; /**< Event mask */
  492. UINT32 uwStackSize; /**< Task stack size */
  493. UINTPTR uwTopOfStack; /**< Task stack top */
  494. UINTPTR uwBottomOfStack; /**< Task stack bottom */
  495. UINTPTR uwSP; /**< Task SP pointer */
  496. UINT32 uwCurrUsed; /**< Current task stack usage */
  497. UINT32 uwPeakUsed; /**< Task stack usage peak */
  498. BOOL bOvf; /**< Flag that indicates whether a task stack overflow
  499. occurs or not */
  500. } TSK_INFO_S;
  501. #ifdef LOSCFG_TASK_STATIC_ALLOCATION
  502. /**
  503. * @ingroup los_task
  504. * @brief Create a task with User defines stack space and suspend .
  505. *
  506. * @par Description:
  507. * This API is used to create a task and suspend it. This task will not be added to the queue of ready tasks before
  508. * resume it.
  509. * User should allocate memory for task's stack and assign its addr to para topStack, the uwStackSize in taskInitParam
  510. * must fit the stack memory size. When the task is deleted, the stack's memory should be free in time by users.
  511. *
  512. * @attention
  513. * <ul>
  514. * <li>The task name is a pointer and is not allocated memory.</li>
  515. * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
  516. * to specify the default task stack size. The stack size should be a reasonable value, if the size is too large, may
  517. * cause memory exhaustion.</li>
  518. * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
  519. * enough to avoid task stack overflow.</li>
  520. * <li>Less parameter value indicates higher task priority.</li>
  521. * <li>The task name cannot be null.</li>
  522. * <li>The pointer to the task executing function cannot be null.</li>
  523. * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
  524. * abnormal.</li>
  525. * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer,
  526. * uwStackSize remain as the kernel stack size.</li>
  527. * </ul>
  528. *
  529. * @param taskId [OUT] Type #UINT32 * Task Id.
  530. * @param initParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
  531. * @param topStack [IN] Type #VOID* Parameter for task's top of stack address.
  532. *
  533. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL.
  534. * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL.
  535. * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
  536. * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
  537. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
  538. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
  539. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
  540. * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
  541. * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
  542. * @retval #LOS_OK The task is successfully created.
  543. * @par Dependency:
  544. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  545. * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
  546. * @see LOS_TaskCreateStatic | LOS_TaskDeleteStatic
  547. * @since Huawei LiteOS V200R005C10
  548. */
  549. extern UINT32 LOS_TaskCreateOnlyStatic(UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID *topStack);
  550. /**
  551. * @ingroup los_task
  552. * @brief Create a task.
  553. *
  554. * @par Description:
  555. * This API is used to create a task. If the priority of the task created after system initialized is higher than
  556. * the current task and task scheduling is not locked, it is scheduled for running.
  557. * User should allocate memory for task's stack and assign its addr to para topStack, the uwStackSize in taskInitParam
  558. * must fit the stack memory size. When the task is deleted, the stack's memory should be free in time by users.
  559. * If not, the created task is added to the queue of ready tasks.
  560. *
  561. * @attention
  562. * <ul>
  563. * <li>The task name is a pointer and is not allocated memory.</li>
  564. * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
  565. * to specify the default task stack size.</li>
  566. * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
  567. * enough to avoid task stack overflow.</li>
  568. * <li>Less parameter value indicates higher task priority.</li>
  569. * <li>The task name cannot be null.</li>
  570. * <li>The pointer to the task executing function cannot be null.</li>
  571. * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
  572. * abnormal.</li>
  573. * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer,
  574. * uwStackSize remain as the kernel stack size.</li>
  575. * <li>If LOSCFG_STATIC_ALLOC_MEM is enabled, user should define a static stack memory and assign to stack pointer,
  576. * the uwStackSize must fit the stack memory size.</li>
  577. * </ul>
  578. *
  579. * @param taskId [OUT] Type #UINT32 * Task Id.
  580. * @param initParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
  581. * @param topStack [IN] Type #VOID * Parameter for task's top of stack address.
  582. *
  583. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL.
  584. * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL.
  585. * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
  586. * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
  587. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
  588. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
  589. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
  590. * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
  591. * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
  592. * @retval #LOS_OK The task is successfully created.
  593. * @par Dependency:
  594. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  595. * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
  596. * @see LOS_TaskCreateOnlyStatic | LOS_TaskDeleteStatic
  597. * @since Huawei LiteOS V200R005C10
  598. */
  599. extern UINT32 LOS_TaskCreateStatic(UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID *topStack);
  600. #endif
  601. /**
  602. * @ingroup los_task
  603. * @brief Create a task and suspend.
  604. *
  605. * @par Description:
  606. * This API is used to create a task and suspend it. This task will not be added to the queue of ready tasks
  607. * before resume it.
  608. *
  609. * @attention
  610. * <ul>
  611. * <li>During task creation, the task control block and task stack of the task that is previously automatically deleted
  612. * are deallocated.</li>
  613. * <li>The task name is a pointer and is not allocated memory.</li>
  614. * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
  615. * to specify the default task stack size. The stack size should be a reasonable value, if the size is too large, may
  616. * cause memory exhaustion.</li>
  617. * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
  618. * enough to avoid task stack overflow.</li>
  619. * <li>Less parameter value indicates higher task priority.</li>
  620. * <li>The task name cannot be null.</li>
  621. * <li>The pointer to the task executing function cannot be null.</li>
  622. * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
  623. * abnormal.</li>
  624. * </ul>
  625. *
  626. * @param taskId [OUT] Type #UINT32 * Task ID.
  627. * @param initParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
  628. *
  629. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param taskId is NULL.
  630. * @retval #LOS_ERRNO_TSK_PTR_NULL Param initParam is NULL.
  631. * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
  632. * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
  633. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
  634. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
  635. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
  636. * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
  637. * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
  638. * @retval #LOS_OK The task is successfully created.
  639. * @par Dependency:
  640. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  641. * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
  642. * @see LOS_TaskDelete | LOS_TaskCreate
  643. * @since Huawei LiteOS V100R001C00
  644. */
  645. extern UINT32 LOS_TaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S *initParam);
  646. /**
  647. * @ingroup los_task
  648. * @brief Create a task.
  649. *
  650. * @par Description:
  651. * This API is used to create a task. If the priority of the task created after system initialized is higher than
  652. * the current task and task scheduling is not locked, it is scheduled for running.
  653. * If not, the created task is added to the queue of ready tasks.
  654. *
  655. * @attention
  656. * <ul>
  657. * <li>During task creation, the task control block and task stack of the task that is previously automatically
  658. * deleted are deallocated.</li>
  659. * <li>The task name is a pointer and is not allocated memory.</li>
  660. * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
  661. * to specify the default task stack size.</li>
  662. * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
  663. * enough to avoid task stack overflow.</li>
  664. * <li>Less parameter value indicates higher task priority.</li>
  665. * <li>The task name cannot be null.</li>
  666. * <li>The pointer to the task executing function cannot be null.</li>
  667. * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
  668. * abnormal.</li>
  669. * </ul>
  670. *
  671. * @param taskId [OUT] Type #UINT32 * Task ID.
  672. * @param initParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
  673. *
  674. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param taskId is NULL.
  675. * @retval #LOS_ERRNO_TSK_PTR_NULL Param initParam is NULL.
  676. * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
  677. * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
  678. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
  679. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
  680. * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
  681. * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
  682. * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
  683. * @retval #LOS_OK The task is successfully created.
  684. * @par Dependency:
  685. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  686. * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
  687. * @see LOS_TaskDelete | LOS_TaskCreateOnly
  688. * @since Huawei LiteOS V100R001C00
  689. */
  690. extern UINT32 LOS_TaskCreate(UINT32 *taskId, TSK_INIT_PARAM_S *initParam);
  691. /**
  692. * @ingroup los_task
  693. * @brief Resume a task.
  694. *
  695. * @par Description:
  696. * This API is used to resume a suspended task.
  697. *
  698. * @attention
  699. * <ul>
  700. * <li>If the task is delayed or blocked, resume the task without adding it to the queue of ready tasks.</li>
  701. * <li>If the priority of the task resumed after system initialized is higher than the current task and task scheduling
  702. * is not locked, it is scheduled for running.</li>
  703. * </ul>
  704. *
  705. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  706. *
  707. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
  708. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  709. * @retval #LOS_ERRNO_TSK_NOT_SUSPENDED The task is not suspended.
  710. * @retval #LOS_OK The task is successfully resumed.
  711. * @par Dependency:
  712. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  713. * @see LOS_TaskSuspend
  714. * @since Huawei LiteOS V100R001C00
  715. */
  716. extern UINT32 LOS_TaskResume(UINT32 taskId);
  717. /**
  718. * @ingroup los_task
  719. * @brief Suspend a task.
  720. *
  721. * @par Description:
  722. * This API is used to suspend a specified task, and the task will be removed from the queue of ready tasks.
  723. *
  724. * @attention
  725. * <ul>
  726. * <li>The task that is running and locked cannot be suspended.</li>
  727. * <li>The idle task and swtmr task cannot be suspended.</li>
  728. * </ul>
  729. *
  730. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  731. *
  732. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
  733. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK Check the task ID and do not operate the system-level
  734. * task, like idle or swtmr task.
  735. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  736. * @retval #LOS_ERRNO_TSK_ALREADY_SUSPENDED The task is already suspended.
  737. * @retval #LOS_ERRNO_TSK_SUSPEND_LOCKED The task being suspended is current task and task
  738. * scheduling is locked.
  739. * @retval #LOS_OK The task is successfully suspended.
  740. * @par Dependency:
  741. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  742. * @see LOS_TaskResume
  743. * @since Huawei LiteOS V100R001C00
  744. */
  745. extern UINT32 LOS_TaskSuspend(UINT32 taskId);
  746. /**
  747. * @ingroup los_task
  748. * @brief Delete a task.
  749. *
  750. * @par Description:
  751. * This API is used to delete a specified task and release the resources for its task stack and task control block.
  752. *
  753. * @attention
  754. * <ul>
  755. * <li>The idle task and swtmr task cannot be deleted.</li>
  756. * <li>If delete current task maybe cause unexpected error.</li>
  757. * <li>If a task get a mutex is deleted or automatically deleted before release this mutex, other tasks pended
  758. * this mutex maybe never be shchduled.</li>
  759. * </ul>
  760. *
  761. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  762. *
  763. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
  764. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK Check the task ID and do not operate the system-level
  765. * task, like idle or swtmr task.
  766. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  767. * @retval #LOS_ERRNO_TSK_DELETE_LOCKED The task being deleted is current task and task scheduling
  768. * is locked.
  769. * @retval #LOS_OK The task is successfully deleted.
  770. * @par Dependency:
  771. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  772. * @see LOS_TaskCreate | LOS_TaskCreateOnly
  773. * @since Huawei LiteOS V100R001C00
  774. */
  775. extern UINT32 LOS_TaskDelete(UINT32 taskId);
  776. /**
  777. * @ingroup los_task
  778. * @brief Delay a task.
  779. *
  780. * @par Description:
  781. * This API is used to delay the execution of the current task. The task is able to be scheduled after it is delayed
  782. * for a specified number of Ticks.
  783. *
  784. * @attention
  785. * <ul>
  786. * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
  787. * <li>If 0 is passed in and the task scheduling is not locked, execute the next task in the queue of tasks with
  788. * the same priority of the current task.
  789. * If no ready task with the priority of the current task is available, the task scheduling will not occur, and the
  790. * current task continues to be executed.</li>
  791. * <li>Using the interface before system initialized is not allowed.</li>
  792. * <li>DO NOT call this API in software timer callback. </li>
  793. * </ul>
  794. *
  795. * @param tick [IN] Type #UINT32 Number of Ticks for which the task is delayed.
  796. *
  797. * @retval #LOS_ERRNO_TSK_DELAY_IN_INT The task delay occurs during an interrupt.
  798. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK The current task is a system-level task, like idle or swtmr
  799. * task. This is not allowed.
  800. * @retval #LOS_ERRNO_TSK_DELAY_IN_LOCK The task delay occurs when the task scheduling is locked.
  801. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
  802. * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling.
  803. * @retval #LOS_OK The task is successfully delayed.
  804. * @par Dependency:
  805. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  806. * @since Huawei LiteOS V100R001C00
  807. */
  808. extern UINT32 LOS_TaskDelay(UINT32 tick);
  809. /**
  810. * @ingroup los_task
  811. * @brief Lock the task scheduling.
  812. *
  813. * @par Description:
  814. * This API is used to lock the task scheduling. Task switching will not occur if the task scheduling is locked.
  815. *
  816. * @attention
  817. * <ul>
  818. * <li>If the task scheduling is locked, but interrupts are not disabled, tasks are still able to be interrupted.</li>
  819. * <li>One is added to the number of task scheduling locks if this API is called. The number of locks is decreased by
  820. * one if the task scheduling is unlocked. Therefore, this API should be used together with LOS_TaskUnlock.</li>
  821. * </ul>
  822. *
  823. * @param None.
  824. *
  825. * @retval None.
  826. * @par Dependency:
  827. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  828. * @see LOS_TaskUnlock
  829. * @since Huawei LiteOS V100R001C00
  830. */
  831. extern VOID LOS_TaskLock(VOID);
  832. /**
  833. * @ingroup los_task
  834. * @brief Unlock the task scheduling.
  835. *
  836. * @par Description:
  837. * This API is used to unlock the task scheduling. Calling this API will decrease the number of task locks by one.
  838. * If a task is locked more than once, the task scheduling will be unlocked only when the number of locks becomes zero.
  839. *
  840. * @attention
  841. * The number of locks is decreased by one if this API is called. One is added to the number of task scheduling
  842. * locks if the task scheduling is locked. Therefore, this API should be used together with LOS_TaskLock.
  843. *
  844. * @param None.
  845. *
  846. * @retval None.
  847. * @par Dependency:
  848. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  849. * @see LOS_TaskLock
  850. * @since Huawei LiteOS V100R001C00
  851. */
  852. extern VOID LOS_TaskUnlock(VOID);
  853. /**
  854. * @ingroup los_task
  855. * @brief Set a task priority.
  856. *
  857. * @par Description:
  858. * This API is used to set the priority of a specified task.
  859. *
  860. * @attention
  861. * <ul>
  862. * <li>If the set priority is higher than the priority of the current running task, task scheduling
  863. * probably occurs.</li>
  864. * <li>Changing the priority of the current running task also probably causes task scheduling.</li>
  865. * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
  866. * <li>Using the interface in the interrupt is not allowed.</li>
  867. * </ul>
  868. *
  869. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  870. * @param taskPrio [IN] Type #UINT16 Task priority.
  871. *
  872. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority
  873. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
  874. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK Check the task ID and do not operate the system-level
  875. * task, like idle or swtmr task.
  876. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  877. * @retval #LOS_OK The priority of the current running task is successfully
  878. * set to a specified priority.
  879. * @par Dependency:
  880. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  881. * @see LOS_TaskPriGet
  882. * @since Huawei LiteOS V100R001C00
  883. */
  884. extern UINT32 LOS_TaskPriSet(UINT32 taskId, UINT16 taskPrio);
  885. /**
  886. * @ingroup los_task
  887. * @brief Set the priority of the current running task to a specified priority.
  888. *
  889. * @par Description:
  890. * This API is used to set the priority of the current running task to a specified priority.
  891. *
  892. * @attention
  893. * <ul>
  894. * <li>Changing the priority of the current running task probably causes task scheduling.</li>
  895. * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
  896. * <li>Using the interface in the interrupt is not allowed.</li>
  897. * </ul>
  898. *
  899. * @param taskPrio [IN] Type #UINT16 Task priority.
  900. *
  901. * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority.
  902. * @retval #LOS_ERRNO_TSK_ID_INVALID The current task ID is invalid.
  903. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK The current task is a system-level task, like idle or swtmr
  904. * task. This is not allowed.
  905. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  906. * @retval #LOS_OK The priority of the current running task is successfully set
  907. * to a specified priority.
  908. * @par Dependency:
  909. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  910. * @see LOS_TaskPriSet | LOS_TaskPriGet
  911. * @since Huawei LiteOS V100R001C00
  912. */
  913. extern UINT32 LOS_CurTaskPriSet(UINT16 taskPrio);
  914. /**
  915. * @ingroup los_task
  916. * @brief Change the scheduling sequence of tasks with the same priority.
  917. *
  918. * @par Description:
  919. * This API is used to move current task in a queue of tasks with the same priority to the tail of the queue of ready
  920. * tasks.
  921. *
  922. * @attention
  923. * At least two ready tasks need to be included in the queue of ready tasks with the same priority. If the
  924. * less than two ready tasks are included in the queue, an error is reported.
  925. *
  926. * @param None.
  927. *
  928. * @retval #LOS_ERRNO_TSK_YIELD_IN_INT The task yield occurs during an interrupt.
  929. * @retval #LOS_ERRNO_TSK_YIELD_IN_LOCK The task yield occurs when the task is locked.
  930. * @retval #LOS_ERRNO_TSK_ID_INVALID The current task ID is invalid.
  931. * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling.
  932. * @retval #LOS_OK The scheduling sequence of tasks with same priority is
  933. * successfully changed.
  934. * @par Dependency:
  935. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  936. * @since Huawei LiteOS V100R001C00
  937. */
  938. extern UINT32 LOS_TaskYield(VOID);
  939. /**
  940. * @ingroup los_task
  941. * @brief Obtain a task priority.
  942. *
  943. * @par Description:
  944. * This API is used to obtain the priority of a specified task.
  945. *
  946. * @attention None.
  947. *
  948. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  949. *
  950. * @retval #OS_INVALID Fails to obtain the task priority.
  951. * @retval #UINT16 The task priority.
  952. * @par Dependency:
  953. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  954. * @see LOS_TaskPriSet
  955. * @since Huawei LiteOS V100R001C00
  956. */
  957. extern UINT16 LOS_TaskPriGet(UINT32 taskId);
  958. /**
  959. * @ingroup los_task
  960. * @brief Obtain current running task ID.
  961. *
  962. * @par Description:
  963. * This API is used to obtain the ID of current running task.
  964. *
  965. * @attention
  966. * This interface should not be called before system initialized.
  967. *
  968. * @retval #LOS_ERRNO_TSK_ID_INVALID Can not get current running task.
  969. * @retval #UINT32 Task ID.
  970. * @par Dependency:
  971. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  972. * @since Huawei LiteOS V100R001C00
  973. */
  974. extern UINT32 LOS_CurTaskIDGet(VOID);
  975. /**
  976. * @ingroup los_task
  977. * @brief Obtain a task information structure.
  978. *
  979. * @par Description:
  980. * This API is used to obtain a task information structure.
  981. *
  982. * @attention
  983. * One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may be
  984. * abnormal.
  985. *
  986. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  987. * @param taskInfo [OUT] Type #TSK_INFO_S* Pointer to the task information structure to be obtained.
  988. *
  989. * @retval #LOS_ERRNO_TSK_PTR_NULL Null parameter.
  990. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid task ID.
  991. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  992. * @retval #LOS_OK The task information structure is successfully obtained.
  993. * @par Dependency:
  994. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  995. * @since Huawei LiteOS V100R001C00
  996. */
  997. extern UINT32 LOS_TaskInfoGet(UINT32 taskId, TSK_INFO_S *taskInfo);
  998. /**
  999. * @ingroup los_task
  1000. * @brief Set the affinity mask of the task scheduling cpu.
  1001. *
  1002. * @par Description:
  1003. * This API is used to set the affinity mask of the task scheduling cpu.
  1004. *
  1005. * @attention
  1006. * If any low #LOSCFG_KERNEL_CORE_NUM bit of the mask is not set or the system task is set, an error is reported.
  1007. *
  1008. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  1009. * @param usCpuAffiMask [IN] Type #UINT16 The scheduling cpu mask.The low to high bit of the mask corresponds to
  1010. * the cpu number, the high bit that exceeding the CPU number is ignored.
  1011. *
  1012. * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid task ID.
  1013. * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
  1014. * @retval #LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR The task cpu affinity mask is incorrect.
  1015. * @retval #LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK The task is system task.
  1016. * @retval #LOS_OK The task cpu affinity mask is successfully set.
  1017. * @par Dependency:
  1018. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1019. * @see LOS_TaskCpuAffiGet
  1020. * @since Huawei LiteOS V200R003C00
  1021. */
  1022. extern UINT32 LOS_TaskCpuAffiSet(UINT32 taskId, UINT16 usCpuAffiMask);
  1023. /**
  1024. * @ingroup los_task
  1025. * @brief Get the affinity mask of the task scheduling cpu.
  1026. *
  1027. * @par Description:
  1028. * This API is used to get the affinity mask of the task scheduling cpu.
  1029. *
  1030. * @attention None.
  1031. *
  1032. * @param taskId [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
  1033. *
  1034. * @retval 0 Fail to obtain the cpu affinity mask.
  1035. * @retval #UINT16 The scheduling cpu mask. The low to high bit of the mask corresponds to the cpu number.
  1036. * @par Dependency:
  1037. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1038. * @see LOS_TaskCpuAffiSet
  1039. * @since Huawei LiteOS V200R003C00
  1040. */
  1041. extern UINT16 LOS_TaskCpuAffiGet(UINT32 taskId);
  1042. /**
  1043. * @ingroup los_task
  1044. * @brief Recycle task stack resource.
  1045. *
  1046. * @par Description:
  1047. * This API is used to recycle task stack resource.
  1048. *
  1049. * @attention None.
  1050. *
  1051. * @param None.
  1052. *
  1053. * @retval None.
  1054. * @par Dependency:
  1055. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1056. * @see None.
  1057. * @since Huawei LiteOS V200R003C00
  1058. */
  1059. extern VOID LOS_TaskResRecycle(VOID);
  1060. #ifdef LOSCFG_OBSOLETE_API
  1061. #define LOS_TASK_PARAM_INIT_ARG_0(initParam, arg) \
  1062. initParam.auwArgs[0] = (UINTPTR)arg
  1063. #define LOS_TASK_PARAM_INIT_ARG(initParam, arg) LOS_TASK_PARAM_INIT_ARG_0(initParam, arg)
  1064. #else
  1065. #define LOS_TASK_PARAM_INIT_ARG(initParam, arg) \
  1066. initParam.pArgs = (VOID *)arg
  1067. #endif
  1068. /**
  1069. * @ingroup los_task
  1070. * @brief Define the lowpower framework process function type.
  1071. *
  1072. * @par Description:
  1073. * This API is used to define the lowpower framework entry function type.
  1074. *
  1075. * @attention None.
  1076. *
  1077. * @param None.
  1078. *
  1079. * @retval None.
  1080. * @par Dependency:
  1081. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1082. * @see None.
  1083. * @since Huawei LiteOS V200R005C10
  1084. */
  1085. typedef VOID (*LOWPOWERIDLEHOOK)(VOID);
  1086. /**
  1087. * @ingroup los_task
  1088. * @brief Register a hook to enter lowpower framework process.
  1089. *
  1090. * @par Description:
  1091. * This API is used to register lowpower framework entry function.
  1092. *
  1093. * @attention None.
  1094. *
  1095. * @param hook [IN] The lowpower framework hook.
  1096. *
  1097. * @retval None.
  1098. * @par Dependency:
  1099. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1100. * @see None.
  1101. * @since Huawei LiteOS V200R005C10
  1102. */
  1103. extern VOID LOS_LowpowerHookReg(LOWPOWERIDLEHOOK hook);
  1104. /**
  1105. * @ingroup los_task
  1106. * @brief Define the type of idle handler hook function.
  1107. *
  1108. * @par Description:
  1109. * This API is used to define the type of idle handler hook function.
  1110. * @attention None.
  1111. *
  1112. * @param None.
  1113. *
  1114. * @retval None.
  1115. * @par Dependency:
  1116. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1117. * @since Huawei LiteOS V200R005C20
  1118. */
  1119. typedef VOID (*IDLEHANDLERHOOK)(VOID);
  1120. /**
  1121. * @ingroup los_task
  1122. * @brief Register the hook function for idle task.
  1123. *
  1124. * @par Description:
  1125. * This API is used to register a hook function called when system idle.
  1126. *
  1127. * @attention The hook will be called when system idle.
  1128. *
  1129. * @param None.
  1130. *
  1131. * @retval None.
  1132. * @par Dependency:
  1133. * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
  1134. * @see None.
  1135. * @since Huawei LiteOS V200R005C20
  1136. */
  1137. extern VOID LOS_IdleHandlerHookReg(IDLEHANDLERHOOK hook);
  1138. #ifdef __cplusplus
  1139. #if __cplusplus
  1140. }
  1141. #endif /* __cplusplus */
  1142. #endif /* __cplusplus */
  1143. #endif /* _LOS_TASK_H */