Curtis Mulady
/
4180_mP_WirelessPong_revA
miniProject-Wireless Pong
Diff: main.cpp
- Revision:
- 8:54dd4a3d0de9
- Parent:
- 7:c9ff6b5c8507
- Child:
- 9:3e4e9d6a8ad8
--- a/main.cpp Fri Oct 05 12:05:01 2012 +0000 +++ b/main.cpp Fri Oct 05 13:02:52 2012 +0000 @@ -35,8 +35,9 @@ char irdatOUT[10]; char irdatIN[10]; char error_code=0; -Thread* threadptr_donothing; +Thread* threadptr_irstuff; DataQueue RX_DataBuffer(1,100); +bool rx_data_available = false; //Function Prototypes void BlinkAlive(void const* arguments); @@ -60,7 +61,7 @@ //Serial init device.baud(2400); - //device.attach(&ISR_UARTRX,Serial::RxIrq); + device.attach(&ISR_UARTRX,Serial::RxIrq); //PC serial init pc.baud(19200); @@ -71,7 +72,7 @@ Thread thread_updatelcd(UpdateLCD); Thread thread_irstuff(IRStuff); Thread thread_donothing(DoNothing); - threadptr_donothing = &thread_donothing; + threadptr_irstuff = &thread_irstuff; @@ -112,7 +113,7 @@ void IRStuff(void const* arguments) { while(true) { - error_code = CheckPacket(irdatIN,2); + //error_code = CheckPacket(irdatIN,2); /*while(device.readable()) { char tempdata = device.getc(); @@ -122,17 +123,18 @@ //pc.printf("UART_STATE: 0x%08X",*((unsigned int *)0x400FC0C4)); + if(rx_data_available) { + if(irdatIN[0]==0x2) pc.printf("\n"); + pc.printf("0x%02X.",irdatIN[0]); + //pc.printf("0x%02X.",irdatIN[1]); + //pc.printf("0x%02X.",irdatIN[2]); + //pc.printf("0x%02X.\n",irdatIN[3]); + rx_data_available = false; + } - /*pc.printf("any data?\n"); - while(RX_DataBuffer.GetNumberOfItems()) - { - char* data; - RX_DataBuffer.Get(data); - pc.printf("0x%02X.",*data); - }*/ //pc.printf("\n\nE=0x%02X\n\n",error_code); - if(error_code==0x0) { + /*if(error_code==0x0) { pc.printf("0x%02X.",irdatIN[1]); Thread::wait(10); } else if(error_code==0x2) { @@ -140,7 +142,8 @@ Thread::wait(10); } else { Thread::wait(10); - } + }*/ + Thread::signal_wait(0x1); } } @@ -153,6 +156,7 @@ irdatOUT[0] = 0xA5; irdatOUT[1] = ++irdata_out; MakePacket(irdatOUT,2); + //pc.printf("UART_STATE: 0x%08X",*((unsigned int *)0x40010014)); Thread::wait(20); } @@ -165,7 +169,7 @@ device.putc(0x02); //pc.printf("0x%02X.",0x02); for(int i=0; i<len; i++) { - check^=data[i]; + check+=data[i]; device.putc(data[i]); //pc.printf("0x%02X.",data[i]); } @@ -199,6 +203,7 @@ //STX recieved if(tempdata!=0x02) { if(tempdata==0xFF) pc.printf("found bad data: 0x%02X",tempdata); + pc.printf("UART_STATE: 0x%08X",*((unsigned int *)0x40010014)); return 0x1; //bad start byte } @@ -209,7 +214,7 @@ //if(t.read_ms()>=UART_TIMEOUT) // return 0x3; //timeout error data[i] = device.getc(); - check ^= data[i]; + check += data[i]; } //Get Checksum while(!device.readable()); @@ -235,15 +240,28 @@ void ISR_UARTRX(void) { uint32_t RBR = LPC_UART1->RBR; - char data = (char)RBR; - RX_DataBuffer.Put(&data); - //pc.printf("!"); + irdatIN[0] = 0; + irdatIN[1] = 0; + irdatIN[2] = 0; + irdatIN[3] = 0; - while(device.readable()) { + irdatIN[0] = (char)RBR; + /*if(device.readable()) + irdatIN[1] = (char) LPC_UART1->RBR; + if(device.readable()) + irdatIN[2] = (char) LPC_UART1->RBR; + if(device.readable()) + irdatIN[3] = (char) LPC_UART1->RBR; + */ + + rx_data_available = true; + (*threadptr_irstuff).signal_set(0x1); + + + /*while(device.readable()) { char data = device.getc(); - RX_DataBuffer.Put(&data); //pc.printf("*"); - } + }*/ }