los_task.h

浏览该文件的文档。
00001 /*----------------------------------------------------------------------------
00002  * Copyright (c) <2013-2015>, <Huawei Technologies Co., Ltd>
00003  * All rights reserved.
00004  * Redistribution and use in source and binary forms, with or without modification,
00005  * are permitted provided that the following conditions are met:
00006  * 1. Redistributions of source code must retain the above copyright notice, this list of
00007  * conditions and the following disclaimer.
00008  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
00009  * of conditions and the following disclaimer in the documentation and/or other materials
00010  * provided with the distribution.
00011  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
00012  * to endorse or promote products derived from this software without specific prior written
00013  * permission.
00014  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00015  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00016  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00018  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00021  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00022  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00023  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00024  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  *---------------------------------------------------------------------------*/
00026 /*----------------------------------------------------------------------------
00027  * Notice of Export Control Law
00028  * ===============================================
00029  * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
00030  * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
00031  * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
00032  * applicable export control laws and regulations.
00033  *---------------------------------------------------------------------------*/
00034 
00035 /**@defgroup los_task Task
00036  * @ingroup kernel
00037  */
00038 
00039 #ifndef _LOS_TASK_H
00040 #define _LOS_TASK_H
00041 
00042 #include "los_base.h"
00043 #include "los_list.h"
00044 #include "los_sys.h"
00045 #include "los_hw.h"
00046 #include "los_tick.h"
00047 #include "los_event.h"
00048 #include "los_err.h"
00049 
00050 #ifdef __cplusplus
00051 #if __cplusplus
00052 extern "C" {
00053 #endif /* __cplusplus */
00054 #endif /* __cplusplus */
00055 
00056 /**
00057  * @ingroup los_task
00058  * Task error code: Insufficient memory for task creation.
00059  *
00060  * Value: 0x03000200
00061  *
00062  * Solution: Allocate bigger memory partition to task creation.
00063  */
00064 #define LOS_ERRNO_TSK_NO_MEMORY                     LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x00)
00065 
00066 /**
00067  * @ingroup los_task
00068  * Task error code: Null parameter.
00069  *
00070  * Value: 0x02000201
00071  *
00072  * Solution: Check the parameter.
00073  */
00074 #define LOS_ERRNO_TSK_PTR_NULL                      LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x01)
00075 
00076 /**
00077  * @ingroup los_task
00078  * Task error code: The task stack is not aligned.
00079  *
00080  * Value: 0x02000202
00081  *
00082  * Solution: Align the task stack.
00083  */
00084 #define LOS_ERRNO_TSK_STKSZ_NOT_ALIGN               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x02)
00085 
00086 /**
00087  * @ingroup los_task
00088  * Task error code: Incorrect task priority.
00089  *
00090  * Value: 0x02000203
00091  *
00092  * Solution: Re-configure the task priority by referring to the priority range.
00093  */
00094 #define LOS_ERRNO_TSK_PRIOR_ERROR                   LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x03)
00095 
00096 /**
00097  * @ingroup los_task
00098  * Task error code: The task entrance is NULL.
00099  *
00100  * Value: 0x02000204
00101  *
00102  * Solution: Define the task entrance function.
00103  */
00104 #define LOS_ERRNO_TSK_ENTRY_NULL                    LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x04)
00105 
00106 /**
00107  * @ingroup los_task
00108  * Task error code: The task name is NULL.
00109  *
00110  * Value: 0x02000205
00111  *
00112  * Solution: Set the task name.
00113  */
00114 #define LOS_ERRNO_TSK_NAME_EMPTY                    LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x05)
00115 
00116 /**
00117  * @ingroup los_task
00118  * Task error code: The task stack size is too small.
00119  *
00120  * Value: 0x02000206
00121  *
00122  * Solution: Expand the task stack.
00123  */
00124 #define LOS_ERRNO_TSK_STKSZ_TOO_SMALL               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x06)
00125 
00126 /**
00127  * @ingroup los_task
00128  * Task error code: Invalid task ID.
00129  *
00130  * Value: 0x02000207
00131  *
00132  * Solution: Check the task ID.
00133  */
00134 #define LOS_ERRNO_TSK_ID_INVALID                    LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x07)
00135 
00136 /**
00137  * @ingroup los_task
00138  * Task error code: The task is already suspended.
00139  *
00140  * Value: 0x02000208
00141  *
00142  * Solution: Suspend the task after it is resumed.
00143  */
00144 #define LOS_ERRNO_TSK_ALREADY_SUSPENDED             LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x08)
00145 
00146 /**
00147  * @ingroup los_task
00148  * Task error code: The task is not suspended.
00149  *
00150  * Value: 0x02000209
00151  *
00152  * Solution: Suspend the task.
00153  */
00154 #define LOS_ERRNO_TSK_NOT_SUSPENDED                 LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x09)
00155 
00156 /**
00157  * @ingroup los_task
00158  * Task error code: The task is not created.
00159  *
00160  * Value: 0x0200020a
00161  *
00162  * Solution: Create the task.
00163  */
00164 #define LOS_ERRNO_TSK_NOT_CREATED                   LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0a)
00165 
00166 /**
00167  * @ingroup los_task
00168  * Task error code: The task message is nonzero.
00169  *
00170  * Value: 0x0200020c
00171  *
00172  * Solution: This error code is not in use temporarily.
00173  */
00174 #define LOS_ERRNO_TSK_MSG_NONZERO                   LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0c)
00175 
00176 /**
00177  * @ingroup los_task
00178  * Task error code: The task delay occurs during an interrupt.
00179  *
00180  * Value: 0x0300020d
00181  *
00182  * Solution: Perform this operation after exiting from the interrupt.
00183  */
00184 #define LOS_ERRNO_TSK_DELAY_IN_INT                  LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x0d)
00185 
00186 /**
00187  * @ingroup los_task
00188  * Task error code: The task delay occurs when the task is locked.
00189  *
00190  * Value: 0x0200020e
00191  *
00192  * Solution: Perform this operation after unlocking the task.
00193  */
00194 #define LOS_ERRNO_TSK_DELAY_IN_LOCK                 LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0e)
00195 
00196 /**
00197  * @ingroup los_task
00198  * Task error code: The task that is being scheduled is invalid.
00199  *
00200  * Value: 0x0200020f
00201  *
00202  * Solution: Check the task.
00203  */
00204 #define LOS_ERRNO_TSK_YIELD_INVALID_TASK            LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0f)
00205 
00206 /**
00207  * @ingroup los_task
00208  * Task error code: Only one task or no task is available for scheduling.
00209  *
00210  * Value: 0x02000210
00211  *
00212  * Solution: Increase the number of tasks.
00213  */
00214 #define LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK         LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x10)
00215 
00216 /**
00217  * @ingroup los_task
00218  * Task error code: No free task control block is available.
00219  *
00220  * Value: 0x02000211
00221  *
00222  * Solution: Increase the number of task control blocks.
00223  */
00224 #define LOS_ERRNO_TSK_TCB_UNAVAILABLE               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x11)
00225 
00226 /**
00227  * @ingroup los_task
00228  * Task error code: The task hook function is not matchable.
00229  *
00230  * Value: 0x02000212
00231  *
00232  * Solution: This error code is not in use temporarily.
00233  */
00234 #define LOS_ERRNO_TSK_HOOK_NOT_MATCH                LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x12)
00235 
00236 /**
00237  * @ingroup los_task
00238  * Task error code: The number of task hook functions exceeds the permitted upper limit.
00239  *
00240  * Value: 0x02000213
00241  *
00242  * Solution: This error code is not in use temporarily.
00243  */
00244 #define LOS_ERRNO_TSK_HOOK_IS_FULL                  LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x13)
00245 
00246 /**
00247  * @ingroup los_task
00248  * Task error code: The operation is performed on the idle task.
00249  *
00250  * Value: 0x02000214
00251  *
00252  * Solution: Check the task ID and do not operate on the idle task.
00253  */
00254 #define LOS_ERRNO_TSK_OPERATE_IDLE                  LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x14)
00255 
00256 /**
00257  * @ingroup los_task
00258  * Task error code: The task that is being suspended is locked.
00259  *
00260  * Value: 0x03000215
00261  *
00262  * Solution: Suspend the task after unlocking the task.
00263  */
00264 #define LOS_ERRNO_TSK_SUSPEND_LOCKED                LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x15)
00265 
00266 /**
00267  * @ingroup los_task
00268  * Task error code: The task stack fails to be freed.
00269  *
00270  * Value: 0x02000217
00271  *
00272  * Solution: This error code is not in use temporarily.
00273  */
00274 #define LOS_ERRNO_TSK_FREE_STACK_FAILED             LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x17)
00275 
00276 /**
00277  * @ingroup los_task
00278  * Task error code: The task stack area is too small.
00279  *
00280  * Value: 0x02000218
00281  *
00282  * Solution: This error code is not in use temporarily.
00283  */
00284 #define LOS_ERRNO_TSK_STKAREA_TOO_SMALL             LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x18)
00285 
00286 /**
00287  * @ingroup los_task
00288  * Task error code: The task fails to be activated.
00289  *
00290  * Value: 0x03000219
00291  *
00292  * Solution: Perform task switching after creating an idle task.
00293  */
00294 #define LOS_ERRNO_TSK_ACTIVE_FAILED                 LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x19)
00295 
00296 /**
00297  * @ingroup los_task
00298  * Task error code: Too many task configuration items.
00299  *
00300  * Value: 0x0200021a
00301  *
00302  * Solution: This error code is not in use temporarily.
00303  */
00304 #define LOS_ERRNO_TSK_CONFIG_TOO_MANY               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1a)
00305 
00306 /**
00307  * @ingroup los_task
00308  * Task error code:
00309  *
00310  * Value: 0x0200021b
00311  *
00312  * Solution: This error code is not in use temporarily.
00313  */
00314 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NOT_ALIGN        LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1b)
00315 
00316 /**
00317  * @ingroup los_task
00318  * Task error code:
00319  *
00320  * Value: 0x0200021d
00321  *
00322  * Solution: This error code is not in use temporarily.
00323  */
00324 #define LOS_ERRNO_TSK_MSG_Q_TOO_MANY                LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1d)
00325 
00326 /**
00327  * @ingroup los_task
00328  * Task error code:
00329  *
00330  * Value: 0x0200021e
00331  *
00332  * Solution: This error code is not in use temporarily.
00333  */
00334 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NULL             LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1e)
00335 
00336 /**
00337  * @ingroup los_task
00338  * Task error code:
00339  *
00340  * Value: 0x0200021f
00341  *
00342  * Solution: This error code is not in use temporarily.
00343  */
00344 #define LOS_ERRNO_TSK_SELF_DELETE_ERR               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1f)
00345 
00346 /**
00347  * @ingroup los_task
00348  * Task error code: The task stack size is too large.
00349  *
00350  * Value: 0x02000220
00351  *
00352  * Solution: shrink the task stack size parameter.
00353  */
00354 #define LOS_ERRNO_TSK_STKSZ_TOO_LARGE               LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x20)
00355 
00356 /**
00357  * @ingroup los_task
00358  * Task error code: Suspending software timer task is not allowed.
00359  *
00360  * Value: 0x02000221
00361  *
00362  * Solution: Check the task ID and do not suspend software timer task.
00363  */
00364 #define LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED                LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x21)
00365 
00366 /**
00367  * @ingroup los_task
00368  * Task error code: The operation is performed on the software timer task.
00369  *
00370  * Value: 0x02000222
00371  *
00372  * Solution: Check the task ID and do not operate on the software timer task.
00373  */
00374 #define LOS_ERRNO_TSK_OPERATE_SWTMR                 LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x22)
00375 
00376 /**
00377  * @ingroup los_task
00378  * Define the type of the task switching hook function.
00379  *
00380  */
00381 typedef VOID (*TSKSWITCHHOOK)(VOID);
00382 
00383 /**
00384  * @ingroup los_task
00385  * User task switching hook function.
00386  *
00387  */
00388 extern TSKSWITCHHOOK g_pfnUsrTskSwitchHook;
00389 
00390 /**
00391 * @ingroup  los_task
00392 * @brief Define the type of a task entrance function.
00393 *
00394 * @par Description:
00395 * This API is used to define the type of a task entrance function and call it after a task is created and triggered.
00396 * @attention None.
00397 *
00398 * @param  uwParam1 [IN] Type #UINT32 The first parameter passed to the task handling function.
00399 * @param  uwParam2 [IN] Type #UINT32 The second parameter passed to the task handling function.
00400 * @param  uwParam3 [IN] Type #UINT32 The third parameter passed to the task handling function.
00401 * @param  uwParam4 [IN] Type #UINT32 The fourth parameter passed to the task handling function.
00402 *
00403 * @retval None.
00404 * @par Dependency:
00405 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00406 * @see
00407 * @since Huawei LiteOS V100R001C00
00408 */
00409 typedef VOID *(*TSK_ENTRY_FUNC)(UINT32 uwArg);
00410 
00411 /**
00412  * @ingroup los_task
00413  * Define the structure of the parameters used for task creation.
00414  *
00415  * Information of specified parameters passed in during task creation.
00416  */
00417 typedef struct tagTskInitParam
00418 {
00419    TSK_ENTRY_FUNC       pfnTaskEntry;               /**< Task entrance function                 */
00420    UINT16               usTaskPrio;                 /**< Task priority                          */
00421    UINT32               uwArg;                      /**< Task parameters                        */
00422    UINT32               uwStackSize;                /**< Task stack size                        */
00423    CHAR                 *pcName;                    /**< Task name                              */
00424    UINT32               uwResved;                   /**< Reserved                               */
00425 } TSK_INIT_PARAM_S;
00426 
00427 /**
00428  * @ingroup los_task
00429  * Task name length
00430  *
00431  */
00432 #define LOS_TASK_NAMELEN                            32
00433 
00434 /**
00435  * @ingroup los_task
00436  * Task information structure.
00437  *
00438  */
00439 typedef struct tagTskInfo
00440 {
00441     CHAR                acName[LOS_TASK_NAMELEN];   /**< Task entrance function         */
00442     UINT32              uwTaskID;                   /**< Task ID                        */
00443     UINT16              usTaskStatus;               /**< Task status                    */
00444     UINT16              usTaskPrio;                 /**< Task priority                  */
00445     VOID                *pTaskSem;                  /**< Semaphore pointer              */
00446     VOID                *pTaskMux;                  /**< Mutex pointer                  */
00447     UINT32              uwSemID;                    /**< Sem ID                         */
00448     UINT32              uwMuxID;                    /**< Mux ID                         */
00449     EVENT_CB_S          uwEvent;                    /**< Event                          */
00450     UINT32              uwEventMask;                /**< Event mask                     */
00451     UINT32              uwStackSize;                /**< Task stack size                */
00452     UINT32              uwTopOfStack;               /**< Task stack top                 */
00453     UINT32              uwBottomOfStack;            /**< Task stack bottom              */
00454     UINT32              uwSP;                       /**< Task SP pointer                */
00455     UINT32              uwCurrUsed;                 /**< Current task stack usage       */
00456     UINT32              uwPeakUsed;                 /**< Task stack usage peak          */
00457     BOOL                bOvf;                       /**< Flag that indicates whether a task stack overflow occurs         */
00458 } TSK_INFO_S;
00459 
00460 /**
00461  * @ingroup los_task
00462  * Task switch information structure.
00463  *
00464  */
00465 #define OS_TASK_SWITCH_INFO_COUNT                           (0xA)
00466 typedef struct tagTaskSwitchInfo
00467 {
00468     UINT8 ucIdx;
00469     UINT8 ucIsFull; /* bit [7] store isfull status, bits [6:0] store count of task switch info */
00470     UINT16 auwPID[OS_TASK_SWITCH_INFO_COUNT];
00471     CHAR   acName[OS_TASK_SWITCH_INFO_COUNT][LOS_TASK_NAMELEN];
00472 }OS_TASK_SWITCH_INFO;
00473 
00474 
00475 /**
00476  * @ingroup  los_task
00477  * @brief Create a task and suspend.
00478  *
00479  * @par Description:
00480  * This API is used to create a task and suspend it. This task will not be added to the queue of ready tasks before resume it.
00481  *
00482  * @attention
00483  * <ul>
00484  * <li>During task creation, the task control block and task stack of the task that is previously automatically deleted are deallocated.</li>
00485  * <li>The task name is a pointer and is not allocated memory.</li>
00486  * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE to specify the default task stack size. The stack size should be a reasonable value, if the size is too large, may cause memory exhaustion.</li>
00487  * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big enough to avoid task stack overflow.</li>
00488  * <li>Less parameter value indicates higher task priority.</li>
00489  * <li>The task name cannot be null.</li>
00490  * <li>The pointer to the task executing function cannot be null.</li>
00491  * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be abnormal.</li>
00492  * </ul>
00493  *
00494  * @param  puwTaskID    [OUT] Type  #UINT32 * Task ID.
00495  * @param  pstInitParam [IN]  Type  #TSK_INIT_PARAM_S * Parameter for task creation.
00496  *
00497  * @retval #LOS_ERRNO_TSK_ID_INVALID        Invalid Task ID, param puwTaskID is NULL.
00498  * @retval #LOS_ERRNO_TSK_PTR_NULL          Param pstInitParam is NULL.
00499  * @retval #LOS_ERRNO_TSK_NAME_EMPTY        The task name is NULL.
00500  * @retval #LOS_ERRNO_TSK_ENTRY_NULL        The task entrance is NULL.
00501  * @retval #LOS_ERRNO_TSK_PRIOR_ERROR       Incorrect task priority.
00502  * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE   The task stack size is too large.
00503  * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL   The task stack size is too small.
00504  * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE   No free task control block is available.
00505  * @retval #LOS_ERRNO_TSK_NO_MEMORY         Insufficient memory for task creation.
00506  * @retval #LOS_OK                          The task is successfully created.
00507  * @par Dependency:
00508  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00509  * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
00510  * @see LOS_TaskDelete
00511  * @since Huawei LiteOS V100R001C00
00512  */
00513 extern UINT32 LOS_TaskCreateOnly(UINT32 *puwTaskID, TSK_INIT_PARAM_S *pstInitParam);
00514 
00515 /**
00516  * @ingroup  los_task
00517  * @brief Create a task.
00518  *
00519  * @par Description:
00520  * This API is used to create a task. If the priority of the task created after system initialized is higher than the current task and task scheduling is not locked, it is scheduled for running.
00521  * If not, the created task is added to the queue of ready tasks.
00522  *
00523  * @attention
00524  * <ul>
00525  * <li>During task creation, the task control block and task stack of the task that is previously automatically deleted are deallocated.</li>
00526  * <li>The task name is a pointer and is not allocated memory.</li>
00527  * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE to specify the default task stack size.</li>
00528  * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big enough to avoid task stack overflow.</li>
00529  * <li>Less parameter value indicates higher task priority.</li>
00530  * <li>The task name cannot be null.</li>
00531  * <li>The pointer to the task executing function cannot be null.</li>
00532  * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be abnormal.</li>
00533  * </ul>
00534  *
00535  * @param  puwTaskID    [OUT] Type  #UINT32 * Task ID.
00536  * @param  pstInitParam [IN]  Type  #TSK_INIT_PARAM_S * Parameter for task creation.
00537  *
00538  * @retval #LOS_ERRNO_TSK_ID_INVALID        Invalid Task ID, param puwTaskID is NULL.
00539  * @retval #LOS_ERRNO_TSK_PTR_NULL          Param pstInitParam is NULL.
00540  * @retval #LOS_ERRNO_TSK_NAME_EMPTY        The task name is NULL.
00541  * @retval #LOS_ERRNO_TSK_ENTRY_NULL        The task entrance is NULL.
00542  * @retval #LOS_ERRNO_TSK_PRIOR_ERROR       Incorrect task priority.
00543  * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE   The task stack size is too large.
00544  * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL   The task stack size is too small.
00545  * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE   No free task control block is available.
00546  * @retval #LOS_ERRNO_TSK_NO_MEMORY         Insufficient memory for task creation.
00547  * @retval #LOS_OK                          The task is successfully created.
00548  * @par Dependency:
00549  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00550  * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
00551  * @see LOS_TaskDelete
00552  * @since Huawei LiteOS V100R001C00
00553  */
00554 extern UINT32 LOS_TaskCreate(UINT32 *puwTaskID, TSK_INIT_PARAM_S *pstInitParam);
00555 
00556 /**
00557  * @ingroup  los_task
00558  * @brief Resume a task.
00559  *
00560  * @par Description:
00561  * This API is used to resume a suspended task.
00562  *
00563  * @attention
00564  * <ul>
00565  * <li>If the task is delayed or blocked, resume the task without adding it to the queue of ready tasks.</li>
00566  * <li>If the priority of the task resumed after system initialized is higher than the current task and task scheduling is not locked, it is scheduled for running.</li>
00567  * </ul>
00568  *
00569  * @param  uwTaskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
00570  *
00571  * @retval #LOS_ERRNO_TSK_ID_INVALID        Invalid Task ID
00572  * @retval #LOS_ERRNO_TSK_NOT_CREATED       The task is not created.
00573  * @retval #LOS_ERRNO_TSK_NOT_SUSPENDED     The task is not suspended.
00574  * @retval #LOS_OK                          The task is successfully resumed.
00575  * @par Dependency:
00576  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00577  * @see LOS_TaskSuspend
00578  * @since Huawei LiteOS V100R001C00
00579  */
00580 extern UINT32 LOS_TaskResume(UINT32 uwTaskID);
00581 
00582 /**
00583  * @ingroup  los_task
00584  * @brief Suspend a task.
00585  *
00586  * @par Description:
00587  * This API is used to suspend a specified task, and the task will be removed from the queue of ready tasks.
00588  *
00589  * @attention
00590  * <ul>
00591  * <li>The task that is running and locked cannot be suspended.</li>
00592  * <li>The idle task and swtmr task cannot be suspended.</li>
00593  * </ul>
00594  *
00595  * @param  uwTaskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
00596  *
00597  * @retval #LOS_ERRNO_TSK_OPERATE_IDLE                  Check the task ID and do not operate on the idle task.
00598  * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED     Check the task ID and do not operate on the swtmr task.
00599  * @retval #LOS_ERRNO_TSK_ID_INVALID                    Invalid Task ID
00600  * @retval #LOS_ERRNO_TSK_NOT_CREATED                   The task is not created.
00601  * @retval #LOS_ERRNO_TSK_ALREADY_SUSPENDED             The task is already suspended.
00602  * @retval #LOS_ERRNO_TSK_SUSPEND_LOCKED                The task being suspended is current task and task scheduling is locked.
00603  * @retval #LOS_OK                                      The task is successfully suspended.
00604  * @par Dependency:
00605  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00606  * @see LOS_TaskResume
00607  * @since Huawei LiteOS V100R001C00
00608  */
00609 extern UINT32 LOS_TaskSuspend(UINT32 uwTaskID);
00610 
00611 /**
00612  * @ingroup  los_task
00613  * @brief Delete a task.
00614  *
00615  * @par Description:
00616  * This API is used to delete a specified task and release the resources for its task stack and task control block.
00617  *
00618  * @attention
00619  * <ul>
00620  * <li>The idle task and swtmr task cannot be deleted.</li>
00621  * <li>If delete current task maybe cause unexpected error.</li>
00622  * <li>If a task get a mutex is deleted or automatically deleted before release this mutex, other tasks pended this mutex maybe never be shchduled.</li>
00623  * </ul>
00624  *
00625  * @param  uwTaskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
00626  *
00627  * @retval #LOS_ERRNO_TSK_OPERATE_IDLE                  Check the task ID and do not operate on the idle task.
00628  * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED     Check the task ID and do not operate on the swtmr task.
00629  * @retval #LOS_ERRNO_TSK_ID_INVALID                    Invalid Task ID
00630  * @retval #LOS_ERRNO_TSK_NOT_CREATED                   The task is not created.
00631  * @retval #LOS_OK                                      The task is successfully deleted.
00632  * @par Dependency:
00633  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00634  * @see LOS_TaskCreate | LOS_TaskCreateOnly
00635  * @since Huawei LiteOS V100R001C00
00636  */
00637 extern UINT32 LOS_TaskDelete(UINT32 uwTaskID);
00638 
00639 /**
00640  * @ingroup  los_task
00641  * @brief Delay a task.
00642  *
00643  * @par Description:
00644  * This API is used to delay the execution of the current task. The task is able to be scheduled after it is delayed for a specified number of Ticks.
00645  *
00646  * @attention
00647  * <ul>
00648  * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
00649  * <li>If 0 is passed in and the task scheduling is not locked, execute the next task in the queue of tasks with the same priority of the current task.
00650  * If no ready task with the priority of the current task is available, the task scheduling will not occur, and the current task continues to be executed.</li>
00651  * <li>Using the interface before system initialized is not allowed.</li>
00652  * </ul>
00653  *
00654  * @param  uwTick [IN] Type #UINT32 Number of Ticks for which the task is delayed.
00655  *
00656  * @retval #LOS_ERRNO_TSK_DELAY_IN_INT              The task delay occurs during an interrupt.
00657  * @retval #LOS_ERRNO_TSK_DELAY_IN_LOCK             The task delay occurs when the task scheduling is locked.
00658  * @retval #LOS_ERRNO_TSK_ID_INVALID                Invalid Task ID
00659  * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK     No tasks with the same priority is available for scheduling.
00660  * @retval #LOS_OK                                  The task is successfully delayed.
00661  * @par Dependency:
00662  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00663  * @see
00664  * @since Huawei LiteOS V100R001C00
00665  */
00666 extern UINT32 LOS_TaskDelay(UINT32 uwTick);
00667 
00668 /**
00669  * @ingroup  los_task
00670  * @brief Lock the task scheduling.
00671  *
00672  * @par Description:
00673  * This API is used to lock the task scheduling. Task switching will not occur if the task scheduling is locked.
00674  *
00675  * @attention
00676  * <ul>
00677  * <li>If the task scheduling is locked, but interrupts are not disabled, tasks are still able to be interrupted.</li>
00678  * <li>One is added to the number of task scheduling locks if this API is called. The number of locks is decreased by one if the task scheduling is unlocked. Therefore, this API should be used together with LOS_TaskUnlock.</li>
00679  * </ul>
00680  *
00681  * @param  None.
00682  *
00683  * @retval None.
00684  * @par Dependency:
00685  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00686  * @see LOS_TaskUnlock
00687  * @since Huawei LiteOS V100R001C00
00688  */
00689 extern VOID LOS_TaskLock(VOID);
00690 
00691 /**
00692  * @ingroup  los_task
00693  * @brief Unlock the task scheduling.
00694  *
00695  * @par Description:
00696  * This API is used to unlock the task scheduling. Calling this API will decrease the number of task locks by one. If a task is locked more than once, the task scheduling will be unlocked only when the number of locks becomes zero.
00697  *
00698  * @attention
00699  * <ul>
00700  * <li>The number of locks is decreased by one if this API is called. One is added to the number of task scheduling locks if the task scheduling is locked. Therefore, this API should be used together with LOS_TaskLock.</li>
00701  * </ul>
00702  *
00703  * @param  None.
00704  *
00705  * @retval None.
00706  * @par Dependency:
00707  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00708  * @see LOS_TaskLock
00709  * @since Huawei LiteOS V100R001C00
00710  */
00711 extern VOID LOS_TaskUnlock(VOID);
00712 
00713 /**
00714  * @ingroup  los_task
00715  * @brief Set a task priority.
00716  *
00717  * @par Description:
00718  * This API is used to set the priority of a specified task.
00719  *
00720  * @attention
00721  * <ul>
00722  * <li>If the set priority is higher than the priority of the current running task, task scheduling probably occurs.</li>
00723  * <li>Changing the priority of the current running task also probably causes task scheduling.</li>
00724  * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
00725  * <li>Using the interface in the interrupt is not allowed.</li>
00726  * </ul>
00727  *
00728  * @param  uwTaskID   [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
00729  * @param  usTaskPrio [IN] Type #UINT16 Task priority.
00730  *
00731  * @retval #LOS_ERRNO_TSK_PRIOR_ERROR    Incorrect task priority.Re-configure the task priority
00732  * @retval #LOS_ERRNO_TSK_OPERATE_IDLE   Check the task ID and do not operate on the idle task.
00733  * @retval #LOS_ERRNO_TSK_ID_INVALID     Invalid Task ID
00734  * @retval #LOS_ERRNO_TSK_NOT_CREATED    The task is not created.
00735  * @retval #LOS_OK                       The task priority is successfully set to a specified priority.
00736  * @par Dependency:
00737  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00738  * @see LOS_TaskPriSet
00739  * @since Huawei LiteOS V100R001C00
00740  */
00741 extern UINT32 LOS_TaskPriSet(UINT32 uwTaskID, UINT16 usTaskPrio);
00742 
00743 /**
00744  * @ingroup  los_task
00745  * @brief Set the priority of the current running task to a specified priority.
00746  *
00747  * @par Description:
00748  * This API is used to set the priority of the current running task to a specified priority.
00749  *
00750  * @attention
00751  * <ul>
00752  * <li>Changing the priority of the current running task probably causes task scheduling.</li>
00753  * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
00754  * <li>Using the interface in the interrupt is not allowed.</li>
00755  * </ul>
00756  *
00757  * @param  usTaskPrio [IN] Type #UINT16 Task priority.
00758  *
00759  * @retval #LOS_ERRNO_TSK_PRIOR_ERROR     Incorrect task priority.Re-configure the task priority
00760  * @retval #LOS_ERRNO_TSK_OPERATE_IDLE    Check the task ID and do not operate on the idle task.
00761  * @retval #LOS_ERRNO_TSK_ID_INVALID      Invalid Task ID
00762  * @retval #LOS_ERRNO_TSK_NOT_CREATED     The task is not created.
00763  * @retval #LOS_OK                        The priority of the current running task is successfully set to a specified priority.
00764  * @par Dependency:
00765  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00766  * @see LOS_TaskPriGet
00767  * @since Huawei LiteOS V100R001C00
00768  */
00769 extern UINT32 LOS_CurTaskPriSet(UINT16 usTaskPrio);
00770 
00771 /**
00772  * @ingroup  los_task
00773  * @brief Change the scheduling sequence of tasks with the same priority.
00774  *
00775  * @par Description:
00776  * 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 tasks.
00777  *
00778  * @attention
00779  * <ul>
00780  * <li>At least two ready tasks need to be included in the queue of ready tasks with the same priority. If the less than two ready tasks are included in the queue, an error is reported.</li>
00781  * </ul>
00782  *
00783  * @param  None.
00784  *
00785  * @retval #LOS_ERRNO_TSK_ID_INVALID                    Invalid Task ID
00786  * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK         No tasks with the same priority is available for scheduling.
00787  * @retval #LOS_OK                                      The scheduling sequence of tasks with same priority is successfully changed.
00788  * @par Dependency:
00789  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00790  * @see
00791  * @since Huawei LiteOS V100R001C00
00792  */
00793 extern UINT32 LOS_TaskYield(VOID);
00794 
00795 /**
00796  * @ingroup  los_task
00797  * @brief Obtain a task priority.
00798  *
00799  * @par Description:
00800  * This API is used to obtain the priority of a specified task.
00801  *
00802  * @attention None.
00803  *
00804  * @param  uwTaskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
00805  *
00806  * @retval #OS_INVALID      The task priority fails to be obtained.
00807  * @retval #UINT16          The task priority.
00808  * @par Dependency:
00809  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00810  * @see LOS_TaskPriSet
00811  * @since Huawei LiteOS V100R001C00
00812  */
00813 extern UINT16 LOS_TaskPriGet(UINT32 uwTaskID);
00814 
00815 /**
00816  * @ingroup  los_task
00817  * @brief Obtain current running task ID.
00818  *
00819  * @par Description:
00820  * This API is used to obtain the ID of current running task.
00821  *
00822  * @attention
00823  * <ul>
00824  * <li> This interface should not be called before system initialized.</li>
00825  * </ul>
00826  *
00827  * @retval #LOS_ERRNO_TSK_ID_INVALID    Invalid Task ID.
00828  * @retval #UINT32                      Task ID.
00829  * @par Dependency:
00830  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00831  * @see
00832  * @since Huawei LiteOS V100R001C00
00833  */
00834 extern UINT32 LOS_CurTaskIDGet(VOID);
00835 
00836 /**
00837  * @ingroup  los_task
00838  * @brief Obtain next running task ID.
00839  *
00840  * @par Description:
00841  * This API is used to obtain the ID of next running task.
00842  *
00843  * @attention None.
00844  *
00845  *
00846  * @retval #LOS_ERRNO_TSK_ID_INVALID    invalid Task ID.
00847  * @retval #UINT32                      task id.
00848  * @par Dependency:
00849  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00850  * @see
00851  * @since Huawei LiteOS V100R001C00
00852  */
00853 extern UINT32 LOS_NextTaskIDGet(VOID);
00854 
00855 /**
00856  * @ingroup  los_task
00857  * @brief Obtain next running task ID.
00858  *
00859  * @par Description:
00860  * This API is used to obtain the ID of next running task.
00861  *
00862  * @attention None.
00863  *
00864  *
00865  * @retval #NULL            invalid Task name.
00866  * @retval #CHAR*           task name.
00867  * @par Dependency:
00868  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00869  * @see
00870  * @since Huawei LiteOS V100R001C00
00871  */
00872 extern CHAR *LOS_CurTaskNameGet(VOID);
00873 
00874 /**
00875  * @ingroup  los_task
00876  * @brief Obtain a task information structure.
00877  *
00878  * @par Description:
00879  * This API is used to obtain a task information structure.
00880  *
00881  * @attention
00882  * <ul>
00883  * <li>One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may be abnormal.</li>
00884  * </ul>
00885  *
00886  * @param  uwTaskID    [IN]  Type  #UINT32 Task ID. The task id value is obtained from task creation.
00887  * @param  pstTaskInfo [OUT] Type  #TSK_INFO_S* Pointer to the task information structure to be obtained.
00888  *
00889  * @retval #LOS_ERRNO_TSK_PTR_NULL        Null parameter.
00890  * @retval #LOS_ERRNO_TSK_ID_INVALID      Invalid task ID.
00891  * @retval #LOS_ERRNO_TSK_NOT_CREATED     The task is not created.
00892  * @retval #LOS_OK                        The task information structure is successfully obtained.
00893  * @par Dependency:
00894  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00895  * @see
00896  * @since Huawei LiteOS V100R001C00
00897  */
00898 extern UINT32 LOS_TaskInfoGet(UINT32 uwTaskID, TSK_INFO_S *pstTaskInfo);
00899 
00900 /**
00901  * @ingroup  los_task
00902  * @brief Obtain the task status.
00903  *
00904  * @par Description:
00905  * This API is used to obtain the task status.
00906  *
00907  * @attention None.
00908  *
00909  * @param  uwTaskID   [IN] Type  #TSK_HANDLE_T Task ID.
00910  * @param  puwTaskStatus [OUT] Type  #UINT32 Pointer to the task status to be obtained.
00911  *
00912  * @retval #LOS_ERRNO_TSK_PTR_NULL                    0x02000201: Null parameter.
00913  * @retval #LOS_ERRNO_TSK_ID_INVALID                  0x02000207: Invalid task ID.
00914  * @retval #LOS_ERRNO_TSK_NOT_CREATED                 0x0200020a: The task is not created.
00915  * @retval #LOS_OK                                   0: The task information structure is successfully obtained.
00916  * @par Dependency:
00917  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00918  * @see
00919  * @since Huawei LiteOS V100R001C00
00920  */
00921 extern UINT32 LOS_TaskStatusGet(UINT32 uwTaskID, UINT32* puwTaskStatus);
00922 
00923 /**
00924  *@ingroup los_monitor
00925  *@brief Obtain all tasks info.
00926  *
00927  *@par Description:
00928  *This API is used to obtain all tasks info.
00929  *@attention
00930  *<ul>
00931  *<li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
00932  *</ul>
00933  *
00934  *@param None.
00935  *
00936  *@retval #OS_ERROR           -1:all tasks info obtain failed.
00937  *@retval #LOS_OK              0:all tasks info is successfully obtained.
00938  *@par Dependency:
00939  *<ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
00940  *@see LOS_TaskInfoMonitor
00941  *@since Huawei LiteOS V100R001C00
00942  */
00943 extern UINT32 LOS_TaskInfoMonitor(VOID);
00944 
00945 /**
00946  * @ingroup  los_task
00947  * @brief Obtain tasks switch info.
00948  *
00949  * @par Description:
00950  * This API is used to obtain tasks switch info.
00951  *
00952  * @attention None.
00953  *
00954  * @param  uwIdx            [IN]  Type  #UINT32  Switch info array index.
00955  * @param  pTaskSwitchInfo  [OUT] Type  #UINT32* First 4 bytes is task id, and then is task name, name len is OS_TSK_NAME_LEN.
00956  *
00957  * @retval #LOS_ERRNO_TSK_PTR_NULL           0x02000201: Null parameter.
00958  * @retval #LOS_OK                           0: The task switch information is successfully obtained.
00959  * @par Dependency:
00960  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00961  * @see
00962  * @since Huawei LiteOS V100R001C00
00963  */
00964 extern UINT32 LOS_TaskSwitchInfoGet(UINT32 uwIdx, UINT32 *pTaskSwitchInfo);
00965 
00966 /**
00967  * @ingroup  los_task
00968  * @brief Obtain tasks schduling info.
00969  *
00970  * @par Description:
00971  * This API is used to obtain task is scheduled.
00972  *
00973  * @attention None.
00974  *
00975  * @param None.
00976  *
00977  * @retval                          1: Tasks is scheduled.
00978  * @retval                          0: Tasks not scheduling yet.
00979  * @par Dependency:
00980  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
00981  * @see
00982  * @since Huawei LiteOS V100R001C00
00983  */
00984 extern BOOL LOS_TaskIsRunning(VOID);
00985 
00986 /**
00987  * @ingroup  los_task
00988  * @brief Obtain current new task ID.
00989  *
00990  * @par Description:
00991  * This API is used to obtain the ID of new  task.
00992  *
00993  * @attention None.
00994  *
00995  *
00996  * @retval #LOS_ERRNO_TSK_ID_INVALID    0x02000207: invalid Task ID.
00997  * @retval # Task ID.
00998  * @par Dependency:
00999  * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
01000  * @see
01001  * @since Huawei LiteOS V100R001C00
01002  */
01003  extern  UINT32 LOS_NewTaskIDGet(VOID);
01004  /**
01005   * @ingroup  los_task
01006   * @brief Obtain current new task name.
01007   *
01008   * @par Description:
01009   * This API is used to obtain the name of new  task.
01010   *
01011   * @attention None.
01012   *
01013   *
01014   * @retval #NULL: invalid Task name.
01015   * @retval # Task name.
01016   * @par Dependency:
01017   * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
01018   * @see
01019   * @since Huawei LiteOS V100R001C00
01020   */
01021  extern CHAR* LOS_TaskNameGet(UINT32 uwTaskID);
01022 
01023 #ifdef __cplusplus
01024 #if __cplusplus
01025 }
01026 #endif /* __cplusplus */
01027 #endif /* __cplusplus */
01028 
01029 #endif /* _LOS_TASK_H */