To fix the hang problem
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: CDMS_HK.h
- Revision:
- 282:74a04dec4b95
- Parent:
- 281:d1c9ae3605a3
- Child:
- 283:5ea9ea429b55
--- a/CDMS_HK.h Wed Jul 27 12:14:58 2016 +0000 +++ b/CDMS_HK.h Sat Jul 30 15:25:21 2016 +0000 @@ -40,31 +40,31 @@ void FCTN_CDMS_HK_MAIN(void const *args) { uint8_t sd_stat = 0; - uint8_t count=0; + uint8_t hk_count=0; while(1) { gHK_THREAD->signal_wait(HK_SIGNAL); - if(count == 1 || count == 2) + gMutex.lock(); + if(hk_count == 1 || hk_count == 2) { FCTN_CDMS_PL_MAIN((void const *)NULL); - count--; + hk_count--; continue; } - else if(count == 0) + else if(hk_count == 0) { FCTN_CDMS_PL_MAIN((void const *)NULL); - count = 2; + hk_count = 2; } gPC.printf("\n\nEntering HK thread\n"); if(EN_CDMS_HK == 0x00) continue; - gMutex.lock(); CDMS_HK_MAIN_STATUS = 0x01; CDMS_HK_MAIN_COUNTER++; - FCTN_CDMS_HK(); - RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3; + FCTN_CDMS_HK();//collects temperatures + RSSI_volatge = COMRX_RSSI_volatge.read() * 3.3;//to be checked VERIFY_COMRX(); VERIFY_RTC(); HANDLE_HW_FAULTS(); @@ -87,7 +87,7 @@ CDMS_HEALTH_DATA[86+i] = CDMS_quant[i]; // Here: Have to FIT flash data. - CDMS_HEALTH_DATA[106] = (EPS_V_A_EN_STATUS<<7) | ((BAE_SW_STATUS<<5)&0x60) | ((CDMS_SD_SW_STATUS<<3)&0x18) | ((PL_BEE_SW_STATUS<<1)&0x06) | (PL_EPS_LATCH_SW_EN & 0x01); + 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); CDMS_HEALTH_DATA[107] = (RTC_INIT_STATUS<<6) | ((CDMS_RTC_DISABLE<<5)&0x20); CDMS_HEALTH_DATA[108] = CDMS_RESET_COUNTER >>8; CDMS_HEALTH_DATA[109] = CDMS_RESET_COUNTER; @@ -109,7 +109,7 @@ uint64_t time = FCTN_CDMS_RD_RTC() >> 7; //Reading Time from RTC for(int i = 124; i<128; i++) CDMS_HEALTH_DATA[i] = time >> i*8; - gPC.printf("0x%x\n",time); + gPC.printf("0x%d\n",time); FCTN_SD_MNGR(); //Adding FSC & TMID to TM frame CDMS_HK_FRAME[0] = 0x20; CDMS_HK_FRAME[1] = FSC_CURRENT[4]+1; @@ -269,6 +269,7 @@ { int Iteration=0; + int resistance; SelectLinec0=0; SelectLinec1=0; @@ -293,11 +294,9 @@ for(Iteration=0; Iteration<16; Iteration++) { if(Iteration<14) { - actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3; - int resistance; - resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]); + if(actual_data.temp_actual[Iteration]>1.47) { actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance); } else { @@ -358,12 +357,12 @@ void VERIFY_COMRX() { //COMRX_OC_FAULT //$ - if(PIN68==0 && RSSI_volatge > 0.4) { + if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4) { COMRX_STATUS = COMRX_ALIVE; } else { RESET_COMRX(); COMRX_RESET_COUNTER++; - if(PIN68==0 && RSSI_volatge > 0.4) + if(COMRX_OC_FAULT==0 && RSSI_volatge > 0.4) COMRX_STATUS = COMRX_ALIVE; else COMRX_STATUS = COMRX_DEAD; @@ -372,17 +371,20 @@ void VERIFY_RTC() { - SPI_mutex.lock(); + uint8_t response; + if(EN_RTC == 0x00) + return; gCS_RTC=1; gCS_RTC=0; spi.write(0x0F); - if(spi.write(0x00) & 0x04 == 0x04) { + response = spi.write(0x00); + CDMS_RTC_BL = (response & 0x10) >>4; + if(response & 0x04 == 0x04) { + RESET_RTC(); RTC_STATUS = 0x01; - RESET_RTC(); RTC_FAULTCOUNT++; } gCS_RTC=1; - SPI_mutex.unlock(); } void HANDLE_HW_FAULTS() @@ -395,16 +397,25 @@ void HANDLE_HW_FAULT_SD() { if(SD_STATUS != DEVICE_DISABLED) { - if(SD_STATUS == DEVICE_OC_FAULT) + if(SD_STATUS == DEVICE_OC_FAULT){ + gPC.printf("Switching on SD card"); SD_SW_EN_DS = 1; //powering on SD - + wait_ms(10); + } + if(SD_OC_FAULT == 0) { + gPC.printf("Switching off SD card"); SD_SW_EN_DS = 0; //switching off SD card - SD_FAULTCOUNT++; SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT; + if(SD_FAULTCOUNT == 3){ + FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED); + gPC.printf("Declaring SD card permanantly Disabled"); + } } else { SD_STATUS = DEVICE_POWERED; + if(SD_STATUS != DEVICE_POWERED) + FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED); SD_FAULTCOUNT = 0; } } @@ -413,15 +424,25 @@ void HANDLE_HW_FAULT_BAE() { if(BAE_STATUS != DEVICE_DISABLED) { - if(BAE_STATUS == DEVICE_OC_FAULT) + if(BAE_STATUS == DEVICE_OC_FAULT){ + gPC.printf("Switching on BAE"); BAE_SW_EN_DS = 1; //Power ON BAE - - if(BAE_OC_FAULT == 0) { // If OC Fault + wait_ms(10); + } + + if(BAE_OC_FAULT == 0) { + gPC.printf("Switching off BAE"); BAE_SW_EN_DS = 0; //Switch OFF BAE BAE_FAULTCOUNT++; BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT; + if(BAE_FAULTCOUNT == 3){ + FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED); + gPC.printf("Declaring BAE permanantly Disabled"); + } } else { BAE_STATUS = DEVICE_POWERED; + if(SD_STATUS != DEVICE_POWERED); + FCTN_CDMS_WR_FLASH(1,DEVICE_POWERED); BAE_FAULTCOUNT = 0; } } @@ -431,6 +452,7 @@ { if(PL_STATUS != DEVICE_DISABLED) { if(PL_STATUS == DEVICE_OC_FAULT){ + gPC.printf("Switching on PL_BEE"); PYLD_DFF_CLK = 0; PYLD_DFF = 1; // Switching ON PL wait_us(1); @@ -440,6 +462,7 @@ wait_us(1); } if(PL_BEE_SW_OC_FAULT == 0) { // if OC Fault + gPC.printf("Switching off PL_BEE"); PYLD_DFF_CLK = 0; PYLD_DFF = 0; //Switching OFF PL wait_us(1); @@ -449,8 +472,13 @@ wait_us(1); PL_FAULTCOUNT++; PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT; + if(PL_FAULTCOUNT == 3){ + FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED); + gPC.printf("Declaring PL_BEE permanantly Disabled"); + } } else { if(PL_STATUS == DEVICE_OC_FAULT){ + gPC.printf("Switching off PL_BEE"); PYLD_DFF_CLK = 0; PYLD_DFF = 0; //Switching OFF PL wait_us(1); @@ -460,6 +488,8 @@ wait_us(1); } PL_STATUS = DEVICE_ENABLED; + if(PL_STATUS != DEVICE_ENABLED) + FCTN_CDMS_WR_FLASH(3,DEVICE_ENABLED); PL_FAULTCOUNT = 0; } }