To fix the hang problem
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: CDMS_HK.h
- Revision:
- 207:28a07943dded
- Parent:
- 206:fba4aeebf004
--- a/CDMS_HK.h Thu Jun 30 14:00:33 2016 +0000 +++ b/CDMS_HK.h Sat Jul 02 10:48:30 2016 +0000 @@ -1,19 +1,23 @@ -#include "cdms_rtc.h" -#include "pinconfig.h" -#include "reset_functions.h" -#include "DefinitionsAndGlobals.h" -#include "COM_SND_TM_functions.h" -#include "COM_SND_TM_functions.h" + +//CDMS HK + #define COMRX_ALIVE 0xFF + #define COMRX_DEAD 0x00 + #define DEVICE_ENABLED 0x00 + #define DEVICE_POWERED 0x01 + #define DEVICE_OC_FAULT 0x02 + #define DEVICE_DISABLED 0x03 void FCTN_CDMS_HK_MAIN(); void FCTN_CDMS_HK(); void VERIFY_COMRX(); void VERIFY_RTC(); void CDMS_HK_SD(); -void CDMS_HW_FAULTS(); +void HANDLE_HW_FAULTS(); void HANDLE_HW_FAULT_SD(); void HANDLE_HW_FAULT_BAE(); void HANDLE_HW_FAULT_PL(); +void FUNC_CDMS_GPIO_STATUS(); +void minMaxHkData(); void COLLECT_CDMS_RAM(); Serial hk_cdms(USBTX, USBRX); @@ -22,26 +26,6 @@ AnalogIn CDMS_temp_sensor(PIN53); AnalogIn COMRX_RSSI_volatge(PIN70); -DigitalIn SD_OC_FAULT (PIN90); -DigitalOut SD_SW_EN_DS (PIN97); -DigitalOut BAE_SW_EN_DS (PIN47); -DigitalOut PL_SW_EN_DS (PIN73); - -//GPIO PINS -DigitalIn V_A_PGOOD (PIN88); -DigitalIn V_B_PGOOD_1 (PIN6); -DigitalIn V_B_PGOOD_2 (PIN7); -DigitalIn V_C_PGOOD (PIN54); -DigitalIn COMRX_OC_FAULT (PIN68); -DigitalIn COMTX_OC_FAULT (PIN69); -DigitalIn BAE_OC_FAULT (PIN92); -DigitalIn PL_GPIO_1_STATUS (PIN71); -DigitalIn PL_GPIO_2_STATUS (PIN81); -DigitalIn PL_GPIO_3_STATUS (PIN80); -DigitalIn PL_BEE_SW_OC_FAULT (PIN4); -DigitalIn PL_EPS_LATCH_SW_OC_FAULT (); -DigitalIn V_C_EN_STATUS (); -DigitalIn V_D_EN_STATUS (); DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines DigitalOut SelectLinec2 (PIN78); @@ -51,7 +35,6 @@ void FCTN_CDMS_HK_MAIN(void const *args) { - uint8_t CDMS_HEALTH_DATA[128] = {0}; unsigned char CDMS_HK_FRAME[134] = {0}; char BAE_HK[128] = {0}; uint8_t convoluted_CDMS_HK[270]; @@ -79,13 +62,13 @@ } CDMS_quant[16]= (uint8_t)RSSI_volatge; CDMS_quant[17]= (uint8_t)quant_data.CDMS_temp_quant; - + minMaxHkData(); uint64_t time = FCTN_CDMS_RD_RTC(); //Reading Time from RTC time = time>>7; uint32_t HK_time = (uint32_t)time; for(int i = 0;i<4;i++) - CDMS_HEALTH_DATA[i] = HK_time[i]; + CDMS_HEALTH_DATA[i] = HK_time >> i; // Here: Have to FIT flash data. for(int i = 0;i<19;i++) //Collecting Data from Temp sensors @@ -124,9 +107,10 @@ /*---------------------------------- BAE HK --------------------------------------------*/ + BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134); if(BAE_HK_I2C == 0){ - TIME_LATEST_I2C_SPEED = FCTN_CDMS_RD_RTC() >> 7; + TIME_LATEST_I2C_BAE = FCTN_CDMS_RD_RTC() >> 7; hk_cdms.printf("Bae hk data received"); } else @@ -135,7 +119,7 @@ BAE_HK[i] = 0; } for(int i = 0;i<4;i++) - BAE_HK[i] = HK_time[i]; + BAE_HK[i] = HK_time >> i; BAE_HK_FRAME[0] = 0x28; BAE_HK_FRAME[1] = FSC_CURRENT[5]+1; BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8; @@ -153,6 +137,17 @@ BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i]; SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5); hk_cdms.printf("BAE hk succesfully completed\r\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 + + // Add SC bits + crc = crc16_gen(SC_HK_LBM_0,133); + SC_HK_LBM_0[132] = crc; + SC_HK_LBM_0[133] = crc >> 8; + FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135); } int quantiz(float start,float step,float x) @@ -163,12 +158,12 @@ return y; } -void saveMin(char x,char y) +char saveMin(char x,char y) { return (y<x)?y:x; } -void saveMax(char x,char y) +char saveMax(char x,char y) { return (y>x)?y:x; } @@ -216,7 +211,7 @@ SelectLinec1=!(SelectLinec1); if(Iteration%4==3) SelectLinec2=!(SelectLinec2); - if(Iteration%8==7) [0] + if(Iteration%8==7) SelectLinec3=!(SelectLinec3); } @@ -291,7 +286,9 @@ { //COMRX_OC_FAULT //$ if(PIN68==0 && RSSI_volatge > 0.4) + { COMRX_STATUS = COMRX_ALIVE; + } else { RESET_COMRX(); @@ -305,7 +302,7 @@ void VERIFY_RTC(){ - if(RTC_STATUS = 0x00) + if(RTC_STATUS == 0x00) { SPI_mutex.lock(); gCS_RTC=1; @@ -313,7 +310,7 @@ spi.write(0x0F); if(spi.write(0x00) & 0x04 == 0x04) { - RTC_STATUS = Not_started; + RTC_STATUS = 0x00; RESET_RTC(); RTC_FAULTCOUNT++; } @@ -326,14 +323,14 @@ { HANDLE_HW_FAULT_SD(); HANDLE_HW_FAULT_BAE(); - HANDLE_HW_FAULT_PL() + HANDLE_HW_FAULT_PL(); } void HANDLE_HW_FAULT_SD() { if(SD_STATUS != DEVICE_DISABLED) { - if(SD_STATUS = DEVICE_OC_FAULT) + if(SD_STATUS == DEVICE_OC_FAULT) SD_SW_EN_DS = 0; //powering on SD if(SD_OC_FAULT == 0) @@ -341,7 +338,7 @@ SD_SW_EN_DS = 1; //switching off SD card SD_FAULTCOUNT++; - SD_STATUS = (SD_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT; + SD_STATUS = (SD_FAULTCOUNT == 3) ? DEVICE_DISABLED :DEVICE_OC_FAULT; } else { @@ -355,7 +352,7 @@ { if(BAE_STATUS != DEVICE_DISABLED) { - if(BAE_STATUS = DEVICE_OC_FAULT) + if(BAE_STATUS == DEVICE_OC_FAULT) BAE_SW_EN_DS = 0; //Power ON BAE if(BAE_OC_FAULT == 0) // If OC Fault @@ -376,7 +373,7 @@ { if(PL_STATUS != DEVICE_DISABLED) { - if(PL_STATUS = DEVICE_OC_FAULT) + if(PL_STATUS == DEVICE_OC_FAULT) PL_SW_EN_DS = 0; //Power ON PL if(PL_BEE_SW_OC_FAULT == 0) // if OC Fault @@ -393,10 +390,11 @@ PL_FAULTCOUNT = 0; } } +} void COLLECT_CDMS_RAM() { - /*--------------------Current FSC's---------------------*/\ + /*--------------------Current FSC's---------------------*/ for(int i=0;i<4;i++) CDMS_HEALTH_DATA[i+43] = FSC_LAST[5] >> (i*8); for(int i=0;i<4;i++)