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