isr example

main.cpp

Committer:
mab5449
Date:
2017-01-13
Revision:
4:40078e697304
Parent:
2:3ded4c6c9dff
Child:
7:985db97e8ae0

File content as of revision 4:40078e697304:

#include "mbed.h"

Thread thread;
Ticker ticker;
Queue<uint32_t, 5> queue;
DigitalOut myled(LED1);

void queue_isr() {
    queue.put((uint32_t*)2);
    myled = !myled;
}

void queue_thread() {
    while (true) {
        queue.put((uint32_t*)1);
        wait(1);
    }
}

int main (void) {
    thread.start(callback(queue_thread));
    ticker.attach(queue_isr, 1.0);

    while (true) {
        osEvent evt = queue.get();
        if (evt.status != osEventMessage) {
            printf("queue->get() returned %02x status\n\r", evt.status);
        } else {
            printf("queue->get() returned %d\n\r", evt.value.v);
        }
    }
}