publishing to check changes in cdms code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA_flag by samp Srinivasan

Revision:
235:c127b15409b2
Parent:
224:3ac1f91e0ebc
Child:
238:4abbc6a3a641
Child:
248:407ab7e337cd
diff -r bfce738e43e8 -r c127b15409b2 CDMS_HK.h
--- a/CDMS_HK.h	Tue Jul 05 16:04:31 2016 +0000
+++ b/CDMS_HK.h	Wed Jul 06 08:09:22 2016 +0000
@@ -27,7 +27,7 @@
 {
     gPC.printf("Entering HK thread");
     unsigned char CDMS_HK_FRAME[134] = {0};
-    char BAE_HK[128] = {0};
+    char BAE_HK[134] = {0};
     uint8_t convoluted_CDMS_HK[270];
     uint8_t interleave_CDMS_HK[288];
     uint8_t CDMS_HEALTH_FINAL[512] = {0};
@@ -92,38 +92,45 @@
         CDMS_HEALTH_FINAL[i] = interleave_CDMS_HK[i];
 
     SD_WRITE(CDMS_HEALTH_FINAL,FSC_CURRENT[4]+1,4);
-    gPC.printf("Completed CDMS HK\n");
+    gPC.printf("\rCompleted CDMS HK\n");
 
     /*---------------------------------- BAE HK --------------------------------------------*/
 
 
     BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
-    gPC.printf("Entering BAE thread\n");
+    gPC.printf("\rEntering BAE HK\n");
     if(BAE_HK_I2C == 0) {
-        TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7;
+        crc = crc16_gen((unsigned char *)BAE_HK,132);
+        if(crc == ((uint16_t)BAE_HK[132] << 8) | (uint16_t)BAE_HK[133]){
+            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]);
+            for(int i = 0; i<4; i++)
+            BAE_HK[i] = HK_time >> i;
+            BAE_HK_FRAME[0] = 0x28;
+            BAE_HK_FRAME[1] = FSC_CURRENT[5]+1;
+            BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8;
+            BAE_HK_FRAME[3] = (FSC_CURRENT[5]+1) >> 16;
+            for(int i = 0; i<128; i++)                       /*Adding actual CDMS Health data to TM frame*/
+                BAE_HK_FRAME[4+i] = BAE_HK[i];
+            crc = crc16_gen(BAE_HK_FRAME,132);               /*Adding CRC to TM frame*/
+            BAE_HK_FRAME[133] = crc;
+            BAE_HK_FRAME[132] = crc >> 8;
+            BAE_HEALTH.convolutionEncode(BAE_HK_FRAME , convoluted_BAE_HK);
+            BAE_HEALTH.convolutionEncode(BAE_HK_FRAME + 67, convoluted_BAE_HK + 135);
+            interleave(convoluted_BAE_HK ,  interleave_BAE_HK);
+            interleave(convoluted_BAE_HK +135, interleave_BAE_HK + 144);
+            for(int i=0; i<288; i++)
+                BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i];
+            SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5);
+        }
+        
     } else {
-        for(int i = 0; i<128; i++)
+        gPC.printf("\rBAE HK data not recieved through I2C\n");
+        for(int i = 0; i<134; i++)
             BAE_HK[i] = 0;
     }
-    for(int i = 0; i<4; i++)
-        BAE_HK[i] = HK_time >> i;
-    BAE_HK_FRAME[0] = 0x28;
-    BAE_HK_FRAME[1] = FSC_CURRENT[5]+1;
-    BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8;
-    BAE_HK_FRAME[3] = (FSC_CURRENT[5]+1) >> 16;
-    for(int i = 0; i<128; i++)                       /*Adding actual CDMS Health data to TM frame*/
-        BAE_HK_FRAME[4+i] = BAE_HK[i];
-    crc = crc16_gen(BAE_HK_FRAME,132);               /*Adding CRC to TM frame*/
-    BAE_HK_FRAME[133] = crc;
-    BAE_HK_FRAME[132] = crc >> 8;
-    BAE_HEALTH.convolutionEncode(BAE_HK_FRAME , convoluted_BAE_HK);
-    BAE_HEALTH.convolutionEncode(BAE_HK_FRAME + 67, convoluted_BAE_HK + 135);
-    interleave(convoluted_BAE_HK ,  interleave_BAE_HK);
-    interleave(convoluted_BAE_HK +135, interleave_BAE_HK + 144);
-    for(int i=0; i<288; i++)
-        BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i];
-    SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5);
-    gPC.printf("Completed BAE HK\n");
+    gPC.printf("\rCompleted BAE HK\n");
 
     /*----------------------------------Beacon message--------------------------------------*/
     unsigned char SC_HK_LBM_0[135];
@@ -135,7 +142,7 @@
     SC_HK_LBM_0[132] = crc;
     SC_HK_LBM_0[133] = crc >> 8;
     FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135);
-    gPC.printf("Completed Beacon\n");
+    gPC.printf("\rCompleted Beacon\n");
 }
 
 int quantiz(float start,float step,float x)
@@ -261,7 +268,7 @@
     GPIO_STATUS=(PL_BEE_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<5)):(GPIO_STATUS)&(~((uint16_t)(0x1<<5)));
     //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)));
-
+    
 }
 
 void VERIFY_COMRX()
@@ -342,16 +349,35 @@
 void HANDLE_HW_FAULT_PL()
 {
     if(PL_STATUS != DEVICE_DISABLED) {
-        if(PL_STATUS == DEVICE_OC_FAULT)
-            PL_SW_EN_DS = 0; //Power ON PL
-
+        if(PL_STATUS == DEVICE_OC_FAULT){
+            PYLD_DFF_CLK = 0;
+            PYLD_DFF = 1;           // Switching ON PL
+            wait_us(1);
+            PYLD_DFF_CLK = 1;
+            wait_us(1);
+            PYLD_DFF_CLK = 0;
+            wait_us(1);         
+        }
         if(PL_BEE_SW_OC_FAULT == 0) { // if OC Fault
-            PL_SW_EN_DS = 1;  // switching OFF PL
+            PYLD_DFF_CLK = 0;     
+            PYLD_DFF = 0;             //Switching OFF PL
+            wait_us(1);
+            PYLD_DFF_CLK = 1;
+            wait_us(1);
+            PYLD_DFF_CLK = 0;
+            wait_us(1);
             PL_FAULTCOUNT++;
             PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
         } else {
-            if(PL_STATUS == DEVICE_OC_FAULT)
-                PL_SW_EN_DS = 0; //Switching OFF PL
+            if(PL_STATUS == DEVICE_OC_FAULT){
+                PYLD_DFF_CLK = 0;     
+                PYLD_DFF = 0;             //Switching OFF PL
+                wait_us(1);
+                PYLD_DFF_CLK = 1;
+                wait_us(1);
+                PYLD_DFF_CLK = 0;
+                wait_us(1);
+            }
             PL_STATUS = DEVICE_ENABLED;
             PL_FAULTCOUNT = 0;
         }