Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Revision:
303:b49b486a7107
Parent:
301:701ac67649b7
Child:
305:beb148fe97dc
diff -r 701ac67649b7 -r b49b486a7107 CDMS_HK.h
--- a/CDMS_HK.h	Sun Sep 04 11:12:00 2016 +0000
+++ b/CDMS_HK.h	Mon Sep 05 11:25:33 2016 +0000
@@ -20,8 +20,14 @@
 
 DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines
 DigitalOut SelectLinec2 (PIN78);
+DigitalOut SelectLinec1 (PIN76);
+DigitalOut SelectLinec0 (PIN77); // LSB of Select Lines
+
+/*
+Before SBC. To be restored in FM model
 DigitalOut SelectLinec1 (PIN77);
 DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
+*/
 
 Convolution CDMS_HEALTH;
 Convolution BAE_HEALTH;
@@ -57,16 +63,16 @@
         FCTN_CDMS_PL_MAIN((void const *)NULL);
         hk_count = 2;
     }
-    gPC.printf("\n\nEntering HK thread\n");
+    gPC.printf("\n\rEntering HK thread\n");
 
     if(EN_CDMS_HK == 0x00)
     continue;
     CDMS_HK_MAIN_STATUS = 0x01;
     CDMS_HK_MAIN_COUNTER++;
 
-    FCTN_CDMS_HK();//collects temperatures
+    FCTN_CDMS_HK();         //collects temperatures
     RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3;//to be checked
-    gPC.printf("\n%f\n",RSSI_volatge);
+    gPC.printf("\n\rRSSI voltage  = %f",RSSI_volatge);
     VERIFY_COMRX();
     VERIFY_RTC();
     HANDLE_HW_FAULTS();
@@ -117,10 +123,12 @@
     CDMS_HK_FRAME[1] = FSC_CURRENT[4]+1;
     CDMS_HK_FRAME[2] = (FSC_CURRENT[4]+1) >> 8;
     CDMS_HK_FRAME[3] = (FSC_CURRENT[4]+1) >> 16;
-
-    for(int i = 0; i<128; i++)                       /*Adding actual CDMS Health data to TM frame*/
-        CDMS_HK_FRAME[4+i] = CDMS_HEALTH_DATA[i];
-
+    gPC.printf("\n");
+    for(int i = 0; i<128; i++){                       /*Adding actual CDMS Health data to TM frame*/
+        CDMS_HK_FRAME[i+4] = CDMS_HEALTH_DATA[i];
+        gPC.printf("%02x",CDMS_HEALTH_DATA[i]);
+    }
+    gPC.printf("\n");
     uint16_t crc = crc16_gen(CDMS_HK_FRAME,132);      /*Adding CRC to TM frame*/
     CDMS_HK_FRAME[133] = crc;
     CDMS_HK_FRAME[132] = crc >> 8;
@@ -249,7 +257,7 @@
 void minMaxHkData()
 {
     if(firstCount==true) {
-        for (int i = 0; i < 16; ++i) {
+        for (int i = 4; i < 16; ++i) {
             min_max_data.temp_min[i] = quant_data.temp_quant[i];
             min_max_data.temp_max[i] = quant_data.temp_quant[i];
         }
@@ -257,7 +265,7 @@
         min_max_data.CDMS_temp_min=quant_data.CDMS_temp_quant;
         min_max_data.CDMS_temp_max=quant_data.CDMS_temp_quant;
     } else {
-        for (int i = 0; i < 16; ++i) {
+        for (int i = 4; i < 16; ++i) {
             min_max_data.temp_min[i] = saveMin(min_max_data.temp_min[i],quant_data.temp_quant[i]);
             min_max_data.temp_max[i] = saveMax(min_max_data.temp_max[i],quant_data.temp_quant[i]);
         }
@@ -278,7 +286,7 @@
     SelectLinec1=0;
     SelectLinec2=0;
     SelectLinec3=0;
-
+    gPC.printf("\r%d %d %d %d\n",SelectLinec3.read(),SelectLinec2.read(),SelectLinec1.read(),SelectLinec0.read());
     for(Iteration=0; Iteration<16; Iteration++) {
 
         actual_data.temp_actual[Iteration]=TempInput.read();
@@ -290,35 +298,38 @@
             SelectLinec2=!(SelectLinec2);
         if(Iteration%8==7)
             SelectLinec3=!(SelectLinec3);
+        gPC.printf("\r%d %d %d %d\n",SelectLinec3.read(),SelectLinec2.read(),SelectLinec1.read(),SelectLinec0.read());
     }
 
     actual_data.CDMS_temp_actual=(-90.7*3.3*CDMS_temp_sensor.read())+190.1543;
-
+    
+    gPC.printf("\rRaw Temp = %f\n",actual_data.temp_actual[15]*3.3);
+    
     for(Iteration=0; Iteration<16; Iteration++) {
 
-        if(Iteration<14) {
-            actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3;
-            resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]);
+        if(Iteration<4)
+            actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3*2;
             
-            if(actual_data.temp_actual[Iteration]>1.47) {
+        else if(Iteration<14){
+            resistance=10000*actual_data.temp_actual[Iteration]*3.3/(3.3-actual_data.temp_actual[Iteration]*3.3);
+           
+            if(actual_data.temp_actual[Iteration]*3.3<1.47)      //Document says 1.378 .Pls Check
                 actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance);
-            } else {
-
+            else
                 actual_data.temp_actual[Iteration]=3365.4/log(7.60573*resistance);
-            }
-        } else
+        }
+        else
             actual_data.temp_actual[Iteration]=(-90.7*3.3*actual_data.temp_actual[Iteration])+190.1543;
     }
-
     for(Iteration=0; Iteration<16; Iteration++) {
 
-        if(Iteration<14) {
-
+        if(Iteration<4)
+            quant_data.temp_quant[Iteration]=actual_data.temp_actual[Iteration] * 10;
+        else if(Iteration<14)
             quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]);
-        } else
+        else
             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);
 
     minMaxHkData();
@@ -327,34 +338,34 @@
 void FUNC_CDMS_GPIO_STATUS()       //Polls the status of Input GPIO PINS
 {
     //V_A_PGOOD //TRZ EN
-    GPIO_STATUS=(V_A_PGOOD)?(GPIO_STATUS)||((uint16_t)(0x1<<15)):(GPIO_STATUS)&(~((uint16_t)(0x1<<15)));
+    GPIO_STATUS=(V_A_PGOOD)?(GPIO_STATUS)|((uint16_t)(0x1<<15)):(GPIO_STATUS)&(~((uint16_t)(0x1<<15)));
     //V_B_PGOOD_1 //3V3BPGOOD //$
-    GPIO_STATUS=(V_B_PGOOD_1)?(GPIO_STATUS)||((uint16_t)(0x1<<14)):(GPIO_STATUS)&(~((uint16_t)(0x1<<14)));
+    GPIO_STATUS=(V_B_PGOOD_1)?(GPIO_STATUS)|((uint16_t)(0x1<<14)):(GPIO_STATUS)&(~((uint16_t)(0x1<<14)));
     //V_B_PGOOD_2 //3V3BEN //$
-    GPIO_STATUS=(V_B_PGOOD_2)?(GPIO_STATUS)||((uint16_t)(0x1<<13)):(GPIO_STATUS)&(~((uint16_t)(0x1<<13)));
+    GPIO_STATUS=(V_B_PGOOD_2)?(GPIO_STATUS)|((uint16_t)(0x1<<13)):(GPIO_STATUS)&(~((uint16_t)(0x1<<13)));
     //V_C_PGOOD //3V3CPGOOD //$
-    GPIO_STATUS=(V_C_PGOOD)?(GPIO_STATUS)||((uint16_t)(0x1<<12)):(GPIO_STATUS)&(~((uint16_t)(0x1<<12)));
+    GPIO_STATUS=(V_C_PGOOD)?(GPIO_STATUS)|((uint16_t)(0x1<<12)):(GPIO_STATUS)&(~((uint16_t)(0x1<<12)));
     //COMRX_OC_FAULT //$
-    GPIO_STATUS=(COMRX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<11)):(GPIO_STATUS)&(~((uint16_t)(0x1<<11)));
+    GPIO_STATUS=(COMRX_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<11)):(GPIO_STATUS)&(~((uint16_t)(0x1<<11)));
     // COMTX_OC_FAULT //$
-    GPIO_STATUS=(COM_TX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
+    GPIO_STATUS=(COM_TX_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
     //BAE_OC_FAULT //$
-    GPIO_STATUS=(BAE_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<9)):(GPIO_STATUS)&(~((uint16_t)(0x1<<9)));
+    GPIO_STATUS=(BAE_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<9)):(GPIO_STATUS)&(~((uint16_t)(0x1<<9)));
     //PL_GPIO_1_STATUS //$
-    GPIO_STATUS=(PL_GPIO_1_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<8)):(GPIO_STATUS)&(~((uint16_t)(0x1<<8)));
+    GPIO_STATUS=(PL_GPIO_1_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<8)):(GPIO_STATUS)&(~((uint16_t)(0x1<<8)));
     //PL_GPIO_2_STATUS //$
-    GPIO_STATUS=(PL_GPIO_2_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<7)):(GPIO_STATUS)&(~((uint16_t)(0x1<<7)));
+    GPIO_STATUS=(PL_GPIO_2_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<7)):(GPIO_STATUS)&(~((uint16_t)(0x1<<7)));
     //PL_GPIO_3_STATUS //$
-    GPIO_STATUS=(PL_GPIO_3_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<6)):(GPIO_STATUS)&(~((uint16_t)(0x1<<6)));
+    GPIO_STATUS=(PL_GPIO_3_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<6)):(GPIO_STATUS)&(~((uint16_t)(0x1<<6)));
     //PL_BEE_SW_OC_FAULT //to be verified
-    GPIO_STATUS=(PL_BEE_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<5)):(GPIO_STATUS)&(~((uint16_t)(0x1<<5)));
+    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)));
+    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=(COM_RX_CNTRL)?(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=(COM_TX_CNTRL)?(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)));
+    gPC.printf("%04x\n",GPIO_STATUS);
 }
 
 void VERIFY_COMRX()
@@ -500,7 +511,10 @@
 
 void COLLECT_CDMS_RAM()
 {
-    CDMS_RAM[0] = ((PL_INIT_STATUS<<7)&0x80)|((PL_MAIN_status<<6)&0x40)|((PL_LOW_POWER<<5)&0x20)|((PL_STATE<<3)&0x18)|(PL_STATUS&0x07);
+    CDMS_RAM[0] = ((PL_INIT_STATUS<<7)&0x80)|((PL_MAIN_status<<6)&0x40)|((PL_LOW_power<<5)&0x20)|((PL_STATE<<3)&0x18)|(PL_STATUS&0x07);
+    gPC.printf("\n\rPL_STATUS : %d",PL_STATUS);
+    gPC.printf("\n\rPL_STATE : %d",PL_STATE);
+    gPC.printf("\n\rpl bits = %02x\n",CDMS_RAM[0]);
     CDMS_RAM[1] = ((PL_RCV_SC_DATA_STATUS<<7)&0x80)|((COM_SESSION<<6)&0x40)|((COM_RX<<5)&0x20)|((RF_SW_STATUS<<4)&0x10)|((COM_TX<<3)&0x08)|((COM_TX_STATUS<<2)&0x04)|((COM_MNG_TMTC<<1)&0x02)|(EN_CDMS_HK&0x01);
     CDMS_RAM[2] = ((EN_PL<<7)&0x80)|((EN_RCV_SC<<6)&0x40)|((CDMS_INIT_STATUS<<5)&0x20)|((CDMS_HK_MAIN_STATUS<<4)&0x10)|((CDMS_HK_STATUS<<2)&0x0C)|((COM_RX_STATUS<<1)&0x02)|(CDMS_RTC_BL&0x01);
     CDMS_RAM[3] = CDMS_I2C_ERR_SPEED_COUNTER >> 8;
@@ -520,37 +534,36 @@
     CDMS_RAM[17] = SD_LIB_WRITES >> 8;
     CDMS_RAM[18] = SD_LIB_WRITES;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[19+i] = TIME_LATEST_RTC >> ((3-i)*8);
+        CDMS_RAM[19+i] = TIME_LATEST_RTC >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[23+i] = TIME_LATEST_I2C_BAE >> ((3-i)*8);
+        CDMS_RAM[23+i] = TIME_LATEST_I2C_BAE >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[27+i] = TIME_LATEST_I2C_SPEED >> ((3-i)*8);
+        CDMS_RAM[27+i] = TIME_LATEST_I2C_SPEED >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[31+i] = TIME_LATEST_SD_WR >> ((3-i)*8);
+        CDMS_RAM[31+i] = TIME_LATEST_SD_WR >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[35+i] = TIME_LATEST_SD_RD >> ((3-i)*8);
+        CDMS_RAM[35+i] = TIME_LATEST_SD_RD >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[39+i] = TIME_LATEST_SPI_SPEED >> ((3-i)*8);
+        CDMS_RAM[39+i] = TIME_LATEST_SPI_SPEED >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[43+i] = FSC_CURRENT[1] >> ((3-i)*8);
+        CDMS_RAM[43+i] = FSC_CURRENT[1] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[47+i] = FSC_LAST[1] >> ((3-i)*8);
+        CDMS_RAM[47+i] = FSC_LAST[1] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[51+i] = FSC_CURRENT[2] >> ((3-i)*8);
+        CDMS_RAM[51+i] = FSC_CURRENT[2] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[55+i] = FSC_LAST[2] >> ((3-i)*8);
+        CDMS_RAM[55+i] = FSC_LAST[2] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[59+i] = FSC_CURRENT[3] >> ((3-i)*8);
+        CDMS_RAM[59+i] = FSC_CURRENT[3] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[63+i] = FSC_LAST[3] >> ((3-i)*8);
+        CDMS_RAM[63+i] = FSC_LAST[3] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[67+i] = FSC_CURRENT[4] >> ((3-i)*8);
+        CDMS_RAM[67+i] = FSC_CURRENT[4] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[71+i] = FSC_LAST[4] >> ((3-i)*8);
+        CDMS_RAM[71+i] = FSC_LAST[4] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[75+i] = FSC_CURRENT[5] >> ((3-i)*8);
+        CDMS_RAM[75+i] = FSC_CURRENT[5] >> (3-i)*8;
     for(int i = 0; i<4; i++)
-        CDMS_RAM[79+i] = FSC_LAST[5] >> ((3-i)*8);
+        CDMS_RAM[79+i] = FSC_LAST[5] >> (3-i)*8;
     CDMS_RAM[83] = 0x00;
-    gPC.printf("%d %d %d %d %d\n",FSC_CURRENT[1],FSC_CURRENT[2],FSC_CURRENT[3],FSC_CURRENT[4],FSC_CURRENT[5]);
 }
\ No newline at end of file