asdf
Dependencies: NokiaLCD XMIT_IR mbed
Fork of 4180_mP_WirelessPong_revC by
Diff: main.cpp
- Revision:
- 7:c9ff6b5c8507
- Parent:
- 6:5563f0026858
- Child:
- 8:54dd4a3d0de9
--- a/main.cpp Thu Oct 04 23:33:35 2012 +0000 +++ b/main.cpp Fri Oct 05 12:05:01 2012 +0000 @@ -2,6 +2,7 @@ #include "rtos.h" #include "NokiaLCD.h" #include "XMIT_IR.h" +#include "queue.h" #define FPS 5 #define UART_TIMEOUT 500 @@ -34,6 +35,8 @@ char irdatOUT[10]; char irdatIN[10]; char error_code=0; +Thread* threadptr_donothing; +DataQueue RX_DataBuffer(1,100); //Function Prototypes void BlinkAlive(void const* arguments); @@ -41,6 +44,8 @@ void IRStuff(void const* arguments); void MakePacket(char* data,int len); char CheckPacket(char* data, int data_size); +void ISR_UARTRX(void); +void DoNothing(void const* arguments); int main() @@ -55,14 +60,18 @@ //Serial init device.baud(2400); + //device.attach(&ISR_UARTRX,Serial::RxIrq); //PC serial init pc.baud(19200); + pc.printf("Starting...\n\n"); //Thread init Thread thread_blinkalive(BlinkAlive); Thread thread_updatelcd(UpdateLCD); Thread thread_irstuff(IRStuff); + Thread thread_donothing(DoNothing); + threadptr_donothing = &thread_donothing; @@ -75,7 +84,7 @@ void UpdateLCD(void const* arguments) { - /*while(true) { + while(true) { led2 = 1; lcd.locate(0,1); lcd.printf("Debug:"); @@ -97,23 +106,41 @@ //End - Sleep thread led2 = 0; Thread::signal_wait(0x1); - }*/ + } } void IRStuff(void const* arguments) { while(true) { - //error_code = CheckPacket(irdatIN,2); - - while(device.readable()) - { + error_code = CheckPacket(irdatIN,2); + + /*while(device.readable()) { char tempdata = device.getc(); if(tempdata==0x02) pc.printf("\n"); pc.printf("0x%02X.",tempdata); + }*/ + + //pc.printf("UART_STATE: 0x%08X",*((unsigned int *)0x400FC0C4)); + + + /*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) { + pc.printf("0x%02X.",irdatIN[1]); + Thread::wait(10); + } else if(error_code==0x2) { + pc.printf("!"); + Thread::wait(10); + } else { + Thread::wait(10); } - - //pc.printf("\n\nERROR=0x%02X\n\n",error_code); - Thread::wait(3000); } } @@ -156,10 +183,10 @@ char tempdata=0x0; char check=0x0; - pc.printf("\nChecking Packet\n\t"); + //pc.printf("\nChecking Packet\n\t"); //Data available if(!device.readable()) { - pc.printf("no data"); + //pc.printf("no data"); return 0x4; //no data } @@ -171,8 +198,7 @@ //STX recieved if(tempdata!=0x02) { - pc.printf("found bad data: 0x%02X",tempdata); - if(tempdata==0xFF) device.getc(); //flush + if(tempdata==0xFF) pc.printf("found bad data: 0x%02X",tempdata); return 0x1; //bad start byte } @@ -199,3 +225,25 @@ } +void DoNothing(void const* arguments) +{ + while(true) { + Thread::signal_wait(0x1); + } +} + +void ISR_UARTRX(void) +{ + uint32_t RBR = LPC_UART1->RBR; + char data = (char)RBR; + RX_DataBuffer.Put(&data); + //pc.printf("!"); + + while(device.readable()) { + char data = device.getc(); + RX_DataBuffer.Put(&data); + //pc.printf("*"); + } + +} +