This is the the starting version of autograder hardwrae
Fork of AutoGrader_HW_01 by
Diff: main.cpp
- Revision:
- 0:440ae480bff2
- Child:
- 1:97884b766b51
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Aug 24 01:36:23 2015 +0000 @@ -0,0 +1,115 @@ +#include "mbed.h" + +Ticker Read_Port; +PortIn DataIn(PortC, 0x000000FF); // p21-p26 +DigitalOut Reset(PTC12); +Serial Comm(USBTX, USBRX); + +#define RX_BUFF_SIZE 64 + +int rx_write_ptr=0; +int rx_read_ptr=0; +int RX_buff[RX_BUFF_SIZE]; + +int Data_avl; +int Port_Data; + +void Serial_Read_callback() +{ + RX_buff[rx_write_ptr++]=Comm.getc(); + if(rx_write_ptr >= RX_BUFF_SIZE) + rx_write_ptr=0; + +} + +int Serial_Read() +{ + int temp; + + temp=RX_buff[rx_read_ptr++]; + if(rx_read_ptr >= RX_BUFF_SIZE) + rx_read_ptr=0; + return temp; +} + +int Serial_Available() +{ + if(rx_read_ptr != rx_write_ptr) + return 1; + else + return 0; +} + +void Read_Port_callback() +{ + Port_Data=DataIn.read(); + Data_avl=1; +} + +int main() +{ + int ch; + int state=0; + int cmd; + int new_frame; + int run_debug; + Comm.baud(115200); + Comm.attach(&Serial_Read_callback); + + while(true) + { + if(Serial_Available()) + { + ch=Serial_Read(); + switch (state) + { + case 0: if(ch == '<') + state++; + break; + + case 1: cmd = ch; + state++; + break; + + case 2: if(ch == '>') + { + state=0; + new_frame =1; + } + break; + + + }//switch + + + }//Serial_available + + if(new_frame) + { + new_frame =0; + + if(cmd == 'P') + { + Read_Port.attach(&Read_Port_callback,0.1); + Reset=0; + wait(0.01); + Reset=1; + run_debug=1; + } + else if(cmd == 'X') + { + Read_Port.detach(); + run_debug=0; + } + + } + if(run_debug) + { + if(Data_avl) + { + Comm.printf("<%d>",Port_Data); + } + } + + }//while +}