-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
35 lines (31 loc) · 861 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "mbed_events.h"
DigitalOut led1(LED1);
InterruptIn sw(SW2);
void rise_handler(void)
{
// Toggle LED
led1 = !led1;
}
void fall_handler(void)
{
printf("fall_handler in context %p\r\n", ThisThread::get_id());
// Toggle LED
led1 = !led1;
}
int main()
{
// Request the shared queue
EventQueue *queue = mbed_event_queue();
printf("Starting in context %p\r\n", ThisThread::get_id());
// The 'rise' handler will execute in IRQ context
sw.rise(rise_handler);
// The 'fall' handler will execute in the context of the shared queue (actually the main thread)
sw.fall(queue->event(fall_handler));
// Setup complete, so we now dispatch the shared queue from main
queue->dispatch_forever();
}