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