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