WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
Software timer
Software timer 的协作图:

宏定义

#define OS_SWTMR_MAX_TIMERID   ((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT)
 
#define OS_SWTMR_HANDLE_QUEUE_SIZE   KERNEL_SWTMR_LIMIT
 
#define LOS_ERRNO_SWTMR_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)
 
#define LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x01)
 
#define LOS_ERRNO_SWTMR_MODE_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02)
 
#define LOS_ERRNO_SWTMR_RET_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x03)
 
#define LOS_ERRNO_SWTMR_MAXSIZE   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x04)
 
#define LOS_ERRNO_SWTMR_ID_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05)
 
#define LOS_ERRNO_SWTMR_NOT_CREATED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x06)
 
#define LOS_ERRNO_SWTMR_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x07)
 
#define LOS_ERRNO_SWTMR_MAXSIZE_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x08)
 
#define LOS_ERRNO_SWTMR_HWI_ACTIVE   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x09)
 
#define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a)
 
#define LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0b)
 
#define LOS_ERRNO_SWTMR_TASK_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0c)
 
#define LOS_ERRNO_SWTMR_NOT_STARTED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0d)
 
#define LOS_ERRNO_SWTMR_STATUS_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0e)
 
#define LOS_ERRNO_SWTMR_SORTLIST_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0f)
 
#define LOS_ERRNO_SWTMR_TICK_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x10)
 
#define LOS_ERRNO_SWTMR_SORTLINK_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11)
 
#define LOS_ERRNO_SWTMR_INVALID_SYNCDEL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x12)
 

类型定义

typedef void(* SWTMR_PROC_FUNC) (UINTPTR arg)
 Define the type of a callback function that handles software timer timeout.
 

枚举

enum  enSwTmrType { LOS_SWTMR_MODE_ONCE , LOS_SWTMR_MODE_PERIOD , LOS_SWTMR_MODE_NO_SELFDELETE , LOS_SWTMR_MODE_OPP }
 

函数

UINT32 LOS_SwtmrStart (UINT16 swtmrId)
 Start a software timer.
 
UINT32 LOS_SwtmrStop (UINT16 swtmrId)
 Stop a software timer.
 
UINT32 LOS_SwtmrTimeGet (UINT16 swtmrId, UINT32 *tick)
 Obtain the number of remaining Ticks configured on a software timer.
 
UINT32 LOS_SwtmrCreate (UINT32 interval, UINT8 mode, SWTMR_PROC_FUNC handler, UINT16 *swtmrId, UINTPTR arg)
 Create a software timer.
 
UINT32 LOS_SwtmrDelete (UINT16 swtmrId)
 Delete a software timer.
 

详细描述

宏定义说明

◆ LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM

#define LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0a)

Software timer error code: Insufficient memory allocated by membox.

Value: 0x0200030a.

Solution: Expand the memory allocated by membox.

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_SWTMR_HWI_ACTIVE

#define LOS_ERRNO_SWTMR_HWI_ACTIVE   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x09)

Software timer error code: The software timer is being used during an interrupt.

Value: 0x02000309.

Solution: Change the source code and do not use the software timer during an interrupt.

◆ LOS_ERRNO_SWTMR_ID_INVALID

#define LOS_ERRNO_SWTMR_ID_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x05)

Software timer error code: Invalid software timer ID.

Value: 0x02000305.

Solution: Pass in a valid software timer ID.

◆ LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED

#define LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x01)

Software timer error code: The expiration time is 0.

Value: 0x02000301.

Solution: Re-define the expiration time.

◆ LOS_ERRNO_SWTMR_INVALID_SYNCDEL

#define LOS_ERRNO_SWTMR_INVALID_SYNCDEL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x12)

Software timer error code: Try to sync delete a software timer during an interrupt or a timer callback.

Value: 0x02000312.

Solution: Change the source code and do not sync delete a software timer during an interrupt or a timer callback.

◆ LOS_ERRNO_SWTMR_MAXSIZE

#define LOS_ERRNO_SWTMR_MAXSIZE   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x04)

Software timer error code: The number of software timers exceeds the configured permitted maximum number.

Value: 0x02000304.

Solution: Re-configure the permitted maximum number of software timers, or wait for a software timer to become available.

◆ LOS_ERRNO_SWTMR_MAXSIZE_INVALID

#define LOS_ERRNO_SWTMR_MAXSIZE_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x08)

Software timer error code: Invalid configured number of software timers.

Value: 0x02000308.

Solution: Re-configure the number of software timers.

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_SWTMR_MODE_INVALID

#define LOS_ERRNO_SWTMR_MODE_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x02)

Software timer error code: Invalid software timer mode.

Value: 0x02000302.

Solution: Check the mode value. The value range is [0,3].

◆ LOS_ERRNO_SWTMR_NO_MEMORY

#define LOS_ERRNO_SWTMR_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x07)

Software timer error code: Insufficient memory for software timer linked list creation.

Value: 0x02000307.

Solution: Allocate bigger memory partition to software timer linked list creation.

◆ LOS_ERRNO_SWTMR_NOT_CREATED

#define LOS_ERRNO_SWTMR_NOT_CREATED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x06)

Software timer error code: The software timer is not created.

Value: 0x02000306.

Solution: Create a software timer.

◆ LOS_ERRNO_SWTMR_NOT_STARTED

#define LOS_ERRNO_SWTMR_NOT_STARTED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0d)

Software timer error code: The software timer is not started.

Value: 0x0200030d.

Solution: Start the software timer.

◆ LOS_ERRNO_SWTMR_PTR_NULL

#define LOS_ERRNO_SWTMR_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x00)

Software timer error code: The timeout handling function is NULL.

Value: 0x02000300.

Solution: Define the timeout handling function.

◆ LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED

#define LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0b)

Software timer error code: The software timer queue fails to be created.

Value: 0x0200030b.

Solution: Check whether more memory can be allocated to the queue to be created.

◆ LOS_ERRNO_SWTMR_RET_PTR_NULL

#define LOS_ERRNO_SWTMR_RET_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x03)

Software timer error code: The passed-in software timer ID is NULL.

Value: 0x02000303.

Solution: Define the software timer ID before passing it in.

◆ LOS_ERRNO_SWTMR_SORTLINK_CREATE_FAILED

#define LOS_ERRNO_SWTMR_SORTLINK_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x11)

Software timer error code: The software sortlink fails to be created.

Value: 0x02000311.

Solution: Check whether the memory is sufficient and re-create the sortlink.

◆ LOS_ERRNO_SWTMR_SORTLIST_NULL

#define LOS_ERRNO_SWTMR_SORTLIST_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0f)

Software timer error code: This error code is not in use temporarily.

Value: 0x0200030f

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_SWTMR_STATUS_INVALID

#define LOS_ERRNO_SWTMR_STATUS_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0e)

Software timer error code: Invalid software timer state.

Value: 0x0200030e.

Solution: Check the software timer state.

◆ LOS_ERRNO_SWTMR_TASK_CREATE_FAILED

#define LOS_ERRNO_SWTMR_TASK_CREATE_FAILED   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x0c)

Software timer error code: The software timer task fails to be created.

Value: 0x0200030c.

Solution: Check whether the memory is sufficient and re-create the task.

◆ LOS_ERRNO_SWTMR_TICK_PTR_NULL

#define LOS_ERRNO_SWTMR_TICK_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_SWTMR, 0x10)

Software timer error code: The passed-in number of remaining Ticks configured on the software timer is NULL.

Value: 0x02000310.

Solution: Define a variable of the number of remaining Ticks before passing in the number of remaining Ticks.

◆ OS_SWTMR_HANDLE_QUEUE_SIZE

#define OS_SWTMR_HANDLE_QUEUE_SIZE   KERNEL_SWTMR_LIMIT

Maximum size of a software timer queue. The default value of LOSCFG_BASE_CORE_SWTMR_LIMIT is 16.

◆ OS_SWTMR_MAX_TIMERID

#define OS_SWTMR_MAX_TIMERID   ((0xFFFF / KERNEL_SWTMR_LIMIT) * KERNEL_SWTMR_LIMIT)

Max number of software timers ID

0xFFFF: max number of all software timers

类型定义说明

◆ SWTMR_PROC_FUNC

typedef void(* SWTMR_PROC_FUNC) (UINTPTR arg)

Define the type of a callback function that handles software timer timeout.

Description:
This API is used to define the type of a callback function that handles software timer timeout, so that it can be called when software timer timeout.
注意
None.
参数
arg[IN] the parameter of the callback function that handles software timer timeout.
返回值
None.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
自从
Huawei LiteOS V100R001C00

枚举类型说明

◆ enSwTmrType

Software timer mode

枚举值
LOS_SWTMR_MODE_ONCE 

One-off software timer, the value is 0.

LOS_SWTMR_MODE_PERIOD 

Periodic software timer, the value is 1.

LOS_SWTMR_MODE_NO_SELFDELETE 

One-off software timer, but not self-delete, the value is 2.

LOS_SWTMR_MODE_OPP 

After the one-off timer finishes timing, the periodic software timer is enabled. The value is 3. This mode is not supported temporarily.

函数说明

◆ LOS_SwtmrCreate()

UINT32 LOS_SwtmrCreate ( UINT32  interval,
UINT8  mode,
SWTMR_PROC_FUNC  handler,
UINT16 swtmrId,
UINTPTR  arg 
)
extern

Create a software timer.

Description:
This API is used to create a software timer that has specified timing duration, timeout handling function, and trigger mode, and to return a handle by which the software timer can be referenced.
注意
  • Do not use the delay interface in the callback function that handles software timer timeout.
  • There are LOSCFG_BASE_CORE_SWTMR_LIMIT timers available, change it's value when necessary.
参数
interval[IN] Timing duration of the software timer to be created (unit: tick).
mode[IN] Software timer mode. Pass in one of the modes specified by enSwTmrType. There are three types of modes, one-off, periodic, and continuously periodic after one-off, of which the third mode is not supported temporarily.
handler[IN] Callback function that handles software timer timeout.
swtmrId[OUT] Software timer ID created by LOS_SwtmrCreate.
arg[IN] Parameter passed in when the callback function that handles software timer timeout is called.
返回值
LOS_ERRNO_SWTMR_INTERVAL_NOT_SUITEDThe software timer timeout interval is 0.
LOS_ERRNO_SWTMR_MODE_INVALIDInvalid software timer mode.
LOS_ERRNO_SWTMR_PTR_NULLThe callback function that handles software timer timeout is NULL.
LOS_ERRNO_SWTMR_RET_PTR_NULLThe passed-in software timer ID is NULL.
LOS_ERRNO_SWTMR_MAXSIZEThe number of software timers exceeds the configured permitted maximum number.
LOS_OKThe software timer is successfully created.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
参见
LOS_SwtmrDelete
自从
Huawei LiteOS V100R001C00

◆ LOS_SwtmrDelete()

UINT32 LOS_SwtmrDelete ( UINT16  swtmrId)
extern

Delete a software timer.

Description:
This API is used to delete a software timer.
注意
The specific timer should be created and then stopped firstly.
参数
swtmrId[IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
返回值
LOS_ERRNO_SWTMR_ID_INVALIDInvalid software timer ID.
LOS_ERRNO_SWTMR_NOT_CREATEDThe software timer is not created.
LOS_ERRNO_SWTMR_STATUS_INVALIDInvalid software timer state.
LOS_OKThe software timer is successfully deleted.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
参见
LOS_SwtmrCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SwtmrStart()

UINT32 LOS_SwtmrStart ( UINT16  swtmrId)
extern

Start a software timer.

Description:
This API is used to start a software timer that has a specified ID.
注意
The specific timer must be created first.
参数
swtmrId[IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
返回值
LOS_ERRNO_SWTMR_ID_INVALIDInvalid software timer ID.
LOS_ERRNO_SWTMR_NOT_CREATEDThe software timer is not created.
LOS_ERRNO_SWTMR_STATUS_INVALIDInvalid software timer state.
LOS_OKThe software timer is successfully started.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
参见
LOS_SwtmrStop | LOS_SwtmrCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SwtmrStop()

UINT32 LOS_SwtmrStop ( UINT16  swtmrId)
extern

Stop a software timer.

Description:
This API is used to stop a software timer that has a specified ID.
注意
The specific timer should be created and started firstly.
参数
swtmrId[IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
返回值
LOS_ERRNO_SWTMR_ID_INVALIDInvalid software timer ID.
LOS_ERRNO_SWTMR_NOT_CREATEDThe software timer is not created.
LOS_ERRNO_SWTMR_NOT_STARTEDThe software timer is not started.
LOS_ERRNO_SWTMR_STATUS_INVALIDInvalid software timer state.
LOS_OKThe software timer is successfully stopped.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
参见
LOS_SwtmrStart | LOS_SwtmrCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_SwtmrTimeGet()

UINT32 LOS_SwtmrTimeGet ( UINT16  swtmrId,
UINT32 tick 
)
extern

Obtain the number of remaining Ticks configured on a software timer.

Description:
This API is used to obtain the number of remaining Ticks configured on the software timer of which the ID is specified by usSwTmrID.
注意
The specific timer should be created and started successfully, error happens otherwise.
参数
swtmrId[IN] Software timer ID created by LOS_SwtmrCreate. The value of ID should be in [0, LOSCFG_BASE_CORE_SWTMR_LIMIT - 1].
tick[OUT] Number of remaining Ticks configured on the software timer.
返回值
LOS_ERRNO_SWTMR_ID_INVALIDInvalid software timer ID.
LOS_ERRNO_SWTMR_TICK_PTR_NULLThe input parameter tick is a NULL pointer.
LOS_ERRNO_SWTMR_NOT_CREATEDThe software timer is not created.
LOS_ERRNO_SWTMR_NOT_STARTEDThe software timer is not started.
LOS_ERRNO_SWTMR_STATUS_INVALIDInvalid software timer state.
LOS_OKThe number of remaining Ticks is successfully obtained.
Dependency:
  • los_swtmr.h: the header file that contains the API declaration.
参见
LOS_SwtmrCreate
自从
Huawei LiteOS V100R001C00