To fix the hang problem
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: CDMS_HK.h
- Revision:
- 289:9bd62b69874c
- Parent:
- 271:72529b247333
- Child:
- 290:3159ff1081a2
--- a/CDMS_HK.h Fri Aug 05 17:13:23 2016 +0000 +++ b/CDMS_HK.h Sat Aug 06 06:34:38 2016 +0000 @@ -11,6 +11,8 @@ void minMaxHkData(); void COLLECT_CDMS_RAM(); +extern uint8_t beacon_array[134]; + AnalogIn TempInput(PIN27); // Input from Current Multiplexer AnalogIn CDMS_temp_sensor(PIN53); AnalogIn COMRX_RSSI_volatge(PIN70); @@ -38,22 +40,35 @@ void FCTN_CDMS_HK_MAIN(void const *args) { uint8_t sd_stat = 0; + uint8_t hk_count=0; while(1) { gHK_THREAD->signal_wait(HK_SIGNAL); + gMutex.lock(); + if(hk_count == 1 || hk_count == 2) + { + FCTN_CDMS_PL_MAIN((void const *)NULL); + hk_count--; + continue; + } + else if(hk_count == 0) + { + FCTN_CDMS_PL_MAIN((void const *)NULL); + hk_count = 2; + } gPC.printf("\n\nEntering HK thread\n"); - gMutex.lock(); - + if(EN_CDMS_HK == 0x00) + continue; 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(); - FUNC_CDMS_GPIO_STATUS(); //yet to be done + FUNC_CDMS_GPIO_STATUS(); uint8_t CDMS_quant[20]; CDMS_quant[1]= (uint8_t)quant_data.CDMS_temp_quant; @@ -71,12 +86,30 @@ for(int i = 0;i<20;i++) //Collecting Data from Temp sensors CDMS_HEALTH_DATA[86+i] = CDMS_quant[i]; - // Here: Have to FIT flash data. + // Here: Have to FIT flash data. + 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; + CDMS_HEALTH_DATA[110] = TIME_LATEST_CDSMS_RESET >>24; + CDMS_HEALTH_DATA[111] = TIME_LATEST_CDSMS_RESET >>16; + CDMS_HEALTH_DATA[112] = TIME_LATEST_CDSMS_RESET >>8; + CDMS_HEALTH_DATA[113] = TIME_LATEST_CDSMS_RESET; + CDMS_HEALTH_DATA[114] = COM_TC_BYTES_LIMIT>>8; + CDMS_HEALTH_DATA[115] = COM_TC_BYTES_LIMIT; + CDMS_HEALTH_DATA[116] = COM_RX_CURRENT_MAX; + CDMS_HEALTH_DATA[117] = COM_RX_DISABLE_TIMEOUT; + CDMS_HEALTH_DATA[118] = COM_PA_TMP_HIGH; + CDMS_HEALTH_DATA[119] = COM_PA_RECOVERY_TIMEOUT; + CDMS_HEALTH_DATA[120] = COM_SESSION_TIMEOUT; + CDMS_HEALTH_DATA[121] = COM_RSSI_MIN; + CDMS_HEALTH_DATA[122] = SD_LIB_BLK_CURRENT>>8; + CDMS_HEALTH_DATA[122] = SD_LIB_BLK_CURRENT; 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; @@ -104,15 +137,16 @@ gPC.puts("sd write failure"); break; } - /*gPC.printf("Completed CDMS HK\t")*/; + gPC.printf("Completed CDMS HK\t"); /*---------------------------------- BAE HK --------------------------------------------*/ BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134); - /*gPC.printf("Entering BAE HK\t")*/; + gPC.printf("Entering BAE HK\t"); if(BAE_HK_I2C == 0) { crc = crc16_gen((unsigned char *)BAE_HK,132); if(crc == ((uint16_t)BAE_HK[132] << 8) | (uint16_t)BAE_HK[133]){ + gPC.printf("BAE HK data recieved through I2C\t"); TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7; /*for(int i = 0; i<15; i++) gPC.printf("\r 0x%02X\n",BAE_HK[i]);*/ @@ -143,28 +177,51 @@ } } else { - /*gPC.printf("BAE HK data not recieved through I2C\t")*/; + gPC.printf("BAE HK data not recieved through I2C\t"); for(int i = 0; i<134; i++) BAE_HK[i] = 0; } - /*gPC.printf("Completed BAE HK\n")*/; + gPC.printf("Completed BAE HK\n"); /*----------------------------------Beacon message--------------------------------------*/ - unsigned char SC_HK_LBM_0[135]; - SC_HK_LBM_0[0] = 0; // Sending long beacon msg as telecommand with Packet sequence count 0x00 + + // Add HK bits - + beacon_array[0] = 0x00; + beacon_array[1] = time >> 32; + beacon_array[2] = time >> 24; + beacon_array[3] = time >> 16; + beacon_array[4] = time >> 8; + beacon_array[5] = time; + beacon_array[6] = SD_FAULTCOUNT >> 8; + beacon_array[7] = SD_FAULTCOUNT; + beacon_array[8] = RTC_FAULTCOUNT >> 8; + beacon_array[9] = RTC_FAULTCOUNT; + 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)|(COMTX_OC_FAULT); + beacon_array[11] = (COM_RX_CNTRL <<7)|(COM_TX_CNTRL); + beacon_array[12] = CDMS_HK_MAIN_COUNTER >>8; + beacon_array[13] = CDMS_HK_MAIN_COUNTER; + beacon_array[14] = PL_MAIN_COUNTER >>8; + beacon_array[15] = PL_MAIN_COUNTER; + beacon_array[16] = PL_RCV_SC_DATA_COUNTER >>8; + beacon_array[17] = PL_RCV_SC_DATA_COUNTER; + beacon_array[18] = TIME_LATEST_SPI_SPEED >>24; + beacon_array[19] = TIME_LATEST_SPI_SPEED >>16; + beacon_array[20] = TIME_LATEST_SPI_SPEED >>8; + beacon_array[21] = TIME_LATEST_SPI_SPEED; + beacon_array[22] = (uint8_t)RSSI_volatge; + // Add SC bits - crc = crc16_gen(SC_HK_LBM_0,133); - SC_HK_LBM_0[132] = crc; - SC_HK_LBM_0[133] = crc >> 8; + crc = crc16_gen(beacon_array,132); + beacon_array[132] = crc; + beacon_array[133] = crc >> 8; bool y; - y = FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135); + y = FCTN_I2C_WRITE((char *)beacon_array,134); if(y == 0) - /*gPC.printf("long Bcn sent\n\r")*/; + gPC.printf("long Bcn sent\n\r"); else gPC.printf("long Bcn not sent\r\n"); - gPC.printf("\rCompleted HK\n"); + gPC.printf("\rCompleted Beacon\n"); gMutex.unlock(); } } @@ -213,6 +270,7 @@ { int Iteration=0; + int resistance; SelectLinec0=0; SelectLinec1=0; @@ -237,11 +295,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 { @@ -293,21 +349,21 @@ //PL_EPS_LATCH_SW_OC_FAULT // to be verified GPIO_STATUS=(PL_EPS_LATCH_SW_OC_FAULT)?(GPIO_STATUS)||((uint16_t)(0x1<<4)):(GPIO_STATUS)&(~((uint16_t)(0x1<<4))); //EPS_V_C_EN_STATUS - GPIO_STATUS=(EPS_V_C_EN_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<3)):(GPIO_STATUS)&(~((uint16_t)(0x1<<3))); + GPIO_STATUS=(COM_RX_CNTRL)?(GPIO_STATUS)||((uint16_t)(0x1<<3)):(GPIO_STATUS)&(~((uint16_t)(0x1<<3))); //EPS_V_D_EN_STATUS - GPIO_STATUS=(EPS_V_D_EN_STATUS)?(GPIO_STATUS)||((uint16_t)(0x1<<2)):(GPIO_STATUS)&(~((uint16_t)(0x1<<2))); + GPIO_STATUS=(COM_TX_CNTRL)?(GPIO_STATUS)||((uint16_t)(0x1<<2)):(GPIO_STATUS)&(~((uint16_t)(0x1<<2))); } 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; @@ -316,21 +372,20 @@ void VERIFY_RTC() { - if(RTC_STATUS == 0x00) { - if(RTC_FAULTCOUNT == 3) + uint8_t response; + if(EN_RTC == 0x00) return; - SPI_mutex.lock(); gCS_RTC=1; gCS_RTC=0; spi.write(0x0F); - if(spi.write(0x00) & 0x04 == 0x04) { - RTC_STATUS = 0x00; + response = spi.write(0x00); + CDMS_RTC_BL = (response & 0x10) >>4; + if(response & 0x04 == 0x04) { RESET_RTC(); + RTC_STATUS = 0x01; RTC_FAULTCOUNT++; } gCS_RTC=1; - SPI_mutex.unlock(); - } } void HANDLE_HW_FAULTS() @@ -343,16 +398,25 @@ void HANDLE_HW_FAULT_SD() { if(SD_STATUS != DEVICE_DISABLED) { - if(SD_STATUS == DEVICE_OC_FAULT) - SD_SW_EN_DS = 0; //powering on SD - + 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) { - SD_SW_EN_DS = 1; //switching off SD card - + 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; } } @@ -361,15 +425,25 @@ void HANDLE_HW_FAULT_BAE() { if(BAE_STATUS != DEVICE_DISABLED) { - if(BAE_STATUS == DEVICE_OC_FAULT) - BAE_SW_EN_DS = 0; //Power ON BAE - - if(BAE_OC_FAULT == 0) { // If OC Fault - BAE_SW_EN_DS = 1; //Switch OFF BAE + if(BAE_STATUS == DEVICE_OC_FAULT){ + gPC.printf("Switching on BAE"); + BAE_SW_EN_DS = 1; //Power ON BAE + 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; } } @@ -379,6 +453,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); @@ -388,6 +463,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); @@ -397,8 +473,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); @@ -408,6 +489,8 @@ wait_us(1); } PL_STATUS = DEVICE_ENABLED; + if(PL_STATUS != DEVICE_ENABLED) + FCTN_CDMS_WR_FLASH(3,DEVICE_ENABLED); PL_FAULTCOUNT = 0; } }