]> git.droids-corp.org - protos/xbee-avr.git/commitdiff
remove mainloop callout manager (all is handled under intr)
authorOlivier Matz <zer0@droids-corp.org>
Thu, 6 Mar 2014 17:17:51 +0000 (18:17 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 9 Mar 2014 21:13:08 +0000 (22:13 +0100)
commands.c
commands_gen.c
main.c
main.h
xbee_user.c

index ffcd918e1024a74750816eef4c02ea6b7fad0d50..cf060fc902fc3d77eca8c26e5f87b8b09d614b33 100644 (file)
@@ -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;
        }
index d09d69ef933673f047eac7df217458ba705a600d..f1039b3ab323350e4421befff67f767c188f6c16 100644 (file)
@@ -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 1b9bc971fca111c87614b7699955904608d813ed..11fd44234ed6c51f0a20e6bbea800a10a7dd58d2 100644 (file)
--- 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 18ddf0514d8c19c763a1599512b4e68b717b6dfc..afb1c3e132b9dca583a9b9e999f53a09d2f5f5ce 100644 (file)
--- 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;
index ecca81686feb4675f1f4a2db1631e9c191ac6a0f..26fe26116cd7a6e76601e45e69c907bad341ee6a 100644 (file)
@@ -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;