-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
40 lines (34 loc) · 966 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
36
37
38
39
40
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
static DigitalOut led1(LED1);
static DigitalOut led2(LED2);
static BufferedSerial device(STDIO_UART_TX, STDIO_UART_RX);
static void callback_ex()
{
// always read until data is exhausted - we may not get another
// sigio otherwise
while (1) {
char c;
if (device.read(&c, 1) != 1) {
break;
}
putchar(c);
putchar('\n');
led2 = !led2;
}
}
int main()
{
// Ensure that device.read() returns -EAGAIN when out of data
device.set_blocking(false);
// sigio callback is deferred to event queue, as we cannot in general
// perform read() calls directly from the sigio() callback.
device.sigio(mbed_event_queue()->event(callback_ex));
while (1) {
led1 = !led1;
ThisThread::sleep_for(500);
}
}