![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CDMS_CODE_samp_23SEP_DMA_flag
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA by
DefinitionsAndGlobals.h
- Committer:
- chaithanyarss
- Date:
- 2016-09-05
- Revision:
- 297:7cc868888d56
- Parent:
- 295:699801854b71
- Child:
- 298:5d3958886809
File content as of revision 297:7cc868888d56:
///639+................................++.300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002025555. // **************DEFINITIONS********************* #define dma 0 // COM_RX #define RX_TIMEOUT_LIMIT 0.5 #define COM_RX_UART_TX PTE20 // For bypassing RX1M (SET BAUD RATE 1200) #define COM_RX_UART_TX USBTX #define COM_RX_UART_RX PTE21 // For bypassing RX1M (SET BAUD RATE 1200) #define COM_RX_UART_RX USBRX //#define COM_RX_UART_TX USBTX //#define COM_RX_UART_RX USBRX // COMMON SPI #define SPI_MOSI PTE1 #define SPI_MISO PTE3 #define SPI_CLK PTE2 #define SPI_CS_ADF PTA15 #define SPI_CS_SDC PIN20 //#define SPI_CS_RTC PIN26 #define SPI_CS_RTC PIN60 // COM_TX #define COM_TX_CONFIG_LIMIT 3 #define COM_TX_TICKER_LIMIT 32 // ADF INTERRUPT #define ADF_IRQ PTA14 //I2C - Payload to CDMS (need to change while using CDMS hardware); I2C master(PIN32,PIN31); DigitalIn PL_I2C_Intr(PTC13); DigitalOut PL_I2C_GPIO(PTC1); //I2C - CDMS to BAE //DigitalIn BAE_I2C_GPIO(PIN67);//PTB21 from bae to cdms //DigitalOut CDMS_I2C_GPIO(PIN39);//PTA5 from cdms to bae #define SBC 1 #if SBC DigitalOut CDMS_I2C_GPIO(PIN67,0); DigitalIn BAE_I2C_GPIO(PIN1); #endif #if !SBC DigitalIn BAE_I2C_GPIO(PIN67); DigitalOut CDMS_I2C_GPIO(PIN39,0); #endif // TC LIST #define TCL_STATE_INCOMPLETE 0x00 #define TCL_STATE_ABORTED 0x01 #define TCL_STATE_EXECUTING 0x02 #define TCL_STATE_COMPLETED 0x03 // LIST OF FLAGS #define UART_INT_FLAG 0x0001 #define NEW_TC_RECEIVED 0x0002 #define COM_SESSION_FLAG 0x0004 #define COM_RX_FLAG 0x0008 #define COM_MNG_TMTC_RUNNING_FLAG 0x0010 #define COM_SESSION_VALIDITY 0x0020 #define ALL_CRC_PASS_FLAG 0x0040 #define COM_PA_HOT_FLAG 0x0080 #define COM_PA_OC_FLAG 0x8000 #define COM_TX_FLAG 0x0100 #define COM_SESSION_TIMEOUT_FLAG 0x0200 #define COM_AUTO_POWER_OFF_BAE_FLAG 0x0400 #define BAE_SW_EN_FLAG 0x0800 #define RF_SW_STATUS_FLAG 0x1000 #define COM_INIT_STATUS_FLAG 0x2000 #define COM_TX_STATUS_FLAG 0x4000 //RF relay STATUS #define RF_COM_TX 0 #define RF_BCN 1 // COM_MNG_TMTC THREAD #define SESSION_TIME_LIMIT 1500 #define COM_MNG_TMTC_SIGNAL_UART_INT 0x01 #define COM_MNG_TMTC_SIGNAL_ADF_NSD 0x02 #define COM_MNG_TMTC_SIGNAL_ADF_SD 0x03 #define cdms_reset_timeout 345600000 // COM_MNG_TMTC #define COM_PA_COOLING_TIME_LIMIT 20 #define COM_MAX_TC_LIMIT 256 #define TM_ACK_CODE_INDEX 2 #define CRC_FAIL_NACK_CODE 0x01 // call sign #define PSC_CALLSIGN 0x00 #define APID_CALLSIGN 0x00 // max value of telecommands in a tcl #define TCL_OVERFLOW_CONSTANT 256 #define TM_OVERFLOW_CONSTANT 256 #define BYTE_OVERFLOW_CONSTANT 35000 // starting value of packet sequence count at each pass #define PSC_START_VALUE 1 // APID list #define APID_COM 0 #define APID_BAE 1 #define APID_CDMS 2 #define APID_SPEED 3 //SERVICE #define SERVICE_OBOSC 0xB #define SERVICE_OBSRS 0xF // HIGH PRIORITY TC - priority list // not correct values here #define HPTC1 5 #define HPTC2 6 // Add more entries above // TMID list #define TMID_ACK_L1 0xA #define TMID_ACK_L234 0xB #define TMID_TCL 0x7 #define TMID_CALL_SIGN 0xE // OBOSC SERVICE SUBTYPE #define OBOSC_TCL_MAX_SHORT_SIZE 11 #define OBOSC_LONG_TC_FIRST_HALF_SIZE 67 #define OBOSC_LONG_TC_SECOND_HALF_SIZE 68 #define OBOSC_TCL_TAG_LONG_FIRST_HALF 0x10 #define OBOSC_TCL_TAG_LONG_SECOND_HALF 0x11 #define OBOSC_SUB_DISABLE 0x01 #define OBOSC_SUB_RETRY 0x05 #define OBOSC_SUB_REP_TCLD 0x06 #define OBOSC_SUB_REP_LE 0x0F #define OBOSC_SUB_RESET 0x07 // PAYLOAD or SCIENCE #define PAYLOAD_BUFFER_LENGTH 6723 #define PAY_SPI_MOSI PTE18 #define PAY_SPI_MISO PTE19 #define PAY_SPI_CLK PTE17 #define PAY_SPI_CS PTE16 #define SCIENCE_SIGNAL 0x04 //BEACON #define BCN_APID_SOURCE 0x41 #define BCN_SERVICE 0x81 //BAE #define BAE_APID_SOURCE 0x81 #define BAE_SERVICE 0x81 #define BAE_POWER_ON_PID 0x13 #define BAE_POWER_OFF_PID 0x23 #define BAE_RESET_PID 0x33 //RF RELAY #define RF_RELAY_CNTRL_TX PTB7 #define RF_RELAY_CNTRL_BCN PTB17 //CDMS HK #define HK_SIGNAL 0x05 #define COMRX_ALIVE 0x01 #define COMRX_DEAD 0x00 #define DEVICE_ENABLED 0x00 #define DEVICE_POWERED 0x01 #define DEVICE_OC_FAULT 0x02 #define DEVICE_DISABLED 0x03 // ****************GLOBAL VARIABLES****************** //Global Mutex gMutex; // DEBUG Serial gPC( USBTX, USBRX ); DigitalOut gLEDR(LED_RED); DigitalOut gLEDG(LED_GREEN); // COM_RX RawSerial RX1M( COM_RX_UART_TX, COM_RX_UART_RX ); COM_RX_DATA_NODE *gRX_HEAD_DATA_NODE = NULL; COM_RX_DATA_NODE *gRX_CURRENT_DATA_NODE = NULL; // uint8_t *gRX_CURRENT_PTR = NULL; uint32_t gRX_COUNT = 0; uint16_t gTOTAL_RAW_BYTES = 0; uint16_t gTOTAL_INCORRECT_SIZE_TC = 0x00; uint16_t gTOTAL_CRC_FAIL_TC = 0x00; uint16_t gTOTAL_REPEATED_TC = 0x00; // COMMON SPI SPI spi( SPI_MOSI, SPI_MISO, SPI_CLK ); DigitalOut gCS_ADF(SPI_CS_ADF); DigitalOut cs_sd(SPI_CS_SDC); DigitalOut gCS_RTC(SPI_CS_RTC); Mutex SPI_mutex; //I2C Mutex BAE_I2C_mutex; //RF Relay DigitalOut RF_SW_CNTRL_BCN(RF_RELAY_CNTRL_BCN); DigitalOut RF_SW_CNTRL_TX(RF_RELAY_CNTRL_TX); //COM_RX DigitalOut COM_RX_CNTRL(PIN72,1); DigitalOut COM_TX_CNTRL(PIN56,1); DigitalIn COM_TX_OC_FAULT(PIN69); // TC LIST Base_tc* gHEAD_NODE_TCL = NULL; Base_tc* gLAST_NODE_TCL = NULL; uint8_t gMASTER_STATE = TCL_STATE_INCOMPLETE; uint16_t gFLAGS = 0x0000; // COM_MNG_TMTC THREAD Thread* gCOM_MNG_TMTC_THREAD = NULL; Timeout gRX_TIMEOUT; Timeout gSESSION_TIMEOUT; Timeout gCOM_RX_DISABLE; // COM_MNG_TMTC RtosTimer *sys_reset_cdms_timer; // PA cooling timeout Timeout gCOM_PA_COOLING_TIMEOUT; // GS code for verification const uint8_t gGSCODE[] = {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t gTOTAL_VALID_TC = 0x00; // USE LAST_L1_ACK FOR GENERATING REPORT uint8_t gLAST_TM[TM_LONG_SIZE]; uint8_t gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE; // PAYLOAD OR SCIENCE_THREAD Thread* gSCIENCE_THREAD = NULL; dmaSPISlave *gPAY_SPI; uint8_t gPAYLOAD_BUFFER[PAYLOAD_BUFFER_LENGTH] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44,1,44,1,44,1,44,1,44,1,44,1,188,2,188,2,188,2,188,2,88,2,88,2,88,2,88,2,100,0,100,0,200,0,200,0,244,1,244,1,88,2,88,2,208,2,208,2,246,0,246,0,10,0,250,0,250,0,250,0,120,0,0,0,172,13,0,0,184,11,0,0,160,15,0,0}; RtosTimer *PL_wo_dma; // CALL SIGN TM const uint8_t gCALL_SIGN_STRING[TM_SHORT_SIZE] = {0xE0, 0x00, 0x00, 0x00, 0x56, 0x55, 0x32, 0x4E, 0x43, 0x46, 0x00, 0xAC, 0x11}; //HK Thread Thread* gHK_THREAD = NULL; RtosTimer *HK_counter; // CDMS HK uint8_t CDMS_STANDBY; uint8_t CDMS_HEALTH_DATA[128]; uint8_t CDMS_RAM[59] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; uint16_t GPIO_STATUS; uint8_t CDMS_HK_MAIN_STATUS; uint8_t COMRX_STATUS; uint8_t RTC_FAULTCOUNT = 0; uint16_t SD_FAULTCOUNT = 0; uint8_t SD_STATUS; uint8_t BAE_FAULTCOUNT = 0; uint8_t BAE_STATUS; uint8_t PL_STATUS; uint16_t PL_FAULTCOUNT = 0; bool BAE_HK_I2C; uint8_t RTC_STATUS; float RSSI_volatge; CDMS_HK_actual actual_data; CDMS_HK_quant quant_data; CDMS_HK_min_max min_max_data; bool firstCount=true; //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); DigitalOut PL_GPIO_1_STATUS (PIN71); // PYLD EPS CNTRL Signal1 / PYLD_EPS_CNTRL_SIG1 DigitalOut PL_GPIO_2_STATUS (PIN81);//PYLD EPS CNTRL 2 / PYLD_EPS_CNTRL_2 DigitalOut PL_GPIO_3_STATUS (PIN80);// PYLD EPS CNTRL 3 / PYLD_EPS_CNTRL_3 DigitalIn PL_BEE_SW_OC_FAULT (PIN91); DigitalIn PL_EPS_LATCH_SW_OC_FAULT (PIN5); //DigitalOut EPS_V_C_EN_STATUS (PIN72,1);//COMM RX PWR CNTRL //DigitalOut EPS_V_D_EN_STATUS (PIN56,1);//3V6_EN DigitalIn SD_OC_FAULT (PIN90); DigitalOut SD_SW_EN_DS (PIN97,1);//SD CARD SW EN/DIS or SD_CARD_SW_EN_DIS DigitalOut BAE_SW_EN_DS (PIN47,1);//BAE_SW_EN_DIS //DigitalOut TRXY_EN (PIN84);//TRXY EN //DigitalOut TRZ_EN (PIN88);//TRZ EN DigitalOut V_A_EN (PIN99,1);//TRZ FLT (no INTR capability) DigitalIn sys_pwr_rst (PIN46);//PTD3 DigitalOut PYLD_DFF (PIN73);//PYLD_SW_PWR_EN_DIS DigitalOut PYLD_DFF_CLK (PIN65);//PL_3V3_EN_CLK DigitalOut PYLD_EPS_DFF_PWR (PIN64);//TPS_SW_PL_LAT_ENA_DIS DigitalOut PYLD_EPS_DFF_PWR_CLK (PIN40);//PYLD_EPS_LATCH_CLK DigitalOut RESET_TO_BAE(PIN93,1);//RESET_BAE_FROM_CDMS DigitalOut RESET_TO_PYLD(PIN21,1);//RESET_PYLD //SD HK uint32_t FSC_CURRENT[6]; uint32_t FSC_LAST[6]; uint8_t SD_RD_ERROR; //Time's uint32_t TIME_LATEST_RTC; uint32_t TIME_LATEST_I2C_BAE; uint32_t TIME_LATEST_I2C_SPEED; uint32_t TIME_LATEST_SD_WR; uint32_t TIME_LATEST_SD_RD; uint32_t TIME_LATEST_SPI_SPEED; //Counter's uint16_t CDMS_I2C_ERR_SPEED_COUNTER = 0; uint16_t CDMS_I2C_ERR_BAE_COUNTER = 0; uint16_t CDMS_HK_MAIN_COUNTER = 0; uint16_t COMRX_RESET_COUNTER = 0; uint16_t PL_MAIN_COUNTER = 0; uint16_t PL_RCV_SC_DATA_COUNTER = 0; uint16_t CDMS_WR_SD_FAULT_COUNTER = 0; uint16_t SD_LIB_WRITES = 0; //CDMS RAM parameters uint8_t PL_INIT_STATUS = 0; uint8_t PL_MAIN_status; uint8_t PL_LOW_POWER; uint8_t PL_STATE; uint8_t PL_RCV_SC_DATA_STATUS = 0; uint8_t COM_SESSION; uint8_t COM_RX; uint8_t RF_SW_STATUS; uint8_t COM_TX; uint8_t COM_TX_STATUS; uint8_t COM_MNG_TMTC; uint8_t EN_CDMS_HK = 1; uint8_t EN_PL = 1; uint8_t EN_RCV_SC = 1; uint8_t CDMS_INIT_STATUS; uint8_t CDMS_HK_STATUS; uint8_t COM_RX_STATUS; uint8_t CDMS_RTC_BL; //CDMS FLASH parameters uint8_t EPS_V_A_EN_STATUS; //uint8_t BAE_SW_STATUS; //uint8_t CDMS_SD_SW_STATUS; //uint8_t PL_BEE_SW_STATUS;* uint8_t PL_EPS_LATCH_SW_EN; uint8_t RTC_INIT_STATUS; uint8_t CDMS_RTC_DISABLE; uint16_t CDMS_RESET_COUNTER; uint32_t TIME_LATEST_CDSMS_RESET; uint16_t COM_TC_BYTES_LIMIT; uint8_t COM_RX_CURRENT_MAX; uint8_t COM_RX_DISABLE_TIMEOUT; uint8_t COM_PA_TMP_HIGH; uint8_t COM_PA_RECOVERY_TIMEOUT; uint8_t COM_SESSION_TIMEOUT; uint8_t COM_RSSI_MIN; uint16_t SD_LIB_BLK_CURRENT; // Ambigouties uint8_t EN_RTC = 0x01;