NXP

nxp zigbee软件定时器使用方法

2019-07-12 11:17发布

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