X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee-avr.git;a=blobdiff_plain;f=beep.c;h=1a31186da2a2e4ed573f865d37a8edc804bf5a7c;hp=f34219c020527015b87307c7ab29cf6687b67059;hb=HEAD;hpb=9a43add2f0ed382ce1f180bba65fdc077d03b6fb diff --git a/beep.c b/beep.c index f34219c..1a31186 100644 --- a/beep.c +++ b/beep.c @@ -31,18 +31,19 @@ #include #include -#include #include #include "main.h" /* 100 ms */ -#define BEEP_PERIOD (100000UL/SCHEDULER_UNIT) +#define BEEP_PERIOD_MS 100 static struct cirbuf beep_fifo; static char beep_fifo_buf[16]; volatile uint8_t beep_mask = 1; /* init beep */ +static struct callout beep_timer; + union beep_t { uint8_t u08; struct { @@ -54,14 +55,15 @@ union beep_t { static volatile union beep_t current_beep; /* called by the scheduler */ -static void beep_cb(void *arg) +static void beep_cb(struct callout_mgr *cm, struct callout *tim, void *arg) { (void)arg; beep_mask = 0; if (current_beep.len == 0 && current_beep.pause == 0) { if (CIRBUF_GET_LEN(&beep_fifo) == 0) - return; + goto reschedule; + current_beep.u08 = cirbuf_get_head(&beep_fifo); cirbuf_del_head(&beep_fifo); } @@ -75,12 +77,15 @@ static void beep_cb(void *arg) case 3: beep_mask = 8; break; default: break; } - return; + goto reschedule; } if (current_beep.pause > 0) { current_beep.pause --; } + + reschedule: + callout_reschedule(cm, tim, BEEP_PERIOD_MS); } void beep(uint8_t tone, uint8_t len, uint8_t pause) @@ -99,6 +104,6 @@ void beep(uint8_t tone, uint8_t len, uint8_t pause) void beep_init(void) { cirbuf_init(&beep_fifo, beep_fifo_buf, 0, sizeof(beep_fifo_buf)); - scheduler_add_periodical_event_priority(&beep_cb, NULL, - BEEP_PERIOD, BEEP_PRIO); + callout_init(&beep_timer, beep_cb, NULL, BEEP_PRIO); + callout_schedule(&xbeeboard.intr_cm, &beep_timer, BEEP_PERIOD_MS); }