General testings

Dependencies:   mbed

Fork of BEACON_CODE_NEW by Mohamed Azad

Files at this revision

API Documentation at this revision

Comitter:
shekhar
Date:
Wed Oct 28 13:29:02 2015 +0000
Parent:
20:a7dbfbc462f1
Child:
22:c6c77fdfacd8
Commit message:
added few wait()s in msecs

Changed in this revision

beacon.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/beacon.h	Tue Oct 27 13:15:47 2015 +0000
+++ b/beacon.h	Wed Oct 28 13:29:02 2015 +0000
@@ -12,21 +12,13 @@
 #define LONG_TX_DATA 75    //in bytes      
 
 //#define RF_SILENCE_TIME 5   //in seconds
-#define RF_SILENCE_TIME 35*60
-
-//GLOBAL VARIABLES
-uint8_t BCN_INIT_STATUS;
-uint8_t BCN_TX_MAIN_STATUS;
-uint8_t BCN_TX_STATUS;
-uint8_t BCN_TX_EN = 1;              //hardcoding for now    //check where is this variable toggled??
-uint8_t BCN_FEN = 0;                //write this to non-erasable memory.
-uint8_t BCN_STANDBY = 0;            //hardcoding for now    //check where is this variable toggled??
-uint8_t BCN_TS_BUFFER;              // For Temperature 
+//#define RF_SILENCE_TIME 35*60
+#define RF_SILENCE_TIME 5 //changed for testing
 
 //FUNCTION PROTOTYPING
-void P_BCN_INIT();
-void P_BCN_FEN();
-void P_BCN_TX_MAIN();
+void FCTN_BCN_INIT();
+void FCTN_BCN_FEN();
+void FCTN_BCN_TX_MAIN();
 void Set_BCN_TX_STATUS(uint8_t);
 uint8_t check_Temperature();
 void SHORT_BCN_TX();
--- a/main.cpp	Tue Oct 27 13:15:47 2015 +0000
+++ b/main.cpp	Wed Oct 28 13:29:02 2015 +0000
@@ -1,5 +1,6 @@
 #include "beacon.h"
 #include <stdio.h>
+//Takes approx. 4.3 sec in void FCTN_BCN_TX_MAIN() (temp.calc. + long_beacon + short_beacon) 
 
 Serial pc(USBTX, USBRX);        //tx,rx
 SPI spi(D11, D12, D13);              // mosi, miso, sclk
@@ -8,23 +9,35 @@
 Timer t_i;
 Ticker loop;
 
-void P_BCN_INIT()
+//GLOBAL VARIABLES
+uint8_t BCN_INIT_STATUS = 0;
+uint8_t BCN_TX_MAIN_STATUS = 0;
+uint8_t BCN_TX_STATUS = 0;
+uint8_t BCN_TX_EN = 1;              //hardcoding for now    //check where is this variable toggled??
+uint8_t BCN_FEN = 0;                //write this to non-erasable memory.
+uint8_t BCN_STANDBY = 0;            //hardcoding for now    //check where is this variable toggled??
+uint8_t BCN_TS_BUFFER = 0;              // For Temperature 
+
+void FCTN_BCN_INIT()
 {
-    //pc.printf("P_BCN_INIT\n");
+    //t_i.start();
+    pc.printf("FCTN_BCN_INIT\n");
     BCN_INIT_STATUS = 1;
     Init_BEACON_HW();
     if (BCN_FEN == 0)
         t.start();//Start the timer for RF_Silence
     BCN_INIT_STATUS = 0;
 }
-void P_BCN_FEN()
+void FCTN_BCN_FEN()
 {
-    //pc.printf("P_FEN\n");
+    pc.printf("FCTN_FEN\n");
     BCN_FEN = 1;//write this value to flash
 }
-void P_BCN_TX_MAIN()
+void FCTN_BCN_TX_MAIN()
 {
-    //pc.printf("P_BCN_TX_MAIN\n");
+    pc.printf("FCTN_BCN_TX_MAIN\n");
+    t_i.start();
+    int begin = t_i.read_us();
     BCN_TX_MAIN_STATUS = 1;
     
     if(BCN_FEN == 1)
@@ -43,14 +56,10 @@
                 // break;
             }
             else
-            {       //transmit short beacon and long beacon
-                    //t_i.start();
-                    //int begin = t_i.read_us();
+            {       
+                    //transmit short beacon and long beacon
                     SHORT_BCN_TX();
                     LONG_BCN_TX();
-                    //t_i.stop();
-                    //int end = t_i.read_us();
-                    //pc.printf("The time required for short and long is %d seconds\r\n", end-begin);
                     
                     if(Check_ACK_RECEIVED() == 1)
                     {
@@ -76,6 +85,10 @@
         Set_BCN_TX_STATUS(BCN_RF_SILENCE);  //Window of RF Silence: None of the Txs should be on.
         BCN_TX_MAIN_STATUS = 0;
     }
+    t_i.stop();
+    int end = t_i.read_us();
+    pc.printf("The time required for short and long is %d seconds\r\n", end-begin);
+    
 }
 
 void Set_BCN_TX_STATUS(uint8_t STATUS)
@@ -88,7 +101,7 @@
     uint8_t temperature;
     writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80);            
     writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20);
-    wait(1);
+    wait(0.1);
     temperature = readreg(RF22_REG_11_ADC_Value);
     temperature = (float)temperature*0.5 - 64;
     return temperature;
@@ -98,14 +111,10 @@
 {
     writereg(RF22_REG_6E_TX_DATA_RATE,0x01);
     writereg(RF22_REG_6F_TX_DATA_RATE,0x4F);//160bps
-    writereg(RF22_REG_3E_PACKET_LENGTH,SHORT_TX_DATA); //short packet length
-    
-    wait(0.02);   
-    
-   
-   
-    //get short_beacon array
-    
+    writereg(RF22_REG_3E_PACKET_LENGTH,SHORT_TX_DATA); //short packet length 
+    wait(0.02);                                                                             
+
+    //extract values from short_beacon[]
     struct Short_beacon
     {
         uint8_t Voltage[1];
@@ -116,17 +125,16 @@
     }Shortbeacon = { {0x88}, {0x99, 0xAA} , {0xAA},{0xAA,0xDD,0xEE}, {0x00} };
     
     //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[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,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
-    uint8_t byte = 0;
+    int byte = 0;
     cs = 0;
     spi.write(0xFF);   
-    
+
     for (int byte_counter = 0; byte_counter <15 ; byte_counter++)
     {
         for(int j = 3; j >= 0 ; j--)
@@ -155,13 +163,14 @@
     
     //Set to Tx mode
     writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-      
+    wait(0.1);  
     //Check for fifoThresh
     while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
+
+
+    //Check for packet_sent
+    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04);
     
-    //Check for packetsent interrupt
-    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04);
-             
     //pc.printf("Short packet sent\r\n");
     
     writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
@@ -200,7 +209,7 @@
     
     //Set to Tx mode
     writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-
+    wait(0.1);
     //Check for fifoThresh
     while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
     
@@ -211,7 +220,7 @@
         spi.write(Long_beacon[i]);
     }
     cs = 1;
-    wait(0.01);
+    wait(0.1);
     //Check for fifoThresh
     while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
     
@@ -224,7 +233,7 @@
 }
 void reset_uC()
 {
-    P_BCN_INIT();
+    FCTN_BCN_INIT();
 }
 void writereg(uint8_t reg,uint8_t val)
 {
@@ -241,7 +250,7 @@
             }
             else if(count == 5)
             {
-                reset_uC();break;
+                reset_uC(), printf("reg = 0x%X\n",reg);break;
             }
         }
         else
@@ -289,20 +298,22 @@
 
 void Init_BEACON_HW()
 {
+    wait(0.1);
     cs=1;                          // chip must be deselected
+    wait(0.1);
     spi.format(8,0);
     spi.frequency(10000000);       //10MHz SCLK
     
     //should either have a flag for invalid SPI or discard this for actual case or add reset
     if (readreg(RF22_REG_00_DEVICE_TYPE) == 0x08)
-        /*pc.printf("spi connection valid\r\n")*/;
+        pc.printf("spi connection valid\r\n");
     else
-        {//pc.printf("error in spi connection\r\n");
+        {pc.printf("error in spi connection\r\n");
         reset_uC();
         }
     
     writereg(RF22_REG_07_OPERATING_MODE1,0x80);        //sw_reset
-    wait(1);                    //takes time to reset                                  
+    wait(0.1);                    //takes time to reset                                  
 
     clearTxBuf();                                                                                                                        
     
@@ -324,7 +335,7 @@
 
     if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00)
         {
-            //pc.printf("frequency not set properly\r\n");
+            pc.printf("frequency not set properly\r\n");
             reset_uC();
         }
 
@@ -357,24 +368,24 @@
 {
     if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)  
     {
-        //printf("Packet sent: ACK received\r\n");
+        printf("Packet sent: ACK received\r\n");
         return 1;   
     }
     else
     {
-        //pc.printf("Packet not sent\r\n");
+        pc.printf("Packet not sent\r\n");
         return 0;
     }
 }
 int main()
 {
-    P_BCN_INIT(); 
+    FCTN_BCN_INIT(); 
     
-    loop.attach(&P_BCN_TX_MAIN, 30.0);
+    loop.attach(&FCTN_BCN_TX_MAIN, 10.0);//in actual case its 30.0
     
     while(t.read() < RF_SILENCE_TIME);
         
-    P_BCN_FEN();
+    FCTN_BCN_FEN();
     
     while(1);