DMA issue to be tested

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Files at this revision

API Documentation at this revision

Comitter:
chaithanyarss
Date:
Sat Jul 30 15:25:21 2016 +0000
Parent:
281:d1c9ae3605a3
Child:
283:5ea9ea429b55
Commit message:
testing HK thread Indo MIM

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	Wed Jul 27 12:14:58 2016 +0000
+++ b/CDMS_HK.h	Sat Jul 30 15:25:21 2016 +0000
@@ -40,31 +40,31 @@
 void FCTN_CDMS_HK_MAIN(void const *args)
 {
     uint8_t sd_stat = 0;
-    uint8_t count=0;
+    uint8_t hk_count=0;
     while(1)
     {
     gHK_THREAD->signal_wait(HK_SIGNAL);
-    if(count == 1 || count == 2)
+    gMutex.lock();
+    if(hk_count == 1 || hk_count == 2)
     {
         FCTN_CDMS_PL_MAIN((void const *)NULL);
-        count--;
+        hk_count--;
         continue;       
     }
-    else if(count == 0)
+    else if(hk_count == 0)
     {
         FCTN_CDMS_PL_MAIN((void const *)NULL);
-        count = 2;
+        hk_count = 2;
     }
     gPC.printf("\n\nEntering HK thread\n");
 
     if(EN_CDMS_HK == 0x00)
     continue;
-    gMutex.lock();
     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();
@@ -87,7 +87,7 @@
         CDMS_HEALTH_DATA[86+i] = CDMS_quant[i];
 
     // Here: Have to FIT flash data.
-    CDMS_HEALTH_DATA[106] = (EPS_V_A_EN_STATUS<<7) | ((BAE_SW_STATUS<<5)&0x60) | ((CDMS_SD_SW_STATUS<<3)&0x18) | ((PL_BEE_SW_STATUS<<1)&0x06) | (PL_EPS_LATCH_SW_EN & 0x01);
+    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;
@@ -109,7 +109,7 @@
     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;
@@ -269,6 +269,7 @@
 {
 
     int Iteration=0;
+    int resistance;
 
     SelectLinec0=0;
     SelectLinec1=0;
@@ -293,11 +294,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 {
@@ -358,12 +357,12 @@
 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;
@@ -372,17 +371,20 @@
 
 void VERIFY_RTC()
 {
-        SPI_mutex.lock();
+        uint8_t response;
+        if(EN_RTC == 0x00)
+        return;
         gCS_RTC=1;
         gCS_RTC=0;
         spi.write(0x0F);
-        if(spi.write(0x00) & 0x04 == 0x04) {
+        response = spi.write(0x00);
+        CDMS_RTC_BL = (response & 0x10) >>4;
+        if(response & 0x04 == 0x04) {
+            RESET_RTC();
             RTC_STATUS = 0x01;
-            RESET_RTC();
             RTC_FAULTCOUNT++;
         }
         gCS_RTC=1;
-        SPI_mutex.unlock();
 }
 
 void HANDLE_HW_FAULTS()
@@ -395,16 +397,25 @@
 void HANDLE_HW_FAULT_SD()
 {
     if(SD_STATUS != DEVICE_DISABLED) {
-        if(SD_STATUS == DEVICE_OC_FAULT)
+        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) {
+            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;
         }
     }
@@ -413,15 +424,25 @@
 void HANDLE_HW_FAULT_BAE()
 {
     if(BAE_STATUS != DEVICE_DISABLED) {
-        if(BAE_STATUS == DEVICE_OC_FAULT)
+        if(BAE_STATUS == DEVICE_OC_FAULT){
+            gPC.printf("Switching on BAE");
             BAE_SW_EN_DS = 1; //Power ON BAE
-
-        if(BAE_OC_FAULT == 0) { // If OC Fault
+            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;
         }
     }
@@ -431,6 +452,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);
@@ -440,6 +462,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);
@@ -449,8 +472,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);
@@ -460,6 +488,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	Wed Jul 27 12:14:58 2016 +0000
+++ b/CDMS_PL.h	Sat Jul 30 15:25:21 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	Wed Jul 27 12:14:58 2016 +0000
+++ b/COM_MNG_TMTC.h	Sat Jul 30 15:25:21 2016 +0000
@@ -1630,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	Wed Jul 27 12:14:58 2016 +0000
+++ b/DefinitionsAndGlobals.h	Sat Jul 30 15:25:21 2016 +0000
@@ -1,7 +1,7 @@
 ///639+................................++.300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002025555.
 // **************DEFINITIONS*********************
 
-#define dma 1
+#define dma 0
 
 // COM_RX
     #define RX_TIMEOUT_LIMIT 0.5
@@ -207,8 +207,8 @@
 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
@@ -257,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;
@@ -341,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;
@@ -366,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	Wed Jul 27 12:14:58 2016 +0000
+++ b/FMS_all.h	Sat Jul 30 15:25:21 2016 +0000
@@ -81,7 +81,6 @@
 {
     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");
 }
@@ -90,7 +89,6 @@
 {
     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");
 }
@@ -122,7 +120,6 @@
 {
     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");
 }
@@ -131,7 +128,6 @@
 {
     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");
 }
@@ -146,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);
 }
 
@@ -160,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);
 }
 
@@ -209,6 +203,8 @@
     SD_SW_EN_DS = 0;
     wait_ms(10);
     SD_SW_EN_DS = 1;
+    SD_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
     gPC.printf("rst sd\n");
 }
 
@@ -217,6 +213,8 @@
     BAE_SW_EN_DS = 0;
     wait_ms(10);
     BAE_SW_EN_DS = 1;
+    BAE_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
     gPC.printf("rst bae\n");
 }
 
@@ -225,6 +223,8 @@
     PYLD_DFF = 0;
     wait_ms(10);
     PYLD_DFF = 1;
+    PL_STATUS = DEVICE_POWERED;
+    FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED);
 }
 
 void RST_BAE()
--- a/Flash.h	Wed Jul 27 12:14:58 2016 +0000
+++ b/Flash.h	Sat Jul 30 15:25:21 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	Wed Jul 27 12:14:58 2016 +0000
+++ b/RESET_functions.h	Sat Jul 30 15:25:21 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	Wed Jul 27 12:14:58 2016 +0000
+++ b/Structures.h	Sat Jul 30 15:25:21 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	Wed Jul 27 12:14:58 2016 +0000
+++ b/ThreadsAndFunctions.h	Sat Jul 30 15:25:21 2016 +0000
@@ -128,7 +128,7 @@
             if( !(gFLAGS & COM_SESSION_FLAG) ){
                 // DISABLE THREADS
                 HK_counter->stop();
-                gPAY_SPI->bulkRead_pause();
+                //gPAY_SPI->bulkRead_pause();
                 gFLAGS = gFLAGS | COM_SESSION_FLAG;
                 gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT);
                 gFLAGS = gFLAGS | COM_RX_FLAG;
@@ -221,7 +221,7 @@
                             gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY);
                             // ENABLE THREADS
                             HK_counter->start(10000);
-                            gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+                            //gPAY_SPI->bulkRead_resume(&payload_isr_fun);
                             gSESSION_TIMEOUT.detach();
                             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
                             // WARNING: clear COM_MNG_TMTC ?
@@ -280,7 +280,7 @@
                 reset_all;
                 // ENABLE THREADS
                 HK_counter->start(10000);
-                gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+                //gPAY_SPI->bulkRead_resume(&payload_isr_fun);
                 gSESSION_TIMEOUT.detach();
                 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
             }
@@ -309,7 +309,7 @@
             COM_POWER_OFF_TX;
             /*ENABLE THREADS*/
             HK_counter->start(10000);
-            gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+            //gPAY_SPI->bulkRead_resume(&payload_isr_fun);
             gSESSION_TIMEOUT.detach();
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
@@ -322,7 +322,7 @@
             reset_all;
             // ENABLE THREADS
             HK_counter->start(10000);
-            gPAY_SPI->bulkRead_resume(&payload_isr_fun);
+            //gPAY_SPI->bulkRead_resume(&payload_isr_fun);
             gSESSION_TIMEOUT.detach();
             gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
         }
--- a/cdms_rtc.h	Wed Jul 27 12:14:58 2016 +0000
+++ b/cdms_rtc.h	Sat Jul 30 15:25:21 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	Wed Jul 27 12:14:58 2016 +0000
+++ b/main.cpp	Sat Jul 30 15:25:21 2016 +0000
@@ -17,6 +17,7 @@
 #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"
@@ -25,7 +26,6 @@
 #include "CDMS_HK.h"
 #include "adf.h"
 #include "COM_RCV_TC.h"
-#include "Flash.h"
 #include "FMS_all.h"
 #include "Compression.h"
 #include "COM_MNG_TMTC.h"