library for implementing ir transmission

Revision:
6:281167565d6d
Parent:
5:ad52a062d494
Child:
7:01243fe65940
diff -r ad52a062d494 -r 281167565d6d XMIT_IR.cpp
--- a/XMIT_IR.cpp	Sat Oct 06 14:40:38 2012 +0000
+++ b/XMIT_IR.cpp	Sat Oct 06 17:36:37 2012 +0000
@@ -16,6 +16,10 @@
     (*ir_serial).attach(fptr_isr_rx,Serial::RxIrq);
     (*ir_serial).attach(fptr_isr_tx,Serial::TxIrq);
 
+//    uint_32 tmp = LPC_UART1->IER;
+
+//    LPC_UART1->IER = tmp;
+
     //Initialize Variables
     for(int i=0; i<data_buff_len+3; i++)
         packet_buffer_in[i] = 0;
@@ -38,17 +42,38 @@
 void IRTransmitter::MakePacket(char* data,int len)
 {
     char check =0x0;
-    (*ir_serial).putc(ASCII_STX);
+    Timer t;
+    t.reset();
+    t.start();
+
+    //(*ir_serial).putc(ASCII_STX);
+    mail_tx_packet(ASCII_STX);
     for(int i=0; i<len; i++) {
         check^=data[i];
-        (*ir_serial).putc(data[i]);
+        //(*ir_serial).putc(data[i]);
+        mail_tx_packet(data[i]);
     }
-    (*ir_serial).putc(check);
-    (*ir_serial).putc(ASCII_ETX);
-    
-    /*char* mail = ir_txdata_mailbox.alloc();
-    mail[0] = (char)data;
-    ir_txdata_mailbox.put(mail);*/
+    //(*ir_serial).putc(check);
+    mail_tx_packet(check);
+    //(*ir_serial).putc(ASCII_ETX);
+    mail_tx_packet(ASCII_ETX);
+
+    t.stop();
+    int time = t.read_ms();
+    (*debug_port).printf("\nms=%d\n",time);
+
+    char tmp = isr_tx();
+    LPC_UART1->THR = (uint32_t)data;
+
+
+
+}
+
+void IRTransmitter::mail_tx_packet(char data)
+{
+    char* mail = ir_txdata_mailbox.alloc();
+    mail[0] = data;
+    ir_txdata_mailbox.put(mail);
 }
 
 
@@ -77,6 +102,11 @@
         }
         (*debug_port).printf("  PKT_VALID=0x%02X.",packet_is_valid(len));*/
 
+        if((*data)=='?') {
+            (*debug_port).putc('*');
+        }
+
+
 
         if(packet_is_valid(len)==0) {
             return_state = 1;
@@ -133,10 +163,22 @@
     ir_rxdata_mailbox.put(mail);
 }
 
-void IRTransmitter::isr_tx()
+char IRTransmitter::isr_tx(void)
 {
     //char* mail = ir_rxdata_mailbox.alloc();
     //mail[0] = (char)data;
     //ir_rxdata_mailbox.put(mail);
+
+    char data = 0xF1;
+    osEvent evt = ir_txdata_mailbox.get();
+    if(evt.status == osEventMail) {
+        char* mail = (char*)evt.value.p;
+        data = (*mail);
+
+        //(*ir_serial).putc(data);
+        ir_rxdata_mailbox.free(mail);
+    }
+    //(*debug_port).printf("TX=0x%02X.",data);
+    return data;
 }