API函数
//创建
void OSTmrCreate (OS_TMR *p_tmr,
CPU_CHAR *p_name,
OS_TICK dly,
OS_TICK period,
OS_OPT opt,
OS_TMR_CALLBACK_PTR p_callback,
void *p_callback_arg,
OS_ERR *p_err);
//删除
CPU_BOOLEAN OSTmrDel (OS_TMR *p_tmr,
OS_ERR *p_err);
//获取剩余时间
OS_TICK OSTmrRemainGet (OS_TMR *p_tmr,
OS_ERR *p_err);
//启动
CPU_BOOLEAN OSTmrStart (OS_TMR *p_tmr,
OS_ERR *p_err);
//获取当前定时器状态
OS_STATE OSTmrStateGet (OS_TMR *p_tmr,
OS_ERR *p_err);
//停止
CPU_BOOLEAN OSTmrStop (OS_TMR *p_tmr,
OS_OPT opt,
void *p_callback_arg,
OS_ERR *p_err);
举例
OSTmrCreate((OS_TMR *)&tmr, //定时器
(CPU_CHAR *)"tmr", //定时器名字
(OS_TICK )20, //20*10=200ms
(OS_TICK )100, //100*10=1000ms
(OS_OPT )OS_OPT_TMR_PERIODIC, //周期模式
(OS_TMR_CALLBACK_PTR)tmr_callback,//定时器回调函数
(void *)0, //参数为0
(OS_ERR *)&err); //返回的错误码
//定时器的回调函数
void tmr_callback(void *p_tmr, void *p_arg)
{
static u8 tmr_num=0;
tmr_num++; //定时器执行次数加1
printf("定时器运行结束
");
}
int main()
{
OSTmrStart(&tmr, &err); //开启定时器
OSTmrStop(&tmr, OS_OPT_TMR_NONE, 0, &err); //关闭定时器
return 0;
}
实验现象