Team Fox / Mbed 2 deprecated TR_EXCITATION_TEST

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of BAE_CODE_MARCH_2017 by Team Fox

Revision:
26:c8655e0ec73a
Parent:
23:c65456ec5e61
--- a/BCN.cpp	Sat Jul 02 14:06:10 2016 +0000
+++ b/BCN.cpp	Sun Jul 03 19:25:48 2016 +0000
@@ -29,6 +29,11 @@
                                     //This Flag when exceeds a threshold, uC should reset.
 uint16_t BCN_TX_MAIN_COUNTER = 0;
 
+extern uint8_t BCN_LONG_MSG_TYPE = 1;
+extern uint8_t LONG_HK_data[2][134];
+
+extern DigitalOut BCN_SW(PIN14);
+
 void FCTN_BCN_INIT()
 {
     pc_bcn.printf("FCTN_BCN_INIT\n");
@@ -66,39 +71,43 @@
     if(BCN_FEN == 1)
     {
         if(BCN_TX_SW_STATUS == 0b00000001)
-        {
-            //Measure and store BCN temperature in BCN_TS_BUFFER
-            BCN_TMP = check_Temperature();
-            pc_bcn.printf("temperature = %d\n\r",BCN_TMP);
-            //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER
-            if(BCN_SPND_TX == 1 )
+        {   
+            Init_BEACON_HW();
+            if( BCN_TX_STATUS == BCN_INIT_SUCCESS )
             {
-                Set_BCN_TX_STATUS(BCN_TX_STANDBY);
-                BCN_TX_MAIN_STATUS = 0;
-                
-                // break;
-            }
-            else
-            {       
-                    //transmit short beacon and long beacon
-                    begintx = t_i.read_us();
-                    BCN_TX();
-                    endtx = t_i.read_us();
-                    
-                    if(Check_ACK_RECEIVED() == 1)
-                    {
-                        Set_BCN_TX_STATUS(BCN_TX_SUCCESS);
-                        BCN_TX_MAIN_STATUS = 0;   
-                    }
-                    else
-                    {
-                        //Set_BCN_TX_STATUS(BCN_TX_FAILURE);
-                        BCN_FAIL_COUNT++;
-                        Init_BEACON_HW();
-                        BCN_TX_MAIN_STATUS = 0;
+                //Measure and store BCN temperature in BCN_TS_BUFFER
+                uint8_t temp_temp = check_Temperature();
+                if( temp_temp != 0xFF )
+                    BCN_TMP = temp_temp;
+                pc_bcn.printf("temperature = %d\n\r",BCN_TMP);
+                //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER
+                if(BCN_SPND_TX == 1 )
+                {
+                    Set_BCN_TX_STATUS(BCN_TX_SUSPENDED);
+                    BCN_TX_MAIN_STATUS = 0;
+                }
+                else
+                {       
+                        //transmit short beacon and long beacon
+                        begintx = t_i.read_us();
+                        BCN_TX();
+                        endtx = t_i.read_us();
                         
-                    }
-             }
+                        if(Check_ACK_RECEIVED() == 1)
+                        {
+                            Set_BCN_TX_STATUS(BCN_TX_SUCCESS);
+                            BCN_TX_MAIN_STATUS = 0;   
+                        }
+                        else
+                        {
+                            Set_BCN_TX_STATUS(BCN_TX_FAILURE);
+                            //BCN_FAIL_COUNT++;
+                            //Init_BEACON_HW();
+                            BCN_TX_MAIN_STATUS = 0;
+                            
+                        }
+                }
+            }   
         }
         else
         {
@@ -132,11 +141,14 @@
 {   
     uint8_t temperature;
     writereg(RF22_REG_0F_ADC_CONFIGURATION,0x00);//set ADC to temp measurement            
-    writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20);//measure in degree celsius
+    writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x60);//measure in degree celsius
     writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80);//start adc
     wait(0.1);
-    temperature = readreg(RF22_REG_11_ADC_Value);
-    temperature = (float)temperature*0.5 - 64;
+    if( readreg(RF22_REG_0F_ADC_CONFIGURATION) & 0x80 == 0x00 )
+    {    temperature = readreg(RF22_REG_11_ADC_Value);
+         temperature = (float)temperature - 64;
+    }
+    else temperature = 0xFF;
     return temperature;
 }
 
@@ -150,7 +162,7 @@
                                                                            
     uint32_t timeout_count = 10e5;
     //extract values from short_beacon[]
-    
+    /*
     uint8_t Long_beacon[LONG_TX_DATA];
     for(int i = 0;i<LONG_TX_DATA;i++)
     {
@@ -169,7 +181,7 @@
     //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[] = { 0xF3, 0x02, 0xFA, 0xC6, 0xD4, 0x28, 0x8A,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
     
@@ -182,7 +194,7 @@
         {
             cs = 0;
             spi.write(0xFF);
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,j))!= pow(2.0,j))
+            if((SHORT_HK_data[byte_counter] & (uint8_t) pow(2.0,j))!= pow(2.0,j))
             {
                 //byte=0x00;
                 spi.write(zerobyte[0]);
@@ -228,12 +240,14 @@
         //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);
-        }
+            wait_ms(25);
+            while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else if(timeout_count == 1) reset_rfm(1);
+            {
+                //pc_bcn.printf("w_f_empty\n");
+                //reset_rfm(1);
+            }
+            timeout_count = 10e5;
         }
                 
        /* if(byte_counter%2==0 && byte_counter)
@@ -244,17 +258,17 @@
             //pc_bcn.printf("W = %d\r\n",byte_counter);    
     }   
     
-    for(byte_counter = 15;byte_counter<142;byte_counter++)
+    for(byte_counter = 15;byte_counter<149;byte_counter++)
     {
         cs = 0;
         spi.write(0xFF);   
-        spi.write(Long_beacon[byte_counter-15]);
+        spi.write(LONG_HK_data[BCN_LONG_MSG_TYPE][byte_counter-15]);
         cs = 1;
         
         if((byte_counter-15)%32==0)
         {   //Check for fifoThresh
             wait_ms(25);
-            while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else //if(timeout_count == 1) 
+            while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;else if(timeout_count == 1) reset_rfm(1);
             {
                 //pc_bcn.printf("Reset\n");
                 //reset_rfm(1);
@@ -264,9 +278,9 @@
     }
     wait_ms(70);
     //Check for fifoThresh
-    while(1)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else 
+    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x40) == 0x00)break;else if(timeout_count == 1) reset_rfm(1);
     {
-        pc_bcn.printf("Waiting for fifo to empty\r\n");
+        //pc_bcn.printf("Waiting for fifo to empty\r\n");
     }
     
     //Check for packetsent interrupt
@@ -305,7 +319,7 @@
             {
                 break;    
             }
-            else if(count == 5)
+            else if(count == 2)
             {
                 reset_rfm(1); printf("reg = 0x%X\n",reg);break;
             }
@@ -475,4 +489,17 @@
 }
 */
   
+void  FCTN_BCN_SPND_TX()
+{
+     BCN_SPND_TX = 1;
+     if( BCN_TX_MAIN_STATUS == 1 && BCN_TX_SW_STATUS == 1 )
+     {
+         writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
+         if( readreg(RF22_REG_07_OPERATING_MODE1) & 0x08 == 0x08 )
+         {
+             BCN_SW = 0;
+             BCN_TX_SW_STATUS = 3;
+         }
+     }
+}
   
\ No newline at end of file