publishing to check changes in cdms code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA_flag by samp Srinivasan

Committer:
chaithanyarss
Date:
Fri Jul 08 12:53:24 2016 +0000
Revision:
248:407ab7e337cd
Parent:
235:c127b15409b2
Child:
250:12de1b155715
Completed HK except Flash

Who changed what in which revision?

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