1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2015. All rights reserved. 3 * Description: LiteOS Task Module Implementation 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 9 * of conditions and the following disclaimer in the documentation and/or other materials 10 * provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 12 * to endorse or promote products derived from this software without specific prior written 13 * permission. 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * --------------------------------------------------------------------------- */ 26 27 /** 28 * @defgroup los_task Task 29 * @ingroup kernel 30 */ 31 32 #ifndef _LOS_TASK_H 33 #define _LOS_TASK_H 34 35 #include "los_base.h" 36 #include "los_list.h" 37 #include "los_sys.h" 38 #include "los_tick.h" 39 #include "los_event.h" 40 #include "los_err.h" 41 42 #ifdef __cplusplus 43 #if __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 #endif /* __cplusplus */ 47 48 /** 49 * @ingroup los_task 50 * Task error code: Insufficient memory for task creation. 51 * 52 * Value: 0x03000200 53 * 54 * Solution: Allocate bigger memory partition to task creation. 55 */ 56 #define LOS_ERRNO_TSK_NO_MEMORY LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x00) 57 58 /** 59 * @ingroup los_task 60 * Task error code: Null parameter. 61 * 62 * Value: 0x02000201 63 * 64 * Solution: Check the parameter. 65 */ 66 #define LOS_ERRNO_TSK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x01) 67 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 /** 79 * @ingroup los_task 80 * Task error code: Incorrect task priority. 81 * 82 * Value: 0x02000203 83 * 84 * Solution: Re-configure the task priority by referring to the priority range. 85 */ 86 #define LOS_ERRNO_TSK_PRIOR_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x03) 87 88 /** 89 * @ingroup los_task 90 * Task error code: The task entrance is NULL. 91 * 92 * Value: 0x02000204 93 * 94 * Solution: Define the task entrance function. 95 */ 96 #define LOS_ERRNO_TSK_ENTRY_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x04) 97 98 /** 99 * @ingroup los_task 100 * Task error code: The task name is NULL. 101 * 102 * Value: 0x02000205 103 * 104 * Solution: Set the task name. 105 */ 106 #define LOS_ERRNO_TSK_NAME_EMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x05) 107 108 /** 109 * @ingroup los_task 110 * Task error code: The task stack size is too small. 111 * 112 * Value: 0x02000206 113 * 114 * Solution: Expand the task stack. 115 */ 116 #define LOS_ERRNO_TSK_STKSZ_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x06) 117 118 /** 119 * @ingroup los_task 120 * Task error code: Invalid task ID. 121 * 122 * Value: 0x02000207 123 * 124 * Solution: Check the task ID. 125 */ 126 #define LOS_ERRNO_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x07) 127 128 /** 129 * @ingroup los_task 130 * Task error code: The task is already suspended. 131 * 132 * Value: 0x02000208 133 * 134 * Solution: Suspend the task after it is resumed. 135 */ 136 #define LOS_ERRNO_TSK_ALREADY_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x08) 137 138 /** 139 * @ingroup los_task 140 * Task error code: The task is not suspended. 141 * 142 * Value: 0x02000209 143 * 144 * Solution: Suspend the task. 145 */ 146 #define LOS_ERRNO_TSK_NOT_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x09) 147 148 /** 149 * @ingroup los_task 150 * Task error code: The task is not created. 151 * 152 * Value: 0x0200020a 153 * 154 * Solution: Create the task. 155 */ 156 #define LOS_ERRNO_TSK_NOT_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0a) 157 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 */ 166 #define LOS_ERRNO_TSK_MSG_NONZERO LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0c) 167 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 /** 179 * @ingroup los_task 180 * Task error code: The task delay occurs when the task is locked. 181 * 182 * Value: 0x0200020e 183 * 184 * Solution: Perform this operation after unlocking the task. 185 */ 186 #define LOS_ERRNO_TSK_DELAY_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0e) 187 188 /** 189 * @ingroup los_task 190 * Task error code: The task that is being scheduled is invalid. 191 * 192 * Value: 0x0200020f 193 * 194 * Solution: Check the task. 195 */ 196 #define LOS_ERRNO_TSK_YIELD_INVALID_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0f) 197 198 /** 199 * @ingroup los_task 200 * Task error code: Only one task or no task is available for scheduling. 201 * 202 * Value: 0x02000210 203 * 204 * Solution: Increase the number of tasks. 205 */ 206 #define LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x10) 207 208 /** 209 * @ingroup los_task 210 * Task error code: No free task control block is available. 211 * 212 * Value: 0x02000211 213 * 214 * Solution: Increase the number of task control blocks. 215 */ 216 #define LOS_ERRNO_TSK_TCB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x11) 217 218 /** 219 * @ingroup los_task 220 * Task error code: The task hook function is not matchable. 221 * 222 * Value: 0x02000212 223 * 224 * Solution: This error code is not in use temporarily. 225 */ 226 #define LOS_ERRNO_TSK_HOOK_NOT_MATCH LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x12) 227 228 /** 229 * @ingroup los_task 230 * Task error code: The number of task hook functions exceeds the permitted upper limit. 231 * 232 * Value: 0x02000213 233 * 234 * Solution: This error code is not in use temporarily. 235 */ 236 #define LOS_ERRNO_TSK_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x13) 237 238 /** 239 * @ingroup los_task 240 * Task error code: The operation is performed on the idle task. 241 * 242 * Value: 0x02000214 243 * 244 * Solution: Check the task ID and do not operate on the idle task. 245 */ 246 #define LOS_ERRNO_TSK_OPERATE_IDLE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x14) 247 248 /** 249 * @ingroup los_task 250 * Task error code: The task that is being suspended is locked. 251 * 252 * Value: 0x03000215 253 * 254 * Solution: Suspend the task after unlocking the task. 255 */ 256 #define LOS_ERRNO_TSK_SUSPEND_LOCKED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x15) 257 258 /** 259 * @ingroup los_task 260 * Task error code: The task stack fails to be freed. 261 * 262 * Value: 0x02000217 263 * 264 * Solution: This error code is not in use temporarily. 265 */ 266 #define LOS_ERRNO_TSK_FREE_STACK_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x17) 267 268 /** 269 * @ingroup los_task 270 * Task error code: The task stack area is too small. 271 * 272 * Value: 0x02000218 273 * 274 * Solution: This error code is not in use temporarily. 275 */ 276 #define LOS_ERRNO_TSK_STKAREA_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x18) 277 278 /** 279 * @ingroup los_task 280 * Task error code: The task fails to be activated. 281 * 282 * Value: 0x03000219 283 * 284 * Solution: Perform task switching after creating an idle task. 285 */ 286 #define LOS_ERRNO_TSK_ACTIVE_FAILED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x19) 287 288 /** 289 * @ingroup los_task 290 * Task error code: Too many task configuration items. 291 * 292 * Value: 0x0200021a 293 * 294 * Solution: This error code is not in use temporarily. 295 */ 296 #define LOS_ERRNO_TSK_CONFIG_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1a) 297 298 /** 299 * @ingroup los_task 300 * Task error code: 301 * 302 * Value: 0x0200021b 303 * 304 * Solution: This error code is not in use temporarily. 305 */ 306 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NOT_ALIGN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1b) 307 308 /** 309 * @ingroup los_task 310 * Task error code: 311 * 312 * Value: 0x0200021d 313 * 314 * Solution: This error code is not in use temporarily. 315 */ 316 #define LOS_ERRNO_TSK_MSG_Q_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1d) 317 318 /** 319 * @ingroup los_task 320 * Task error code: 321 * 322 * Value: 0x0200021e 323 * 324 * Solution: This error code is not in use temporarily. 325 */ 326 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1e) 327 328 /** 329 * @ingroup los_task 330 * Task error code: 331 * 332 * Value: 0x0200021f 333 * 334 * Solution: This error code is not in use temporarily. 335 */ 336 #define LOS_ERRNO_TSK_SELF_DELETE_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1f) 337 338 /** 339 * @ingroup los_task 340 * Task error code: The task stack size is too large. 341 * 342 * Value: 0x02000220 343 * 344 * Solution: shrink the task stack size parameter. 345 */ 346 #define LOS_ERRNO_TSK_STKSZ_TOO_LARGE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x20) 347 348 /** 349 * @ingroup los_task 350 * Task error code: Suspending software timer task is not allowed. 351 * 352 * Value: 0x02000221 353 * 354 * Solution: Check the task ID and do not suspend software timer task. 355 */ 356 #define LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x21) 357 358 /** 359 * @ingroup los_task 360 * Task error code: The operation is performed on the software timer task. 361 * 362 * Value: 0x02000222 363 * 364 * Solution: Check the task ID and do not operate on the software timer task. 365 */ 366 #define LOS_ERRNO_TSK_OPERATE_SWTMR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x22) 367 368 /** 369 * @ingroup los_task 370 * Task error code: The task stack pointer is error. 371 * 372 * Value: 0x02000223 373 * 374 * Solution: Check the task stack pointer. 375 */ 376 #define LOS_ERRNO_TSK_STACK_POINTER_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x23) 377 378 /** 379 * @ingroup los_task 380 * Define the type of the task switching hook function. 381 * 382 */ 383 typedef VOID (*TSKSWITCHHOOK)(VOID); 384 385 /** 386 * @ingroup los_task 387 * User task switching hook function. 388 * 389 */ 390 extern TSKSWITCHHOOK g_pfnUsrTskSwitchHook; 391 392 /** 393 * @ingroup los_task 394 * @brief Define the type of a task entrance function. 395 * 396 * @par Description: 397 * This API is used to define the type of a task entrance function and call it after a task is created and triggered. 398 * @attention None. 399 * 400 * @param param1 [IN] Type #UINT32 The first parameter passed to the task handling function. 401 * @param param2 [IN] Type #UINT32 The second parameter passed to the task handling function. 402 * @param param3 [IN] Type #UINT32 The third parameter passed to the task handling function. 403 * @param param4 [IN] Type #UINT32 The fourth parameter passed to the task handling function. 404 * 405 * @retval None. 406 * @par Dependency: 407 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 408 * @see 409 */ 410 typedef VOID *(*TSK_ENTRY_FUNC)(UINT32 param1, UINT32 param2, UINT32 param3, UINT32 param4); 411 #define LOS_TASK_STATUS_DETACHED 0x0100 412 413 #define LOS_TASK_ARG_NUM 4 414 /** 415 * @ingroup los_task 416 * Define the structure of the parameters used for task creation. 417 * 418 * Information of specified parameters passed in during task creation. 419 */ 420 typedef struct tagTskInitParam { 421 TSK_ENTRY_FUNC pfnTaskEntry; /**< Task entrance function */ 422 UINT16 usTaskPrio; /**< Task priority */ 423 UINT32 auwArgs[LOS_TASK_ARG_NUM]; /**< Task parameters */ 424 UINT32 uwStackSize; /**< Task stack size */ 425 CHAR *pcName; /**< Task name */ 426 UINT32 uwResved; /**< Reserved */ 427 } TSK_INIT_PARAM_S; 428 429 /** 430 * @ingroup los_task 431 * Task name length 432 * 433 */ 434 #define LOS_TASK_NAMELEN 32 435 436 /** 437 * @ingroup los_task 438 * Task information structure. 439 * 440 */ 441 typedef struct tagTskInfo { 442 CHAR acName[LOS_TASK_NAMELEN]; /**< Task entrance function */ 443 UINT32 uwTaskID; /**< Task ID */ 444 UINT16 usTaskStatus; /**< Task status */ 445 UINT16 usTaskPrio; /**< Task priority */ 446 VOID *pTaskSem; /**< Semaphore pointer */ 447 VOID *pTaskMux; /**< Mutex pointer */ 448 EVENT_CB_S uwEvent; /**< Event */ 449 UINT32 uwEventMask; /**< Event mask */ 450 UINT32 uwStackSize; /**< Task stack size */ 451 UINT32 uwTopOfStack; /**< Task stack top */ 452 UINT32 uwBottomOfStack; /**< Task stack bottom */ 453 UINT32 mstatus; /**< Task current mstatus */ 454 UINT32 mepc; /**< Task current mepc */ 455 UINT32 tp; /**< Task current tp */ 456 UINT32 ra; /**< Task current ra */ 457 UINT32 uwSP; /**< Task SP pointer */ 458 UINT32 uwCurrUsed; /**< Current task stack usage */ 459 UINT32 uwPeakUsed; /**< Task stack usage peak */ 460 BOOL bOvf; /**< Flag that indicates whether a task stack overflow occurs */ 461 } TSK_INFO_S; 462 463 /** 464 * @ingroup los_task 465 * @brief Create a task and suspend. 466 * 467 * @par Description: 468 * This API is used to create a task and suspend it. This task will not be added to the queue of ready tasks before 469 * resume it. 470 * 471 * @attention 472 * <ul> 473 * <li>During task creation, the task control block and task stack of the task that is previously automatically deleted 474 * are deallocated.</li> 475 * <li>The task name is a pointer and is not allocated memory.</li> 476 * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE 477 * to specify the default task stack size. The stack size should be a reasonable value, if the size is too large, may 478 * cause memory exhaustion.</li> 479 * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big 480 * enough to avoid task stack overflow.</li> 481 * <li>Less parameter value indicates higher task priority.</li> 482 * <li>The task name cannot be null.</li> 483 * <li>The pointer to the task executing function cannot be null.</li> 484 * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be 485 * abnormal.</li> 486 * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer, 487 * uwStackSize remain as the kernel stack size.</li> 488 * </ul> 489 * 490 * @param taskID [OUT] Type #UINT32 * Task ID. 491 * @param taskInitParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation. 492 * 493 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL. 494 * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL. 495 * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL. 496 * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL. 497 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority. 498 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large. 499 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small. 500 * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available. 501 * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation. 502 * @retval #LOS_OK The task is successfully created. 503 * @par Dependency: 504 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 505 * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul> 506 * @see LOS_TaskDelete 507 */ 508 extern UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S *taskInitParam); 509 510 /** 511 * @ingroup los_task 512 * @brief Create a task. 513 * 514 * @par Description: 515 * This API is used to create a task. If the priority of the task created after system initialized is higher than 516 * the current task and task scheduling is not locked, it is scheduled for running. 517 * If not, the created task is added to the queue of ready tasks. 518 * 519 * @attention 520 * <ul> 521 * <li>During task creation, the task control block and task stack of the task that is previously automatically 522 * deleted are deallocated.</li> 523 * <li>The task name is a pointer and is not allocated memory.</li> 524 * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE 525 * to specify the default task stack size.</li> 526 * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big 527 * enough to avoid task stack overflow.</li> 528 * <li>Less parameter value indicates higher task priority.</li> 529 * <li>The task name cannot be null.</li> 530 * <li>The pointer to the task executing function cannot be null.</li> 531 * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be 532 * abnormal.</li> 533 * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer, 534 * uwStackSize remain as the kernel stack size.</li> 535 * </ul> 536 * 537 * @param taskID [OUT] Type #UINT32 * Task ID. 538 * @param taskInitParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation. 539 * 540 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL. 541 * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL. 542 * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL. 543 * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL. 544 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority. 545 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large. 546 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small. 547 * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available. 548 * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation. 549 * @retval #LOS_OK The task is successfully created. 550 * @par Dependency: 551 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 552 * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul> 553 * @see LOS_TaskDelete 554 */ 555 extern UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *taskInitParam); 556 557 /** 558 * @ingroup los_task 559 * @brief Resume a task. 560 * 561 * @par Description: 562 * This API is used to resume a suspended task. 563 * 564 * @attention 565 * <ul> 566 * <li>If the task is delayed or blocked, resume the task without adding it to the queue of ready tasks.</li> 567 * <li>If the priority of the task resumed after system initialized is higher than the current task and task scheduling 568 * is not locked, it is scheduled for running.</li> 569 * </ul> 570 * 571 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 572 * 573 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 574 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 575 * @retval #LOS_ERRNO_TSK_NOT_SUSPENDED The task is not suspended. 576 * @retval #LOS_OK The task is successfully resumed. 577 * @par Dependency: 578 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 579 * @see LOS_TaskSuspend 580 */ 581 extern UINT32 LOS_TaskResume(UINT32 taskID); 582 583 /** 584 * @ingroup los_task 585 * @brief Suspend a task. 586 * 587 * @par Description: 588 * This API is used to suspend a specified task, and the task will be removed from the queue of ready tasks. 589 * 590 * @attention 591 * <ul> 592 * <li>The task that is running and locked cannot be suspended.</li> 593 * <li>The idle task and swtmr task cannot be suspended.</li> 594 * </ul> 595 * 596 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 597 * 598 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task. 599 * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED Check the task ID and do not operate on the swtmr task. 600 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 601 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 602 * @retval #LOS_ERRNO_TSK_ALREADY_SUSPENDED The task is already suspended. 603 * @retval #LOS_ERRNO_TSK_SUSPEND_LOCKED The task being suspended is current task and task scheduling 604 * is locked. 605 * @retval #LOS_OK The task is successfully suspended. 606 * @par Dependency: 607 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 608 * @see LOS_TaskResume 609 */ 610 extern UINT32 LOS_TaskSuspend(UINT32 taskID); 611 612 /** 613 * @ingroup los_task 614 * @brief Delete a task. 615 * 616 * @par Description: 617 * This API is used to delete a specified task and release the resources for its task stack and task control block. 618 * 619 * @attention 620 * <ul> 621 * <li>The idle task and swtmr task cannot be deleted.</li> 622 * <li>If delete current task maybe cause unexpected error.</li> 623 * <li>If a task get a mutex is deleted or automatically deleted before release this mutex, other tasks pended 624 * this mutex maybe never be shchduled.</li> 625 * </ul> 626 * 627 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 628 * 629 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task. 630 * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED Check the task ID and do not operate on the swtmr task. 631 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 632 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 633 * @retval #LOS_OK The task is successfully deleted. 634 * @par Dependency: 635 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 636 * @see LOS_TaskCreate | LOS_TaskCreateOnly 637 */ 638 extern UINT32 LOS_TaskDelete(UINT32 taskID); 639 640 /** 641 * @ingroup los_task 642 * @brief Delay a task. 643 * 644 * @par Description: 645 * This API is used to delay the execution of the current task. The task is able to be scheduled after it is delayed 646 * for a specified number of Ticks. 647 * 648 * @attention 649 * <ul> 650 * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li> 651 * <li>If 0 is passed in and the task scheduling is not locked, execute the next task in the queue of tasks with 652 * the same priority of the current task. 653 * If no ready task with the priority of the current task is available, the task scheduling will not occur, and the 654 * current task continues to be executed.</li> 655 * <li>Using the interface before system initialized is not allowed.</li> 656 * </ul> 657 * 658 * @param tick [IN] Type #UINT32 Number of Ticks for which the task is delayed. 659 * 660 * @retval #LOS_ERRNO_TSK_DELAY_IN_INT The task delay occurs during an interrupt. 661 * @retval #LOS_ERRNO_TSK_DELAY_IN_LOCK The task delay occurs when the task scheduling is locked. 662 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 663 * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling. 664 * @retval #LOS_OK The task is successfully delayed. 665 * @par Dependency: 666 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 667 * @see 668 */ 669 extern UINT32 LOS_TaskDelay(UINT32 tick); 670 671 /** 672 * @ingroup los_task 673 * @brief Lock the task scheduling. 674 * 675 * @par Description: 676 * This API is used to lock the task scheduling. Task switching will not occur if the task scheduling is locked. 677 * 678 * @attention 679 * <ul> 680 * <li>If the task scheduling is locked, but interrupts are not disabled, tasks are still able to be interrupted.</li> 681 * <li>One is added to the number of task scheduling locks if this API is called. The number of locks is decreased by 682 * one if the task scheduling is unlocked. Therefore, this API should be used together with LOS_TaskUnlock.</li> 683 * </ul> 684 * 685 * @param None. 686 * 687 * @retval None. 688 * @par Dependency: 689 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 690 * @see LOS_TaskUnlock 691 */ 692 extern VOID LOS_TaskLock(VOID); 693 694 /** 695 * @ingroup los_task 696 * @brief Unlock the task scheduling. 697 * 698 * @par Description: 699 * This API is used to unlock the task scheduling. Calling this API will decrease the number of task locks by one. 700 * If a task is locked more than once, the task scheduling will be unlocked only when the number of locks becomes zero. 701 * 702 * @attention 703 * <ul> 704 * <li>The number of locks is decreased by one if this API is called. One is added to the number of task scheduling 705 * locks if the task scheduling is locked. Therefore, this API should be used together with LOS_TaskLock.</li> 706 * </ul> 707 * 708 * @param None. 709 * 710 * @retval None. 711 * @par Dependency: 712 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 713 * @see LOS_TaskLock 714 */ 715 extern VOID LOS_TaskUnlock(VOID); 716 717 /** 718 * @ingroup los_task 719 * @brief Set a task priority. 720 * 721 * @par Description: 722 * This API is used to set the priority of a specified task. 723 * 724 * @attention 725 * <ul> 726 * <li>If the set priority is higher than the priority of the current running task, task scheduling probably occurs. 727 * </li> 728 * <li>Changing the priority of the current running task also probably causes task scheduling.</li> 729 * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li> 730 * <li>Using the interface in the interrupt is not allowed.</li> 731 * </ul> 732 * 733 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 734 * @param taskPrio [IN] Type #UINT16 Task priority. 735 * 736 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority 737 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task. 738 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 739 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 740 * @retval #LOS_OK The task priority is successfully set to a specified priority. 741 * @par Dependency: 742 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 743 * @see LOS_TaskPriSet 744 */ 745 extern UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio); 746 747 /** 748 * @ingroup los_task 749 * @brief Set the priority of the current running task to a specified priority. 750 * 751 * @par Description: 752 * This API is used to set the priority of the current running task to a specified priority. 753 * 754 * @attention 755 * <ul> 756 * <li>Changing the priority of the current running task probably causes task scheduling.</li> 757 * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li> 758 * <li>Using the interface in the interrupt is not allowed.</li> 759 * </ul> 760 * 761 * @param taskPrio [IN] Type #UINT16 Task priority. 762 * 763 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority 764 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task. 765 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 766 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 767 * @retval #LOS_OK The priority of the current running task is successfully set to a specified 768 * priority. 769 * @par Dependency: 770 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 771 * @see LOS_TaskPriGet 772 */ 773 extern UINT32 LOS_CurTaskPriSet(UINT16 taskPrio); 774 775 /** 776 * @ingroup los_task 777 * @brief Change the scheduling sequence of tasks with the same priority. 778 * 779 * @par Description: 780 * 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 781 * tasks. 782 * 783 * @attention 784 * <ul> 785 * <li>At least two ready tasks need to be included in the queue of ready tasks with the same priority. If the 786 * less than two ready tasks are included in the queue, an error is reported.</li> 787 * <li>If call this API after tasklock,it will not report an error, 788 * and the task will schedule soon after task unlock</li> 789 * </ul> 790 * 791 * @param None. 792 * 793 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID 794 * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling. 795 * @retval #LOS_OK The scheduling sequence of tasks with same priority is 796 * successfully changed. 797 * @par Dependency: 798 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 799 * @see 800 */ 801 extern UINT32 LOS_TaskYield(VOID); 802 803 /** 804 * @ingroup los_task 805 * @brief Obtain a task priority. 806 * 807 * @par Description: 808 * This API is used to obtain the priority of a specified task. 809 * 810 * @attention None. 811 * 812 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 813 * 814 * @retval #OS_INVALID The task priority fails to be obtained. 815 * @retval #UINT16 The task priority. 816 * @par Dependency: 817 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 818 * @see LOS_TaskPriSet 819 */ 820 extern UINT16 LOS_TaskPriGet(UINT32 taskID); 821 822 /** 823 * @ingroup los_task 824 * @brief Obtain current running task ID. 825 * 826 * @par Description: 827 * This API is used to obtain the ID of current running task. 828 * 829 * @attention 830 * <ul> 831 * <li> This interface should not be called before system initialized.</li> 832 * </ul> 833 * 834 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID. 835 * @retval #UINT32 Task ID. 836 * @par Dependency: 837 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 838 * @see 839 */ 840 extern UINT32 LOS_CurTaskIDGet(VOID); 841 842 /** 843 * @ingroup los_task 844 * @brief Obtain next running task ID. 845 * 846 * @par Description: 847 * This API is used to obtain the ID of next running task. 848 * 849 * @attention None. 850 * 851 * 852 * @retval #NULL invalid Task name. 853 * @retval #CHAR* task name. 854 * @par Dependency: 855 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 856 * @see 857 */ 858 extern CHAR *LOS_CurTaskNameGet(VOID); 859 860 /** 861 * @ingroup los_task 862 * @brief Obtain a task information structure. 863 * 864 * @par Description: 865 * This API is used to obtain a task information structure. 866 * 867 * @attention 868 * <ul> 869 * <li>One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may be 870 * abnormal.</li> 871 * </ul> 872 * 873 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation. 874 * @param taskInfo [OUT] Type #TSK_INFO_S* Pointer to the task information structure to be obtained. 875 * 876 * @retval #LOS_ERRNO_TSK_PTR_NULL Null parameter. 877 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid task ID. 878 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created. 879 * @retval #LOS_OK The task information structure is successfully obtained. 880 * @par Dependency: 881 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 882 * @see 883 */ 884 extern UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo); 885 886 /** 887 * @ingroup los_task 888 * @brief Obtain the task status. 889 * 890 * @par Description: 891 * This API is used to obtain the task status. 892 * 893 * @attention None. 894 * 895 * @param taskID [IN] Type #TSK_HANDLE_T Task ID. 896 * @param taskStatus [OUT] Type #UINT32 Pointer to the task status to be obtained. 897 * 898 * @retval #LOS_ERRNO_TSK_PTR_NULL 0x02000201: Null parameter. 899 * @retval #LOS_ERRNO_TSK_ID_INVALID 0x02000207: Invalid task ID. 900 * @retval #LOS_ERRNO_TSK_NOT_CREATED 0x0200020a: The task is not created. 901 * @retval #LOS_OK 0: The task information structure is successfully obtained. 902 * @par Dependency: 903 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 904 * @see 905 */ 906 extern UINT32 LOS_TaskStatusGet(UINT32 taskID, UINT32* taskStatus); 907 908 /** 909 * @ingroup los_task 910 * @brief Obtain tasks switch info. 911 * 912 * @par Description: 913 * This API is used to obtain tasks switch info. 914 * 915 * @attention None. 916 * 917 * @param index [IN] Type #UINT32 Switch info array index. 918 * @param taskSwitchInfo [OUT] Type #UINT32* First 4 bytes is task id, and then is task name, name len is 919 * OS_TSK_NAME_LEN. 920 * 921 * @retval #LOS_ERRNO_TSK_PTR_NULL 0x02000201: Null parameter. 922 * @retval #LOS_OK 0: The task switch information is successfully obtained. 923 * @par Dependency: 924 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 925 * @see 926 */ 927 extern UINT32 LOS_TaskSwitchInfoGet(UINT32 index, UINT32 *taskSwitchInfo); 928 929 /** 930 * @ingroup los_task 931 * @brief Obtain tasks schduling info. 932 * 933 * @par Description: 934 * This API is used to obtain task is scheduled. 935 * 936 * @attention None. 937 * 938 * @param None. 939 * 940 * @retval #TRUE Tasks is scheduled. 941 * @retval #FALSE Tasks not scheduling yet. 942 * @par Dependency: 943 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 944 * @see 945 */ 946 extern BOOL LOS_TaskIsRunning(VOID); 947 948 /** 949 * @ingroup los_task 950 * @brief Obtain current new task name. 951 * 952 * @par Description: 953 * This API is used to obtain the name of new task. 954 * 955 * @attention None. 956 * 957 * @param taskID [IN] Task ID. 958 * 959 * @retval #NULL: invalid Task name. 960 * @retval # Task name. 961 * @par Dependency: 962 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul> 963 * @see 964 */ 965 extern CHAR* LOS_TaskNameGet(UINT32 taskID); 966 967 extern UINT32 LOS_TaskUsage(VOID); 968 969 #ifdef __cplusplus 970 #if __cplusplus 971 } 972 #endif /* __cplusplus */ 973 #endif /* __cplusplus */ 974 975 #endif /* _LOS_TASK_H */ 976