nxp zigbee软件定时器使用方法

本文详细介绍了嵌入式系统中定时器的六个关键API:初始化、打开、开始、停止、关闭和获取状态。通过具体示例展示了如何使用这些API进行定时器的配置和控制,适用于嵌入式软件开发人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 初始化定时器:
ZTIMER_teStatus ZTIMER_eInit(ZTIMER_tsTimer *psTimers,uint8 u8NumTimers);
psTimers Pointer to an array of structures, where each array element contains information for
one timer
u8NumTimers Number of timers in the above array

–>eg: ZTIMER_eInit(asTimers, sizeof(asTimers) / sizeof(ZTIMER_tsTimer));
– PRIVATE ZTIMER_tsTimer asTimers[APP_ZTIMER_STORAGE +BDB_ZTIMER_STORAGE];

2. 打开定时器:
ZTIMER_teStatus ZTIMER_eOpen(
uint8 *pu8TimerIndex,
ZTIMER_tpfCallback pfCallback,
void *pvParams,
uint8 u8Flags);

pu8TimerIndex Pointer to location containing the index number of the timer in the list of timers
initialised using ZTIMER_eInit()
pfCallback Pointer to the user-defined callback function for the timer
pvParams Pointer to a list of parameter values for the timer
u8Flags Flag indicating whether the timer should allow or prevent sleep, one of:
ZTIMER_FLAG_ALLOW_SLEEP
ZTIMER_FLAG_PREVENT_SLEEP

–>eg: ZTIMER_eOpen(&u8TimerButtonScan, APP_cbTimerButtonScan, NULL,
ZTIMER_FLAG_PREVENT_SLEEP);
– PUBLIC uint8 u8TimerButtonScan;
– PUBLIC void APP_cbTimerButtonScan(void *pvParam){};

–>eg: ZTIMER_eOpen(&u8TimerZCL, APP_cbTimerZclTick, NULL,
ZTIMER_FLAG_PREVENT_SLEEP);
– PUBLIC uint8 u8TimerZCL;
– PUBLIC void APP_cbTimerZclTick(void *pvParam){};

3.开始定时器:
//Before a timer is started, it must have been opened using ZTIMER_eOpen()
ZTIMER_teStatus ZTIMER_eStart(uint8 u8TimerIndex,uint32 u32Time);

pu8TimerIndex Index number of the timer in the list of timers initialised using ZTIMER_eInit()
u32Time The time, in milliseconds, for which the timer should run

–> eg: ZTIMER_eStart(u8TimerButtonScan, ZTIMER_TIME_MSEC(10));
#define ZTIMER_TIME_SEC(v) ((uint32)(v) * 1000UL)
#define ZTIMER_TIME_MSEC(v) ((uint32)(v) * 1UL)

4. 停止定时器:
//The timer must have been previously started using ZTIMER_eStart()
ZTIMER_teStatus ZTIMER_eStop(uint8 u8TimerIndex);
pu8TimerIndex Index number of the timer in the list of timers initialised using ZTIMER_eInit()

–>eg: ZTIMER_eStop(u8TimerButtonScan);

5.关定时器:
//The timer must have been previously opened using ZTIMER_eOpen()
ZTIMER_teStatus ZTIMER_eClose(uint8 u8TimerIndex);

–>eg: ZTIMER_eClose(u8TimerButtonScan);

6.获取定时器状态:
ZTIMER_teState ZTIMER_eGetState(uint8 u8TimerIndex);
The possible reported states are:
 Running Stopped Expired Closed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值