serial teste pulga to pulga

Files at this revision

API Documentation at this revision

Comitter:
ruschigo
Date:
Sun May 03 15:22:29 2020 +0000
Parent:
1:10de89ea1f70
Commit message:
a

Changed in this revision

Source/definitions.txt Show annotated file Show diff for this revision Revisions of this file
Source/main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
mbed_coragem.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Source/definitions.txt	Sat May 02 03:01:56 2020 +0000
+++ b/Source/definitions.txt	Sun May 03 15:22:29 2020 +0000
@@ -24,7 +24,7 @@
 /* General*/
 
 /* Serial*/
-RawSerial pc(USBTX, USBRX);
+//RawSerial pc(USBTX, USBRX);
 
 float display_data;
 int display_ctrl;
--- a/Source/main.cpp	Sat May 02 03:01:56 2020 +0000
+++ b/Source/main.cpp	Sun May 03 15:22:29 2020 +0000
@@ -24,9 +24,12 @@
 #define FIO2_VP 0x125 //FiO2 Tela 40
 #define ONOFF_ASSISTED_MODE_VP 0x170 //MODO ASSISTIDO tela 40
 
+#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512
+#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 1024 
+
 Timer timer_main;
 
-RawSerial serial_to_pulga(P0_11, P0_8);
+Serial serial_to_pulga(P0_11, P0_8);
 
 float rx_pot[4];
 
@@ -119,6 +122,20 @@
 int bc = 0;//byte couter
 int i_rx = 0;//counter to start receive rx at serial
 
+void clear_display_buffer(){
+    int i = 0;
+    char msg[30] = "DISPLAY:";
+    char t[3];
+    while(i<7){
+        sprintf(t,"%x",serial_rx_buffer[i]);
+        strcat(msg, t);
+        serial_rx_buffer[i] = 0x0;
+        i++;
+    }   
+    //pc.puts(msg);
+    //pc.puts("\n"); 
+}
+
 #define DELAY_UART 2000 //us
 void serial_rx_irq(){
     int time_us;
@@ -131,17 +148,26 @@
     uint16_t data[255];//to store data
     pkt.buffer = data;
     int unknow = 1;//if unknow pkt come
+    while(serial1.readable()){
+            serial_rx_buffer[i_rx] = serial1.getc();
+            i_rx++;
+            if(i_rx>=8){
+                i_rx = 0;
+                //pc_puts(rx_pulga_buffer, 7);
+                break;
+            }
+    }
     /*
     *Never remove the timer serial_timer, it keep the mininum time between
     *two uart datas, if you have problem with serial, try change the DELAY_UART
     *value, mbed api do not says anything about this timing issue
     */
-    serial_timer.reset();//restart timer
+    /*serial_timer.reset();//restart timer
     serial_timer.start();
     time_us = serial_timer.read_us();
     while(time_us<DELAY_UART){
         time_us = serial_timer.read_us();
-    }
+    }*/
     //if(time_us >= DELAY_UART) 
     //{
         /*if(serial_rx_buffer[0] != 0x5a){ 
@@ -153,7 +179,7 @@
             //bc = 255;
         }*/
         
-        while(serial1.readable()){//get only one byte per interrupt
+       /* while(serial1.readable()){//get only one byte per interrupt
             serial_timer.reset();//restart timer
             serial_timer.start();
             time_us = serial_timer.read_us();
@@ -194,11 +220,11 @@
     }*/
     //serial_timer.reset();//restart timer
     //serial_timer.start();
-    serial_timer.stop();
+    //serial_timer.stop();
     //j = 0;
     //sprintf(debug_msg, "rx_bytes:%d \n bc = %d\n", i_rx, bc);
     //pc.puts(debug_msg);
-    if(bc == 0 && i_rx >0){//packt was received
+    if(i_rx == 0){//packt was received
         /*if(serial_rx_buffer[2] >= 0x80 && serial_rx_buffer[2] <= 0x84)  
         {    
             serial_to_proculus_pkt_2(serial_rx_buffer, &pkt);
@@ -344,11 +370,7 @@
                 //}
             }
         }
-        i = 0;
-        while(i<100){
-            serial_rx_buffer[i] = 0x0;
-            i++;
-        }    
+        clear_display_buffer();
         i_rx = 0;
     }
 }
@@ -391,14 +413,14 @@
     int i = 0;
     char msg[30] = "PKT:";
     char t[3];
-    while(i<10){
+    while(i<7){
         sprintf(t,"%x",rx_pulga_buffer[i]);
         strcat(msg, t);
         rx_pulga_buffer[i] = 0x0;
         i++;
     }   
-    pc.puts(msg);
-    pc.puts("\n"); 
+    //pc.puts(msg);
+    //pc.puts("\n"); 
 }
 
 //***********************************************************************************************
@@ -414,8 +436,17 @@
     int time_us;
     char debug_msg[100];
     pulga_pkt.buffer = data;
-    pulga_rx_timer.reset();//restart timer
-    pulga_rx_timer.start();
+    while(serial_to_pulga.readable()){
+            rx_pulga_buffer[rx_i] = serial_to_pulga.getc();
+            rx_i++;
+            if(rx_i>=7){
+                rx_i = 0;
+                //pc_puts(rx_pulga_buffer, 7);
+                break;
+            }
+    }
+    //pulga_rx_timer.reset();//restart timer
+    //pulga_rx_timer.start();
     //time_us = pulga_rx_timer.read_us();
     //while(time_us<DELAY_P2PS){
     //    time_us = pulga_rx_timer.read_us();
@@ -426,7 +457,7 @@
     if(rx_i >1 && rx_pulga_buffer[1] != 0xa9){
         rx_i = 0;
     }*/
-        
+    /*
     while(serial_to_pulga.readable()){//get only one byte per interrupt
         if(rx_pulga_buffer[0] != 0x9a){//avoid noise 
             rx_i = 0;
@@ -444,12 +475,12 @@
             clear_pulga_buffer();
         }
         
-        /*pulga_rx_timer.reset();//restart timer
+        pulga_rx_timer.reset();//restart timer
         pulga_rx_timer.start();
         time_us = pulga_rx_timer.read_us();
         while(time_us<DELAY_P2PS){
             time_us = pulga_rx_timer.read_us();
-        }*/
+        }
         rx_pulga_buffer[rx_i] = serial_to_pulga.getc();
         
         if(rx_i == 2)//get bc(how many byts will come
@@ -457,23 +488,22 @@
         
         if(pulga_bc > 0 && rx_i > 2)//avoid decrement it when it  was got
             pulga_bc--;
-        /*   
+          
         sprintf(debug_msg,"rx_pulga_buffer[%d] = %x\n",rx_i ,rx_pulga_buffer[rx_i]);
         pc.puts(debug_msg);
         sprintf(debug_msg,"pulga_bc = %d\n",pulga_bc);
         pc.puts(debug_msg);
-        */
+        
         
         rx_i++;
         if(pulga_bc == 0 && rx_i > 2)
             rx_i = 0;
     }
-        
+    */ 
     /*if(rx_i == 2)//get bc(how many byts will come
         pulga_bc = rx_pulga_buffer[2];*/
     
-    if(pulga_bc == 0 && rx_i >0){
-        //
+    if(rx_i ==0){
         if(rx_pulga_buffer[3] >= 0x40 && rx_pulga_buffer[3] <= 0x49)  
         {    
             serial_to_pulga_pkt(rx_pulga_buffer, &pulga_pkt);
@@ -489,7 +519,6 @@
         }
         clear_pulga_buffer();
         rx_i = 0;
-        pulga_bc = 0;
     }
         
 }
@@ -501,8 +530,8 @@
 {
     
     //setup the device rx irq handler
-    serial1.attach(&serial_rx_irq, RawSerial::RxIrq);
-    serial_to_pulga.attach(&serial_pulga_rx, RawSerial::RxIrq);
+    //serial1.attach(&serial_rx_irq, RawSerial::RxIrq);
+    //serial_to_pulga.attach(&serial_pulga_rx, RawSerial::RxIrq);
     //setup the baud rate to match with display
     serial1.baud(115200);
     serial_to_pulga.baud(9600);
@@ -529,18 +558,28 @@
     }
 }
 
+/*int pc_puts(const char *str, int size){
+    int i = 0;
+    while(i < size){
+        pc.putc(str[i]);
+        i++;
+    }
+    return 0;
+}*/
+
 //***********************************************************************************************
 int main()
 {
-    //wait(3);//time to display setup. not sure about this value
+    wait(3);//time to display setup. not sure about this value
     Setup();
     jump_to_screen(SCREEN_STARTUP);
+    int i = 0;
     while (true) {
+        //jump_to_screen(SCREEN_STARTUP);
         //update_screen();
         //Send_to_pulga();
-        //pc.puts("teste \n");
-        serial_to_pulga.puts("test output\n");
-        //serial_to_pulga.puts("puts \n");
-        wait(0.3);
+        serial_pulga_rx();
+        wait(0.2);
+        serial_rx_irq();
     }
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Sun May 03 15:22:29 2020 +0000
@@ -0,0 +1,35 @@
+{  
+    
+    "target_overrides": {
+        "K64F": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "NUCLEO_F401RE": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "DISCO_L475VG_IOT01A": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "NRF52840_DK": {
+            "platform.stdio-baud-rate": 9600,
+            "platform.default-serial-baud-rate": 9600,
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_LL", "SOFTDEVICE_N ONE", "NORDIC_CORDIO"],
+            "target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S140_FULL", "NORDIC_SOFTDEVICE"],           
+            "target.lf_clock_src": "NRF_LF_SRC_XTAL",
+            "target.lf_clock_rc_calib_timer_interval": 16,
+            "target.lf_clock_rc_calib_mode_config": 2
+
+
+            
+        },
+        "NRF52_DK": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_LL", "SOFTDEVICE_NONE", "NORDIC_CORDIO"],
+            "target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S132_FULL", "NORDIC_SOFTDEVICE"]
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_coragem.lib	Sun May 03 15:22:29 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/leiachewbacca/mbed_coragem/#b8dad0652c9cd2321126a590280a18a964e1eed0