本帖最后由 zhanxiao 于 2022-9-24 16:20 编辑
我现在只想到在ble ready后调用定时器
先定义 msg
enum user_msg_id
{
APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER,
APP_CUSTS_2MS_MAIN_LOOP,//4 2ms
APP_CUSTS_5MS_AD,
APP_CUSTS_10MS_LED,
APP_CUSTS_10MS_KEY,
APP_CUSTS_10MS_WIRELESS,
APP_CUSTS_10MS_MISC,
APP_CUSTS_100MS_HINT,
};
然后在APP_BLE_OS_READY调用v_ble_init_ok_callback启动定时器
void v_ble_init_ok_callback(void)
{
ke_timer_set(APP_CUSTS_100MS_HINT, TASK_APP, 101);
ke_timer_set(APP_CUSTS_10MS_MISC, TASK_APP, 13);
ke_timer_set(APP_CUSTS_10MS_KEY, TASK_APP, 12);
ke_timer_set(APP_CUSTS_10MS_WIRELESS, TASK_APP, 11);
ke_timer_set(APP_CUSTS_10MS_LED, TASK_APP, 10);
ke_timer_set(APP_CUSTS_5MS_AD, TASK_APP, 5);
ke_timer_set(APP_CUSTS_2MS_MAIN_LOOP, TASK_APP, 2);
}
然后在msg的回调里面处理数据:
void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param)
{
#ifndef USE_RWIP
switch (msgid)
{
//case APP_CUSTS_TEST_EVT:
// break;
default:
break;
}
#else
extern void v_cust_handler(ke_msg_id_t const msgid);
v_cust_handler(msgid);
#endif
}
void v_cust_handler(ke_msg_id_t const msgid)
{
extern uint8_t fg_wakeup_by_acc;
if(WORK_ST_OFF==e_flow_work_st)
{
}
else
{
switch ( msgid )
{
case APP_CUSTS_2MS_MAIN_LOOP:
v_2ms_main_loop();
ke_timer_set(APP_CUSTS_2MS_MAIN_LOOP, TASK_APP, 2);
break;
case APP_CUSTS_5MS_AD:
v_5ms_ad_loop();
ke_timer_set(APP_CUSTS_5MS_AD, TASK_APP, 5);
break;
case APP_CUSTS_10MS_LED:
v_10ms_led_process();
ke_timer_set(APP_CUSTS_10MS_LED, TASK_APP, 10);
break;
case APP_CUSTS_10MS_KEY:
v_10ms_key_process();
ke_timer_set(APP_CUSTS_10MS_KEY, TASK_APP, 12);
break;
case APP_CUSTS_10MS_WIRELESS:
v_10ms_wireless_process();
ke_timer_set(APP_CUSTS_10MS_WIRELESS, TASK_APP, 11);
break;
case APP_CUSTS_10MS_MISC:
v_10ms_misc_process();
ke_timer_set(APP_CUSTS_10MS_MISC, TASK_APP, 13);
break;
case APP_CUSTS_100MS_HINT:
v_100ms_loop_process();
#ifdef IWDG_ADDED
IWDG_ReloadKey();
#endif
ke_timer_set(APP_CUSTS_100MS_HINT, TASK_APP, 101);
break;
default:
break;
}
}
}
我的led处理里面比较耗时,但是也最多2ms,有一个uart中断,中断中只是idle收DMA接收到的数据(rdtss的例程里面的)
systick 中断,中断中只有变量简单操作
#define TIMER_GO(timer) {if(timer>TIMER_STOP) timer++;}
void tick_handler (void)
{
d_system_time_clock++;
if (delay_timer > TIMER_STOP)
delay_timer++;
if (timer_10ms_tick < 14)
timer_10ms_tick++;
else
{
timer_10ms_tick = 0;
fg_10ms_trigger = TRUE;
}
if (timer_2ms_tick < 1)
timer_2ms_tick++;
else
{
timer_2ms_tick = 0;
fg_2ms_trigger = TRUE;
}
if (timer_5ms_tick < 6)
timer_5ms_tick++;
else
{
timer_5ms_tick = 0;
fg_5ms_trigger = TRUE;
}
if (timer_100ms_tick < 100)
timer_100ms_tick++;
else
{
timer_100ms_tick = 0;
fg_100ms_trigger = TRUE;
}
if (timer_1000ms_tick < 1000)
timer_1000ms_tick++;
else
{
fg_1000ms_trigger=TRUE;
timer_1000ms_tick=0;
}
TIMER_GO(w_refresh_guard_timer);
TIMER_GO(w_system_sleep_timer);
TIMER_GO(w_power_delay_timer);
TIMER_GO(w_recv_bt_timerout);
TIMER_GO(w_send_timer_out);
}
还有一个IO中断,
void v_wakeup_on(void)
{
if ( EXTI_GetITStatus(KEY_INPUT_EXTI_LINE)!= RESET)
{
if(now_not_insleep==FALSE)
fg_wakeup_by_acc=TRUE;
EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE);
}
}
我使用发现有2个问题:
1:time定时不准,明显慢
2:遇到死机的情况(几个小时可能会出现,没有手机连接过蓝牙),因为所有IO都被使用了,无法跟踪,
版主,有什么建议?
|