This is the the starting version of autograder hardwrae
Fork of AutoGrader_HW_01 by
main.cpp
- Committer:
- naray23
- Date:
- 2015-08-31
- Revision:
- 1:97884b766b51
- Parent:
- 0:440ae480bff2
- Child:
- 2:b3286d232452
File content as of revision 1:97884b766b51:
#include "mbed.h" Ticker Read_Port; //Timer Polling PortIn DataIn(PortC, 0x000000FF); // p21-p26 DigitalOut Reset(PTC12); //ptc12 reset 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; int Port_Data_prev=0; int Time_cntr=0; 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(); if((Port_Data ^ Port_Data_prev) != 0) { Data_avl=1; Port_Data_prev=Port_Data; } Time_cntr++; } int main() { int ch; int state=0; int cmd=0;; int paramval[3][3]; int paramstate=0; int paramdigcnt=0; int new_frame=0; int run_debug=0; float scan_time; Comm.baud(115200); Comm.attach(&Serial_Read_callback); while(true) { if(Serial_Available()) { ch=Serial_Read(); Comm.printf("%c",ch,state); switch (state) { case 0: if(ch == '<') { state++; paramstate=0;; } break; case 1: cmd = ch; state++; break; case 2: if(ch == ',') { paramstate++; paramdigcnt=2; } else if(ch == '>') { state=0; new_frame =1; } else { paramval[paramstate-1][paramdigcnt--]=ch-'0'; } break; }//switch }//Serial_available if(new_frame) { Comm.printf("\n\rStarted polling Command=%c \n\r",cmd); new_frame =0; Port_Data_prev=0; Time_cntr=0; if(cmd == 'P') { scan_time= (paramval[0][0]-+paramval[0][1]* 10 + paramval[0][2] * 100)*0.01; Comm.printf("Scan Time %f mS \n\r",scan_time*1000); Read_Port.attach(&Read_Port_callback,scan_time); 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("<%.4X,%.2X>\n\r",Time_cntr,Port_Data); Data_avl=0; Time_cntr=0; } } }//while }