Supachai Vorapojpisut
/
le484_2016
Course project for LE484 at Thammasat University, class of 2016
main.cpp@3:e38819a2b38c, 2017-05-08 (annotated)
- Committer:
- vsupacha
- Date:
- Mon May 08 04:05:24 2017 +0000
- Revision:
- 3:e38819a2b38c
- Parent:
- 2:d117505b89ce
- Child:
- 4:3aaedd16c77b
Try Mail API to forward data from ISR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsupacha | 0:aefb68fd2505 | 1 | /** |
vsupacha | 0:aefb68fd2505 | 2 | * @brief Main loop: XBee protocol handler |
natanich | 2:d117505b89ce | 3 | * @author Supachai Vorapojpisut,Vissarut Prakobpon , Natanich Bunsila |
vsupacha | 0:aefb68fd2505 | 4 | * @date May 8, 2017 |
vsupacha | 0:aefb68fd2505 | 5 | */ |
vsupacha | 0:aefb68fd2505 | 6 | |
vsupacha | 0:aefb68fd2505 | 7 | #include "mbed.h" |
vsupacha | 0:aefb68fd2505 | 8 | |
vsupacha | 0:aefb68fd2505 | 9 | DigitalOut led1(LED1); |
vsupacha | 0:aefb68fd2505 | 10 | |
vsupacha | 3:e38819a2b38c | 11 | RawSerial pc(USBTX, USBRX); // use USB-serial for testing purpose |
vsupacha | 3:e38819a2b38c | 12 | Mail<char, 2> mbx; // use Mail API to forward data |
vsupacha | 3:e38819a2b38c | 13 | |
vsupacha | 3:e38819a2b38c | 14 | /** |
vsupacha | 3:e38819a2b38c | 15 | * @brief ISR code: reception of XBee API frame |
vsupacha | 3:e38819a2b38c | 16 | */ |
vsupacha | 3:e38819a2b38c | 17 | void rxHandler() { |
vsupacha | 3:e38819a2b38c | 18 | char *mail = mbx.alloc(); |
vsupacha | 3:e38819a2b38c | 19 | *mail = pc.getc(); |
vsupacha | 3:e38819a2b38c | 20 | mbx.put(mail); |
vsupacha | 3:e38819a2b38c | 21 | } |
vsupacha | 3:e38819a2b38c | 22 | |
vsupacha | 3:e38819a2b38c | 23 | |
vsupacha | 3:e38819a2b38c | 24 | /** |
vsupacha | 3:e38819a2b38c | 25 | * @brief Main code: initial serial RX handler, then wait for detected frame |
vsupacha | 3:e38819a2b38c | 26 | */ |
vsupacha | 0:aefb68fd2505 | 27 | int main() { |
vsupacha | 3:e38819a2b38c | 28 | pc.attach(rxHandler); |
vsupacha | 0:aefb68fd2505 | 29 | while (true) { |
vsupacha | 3:e38819a2b38c | 30 | osEvent evt = mbx.get(); |
vsupacha | 3:e38819a2b38c | 31 | if (evt.status == osEventMail) { |
vsupacha | 3:e38819a2b38c | 32 | char *mail = (mail_t*)evt.value.p; |
vsupacha | 3:e38819a2b38c | 33 | pc.printf("Got %c\n", *mail); |
vsupacha | 3:e38819a2b38c | 34 | mbx.free(mail); |
vsupacha | 3:e38819a2b38c | 35 | } |
vsupacha | 0:aefb68fd2505 | 36 | } |
vsupacha | 0:aefb68fd2505 | 37 | } |
vsupacha | 0:aefb68fd2505 | 38 |