Course project for LE484 at Thammasat University, class of 2016

Committer:
vsupacha
Date:
Mon May 08 04:15:22 2017 +0000
Revision:
5:d35cd42da2ac
Parent:
4:3aaedd16c77b
Child:
6:da3c4393efee
Add platform.h

Who changed what in which revision?

UserRevisionLine numberNew 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 5:d35cd42da2ac 8 #include "platform.h"
vsupacha 0:aefb68fd2505 9
vsupacha 0:aefb68fd2505 10 DigitalOut led1(LED1);
vsupacha 0:aefb68fd2505 11
vsupacha 3:e38819a2b38c 12 RawSerial pc(USBTX, USBRX); // use USB-serial for testing purpose
vsupacha 3:e38819a2b38c 13 Mail<char, 2> mbx; // use Mail API to forward data
vsupacha 3:e38819a2b38c 14
vsupacha 3:e38819a2b38c 15 /**
vsupacha 3:e38819a2b38c 16 * @brief ISR code: reception of XBee API frame
vsupacha 3:e38819a2b38c 17 */
vsupacha 3:e38819a2b38c 18 void rxHandler() {
vsupacha 3:e38819a2b38c 19 char *mail = mbx.alloc();
vsupacha 3:e38819a2b38c 20 *mail = pc.getc();
vsupacha 3:e38819a2b38c 21 mbx.put(mail);
vsupacha 3:e38819a2b38c 22 }
vsupacha 3:e38819a2b38c 23
vsupacha 3:e38819a2b38c 24
vsupacha 3:e38819a2b38c 25 /**
vsupacha 3:e38819a2b38c 26 * @brief Main code: initial serial RX handler, then wait for detected frame
vsupacha 3:e38819a2b38c 27 */
vsupacha 0:aefb68fd2505 28 int main() {
vsupacha 3:e38819a2b38c 29 pc.attach(rxHandler);
vsupacha 0:aefb68fd2505 30 while (true) {
vsupacha 3:e38819a2b38c 31 osEvent evt = mbx.get();
vsupacha 3:e38819a2b38c 32 if (evt.status == osEventMail) {
vsupacha 4:3aaedd16c77b 33 char *mail = (char*)evt.value.p;
vsupacha 3:e38819a2b38c 34 pc.printf("Got %c\n", *mail);
vsupacha 3:e38819a2b38c 35 mbx.free(mail);
vsupacha 3:e38819a2b38c 36 }
vsupacha 0:aefb68fd2505 37 }
vsupacha 0:aefb68fd2505 38 }
vsupacha 0:aefb68fd2505 39