From 64ee3de535747a69cb7467e05bcecec211623e63 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Thu, 6 Mar 2014 18:17:51 +0100 Subject: [PATCH] remove mainloop callout manager (all is handled under intr) --- commands.c | 18 +++++++++--------- commands_gen.c | 3 --- main.c | 1 - main.h | 2 +- xbee_user.c | 16 +++++++++++----- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/commands.c b/commands.c index ffcd918..cf060fc 100644 --- a/commands.c +++ b/commands.c @@ -753,18 +753,18 @@ static void cmd_range_parsed(void *parsed_result, void *data) return; } range_cur_count = range_count; - callout_init(&range_event, range_cb, NULL, 0); - callout_schedule(&xbeeboard.mainloop_cm, - &range_event, 0); /* immediate */ + callout_init(&range_event, range_cb, NULL, LOW_PRIO); range_running = 1; + callout_schedule(&xbeeboard.intr_cm, + &range_event, 0); /* immediate */ } else if (!strcmp(res->action, "end")) { if (range_running == 0) { printf_P(PSTR("not running\r\n")); return; } + callout_stop(&xbeeboard.intr_cm, &range_event); range_running = 0; - callout_stop(&xbeeboard.mainloop_cm, &range_event); } } @@ -1003,11 +1003,11 @@ static void cmd_monitor_parsed(void *parsed_result, void *data) printf_P(PSTR("no regs to be monitored\r\n")); return; } - callout_init(&monitor_event, monitor_cb, NULL, 0); - callout_schedule(&xbeeboard.mainloop_cm, - &monitor_event, 0); /* immediate */ + callout_init(&monitor_event, monitor_cb, NULL, 1); monitor_running = 1; monitor_current = LIST_FIRST(&xbee_monitor_list); + callout_schedule(&xbeeboard.intr_cm, + &monitor_event, 0); /* immediate */ printf_P(PSTR("monitor cb: %S %s\r\n"), monitor_current->desc, monitor_current->atcmd); @@ -1018,8 +1018,8 @@ static void cmd_monitor_parsed(void *parsed_result, void *data) printf_P(PSTR("not running\r\n")); return; } + callout_stop(&xbeeboard.intr_cm, &monitor_event); monitor_running = 0; - callout_stop(&xbeeboard.mainloop_cm, &monitor_event); } } @@ -1182,7 +1182,7 @@ static void cmd_monitor_del_parsed(void *parsed_result, void *data) monitor_count --; if (monitor_count == 0) { printf_P(PSTR("Disable monitoring, no more event\r\n")); - callout_stop(&xbeeboard.mainloop_cm, &monitor_event); + callout_stop(&xbeeboard.intr_cm, &monitor_event); monitor_running = 0; return; } diff --git a/commands_gen.c b/commands_gen.c index d09d69e..f1039b3 100644 --- a/commands_gen.c +++ b/commands_gen.c @@ -122,10 +122,7 @@ static void cmd_callout_parsed(void *parsed_result, void *data) { (void)parsed_result; (void)data; - printf_P(PSTR("intr_cm:\n")); callout_dump_stats(&xbeeboard.intr_cm); - printf_P(PSTR("mainloop_cm:\n")); - callout_dump_stats(&xbeeboard.mainloop_cm); } const char PROGMEM str_callout_arg0[] = "callout"; diff --git a/main.c b/main.c index 1b9bc97..11fd442 100644 --- a/main.c +++ b/main.c @@ -157,7 +157,6 @@ int main(void) timer0_register_OV_intr(main_timer_interrupt); callout_mgr_init(&xbeeboard.intr_cm, get_time_ms); - callout_mgr_init(&xbeeboard.mainloop_cm, get_time_ms); cmdline_init(); spi_servo_init(); diff --git a/main.h b/main.h index 18ddf05..afb1c3e 100644 --- a/main.h +++ b/main.h @@ -64,6 +64,7 @@ #define BEEP_PRIO 120 #define SPI_PRIO 100 /* users of spi_servo must have lower prio */ #define XBEE_PRIO 80 +#define LOW_PRIO 60 /* lowest priority */ #define MAX_POWER_LEVEL 5 @@ -73,7 +74,6 @@ struct xbeeboard { struct rdline rdl; char prompt[RDLINE_PROMPT_SIZE]; - struct callout_mgr mainloop_cm; struct callout_mgr intr_cm; struct callout spi_timer; struct callout beep_timer; diff --git a/xbee_user.c b/xbee_user.c index ecca816..26fe261 100644 --- a/xbee_user.c +++ b/xbee_user.c @@ -517,13 +517,21 @@ static void evt_timeout(struct callout_mgr *cm, struct callout *clt, void xbee_load_timeout(struct xbee_ctx *ctx) { - callout_init(&ctx->timeout, evt_timeout, ctx, 0); - callout_schedule(&xbeeboard.mainloop_cm, &ctx->timeout, XBEE_TIMEOUT_MS); + uint8_t prio; + + callout_init(&ctx->timeout, evt_timeout, ctx, XBEE_PRIO); + prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO); + callout_schedule(&xbeeboard.intr_cm, &ctx->timeout, XBEE_TIMEOUT_MS); + callout_mgr_restore_prio(&xbeeboard.intr_cm, prio); } void xbee_unload_timeout(struct xbee_ctx *ctx) { - callout_stop(&xbeeboard.mainloop_cm, &ctx->timeout); + uint8_t prio; + + prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO); + callout_stop(&xbeeboard.intr_cm, &ctx->timeout); + callout_mgr_restore_prio(&xbeeboard.intr_cm, prio); } static void xbee_rx_poll_timer_cb(struct callout_mgr *cm, struct callout *tim, @@ -539,8 +547,6 @@ void xbee_mainloop(void) uint8_t prio; while (1) { - callout_manage(&xbeeboard.mainloop_cm); - if (xbee_raw) { int16_t c; -- 2.39.5