To fix the hang problem
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: CDMS_HK.h
- Revision:
- 279:9501ee30957d
- Parent:
- 271:72529b247333
- Child:
- 280:5e2f8e06f01f
--- a/CDMS_HK.h Wed Jul 27 10:42:35 2016 +0000 +++ b/CDMS_HK.h Wed Jul 27 11:29:24 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,13 +40,26 @@ void FCTN_CDMS_HK_MAIN(void const *args) { uint8_t sd_stat = 0; + uint8_t count; while(1) { gHK_THREAD->signal_wait(HK_SIGNAL); + if(count == 1 || count == 2) + { + FCTN_CDMS_PL_MAIN((void const *)NULL); + count--; + continue; + } + else if(count == 0) + { + FCTN_CDMS_PL_MAIN((void const *)NULL); + 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++; @@ -53,7 +68,7 @@ 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,7 +86,25 @@ 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_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[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++) @@ -104,12 +137,12 @@ 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]){ @@ -143,28 +176,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] = (EPS_V_C_EN_STATUS <<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(); } } @@ -295,7 +351,7 @@ //EPS_V_C_EN_STATUS GPIO_STATUS=(EPS_V_C_EN_STATUS)?(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))); } @@ -316,21 +372,17 @@ void VERIFY_RTC() { - if(RTC_STATUS == 0x00) { - if(RTC_FAULTCOUNT == 3) - return; SPI_mutex.lock(); gCS_RTC=1; gCS_RTC=0; spi.write(0x0F); if(spi.write(0x00) & 0x04 == 0x04) { - RTC_STATUS = 0x00; + RTC_STATUS = 0x01; RESET_RTC(); RTC_FAULTCOUNT++; } gCS_RTC=1; SPI_mutex.unlock(); - } } void HANDLE_HW_FAULTS()