Team Fox / Mbed 2 deprecated TR_EXCITATION_TEST

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of BAE_CODE_MARCH_2017 by Team Fox

Revision:
23:c65456ec5e61
Parent:
20:949d13045431
Child:
26:c8655e0ec73a
--- a/BCN.cpp	Fri Jul 01 18:14:34 2016 +0000
+++ b/BCN.cpp	Sat Jul 02 10:09:35 2016 +0000
@@ -2,7 +2,7 @@
 #include <stdio.h>
 #include "pin_config.h"
 //Check the pin names
-//Takes max 4.3 sec in void FCTN_BCN_TX_MAIN() (temp.calc. + long_beacon + short_beacon) 
+//Takes max 4 sec in void FCTN_BCN_TX_MAIN() (temp.calc. + long_beacon + short_beacon) 
 
 Serial pc_bcn(USBTX, USBRX);        //tx,rx
 SPI spi(D11, D12, D13);              // mosi, miso, sclk 
@@ -84,15 +84,6 @@
                     begintx = t_i.read_us();
                     BCN_TX();
                     endtx = t_i.read_us();
-                    /*
-                    begins = t_i.read_us();
-                    SHORT_BCN_TX();
-                    //ends = t_i.read_us();
-                    
-                    beginl = t_i.read_us();
-                    LONG_BCN_TX();
-                    endl = t_i.read_us();
-                    */
                     
                     if(Check_ACK_RECEIVED() == 1)
                     {
@@ -101,7 +92,7 @@
                     }
                     else
                     {
-                        Set_BCN_TX_STATUS(BCN_TX_FAILURE);
+                        //Set_BCN_TX_STATUS(BCN_TX_FAILURE);
                         BCN_FAIL_COUNT++;
                         Init_BEACON_HW();
                         BCN_TX_MAIN_STATUS = 0;
@@ -148,151 +139,7 @@
     temperature = (float)temperature*0.5 - 64;
     return temperature;
 }
-#if 0
-void SHORT_BCN_TX()
-{
-    /*
-    writereg(RF22_REG_6E_TX_DATA_RATE,0x01);
-    writereg(RF22_REG_6F_TX_DATA_RATE,0x50);//160bps
-    */
-    writereg(RF22_REG_6E_TX_DATA_RATE,0x0A);
-    writereg(RF22_REG_6F_TX_DATA_RATE,0x7C);//1280bps
-    
-    //writereg(RF22_REG_3E_PACKET_LENGTH,1); //short packet length 
-    wait(0.02);      
-                                                                           
-    uint32_t timeout_count = 10e5;
-    //extract values from short_beacon[]
-    
-    struct Short_beacon
-    {
-        uint8_t Voltage[1];
-        uint8_t AngularSpeed[2];
-        uint8_t SubsystemStatus[1];
-        uint8_t Temp[3];
-        uint8_t ErrorFlag[1];
-    }Shortbeacon = { {0xFF}, {0xFF, 0xFF} , {0xFF},{0xFF,0xFF,0xFF}, {0xFF} };
-    
-    //filling hk data
-    //uint8_t short_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]};
-    uint8_t short_beacon[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]};
-        
-    //writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode       ??    
-    clearTxBuf();     //writing data first time
-    
-    int byte_count=0;
-    uint8_t onebyte[4] = {0x81,0xA6,0xBE,0x4E};
-    uint8_t zerobyte[4] = {0x7E,0x59,0x41,0xB1};
-    for (int byte_counter = 0; byte_counter <15 ; byte_counter++)
-    {
-        //pc_bcn.printf("byte-counter=%d\r\n", byte_counter);
-        /*
-        for(int j = 3; j >= 0 ; j--)
-        {
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,(j*2+1)))!= pow(2.0,(j*2+1)))
-            {
-                byte=0x00;
-            }
-            else
-            { 
-                byte=0xF0;
-            }  
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,j*2))!= pow(2.0,j*2))
-            {
-                byte=byte | 0x00;
-            }
-            else
-            { 
-               byte=byte | 0x0F;
-            }
-            cs = 0;
-            spi.write(0xFF);   
-            spi.write(byte);
-            cs = 1;1
-         }
-         */
-         for(int j = 7; j >= 0 ; j--)
-        {
-            cs = 0;
-            spi.write(0xFF);
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,j))!= pow(2.0,j))
-            {
-                //byte=0x00;
-                spi.write(zerobyte[0]);
-                spi.write(zerobyte[1]);
-                spi.write(zerobyte[2]);
-                spi.write(zerobyte[3]);
-            }
-            else
-            { 
-                //byte=0xFF;
-                spi.write(onebyte[0]);
-                spi.write(onebyte[1]);
-                spi.write(onebyte[2]);
-                spi.write(onebyte[3]);
-            } 
-            cs = 1;
-            /*
-            spi.write(byte);
-            spi.write(byte);
-            spi.write(byte);
-            spi.write(byte); //Each bit is written 32 times
-            */
-            byte_count+=4;
-        
-        }     
-        
-        if(byte_counter == 1)
-        {
-           
-            //Set to Tx mode
-            writereg(RF22_REG_07_OPERATING_MODE1,0x08);       //txon
-            wait(0.1);// takes time to set to tx mode hence the delay of 0.1.  
 
-        }
-        //testing level
-        /*if(byte_counter > 0)
-        while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else
-        {
-            pc_bcn.printf("w_f_empty1\n\r");
-            //reset_rfm(1);
-        }*/
-        
-        
-        //Check for fifoThresh
-        
-        if(byte_counter > 0)
-        {wait_ms(25);
-        while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else
-        {
-            //pc_bcn.printf("w_f_empty\n");
-            //reset_rfm(1);
-        }
-        }
-                
-       /* if(byte_counter%2==0 && byte_counter)
-        while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else 
-        {
-            pc_bcn.printf("W = %d\r\n",byte_counter);
-        }*/
-            pc_bcn.printf("W = %d\r\n",byte_counter);    
-    }   
-    
-    //Check for fifoThresh
-    while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else 
-    {
-        pc_bcn.printf("Waiting for fifo to empty\r\n");
-        }
-    
-    //Check for packetsent interrupt
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;else if(timeout_count == 1) reset_rfm(1);
-    
-    pc_bcn.printf("Short packet sent, bytes written = %d\r\n",byte_count);
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
-    
-}
-#endif
 void BCN_TX()
 {
     printf("BCN_TX\n\r");
@@ -326,7 +173,7 @@
     //writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode       ??    
     clearTxBuf();     //writing data first time
     
-    int byte_count=0, byte_counter;
+    int byte_counter;
     uint8_t onebyte[4] = {0x81,0xA6,0xBE,0x4E};
     uint8_t zerobyte[4] = {0x7E,0x59,0x41,0xB1};
     for (byte_counter = 0; byte_counter <15 ; byte_counter++)
@@ -358,17 +205,17 @@
             spi.write(byte);
             spi.write(byte); //Each bit is written 32 times
             */
-            byte_count+=4;
         
         }     
         
         if(byte_counter == 1)
-        {          
-            //Set to Tx mode
-            writereg(RF22_REG_07_OPERATING_MODE1,0x08);       //txon
-            wait(0.1);// takes time to set to tx mode hence the delay of 0.1.  
-
-        }
+            if(BCN_SPND_TX != 1)                                  //Check for flag update by COM
+            {          
+                //Set to Tx mode
+                writereg(RF22_REG_07_OPERATING_MODE1,0x08);       //txon
+                wait(0.1);// takes time to set to tx mode hence the delay of 0.1.  
+            }
+        
         //testing level
         /*if(byte_counter > 0)
         while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else
@@ -430,70 +277,7 @@
     writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
     
 }
-#if 0
-void LONG_BCN_TX()
-{
-    /*
-    writereg(RF22_REG_6E_TX_DATA_RATE,0x04);
-    writereg(RF22_REG_6F_TX_DATA_RATE,0xEA);//600 bps
-    */
-    writereg(RF22_REG_3E_PACKET_LENGTH,LONG_TX_DATA); //long packet length
-    wait(0.02);                                                           
-    uint32_t timeout_count=10e5;
-   
-    //get long_beacon array
-    
-    uint8_t Long_beacon[LONG_TX_DATA];
-    for(int i = 0;i<LONG_TX_DATA;i++)
-    {
-        Long_beacon[i] = 0xFF;
-    }
-    
-    clearTxBuf();     
-    //writing data first time
-    cs = 0;
-    spi.write(0xFF);   
-    for(int i=0; i<64;i++)
-    {
-        spi.write(Long_beacon[i]);
-    }
-    cs = 1;
-    
-    //Set to Tx mode
-    writereg(RF22_REG_07_OPERATING_MODE1,0x08);
-    wait(0.1);//necessary
-    
-    //Check for fifoThresh
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else if(timeout_count == 1) 
-    {
-        pc_bcn.printf("Reset\n");
-        reset_rfm(1);
-    }
-    timeout_count=10e5;
-    
-    cs = 0;
-    spi.write(0xFF);   
-    for(int i=64; i<127;i++)
-    {
-        spi.write(Long_beacon[i]);
-    }
-    cs = 1;
-    wait(0.1);
-    //Check for fifoThresh
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else if(timeout_count == 1) 
-    {
-        pc_bcn.printf("Reset\n");
-        reset_rfm(1);}
-    timeout_count=10e5;
-    
-    //Check for packetsent interrupt
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;else if(timeout_count == 1) reset_rfm(1);
-         
-    //pc_bcn.printf("Long packet sent\r\n");
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
-}
-#endif
+
 void reset_rfm(uint8_t fl)
 {
     if (fl ==1 && ERROR_CHECK ==0)  
@@ -583,7 +367,7 @@
         {
             pc_bcn.printf("spi connection valid\r\n");
             reset_rfm(0);
-            Set_BCN_TX_STATUS(BCN_TX_INITIALIZED);
+            Set_BCN_TX_STATUS(BCN_INIT_SUCCESS);
             break;
         }
         else if (BCN_INIT_COUNTER == 1)
@@ -603,13 +387,13 @@
         else 
         {
             pc_bcn.printf("BCN_TX_FAILURE\r\n");
-            Set_BCN_TX_STATUS(BCN_TX_FAILURE);
+            Set_BCN_TX_STATUS(BCN_INIT_FAILURE);
             break;
         }
         BCN_INIT_COUNTER++;
     }
     
-    if(BCN_TX_STATUS == BCN_TX_INITIALIZED)
+    if(BCN_TX_STATUS == BCN_INIT_SUCCESS)
     {
         writereg(RF22_REG_07_OPERATING_MODE1,0x80);        //sw_reset
         wait(0.1);                    //takes time to reset                                  
@@ -653,11 +437,10 @@
         //Set Data rate - same for both long and short beacon
         
         writereg(RF22_REG_6E_TX_DATA_RATE,0x0A);
-        writereg(RF22_REG_6F_TX_DATA_RATE,0x7C);//1280bps
+        writereg(RF22_REG_6F_TX_DATA_RATE,0x7C);//1280bps 
+        writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);//For data rates below 30kbps
         
-          
-        writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);
-        writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21
+        writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//0x21 = FIFO mode with ook demodulation
         
         //set tx power
         writereg(RF22_REG_6D_TX_POWER,0x07);    //20dbm
@@ -690,4 +473,6 @@
     while(1);
     
 }
-*/
\ No newline at end of file
+*/
+  
+  
\ No newline at end of file