- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# drivers/led/blink.c

Go to the documentation of this file.

    00001
    00041 #include <led.h>
    00042 #include <softirq.h>
    00043 #include <app/timer.h>
    00044
    00045 static void led_blink_toggle(void *data)
    00046 {
    00047         struct blinking_led     *blink = data;
    00048
    00049         if (!blink->enabled) {
    00050                 blink->active = false;
    00051                 return;
    00052         }
    00053
    00054         if (blink->state) {
    00055                 blink->state = false;
    00056                 led_deactivate(blink->led);
    00057         } else {
    00058                 blink->state = true;
    00059                 led_activate(blink->led);
    00060         }
    00061
    00062         timer_add_task_us(&led_timer, &blink->task,
    00063                         blink->period_ms * 1000);
    00064 }
    00065
    00070 void led_blink_start(struct blinking_led *blink)
    00071 {
    00072         softirq_disable();
    00073         if (!blink->enabled) {
    00074                 blink->enabled = true;
    00075                 if (!blink->active) {
    00076                         blink->state = false;
    00077                         led_deactivate(blink->led);
    00078                         timer_add_task_us(&led_timer, &blink->task,
    00079                                         blink->period_ms * 1000);
    00080                 }
    00081         }
    00082         softirq_enable();
    00083 }
    00084
    00089 void led_blink_stop(struct blinking_led *blink)
    00090 {
    00091         softirq_disable();
    00092         blink->enabled = false;
    00093         softirq_enable();
    00094 }
    00095
    00103 void led_blink_init(struct blinking_led *blink, enum board_led_id led,
    00104                 unsigned int period_ms)
    00105 {
    00106         blink->led = led;
    00107         blink->period_ms = period_ms;
    00108         timer_init_task(&blink->task, led_blink_toggle, blink);
    00109         blink->enabled = false;
    00110         blink->active = false;
    00111 }