Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Committer:
chaithanyarss
Date:
Sat Jan 07 01:35:54 2017 +0000
Revision:
340:d05e7b4b6690
Parent:
339:5c4bda268e08
Reverting changes to 326 version

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