FM

Dependencies:   SimpleDMA eeprom mbed-rtos mbed FreescaleIAP

Fork of CDMS_CODE by shubham c

Files at this revision

API Documentation at this revision

Comitter:
samp1234
Date:
Sat Mar 11 04:46:31 2017 +0000
Parent:
353:e1803e801e20
Commit message:
with obsrs 10mins implementation

Changed in this revision

CDMS_HK.h Show annotated file Show diff for this revision Revisions of this file
COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
DefinitionsAndGlobals.h Show annotated file Show diff for this revision Revisions of this file
EEPROM.h Show diff for this revision Revisions of this file
FMS_all.h Show annotated file Show diff for this revision Revisions of this file
Flash.h Show annotated file Show diff for this revision Revisions of this file
FreescaleIAP.lib Show annotated file Show diff for this revision Revisions of this file
OBSRS.h Show annotated file Show diff for this revision Revisions of this file
ThreadsAndFunctions.h Show annotated file Show diff for this revision Revisions of this file
adf.h Show annotated file Show diff for this revision Revisions of this file
cdms_rtc.h Show annotated file Show diff for this revision Revisions of this file
cdms_sd.h Show annotated file Show diff for this revision Revisions of this file
common_functions.h Show annotated file Show diff for this revision Revisions of this file
i2c.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/CDMS_HK.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/CDMS_HK.h	Sat Mar 11 04:46:31 2017 +0000
@@ -12,6 +12,7 @@
 void COLLECT_CDMS_RAM();
 
 extern uint8_t beacon_array[134];
+//extern RSSI_MAX;
 
 AnalogIn TempInput(PIN27);          // Input from Current Multiplexer
 AnalogIn CDMS_temp_sensor(PIN53);
@@ -22,12 +23,12 @@
 DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines
 DigitalOut SelectLinec2 (PIN78);
 // SBC V1.0
-//DigitalOut SelectLinec1 (PIN76);
-//DigitalOut SelectLinec0 (PIN77); // LSB of Select Lines
+DigitalOut SelectLinec1 (PIN76);
+DigitalOut SelectLinec0 (PIN77); // LSB of Select Lines
 
 // SBC V2.0
-DigitalOut SelectLinec1 (PIN77);
-DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
+//DigitalOut SelectLinec1 (PIN77);
+//DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
 
 
 Convolution CDMS_HEALTH;
@@ -82,6 +83,8 @@
             RSSI_VOLTAGE = COMRX_RSSI_VOLTAGE.read() * 3.3;//to be checked
         }
         else COM_RSSI_SET = 0;
+          gPC.printf("RSSI_MAX = %f",RSSI_MAX);
+  //        gPC.printf("RSSI= %f",RSSI_VOLTAGE);
         //VERIFY_COMRX();
         VERIFY_RTC();
         HANDLE_HW_FAULTS();
@@ -91,7 +94,7 @@
         CDMS_quant[0]= COM_ADF_TMP+40;
         CDMS_quant[1]= (uint8_t)quant_data.CDMS_temp_quant;
         CDMS_quant[2]= (uint8_t)(RSSI_VOLTAGE*10);
-        CDMS_quant[3]= (uint8_t)(EPS_BTRY_VOLT*33*(62.0/11));
+        CDMS_quant[3]= (uint8_t)(EPS_BTRY_VOLT.read()*33*(62.0/11));
         for(int i=0; i<16; i++) {
             CDMS_quant[i+4]= (uint8_t)quant_data.temp_quant[i];
         }
@@ -257,7 +260,7 @@
             beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(0<<2)|(COMRX_OC_FAULT<<1)|(com_oc_sw_status);
             COM_OC_SET = 0;
         }
-        beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL);
+        beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL<<6);
         beacon_array[12] = CDMS_HK_MAIN_COUNTER >>8;
         beacon_array[13] = CDMS_HK_MAIN_COUNTER;
         beacon_array[14] = PL_MAIN_COUNTER >>8;
@@ -388,14 +391,17 @@
             quant_data.temp_quant[Iteration]=actual_data.temp_actual[Iteration];
             wait(0.001);
         } else if(Iteration<14)
+           {
             quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]);
         // quant_data.temp_quant[Iteration]=quantiz(0,1,actual_data.temp_actual[Iteration]);
+            quant_data.temp_quant[13]= COM_PA_TMP_IN_TX;
+            }
         else
             // quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
             quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
     }
-    quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual);
-
+ //   quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual);
+     quant_data.CDMS_temp_quant=10*RSSI_MAX;
     minMaxHkData();
 }
 
@@ -501,13 +507,13 @@
             SD_FAULTCOUNT++;
             SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT;
             if(SD_FAULTCOUNT == 3) {
-                WRITE_TO_EEPROM(2,DEVICE_DISABLED);
+                FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED);
                 gPC.printf("Declaring SD card permanantly Disabled");
             }
         } else {
             SD_STATUS = DEVICE_POWERED;
             if(SD_STATUS != DEVICE_POWERED)
-                WRITE_TO_EEPROM(2,DEVICE_POWERED);
+                FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
             SD_FAULTCOUNT = 0;
         }
     }
@@ -528,13 +534,13 @@
             BAE_FAULTCOUNT++;
             BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
             if(BAE_FAULTCOUNT == 3) {
-                WRITE_TO_EEPROM(1,DEVICE_DISABLED);
+                FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED);
                 gPC.printf("Declaring BAE permanantly Disabled");
             }
         } else {
             BAE_STATUS = DEVICE_POWERED;
             if(SD_STATUS != DEVICE_POWERED);
-            WRITE_TO_EEPROM(1,DEVICE_POWERED);
+            FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
             BAE_FAULTCOUNT = 0;
         }
     }
@@ -565,7 +571,7 @@
             PL_FAULTCOUNT++;
             PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
             if(PL_FAULTCOUNT == 3) {
-                WRITE_TO_EEPROM(3,DEVICE_DISABLED);
+               FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED);
                 gPC.printf("Declaring PL_BEE permanantly Disabled");
             }
         } else {
@@ -581,7 +587,7 @@
             }
             PL_STATUS = DEVICE_ENABLED;
             if(PL_STATUS != DEVICE_ENABLED)
-                WRITE_TO_EEPROM(3,DEVICE_ENABLED);
+                FCTN_CDMS_WR_FLASH(3,DEVICE_ENABLED);
             PL_FAULTCOUNT = 0;
         }
     }
--- a/COM_MNG_TMTC.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/COM_MNG_TMTC.h	Sat Mar 11 04:46:31 2017 +0000
@@ -486,8 +486,10 @@
                                 for(uint8_t z=24;z<32;z++)
                                     flasharray_thres[z] = scp_threshold_m0[z+8];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
-                                
+   //                            FCTN_CDMS_WR_S_FLASH(mid,flasharray_thres);
+                                erase_sector(strt_add_thres);
+                                program_flash(strt_add_thres, (char*)flasharray_thres,32);
+     
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -499,7 +501,9 @@
                                 for(uint8_t z=0;z<12;z++)
                                     flasharray_thres[z] = scp_threshold_m0[z+40];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+  //                              FCTN_CDMS_WR_S_FLASH(mid,flasharray_thres);
+                                erase_sector(strt_add_thres+SECTOR_SIZE);
+                                program_flash(strt_add_thres+SECTOR_SIZE, (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -512,7 +516,9 @@
                                 for(uint8_t z=0;z<32;z++)
                                     flasharray_thres[z] = scp_threshold_m1[z];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+  //                              THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+                                 erase_sector(strt_add_thres+(2*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(2*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -525,7 +531,9 @@
                                 for(uint8_t z=0;z<20;z++)
                                     flasharray_thres[z] = scp_threshold_m1[z+32];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+ //                               THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+                                erase_sector(strt_add_thres+(3*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(3*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -552,7 +560,10 @@
                                 flasharray_thres[10] = scp_sfp_threshold_m0_2[1];
                                 flasharray_thres[11] = scp_sfp_threshold_m0_2[2];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+  //                              THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+    
+                                erase_sector(strt_add_thres+(4*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(4*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -569,7 +580,9 @@
                                 for(uint8_t z=24;z<32;z++)
                                     flasharray_thres[z] = sfp_threshold_m0[z+8];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+  //                              THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+                                erase_sector(strt_add_thres+(5*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(5*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -582,8 +595,9 @@
                                 for(uint8_t z=0;z<12;z++)
                                     flasharray_thres[z] = sfp_threshold_m0[z+40];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
-                                
+ //                               THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+                                        erase_sector(strt_add_thres+(6*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(6*SECTOR_SIZE), (char*)flasharray_thres,32);                             
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                                 return tm_ptr_short;
@@ -595,7 +609,10 @@
                                 for(uint8_t z=0;z<32;z++)
                                     flasharray_thres[z] = sfp_threshold_m1[z];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+ //                               THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+ 
+                                erase_sector(strt_add_thres+(7*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(7*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
@@ -608,7 +625,9 @@
                                 for(uint8_t z=0;z<20;z++)
                                     flasharray_thres[z] = sfp_threshold_m1[z+32];
                                 
-                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+//                                THRES_WRITE_TO_EEPROM(mid,flasharray_thres);
+                                erase_sector(strt_add_thres+(8*SECTOR_SIZE));
+                                program_flash(strt_add_thres+(8*SECTOR_SIZE), (char*)flasharray_thres,32);
                                 
                                 Base_tm *tm_ptr_short = new Short_tm;
                                 ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
--- a/DefinitionsAndGlobals.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/DefinitionsAndGlobals.h	Sat Mar 11 04:46:31 2017 +0000
@@ -17,8 +17,8 @@
     #define SPI_CLK PTE2
     #define SPI_CS_ADF PTA15
     #define SPI_CS_SDC PIN20
-     #define SPI_CS_RTC PIN26 // actual
-  //   #define SPI_CS_RTC PIN60 // sbc with jumper v1.0
+  //   #define SPI_CS_RTC PIN26 // actual
+     #define SPI_CS_RTC PIN60 // sbc with jumper v1.0
     
 // COM_TX
     #define COM_TX_CONFIG_LIMIT 3
@@ -29,24 +29,24 @@
     
 //I2C - Payload to CDMS (need to change while using CDMS hardware);
     I2C master(PIN32,PIN31);
-    DigitalIn PL_I2C_Intr(PTC13);
-    DigitalOut PL_I2C_GPIO(PTC1);
+    DigitalIn PL_I2C_Intr(PTC13); //PIN89
+    DigitalOut PL_I2C_GPIO(PTC1); //PIN71
             
 //I2C - CDMS to BAE
   //  DigitalOut CDMS_I2C_GPIO(PIN67);//PTB21 from bae to cdms
   //  DigitalIn BAE_I2C_GPIO(PIN39);//PTA5 from cdms to bae 
     
- //   #define SBC 1
+    #define SBC 1
     
- //   #if SBC
- //   DigitalOut CDMS_I2C_GPIO(PIN67,1);
- //   DigitalIn BAE_I2C_GPIO(PIN1);
- //   #endif
+  //  #if SBC
+    DigitalOut CDMS_I2C_GPIO(PIN67,1);
+    DigitalIn BAE_I2C_GPIO(PIN1);
+  //  #endif
     
   //  #if !SBC
-    DigitalIn BAE_I2C_GPIO(PIN67);
-    DigitalOut CDMS_I2C_GPIO(PIN39,0);    
-   // #endif
+  //  DigitalIn BAE_I2C_GPIO(PIN67);
+  //  DigitalOut CDMS_I2C_GPIO(PIN39,0);    
+// #endif
 
 // TC LIST
     #define TCL_STATE_INCOMPLETE 0x00
@@ -155,8 +155,10 @@
     #define BAE_RESET_PID 0x33
 
 //RF RELAY
-    #define RF_RELAY_CNTRL_TX PTA12
-    #define RF_RELAY_CNTRL_BCN PTA7 
+  //  #define RF_RELAY_CNTRL_TX PTA12
+  //  #define RF_RELAY_CNTRL_BCN PTA7 
+  #define RF_RELAY_CNTRL_TX PTB7
+    #define RF_RELAY_CNTRL_BCN PTB17 
     
 //CDMS HK
 #define HK_SIGNAL 0x05
@@ -267,6 +269,7 @@
 bool BAE_HK_I2C;
 uint8_t RTC_STATUS;
 float RSSI_VOLTAGE;
+float RSSI_MAX;
 uint8_t COM_ADF_TMP = 0;
 uint8_t COM_PA_IC_TMP = 0;
 uint8_t BAE_HK_SD_DATA_READY = 0;
@@ -385,8 +388,9 @@
 uint8_t COM_RX_CURRENT_MAX;
 uint8_t COM_RX_DISABLE_TIMEOUT;
 uint8_t COM_PA_TMP_HIGH;
+uint8_t COM_PA_TMP_IN_TX;
 uint8_t COM_PA_RECOVERY_TIMEOUT;
-uint8_t COM_SESSION_TIMEOUT = 60;  //confirm with Anirudh 
+uint8_t COM_SESSION_TIMEOUT = 300;  //confirm with Anirudh 
 uint8_t COM_RSSI_MIN;
 uint16_t SD_LIB_BLK_CURRENT;
 
--- a/EEPROM.h	Tue Feb 21 06:30:56 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-#ifndef EEPROM_H
-#define EEPROM_H
-
-#define ee_scl PIN86
-#define ee_sda PIN87
-#define check 10
-
-EEPROM e2prom(ee_sda, ee_scl, 0, EEPROM::T24C512);
-int32_t INITIAL_EEPROM[32] = {1,1,1,1,1,0,0,0,0,35001,0xff,300,85,20,20,3,8000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-uint32_t flasharray_thres[32];
-
-void WRITE_TO_EEPROM(uint32_t address, int32_t data_block)
-{
-    e2prom.write(address*4+10,data_block);
-}
-
-void THRES_WRITE_TO_EEPROM(uint16_t mid, uint32_t* thres_data)
-{
-    int8_t data[128];
-    memcpy(data,&thres_data,128);
-    
-    if(mid <11 & mid >1)
-    {
-        e2prom.write((uint32_t)(mid-1)*128,data,128);
-    }    
-}
-
-uint32_t READ_FROM_EERPOM(uint32_t address)
-{
-    int32_t data;
-    e2prom.read(address*4+10, data);
-    return (uint32_t)data;
-}
-
-void INIT_EEPROM()
-{
-  //  int32_t test_buffer;
-   // e2prom.ready();
-   // e2prom.read(2,test_buffer);
-   /* if(test_buffer == 0)
-    {
-        for(int i=0;i<32;i++)
-            WRITE_TO_EEPROM( i, INITIAL_EEPROM[i]);
-        
-        e2prom.write(2,1);
-        gPC.printf("starting flash");
-    }
-    */
-    gPC.printf("Reading intial parametrs from flash\n");
-    EPS_V_A_EN_STATUS         = READ_FROM_EERPOM(0); // ok
-    BAE_STATUS                = READ_FROM_EERPOM(1); //ok
-    SD_STATUS                 = READ_FROM_EERPOM(2); //ok
-    PL_STATUS                 = READ_FROM_EERPOM(3); //ok
-    PL_EPS_LATCH_SW_EN        = READ_FROM_EERPOM(4); //ok
-    RTC_INIT_STATUS           = READ_FROM_EERPOM(5);
-    CDMS_RTC_DISABLE          = READ_FROM_EERPOM(6);
-    EN_RTC = CDMS_RTC_DISABLE&0x01;
-    CDMS_RESET_COUNTER        = READ_FROM_EERPOM(7);  //ok
- //   TIME_LATEST_CDSMS_RESET   = READ_FROM_EERPOM(8);
- //   COM_TC_BYTES_LIMIT        = READ_FROM_EERPOM(9);
- //   COM_RX_CURRENT_MAX        = READ_FROM_EERPOM(10);
- //   COM_RX_DISABLE_TIMEOUT    = READ_FROM_EERPOM(11);
- //   COM_PA_TMP_HIGH           = READ_FROM_EERPOM(12);
-  //  COM_PA_RECOVERY_TIMEOUT   = READ_FROM_EERPOM(13);
-  //  COM_SESSION_TIMEOUT       = READ_FROM_EERPOM(14);
- //   COM_RSSI_MIN              = READ_FROM_EERPOM(15);
-    SD_LIB_BLK_CURRENT        = READ_FROM_EERPOM(16); 
-    // added by samp
-  if (CDMS_RTC_DISABLE ==0)
-  {
-    gCS_RTC=0;
-    spi.write(0x8C); //register address with write flag
-    spi.write(0x40);//enabling halt bit in the seconds register
-    gCS_RTC=1;
-    
-   } 
-    
-}
-
-#endif
\ No newline at end of file
--- a/FMS_all.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/FMS_all.h	Sat Mar 11 04:46:31 2017 +0000
@@ -85,7 +85,7 @@
     SD_CARD_fromISO_ENA4 = 1;
     SD_SW_EN_DS = 1;
     SD_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(2,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
     gPC.printf("sw on sd\n");
 }
 
@@ -95,7 +95,7 @@
     SD_CARD_fromISO_ENA4 = 0;
     SD_SW_EN_DS = 0;
     SD_STATUS = DEVICE_DISABLED;
-    WRITE_TO_EEPROM(2,DEVICE_DISABLED);
+   FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED);
     gPC.printf("sw off sd\n");
 }
 
@@ -114,7 +114,8 @@
     gCS_RTC=1;
      EN_RTC = 0x01;
 //    CDMS_RTC_DISABLE =1;
-     WRITE_TO_EEPROM(6,1);
+    FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
+  //  gPC.printf("0x%08X \n", READ_FROM_EERPOM(6));
     SPI_mutex.unlock();
     gPC.printf("sw on rtc\n");
 }
@@ -134,7 +135,7 @@
    
    EN_RTC  = 0x00;
 //    CDMS_RTC_DISABLE = 0;
-    WRITE_TO_EEPROM(6,0);
+    FCTN_CDMS_WR_FLASH(6,0x00);
     SPI_mutex.unlock();
     gPC.printf("sw off rtc\n");
 }
@@ -143,7 +144,7 @@
 {
     BAE_SW_EN_DS = 1;
     BAE_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(1,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
     gPC.printf("sw on bae\n");
 }
 
@@ -151,7 +152,7 @@
 {
     BAE_SW_EN_DS = 0;
     BAE_STATUS = DEVICE_DISABLED;
-    WRITE_TO_EEPROM(1,DEVICE_DISABLED);
+     FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED);
     gPC.printf("sw off bae\n");
 }
 
@@ -165,7 +166,7 @@
     PYLD_DFF_CLK = 0;
     wait_us(1);
     PL_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(3,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED);
 }
 
 void SW_OFF_PL_BEE()
@@ -178,7 +179,7 @@
     PYLD_DFF_CLK = 0;
     wait_us(1);
     PL_STATUS = DEVICE_DISABLED;
-    WRITE_TO_EEPROM(3,DEVICE_DISABLED);
+   FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED);
 }
 
 void SW_ON_PL_EPS()
@@ -191,7 +192,7 @@
     PYLD_EPS_DFF_PWR_CLK = 0;
     wait_us(1);
     PL_EPS_LATCH_SW_EN = 1;
-    WRITE_TO_EEPROM(4,1);
+    FCTN_CDMS_WR_FLASH(4,1);
 }
 
 void SW_OFF_PL_EPS()
@@ -204,21 +205,21 @@
     PYLD_EPS_DFF_PWR_CLK = 0;
     wait_us(1);
     PL_EPS_LATCH_SW_EN = 0;
-    WRITE_TO_EEPROM(4,0);
+    FCTN_CDMS_WR_FLASH(4,0);
 }
 
 void SW_ON_V_A_EN()
 {
     V_A_EN = 1;
     EPS_V_A_EN_STATUS = 1;
-    WRITE_TO_EEPROM(0,1);
+   FCTN_CDMS_WR_FLASH(0,1);
 }
 
 void SW_OFF_V_A_EN()
 {
     V_A_EN = 0;
     EPS_V_A_EN_STATUS = 0;
-    WRITE_TO_EEPROM(0,0);
+   FCTN_CDMS_WR_FLASH(0,0);
 }
 
 void RST_SD()
@@ -231,7 +232,7 @@
     SD_CARD_fromISO_ENA4 = 1;
     SD_SW_EN_DS = 1;
     SD_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(2,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
     gPC.printf("rst sd\n");
 }
 
@@ -242,7 +243,7 @@
    BAE_SW_EN_DS = 1;
    
     BAE_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(1,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
     gPC.printf("rst bae\n");
 }
 
@@ -252,7 +253,7 @@
     wait_ms(10);
     PYLD_DFF = 1;
     PL_STATUS = DEVICE_POWERED;
-    WRITE_TO_EEPROM(3,DEVICE_POWERED);
+    FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED);
 }
 
 void RST_BAE()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Flash.h	Sat Mar 11 04:46:31 2017 +0000
@@ -0,0 +1,113 @@
+#include "FreescaleIAP.h"
+
+int strt_add_thres = flash_size() - (11*SECTOR_SIZE);
+uint32_t flasharray_thres[32] = {0};
+
+void FCTN_CDMS_WR_FLASH(uint16_t , uint32_t);
+int strt_add = flash_size() - (2*SECTOR_SIZE);
+uint32_t flasharray[32];    //256+(3*1024)
+uint32_t INITIAL_FLASH[32];
+
+/*corrected*/
+int *nativeflash = (int*)strt_add;
+
+void FLASH_INI()
+{
+    INITIAL_FLASH[16] = 80000;
+    uint32_t read[32]; 
+    for(int i=0;i<32;i++)
+    {  
+        read[i] = nativeflash[i];
+    }
+            
+    if(read[0] == -1)
+    {
+        for(int j=0;j<32;j++)
+        {   
+            FCTN_CDMS_WR_FLASH(j,INITIAL_FLASH[j]); 
+        } 
+    }
+    else
+    {
+        for(int j=0;j<32;j++)
+        {   
+            read[j] = nativeflash[j];
+        }
+    }
+    EPS_V_A_EN_STATUS = read[0];
+    BAE_STATUS = read[1]; 
+    SD_STATUS = read[2];
+    PL_STATUS = read[3];
+    PL_EPS_LATCH_SW_EN = read[4];
+    RTC_INIT_STATUS = read[5];
+    CDMS_RTC_DISABLE = read[6];
+    CDMS_RESET_COUNTER = read[7];
+    TIME_LATEST_CDSMS_RESET = read[8];
+    COM_TC_BYTES_LIMIT = read[9];
+    COM_RX_CURRENT_MAX = read[10];
+    COM_RX_DISABLE_TIMEOUT = read[11];
+    COM_PA_TMP_HIGH = read[12];
+    COM_PA_RECOVERY_TIMEOUT = read[13];
+    COM_SESSION_TIMEOUT = read[14];
+    COM_RSSI_MIN = read[15];
+    SD_LIB_BLK_CURRENT = read[16];
+    CDMS_RESET_COUNTER = read[17];
+}
+
+/*Writing to the Flash*/
+void FCTN_CDMS_WR_FLASH(uint16_t j,uint32_t datablock)  //j-position to write address  ; fdata - flash data to be written
+{
+    for(int i=0;i<17;i++)
+    {
+        flasharray[i]=nativeflash[i];
+    }
+    flasharray[j]=datablock;
+    erase_sector(strt_add);
+    program_flash(strt_add, (char*)flasharray,32);
+}
+/*End*/
+
+/*===================================================MMS Functions=================================================*/
+
+void FCTN_CDMS_WR_S_FLASH(uint16_t mid,uint32_t datablock);
+
+void FCTN_CDMS_WR_S_FLASH(uint16_t mid,uint32_t datablock)
+{
+    if(mid == 0x0100)
+    {
+        FCTN_CDMS_WR_FLASH(11,(datablock>>16) & 0x000000FF);
+        FCTN_CDMS_WR_FLASH(13,(datablock>>8) & 0x000000FF);
+        FCTN_CDMS_WR_FLASH(14,datablock & 0x000000FF);
+    }
+    else if(mid == 0x0101)
+    {
+        FCTN_CDMS_WR_FLASH(12,(datablock>>16) & 0x000000FF);
+        FCTN_CDMS_WR_FLASH(10,(datablock>>8) & 0x000000FF);
+        FCTN_CDMS_WR_FLASH(15,datablock & 0x000000FF);
+    }
+    else if(mid == 0x0102)
+    {
+        FCTN_CDMS_WR_FLASH(9,datablock & 0x0000FFFF);
+    }
+    else if(mid == 0x0103)
+    {
+        FCTN_CDMS_WR_FLASH(6,datablock & 0x00000001);
+    } 
+}
+
+int verify_flash_sector(int mid,uint32_t* flasharray_thres)
+{
+    int add = strt_add_thres + ((mid-1)*SECTOR_SIZE);
+    int result = 0;
+    int* testflash = (int*)add;
+    for(int i=0;i<32;i++)
+    {  
+        if(testflash[i] == flasharray_thres[i])
+            continue;
+        else
+        {
+            return 1;
+        }
+    }
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FreescaleIAP.lib	Sat Mar 11 04:46:31 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/FreescaleIAP/#6749f7702fa5
--- a/OBSRS.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/OBSRS.h	Sat Mar 11 04:46:31 2017 +0000
@@ -90,21 +90,20 @@
     ackl234new->TM_string[12] = crc & 0x00FF;\
 }
 
-void restart_adf(){
-    /*go to phy off and and py on then phy TX again    */
-    gCS_ADF = 0;
-    spi.write(0xB1);/*phy_on */
-    gCS_ADF = 1;
-    gCS_ADF = 0;
-    spi.write(0xB0);/*phy_off */
-    gCS_ADF = 1;
-    gCS_ADF = 0;
-    spi.write(0xB1);/*phy_on */
-    gCS_ADF = 1;
-    gCS_ADF = 0;
-    spi.write(0xB5);/*start transmission*/
-    gCS_ADF = 1;
-    }
+//void restart_adf(){
+//    gCS_ADF = 0;
+//    spi.write(0xB1);/*phy_on */
+//    gCS_ADF = 1;
+//    gCS_ADF = 0;
+//    spi.write(0xB0);/*phy_off */
+//    gCS_ADF = 1;
+//    gCS_ADF = 0;
+//    spi.write(0xB1);/*phy_on */
+//    gCS_ADF = 1;
+//    gCS_ADF = 0;
+//    spi.write(0xB5);/*start transmission*/
+//    gCS_ADF = 1;
+//    }
     
 int diff_prev;
 void differential_encode(unsigned char* ptr, int length){
@@ -368,6 +367,7 @@
         else if(enable_call_sign){                   // sending call sign
             send_call_sign ;
         }
+        
         else if(enable_T_frame){
             if(read_success == 0){
                 if(T_frames_sent < T_frames_in_segment){
@@ -485,7 +485,8 @@
             counter_EoS=120;\
             if(counter_EoS == 120){
 //                cout<<"EoS sent"<<ENDL;
-                restart_adf();
+//                restart_adf();
+                restart_adf_flag=true;
                 enable_new_segment = true;
                 counter_EoS = 0;
 //                cout<<"new session"<<ENDL;
--- a/ThreadsAndFunctions.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/ThreadsAndFunctions.h	Sat Mar 11 04:46:31 2017 +0000
@@ -5,6 +5,8 @@
 #include "adf.h"
 #include "dmaSPIslave.h"
 
+
+
 dmaSPISlave *gPAY_SPI;
 
 void payload_isr_fun(){
@@ -106,7 +108,9 @@
     //Checking RSSI
     if(!COM_RSSI_SET)
     RSSI_VOLTAGE = COMRX_RSSI_VOLTAGE.read() * 3.3;//to be checked
+    RSSI_MAX = RSSI_VOLTAGE;
     COM_RSSI_SET = 1;
+  
     gFLAGS = gFLAGS | UART_INT_FLAG;
     gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
 }
--- a/adf.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/adf.h	Sat Mar 11 04:46:31 2017 +0000
@@ -29,7 +29,7 @@
 bool power_reset_flag=false;
 unsigned int power_reset_count=0;
 bool Configuration_done=false;
-#define HW_THRS 2
+#define HW_THRS 5    //-mah
 bool hw_reset_flag = false;
 uint8_t firstbyte;
 uint8_t secondbyte;
@@ -64,8 +64,8 @@
 #define BUSY 0x00
 //===================================================
 
-#define POWER_RESET_THRS 2
-#define HW_RESET_THRS 2
+#define POWER_RESET_THRS 5
+#define HW_RESET_THRS 5
 
 unsigned int Adf_data_counter=0;
 unsigned char status =0;
@@ -90,7 +90,7 @@
 buffer_state = true;\
 loop_on = true;\
 ADF_off = false;\
-/*sent_tmfrom_SDcard = false;*/\
+sent_tmfrom_SDcard = false;\
 Adf_data_counter=0;\
 status =0;\
 cmd_err_cnt=0;\
@@ -503,7 +503,9 @@
             T.stop();\
             T.reset();\
             loop_on=false;\
-            if(restart_adf_flag)\
+            break;\
+            /*if(restart_adf_flag)*/\
+            if(0)\
             {\
                 restart_adf_flag=false;\
                 ADF_off=false;\
@@ -521,7 +523,7 @@
                 gPC.printf("Data_error_detected");\
                 T.stop();\
                 T.reset();\
-                }\        
+                }\
         }\
 }
 
@@ -661,9 +663,16 @@
     initial_adf_check;\
     gPC.puts("Config_part done\r\n");\
 }
- 
+//obsrs_flag must be put high in obsrs 
+bool retransmit = true;
+bool configure = true;
 void transmit_adf(){
-while(power_reset_count<POWER_RESET_THRS){ 
+    configure =true;
+    
+while(retransmit||configure){
+    configure =0;
+    retransmit=0;
+while(power_reset_count<POWER_RESET_THRS){     
     restart_adf_flag=false;
     bool tx_err=false;
     configure_adf;
@@ -672,7 +681,8 @@
         gCS_ADF=0;
         spi.write(0x1B);
         spi.write(0x07);
-        spi.write(0x35);
+   //     spi.write(0x35);
+    spi.write(0x36);
         gCS_ADF=1;
     CMD(CMD_PHY_TX);
     wait_us(2000);
@@ -693,7 +703,13 @@
         break;
     }
     gPC.puts("after while looprn");
+    
 }
+if(restart_adf_flag){
+        retransmit=true;
+        restart_adf_flag=false;
+        }
 }
 
+}
 #endif
\ No newline at end of file
--- a/cdms_rtc.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/cdms_rtc.h	Sat Mar 11 04:46:31 2017 +0000
@@ -80,7 +80,7 @@
     gCS_RTC=1;
     gPC.puts("\n\r rtc initalised \n");
     RTC_INIT_STATUS = 1;
-    WRITE_TO_EEPROM(5,1);
+   FCTN_CDMS_WR_FLASH(5,1);
     SPI_mutex.unlock();
 }
  
--- a/cdms_sd.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/cdms_sd.h	Sat Mar 11 04:46:31 2017 +0000
@@ -20,17 +20,17 @@
 
 #define SD_MAX_CYCLES 10000
 
-uint32_t SD_SCP_FIRST=1001;
-uint32_t SD_SCP_LAST=2000;
-uint32_t SD_SFF_AT_FIRST=2001;
-uint32_t SD_SFF_AT_LAST = 3000;
-uint32_t SD_SFF_BT_FIRST =3001;
-uint32_t SD_SFF_BT_LAST=4000;
-uint32_t SD_HK_ARCH_FIRST=4001;
-uint32_t SD_HK_ARCH_LAST= 5000;
-uint32_t LOG_FIRST =5001;
-uint32_t LOG_LAST=6000;
-uint32_t SD_MNG_SECT = 8000;
+uint32_t SD_SCP_FIRST=10001;
+uint32_t SD_SCP_LAST=20000;
+uint32_t SD_SFF_AT_FIRST=20001;
+uint32_t SD_SFF_AT_LAST = 30000;
+uint32_t SD_SFF_BT_FIRST =30001;
+uint32_t SD_SFF_BT_LAST=40000;
+uint32_t SD_HK_ARCH_FIRST=40001;
+uint32_t SD_HK_ARCH_LAST= 50000;
+uint32_t LOG_FIRST =50001;
+uint32_t LOG_LAST=60000;
+uint32_t SD_MNG_SECT = 80000;
 
 extern uint8_t SD_INIT_FLAGS;
 
@@ -133,7 +133,7 @@
     if(SD_MNG_SECT != SD_LIB_BLK_CURRENT)
     {
         SD_LIB_BLK_CURRENT = SD_MNG_SECT;
-        WRITE_TO_EEPROM(16,SD_LIB_BLK_CURRENT);    
+        FCTN_CDMS_WR_FLASH(16,SD_LIB_BLK_CURRENT);      
     }
     SD_LIB_WRITES = SD_LIB_WRITES%(int)0xFFFF;
     disk_write(buffer,SD_MNG_SECT);
--- a/common_functions.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/common_functions.h	Sat Mar 11 04:46:31 2017 +0000
@@ -156,26 +156,37 @@
         gFLAGS = gFLAGS & ~(COM_PA_OC_FLAG);\
     /*P_CDMS_HANDLE_HW_FAULTS*/\
 }
-
 #define isPAhot(returnHere){\
     uint8_t pa_temp = 0;\
+    float pa_temp1 = 0;\
     SelectLinec0=0;\
     SelectLinec1=0;\
     SelectLinec2=0;\
     SelectLinec3=1;\
-    pa_temp = TempInput.read();\
-    pa_temp = pa_temp * 3.3;\
+    wait_ms(1);\
+    pa_temp1 = TempInput.read();\
+    pa_temp1 = pa_temp1 * 3.3;\
     float resistance;\
-    resistance = 24000 * pa_temp/(3.3 - pa_temp);\
-    if(pa_temp > 1.47) {\
-        pa_temp = 3694/log(24.032242*resistance);\
+    resistance = 24000 * pa_temp1/(3.3 - pa_temp1);\
+    if(pa_temp1 > 1.47) {\
+        pa_temp1 = (3694/log(24.032242*resistance))-273;\
     }\
     else{\
-        pa_temp = 3365.4/log(7.60573*resistance);\
+        pa_temp1 = (3365.4/log(7.60573*resistance))-273;\
     }\
-    COM_PA_IC_TMP = quantiz(tstart_thermistor,tstep_thermistor,pa_temp);\
+    gPC.printf("PA Temp = %f \r\n",pa_temp1);\
+    float pa_volt = 0;\
+    SelectLinec0=0;\
+    SelectLinec1=0;\
+    SelectLinec2=0;\
+    SelectLinec3=0;\
+    wait_ms(1);\
+    pa_volt = 2*3.3*TempInput.read();\
+    gPC.printf("PA V  = %f r\n",pa_volt);\
+    COM_PA_IC_TMP = quantiz(tstart_thermistor,tstep_thermistor,pa_temp1);\
+    COM_PA_TMP_IN_TX = COM_PA_IC_TMP;\
     /*comment this ater*/\
-    COM_PA_IC_TMP = 0;\
+     COM_PA_IC_TMP = 0;\
     /*COM_PA_TMP_HIGH to be found*/\
     if (COM_PA_IC_TMP > COM_PA_TMP_HIGH){\
         returnHere = 0xFF;\
--- a/i2c.h	Tue Feb 21 06:30:56 2017 +0000
+++ b/i2c.h	Sat Mar 11 04:46:31 2017 +0000
@@ -139,20 +139,17 @@
 {    
    //  gPC.printf("i2C_wr\r\n");
     CDMS_I2C_GPIO = 1;
-    wait_us(1);
     write_ack = master.write(addr_bae|0x00,data,tc_len2);    
     Thread::wait(1);   //As per the tests Thread::wait is not required on master side but its safe to give 1ms
     pdirw1=PTE->PDIR;
     uint8_t i2c_count = 0;
     if(write_ack == 0)
     {
-       gPC.printf("\n\r before count loop");
         while(((pdirw1 & 0x03000000)!=0x03000000)&& i2c_count<10)
         {
             Thread::wait(1);
             pdirw1=PTE->PDIR;
             i2c_count++;
-       
         }
         if(((pdirw1 & 0x03000000)==0x03000000))
         {
--- a/main.cpp	Tue Feb 21 06:30:56 2017 +0000
+++ b/main.cpp	Sat Mar 11 04:46:31 2017 +0000
@@ -1,7 +1,7 @@
 // TESTING PUSH PULL IN MAIN CPP
 
 #include "mbed.h"
-#include "eeprom.h"
+//#include "eeprom.h"
 
 #define DEBUG 1
 
@@ -15,7 +15,8 @@
 #include "DefinitionsAndGlobals.h"
 #include "crc.h"
 #include "i2c.h"
-#include "EEPROM.h"
+//#include "EEPROM.h"
+#include "Flash.h"
 #include "COM_SND_TM_functions.h"
 #include "cdms_rtc.h"
 #include "COM_SND_TM.h"
@@ -88,18 +89,19 @@
     
     FCTN_CDMS_INIT_RTC();/* rtc initialization*/
     FCTN_CDMS_SD_INIT();/* sd card initialization*/
-    INIT_EEPROM(); // added by samp
+   // INIT_EEPROM(); // added by samp
 
     CDMS_RESET_COUNTER++;
-    WRITE_TO_EEPROM(7,CDMS_RESET_COUNTER);
+    FCTN_CDMS_WR_FLASH(17,CDMS_RESET_COUNTER);
     TIME_LATEST_CDSMS_RESET = FCTN_CDMS_RD_RTC() >> 7;
-    WRITE_TO_EEPROM(8,TIME_LATEST_CDSMS_RESET);
+    FCTN_CDMS_WR_FLASH(8,TIME_LATEST_CDSMS_RESET);
     
+   // gPC.printf("%d \n", READ_FROM_EERPOM(8));
     uint8_t test[512];
   
     for(int i =0; i<512; i++)
         test[i] = 0;
-    disk_write(test,8000);
+    //disk_write(test,80000);
    
     //SD_MNG_SECT = SD_LIB_BLK_CURRENT;
     FCTN_SD_MNGR();