Hi
对于应用层,想在某个时刻唤醒的话,用soft timer就可以达到目的,参考handbook描述的如下demo
Demo
blt soft timer的Demo code请参考B91m (B91 and B92) feature中TEST_USER_BLT_SOFT_TIMER。
int gpio_test0(void)
{
//GPIO toggle to see the effect
gpio_toggle(GPIO_LED_BLUE);
return 0;
}
_attribute_ble_data_retention_ static u8 timer_change_flg = 0;
int gpio_test1(void)
{
//GPIO toggle to see the effect
gpio_toggle(GPIO_LED_GREEN);
timer_change_flg = !timer_change_flg;
if (timer_change_flg) {
return 7000;
} else {
return 17000;
}
}
int gpio_test2(void)
{
//GPIO toggle to see the effect
gpio_toggle(GPIO_LED_WHITE);
//timer last for 5 second
if (clock_time_exceed(0, 5000000)) {
//return -1;
//blt_soft_timer_delete(&gpio_test2);
} else {
}
return 0;
}
int gpio_test3(void)
{
//GPIO toggle to see the effect
gpio_toggle(GPIO_LED_RED);
;
return 0;
}
初始化:
##if (BLT_SOFTWARE_TIMER_ENABLE)
blt_soft_timer_init();
blt_soft_timer_add(&gpio_test0, 23000); //23ms
blt_soft_timer_add(&gpio_test1, 7000); //7ms <-> 17ms
blt_soft_timer_add(&gpio_test2, 13000); //13ms
blt_soft_timer_add(&gpio_test3, 100000); //100ms
##endif
定义了4个任务,这4个定时任务各有特点:
(1) gpio_test0每23ms toggle一次。
(2) gpio_test1使用了7ms/17ms两个时间的切换定时。
(3) gpio_test2在系统运行5s后将自己删掉。代码中有两种方式可以实现这个功能:一是调用blt_soft_timer_delete(&gpio_test2);二是return -1。
(4) gpio_test3每100ms toggle一次。
谢谢
|