Course project for LE484 at Thammasat University, class of 2016

Committer:
vsupacha
Date:
Mon May 08 05:11:22 2017 +0000
Revision:
12:845639da2f03
Parent:
11:8b9668e37646
Parent:
10:25704cab4585
Fix wrong code

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
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 12:845639da2f03 13 Thread sensorThread;
vsupacha 12:845639da2f03 14 Thread ledThread;
natanich 11:8b9668e37646 15
vsupacha 3:e38819a2b38c 16
vsupacha 3:e38819a2b38c 17 /**
vsupacha 3:e38819a2b38c 18 * @brief ISR code: reception of XBee API frame
vsupacha 3:e38819a2b38c 19 */
vsupacha 12:845639da2f03 20 void rxHandler()
vsupacha 12:845639da2f03 21 {
vsupacha 12:845639da2f03 22 char *mail = mbx.alloc();
vsupacha 3:e38819a2b38c 23 *mail = pc.getc();
vsupacha 3:e38819a2b38c 24 mbx.put(mail);
vsupacha 3:e38819a2b38c 25 }
vsupacha 3:e38819a2b38c 26
vsupacha 3:e38819a2b38c 27
vsupacha 3:e38819a2b38c 28 /**
vsupacha 12:845639da2f03 29 * @brief Main code: initial serial RX handler, then wait for detected frame
vsupacha 3:e38819a2b38c 30 */
vsupacha 12:845639da2f03 31 int main()
vsupacha 12:845639da2f03 32 {
vsupacha 12:845639da2f03 33 ledThread.start(led1_thread);
vsupacha 12:845639da2f03 34 sensorThread.start(sensorIn);
3ecauz 7:d702abfe51e3 35 pc.attach(rxHandler);
vsupacha 0:aefb68fd2505 36 while (true) {
vsupacha 3:e38819a2b38c 37 osEvent evt = mbx.get();
vsupacha 3:e38819a2b38c 38 if (evt.status == osEventMail) {
vsupacha 4:3aaedd16c77b 39 char *mail = (char*)evt.value.p;
vsupacha 3:e38819a2b38c 40 pc.printf("Got %c\n", *mail);
vsupacha 3:e38819a2b38c 41 mbx.free(mail);
vsupacha 3:e38819a2b38c 42 }
vsupacha 0:aefb68fd2505 43 }
vsupacha 0:aefb68fd2505 44 }
vsupacha 0:aefb68fd2505 45