for frequency correction testing

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
chaithanyarss
Date:
Sun Jul 03 09:47:05 2016 +0000
Revision:
215:570251b23c7b
Parent:
210:f4acf895b598
Child:
218:8e8396f15bc2
Reset added

Who changed what in which revision?

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