working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
samp1234
Date:
Tue Mar 28 08:50:07 2017 +0000
Revision:
355:a5e72222ff26
Parent:
354:eb6c863756a8
Child:
356:197c93dc2012
Final with 1min obsrs

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 289:9bd62b69874c 14 extern uint8_t beacon_array[134];
samp1234 354:eb6c863756a8 15 //extern RSSI_MAX;
ee12b079 289:9bd62b69874c 16
ee12b079 210:f4acf895b598 17 AnalogIn TempInput(PIN27); // Input from Current Multiplexer
shreeshas95 103:b55559925dc1 18 AnalogIn CDMS_temp_sensor(PIN53);
chaithanyarss 333:cddef120cae3 19 AnalogIn COMRX_RSSI_VOLTAGE(PIN70);
ee12b079 322:7d906d34aaff 20 AnalogIn EPS_BTRY_VOLT (PIN54);
samp1234 352:022c513aee03 21 AnalogIn BAE_CURRENT_MUX_OUT (PIN53);
ee12b079 210:f4acf895b598 22
shreeshas95 103:b55559925dc1 23 DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines
shreeshas95 103:b55559925dc1 24 DigitalOut SelectLinec2 (PIN78);
samp1234 352:022c513aee03 25 // SBC V1.0
samp1234 354:eb6c863756a8 26 DigitalOut SelectLinec1 (PIN76);
samp1234 354:eb6c863756a8 27 DigitalOut SelectLinec0 (PIN77); // LSB of Select Lines
chaithanyarss 303:b49b486a7107 28
samp1234 352:022c513aee03 29 // SBC V2.0
samp1234 354:eb6c863756a8 30 //DigitalOut SelectLinec1 (PIN77);
samp1234 354:eb6c863756a8 31 //DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
samp1234 352:022c513aee03 32
shreeshas95 103:b55559925dc1 33
chaithanyarss 251:c766afa330a3 34 Convolution CDMS_HEALTH;
chaithanyarss 251:c766afa330a3 35 Convolution BAE_HEALTH;
chaithanyarss 251:c766afa330a3 36 unsigned char CDMS_HK_FRAME[134] = {0};
chaithanyarss 251:c766afa330a3 37 char BAE_HK[134] = {0};
chaithanyarss 251:c766afa330a3 38 uint8_t convoluted_CDMS_HK[270];
chaithanyarss 251:c766afa330a3 39 uint8_t interleave_CDMS_HK[288];
chaithanyarss 251:c766afa330a3 40 uint8_t CDMS_HEALTH_FINAL[512] = {0};
chaithanyarss 251:c766afa330a3 41 uint8_t convoluted_BAE_HK[270];
chaithanyarss 251:c766afa330a3 42 uint8_t interleave_BAE_HK[288];
chaithanyarss 251:c766afa330a3 43 uint8_t BAE_HEALTH_FINAL[512] = {0};
chaithanyarss 251:c766afa330a3 44 unsigned char BAE_HK_FRAME[134] = {0};
chaithanyarss 251:c766afa330a3 45
chaithanyarss 251:c766afa330a3 46
chaithanyarss 251:c766afa330a3 47
shreeshas95 104:a50ae79ca36e 48 void FCTN_CDMS_HK_MAIN(void const *args)
shreeshas95 103:b55559925dc1 49 {
ee12b079 268:ded5306a1fd1 50 uint8_t sd_stat = 0;
ee12b079 289:9bd62b69874c 51 uint8_t hk_count=0;
chaithanyarss 332:7d2431ce979f 52 while(1) {
ee12b079 342:77b0d59897f7 53 gPC.printf("waiting for HK sig\n\r");
chaithanyarss 332:7d2431ce979f 54 gHK_THREAD->signal_wait(HK_SIGNAL);
ee12b079 342:77b0d59897f7 55 gPC.printf("checking mutex in HK\n\r");
chaithanyarss 332:7d2431ce979f 56 gMutex.lock();
samp1234 346:204497974293 57 SCI_LED1 =1;
ee12b079 342:77b0d59897f7 58 gPC.printf("locked mutex, entered in HK \n\r");
chaithanyarss 332:7d2431ce979f 59 if(hk_count == 1 || hk_count == 2) {
chaithanyarss 332:7d2431ce979f 60 FCTN_CDMS_PL_MAIN((void const *)NULL);
chaithanyarss 332:7d2431ce979f 61 hk_count--;
ee12b079 342:77b0d59897f7 62 gPC.printf("releasing mutex for HK_PL \n\r");
samp1234 346:204497974293 63 SCI_LED1 =0;
samp1234 353:e1803e801e20 64 PL_GPIO_3_STATUS=0;
chaithanyarss 332:7d2431ce979f 65 gMutex.unlock();
chaithanyarss 332:7d2431ce979f 66 continue;
chaithanyarss 332:7d2431ce979f 67 } else if(hk_count == 0) {
chaithanyarss 332:7d2431ce979f 68 FCTN_CDMS_PL_MAIN((void const *)NULL);
chaithanyarss 332:7d2431ce979f 69 hk_count = 2;
chaithanyarss 332:7d2431ce979f 70 }
ee12b079 342:77b0d59897f7 71
chaithanyarss 332:7d2431ce979f 72 //gPC.printf("\n\r%d\n",CDMS_WR_SD_FAULT_COUNTER);
chaithanyarss 332:7d2431ce979f 73 if(EN_CDMS_HK == 0x00)
chaithanyarss 332:7d2431ce979f 74 continue;
chaithanyarss 332:7d2431ce979f 75 CDMS_HK_MAIN_STATUS = 0x01;
chaithanyarss 332:7d2431ce979f 76 CDMS_HK_MAIN_COUNTER++;
ee12b079 210:f4acf895b598 77
samp1234 346:204497974293 78
chaithanyarss 332:7d2431ce979f 79 FCTN_CDMS_HK(); //collects temperatures
samp1234 346:204497974293 80
ee12b079 338:d63eb331a67d 81 if(!COM_RSSI_SET)
ee12b079 338:d63eb331a67d 82 {
ee12b079 338:d63eb331a67d 83 RSSI_VOLTAGE = COMRX_RSSI_VOLTAGE.read() * 3.3;//to be checked
ee12b079 338:d63eb331a67d 84 }
ee12b079 338:d63eb331a67d 85 else COM_RSSI_SET = 0;
samp1234 354:eb6c863756a8 86 gPC.printf("RSSI_MAX = %f",RSSI_MAX);
samp1234 354:eb6c863756a8 87 // gPC.printf("RSSI= %f",RSSI_VOLTAGE);
chaithanyarss 332:7d2431ce979f 88 //VERIFY_COMRX();
chaithanyarss 332:7d2431ce979f 89 VERIFY_RTC();
chaithanyarss 332:7d2431ce979f 90 HANDLE_HW_FAULTS();
chaithanyarss 332:7d2431ce979f 91 FUNC_CDMS_GPIO_STATUS();
chaithanyarss 257:7d404e9dc9e2 92
chaithanyarss 332:7d2431ce979f 93 uint8_t CDMS_quant[20];
chaithanyarss 332:7d2431ce979f 94 CDMS_quant[0]= COM_ADF_TMP+40;
chaithanyarss 332:7d2431ce979f 95 CDMS_quant[1]= (uint8_t)quant_data.CDMS_temp_quant;
chaithanyarss 333:cddef120cae3 96 CDMS_quant[2]= (uint8_t)(RSSI_VOLTAGE*10);
samp1234 354:eb6c863756a8 97 CDMS_quant[3]= (uint8_t)(EPS_BTRY_VOLT.read()*33*(62.0/11));
chaithanyarss 332:7d2431ce979f 98 for(int i=0; i<16; i++) {
chaithanyarss 332:7d2431ce979f 99 CDMS_quant[i+4]= (uint8_t)quant_data.temp_quant[i];
chaithanyarss 332:7d2431ce979f 100 }
chaithanyarss 332:7d2431ce979f 101 minMaxHkData();
chaithanyarss 224:3ac1f91e0ebc 102
chaithanyarss 332:7d2431ce979f 103 CDMS_HEALTH_DATA[1] = GPIO_STATUS; //Reading GPIO Pins
chaithanyarss 332:7d2431ce979f 104 CDMS_HEALTH_DATA[0] = GPIO_STATUS >> 8;
chaithanyarss 332:7d2431ce979f 105 COLLECT_CDMS_RAM();
chaithanyarss 332:7d2431ce979f 106 for(int i = 0; i<84; i++)
chaithanyarss 332:7d2431ce979f 107 CDMS_HEALTH_DATA[2+i] = CDMS_RAM[i]; //Reading RAM parameters
chaithanyarss 332:7d2431ce979f 108 for(int i = 0; i<20; i++) //Collecting Data from Temp sensors
chaithanyarss 332:7d2431ce979f 109 CDMS_HEALTH_DATA[86+i] = CDMS_quant[i];
chaithanyarss 224:3ac1f91e0ebc 110
chaithanyarss 332:7d2431ce979f 111 // Here: Have to FIT flash data.
chaithanyarss 332:7d2431ce979f 112 CDMS_HEALTH_DATA[106] = (EPS_V_A_EN_STATUS<<7) | ((BAE_STATUS<<5)&0x60) | ((SD_STATUS<<3)&0x18) | ((PL_STATUS<<1)&0x06) | (PL_EPS_LATCH_SW_EN & 0x01);
samp1234 353:e1803e801e20 113 // CDMS_HEALTH_DATA[107] = (RTC_INIT_STATUS<<6) | ((CDMS_RTC_DISABLE<<5)&0x20);
samp1234 353:e1803e801e20 114 CDMS_HEALTH_DATA[107] = (RTC_INIT_STATUS<<6) | ((EN_RTC<<5)&0x20); // changed by samp
samp1234 353:e1803e801e20 115 gPC.printf("\n\r 0x%08X",EN_RTC);
chaithanyarss 332:7d2431ce979f 116 CDMS_HEALTH_DATA[108] = CDMS_RESET_COUNTER >>8;
chaithanyarss 332:7d2431ce979f 117 CDMS_HEALTH_DATA[109] = CDMS_RESET_COUNTER;
chaithanyarss 332:7d2431ce979f 118 CDMS_HEALTH_DATA[110] = TIME_LATEST_CDSMS_RESET >>24;
chaithanyarss 332:7d2431ce979f 119 CDMS_HEALTH_DATA[111] = TIME_LATEST_CDSMS_RESET >>16;
chaithanyarss 332:7d2431ce979f 120 CDMS_HEALTH_DATA[112] = TIME_LATEST_CDSMS_RESET >>8;
chaithanyarss 332:7d2431ce979f 121 CDMS_HEALTH_DATA[113] = TIME_LATEST_CDSMS_RESET;
chaithanyarss 332:7d2431ce979f 122 COM_TC_BYTES_LIMIT = BYTE_OVERFLOW_CONSTANT;
chaithanyarss 332:7d2431ce979f 123 CDMS_HEALTH_DATA[114] = COM_TC_BYTES_LIMIT>>8;
chaithanyarss 332:7d2431ce979f 124 CDMS_HEALTH_DATA[115] = COM_TC_BYTES_LIMIT;
chaithanyarss 332:7d2431ce979f 125 CDMS_HEALTH_DATA[116] = COM_RX_CURRENT_MAX;
chaithanyarss 332:7d2431ce979f 126 CDMS_HEALTH_DATA[117] = COM_RX_DISABLE_TIMEOUT;
chaithanyarss 332:7d2431ce979f 127 CDMS_HEALTH_DATA[118] = COM_PA_TMP_HIGH;
chaithanyarss 332:7d2431ce979f 128 CDMS_HEALTH_DATA[119] = COM_PA_RECOVERY_TIMEOUT;
chaithanyarss 332:7d2431ce979f 129 CDMS_HEALTH_DATA[120] = COM_SESSION_TIMEOUT/60;
chaithanyarss 332:7d2431ce979f 130 CDMS_HEALTH_DATA[121] = COM_RSSI_MIN;
chaithanyarss 332:7d2431ce979f 131 CDMS_HEALTH_DATA[122] = SD_LIB_BLK_CURRENT>>8;
samp1234 355:a5e72222ff26 132 CDMS_HEALTH_DATA[123] = SD_LIB_BLK_CURRENT;
chaithanyarss 328:2242ebc71be8 133
chaithanyarss 332:7d2431ce979f 134 uint32_t time = FCTN_CDMS_RD_RTC() >> 7; //Reading Time from RTC
chaithanyarss 332:7d2431ce979f 135 for(int i = 124; i<128; i++)
chaithanyarss 332:7d2431ce979f 136 CDMS_HEALTH_DATA[i] = time >> (127-i)*8;
chaithanyarss 332:7d2431ce979f 137
chaithanyarss 332:7d2431ce979f 138 gPC.printf("\t\t%d/%d/%d ",((time & 0x003E0000)>>17),((time & 0x03C00000)>>22),((time & 0x0C000000)>>26)+2016);
chaithanyarss 332:7d2431ce979f 139 gPC.printf("%d:%d:%d\n",((time & 0x0001F000)>>12),((time & 0x00000FC0)>>6),(time & 0x0000003F));
samp1234 346:204497974293 140 if(CDMS_HK_SD_DATA_READY==1||BAE_HK_SD_DATA_READY==1)
samp1234 346:204497974293 141 {
samp1234 346:204497974293 142 FCTN_SD_MNGR();
samp1234 346:204497974293 143 gPC.printf("endHK_SD");
samp1234 346:204497974293 144 }
samp1234 346:204497974293 145 // gPC.printf("endHK_SD"); //Adding FSC & TMID to TM frame
samp1234 346:204497974293 146
chaithanyarss 332:7d2431ce979f 147 CDMS_HK_FRAME[0] = 0x20;
chaithanyarss 332:7d2431ce979f 148 CDMS_HK_FRAME[1] = (FSC_CURRENT[4]+1) >> 16;
chaithanyarss 332:7d2431ce979f 149 CDMS_HK_FRAME[2] = (FSC_CURRENT[4]+1) >> 8;
chaithanyarss 332:7d2431ce979f 150 CDMS_HK_FRAME[3] = FSC_CURRENT[4]+1;
chaithanyarss 332:7d2431ce979f 151 // gPC.printf("\n");
chaithanyarss 332:7d2431ce979f 152 for(int i = 0; i<128; i++) { /*Adding actual CDMS Health data to TM frame*/
chaithanyarss 332:7d2431ce979f 153 CDMS_HK_FRAME[i+4] = CDMS_HEALTH_DATA[i];
chaithanyarss 332:7d2431ce979f 154 //gPC.printf("%02x",CDMS_HEALTH_DATA[i]);
chaithanyarss 332:7d2431ce979f 155 }
chaithanyarss 332:7d2431ce979f 156 // gPC.printf("\n");
chaithanyarss 332:7d2431ce979f 157 uint16_t crc = crc16_gen(CDMS_HK_FRAME,132); /*Adding CRC to TM frame*/
chaithanyarss 332:7d2431ce979f 158 CDMS_HK_FRAME[132] = crc >> 8;
chaithanyarss 332:7d2431ce979f 159 CDMS_HK_FRAME[133] = crc;
chaithanyarss 257:7d404e9dc9e2 160
chaithanyarss 332:7d2431ce979f 161 exor(CDMS_HK_FRAME);
chaithanyarss 332:7d2431ce979f 162 CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME , convoluted_CDMS_HK);
chaithanyarss 332:7d2431ce979f 163 CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME + 67, convoluted_CDMS_HK + 135);
chaithanyarss 332:7d2431ce979f 164 //gPC.printf("\n\r reached here");
chaithanyarss 332:7d2431ce979f 165 interleave(convoluted_CDMS_HK , interleave_CDMS_HK);
chaithanyarss 332:7d2431ce979f 166 interleave(convoluted_CDMS_HK +135, interleave_CDMS_HK + 144);
chaithanyarss 332:7d2431ce979f 167 //gPC.printf("\n\r reached here");
samp1234 346:204497974293 168 // gPC.printf("enterdHK_SD");
samp1234 346:204497974293 169
samp1234 346:204497974293 170 if(CDMS_HK_SD_DATA_READY==1)
samp1234 346:204497974293 171 {
chaithanyarss 332:7d2431ce979f 172 for(int i=0; i<288; i++)
chaithanyarss 332:7d2431ce979f 173 CDMS_HEALTH_FINAL[i] = interleave_CDMS_HK[i];
chaithanyarss 332:7d2431ce979f 174 //gPC.printf("\n\r reached here");
chaithanyarss 332:7d2431ce979f 175 sd_stat = SD_WRITE(CDMS_HEALTH_FINAL,FSC_CURRENT[4]+1,4);
samp1234 346:204497974293 176
chaithanyarss 332:7d2431ce979f 177 if(sd_stat) {
chaithanyarss 332:7d2431ce979f 178 gPC.puts("sd write failure $*&^@!~!");
samp1234 346:204497974293 179 }
ee12b079 268:ded5306a1fd1 180 }
samp1234 346:204497974293 181 // }
samp1234 346:204497974293 182 CDMS_HK_SD_DATA_READY=1;
samp1234 346:204497974293 183
chaithanyarss 332:7d2431ce979f 184 // gPC.printf("Completed CDMS HK\t");
chaithanyarss 332:7d2431ce979f 185
chaithanyarss 332:7d2431ce979f 186 /*---------------------------------- BAE HK --------------------------------------------*/
samp1234 346:204497974293 187
samp1234 346:204497974293 188 // gPC.printf("endHK_SD2");
chaithanyarss 332:7d2431ce979f 189 BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
samp1234 346:204497974293 190 // gPC.printf("\nEntering BAE HK\t");
chaithanyarss 332:7d2431ce979f 191 if(BAE_HK_I2C == 0) {
samp1234 346:204497974293 192 // gPC.printf("BAE_HK_");
chaithanyarss 332:7d2431ce979f 193 crc = crc16_gen((unsigned char *)BAE_HK,132);
chaithanyarss 332:7d2431ce979f 194 if(crc == ((uint16_t)BAE_HK[132] << 8) | (uint16_t)BAE_HK[133]) {
samp1234 352:022c513aee03 195 gPC.printf("BAE HK data recieved through I2C\t");
chaithanyarss 332:7d2431ce979f 196 TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7;
chaithanyarss 332:7d2431ce979f 197 /*for(int i = 0; i<15; i++)
chaithanyarss 332:7d2431ce979f 198 gPC.printf("\r 0x%02X\n",BAE_HK[i]);*/
chaithanyarss 332:7d2431ce979f 199 for(int i = 0; i<4; i++)
chaithanyarss 332:7d2431ce979f 200 BAE_HK[i] = time >> (3-i)*8;
chaithanyarss 332:7d2431ce979f 201 BAE_HK_FRAME[0] = 0x28;
chaithanyarss 332:7d2431ce979f 202 BAE_HK_FRAME[1] = (FSC_CURRENT[5]+1) >> 16;
chaithanyarss 332:7d2431ce979f 203 BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8;
chaithanyarss 332:7d2431ce979f 204 BAE_HK_FRAME[3] = FSC_CURRENT[5]+1;
chaithanyarss 332:7d2431ce979f 205 for(int i = 0; i<128; i++) /*Adding actual CDMS Health data to TM frame*/
chaithanyarss 332:7d2431ce979f 206 BAE_HK_FRAME[4+i] = BAE_HK[i];
chaithanyarss 332:7d2431ce979f 207 crc = crc16_gen(BAE_HK_FRAME,132); /*Adding CRC to TM frame*/
chaithanyarss 332:7d2431ce979f 208 BAE_HK_FRAME[132] = crc >> 8;
chaithanyarss 332:7d2431ce979f 209 BAE_HK_FRAME[133] = crc;
chaithanyarss 332:7d2431ce979f 210 exor(BAE_HK_FRAME);
chaithanyarss 332:7d2431ce979f 211 BAE_HEALTH.convolutionEncode(BAE_HK_FRAME , convoluted_BAE_HK);
chaithanyarss 332:7d2431ce979f 212 BAE_HEALTH.convolutionEncode(BAE_HK_FRAME + 67, convoluted_BAE_HK + 135);
chaithanyarss 332:7d2431ce979f 213 interleave(convoluted_BAE_HK , interleave_BAE_HK);
chaithanyarss 332:7d2431ce979f 214 interleave(convoluted_BAE_HK +135, interleave_BAE_HK + 144);
samp1234 346:204497974293 215
samp1234 346:204497974293 216 // gPC.printf("enterHK_SD3");
samp1234 346:204497974293 217
samp1234 346:204497974293 218 if(BAE_HK_SD_DATA_READY==1)
samp1234 346:204497974293 219 {
samp1234 346:204497974293 220
chaithanyarss 332:7d2431ce979f 221 for(int i=0; i<288; i++)
chaithanyarss 332:7d2431ce979f 222 BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i];
chaithanyarss 332:7d2431ce979f 223 sd_stat = SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5);
chaithanyarss 332:7d2431ce979f 224 if(sd_stat) {
samp1234 346:204497974293 225 gPC.puts("BAE_HK sd write fail");
chaithanyarss 332:7d2431ce979f 226 //break;
chaithanyarss 332:7d2431ce979f 227 }
samp1234 346:204497974293 228 }
samp1234 346:204497974293 229 BAE_HK_SD_DATA_READY = 1;
samp1234 346:204497974293 230 // gPC.printf("endHK_SD4");
chaithanyarss 332:7d2431ce979f 231 }
ee12b079 247:d0be0773b951 232
chaithanyarss 332:7d2431ce979f 233 } else {
chaithanyarss 332:7d2431ce979f 234 gPC.printf("BAE HK data not recieved through I2C\t");
samp1234 352:022c513aee03 235 gPC.printf("/r/n ack= %d",BAE_HK_I2C);
chaithanyarss 332:7d2431ce979f 236 for(int i = 0; i<134; i++)
chaithanyarss 332:7d2431ce979f 237 BAE_HK[i] = 0;
samp1234 352:022c513aee03 238
chaithanyarss 332:7d2431ce979f 239 }
chaithanyarss 332:7d2431ce979f 240 // gPC.printf("Completed BAE HK\n");
chaithanyarss 332:7d2431ce979f 241
chaithanyarss 332:7d2431ce979f 242 /*----------------------------------Beacon message--------------------------------------*/
chaithanyarss 332:7d2431ce979f 243
chaithanyarss 332:7d2431ce979f 244
chaithanyarss 332:7d2431ce979f 245 // Add HK bits
chaithanyarss 332:7d2431ce979f 246 beacon_array[0] = 0x00;
chaithanyarss 332:7d2431ce979f 247 beacon_array[1] = time >> 32;
chaithanyarss 332:7d2431ce979f 248 beacon_array[2] = time >> 24;
chaithanyarss 332:7d2431ce979f 249 beacon_array[3] = time >> 16;
chaithanyarss 332:7d2431ce979f 250 beacon_array[4] = time >> 8;
chaithanyarss 332:7d2431ce979f 251 beacon_array[5] = time;
chaithanyarss 332:7d2431ce979f 252 beacon_array[6] = SD_FAULTCOUNT >> 8;
chaithanyarss 332:7d2431ce979f 253 beacon_array[7] = SD_FAULTCOUNT;
chaithanyarss 332:7d2431ce979f 254 beacon_array[8] = RTC_FAULTCOUNT >> 8;
chaithanyarss 332:7d2431ce979f 255 beacon_array[9] = RTC_FAULTCOUNT;
ee12b079 338:d63eb331a67d 256 if(!COM_OC_SET)
chaithanyarss 332:7d2431ce979f 257 beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(0<<2)|(COMRX_OC_FAULT<<1)|(COM_TX_OC_FAULT);
ee12b079 338:d63eb331a67d 258 else
ee12b079 338:d63eb331a67d 259 {
ee12b079 338:d63eb331a67d 260 beacon_array[10] = (((SD_STATUS == DEVICE_DISABLED || SD_STATUS == DEVICE_OC_FAULT)?1:0)<<7)|(RTC_STATUS <<6)|(COM_RX_STATUS<<3)|(0<<2)|(COMRX_OC_FAULT<<1)|(com_oc_sw_status);
ee12b079 338:d63eb331a67d 261 COM_OC_SET = 0;
ee12b079 338:d63eb331a67d 262 }
samp1234 354:eb6c863756a8 263 beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL<<6);
chaithanyarss 332:7d2431ce979f 264 beacon_array[12] = CDMS_HK_MAIN_COUNTER >>8;
chaithanyarss 332:7d2431ce979f 265 beacon_array[13] = CDMS_HK_MAIN_COUNTER;
chaithanyarss 332:7d2431ce979f 266 beacon_array[14] = PL_MAIN_COUNTER >>8;
chaithanyarss 332:7d2431ce979f 267 beacon_array[15] = PL_MAIN_COUNTER;
chaithanyarss 332:7d2431ce979f 268 beacon_array[16] = PL_RCV_SC_DATA_COUNTER >>8;
chaithanyarss 332:7d2431ce979f 269 beacon_array[17] = PL_RCV_SC_DATA_COUNTER;
chaithanyarss 332:7d2431ce979f 270 beacon_array[18] = TIME_LATEST_SPI_SPEED >>24;
chaithanyarss 332:7d2431ce979f 271 beacon_array[19] = TIME_LATEST_SPI_SPEED >>16;
chaithanyarss 332:7d2431ce979f 272 beacon_array[20] = TIME_LATEST_SPI_SPEED >>8;
chaithanyarss 332:7d2431ce979f 273 beacon_array[21] = TIME_LATEST_SPI_SPEED;
chaithanyarss 333:cddef120cae3 274 beacon_array[22] = (uint8_t)(RSSI_VOLTAGE*10);
chaithanyarss 332:7d2431ce979f 275
chaithanyarss 332:7d2431ce979f 276 // Add SC bits
chaithanyarss 332:7d2431ce979f 277 crc = crc16_gen(beacon_array,132);
chaithanyarss 332:7d2431ce979f 278 beacon_array[132] = crc;
chaithanyarss 332:7d2431ce979f 279 beacon_array[133] = crc >> 8;
chaithanyarss 332:7d2431ce979f 280 bool y;
samp1234 353:e1803e801e20 281 y = FCTN_I2C_WRITE((char *)beacon_array,135); //134
chaithanyarss 332:7d2431ce979f 282 if(y == 0) {
ee12b079 245:da9d1bd999da 283 TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7;
chaithanyarss 332:7d2431ce979f 284 //gPC.printf("long Bcn sent\n\r");
chaithanyarss 332:7d2431ce979f 285 } else
chaithanyarss 332:7d2431ce979f 286 gPC.printf("long Bcn not sent\r\n");
chaithanyarss 332:7d2431ce979f 287 //gPC.printf("\rCompleted Beacon\n");
ee12b079 342:77b0d59897f7 288 gPC.printf("\rreleasing mutex for HK_MAIN \n\r");
samp1234 346:204497974293 289 SCI_LED1 =0;
samp1234 346:204497974293 290 gMutex.unlock();
ee12b079 245:da9d1bd999da 291 }
ee12b079 210:f4acf895b598 292 }
shreeshas95 103:b55559925dc1 293
shreeshas95 103:b55559925dc1 294 int quantiz(float start,float step,float x)
shreeshas95 103:b55559925dc1 295 {
shreeshas95 103:b55559925dc1 296 int y=(x-start)/step;
shreeshas95 103:b55559925dc1 297 if(y<=0)y=0;
shreeshas95 103:b55559925dc1 298 if(y>=255)y=255;
shreeshas95 103:b55559925dc1 299 return y;
shreeshas95 103:b55559925dc1 300 }
shreeshas95 103:b55559925dc1 301
ee12b079 210:f4acf895b598 302 char saveMin(char x,char y)
ee12b079 210:f4acf895b598 303 {
ee12b079 210:f4acf895b598 304 return (y<x)?y:x;
shreeshas95 103:b55559925dc1 305 }
ee12b079 210:f4acf895b598 306
ee12b079 210:f4acf895b598 307 char saveMax(char x,char y)
ee12b079 210:f4acf895b598 308 {
ee12b079 210:f4acf895b598 309 return (y>x)?y:x;
shreeshas95 103:b55559925dc1 310 }
ee12b079 210:f4acf895b598 311
ee12b079 210:f4acf895b598 312 void minMaxHkData()
chaithanyarss 224:3ac1f91e0ebc 313 {
chaithanyarss 333:cddef120cae3 314 MAX_COM_ADF_TMP = (MAX_COM_ADF_TMP < COM_ADF_TMP)?COM_ADF_TMP:MAX_COM_ADF_TMP;
chaithanyarss 333:cddef120cae3 315 MIN_COM_ADF_TMP = (MIN_COM_ADF_TMP > COM_ADF_TMP)?COM_ADF_TMP:MIN_COM_ADF_TMP;
chaithanyarss 333:cddef120cae3 316
chaithanyarss 333:cddef120cae3 317 MAX_RSSI_VOLTAGE = (MAX_RSSI_VOLTAGE < RSSI_VOLTAGE)?RSSI_VOLTAGE:MAX_RSSI_VOLTAGE;
chaithanyarss 333:cddef120cae3 318 MIN_RSSI_VOLTAGE = (MIN_RSSI_VOLTAGE > RSSI_VOLTAGE)?RSSI_VOLTAGE:MIN_RSSI_VOLTAGE;
chaithanyarss 333:cddef120cae3 319
chaithanyarss 224:3ac1f91e0ebc 320 if(firstCount==true) {
chaithanyarss 333:cddef120cae3 321 for (int i = 0; i < 16; ++i) {
chaithanyarss 224:3ac1f91e0ebc 322 min_max_data.temp_min[i] = quant_data.temp_quant[i];
chaithanyarss 224:3ac1f91e0ebc 323 min_max_data.temp_max[i] = quant_data.temp_quant[i];
shreeshas95 103:b55559925dc1 324 }
shreeshas95 103:b55559925dc1 325
shreeshas95 103:b55559925dc1 326 min_max_data.CDMS_temp_min=quant_data.CDMS_temp_quant;
shreeshas95 103:b55559925dc1 327 min_max_data.CDMS_temp_max=quant_data.CDMS_temp_quant;
chaithanyarss 224:3ac1f91e0ebc 328 } else {
chaithanyarss 333:cddef120cae3 329 for (int i = 0; i < 16; ++i) {
chaithanyarss 224:3ac1f91e0ebc 330 min_max_data.temp_min[i] = saveMin(min_max_data.temp_min[i],quant_data.temp_quant[i]);
chaithanyarss 224:3ac1f91e0ebc 331 min_max_data.temp_max[i] = saveMax(min_max_data.temp_max[i],quant_data.temp_quant[i]);
shreeshas95 103:b55559925dc1 332 }
chaithanyarss 224:3ac1f91e0ebc 333
ee12b079 210:f4acf895b598 334 min_max_data.CDMS_temp_min = saveMin(min_max_data.CDMS_temp_min,quant_data.CDMS_temp_quant);
ee12b079 210:f4acf895b598 335 min_max_data.CDMS_temp_max = saveMax(min_max_data.CDMS_temp_max,quant_data.CDMS_temp_quant);
chaithanyarss 224:3ac1f91e0ebc 336 }
shreeshas95 103:b55559925dc1 337 firstCount=false;
shreeshas95 103:b55559925dc1 338 }
shreeshas95 103:b55559925dc1 339
shreeshas95 103:b55559925dc1 340 void FCTN_CDMS_HK()
shreeshas95 103:b55559925dc1 341 {
chaithanyarss 224:3ac1f91e0ebc 342
shreeshas95 103:b55559925dc1 343 int Iteration=0;
spacelab 308:7c3872365d58 344 float resistance;
shreeshas95 103:b55559925dc1 345
shreeshas95 103:b55559925dc1 346 SelectLinec0=0;
shreeshas95 103:b55559925dc1 347 SelectLinec1=0;
shreeshas95 103:b55559925dc1 348 SelectLinec2=0;
shreeshas95 103:b55559925dc1 349 SelectLinec3=0;
spacelab 309:6ed5535ac465 350 wait_ms(1);
spacelab 308:7c3872365d58 351 //gPC.printf("\r%d %d %d %d\n",SelectLinec3.read(),SelectLinec2.read(),SelectLinec1.read(),SelectLinec0.read());
chaithanyarss 224:3ac1f91e0ebc 352 for(Iteration=0; Iteration<16; Iteration++) {
shreeshas95 103:b55559925dc1 353
shreeshas95 103:b55559925dc1 354 actual_data.temp_actual[Iteration]=TempInput.read();
shreeshas95 103:b55559925dc1 355
shreeshas95 103:b55559925dc1 356 SelectLinec0=!(SelectLinec0);
shreeshas95 103:b55559925dc1 357 if(Iteration%2==1)
shreeshas95 103:b55559925dc1 358 SelectLinec1=!(SelectLinec1);
shreeshas95 103:b55559925dc1 359 if(Iteration%4==3)
shreeshas95 103:b55559925dc1 360 SelectLinec2=!(SelectLinec2);
shreeshas95 103:b55559925dc1 361 if(Iteration%8==7)
chaithanyarss 224:3ac1f91e0ebc 362 SelectLinec3=!(SelectLinec3);
chaithanyarss 332:7d2431ce979f 363 wait_ms(1);
chaithanyarss 332:7d2431ce979f 364 // gPC.printf("\r%d %d %d %d\n",SelectLinec3.read(),SelectLinec2.read(),SelectLinec1.read(),SelectLinec0.read());
shreeshas95 103:b55559925dc1 365 }
shreeshas95 103:b55559925dc1 366
ee12b079 210:f4acf895b598 367 actual_data.CDMS_temp_actual=(-90.7*3.3*CDMS_temp_sensor.read())+190.1543;
chaithanyarss 332:7d2431ce979f 368
spacelab 309:6ed5535ac465 369
chaithanyarss 332:7d2431ce979f 370
chaithanyarss 224:3ac1f91e0ebc 371 for(Iteration=0; Iteration<16; Iteration++) {
chaithanyarss 224:3ac1f91e0ebc 372
chaithanyarss 332:7d2431ce979f 373 if(Iteration<4) {
ee12b079 322:7d906d34aaff 374 actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3*2*10;
chaithanyarss 332:7d2431ce979f 375 } else if(Iteration<14) {
chaithanyarss 328:2242ebc71be8 376 resistance=22000*actual_data.temp_actual[Iteration]*3.3/(3.3-actual_data.temp_actual[Iteration]*3.3);
chaithanyarss 332:7d2431ce979f 377
chaithanyarss 303:b49b486a7107 378 if(actual_data.temp_actual[Iteration]*3.3<1.47) //Document says 1.378 .Pls Check
chaithanyarss 332:7d2431ce979f 379
chaithanyarss 332:7d2431ce979f 380 actual_data.temp_actual[Iteration]=(3694/log(24.032242*resistance))-273;
chaithanyarss 303:b49b486a7107 381 else
chaithanyarss 332:7d2431ce979f 382
samp1234 311:af5ab655ba00 383 actual_data.temp_actual[Iteration]=(3365.4/log(7.60573*resistance))-273;
chaithanyarss 332:7d2431ce979f 384
chaithanyarss 332:7d2431ce979f 385 } else
shreeshas95 103:b55559925dc1 386 actual_data.temp_actual[Iteration]=(-90.7*3.3*actual_data.temp_actual[Iteration])+190.1543;
shreeshas95 103:b55559925dc1 387 }
chaithanyarss 224:3ac1f91e0ebc 388 for(Iteration=0; Iteration<16; Iteration++) {
shreeshas95 103:b55559925dc1 389
chaithanyarss 332:7d2431ce979f 390 if(Iteration<4) {
chaithanyarss 328:2242ebc71be8 391 quant_data.temp_quant[Iteration]=actual_data.temp_actual[Iteration];
chaithanyarss 328:2242ebc71be8 392 wait(0.001);
chaithanyarss 332:7d2431ce979f 393 } else if(Iteration<14)
samp1234 354:eb6c863756a8 394 {
shreeshas95 103:b55559925dc1 395 quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]);
chaithanyarss 332:7d2431ce979f 396 // quant_data.temp_quant[Iteration]=quantiz(0,1,actual_data.temp_actual[Iteration]);
samp1234 354:eb6c863756a8 397 quant_data.temp_quant[13]= COM_PA_TMP_IN_TX;
samp1234 354:eb6c863756a8 398 }
chaithanyarss 303:b49b486a7107 399 else
chaithanyarss 332:7d2431ce979f 400 // quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
chaithanyarss 332:7d2431ce979f 401 quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
shreeshas95 103:b55559925dc1 402 }
samp1234 354:eb6c863756a8 403 // quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual);
samp1234 354:eb6c863756a8 404 quant_data.CDMS_temp_quant=10*RSSI_MAX;
shreeshas95 103:b55559925dc1 405 minMaxHkData();
ee12b079 210:f4acf895b598 406 }
ee12b079 210:f4acf895b598 407
ee12b079 210:f4acf895b598 408 void FUNC_CDMS_GPIO_STATUS() //Polls the status of Input GPIO PINS
ee12b079 210:f4acf895b598 409 {
ee12b079 322:7d906d34aaff 410 /*
chaithanyarss 224:3ac1f91e0ebc 411 //V_A_PGOOD //TRZ EN
chaithanyarss 303:b49b486a7107 412 GPIO_STATUS=(V_A_PGOOD)?(GPIO_STATUS)|((uint16_t)(0x1<<15)):(GPIO_STATUS)&(~((uint16_t)(0x1<<15)));
chaithanyarss 224:3ac1f91e0ebc 413 //V_B_PGOOD_1 //3V3BPGOOD //$
chaithanyarss 303:b49b486a7107 414 GPIO_STATUS=(V_B_PGOOD_1)?(GPIO_STATUS)|((uint16_t)(0x1<<14)):(GPIO_STATUS)&(~((uint16_t)(0x1<<14)));
chaithanyarss 224:3ac1f91e0ebc 415 //V_B_PGOOD_2 //3V3BEN //$
chaithanyarss 303:b49b486a7107 416 GPIO_STATUS=(V_B_PGOOD_2)?(GPIO_STATUS)|((uint16_t)(0x1<<13)):(GPIO_STATUS)&(~((uint16_t)(0x1<<13)));
chaithanyarss 224:3ac1f91e0ebc 417 //V_C_PGOOD //3V3CPGOOD //$
chaithanyarss 303:b49b486a7107 418 GPIO_STATUS=(V_C_PGOOD)?(GPIO_STATUS)|((uint16_t)(0x1<<12)):(GPIO_STATUS)&(~((uint16_t)(0x1<<12)));
ee12b079 322:7d906d34aaff 419 */
chaithanyarss 332:7d2431ce979f 420
chaithanyarss 224:3ac1f91e0ebc 421 //COMRX_OC_FAULT //$
chaithanyarss 303:b49b486a7107 422 GPIO_STATUS=(COMRX_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<11)):(GPIO_STATUS)&(~((uint16_t)(0x1<<11)));
chaithanyarss 224:3ac1f91e0ebc 423 // COMTX_OC_FAULT //$
chaithanyarss 303:b49b486a7107 424 GPIO_STATUS=(COM_TX_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<10)):(GPIO_STATUS)&(~((uint16_t)(0x1<<10)));
ee12b079 322:7d906d34aaff 425 // CDMS_SD_OC_FAULT
ee12b079 322:7d906d34aaff 426 GPIO_STATUS=(SD_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<9)):(GPIO_STATUS)&(~((uint16_t)(0x1<<9)));
chaithanyarss 224:3ac1f91e0ebc 427 //BAE_OC_FAULT //$
ee12b079 322:7d906d34aaff 428 GPIO_STATUS=(BAE_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<8)):(GPIO_STATUS)&(~((uint16_t)(0x1<<8)));
chaithanyarss 332:7d2431ce979f 429
ee12b079 322:7d906d34aaff 430 /*
chaithanyarss 224:3ac1f91e0ebc 431 //PL_GPIO_1_STATUS //$
chaithanyarss 303:b49b486a7107 432 GPIO_STATUS=(PL_GPIO_1_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<8)):(GPIO_STATUS)&(~((uint16_t)(0x1<<8)));
chaithanyarss 224:3ac1f91e0ebc 433 //PL_GPIO_2_STATUS //$
chaithanyarss 303:b49b486a7107 434 GPIO_STATUS=(PL_GPIO_2_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<7)):(GPIO_STATUS)&(~((uint16_t)(0x1<<7)));
chaithanyarss 224:3ac1f91e0ebc 435 //PL_GPIO_3_STATUS //$
chaithanyarss 303:b49b486a7107 436 GPIO_STATUS=(PL_GPIO_3_STATUS)?(GPIO_STATUS)|((uint16_t)(0x1<<6)):(GPIO_STATUS)&(~((uint16_t)(0x1<<6)));
ee12b079 322:7d906d34aaff 437 */
chaithanyarss 332:7d2431ce979f 438
chaithanyarss 224:3ac1f91e0ebc 439 //PL_BEE_SW_OC_FAULT //to be verified
ee12b079 322:7d906d34aaff 440 GPIO_STATUS=(PL_BEE_SW_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<4)):(GPIO_STATUS)&(~((uint16_t)(0x1<<4)));
chaithanyarss 224:3ac1f91e0ebc 441 //PL_EPS_LATCH_SW_OC_FAULT // to be verified
ee12b079 322:7d906d34aaff 442 GPIO_STATUS=(PL_EPS_LATCH_SW_OC_FAULT)?(GPIO_STATUS)|((uint16_t)(0x1<<3)):(GPIO_STATUS)&(~((uint16_t)(0x1<<3)));
chaithanyarss 257:7d404e9dc9e2 443 //EPS_V_C_EN_STATUS
ee12b079 322:7d906d34aaff 444 GPIO_STATUS=(COM_RX_CNTRL)?(GPIO_STATUS)|((uint16_t)(0x1<<2)):(GPIO_STATUS)&(~((uint16_t)(0x1<<2)));
chaithanyarss 257:7d404e9dc9e2 445 //EPS_V_D_EN_STATUS
ee12b079 322:7d906d34aaff 446 GPIO_STATUS=(COM_TX_CNTRL)?(GPIO_STATUS)|((uint16_t)(0x1<<1)):(GPIO_STATUS)&(~((uint16_t)(0x1<<1)));
chaithanyarss 332:7d2431ce979f 447 // gPC.printf("%04x\n",GPIO_STATUS);
chaithanyarss 332:7d2431ce979f 448 gPC.printf("\n\rBAE_OC STATE = %04x",GPIO_STATUS);
ee12b079 210:f4acf895b598 449 }
ee12b079 210:f4acf895b598 450
ee12b079 210:f4acf895b598 451 void VERIFY_COMRX()
ee12b079 210:f4acf895b598 452 {
chaithanyarss 224:3ac1f91e0ebc 453 //COMRX_OC_FAULT //$
chaithanyarss 333:cddef120cae3 454 if(COMRX_OC_FAULT==0 && RSSI_VOLTAGE > 0.4) {
chaithanyarss 224:3ac1f91e0ebc 455 COMRX_STATUS = COMRX_ALIVE;
chaithanyarss 224:3ac1f91e0ebc 456 } else {
chaithanyarss 290:3159ff1081a2 457 //RESET_COMRX();
chaithanyarss 224:3ac1f91e0ebc 458 COMRX_RESET_COUNTER++;
chaithanyarss 333:cddef120cae3 459 if(COMRX_OC_FAULT==0 && RSSI_VOLTAGE > 0.4)
chaithanyarss 224:3ac1f91e0ebc 460 COMRX_STATUS = COMRX_ALIVE;
chaithanyarss 224:3ac1f91e0ebc 461 else
chaithanyarss 224:3ac1f91e0ebc 462 COMRX_STATUS = COMRX_DEAD;
chaithanyarss 224:3ac1f91e0ebc 463 }
ee12b079 210:f4acf895b598 464 }
ee12b079 210:f4acf895b598 465
chaithanyarss 224:3ac1f91e0ebc 466 void VERIFY_RTC()
chaithanyarss 224:3ac1f91e0ebc 467 {
chaithanyarss 332:7d2431ce979f 468 uint8_t response;
chaithanyarss 332:7d2431ce979f 469 if(EN_RTC == 0x00)
chaithanyarss 260:65e1ace927fd 470 return;
chaithanyarss 332:7d2431ce979f 471 gCS_RTC=1;
chaithanyarss 332:7d2431ce979f 472 gCS_RTC=0;
chaithanyarss 332:7d2431ce979f 473 spi.write(0x0F);
chaithanyarss 332:7d2431ce979f 474 response = spi.write(0x00);
chaithanyarss 332:7d2431ce979f 475 CDMS_RTC_BL = (response & 0x10) >>4;
chaithanyarss 332:7d2431ce979f 476 if(response & 0x04 == 0x04) {
chaithanyarss 332:7d2431ce979f 477 //RESET_RTC();
chaithanyarss 332:7d2431ce979f 478 RTC_STATUS = 0x01;
chaithanyarss 332:7d2431ce979f 479 RTC_FAULTCOUNT++;
chaithanyarss 332:7d2431ce979f 480 }
chaithanyarss 332:7d2431ce979f 481 gCS_RTC=1;
ee12b079 210:f4acf895b598 482 }
ee12b079 210:f4acf895b598 483
ee12b079 210:f4acf895b598 484 void HANDLE_HW_FAULTS()
ee12b079 210:f4acf895b598 485 {
chaithanyarss 224:3ac1f91e0ebc 486 HANDLE_HW_FAULT_SD();
chaithanyarss 224:3ac1f91e0ebc 487 HANDLE_HW_FAULT_BAE();
chaithanyarss 224:3ac1f91e0ebc 488 HANDLE_HW_FAULT_PL();
ee12b079 210:f4acf895b598 489 }
ee12b079 210:f4acf895b598 490
ee12b079 210:f4acf895b598 491 void HANDLE_HW_FAULT_SD()
ee12b079 210:f4acf895b598 492 {
chaithanyarss 224:3ac1f91e0ebc 493 if(SD_STATUS != DEVICE_DISABLED) {
chaithanyarss 332:7d2431ce979f 494 if(SD_STATUS == DEVICE_OC_FAULT) {
ee12b079 289:9bd62b69874c 495 gPC.printf("Switching on SD card");
samp1234 352:022c513aee03 496 SD_CARD_fromuC_ENA3 = 1;
samp1234 352:022c513aee03 497 SD_CARD_fromISO_ENA4 = 1;
ee12b079 289:9bd62b69874c 498 SD_SW_EN_DS = 1; //powering on SD
ee12b079 289:9bd62b69874c 499 wait_ms(10);
ee12b079 289:9bd62b69874c 500 }
chaithanyarss 332:7d2431ce979f 501
chaithanyarss 224:3ac1f91e0ebc 502 if(SD_OC_FAULT == 0) {
ee12b079 289:9bd62b69874c 503 gPC.printf("Switching off SD card");
samp1234 352:022c513aee03 504 SD_CARD_fromuC_ENA3 = 0;
samp1234 352:022c513aee03 505 SD_CARD_fromISO_ENA4 = 0;
ee12b079 289:9bd62b69874c 506 SD_SW_EN_DS = 0; //switching off SD card
chaithanyarss 224:3ac1f91e0ebc 507 SD_FAULTCOUNT++;
chaithanyarss 224:3ac1f91e0ebc 508 SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT;
chaithanyarss 332:7d2431ce979f 509 if(SD_FAULTCOUNT == 3) {
samp1234 354:eb6c863756a8 510 FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED);
ee12b079 289:9bd62b69874c 511 gPC.printf("Declaring SD card permanantly Disabled");
ee12b079 289:9bd62b69874c 512 }
chaithanyarss 224:3ac1f91e0ebc 513 } else {
chaithanyarss 224:3ac1f91e0ebc 514 SD_STATUS = DEVICE_POWERED;
ee12b079 289:9bd62b69874c 515 if(SD_STATUS != DEVICE_POWERED)
samp1234 354:eb6c863756a8 516 FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED);
chaithanyarss 224:3ac1f91e0ebc 517 SD_FAULTCOUNT = 0;
chaithanyarss 224:3ac1f91e0ebc 518 }
ee12b079 210:f4acf895b598 519 }
ee12b079 210:f4acf895b598 520 }
ee12b079 210:f4acf895b598 521
ee12b079 210:f4acf895b598 522 void HANDLE_HW_FAULT_BAE()
ee12b079 210:f4acf895b598 523 {
chaithanyarss 224:3ac1f91e0ebc 524 if(BAE_STATUS != DEVICE_DISABLED) {
chaithanyarss 332:7d2431ce979f 525 if(BAE_STATUS == DEVICE_OC_FAULT) {
ee12b079 289:9bd62b69874c 526 gPC.printf("Switching on BAE");
ee12b079 289:9bd62b69874c 527 BAE_SW_EN_DS = 1; //Power ON BAE
ee12b079 289:9bd62b69874c 528 wait_ms(10);
ee12b079 289:9bd62b69874c 529 }
chaithanyarss 332:7d2431ce979f 530
ee12b079 289:9bd62b69874c 531 if(BAE_OC_FAULT == 0) {
ee12b079 289:9bd62b69874c 532 gPC.printf("Switching off BAE");
ee12b079 289:9bd62b69874c 533 BAE_SW_EN_DS = 0; //Switch OFF BAE
chaithanyarss 224:3ac1f91e0ebc 534 BAE_FAULTCOUNT++;
chaithanyarss 224:3ac1f91e0ebc 535 BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
chaithanyarss 332:7d2431ce979f 536 if(BAE_FAULTCOUNT == 3) {
samp1234 354:eb6c863756a8 537 FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED);
ee12b079 289:9bd62b69874c 538 gPC.printf("Declaring BAE permanantly Disabled");
ee12b079 289:9bd62b69874c 539 }
chaithanyarss 224:3ac1f91e0ebc 540 } else {
chaithanyarss 224:3ac1f91e0ebc 541 BAE_STATUS = DEVICE_POWERED;
ee12b079 289:9bd62b69874c 542 if(SD_STATUS != DEVICE_POWERED);
samp1234 354:eb6c863756a8 543 FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED);
chaithanyarss 224:3ac1f91e0ebc 544 BAE_FAULTCOUNT = 0;
chaithanyarss 224:3ac1f91e0ebc 545 }
ee12b079 210:f4acf895b598 546 }
ee12b079 210:f4acf895b598 547 }
ee12b079 210:f4acf895b598 548
ee12b079 210:f4acf895b598 549 void HANDLE_HW_FAULT_PL()
ee12b079 210:f4acf895b598 550 {
chaithanyarss 224:3ac1f91e0ebc 551 if(PL_STATUS != DEVICE_DISABLED) {
chaithanyarss 332:7d2431ce979f 552 if(PL_STATUS == DEVICE_OC_FAULT) {
ee12b079 289:9bd62b69874c 553 gPC.printf("Switching on PL_BEE");
ee12b079 245:da9d1bd999da 554 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 555 PYLD_DFF = 1; // Switching ON PL
ee12b079 245:da9d1bd999da 556 wait_us(1);
ee12b079 245:da9d1bd999da 557 PYLD_DFF_CLK = 1;
ee12b079 245:da9d1bd999da 558 wait_us(1);
ee12b079 245:da9d1bd999da 559 PYLD_DFF_CLK = 0;
chaithanyarss 332:7d2431ce979f 560 wait_us(1);
ee12b079 245:da9d1bd999da 561 }
chaithanyarss 224:3ac1f91e0ebc 562 if(PL_BEE_SW_OC_FAULT == 0) { // if OC Fault
ee12b079 289:9bd62b69874c 563 gPC.printf("Switching off PL_BEE");
chaithanyarss 332:7d2431ce979f 564 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 565 PYLD_DFF = 0; //Switching OFF PL
ee12b079 245:da9d1bd999da 566 wait_us(1);
ee12b079 245:da9d1bd999da 567 PYLD_DFF_CLK = 1;
ee12b079 245:da9d1bd999da 568 wait_us(1);
ee12b079 245:da9d1bd999da 569 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 570 wait_us(1);
chaithanyarss 224:3ac1f91e0ebc 571 PL_FAULTCOUNT++;
chaithanyarss 224:3ac1f91e0ebc 572 PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
chaithanyarss 332:7d2431ce979f 573 if(PL_FAULTCOUNT == 3) {
samp1234 354:eb6c863756a8 574 FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED);
ee12b079 289:9bd62b69874c 575 gPC.printf("Declaring PL_BEE permanantly Disabled");
ee12b079 289:9bd62b69874c 576 }
chaithanyarss 224:3ac1f91e0ebc 577 } else {
chaithanyarss 332:7d2431ce979f 578 if(PL_STATUS == DEVICE_OC_FAULT) {
ee12b079 289:9bd62b69874c 579 gPC.printf("Switching off PL_BEE");
chaithanyarss 332:7d2431ce979f 580 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 581 PYLD_DFF = 0; //Switching OFF PL
ee12b079 245:da9d1bd999da 582 wait_us(1);
ee12b079 245:da9d1bd999da 583 PYLD_DFF_CLK = 1;
ee12b079 245:da9d1bd999da 584 wait_us(1);
ee12b079 245:da9d1bd999da 585 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 586 wait_us(1);
ee12b079 245:da9d1bd999da 587 }
chaithanyarss 224:3ac1f91e0ebc 588 PL_STATUS = DEVICE_ENABLED;
ee12b079 289:9bd62b69874c 589 if(PL_STATUS != DEVICE_ENABLED)
samp1234 354:eb6c863756a8 590 FCTN_CDMS_WR_FLASH(3,DEVICE_ENABLED);
chaithanyarss 224:3ac1f91e0ebc 591 PL_FAULTCOUNT = 0;
chaithanyarss 224:3ac1f91e0ebc 592 }
ee12b079 210:f4acf895b598 593 }
ee12b079 210:f4acf895b598 594 }
chaithanyarss 224:3ac1f91e0ebc 595
ee12b079 210:f4acf895b598 596 void COLLECT_CDMS_RAM()
chaithanyarss 224:3ac1f91e0ebc 597 {
chaithanyarss 303:b49b486a7107 598 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 332:7d2431ce979f 599
chaithanyarss 332:7d2431ce979f 600 CDMS_RAM[1] = ( (PL_RCV_SC_DATA_STATUS<<7) & 0x80 )|
chaithanyarss 332:7d2431ce979f 601 ( ((gFLAGS & COM_SESSION_FLAG)<<3) & 0x40 )|
chaithanyarss 332:7d2431ce979f 602 ( ((gFLAGS & COM_RX_FLAG)<<1) & 0x20 )|
chaithanyarss 332:7d2431ce979f 603 ( ((gFLAGS & RF_SW_STATUS_FLAG)>>8)&0x10 )|
chaithanyarss 332:7d2431ce979f 604 ( ((gFLAGS & COM_TX_FLAG)>>5)&0x08 )|
chaithanyarss 332:7d2431ce979f 605 ( (COM_TX_STATUS<<2)&0x04 )|
chaithanyarss 332:7d2431ce979f 606 ( ((gFLAGS & COM_MNG_TMTC_RUNNING_FLAG)>>3) & 0x02 )|
chaithanyarss 332:7d2431ce979f 607 (EN_CDMS_HK&0x01);
chaithanyarss 332:7d2431ce979f 608 CDMS_RAM[2] = ((EN_PL<<7)&0x80)|((EN_RCV_SC<<6)&0x40)|
chaithanyarss 332:7d2431ce979f 609 ((CDMS_INIT_STATUS<<5)&0x20)|
chaithanyarss 332:7d2431ce979f 610 ((CDMS_HK_MAIN_STATUS<<4)&0x10)|
chaithanyarss 332:7d2431ce979f 611 ((CDMS_HK_STATUS<<2)&0x0C)|
chaithanyarss 332:7d2431ce979f 612 ((COM_RX_STATUS<<1)&0x02)|
chaithanyarss 332:7d2431ce979f 613 (CDMS_RTC_BL&0x01);
chaithanyarss 257:7d404e9dc9e2 614 CDMS_RAM[3] = CDMS_I2C_ERR_SPEED_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 615 CDMS_RAM[4] = CDMS_I2C_ERR_SPEED_COUNTER;
chaithanyarss 257:7d404e9dc9e2 616 CDMS_RAM[5] = CDMS_I2C_ERR_BAE_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 617 CDMS_RAM[6] = CDMS_I2C_ERR_BAE_COUNTER;
chaithanyarss 257:7d404e9dc9e2 618 CDMS_RAM[7] = CDMS_HK_MAIN_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 619 CDMS_RAM[8] = CDMS_HK_MAIN_COUNTER;
chaithanyarss 257:7d404e9dc9e2 620 CDMS_RAM[9] = PL_MAIN_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 621 CDMS_RAM[10] = PL_MAIN_COUNTER;
chaithanyarss 257:7d404e9dc9e2 622 CDMS_RAM[11] = PL_RCV_SC_DATA_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 623 CDMS_RAM[12] = PL_RCV_SC_DATA_COUNTER;
chaithanyarss 257:7d404e9dc9e2 624 CDMS_RAM[13] = COMRX_RESET_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 625 CDMS_RAM[14] = COMRX_RESET_COUNTER;
chaithanyarss 257:7d404e9dc9e2 626 CDMS_RAM[15] = CDMS_WR_SD_FAULT_COUNTER >> 8;
chaithanyarss 257:7d404e9dc9e2 627 CDMS_RAM[16] = CDMS_WR_SD_FAULT_COUNTER;
chaithanyarss 257:7d404e9dc9e2 628 CDMS_RAM[17] = SD_LIB_WRITES >> 8;
chaithanyarss 257:7d404e9dc9e2 629 CDMS_RAM[18] = SD_LIB_WRITES;
spacelab 313:5d06a08baf0e 630 TIME_LATEST_RTC= FCTN_CDMS_RD_RTC() >> 7; // added by samp
chaithanyarss 257:7d404e9dc9e2 631 for(int i = 0; i<4; i++)
chaithanyarss 332:7d2431ce979f 632 CDMS_RAM[19+i] = TIME_LATEST_RTC >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 633 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 634 CDMS_RAM[23+i] = TIME_LATEST_I2C_BAE >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 635 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 636 CDMS_RAM[27+i] = TIME_LATEST_I2C_SPEED >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 637 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 638 CDMS_RAM[31+i] = TIME_LATEST_SD_WR >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 639 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 640 CDMS_RAM[35+i] = TIME_LATEST_SD_RD >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 641 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 642 CDMS_RAM[39+i] = TIME_LATEST_SPI_SPEED >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 643 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 644 CDMS_RAM[43+i] = FSC_CURRENT[1] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 645 for(int i = 0; i<4; i++)
chaithanyarss 327:5a967a66c10f 646 CDMS_RAM[47+i] = FSC_OLD[1] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 647 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 648 CDMS_RAM[51+i] = FSC_CURRENT[2] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 649 for(int i = 0; i<4; i++)
chaithanyarss 327:5a967a66c10f 650 CDMS_RAM[55+i] = FSC_OLD[2] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 651 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 652 CDMS_RAM[59+i] = FSC_CURRENT[3] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 653 for(int i = 0; i<4; i++)
chaithanyarss 327:5a967a66c10f 654 CDMS_RAM[63+i] = FSC_OLD[3] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 655 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 656 CDMS_RAM[67+i] = FSC_CURRENT[4] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 657 for(int i = 0; i<4; i++)
chaithanyarss 327:5a967a66c10f 658 CDMS_RAM[71+i] = FSC_OLD[4] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 659 for(int i = 0; i<4; i++)
chaithanyarss 303:b49b486a7107 660 CDMS_RAM[75+i] = FSC_CURRENT[5] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 661 for(int i = 0; i<4; i++)
chaithanyarss 327:5a967a66c10f 662 CDMS_RAM[79+i] = FSC_OLD[5] >> (3-i)*8;
chaithanyarss 257:7d404e9dc9e2 663 CDMS_RAM[83] = 0x00;
samp1234 348:8e6b2b4d244e 664 gPC.printf("\n\r%u %u %u %u %u",FSC_CURRENT[1],FSC_CURRENT[2],FSC_CURRENT[3],FSC_CURRENT[4],FSC_CURRENT[5]);
shreeshas95 103:b55559925dc1 665 }