Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
chaithanyarss
Date:
Mon Jul 04 07:53:00 2016 +0000
Revision:
221:2efc13ccbe4c
Parent:
105:5ce0337e7c15
Added HK. still working;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaithanyarss 221:2efc13ccbe4c 1
shreeshas95 103:b55559925dc1 2
shreeshas95 103:b55559925dc1 3 void FCTN_CDMS_HK_MAIN();
shreeshas95 103:b55559925dc1 4 void FCTN_CDMS_HK();
chaithanyarss 221:2efc13ccbe4c 5 void VERIFY_COMRX();
chaithanyarss 221:2efc13ccbe4c 6 void VERIFY_RTC();
chaithanyarss 221:2efc13ccbe4c 7 void CDMS_HK_SD();
chaithanyarss 221:2efc13ccbe4c 8 void HANDLE_HW_FAULTS();
chaithanyarss 221:2efc13ccbe4c 9 void HANDLE_HW_FAULT_SD();
chaithanyarss 221:2efc13ccbe4c 10 void HANDLE_HW_FAULT_BAE();
chaithanyarss 221:2efc13ccbe4c 11 void HANDLE_HW_FAULT_PL();
chaithanyarss 221:2efc13ccbe4c 12 void FUNC_CDMS_GPIO_STATUS();
chaithanyarss 221:2efc13ccbe4c 13 void minMaxHkData();
chaithanyarss 221:2efc13ccbe4c 14 void COLLECT_CDMS_RAM();
shreeshas95 103:b55559925dc1 15
shreeshas95 103:b55559925dc1 16 Serial hk_cdms(USBTX, USBRX);
shreeshas95 103:b55559925dc1 17
chaithanyarss 221:2efc13ccbe4c 18 AnalogIn TempInput(PIN27); // Input from Current Multiplexer
shreeshas95 103:b55559925dc1 19 AnalogIn CDMS_temp_sensor(PIN53);
chaithanyarss 221:2efc13ccbe4c 20 AnalogIn COMRX_RSSI_volatge(PIN70);
chaithanyarss 221:2efc13ccbe4c 21
shreeshas95 103:b55559925dc1 22
shreeshas95 103:b55559925dc1 23 DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines
shreeshas95 103:b55559925dc1 24 DigitalOut SelectLinec2 (PIN78);
shreeshas95 103:b55559925dc1 25 DigitalOut SelectLinec1 (PIN77);
shreeshas95 103:b55559925dc1 26 DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
shreeshas95 103:b55559925dc1 27
shreeshas95 104:a50ae79ca36e 28 void FCTN_CDMS_HK_MAIN(void const *args)
shreeshas95 103:b55559925dc1 29 {
chaithanyarss 221:2efc13ccbe4c 30
chaithanyarss 221:2efc13ccbe4c 31 unsigned char CDMS_HK_FRAME[134] = {0};
chaithanyarss 221:2efc13ccbe4c 32 char BAE_HK[128] = {0};
chaithanyarss 221:2efc13ccbe4c 33 uint8_t convoluted_CDMS_HK[270];
chaithanyarss 221:2efc13ccbe4c 34 uint8_t interleave_CDMS_HK[288];
chaithanyarss 221:2efc13ccbe4c 35 uint8_t CDMS_HEALTH_FINAL[512] = {0};
chaithanyarss 221:2efc13ccbe4c 36 uint8_t convoluted_BAE_HK[270];
chaithanyarss 221:2efc13ccbe4c 37 uint8_t interleave_BAE_HK[288];
chaithanyarss 221:2efc13ccbe4c 38 uint8_t BAE_HEALTH_FINAL[512] = {0};
chaithanyarss 221:2efc13ccbe4c 39 unsigned char BAE_HK_FRAME[134] = {0};
chaithanyarss 221:2efc13ccbe4c 40
chaithanyarss 221:2efc13ccbe4c 41 CDMS_HK_MAIN_STATUS = 0x01;
chaithanyarss 221:2efc13ccbe4c 42 CDMS_HK_MAIN_COUNTER++;
chaithanyarss 221:2efc13ccbe4c 43
chaithanyarss 221:2efc13ccbe4c 44 FCTN_CDMS_HK();
chaithanyarss 221:2efc13ccbe4c 45 RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3;
chaithanyarss 221:2efc13ccbe4c 46 VERIFY_COMRX();
chaithanyarss 221:2efc13ccbe4c 47 VERIFY_RTC();
chaithanyarss 221:2efc13ccbe4c 48 HANDLE_HW_FAULTS();
chaithanyarss 221:2efc13ccbe4c 49 FUNC_CDMS_GPIO_STATUS(); //yet to be done
chaithanyarss 221:2efc13ccbe4c 50
chaithanyarss 221:2efc13ccbe4c 51 uint8_t CDMS_quant[19];
chaithanyarss 221:2efc13ccbe4c 52 for(int i=0; i<16; i++) {
chaithanyarss 221:2efc13ccbe4c 53 CDMS_quant[i]= (uint8_t)quant_data.temp_quant[i];
chaithanyarss 221:2efc13ccbe4c 54 }
chaithanyarss 221:2efc13ccbe4c 55 CDMS_quant[16]= (uint8_t)RSSI_volatge;
chaithanyarss 221:2efc13ccbe4c 56 CDMS_quant[17]= (uint8_t)quant_data.CDMS_temp_quant;
chaithanyarss 221:2efc13ccbe4c 57 minMaxHkData();
chaithanyarss 221:2efc13ccbe4c 58
chaithanyarss 221:2efc13ccbe4c 59 uint64_t time = FCTN_CDMS_RD_RTC(); //Reading Time from RTC
chaithanyarss 221:2efc13ccbe4c 60 time = time>>7;
chaithanyarss 221:2efc13ccbe4c 61 uint32_t HK_time = (uint32_t)time;
chaithanyarss 221:2efc13ccbe4c 62 for(int i = 0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 63 CDMS_HEALTH_DATA[i] = HK_time >> i;
chaithanyarss 221:2efc13ccbe4c 64
chaithanyarss 221:2efc13ccbe4c 65 // Here: Have to FIT flash data.
chaithanyarss 221:2efc13ccbe4c 66 for(int i = 0; i<19; i++) //Collecting Data from Temp sensors
chaithanyarss 221:2efc13ccbe4c 67 CDMS_HEALTH_DATA[i+24] = CDMS_quant[i];
chaithanyarss 221:2efc13ccbe4c 68
chaithanyarss 221:2efc13ccbe4c 69 COLLECT_CDMS_RAM(); //Reading RAM parameters
chaithanyarss 221:2efc13ccbe4c 70
chaithanyarss 221:2efc13ccbe4c 71 CDMS_HEALTH_DATA[126] = GPIO_STATUS; //Reading GPIO Pins
chaithanyarss 221:2efc13ccbe4c 72 CDMS_HEALTH_DATA[127] = GPIO_STATUS >> 8;
chaithanyarss 221:2efc13ccbe4c 73
chaithanyarss 221:2efc13ccbe4c 74 FCTN_SD_MNGR(); //Adding FSC & TMID to TM frame
chaithanyarss 221:2efc13ccbe4c 75 CDMS_HK_FRAME[0] = 0x20;
chaithanyarss 221:2efc13ccbe4c 76 CDMS_HK_FRAME[1] = FSC_CURRENT[4]+1;
chaithanyarss 221:2efc13ccbe4c 77 CDMS_HK_FRAME[2] = (FSC_CURRENT[4]+1) >> 8;
chaithanyarss 221:2efc13ccbe4c 78 CDMS_HK_FRAME[3] = (FSC_CURRENT[4]+1) >> 16;
chaithanyarss 221:2efc13ccbe4c 79
chaithanyarss 221:2efc13ccbe4c 80 for(int i = 0; i<128; i++) /*Adding actual CDMS Health data to TM frame*/
chaithanyarss 221:2efc13ccbe4c 81 CDMS_HK_FRAME[4+i] = CDMS_HEALTH_DATA[i];
chaithanyarss 221:2efc13ccbe4c 82
chaithanyarss 221:2efc13ccbe4c 83 uint16_t crc = crc16_gen(CDMS_HK_FRAME,132); /*Adding CRC to TM frame*/
chaithanyarss 221:2efc13ccbe4c 84 CDMS_HK_FRAME[133] = crc;
chaithanyarss 221:2efc13ccbe4c 85 CDMS_HK_FRAME[132] = crc >> 8;
chaithanyarss 221:2efc13ccbe4c 86
chaithanyarss 221:2efc13ccbe4c 87 Convolution CDMS_HEALTH;
chaithanyarss 221:2efc13ccbe4c 88 Convolution BAE_HEALTH;
chaithanyarss 221:2efc13ccbe4c 89 CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME , convoluted_CDMS_HK);
chaithanyarss 221:2efc13ccbe4c 90 CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME + 67, convoluted_CDMS_HK + 135);
chaithanyarss 221:2efc13ccbe4c 91 interleave(convoluted_CDMS_HK , interleave_CDMS_HK);
chaithanyarss 221:2efc13ccbe4c 92 interleave(convoluted_CDMS_HK +135, interleave_CDMS_HK + 144);
chaithanyarss 221:2efc13ccbe4c 93 for(int i=0; i<288; i++)
chaithanyarss 221:2efc13ccbe4c 94 CDMS_HEALTH_FINAL[i] = interleave_CDMS_HK[i];
chaithanyarss 221:2efc13ccbe4c 95
chaithanyarss 221:2efc13ccbe4c 96 SD_WRITE(CDMS_HEALTH_FINAL,FSC_CURRENT[4]+1,4);
chaithanyarss 221:2efc13ccbe4c 97 hk_cdms.printf("CDMS hk succesfully completed\r\n");
shreeshas95 103:b55559925dc1 98
shreeshas95 103:b55559925dc1 99
chaithanyarss 221:2efc13ccbe4c 100 /*---------------------------------- BAE HK --------------------------------------------*/
chaithanyarss 221:2efc13ccbe4c 101
chaithanyarss 221:2efc13ccbe4c 102
chaithanyarss 221:2efc13ccbe4c 103 BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
chaithanyarss 221:2efc13ccbe4c 104 if(BAE_HK_I2C == 0) {
chaithanyarss 221:2efc13ccbe4c 105 TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7;
chaithanyarss 221:2efc13ccbe4c 106 hk_cdms.printf("Bae hk data received");
chaithanyarss 221:2efc13ccbe4c 107 } else {
chaithanyarss 221:2efc13ccbe4c 108 for(int i = 0; i<128; i++)
chaithanyarss 221:2efc13ccbe4c 109 BAE_HK[i] = 0;
chaithanyarss 221:2efc13ccbe4c 110 }
chaithanyarss 221:2efc13ccbe4c 111 for(int i = 0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 112 BAE_HK[i] = HK_time >> i;
chaithanyarss 221:2efc13ccbe4c 113 BAE_HK_FRAME[0] = 0x28;
chaithanyarss 221:2efc13ccbe4c 114 BAE_HK_FRAME[1] = FSC_CURRENT[5]+1;
chaithanyarss 221:2efc13ccbe4c 115 BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8;
chaithanyarss 221:2efc13ccbe4c 116 BAE_HK_FRAME[3] = (FSC_CURRENT[5]+1) >> 16;
chaithanyarss 221:2efc13ccbe4c 117 for(int i = 0; i<128; i++) /*Adding actual CDMS Health data to TM frame*/
chaithanyarss 221:2efc13ccbe4c 118 BAE_HK_FRAME[4+i] = BAE_HK[i];
chaithanyarss 221:2efc13ccbe4c 119 crc = crc16_gen(BAE_HK_FRAME,132); /*Adding CRC to TM frame*/
chaithanyarss 221:2efc13ccbe4c 120 BAE_HK_FRAME[133] = crc;
chaithanyarss 221:2efc13ccbe4c 121 BAE_HK_FRAME[132] = crc >> 8;
chaithanyarss 221:2efc13ccbe4c 122 BAE_HEALTH.convolutionEncode(BAE_HK_FRAME , convoluted_BAE_HK);
chaithanyarss 221:2efc13ccbe4c 123 BAE_HEALTH.convolutionEncode(BAE_HK_FRAME + 67, convoluted_BAE_HK + 135);
chaithanyarss 221:2efc13ccbe4c 124 interleave(convoluted_BAE_HK , interleave_BAE_HK);
chaithanyarss 221:2efc13ccbe4c 125 interleave(convoluted_BAE_HK +135, interleave_BAE_HK + 144);
chaithanyarss 221:2efc13ccbe4c 126 for(int i=0; i<288; i++)
chaithanyarss 221:2efc13ccbe4c 127 BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i];
chaithanyarss 221:2efc13ccbe4c 128 SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5);
chaithanyarss 221:2efc13ccbe4c 129 hk_cdms.printf("BAE hk succesfully completed\r\n");
chaithanyarss 221:2efc13ccbe4c 130
chaithanyarss 221:2efc13ccbe4c 131 /*----------------------------------Beacon message--------------------------------------*/
chaithanyarss 221:2efc13ccbe4c 132 unsigned char SC_HK_LBM_0[135];
chaithanyarss 221:2efc13ccbe4c 133 SC_HK_LBM_0[0] = 0; // Sending long beacon msg as telecommand with Packet sequence count 0x00
chaithanyarss 221:2efc13ccbe4c 134 // Add HK bits
chaithanyarss 221:2efc13ccbe4c 135
chaithanyarss 221:2efc13ccbe4c 136 // Add SC bits
chaithanyarss 221:2efc13ccbe4c 137 crc = crc16_gen(SC_HK_LBM_0,133);
chaithanyarss 221:2efc13ccbe4c 138 SC_HK_LBM_0[132] = crc;
chaithanyarss 221:2efc13ccbe4c 139 SC_HK_LBM_0[133] = crc >> 8;
chaithanyarss 221:2efc13ccbe4c 140 FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135);
chaithanyarss 221:2efc13ccbe4c 141 }
shreeshas95 103:b55559925dc1 142
shreeshas95 103:b55559925dc1 143 int quantiz(float start,float step,float x)
shreeshas95 103:b55559925dc1 144 {
shreeshas95 103:b55559925dc1 145 int y=(x-start)/step;
shreeshas95 103:b55559925dc1 146 if(y<=0)y=0;
shreeshas95 103:b55559925dc1 147 if(y>=255)y=255;
shreeshas95 103:b55559925dc1 148 return y;
shreeshas95 103:b55559925dc1 149 }
shreeshas95 103:b55559925dc1 150
chaithanyarss 221:2efc13ccbe4c 151 char saveMin(char x,char y)
chaithanyarss 221:2efc13ccbe4c 152 {
chaithanyarss 221:2efc13ccbe4c 153 return (y<x)?y:x;
shreeshas95 103:b55559925dc1 154 }
chaithanyarss 221:2efc13ccbe4c 155
chaithanyarss 221:2efc13ccbe4c 156 char saveMax(char x,char y)
chaithanyarss 221:2efc13ccbe4c 157 {
chaithanyarss 221:2efc13ccbe4c 158 return (y>x)?y:x;
shreeshas95 103:b55559925dc1 159 }
chaithanyarss 221:2efc13ccbe4c 160
chaithanyarss 221:2efc13ccbe4c 161 void minMaxHkData()
chaithanyarss 221:2efc13ccbe4c 162 {
chaithanyarss 221:2efc13ccbe4c 163 if(firstCount==true) {
chaithanyarss 221:2efc13ccbe4c 164 for (int i = 0; i < 16; ++i) {
chaithanyarss 221:2efc13ccbe4c 165 min_max_data.temp_min[i] = quant_data.temp_quant[i];
chaithanyarss 221:2efc13ccbe4c 166 min_max_data.temp_max[i] = quant_data.temp_quant[i];
shreeshas95 103:b55559925dc1 167 }
shreeshas95 103:b55559925dc1 168
shreeshas95 103:b55559925dc1 169 min_max_data.CDMS_temp_min=quant_data.CDMS_temp_quant;
shreeshas95 103:b55559925dc1 170 min_max_data.CDMS_temp_max=quant_data.CDMS_temp_quant;
chaithanyarss 221:2efc13ccbe4c 171 } else {
chaithanyarss 221:2efc13ccbe4c 172 for (int i = 0; i < 16; ++i) {
chaithanyarss 221:2efc13ccbe4c 173 min_max_data.temp_min[i] = saveMin(min_max_data.temp_min[i],quant_data.temp_quant[i]);
chaithanyarss 221:2efc13ccbe4c 174 min_max_data.temp_max[i] = saveMax(min_max_data.temp_max[i],quant_data.temp_quant[i]);
chaithanyarss 221:2efc13ccbe4c 175 }
chaithanyarss 221:2efc13ccbe4c 176
chaithanyarss 221:2efc13ccbe4c 177 min_max_data.CDMS_temp_min = saveMin(min_max_data.CDMS_temp_min,quant_data.CDMS_temp_quant);
chaithanyarss 221:2efc13ccbe4c 178 min_max_data.CDMS_temp_max = saveMax(min_max_data.CDMS_temp_max,quant_data.CDMS_temp_quant);
shreeshas95 103:b55559925dc1 179 }
shreeshas95 103:b55559925dc1 180 firstCount=false;
shreeshas95 103:b55559925dc1 181 }
shreeshas95 103:b55559925dc1 182
shreeshas95 103:b55559925dc1 183 void FCTN_CDMS_HK()
shreeshas95 103:b55559925dc1 184 {
chaithanyarss 221:2efc13ccbe4c 185
shreeshas95 103:b55559925dc1 186 int Iteration=0;
shreeshas95 103:b55559925dc1 187
shreeshas95 103:b55559925dc1 188 SelectLinec0=0;
shreeshas95 103:b55559925dc1 189 SelectLinec1=0;
shreeshas95 103:b55559925dc1 190 SelectLinec2=0;
shreeshas95 103:b55559925dc1 191 SelectLinec3=0;
shreeshas95 103:b55559925dc1 192
chaithanyarss 221:2efc13ccbe4c 193 for(Iteration=0; Iteration<16; Iteration++) {
shreeshas95 103:b55559925dc1 194
shreeshas95 103:b55559925dc1 195 actual_data.temp_actual[Iteration]=TempInput.read();
shreeshas95 103:b55559925dc1 196
shreeshas95 103:b55559925dc1 197 SelectLinec0=!(SelectLinec0);
shreeshas95 103:b55559925dc1 198 if(Iteration%2==1)
shreeshas95 103:b55559925dc1 199 SelectLinec1=!(SelectLinec1);
shreeshas95 103:b55559925dc1 200 if(Iteration%4==3)
shreeshas95 103:b55559925dc1 201 SelectLinec2=!(SelectLinec2);
shreeshas95 103:b55559925dc1 202 if(Iteration%8==7)
chaithanyarss 221:2efc13ccbe4c 203 SelectLinec3=!(SelectLinec3);
shreeshas95 103:b55559925dc1 204 }
shreeshas95 103:b55559925dc1 205
chaithanyarss 221:2efc13ccbe4c 206 actual_data.CDMS_temp_actual=(-90.7*3.3*CDMS_temp_sensor.read())+190.1543;
shreeshas95 103:b55559925dc1 207
chaithanyarss 221:2efc13ccbe4c 208 for(Iteration=0; Iteration<16; Iteration++) {
chaithanyarss 221:2efc13ccbe4c 209
chaithanyarss 221:2efc13ccbe4c 210 if(Iteration<14) {
shreeshas95 103:b55559925dc1 211
shreeshas95 103:b55559925dc1 212 actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3;
chaithanyarss 221:2efc13ccbe4c 213 int resistance;
chaithanyarss 221:2efc13ccbe4c 214
shreeshas95 103:b55559925dc1 215 resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]);
chaithanyarss 221:2efc13ccbe4c 216 if(actual_data.temp_actual[Iteration]>1.47) {
shreeshas95 103:b55559925dc1 217 actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance);
chaithanyarss 221:2efc13ccbe4c 218 } else {
chaithanyarss 221:2efc13ccbe4c 219
shreeshas95 103:b55559925dc1 220 actual_data.temp_actual[Iteration]=3365.4/log(7.60573*resistance);
shreeshas95 103:b55559925dc1 221 }
chaithanyarss 221:2efc13ccbe4c 222 } else
shreeshas95 103:b55559925dc1 223 actual_data.temp_actual[Iteration]=(-90.7*3.3*actual_data.temp_actual[Iteration])+190.1543;
shreeshas95 103:b55559925dc1 224 }
shreeshas95 103:b55559925dc1 225
chaithanyarss 221:2efc13ccbe4c 226 for(Iteration=0; Iteration<16; Iteration++) {
shreeshas95 103:b55559925dc1 227
chaithanyarss 221:2efc13ccbe4c 228 if(Iteration<14) {
shreeshas95 103:b55559925dc1 229
shreeshas95 103:b55559925dc1 230 quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]);
chaithanyarss 221:2efc13ccbe4c 231 } else
shreeshas95 103:b55559925dc1 232 quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
shreeshas95 103:b55559925dc1 233 }
shreeshas95 103:b55559925dc1 234
shreeshas95 103:b55559925dc1 235 quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual);
shreeshas95 103:b55559925dc1 236
shreeshas95 103:b55559925dc1 237 minMaxHkData();
chaithanyarss 221:2efc13ccbe4c 238 }
chaithanyarss 221:2efc13ccbe4c 239
chaithanyarss 221:2efc13ccbe4c 240 void FUNC_CDMS_GPIO_STATUS() //Polls the status of Input GPIO PINS
chaithanyarss 221:2efc13ccbe4c 241 {
chaithanyarss 221:2efc13ccbe4c 242 //V_A_PGOOD //TRZ EN
chaithanyarss 221:2efc13ccbe4c 243 GPIO_STATUS=(V_A_PGOOD)?(GPIO_STATUS)||((uint16_t)(0x1<<15)):(GPIO_STATUS)&(~((uint16_t)(0x1<<15)));
chaithanyarss 221:2efc13ccbe4c 244 //V_B_PGOOD_1 //3V3BPGOOD //$
chaithanyarss 221:2efc13ccbe4c 245 GPIO_STATUS=(V_B_PGOOD_1)?(GPIO_STATUS)||((uint16_t)(0x1<<14)):(GPIO_STATUS)&(~((uint16_t)(0x1<<14)));
chaithanyarss 221:2efc13ccbe4c 246 //V_B_PGOOD_2 //3V3BEN //$
chaithanyarss 221:2efc13ccbe4c 247 GPIO_STATUS=(V_B_PGOOD_2)?(GPIO_STATUS)||((uint16_t)(0x1<<13)):(GPIO_STATUS)&(~((uint16_t)(0x1<<13)));
chaithanyarss 221:2efc13ccbe4c 248 //V_C_PGOOD //3V3CPGOOD //$
chaithanyarss 221:2efc13ccbe4c 249 GPIO_STATUS=(V_C_PGOOD)?(GPIO_STATUS)||((uint16_t)(0x1<<12)):(GPIO_STATUS)&(~((uint16_t)(0x1<<12)));
chaithanyarss 221:2efc13ccbe4c 250 //COMRX_OC_FAULT //$
chaithanyarss 221:2efc13ccbe4c 251 GPIO_STATUS=(COMRX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<11)):(GPIO_STATUS)&(~((uint16_t)(0x1<<11)));
chaithanyarss 221:2efc13ccbe4c 252 // COMTX_OC_FAULT //$
chaithanyarss 221:2efc13ccbe4c 253 GPIO_STATUS=(COMTX_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
chaithanyarss 221:2efc13ccbe4c 254 //BAE_OC_FAULT //$
chaithanyarss 221:2efc13ccbe4c 255 GPIO_STATUS=(BAE_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<9)):(GPIO_STATUS)&(~((uint16_t)(0x1<<9)));
chaithanyarss 221:2efc13ccbe4c 256 //PL_GPIO_1_STATUS //$
chaithanyarss 221:2efc13ccbe4c 257 GPIO_STATUS=(PL_GPIO_1_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<8)):(GPIO_STATUS)&(~((uint16_t)(0x1<<8)));
chaithanyarss 221:2efc13ccbe4c 258 //PL_GPIO_2_STATUS //$
chaithanyarss 221:2efc13ccbe4c 259 GPIO_STATUS=(PL_GPIO_2_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<7)):(GPIO_STATUS)&(~((uint16_t)(0x1<<7)));
chaithanyarss 221:2efc13ccbe4c 260 //PL_GPIO_3_STATUS //$
chaithanyarss 221:2efc13ccbe4c 261 GPIO_STATUS=(PL_GPIO_3_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<6)):(GPIO_STATUS)&(~((uint16_t)(0x1<<6)));
chaithanyarss 221:2efc13ccbe4c 262 //PL_BEE_SW_OC_FAULT //to be verified
chaithanyarss 221:2efc13ccbe4c 263 GPIO_STATUS=(PL_BEE_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<5)):(GPIO_STATUS)&(~((uint16_t)(0x1<<5)));
chaithanyarss 221:2efc13ccbe4c 264 //PL_EPS_LATCH_SW_OC_FAULT // to be verified
chaithanyarss 221:2efc13ccbe4c 265 GPIO_STATUS=(PL_EPS_LATCH_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<4)):(GPIO_STATUS)&(~((uint16_t)(0x1<<4)));
chaithanyarss 221:2efc13ccbe4c 266
chaithanyarss 221:2efc13ccbe4c 267 }
chaithanyarss 221:2efc13ccbe4c 268
chaithanyarss 221:2efc13ccbe4c 269 void VERIFY_COMRX()
chaithanyarss 221:2efc13ccbe4c 270 {
chaithanyarss 221:2efc13ccbe4c 271 //COMRX_OC_FAULT //$
chaithanyarss 221:2efc13ccbe4c 272 if(PIN68==0 && RSSI_volatge > 0.4) {
chaithanyarss 221:2efc13ccbe4c 273 COMRX_STATUS = COMRX_ALIVE;
chaithanyarss 221:2efc13ccbe4c 274 } else {
chaithanyarss 221:2efc13ccbe4c 275 RESET_COMRX();
chaithanyarss 221:2efc13ccbe4c 276 COMRX_RESET_COUNTER++;
chaithanyarss 221:2efc13ccbe4c 277 if(PIN68==0 && RSSI_volatge > 0.4)
chaithanyarss 221:2efc13ccbe4c 278 COMRX_STATUS = COMRX_ALIVE;
chaithanyarss 221:2efc13ccbe4c 279 else
chaithanyarss 221:2efc13ccbe4c 280 COMRX_STATUS = COMRX_DEAD;
chaithanyarss 221:2efc13ccbe4c 281 }
chaithanyarss 221:2efc13ccbe4c 282 }
chaithanyarss 221:2efc13ccbe4c 283
chaithanyarss 221:2efc13ccbe4c 284 void VERIFY_RTC()
chaithanyarss 221:2efc13ccbe4c 285 {
chaithanyarss 221:2efc13ccbe4c 286
chaithanyarss 221:2efc13ccbe4c 287 if(RTC_STATUS == 0x00) {
chaithanyarss 221:2efc13ccbe4c 288 SPI_mutex.lock();
chaithanyarss 221:2efc13ccbe4c 289 gCS_RTC=1;
chaithanyarss 221:2efc13ccbe4c 290 gCS_RTC=0;
chaithanyarss 221:2efc13ccbe4c 291 spi.write(0x0F);
chaithanyarss 221:2efc13ccbe4c 292 if(spi.write(0x00) & 0x04 == 0x04) {
chaithanyarss 221:2efc13ccbe4c 293 RTC_STATUS = 0x00;
chaithanyarss 221:2efc13ccbe4c 294 RESET_RTC();
chaithanyarss 221:2efc13ccbe4c 295 RTC_FAULTCOUNT++;
chaithanyarss 221:2efc13ccbe4c 296 }
chaithanyarss 221:2efc13ccbe4c 297 gCS_RTC=1;
chaithanyarss 221:2efc13ccbe4c 298 SPI_mutex.unlock();
chaithanyarss 221:2efc13ccbe4c 299 }
chaithanyarss 221:2efc13ccbe4c 300 }
chaithanyarss 221:2efc13ccbe4c 301
chaithanyarss 221:2efc13ccbe4c 302 void HANDLE_HW_FAULTS()
chaithanyarss 221:2efc13ccbe4c 303 {
chaithanyarss 221:2efc13ccbe4c 304 HANDLE_HW_FAULT_SD();
chaithanyarss 221:2efc13ccbe4c 305 HANDLE_HW_FAULT_BAE();
chaithanyarss 221:2efc13ccbe4c 306 HANDLE_HW_FAULT_PL();
chaithanyarss 221:2efc13ccbe4c 307 }
chaithanyarss 221:2efc13ccbe4c 308
chaithanyarss 221:2efc13ccbe4c 309 void HANDLE_HW_FAULT_SD()
chaithanyarss 221:2efc13ccbe4c 310 {
chaithanyarss 221:2efc13ccbe4c 311 if(SD_STATUS != DEVICE_DISABLED) {
chaithanyarss 221:2efc13ccbe4c 312 if(SD_STATUS == DEVICE_OC_FAULT)
chaithanyarss 221:2efc13ccbe4c 313 SD_SW_EN_DS = 0; //powering on SD
chaithanyarss 221:2efc13ccbe4c 314
chaithanyarss 221:2efc13ccbe4c 315 if(SD_OC_FAULT == 0) {
chaithanyarss 221:2efc13ccbe4c 316 SD_SW_EN_DS = 1; //switching off SD card
chaithanyarss 221:2efc13ccbe4c 317
chaithanyarss 221:2efc13ccbe4c 318 SD_FAULTCOUNT++;
chaithanyarss 221:2efc13ccbe4c 319 SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT;
chaithanyarss 221:2efc13ccbe4c 320 } else {
chaithanyarss 221:2efc13ccbe4c 321 SD_STATUS = DEVICE_POWERED;
chaithanyarss 221:2efc13ccbe4c 322 SD_FAULTCOUNT = 0;
chaithanyarss 221:2efc13ccbe4c 323 }
chaithanyarss 221:2efc13ccbe4c 324 }
chaithanyarss 221:2efc13ccbe4c 325 }
chaithanyarss 221:2efc13ccbe4c 326
chaithanyarss 221:2efc13ccbe4c 327 void HANDLE_HW_FAULT_BAE()
chaithanyarss 221:2efc13ccbe4c 328 {
chaithanyarss 221:2efc13ccbe4c 329 if(BAE_STATUS != DEVICE_DISABLED) {
chaithanyarss 221:2efc13ccbe4c 330 if(BAE_STATUS == DEVICE_OC_FAULT)
chaithanyarss 221:2efc13ccbe4c 331 BAE_SW_EN_DS = 0; //Power ON BAE
chaithanyarss 221:2efc13ccbe4c 332
chaithanyarss 221:2efc13ccbe4c 333 if(BAE_OC_FAULT == 0) { // If OC Fault
chaithanyarss 221:2efc13ccbe4c 334 BAE_SW_EN_DS = 1; //Switch OFF BAE
chaithanyarss 221:2efc13ccbe4c 335 BAE_FAULTCOUNT++;
chaithanyarss 221:2efc13ccbe4c 336 BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
chaithanyarss 221:2efc13ccbe4c 337 } else {
chaithanyarss 221:2efc13ccbe4c 338 BAE_STATUS = DEVICE_POWERED;
chaithanyarss 221:2efc13ccbe4c 339 BAE_FAULTCOUNT = 0;
chaithanyarss 221:2efc13ccbe4c 340 }
chaithanyarss 221:2efc13ccbe4c 341 }
chaithanyarss 221:2efc13ccbe4c 342 }
chaithanyarss 221:2efc13ccbe4c 343
chaithanyarss 221:2efc13ccbe4c 344 void HANDLE_HW_FAULT_PL()
chaithanyarss 221:2efc13ccbe4c 345 {
chaithanyarss 221:2efc13ccbe4c 346 if(PL_STATUS != DEVICE_DISABLED) {
chaithanyarss 221:2efc13ccbe4c 347 if(PL_STATUS == DEVICE_OC_FAULT)
chaithanyarss 221:2efc13ccbe4c 348 PL_SW_EN_DS = 0; //Power ON PL
chaithanyarss 221:2efc13ccbe4c 349
chaithanyarss 221:2efc13ccbe4c 350 if(PL_BEE_SW_OC_FAULT == 0) { // if OC Fault
chaithanyarss 221:2efc13ccbe4c 351 PL_SW_EN_DS = 1; // switching OFF PL
chaithanyarss 221:2efc13ccbe4c 352 PL_FAULTCOUNT++;
chaithanyarss 221:2efc13ccbe4c 353 PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
chaithanyarss 221:2efc13ccbe4c 354 } else {
chaithanyarss 221:2efc13ccbe4c 355 if(PL_STATUS == DEVICE_OC_FAULT)
chaithanyarss 221:2efc13ccbe4c 356 PL_SW_EN_DS = 0; //Switching OFF PL
chaithanyarss 221:2efc13ccbe4c 357 PL_STATUS = DEVICE_ENABLED;
chaithanyarss 221:2efc13ccbe4c 358 PL_FAULTCOUNT = 0;
chaithanyarss 221:2efc13ccbe4c 359 }
chaithanyarss 221:2efc13ccbe4c 360 }
chaithanyarss 221:2efc13ccbe4c 361 }
chaithanyarss 221:2efc13ccbe4c 362
chaithanyarss 221:2efc13ccbe4c 363 void COLLECT_CDMS_RAM()
chaithanyarss 221:2efc13ccbe4c 364 {
chaithanyarss 221:2efc13ccbe4c 365 /*--------------------Current FSC's---------------------*/
chaithanyarss 221:2efc13ccbe4c 366 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 367 CDMS_HEALTH_DATA[i+43] = FSC_LAST[5] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 368 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 369 CDMS_HEALTH_DATA[i+47] = FSC_CURRENT[5] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 370 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 371 CDMS_HEALTH_DATA[i+51] = FSC_LAST[4] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 372 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 373 CDMS_HEALTH_DATA[i+55] = FSC_CURRENT[4] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 374 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 375 CDMS_HEALTH_DATA[i+59] = FSC_LAST[3] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 376 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 377 CDMS_HEALTH_DATA[i+63] = FSC_CURRENT[3] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 378 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 379 CDMS_HEALTH_DATA[i+67] = FSC_LAST[2] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 380 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 381 CDMS_HEALTH_DATA[i+71] = FSC_CURRENT[2] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 382 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 383 CDMS_HEALTH_DATA[i+75] = FSC_LAST[1] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 384 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 385 CDMS_HEALTH_DATA[i+79] = FSC_CURRENT[1] >> (i*8);
chaithanyarss 221:2efc13ccbe4c 386 /*---------------------Latest Time----------------------*/
chaithanyarss 221:2efc13ccbe4c 387 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 388 CDMS_HEALTH_DATA[i+83] = TIME_LATEST_SPI_SPEED >> (i*8);
chaithanyarss 221:2efc13ccbe4c 389 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 390 CDMS_HEALTH_DATA[i+87] = TIME_LATEST_SD_RD >> (i*8);
chaithanyarss 221:2efc13ccbe4c 391 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 392 CDMS_HEALTH_DATA[i+91] = TIME_LATEST_SD_WR >> (i*8);
chaithanyarss 221:2efc13ccbe4c 393 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 394 CDMS_HEALTH_DATA[i+95] = TIME_LATEST_I2C_SPEED >> (i*8);
chaithanyarss 221:2efc13ccbe4c 395 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 396 CDMS_HEALTH_DATA[i+99] = TIME_LATEST_I2C_BAE >> (i*8);
chaithanyarss 221:2efc13ccbe4c 397 for(int i=0; i<4; i++)
chaithanyarss 221:2efc13ccbe4c 398 CDMS_HEALTH_DATA[i+103] = TIME_LATEST_RTC >> (i*8);
chaithanyarss 221:2efc13ccbe4c 399 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 400 CDMS_HEALTH_DATA[i+107] = COMRX_RESET_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 401 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 402 CDMS_HEALTH_DATA[i+107] = PL_RCV_SC_DATA_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 403 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 404 CDMS_HEALTH_DATA[i+111] = PL_MAIN_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 405 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 406 CDMS_HEALTH_DATA[i+113] = CDMS_HK_MAIN_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 407 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 408 CDMS_HEALTH_DATA[i+115] = CDMS_I2C_ERR_BAE_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 409 for(int i=0; i<2; i++)
chaithanyarss 221:2efc13ccbe4c 410 CDMS_HEALTH_DATA[i+117] = CDMS_I2C_ERR_SPEED_COUNTER >> (i*8);
chaithanyarss 221:2efc13ccbe4c 411 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | CDMS_STANDBY_PL << 7;
chaithanyarss 221:2efc13ccbe4c 412 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_INIT_STATUS << 6) & 0x40);
chaithanyarss 221:2efc13ccbe4c 413 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_HK_MAIN_STATUS << 5) & 0x20);
chaithanyarss 221:2efc13ccbe4c 414 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_HK_STATUS << 3) & 0x18);
chaithanyarss 221:2efc13ccbe4c 415 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((COMRX_STATUS << 2) & 0x04);
chaithanyarss 221:2efc13ccbe4c 416 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_RTC_BL << 1) & 0x02);
chaithanyarss 221:2efc13ccbe4c 417 CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] & 0xFE;
chaithanyarss 221:2efc13ccbe4c 418
chaithanyarss 221:2efc13ccbe4c 419 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | PL_RCV_SC_DATA_STATUS << 7;
chaithanyarss 221:2efc13ccbe4c 420 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_SESSION << 6) & 0x40);
chaithanyarss 221:2efc13ccbe4c 421 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_RX << 5) & 0x20);
chaithanyarss 221:2efc13ccbe4c 422 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((RF_SW_STATUS << 4) & 0x10);
chaithanyarss 221:2efc13ccbe4c 423 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_TX << 3) & 0x08);
chaithanyarss 221:2efc13ccbe4c 424 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_TX_STATUS << 2) & 0x04);
chaithanyarss 221:2efc13ccbe4c 425 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_MNG_TMTC << 1) & 0x02);
chaithanyarss 221:2efc13ccbe4c 426 CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | (CDMS_STANDBY_HK & 0x01);
chaithanyarss 221:2efc13ccbe4c 427
chaithanyarss 221:2efc13ccbe4c 428 CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | PL_INIT_STATUS << 7;
chaithanyarss 221:2efc13ccbe4c 429 CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_MAIN_STATUS << 6) & 0x40);
chaithanyarss 221:2efc13ccbe4c 430 CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_LOW_POWER << 5) & 0x20);
chaithanyarss 221:2efc13ccbe4c 431 CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_STATE << 3) & 0x18);
chaithanyarss 221:2efc13ccbe4c 432 CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | (PL_STATUS & 0x07);
shreeshas95 103:b55559925dc1 433 }