Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Sat Aug 06 06:34:38 2016 +0000
Parent:
288:aa93d6652381
Child:
290:3159ff1081a2
Commit message:
CDMS, including Chaitanya's part

Changed in this revision

CDMS_HK.h Show annotated file Show diff for this revision Revisions of this file
CDMS_PL.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
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
RESET_functions.h Show annotated file Show diff for this revision Revisions of this file
Structures.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
cdms_rtc.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	Fri Aug 05 17:13:23 2016 +0000
+++ b/CDMS_HK.h	Sat Aug 06 06:34:38 2016 +0000
@@ -11,6 +11,8 @@
 void minMaxHkData();
 void COLLECT_CDMS_RAM();
 
+extern uint8_t beacon_array[134];
+
 AnalogIn TempInput(PIN27);          // Input from Current Multiplexer
 AnalogIn CDMS_temp_sensor(PIN53);
 AnalogIn COMRX_RSSI_volatge(PIN70);
@@ -38,22 +40,35 @@
 void FCTN_CDMS_HK_MAIN(void const *args)
 {
     uint8_t sd_stat = 0;
+    uint8_t hk_count=0;
     while(1)
     {
     gHK_THREAD->signal_wait(HK_SIGNAL);
+    gMutex.lock();
+    if(hk_count == 1 || hk_count == 2)
+    {
+        FCTN_CDMS_PL_MAIN((void const *)NULL);
+        hk_count--;
+        continue;       
+    }
+    else if(hk_count == 0)
+    {
+        FCTN_CDMS_PL_MAIN((void const *)NULL);
+        hk_count = 2;
+    }
     gPC.printf("\n\nEntering HK thread\n");
 
-    gMutex.lock();
-
+    if(EN_CDMS_HK == 0x00)
+    continue;
     CDMS_HK_MAIN_STATUS = 0x01;
     CDMS_HK_MAIN_COUNTER++;
 
-    FCTN_CDMS_HK();
-    RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3;
+    FCTN_CDMS_HK();//collects temperatures
+    RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3;//to be checked
     VERIFY_COMRX();
     VERIFY_RTC();
     HANDLE_HW_FAULTS();
-    FUNC_CDMS_GPIO_STATUS(); //yet to be done
+    FUNC_CDMS_GPIO_STATUS();
 
     uint8_t CDMS_quant[20];
     CDMS_quant[1]= (uint8_t)quant_data.CDMS_temp_quant;
@@ -71,12 +86,30 @@
     for(int i = 0;i<20;i++)                                   //Collecting Data from Temp sensors
         CDMS_HEALTH_DATA[86+i] = CDMS_quant[i];
 
-    // Here: Have to FIT flash data.    
+    // Here: Have to FIT flash data.
+    CDMS_HEALTH_DATA[106] = (EPS_V_A_EN_STATUS<<7) | ((BAE_STATUS<<5)&0x60) | ((SD_STATUS<<3)&0x18) | ((PL_STATUS<<1)&0x06) | (PL_EPS_LATCH_SW_EN & 0x01);
+    CDMS_HEALTH_DATA[107] = (RTC_INIT_STATUS<<6) | ((CDMS_RTC_DISABLE<<5)&0x20);
+    CDMS_HEALTH_DATA[108] = CDMS_RESET_COUNTER >>8;
+    CDMS_HEALTH_DATA[109] = CDMS_RESET_COUNTER;
+    CDMS_HEALTH_DATA[110] = TIME_LATEST_CDSMS_RESET >>24;
+    CDMS_HEALTH_DATA[111] = TIME_LATEST_CDSMS_RESET >>16;
+    CDMS_HEALTH_DATA[112] = TIME_LATEST_CDSMS_RESET >>8;
+    CDMS_HEALTH_DATA[113] = TIME_LATEST_CDSMS_RESET;
+    CDMS_HEALTH_DATA[114] = COM_TC_BYTES_LIMIT>>8;
+    CDMS_HEALTH_DATA[115] = COM_TC_BYTES_LIMIT;
+    CDMS_HEALTH_DATA[116] = COM_RX_CURRENT_MAX;
+    CDMS_HEALTH_DATA[117] = COM_RX_DISABLE_TIMEOUT;
+    CDMS_HEALTH_DATA[118] = COM_PA_TMP_HIGH;
+    CDMS_HEALTH_DATA[119] = COM_PA_RECOVERY_TIMEOUT;
+    CDMS_HEALTH_DATA[120] = COM_SESSION_TIMEOUT;
+    CDMS_HEALTH_DATA[121] = COM_RSSI_MIN;
+    CDMS_HEALTH_DATA[122] = SD_LIB_BLK_CURRENT>>8;
+    CDMS_HEALTH_DATA[122] = SD_LIB_BLK_CURRENT;
     
     uint64_t time = FCTN_CDMS_RD_RTC() >> 7;             //Reading Time from RTC
     for(int i = 124; i<128; i++)
         CDMS_HEALTH_DATA[i] = time >> i*8;
-    gPC.printf("0x%x\n",time);
+    gPC.printf("0x%d\n",time);
     FCTN_SD_MNGR();                                 //Adding FSC & TMID to TM frame
     CDMS_HK_FRAME[0] = 0x20;
     CDMS_HK_FRAME[1] = FSC_CURRENT[4]+1;
@@ -104,15 +137,16 @@
         gPC.puts("sd write failure");
         break;
         }
-    /*gPC.printf("Completed CDMS HK\t")*/;
+    gPC.printf("Completed CDMS HK\t");
 
     /*---------------------------------- BAE HK --------------------------------------------*/
 
     BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
-    /*gPC.printf("Entering BAE HK\t")*/;
+    gPC.printf("Entering BAE HK\t");
     if(BAE_HK_I2C == 0) {
         crc = crc16_gen((unsigned char *)BAE_HK,132);
         if(crc == ((uint16_t)BAE_HK[132] << 8) | (uint16_t)BAE_HK[133]){
+            gPC.printf("BAE HK data recieved through I2C\t");
             TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7;
             /*for(int i = 0; i<15; i++)
                 gPC.printf("\r 0x%02X\n",BAE_HK[i]);*/
@@ -143,28 +177,51 @@
         }
         
     } else {
-        /*gPC.printf("BAE HK data not recieved through I2C\t")*/;
+        gPC.printf("BAE HK data not recieved through I2C\t");
         for(int i = 0; i<134; i++)
             BAE_HK[i] = 0;
     }
-    /*gPC.printf("Completed BAE HK\n")*/;
+    gPC.printf("Completed BAE HK\n");
 
     /*----------------------------------Beacon message--------------------------------------*/
-    unsigned char SC_HK_LBM_0[135];
-    SC_HK_LBM_0[0] = 0;       // Sending long beacon msg as telecommand with Packet sequence count 0x00
+    
+    
     // Add HK bits
-
+    beacon_array[0] = 0x00;
+    beacon_array[1] = time >> 32;
+    beacon_array[2] = time >> 24;
+    beacon_array[3] = time >> 16;
+    beacon_array[4] = time >> 8;
+    beacon_array[5] = time;
+    beacon_array[6] = SD_FAULTCOUNT >> 8;
+    beacon_array[7] = SD_FAULTCOUNT;
+    beacon_array[8] = RTC_FAULTCOUNT >> 8;
+    beacon_array[9] = RTC_FAULTCOUNT;
+    beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(V_C_PGOOD<<2)|(COMRX_OC_FAULT<<1)|(COMTX_OC_FAULT);
+    beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL);
+    beacon_array[12] = CDMS_HK_MAIN_COUNTER >>8;
+    beacon_array[13] = CDMS_HK_MAIN_COUNTER;
+    beacon_array[14] = PL_MAIN_COUNTER >>8;
+    beacon_array[15] = PL_MAIN_COUNTER;
+    beacon_array[16] = PL_RCV_SC_DATA_COUNTER >>8;
+    beacon_array[17] = PL_RCV_SC_DATA_COUNTER;
+    beacon_array[18] = TIME_LATEST_SPI_SPEED >>24;
+    beacon_array[19] = TIME_LATEST_SPI_SPEED >>16;
+    beacon_array[20] = TIME_LATEST_SPI_SPEED >>8;
+    beacon_array[21] = TIME_LATEST_SPI_SPEED;
+    beacon_array[22] = (uint8_t)RSSI_volatge;
+    
     // Add SC bits
-    crc = crc16_gen(SC_HK_LBM_0,133);
-    SC_HK_LBM_0[132] = crc;
-    SC_HK_LBM_0[133] = crc >> 8;
+    crc = crc16_gen(beacon_array,132);
+    beacon_array[132] = crc;
+    beacon_array[133] = crc >> 8;
     bool y;
-    y = FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135);
+    y = FCTN_I2C_WRITE((char *)beacon_array,134);
     if(y == 0)
-        /*gPC.printf("long Bcn sent\n\r")*/;
+        gPC.printf("long Bcn sent\n\r");
         else
         gPC.printf("long Bcn not sent\r\n");
-    gPC.printf("\rCompleted HK\n");
+    gPC.printf("\rCompleted Beacon\n");
     gMutex.unlock();
     }
 }
@@ -213,6 +270,7 @@
 {
 
     int Iteration=0;
+    int resistance;
 
     SelectLinec0=0;
     SelectLinec1=0;
@@ -237,11 +295,9 @@
     for(Iteration=0; Iteration<16; Iteration++) {
 
         if(Iteration<14) {
-
             actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3;
-            int resistance;
-
             resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]);
+            
             if(actual_data.temp_actual[Iteration]>1.47) {
                 actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance);
             } else {
@@ -293,21 +349,21 @@
     //PL_EPS_LATCH_SW_OC_FAULT // to be verified
     GPIO_STATUS=(PL_EPS_LATCH_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<4)):(GPIO_STATUS)&(~((uint16_t)(0x1<<4)));
     //EPS_V_C_EN_STATUS
-    GPIO_STATUS=(EPS_V_C_EN_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<3)):(GPIO_STATUS)&(~((uint16_t)(0x1<<3)));
+    GPIO_STATUS=(COM_RX_CNTRL)?(GPIO_STATUS)||((uint16_t)(0x1<<3)):(GPIO_STATUS)&(~((uint16_t)(0x1<<3)));
     //EPS_V_D_EN_STATUS
-    GPIO_STATUS=(EPS_V_D_EN_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<2)):(GPIO_STATUS)&(~((uint16_t)(0x1<<2)));
+    GPIO_STATUS=(COM_TX_CNTRL)?(GPIO_STATUS)||((uint16_t)(0x1<<2)):(GPIO_STATUS)&(~((uint16_t)(0x1<<2)));
     
 }
 
 void VERIFY_COMRX()
 {
     //COMRX_OC_FAULT //$
-    if(PIN68==0 && RSSI_volatge > 0.4) {
+    if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4) {
         COMRX_STATUS = COMRX_ALIVE;
     } else {
         RESET_COMRX();
         COMRX_RESET_COUNTER++;
-        if(PIN68==0 && RSSI_volatge > 0.4)
+        if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4)
             COMRX_STATUS = COMRX_ALIVE;
         else
             COMRX_STATUS = COMRX_DEAD;
@@ -316,21 +372,20 @@
 
 void VERIFY_RTC()
 {
-    if(RTC_STATUS == 0x00) {
-        if(RTC_FAULTCOUNT == 3)
+        uint8_t response;
+        if(EN_RTC == 0x00)
         return;
-        SPI_mutex.lock();
         gCS_RTC=1;
         gCS_RTC=0;
         spi.write(0x0F);
-        if(spi.write(0x00) & 0x04 == 0x04) {
-            RTC_STATUS = 0x00;
+        response = spi.write(0x00);
+        CDMS_RTC_BL = (response & 0x10) >>4;
+        if(response & 0x04 == 0x04) {
             RESET_RTC();
+            RTC_STATUS = 0x01;
             RTC_FAULTCOUNT++;
         }
         gCS_RTC=1;
-        SPI_mutex.unlock();
-    }
 }
 
 void HANDLE_HW_FAULTS()
@@ -343,16 +398,25 @@
 void HANDLE_HW_FAULT_SD()
 {
     if(SD_STATUS != DEVICE_DISABLED) {
-        if(SD_STATUS == DEVICE_OC_FAULT)
-            SD_SW_EN_DS = 0; //powering on SD
-
+        if(SD_STATUS == DEVICE_OC_FAULT){
+            gPC.printf("Switching on SD card");
+            SD_SW_EN_DS = 1; //powering on SD
+            wait_ms(10);
+        }
+            
         if(SD_OC_FAULT == 0) {
-            SD_SW_EN_DS = 1; //switching off SD card
-
+            gPC.printf("Switching off SD card");
+            SD_SW_EN_DS = 0; //switching off SD card
             SD_FAULTCOUNT++;
             SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT;
+            if(SD_FAULTCOUNT == 3){
+                FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED);    
+                gPC.printf("Declaring SD card permanantly Disabled");
+            }
         } else {
             SD_STATUS = DEVICE_POWERED;
+            if(SD_STATUS != DEVICE_POWERED)
+                FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
             SD_FAULTCOUNT = 0;
         }
     }
@@ -361,15 +425,25 @@
 void HANDLE_HW_FAULT_BAE()
 {
     if(BAE_STATUS != DEVICE_DISABLED) {
-        if(BAE_STATUS == DEVICE_OC_FAULT)
-            BAE_SW_EN_DS = 0; //Power ON BAE
-
-        if(BAE_OC_FAULT == 0) { // If OC Fault
-            BAE_SW_EN_DS = 1; //Switch OFF BAE
+        if(BAE_STATUS == DEVICE_OC_FAULT){
+            gPC.printf("Switching on BAE");
+            BAE_SW_EN_DS = 1; //Power ON BAE
+            wait_ms(10);
+        }
+        
+        if(BAE_OC_FAULT == 0) {
+            gPC.printf("Switching off BAE");
+            BAE_SW_EN_DS = 0; //Switch OFF BAE
             BAE_FAULTCOUNT++;
             BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
+            if(BAE_FAULTCOUNT == 3){
+                FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED);
+                gPC.printf("Declaring BAE permanantly Disabled");
+            }
         } else {
             BAE_STATUS = DEVICE_POWERED;
+            if(SD_STATUS != DEVICE_POWERED);
+                FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
             BAE_FAULTCOUNT = 0;
         }
     }
@@ -379,6 +453,7 @@
 {
     if(PL_STATUS != DEVICE_DISABLED) {
         if(PL_STATUS == DEVICE_OC_FAULT){
+            gPC.printf("Switching on PL_BEE");
             PYLD_DFF_CLK = 0;
             PYLD_DFF = 1;           // Switching ON PL
             wait_us(1);
@@ -388,6 +463,7 @@
             wait_us(1);         
         }
         if(PL_BEE_SW_OC_FAULT == 0) { // if OC Fault
+            gPC.printf("Switching off PL_BEE");
             PYLD_DFF_CLK = 0;     
             PYLD_DFF = 0;             //Switching OFF PL
             wait_us(1);
@@ -397,8 +473,13 @@
             wait_us(1);
             PL_FAULTCOUNT++;
             PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
+            if(PL_FAULTCOUNT == 3){
+                FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED);
+                gPC.printf("Declaring PL_BEE permanantly Disabled");
+            }
         } else {
             if(PL_STATUS == DEVICE_OC_FAULT){
+                gPC.printf("Switching off PL_BEE");
                 PYLD_DFF_CLK = 0;     
                 PYLD_DFF = 0;             //Switching OFF PL
                 wait_us(1);
@@ -408,6 +489,8 @@
                 wait_us(1);
             }
             PL_STATUS = DEVICE_ENABLED;
+            if(PL_STATUS != DEVICE_ENABLED)
+                FCTN_CDMS_WR_FLASH(3,DEVICE_ENABLED);
             PL_FAULTCOUNT = 0;
         }
     }
--- a/CDMS_PL.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/CDMS_PL.h	Sat Aug 06 06:34:38 2016 +0000
@@ -269,7 +269,7 @@
     if(t!=0)
     {
         gPC.printf("\n\rTesting OC protection");
-        PL_BEE_SW_STATUS = 2;   //OC protection
+        PL_STATUS = 2;   //OC protection
     }
 }
 void test2(uint8_t t)
@@ -278,7 +278,7 @@
     if(t!=0)    
     {
         gPC.printf("\n\rTesting Deviced Disabled case");
-        PL_BEE_SW_STATUS = 3;   //Device DISABLED 
+        PL_STATUS = 3;   //Device DISABLED 
     }
 }
 void test3(uint8_t t)
@@ -299,6 +299,8 @@
 }*/
 void FCTN_CDMS_PL_MAIN(void const *args)
 {
+    if(EN_PL == 0x00)
+    return;
     uint8_t temp[3];
     pl_main_flag|=PL_MAIN_STATUS;                       //Setting PL_MAIN_STATUS
     PL_MAIN_COUNTER++;                                  
@@ -308,7 +310,7 @@
     temp[2] = (PL_PREV_STATE & STATE_SCIENCE)>>2;
     //test2(1);
 
-    if(PL_BEE_SW_STATUS==2 || PL_BEE_SW_STATUS==3)
+    if(PL_STATUS==2 || PL_STATUS==3)
     {
         gPC.printf("\n\rDevice Disabled or OC Fault");
         pl_main_flag  = pl_main_flag & (~PL_DISABLED);
@@ -420,14 +422,14 @@
         case STATE_OFF: 
         {
             gPC.printf("\n\rEntered PL_OFF case");
-            if(PL_BEE_SW_STATUS!=0) 
+            if(PL_STATUS!=0) 
             {
                 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
                 Base_tm *tm_ptr_standby;
                 SET_PL_BEE_STANDBY(tm_ptr_standby);                             //No ack needed now
                 gPC.printf("\n\rPowering OFF PL_BEE");
                 SET_PL_BEE_OFF;
-                PL_BEE_SW_STATUS=0;    
+                PL_STATUS=0;    
             }           
             pl_main_flag  = pl_main_flag & (~PL_DISABLED);
             pl_main_flag |= PL_OFF;    
@@ -441,11 +443,11 @@
         case STATE_STANDBY: 
         {            
             gPC.printf("\n\rEntered PL_STANDBY case");
-            if(PL_BEE_SW_STATUS==0) 
+            if(PL_STATUS==0) 
             {
                 gPC.printf("\n\rPowering on PL_BEE");
                 SET_PL_BEE_ON;
-                PL_BEE_SW_STATUS=1;
+                PL_STATUS=1;
             }
             gPC.printf("\n\rCommanding PL_BEE to go to Standby State");  
             Base_tm *tm_ptr_standby;
@@ -466,11 +468,11 @@
             gPC.printf("\n\rEntered PL_HIBERNATE case");
             if(POWER_LEVEL==2 || POWER_LEVEL==3 || POWER_LEVEL==0)
             {                
-                if(PL_BEE_SW_STATUS==0) 
+                if(PL_STATUS==0) 
                 {
                     gPC.printf("Powering on PL_BEE\r\n");                    
                     SET_PL_BEE_ON;
-                    PL_BEE_SW_STATUS=1;
+                    PL_STATUS=1;
                 }
                 gPC.printf("\n\rCommanding PL_BEE to go to Hibernate State");  
                 Base_tm *tm_ptr_hibernate;
@@ -484,11 +486,11 @@
             else 
             {
                 pl_main_flag |= PL_LOW_POWER;
-                if(PL_BEE_SW_STATUS==0) 
+                if(PL_STATUS==0) 
                 {
                     gPC.printf("\n\rPowering on PL_BEE");
                     SET_PL_BEE_ON;
-                    PL_BEE_SW_STATUS=1;
+                    PL_STATUS=1;
                 }
                 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
                 Base_tm *tm_ptr_standby;
@@ -516,11 +518,11 @@
             if(POWER_LEVEL==3 || POWER_LEVEL==0)                            //POWER_LEVEL = 0 = NA
             {
                 gPC.printf("\n\rPOWER_LEVEL = 3 or NA");
-                if(PL_BEE_SW_STATUS==0)
+                if(PL_STATUS==0)
                 {
                     gPC.printf("\n\rPowering on PL_BEE");
                     SET_PL_BEE_ON;
-                    PL_BEE_SW_STATUS=1;
+                    PL_STATUS=1;
                 }
                 gPC.printf("\n\rCommanding PL_BEE to go to Science State");  
                 Base_tm *tm_ptr_science;
@@ -541,11 +543,11 @@
                 pl_main_flag |= PL_LOW_POWER;
                 if(POWER_LEVEL==2 || POWER_LEVEL==3 || POWER_LEVEL==0)
                 {                
-                    if(PL_BEE_SW_STATUS==0) 
+                    if(PL_STATUS==0) 
                     {
                         gPC.printf("\n\rPowering on PL_BEE");
                         SET_PL_BEE_ON;
-                        PL_BEE_SW_STATUS=1;
+                        PL_STATUS=1;
                     }
                     gPC.printf("\n\rCommanding PL_BEE to go to Hibernate State");  
                     Base_tm *tm_ptr_hibernate;
@@ -559,11 +561,11 @@
                 else 
                 {
                     pl_main_flag |= PL_LOW_POWER;
-                    if(PL_BEE_SW_STATUS==0) 
+                    if(PL_STATUS==0) 
                     {
                         gPC.printf("\n\rPowering on PL_BEE");
                         SET_PL_BEE_ON;
-                        PL_BEE_SW_STATUS=1;
+                        PL_STATUS=1;
                     }
                     gPC.printf("\n\rCommanding PL_BEE to go to Standby State");  
                     Base_tm *tm_ptr_standby;
--- a/COM_MNG_TMTC.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/COM_MNG_TMTC.h	Sat Aug 06 06:34:38 2016 +0000
@@ -881,7 +881,13 @@
                         {                         
                             //gPC.printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function
                             
-                            STANDBY_PRCS();
+                            if(tc_ptr->TC_string[4] == 0x00 || tc_ptr->TC_string[4] == 0x01)
+                            EN_PL = tc_ptr->TC_string[4];
+                            else if(tc_ptr->TC_string[5] == 0x00 || tc_ptr->TC_string[5] == 0x01)
+                            EN_CDMS_HK = tc_ptr->TC_string[5];
+                            else if(tc_ptr->TC_string[6] == 0x00 || tc_ptr->TC_string[6] == 0x01)
+                            EN_RCV_SC = tc_ptr->TC_string[6];
+                            
                             Base_tm *tm_ptr_short = new Short_tm;
                             ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr));
                             return tm_ptr_short;                                                    
@@ -1624,7 +1630,7 @@
         COM_POWER_OFF_TX;\
         reset_all;\
         /*ENABLE THREADS*/\
-        gPAY_SPI->bulkRead_resume(&payload_isr_fun);\
+        /*gPAY_SPI->bulkRead_resume(&payload_isr_fun)*/;\
         HK_counter->start(10000);\
         gSESSION_TIMEOUT.detach();\
         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
--- a/DefinitionsAndGlobals.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/DefinitionsAndGlobals.h	Sat Aug 06 06:34:38 2016 +0000
@@ -206,10 +206,9 @@
 DigitalOut RF_SW_CNTRL_BCN(RF_RELAY_CNTRL_BCN);
 DigitalOut RF_SW_CNTRL_TX(RF_RELAY_CNTRL_TX);
 
-
 //COM_RX
-DigitalOut COM_RX_CNTRL(PIN72);
-DigitalOut COM_TX_CNTRL(PIN56);
+DigitalOut COM_RX_CNTRL(PIN72,1);
+DigitalOut COM_TX_CNTRL(PIN56,1);
 DigitalIn COM_TX_OC_FAULT(PIN69);
 
 // TC LIST
@@ -258,13 +257,13 @@
 uint16_t GPIO_STATUS;
 uint8_t CDMS_HK_MAIN_STATUS;    
 uint8_t COMRX_STATUS;
-uint8_t RTC_FAULTCOUNT;
-uint16_t SD_FAULTCOUNT;
+uint8_t RTC_FAULTCOUNT = 0;
+uint16_t SD_FAULTCOUNT = 0;
 uint8_t SD_STATUS;
-uint8_t BAE_FAULTCOUNT;
+uint8_t BAE_FAULTCOUNT = 0;
 uint8_t BAE_STATUS;
 uint8_t PL_STATUS;
-uint16_t PL_FAULTCOUNT;
+uint16_t PL_FAULTCOUNT = 0;
 bool BAE_HK_I2C;
 uint8_t RTC_STATUS;
 float RSSI_volatge;
@@ -287,16 +286,16 @@
 DigitalOut PL_GPIO_3_STATUS (PIN80);// PYLD EPS CNTRL 3 / PYLD_EPS_CNTRL_3
 DigitalIn PL_BEE_SW_OC_FAULT (PIN91);
 DigitalIn PL_EPS_LATCH_SW_OC_FAULT (PIN5);
-DigitalOut EPS_V_C_EN_STATUS (PIN72,1);//COMM RX PWR CNTRL
-DigitalOut EPS_V_D_EN_STATUS (PIN56,1);//3V6_EN
+//DigitalOut EPS_V_C_EN_STATUS (PIN72,1);//COMM RX PWR CNTRL
+//DigitalOut EPS_V_D_EN_STATUS (PIN56,1);//3V6_EN
 
 
 DigitalIn SD_OC_FAULT (PIN90);
 DigitalOut SD_SW_EN_DS (PIN97,1);//SD CARD SW EN/DIS or SD_CARD_SW_EN_DIS
 DigitalOut BAE_SW_EN_DS (PIN47,1);//BAE_SW_EN_DIS
-DigitalOut TRXY_EN (PIN84);//TRXY EN
-DigitalOut TRZ_EN (PIN88);//TRZ EN
-DigitalOut V_A_EN (PIN99);//TRZ FLT (no INTR capability)
+//DigitalOut TRXY_EN (PIN84);//TRXY EN
+//DigitalOut TRZ_EN (PIN88);//TRZ EN
+DigitalOut V_A_EN (PIN99,1);//TRZ FLT (no INTR capability)
 DigitalIn sys_pwr_rst (PIN46);//PTD3
 
 DigitalOut PYLD_DFF (PIN73);//PYLD_SW_PWR_EN_DIS
@@ -342,19 +341,20 @@
 uint8_t COM_TX;
 uint8_t COM_TX_STATUS;
 uint8_t COM_MNG_TMTC;
-uint8_t EN_CDMS_HK;
-uint8_t EN_PL;
-uint8_t EN_RCV_SC;
+uint8_t EN_CDMS_HK = 0x01;
+uint8_t EN_PL = 0x01;
+uint8_t EN_RCV_SC = 0x01;
 uint8_t CDMS_INIT_STATUS;
 uint8_t CDMS_HK_STATUS;
 uint8_t COM_RX_STATUS;
 uint8_t CDMS_RTC_BL;
 
 //CDMS FLASH parameters
+
 uint8_t EPS_V_A_EN_STATUS;
-uint8_t BAE_SW_STATUS;
-uint8_t CDMS_SD_SW_STATUS;
-uint8_t PL_BEE_SW_STATUS;
+//uint8_t BAE_SW_STATUS;
+//uint8_t CDMS_SD_SW_STATUS;
+//uint8_t PL_BEE_SW_STATUS;*
 uint8_t PL_EPS_LATCH_SW_EN;
 uint8_t RTC_INIT_STATUS;
 uint8_t CDMS_RTC_DISABLE;
@@ -367,4 +367,7 @@
 uint8_t COM_PA_RECOVERY_TIMEOUT;
 uint8_t COM_SESSION_TIMEOUT;
 uint8_t COM_RSSI_MIN;
-uint16_t SD_LIB_BLK_CURRENT;
\ No newline at end of file
+uint16_t SD_LIB_BLK_CURRENT;
+
+// Ambigouties
+uint8_t EN_RTC = 0x01;
\ No newline at end of file
--- a/FMS_all.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/FMS_all.h	Sat Aug 06 06:34:38 2016 +0000
@@ -3,7 +3,6 @@
 
 /*===================================================FMS Functions=================================================*/
 
-void STANDBY_PRCS();
 
 //Run processes
 void P_PL_INIT();
@@ -48,11 +47,6 @@
     SYS_PWR_RESET();
 }
 
-void STANDBY_PRCS()
-{
-    
-}
-
 void P_PL_INIT()
 {
     
@@ -85,18 +79,16 @@
 
 void CDMS_SD_SW_ON()
 {
-    SD_SW_EN_DS = 0;
+    SD_SW_EN_DS = 1;
     SD_STATUS = DEVICE_POWERED;
-    CDMS_SD_SW_STATUS = DEVICE_POWERED;
     FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
     gPC.printf("sw on sd\n");
 }
 
 void CDMS_SD_SW_OFF()
 {
-    SD_SW_EN_DS = 1;
+    SD_SW_EN_DS = 0;
     SD_STATUS = DEVICE_DISABLED;
-    CDMS_SD_SW_STATUS = DEVICE_DISABLED;
     FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED);
     gPC.printf("sw off sd\n");
 }
@@ -126,18 +118,16 @@
 
 void SW_ON_BAE()
 {
-    BAE_SW_EN_DS = 0;
+    BAE_SW_EN_DS = 1;
     BAE_STATUS = DEVICE_POWERED;
-    BAE_SW_STATUS = DEVICE_POWERED;
     FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
     gPC.printf("sw on bae\n");
 }
 
 void SW_OFF_BAE()
 {
-    BAE_SW_EN_DS = 1;
+    BAE_SW_EN_DS = 0;
     BAE_STATUS = DEVICE_DISABLED;
-    BAE_SW_STATUS = DEVICE_DISABLED;
     FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED);
     gPC.printf("sw off bae\n");
 }
@@ -152,7 +142,6 @@
     PYLD_DFF_CLK = 0;
     wait_us(1);
     PL_STATUS = DEVICE_POWERED;
-    PL_BEE_SW_STATUS = DEVICE_POWERED;
     FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED);
 }
 
@@ -166,7 +155,6 @@
     PYLD_DFF_CLK = 0;
     wait_us(1);
     PL_STATUS = DEVICE_DISABLED;
-    PL_BEE_SW_STATUS = DEVICE_DISABLED;
     FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED);
 }
 
@@ -212,39 +200,45 @@
 
 void RST_SD()
 {
-    SD_SW_EN_DS = 1;
+    SD_SW_EN_DS = 0;
     wait_ms(10);
-    SD_SW_EN_DS = 0;
+    SD_SW_EN_DS = 1;
+    SD_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
     gPC.printf("rst sd\n");
 }
 
 void SW_RST_BAE()
 {
-    BAE_SW_EN_DS = 1;
+    BAE_SW_EN_DS = 0;
     wait_ms(10);
-    BAE_SW_EN_DS = 0;
+    BAE_SW_EN_DS = 1;
+    BAE_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
     gPC.printf("rst bae\n");
 }
 
 void SW_RST_PL_BEE()
 {
-    PYLD_DFF = 1;
+    PYLD_DFF = 0;
     wait_ms(10);
-    PYLD_DFF = 0;
+    PYLD_DFF = 1;
+    PL_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED);
 }
 
 void RST_BAE()
 {
-    RESET_TO_BAE = 1;
+    RESET_TO_BAE = 0;
     wait_ms(10);
-    RESET_TO_BAE = 0;
+    RESET_TO_BAE = 1;
 }
 
 void RST_PL_BEE()
 {
-    RESET_TO_PYLD = 1;
+    RESET_TO_PYLD = 0;
     wait_ms(10);
-    RESET_TO_PYLD = 0;
+    RESET_TO_PYLD = 1;
 }
 
 void CDMS_INTERNAL_RESET()
@@ -346,6 +340,4 @@
 {
     for(int i=4;i<132;i++)
     tm_pointer->TM_string[i] = CDMS_HK_FRAME[i-4];
-}
-
-
+}
\ No newline at end of file
--- a/Flash.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/Flash.h	Sat Aug 06 06:34:38 2016 +0000
@@ -30,9 +30,9 @@
                 read[j] = nativeflash[j];
             }
             EPS_V_A_EN_STATUS = read[0];
-            BAE_SW_STATUS   = read[1]; 
-            CDMS_SD_SW_STATUS = read[2];
-            PL_BEE_SW_STATUS = read[3];
+            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];
--- a/RESET_functions.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/RESET_functions.h	Sat Aug 06 06:34:38 2016 +0000
@@ -4,6 +4,7 @@
 
 void RESET_COMRX()
 {
+    gPC.printf("\r COM RX resetting\n");
     COM_RX_CNTRL = 0;
     wait_ms(10);
     COM_RX_CNTRL =1;
@@ -11,7 +12,7 @@
 
 void RESET_RTC()
 {
-    SPI_mutex.lock();
+    gPC.printf("Resetting RTC");
     gCS_RTC=1;
     gCS_RTC=0;
     spi.write(0x81); //register address with write flag
@@ -34,5 +35,4 @@
     gCS_RTC=0;
     spi.write(0x8F);
     spi.write(0x00);
-    SPI_mutex.unlock();
 }
\ No newline at end of file
--- a/Structures.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/Structures.h	Sat Aug 06 06:34:38 2016 +0000
@@ -145,9 +145,9 @@
 // CDMS HK
 
 #define tstart -40
-#define tstep   8            //to be finalized by thermal team
+#define tstep   1            //to be finalized by thermal team
 #define tstart_thermistor -40
-#define tstep_thermistor 8
+#define tstep_thermistor 1
 
 typedef struct CDMS_HK_actual
 {
--- a/ThreadsAndFunctions.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/ThreadsAndFunctions.h	Sat Aug 06 06:34:38 2016 +0000
@@ -23,7 +23,7 @@
         gPC.puts("sig_set\r\n");
         //for(int i =0; i<PAYLOAD_BUFFER_LENGTH; i++)
         //if (gPAYLOAD_BUFFER[i] != 0) gPC.printf("not zero");  
-        //srp(gPAYLOAD_BUFFER);//skip one apcket when cdms resets
+        srp(gPAYLOAD_BUFFER);//skip one apcket when cdms resets
         gPC.puts("exit_srp\r\n");
         wait(2);/*timeout to be decided*/
         if(dma)
@@ -161,7 +161,7 @@
         }
         else if( gFLAGS & NEW_TC_RECEIVED ){
             gPC.puts("NEW TC RECEIVED\r\n");
-            Thread::wait(10000);
+            //Thread::wait(10000);
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
--- a/cdms_rtc.h	Fri Aug 05 17:13:23 2016 +0000
+++ b/cdms_rtc.h	Sat Aug 06 06:34:38 2016 +0000
@@ -1,6 +1,8 @@
 
 void FCTN_CDMS_INIT_RTC()
 {   
+    if(EN_RTC == 0)
+    return;
     wait_ms(4000);
     SPI_mutex.lock();
     gCS_RTC=1;
@@ -82,6 +84,8 @@
  
 uint64_t FCTN_CDMS_RD_RTC()
 {   
+    if(EN_RTC == 0)
+    return 0;
     SPI_mutex.lock(); 
     uint8_t response;
     uint64_t time = 0;
--- a/main.cpp	Fri Aug 05 17:13:23 2016 +0000
+++ b/main.cpp	Sat Aug 06 06:34:38 2016 +0000
@@ -1,4 +1,3 @@
-
 // TESTING PUSH PULL IN MAIN CPP
 
 #include "mbed.h"
@@ -17,15 +16,15 @@
 #include "i2c.h"
 #include "COM_SND_TM_functions.h"
 #include "COM_SND_TM.h"
+#include "Flash.h"
 #include "cdms_rtc.h"
 #include "cdms_sd.h"
 #include "common_functions.h"
 #include "RESET_functions.h"
+#include "CDMS_PL.h"
 #include "CDMS_HK.h"
 #include "adf.h"
 #include "COM_RCV_TC.h"
-#include "Flash.h"
-#include "CDMS_PL.h"
 #include "FMS_all.h"
 #include "Compression.h"
 #include "COM_MNG_TMTC.h"