Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
aniruddhv
Date:
Sat Jul 23 23:37:46 2016 +0000
Revision:
275:605dd29161ad
Parent:
268:ded5306a1fd1
Changed pin of com_tx_oc_fault, combined global variables

Who changed what in which revision?

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