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 15:54:26 2015 +0000
Parent:
22:c6c77fdfacd8
Child:
24:3d8e70286f67
Commit message:
commented main()

Changed in this revision

BCN.cpp Show annotated file Show diff for this revision Revisions of this file
BCN.h Show annotated file Show diff for this revision Revisions of this file
beacon.h Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BCN.cpp	Wed Oct 28 15:54:26 2015 +0000
@@ -0,0 +1,390 @@
+#include "beacon.h"
+#include <stdio.h>
+//Check the pin names
+//Takes max 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 
+DigitalOut cs(D10);                //slave select or chip select
+Timer t_i;
+//Ticker loop;
+
+//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 = 1;                //hardcoding for now
+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("FCTN_BCN_INIT\n");
+    BCN_INIT_STATUS = 1;
+    Init_BEACON_HW();
+    BCN_INIT_STATUS = 0;
+}
+void FCTN_BCN_FEN()
+{
+    pc.printf("FCTN_FEN\n");
+    BCN_FEN = 1;//write this value to flash
+}
+void FCTN_BCN_TX_MAIN()
+{
+    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)
+    {
+        if(BCN_TX_EN == 1)
+        {
+            //Measure and store BCN temperature in BCN_TS_BUFFER
+            BCN_TS_BUFFER = check_Temperature();
+            pc.printf("\n\ntemperature = %d\n\n",BCN_TS_BUFFER);
+            //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER
+            if(BCN_STANDBY == 1 )
+            {
+                Set_BCN_TX_STATUS(BCN_TX_STANDBY);
+                BCN_TX_MAIN_STATUS = 0;
+                
+                // break;
+            }
+            else
+            {       
+                    //transmit short beacon and long beacon
+                    SHORT_BCN_TX();
+                    LONG_BCN_TX();
+                    
+                    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_TX_MAIN_STATUS = 0;
+                        
+                    }
+             }
+        }
+        else
+        {
+            Set_BCN_TX_STATUS(BCN_TX_DISABLED);
+            BCN_TX_MAIN_STATUS = 0;
+        }
+    }
+    else
+    {
+        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)
+{
+    BCN_TX_STATUS = STATUS;
+}
+
+uint8_t check_Temperature()
+{   
+    uint8_t temperature;
+    writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80);            
+    writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20);
+    wait(0.1);
+    temperature = readreg(RF22_REG_11_ADC_Value);
+    temperature = (float)temperature*0.5 - 64;
+    return temperature;
+}
+
+void SHORT_BCN_TX()
+{
+    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);      
+                                                                           
+    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 = { {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
+    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--)
+        {
+            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;
+            }
+            spi.write(byte);
+         }
+    }   
+    
+    cs = 1;
+    
+    //Set to Tx mode
+    writereg(RF22_REG_07_OPERATING_MODE1,0x09);
+    wait(0.1);  
+    //Check for fifoThresh
+    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;
+    timeout_count=10e5;
+    
+    //Check for packet_sent
+    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;
+    
+    //pc.printf("Short packet sent\r\n");
+    
+    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
+    
+}
+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[75];
+    for(int i = 0;i<75;i++)
+    {
+        Long_beacon[i] = 0xA0;
+    }
+   
+   
+   
+    
+    //setModeIdle();
+    writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode    
+    clearTxBuf();     
+    //writing data first time
+    cs = 0;
+    spi.write(0xFF);   
+    for(int i=0; i<60;i++)
+    {
+        spi.write(Long_beacon[i]);
+    }
+    cs = 1;
+    
+    //Set to Tx mode
+    writereg(RF22_REG_07_OPERATING_MODE1,0x09);
+    wait(0.1);
+    
+    //Check for fifoThresh
+    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;
+    timeout_count=10e5;
+    
+    cs = 0;
+    spi.write(0xFF);   
+    for(int i=60; i<75;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;
+    timeout_count=10e5;
+    
+    //Check for packetsent interrupt
+    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;
+         
+    //pc.printf("Long packet sent\r\n");
+    
+    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
+}
+void reset_uC()
+{
+    FCTN_BCN_INIT();
+}
+void writereg(uint8_t reg,uint8_t val)
+{
+    uint8_t count = 0; 
+    for(;;count++)
+    {
+        int read_val =0; cs = 0;spi.write(reg | 0x80);spi.write(val);cs = 1;
+        if(reg != 0x7 && reg != 0x58 && reg != 0xF) 
+        {        
+            read_val = readreg(reg);
+            if (read_val == val)
+            {
+                break;    
+            }
+            else if(count == 5)
+            {
+                reset_uC(), printf("reg = 0x%X\n",reg);break;
+            }
+        }
+        else
+        break;
+    }
+}   
+uint8_t readreg(uint8_t reg)
+{
+    uint8_t val;cs = 0;spi.write(reg & ~0x80);val = spi.write(0);cs = 1;return val;
+}
+void clearTxBuf()
+{
+    writereg(RF22_REG_08_OPERATING_MODE2,0x01);
+    writereg(RF22_REG_08_OPERATING_MODE2,0x00);
+}
+uint8_t setFrequency(double centre,float afcPullInRange)
+{
+    uint8_t fbsel = 0x40;
+    uint8_t afclimiter;
+    if (centre >= 480.0) {
+        centre /= 2;
+        fbsel |= 0x20;
+        afclimiter = afcPullInRange * 1000000.0 / 1250.0;
+    } else {
+        if (afcPullInRange < 0.0 || afcPullInRange > 0.159375)
+            return false;
+        afclimiter = afcPullInRange * 1000000.0 / 625.0;
+    }
+    centre /= 10.0;
+    double integerPart = floor(centre);
+    double fractionalPart = centre - integerPart;
+ 
+    uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23
+    fbsel |= fb;
+    uint16_t fc = fractionalPart * 64000;
+    writereg(RF22_REG_73_FREQUENCY_OFFSET1, 0);  // REVISIT
+    writereg(RF22_REG_74_FREQUENCY_OFFSET2, 0);
+    writereg(RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel);
+    writereg(RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8);
+    writereg(RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff);
+    writereg(RF22_REG_2A_AFC_LIMITER, afclimiter);
+    return 0;
+}
+
+
+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");
+    else
+        {pc.printf("error in spi connection\r\n");
+        reset_uC();
+        }
+    
+    writereg(RF22_REG_07_OPERATING_MODE1,0x80);        //sw_reset
+    wait(0.1);                    //takes time to reset                                  
+
+    clearTxBuf();                                                                                                                        
+    
+    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
+       
+    //txfifoalmostempty
+    writereg(RF22_REG_7D_TX_FIFO_CONTROL2,30);
+
+    //Packet-engine registers
+    writereg(RF22_REG_30_DATA_ACCESS_CONTROL,0x00); 
+    
+    writereg(RF22_REG_33_HEADER_CONTROL2,0x08);    
+    writereg(RF22_REG_34_PREAMBLE_LENGTH,0x00);       
+
+    writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state                        
+    writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state                        
+
+    setFrequency(435.0,05);
+
+    if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00)
+        {
+            pc.printf("frequency not set properly\r\n");
+            reset_uC();
+        }
+
+    //set Modem Configuration
+    writereg(RF22_REG_1C_IF_FILTER_BANDWIDTH,0xdf);
+    writereg(RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,0x03);
+    writereg(RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE,0x39);
+    writereg(RF22_REG_21_CLOCK_RECOVERY_OFFSET2,0x20);                     
+    writereg(RF22_REG_22_CLOCK_RECOVERY_OFFSET1,0x68);           //updated 20 to 25 reg values from excel sheet for 1.2 Khz freq. deviation,fsk
+    writereg(RF22_REG_23_CLOCK_RECOVERY_OFFSET0,0xdc);
+    writereg(RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1,0x00);
+    writereg(RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0,0x6B);
+    writereg(RF22_REG_2C_OOK_COUNTER_VALUE_1,0x2C);
+    writereg(RF22_REG_2D_OOK_COUNTER_VALUE_2,0x11);    //not required for fsk (OOK counter value)
+    writereg(RF22_REG_2E_SLICER_PEAK_HOLD,0x2A);         //??
+    writereg(RF22_REG_58,0x80);
+    writereg(RF22_REG_69_AGC_OVERRIDE1,0x60);
+    
+    //Data rate set later
+      
+    writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);
+    writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21
+    
+    //set tx power
+    writereg(RF22_REG_6D_TX_POWER,0x07);    //20dbm
+    
+    //TX_packet_length written later
+}
+bool Check_ACK_RECEIVED()
+{
+    if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)  
+    {
+        printf("Packet sent: ACK received\r\n");
+        return 1;   
+    }
+    else
+    {
+        pc.printf("Packet not sent\r\n");
+        return 0;
+    }
+}
+/*int main()
+{
+    FCTN_BCN_INIT(); 
+    
+    loop.attach(&FCTN_BCN_TX_MAIN, 10.0);//in actual case its 30.0
+    
+    while(1);
+    
+}*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BCN.h	Wed Oct 28 15:54:26 2015 +0000
@@ -0,0 +1,127 @@
+#include "mbed.h"
+
+//STATES
+#define BCN_RF_SILENCE 0 
+#define BCN_TX_DISABLED 1
+#define BCN_TX_STANDBY 2
+#define BCN_TX_FAILURE 3
+#define BCN_TX_SUCCESS 4
+
+//Size of tx data
+#define SHORT_TX_DATA 60    //in bytes
+#define LONG_TX_DATA 75    //in bytes      
+
+//#define RF_SILENCE_TIME 35*60
+#define RF_SILENCE_TIME 5 //changed for testing
+
+//FUNCTION PROTOTYPING
+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();
+void LONG_BCN_TX();
+void Init_BEACON_HW();
+void writereg(uint8_t,uint8_t);
+uint8_t readreg(uint8_t);
+void clearTxBuf();
+uint8_t setFrequency(double,float);
+bool Check_ACK_RECEIVED();
+void reset_uC();
+
+#define RF22_MAX_MESSAGE_LEN 255
+
+//These values we set for FIFO thresholds
+#define RF22_TXFFAEM_THRESHOLD 40
+
+//Registers
+#define RF22_REG_00_DEVICE_TYPE                         0x00
+#define RF22_REG_02_DEVICE_STATUS                       0x02
+#define RF22_REG_03_INTERRUPT_STATUS1                   0x03
+#define RF22_REG_04_INTERRUPT_STATUS2                   0x04
+#define RF22_REG_07_OPERATING_MODE1                     0x07
+#define RF22_REG_08_OPERATING_MODE2                     0x08
+#define RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE         0x09
+#define RF22_REG_0B_GPIO_CONFIGURATION0                 0x0b
+#define RF22_REG_0C_GPIO_CONFIGURATION1                 0x0c
+#define RF22_REG_0D_GPIO_CONFIGURATION2                 0x0d
+#define RF22_REG_0F_ADC_CONFIGURATION                   0x0f
+#define RF22_REG_11_ADC_Value                           0x11
+#define RF22_REG_12_Temperature_Sensor_Calibration      0x12
+#define RF22_REG_1C_IF_FILTER_BANDWIDTH                 0x1c
+#define RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE   0x1f
+#define RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE    0x20
+#define RF22_REG_21_CLOCK_RECOVERY_OFFSET2              0x21
+#define RF22_REG_22_CLOCK_RECOVERY_OFFSET1              0x22
+#define RF22_REG_23_CLOCK_RECOVERY_OFFSET0              0x23
+#define RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1    0x24
+#define RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0    0x25
+#define RF22_REG_26_RSSI                                0x26
+#define RF22_REG_27_RSSI_THRESHOLD                      0x27
+#define RF22_REG_28_ANTENNA_DIVERSITY1                  0x28
+#define RF22_REG_29_ANTENNA_DIVERSITY2                  0x29
+#define RF22_REG_2A_AFC_LIMITER                         0x2a
+#define RF22_REG_2B_AFC_CORRECTION_READ                 0x2b
+#define RF22_REG_2C_OOK_COUNTER_VALUE_1                 0x2c
+#define RF22_REG_2D_OOK_COUNTER_VALUE_2                 0x2d
+#define RF22_REG_2E_SLICER_PEAK_HOLD                    0x2e
+#define RF22_REG_30_DATA_ACCESS_CONTROL                 0x30
+#define RF22_REG_31_EZMAC_STATUS                        0x31
+#define RF22_REG_32_HEADER_CONTROL1                     0x32
+#define RF22_REG_33_HEADER_CONTROL2                     0x33
+#define RF22_REG_34_PREAMBLE_LENGTH                     0x34
+#define RF22_REG_35_PREAMBLE_DETECTION_CONTROL1         0x35
+#define RF22_REG_36_SYNC_WORD3                          0x36
+#define RF22_REG_37_SYNC_WORD2                          0x37
+#define RF22_REG_38_SYNC_WORD1                          0x38
+#define RF22_REG_39_SYNC_WORD0                          0x39
+#define RF22_REG_3A_TRANSMIT_HEADER3                    0x3a
+#define RF22_REG_3B_TRANSMIT_HEADER2                    0x3b
+#define RF22_REG_3C_TRANSMIT_HEADER1                    0x3c
+#define RF22_REG_3D_TRANSMIT_HEADER0                    0x3d
+#define RF22_REG_3E_PACKET_LENGTH                       0x3e
+#define RF22_REG_3F_CHECK_HEADER3                       0x3f
+#define RF22_REG_40_CHECK_HEADER2                       0x40
+#define RF22_REG_41_CHECK_HEADER1                       0x41
+#define RF22_REG_42_CHECK_HEADER0                       0x42
+#define RF22_REG_43_HEADER_ENABLE3                      0x43
+#define RF22_REG_44_HEADER_ENABLE2                      0x44
+#define RF22_REG_45_HEADER_ENABLE1                      0x45
+#define RF22_REG_46_HEADER_ENABLE0                      0x46
+#define RF22_REG_47_RECEIVED_HEADER3                    0x47
+#define RF22_REG_48_RECEIVED_HEADER2                    0x48
+#define RF22_REG_49_RECEIVED_HEADER1                    0x49
+#define RF22_REG_4A_RECEIVED_HEADER0                    0x4a
+#define RF22_REG_4B_RECEIVED_PACKET_LENGTH              0x4b
+#define RF22_REG_58                                     0x58
+#define RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS  0x60
+#define RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE    0x61
+#define RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL      0x62
+#define RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION    0x63
+#define RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION      0x64
+#define RF22_REG_65_LDO_CONTROL_OVERRIDE                0x65
+#define RF22_REG_66_LDO_LEVEL_SETTINGS                  0x66
+#define RF22_REG_67_DELTA_SIGMA_ADC_TUNING1             0x67
+#define RF22_REG_68_DELTA_SIGMA_ADC_TUNING2             0x68
+#define RF22_REG_69_AGC_OVERRIDE1                       0x69
+#define RF22_REG_6A_AGC_OVERRIDE2                       0x6a
+#define RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b
+#define RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE   0x6c
+#define RF22_REG_6D_TX_POWER                            0x6d
+#define RF22_REG_6E_TX_DATA_RATE                        0x6e
+#define RF22_REG_6F_TX_DATA_RATE                        0x6f
+#define RF22_REG_70_MODULATION_CONTROL1                 0x70
+#define RF22_REG_71_MODULATION_CONTROL2                 0x71
+#define RF22_REG_72_FREQUENCY_DEVIATION                 0x72
+#define RF22_REG_73_FREQUENCY_OFFSET1                   0x73
+#define RF22_REG_74_FREQUENCY_OFFSET2                   0x74
+#define RF22_REG_75_FREQUENCY_BAND_SELECT               0x75
+#define RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1          0x76
+#define RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0          0x77
+#define RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT    0x79
+#define RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE         0x7a
+#define RF22_REG_7C_TX_FIFO_CONTROL1                    0x7c
+#define RF22_REG_7D_TX_FIFO_CONTROL2                    0x7d
+#define RF22_REG_7E_RX_FIFO_CONTROL                     0x7e
+#define RF22_REG_7F_FIFO_ACCESS                         0x7f
\ No newline at end of file
--- a/beacon.h	Wed Oct 28 14:40:57 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,128 +0,0 @@
-#include "mbed.h"
-
-//STATES
-#define BCN_RF_SILENCE 0 
-#define BCN_TX_DISABLED 1
-#define BCN_TX_STANDBY 2
-#define BCN_TX_FAILURE 3
-#define BCN_TX_SUCCESS 4
-
-//Size of tx data
-#define SHORT_TX_DATA 60    //in bytes
-#define LONG_TX_DATA 75    //in bytes      
-
-//#define RF_SILENCE_TIME 5   //in seconds
-//#define RF_SILENCE_TIME 35*60
-#define RF_SILENCE_TIME 5 //changed for testing
-
-//FUNCTION PROTOTYPING
-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();
-void LONG_BCN_TX();
-void Init_BEACON_HW();
-void writereg(uint8_t,uint8_t);
-uint8_t readreg(uint8_t);
-void clearTxBuf();
-uint8_t setFrequency(double,float);
-bool Check_ACK_RECEIVED();
-void reset_uC();
-
-#define RF22_MAX_MESSAGE_LEN 255
-
-//These values we set for FIFO thresholds
-#define RF22_TXFFAEM_THRESHOLD 40
-
-//Registers
-#define RF22_REG_00_DEVICE_TYPE                         0x00
-#define RF22_REG_02_DEVICE_STATUS                       0x02
-#define RF22_REG_03_INTERRUPT_STATUS1                   0x03
-#define RF22_REG_04_INTERRUPT_STATUS2                   0x04
-#define RF22_REG_07_OPERATING_MODE1                     0x07
-#define RF22_REG_08_OPERATING_MODE2                     0x08
-#define RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE         0x09
-#define RF22_REG_0B_GPIO_CONFIGURATION0                 0x0b
-#define RF22_REG_0C_GPIO_CONFIGURATION1                 0x0c
-#define RF22_REG_0D_GPIO_CONFIGURATION2                 0x0d
-#define RF22_REG_0F_ADC_CONFIGURATION                   0x0f
-#define RF22_REG_11_ADC_Value                           0x11
-#define RF22_REG_12_Temperature_Sensor_Calibration      0x12
-#define RF22_REG_1C_IF_FILTER_BANDWIDTH                 0x1c
-#define RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE   0x1f
-#define RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE    0x20
-#define RF22_REG_21_CLOCK_RECOVERY_OFFSET2              0x21
-#define RF22_REG_22_CLOCK_RECOVERY_OFFSET1              0x22
-#define RF22_REG_23_CLOCK_RECOVERY_OFFSET0              0x23
-#define RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1    0x24
-#define RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0    0x25
-#define RF22_REG_26_RSSI                                0x26
-#define RF22_REG_27_RSSI_THRESHOLD                      0x27
-#define RF22_REG_28_ANTENNA_DIVERSITY1                  0x28
-#define RF22_REG_29_ANTENNA_DIVERSITY2                  0x29
-#define RF22_REG_2A_AFC_LIMITER                         0x2a
-#define RF22_REG_2B_AFC_CORRECTION_READ                 0x2b
-#define RF22_REG_2C_OOK_COUNTER_VALUE_1                 0x2c
-#define RF22_REG_2D_OOK_COUNTER_VALUE_2                 0x2d
-#define RF22_REG_2E_SLICER_PEAK_HOLD                    0x2e
-#define RF22_REG_30_DATA_ACCESS_CONTROL                 0x30
-#define RF22_REG_31_EZMAC_STATUS                        0x31
-#define RF22_REG_32_HEADER_CONTROL1                     0x32
-#define RF22_REG_33_HEADER_CONTROL2                     0x33
-#define RF22_REG_34_PREAMBLE_LENGTH                     0x34
-#define RF22_REG_35_PREAMBLE_DETECTION_CONTROL1         0x35
-#define RF22_REG_36_SYNC_WORD3                          0x36
-#define RF22_REG_37_SYNC_WORD2                          0x37
-#define RF22_REG_38_SYNC_WORD1                          0x38
-#define RF22_REG_39_SYNC_WORD0                          0x39
-#define RF22_REG_3A_TRANSMIT_HEADER3                    0x3a
-#define RF22_REG_3B_TRANSMIT_HEADER2                    0x3b
-#define RF22_REG_3C_TRANSMIT_HEADER1                    0x3c
-#define RF22_REG_3D_TRANSMIT_HEADER0                    0x3d
-#define RF22_REG_3E_PACKET_LENGTH                       0x3e
-#define RF22_REG_3F_CHECK_HEADER3                       0x3f
-#define RF22_REG_40_CHECK_HEADER2                       0x40
-#define RF22_REG_41_CHECK_HEADER1                       0x41
-#define RF22_REG_42_CHECK_HEADER0                       0x42
-#define RF22_REG_43_HEADER_ENABLE3                      0x43
-#define RF22_REG_44_HEADER_ENABLE2                      0x44
-#define RF22_REG_45_HEADER_ENABLE1                      0x45
-#define RF22_REG_46_HEADER_ENABLE0                      0x46
-#define RF22_REG_47_RECEIVED_HEADER3                    0x47
-#define RF22_REG_48_RECEIVED_HEADER2                    0x48
-#define RF22_REG_49_RECEIVED_HEADER1                    0x49
-#define RF22_REG_4A_RECEIVED_HEADER0                    0x4a
-#define RF22_REG_4B_RECEIVED_PACKET_LENGTH              0x4b
-#define RF22_REG_58                                     0x58
-#define RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS  0x60
-#define RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE    0x61
-#define RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL      0x62
-#define RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION    0x63
-#define RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION      0x64
-#define RF22_REG_65_LDO_CONTROL_OVERRIDE                0x65
-#define RF22_REG_66_LDO_LEVEL_SETTINGS                  0x66
-#define RF22_REG_67_DELTA_SIGMA_ADC_TUNING1             0x67
-#define RF22_REG_68_DELTA_SIGMA_ADC_TUNING2             0x68
-#define RF22_REG_69_AGC_OVERRIDE1                       0x69
-#define RF22_REG_6A_AGC_OVERRIDE2                       0x6a
-#define RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b
-#define RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE   0x6c
-#define RF22_REG_6D_TX_POWER                            0x6d
-#define RF22_REG_6E_TX_DATA_RATE                        0x6e
-#define RF22_REG_6F_TX_DATA_RATE                        0x6f
-#define RF22_REG_70_MODULATION_CONTROL1                 0x70
-#define RF22_REG_71_MODULATION_CONTROL2                 0x71
-#define RF22_REG_72_FREQUENCY_DEVIATION                 0x72
-#define RF22_REG_73_FREQUENCY_OFFSET1                   0x73
-#define RF22_REG_74_FREQUENCY_OFFSET2                   0x74
-#define RF22_REG_75_FREQUENCY_BAND_SELECT               0x75
-#define RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1          0x76
-#define RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0          0x77
-#define RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT    0x79
-#define RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE         0x7a
-#define RF22_REG_7C_TX_FIFO_CONTROL1                    0x7c
-#define RF22_REG_7D_TX_FIFO_CONTROL2                    0x7d
-#define RF22_REG_7E_RX_FIFO_CONTROL                     0x7e
-#define RF22_REG_7F_FIFO_ACCESS                         0x7f
\ No newline at end of file
--- a/main.cpp	Wed Oct 28 14:40:57 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,397 +0,0 @@
-#include "beacon.h"
-#include <stdio.h>
-//Takes max 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
-DigitalOut cs(D10);                //slave select or chip select
-Timer t;
-Timer t_i;
-Ticker loop;
-
-//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()
-{
-    //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 FCTN_BCN_FEN()
-{
-    pc.printf("FCTN_FEN\n");
-    BCN_FEN = 1;//write this value to flash
-}
-void FCTN_BCN_TX_MAIN()
-{
-    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)
-    {
-        if(BCN_TX_EN == 1)
-        {
-            //Measure and store BCN temperature in BCN_TS_BUFFER
-            BCN_TS_BUFFER = check_Temperature();
-            pc.printf("\n\ntemperature = %d\n\n",BCN_TS_BUFFER);
-            //Get BCN_HK data from BCN HW(SPI) //Store BCN_HK data in BCN_HK_BUFFER
-            if(BCN_STANDBY == 1 )
-            {
-                Set_BCN_TX_STATUS(BCN_TX_STANDBY);
-                BCN_TX_MAIN_STATUS = 0;
-                
-                // break;
-            }
-            else
-            {       
-                    //transmit short beacon and long beacon
-                    SHORT_BCN_TX();
-                    LONG_BCN_TX();
-                    
-                    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_TX_MAIN_STATUS = 0;
-                        
-                    }
-             }
-        }
-        else
-        {
-            Set_BCN_TX_STATUS(BCN_TX_DISABLED);
-            BCN_TX_MAIN_STATUS = 0;
-        }
-    }
-    else
-    {
-        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)
-{
-    BCN_TX_STATUS = STATUS;
-}
-
-uint8_t check_Temperature()
-{   
-    uint8_t temperature;
-    writereg(RF22_REG_0F_ADC_CONFIGURATION,0x80);            
-    writereg(RF22_REG_12_Temperature_Sensor_Calibration,0x20);
-    wait(0.1);
-    temperature = readreg(RF22_REG_11_ADC_Value);
-    temperature = (float)temperature*0.5 - 64;
-    return temperature;
-}
-
-void SHORT_BCN_TX()
-{
-    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);      
-                                                                           
-    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 = { {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
-    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--)
-        {
-            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;
-            }
-            spi.write(byte);
-         }
-    }   
-    
-    cs = 1;
-    
-    //Set to Tx mode
-    writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-    wait(0.1);  
-    //Check for fifoThresh
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;
-    timeout_count=10e5;
-    
-    //Check for packet_sent
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;
-    
-    //pc.printf("Short packet sent\r\n");
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
-    
-}
-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[75];
-    for(int i = 0;i<75;i++)
-    {
-        Long_beacon[i] = 0xA0;
-    }
-   
-   
-   
-    
-    //setModeIdle();
-    writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode    
-    clearTxBuf();     
-    //writing data first time
-    cs = 0;
-    spi.write(0xFF);   
-    for(int i=0; i<60;i++)
-    {
-        spi.write(Long_beacon[i]);
-    }
-    cs = 1;
-    
-    //Set to Tx mode
-    writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-    wait(0.1);
-    
-    //Check for fifoThresh
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) == 0x20)break;
-    timeout_count=10e5;
-    
-    cs = 0;
-    spi.write(0xFF);   
-    for(int i=60; i<75;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;
-    timeout_count=10e5;
-    
-    //Check for packetsent interrupt
-    while(timeout_count--)if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)break;
-         
-    //pc.printf("Long packet sent\r\n");
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
-}
-void reset_uC()
-{
-    FCTN_BCN_INIT();
-}
-void writereg(uint8_t reg,uint8_t val)
-{
-    uint8_t count = 0; 
-    for(;;count++)
-    {
-        int read_val =0; cs = 0;spi.write(reg | 0x80);spi.write(val);cs = 1;
-        if(reg != 0x7 && reg != 0x58 && reg != 0xF) 
-        {        
-            read_val = readreg(reg);
-            if (read_val == val)
-            {
-                break;    
-            }
-            else if(count == 5)
-            {
-                reset_uC(), printf("reg = 0x%X\n",reg);break;
-            }
-        }
-        else
-        break;
-    }
-}   
-uint8_t readreg(uint8_t reg)
-{
-    uint8_t val;cs = 0;spi.write(reg & ~0x80);val = spi.write(0);cs = 1;return val;
-}
-void clearTxBuf()
-{
-    writereg(RF22_REG_08_OPERATING_MODE2,0x01);
-    writereg(RF22_REG_08_OPERATING_MODE2,0x00);
-}
-uint8_t setFrequency(double centre,float afcPullInRange)
-{
-    uint8_t fbsel = 0x40;
-    uint8_t afclimiter;
-    if (centre >= 480.0) {
-        centre /= 2;
-        fbsel |= 0x20;
-        afclimiter = afcPullInRange * 1000000.0 / 1250.0;
-    } else {
-        if (afcPullInRange < 0.0 || afcPullInRange > 0.159375)
-            return false;
-        afclimiter = afcPullInRange * 1000000.0 / 625.0;
-    }
-    centre /= 10.0;
-    double integerPart = floor(centre);
-    double fractionalPart = centre - integerPart;
- 
-    uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23
-    fbsel |= fb;
-    uint16_t fc = fractionalPart * 64000;
-    writereg(RF22_REG_73_FREQUENCY_OFFSET1, 0);  // REVISIT
-    writereg(RF22_REG_74_FREQUENCY_OFFSET2, 0);
-    writereg(RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel);
-    writereg(RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8);
-    writereg(RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff);
-    writereg(RF22_REG_2A_AFC_LIMITER, afclimiter);
-    return 0;
-}
-
-
-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");
-    else
-        {pc.printf("error in spi connection\r\n");
-        reset_uC();
-        }
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x80);        //sw_reset
-    wait(0.1);                    //takes time to reset                                  
-
-    clearTxBuf();                                                                                                                        
-    
-    writereg(RF22_REG_07_OPERATING_MODE1,0x00);        //standby mode
-       
-    //txfifoalmostempty
-    writereg(RF22_REG_7D_TX_FIFO_CONTROL2,30);
-
-    //Packet-engine registers
-    writereg(RF22_REG_30_DATA_ACCESS_CONTROL,0x00); 
-    
-    writereg(RF22_REG_33_HEADER_CONTROL2,0x08);    
-    writereg(RF22_REG_34_PREAMBLE_LENGTH,0x00);       
-
-    writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state                        
-    writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state                        
-
-    setFrequency(435.0,05);
-
-    if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00)
-        {
-            pc.printf("frequency not set properly\r\n");
-            reset_uC();
-        }
-
-    //set Modem Configuration
-    writereg(RF22_REG_1C_IF_FILTER_BANDWIDTH,0xdf);
-    writereg(RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,0x03);
-    writereg(RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE,0x39);
-    writereg(RF22_REG_21_CLOCK_RECOVERY_OFFSET2,0x20);                     
-    writereg(RF22_REG_22_CLOCK_RECOVERY_OFFSET1,0x68);           //updated 20 to 25 reg values from excel sheet for 1.2 Khz freq. deviation,fsk
-    writereg(RF22_REG_23_CLOCK_RECOVERY_OFFSET0,0xdc);
-    writereg(RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1,0x00);
-    writereg(RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0,0x6B);
-    writereg(RF22_REG_2C_OOK_COUNTER_VALUE_1,0x2C);
-    writereg(RF22_REG_2D_OOK_COUNTER_VALUE_2,0x11);    //not required for fsk (OOK counter value)
-    writereg(RF22_REG_2E_SLICER_PEAK_HOLD,0x2A);         //??
-    writereg(RF22_REG_58,0x80);
-    writereg(RF22_REG_69_AGC_OVERRIDE1,0x60);
-    
-    //Data rate set later
-      
-    writereg(RF22_REG_70_MODULATION_CONTROL1,0x20);
-    writereg(RF22_REG_71_MODULATION_CONTROL2,0x21);//ook = 0x21
-    
-    //set tx power
-    writereg(RF22_REG_6D_TX_POWER,0x07);    //20dbm
-    
-    //TX_packet_length written later
-}
-bool Check_ACK_RECEIVED()
-{
-    if((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) == 0x04)  
-    {
-        printf("Packet sent: ACK received\r\n");
-        return 1;   
-    }
-    else
-    {
-        pc.printf("Packet not sent\r\n");
-        return 0;
-    }
-}
-int main()
-{
-    FCTN_BCN_INIT(); 
-    
-    loop.attach(&FCTN_BCN_TX_MAIN, 10.0);//in actual case its 30.0
-    
-    while(t.read() < RF_SILENCE_TIME);
-        
-    FCTN_BCN_FEN();
-    
-    while(1);
-    
-}
\ No newline at end of file