forked from gatsby/df_datalink
259 lines
8.9 KiB
C
259 lines
8.9 KiB
C
/**
|
|
* @defgroup SystemMonitor
|
|
* @{
|
|
*/
|
|
|
|
#ifndef __SYSTEM_MONITOR_H_
|
|
#define __SYSTEM_MONITOR_H_
|
|
|
|
/***************************** Include Files *********************************/
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "util.h"
|
|
|
|
/************************* Constant Definitions ******************************/
|
|
/**
|
|
* @name SystemMonitor_Constants
|
|
* @{
|
|
*/
|
|
#define PAYLOAD_LEN_MAX 1000
|
|
|
|
#define DATA_ID_NONE UINT32_MAX
|
|
#define DATA_ID_TEST 0x02030203
|
|
|
|
#define VOLTAGE_LSB 0.01 // volt
|
|
#define VOLTAGE_MAX 2.55 // volt
|
|
|
|
#define VOLT_PS_STD 1.0
|
|
#define VOLT_PSAUX_STD 1.8
|
|
#define VOLT_DDR_STD 1.5
|
|
#define VOLT_PL_STD 1.0
|
|
#define VOLT_PLAUX_STD 1.8
|
|
#define VOLT_BRAM_STD 1.0
|
|
|
|
#define VOLT_PS_OK BIT(0)
|
|
#define VOLT_PSAUX_OK BIT(1)
|
|
#define VOLT_DDR_OK BIT(2)
|
|
#define VOLT_PL_OK BIT(3)
|
|
#define VOLT_PLAUX_OK BIT(4)
|
|
#define VOLT_BRAM_OK BIT(5)
|
|
|
|
#define VOLT_ANT_PROC_OK BIT(0)
|
|
#define VOLT_ANT_RF_OK BIT(2)
|
|
#define VOLT_ANT_NIL_OK BIT(4)
|
|
#define ANT_STATE_OK BIT(6)
|
|
|
|
// Xilinx Recommended
|
|
// #define IS_PS_VALID(x) (x <= 1.05 && x >= 0.95)
|
|
// #define IS_PSAUX_VALID(x) (x <= 1.89 && x >= 1.71)
|
|
// #define IS_DDR_VALID(x) (x <= 1.89 && x >= 1.14)
|
|
// #define IS_PL_VALID(x) (x <= 1.03 && x >= 0.97)
|
|
// #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71)
|
|
// #define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97)
|
|
#define IS_PS_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
|
|
#define IS_PSAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
|
|
#define IS_DDR_VALID(x) ((x) <= 1.7 && (x) >= 1.3)
|
|
#define IS_PL_VALID(x) (x <= 1.1 && (x) >= 0.9)
|
|
#define IS_PLAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
|
|
#define IS_BRAM_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
|
|
|
|
#define CLK_SP_PLL1_LOCK BIT(0)
|
|
#define CLK_SP_PLL2_LOCK BIT(2)
|
|
|
|
#define CLK_AD0_BBPLL_LOCK BIT(0)
|
|
#define CLK_AD0_RFPLL_LOCK BIT(2)
|
|
#define CLK_AD1_BBPLL_LOCK BIT(4)
|
|
#define CLK_AD1_RFPLL_LOCK BIT(6)
|
|
|
|
#define CLK_ANT_BBPLL_LOCK BIT(0)
|
|
#define CLK_ANT_RFPLL1_LOCK BIT(2)
|
|
#define CLK_ANT_RFPLL2_LOCK BIT(4)
|
|
|
|
#define TEMPERATURE_LSB 1.0 // Celsius degree
|
|
#define TEMPERATURE_MAX 127.0 // Celsius degree
|
|
#define TEMPERATURE_MIN -128.0 // Celsius degree
|
|
/** @} SystemMonitor_Constants */
|
|
|
|
/************************* Data Type Definitions ****************************/
|
|
|
|
/**
|
|
* @struct SYSINFO
|
|
* @brief System Infomation log
|
|
*/
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
uint32_t psBDS; ///< -- unit: ms, 0~604799999
|
|
uint16_t pBDS; ///< -- unit: week, 0~0~8191
|
|
uint32_t psGPS; ///< -- unit: ms, 0~604799999
|
|
uint16_t pGPS; ///< -- unit: week, 0~0~8191
|
|
uint8_t tmInd; ///< Time validation indicator \n
|
|
// -- [0] GPS\n
|
|
// -- [1] reserve.\n
|
|
// -- [2] UTC\n
|
|
// -- [3] BDS\n
|
|
float tmFly; ///< Time of flying uint: s
|
|
uint8_t stFly; ///< Status of flying \n
|
|
// [7:6] departure status 11 - departed/00 - not departed \n
|
|
// [5:4] ready status 11 - ready/00 - not ready \n
|
|
// [3:2] attitude status 11 - attitude ok/00 - attitude not ok \n
|
|
// [1:0] attitude adjust status 11 - adjusted/00 - not adjusted
|
|
float posX; ///< coord X Position in launch coordinate system
|
|
float posY; ///< coord Y Position in launch coordinate system
|
|
float posZ; ///< coord Z Position in launch coordinate system
|
|
float vX; ///< Speed X in launch coordinate system
|
|
float vY; ///< Speed Y in launch coordinate system
|
|
float vZ; ///< Speed Z in launch coordinate system
|
|
float pitch; ///< Pitch Attitude in launch inertia coordinate system
|
|
float yaw; ///< Yaw Attitude in launch inertia coordinate system
|
|
float roll; ///< Roll Attitude in launch inertia coordinate system
|
|
} SYSINFO;
|
|
|
|
/**
|
|
* @struct SYSBUSLOG
|
|
* @brief System Info holds the system bus log
|
|
*/
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
// SystemBus log
|
|
|
|
uint8_t lastConfig[4]; ///< Last valid config \n
|
|
// byte 0: Enable control, 0xAA - enable, 0x55 - disable \n
|
|
// byte 1: Node ID \n
|
|
// byte 2: Service rate \n
|
|
// byte 3: routing table number
|
|
uint32_t recvCnt; ///< number of received data packet
|
|
uint32_t sendCnt; ///< number of send data packet
|
|
uint32_t remoteCnt; ///< number of remote check commands
|
|
} SYSBUSLOG;
|
|
|
|
/**
|
|
* @struct LINKLOG
|
|
* @brief Linklayer Log struct holds the Linklayer log
|
|
*/
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
// Network log
|
|
uint32_t tuNum; ///< current time unite number
|
|
uint8_t slotNum; ///< current slot number
|
|
uint8_t nodeType; ///< current node type
|
|
uint8_t cxnStatus; ///< current connection status
|
|
uint8_t linkStage; ///< current linklayer working stage
|
|
uint32_t recxnCnt; ///< reconnect trial count
|
|
uint8_t antIndex; ///< current working antenna index
|
|
uint32_t advTxCnt; ///< adv frame send count
|
|
uint32_t advRecvCnt; ///< adv frame received count
|
|
uint32_t advCorrectCnt; ///< adv frame received correctly count
|
|
uint32_t ackTxCnt; ///< ack frame send count
|
|
uint32_t ackRecvCnt; ///< ack frame received count
|
|
uint32_t ackCorrectCnt; ///< ack frame received correctly count
|
|
uint32_t disTxCnt; ///< dist frame send count
|
|
uint32_t disRecvCnt; ///< dist frame received count
|
|
uint32_t disCorrectCnt;///< dist frame received correctly count
|
|
uint32_t mngTxCnt; ///< mng frame send count
|
|
uint32_t mngRecvCnt; ///< mng frame received count
|
|
uint32_t mngCorrectCnt; ///< mng frame received correctly count
|
|
uint32_t rttTxCnt; ///< rtt frame send count
|
|
uint32_t rttRecvCnt; ///< rtt frame received count
|
|
uint32_t rttCorrectCnt; ///< rtt frame received correctly count
|
|
uint32_t svcTxCnt; ///< svc frame send count
|
|
uint32_t svcRecvCnt; ///< svc frame received count
|
|
uint32_t svcCorrectCnt; ///< svc frame received correctly count
|
|
int32_t timeDev; ///< last time deviation result
|
|
uint32_t sendId; ///< last send data id
|
|
uint32_t recvId; ///< last received data id
|
|
uint8_t reserve[3]; ///< reserved data
|
|
} LINKLOG;
|
|
|
|
/**
|
|
* @struct PHYLOG
|
|
* @brief Physical Layer Log struct holds the Linklayer log
|
|
*/
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
uint32_t acqCnt; ///< acquisition count
|
|
uint32_t fsyncCnt; ///< frame sync count
|
|
uint32_t decodeCnt; ///< decode count
|
|
uint32_t crcCnt; ///< crc valid count
|
|
double doppler; ///< last doppler estimation result
|
|
uint64_t recvStamp; ///< last frame arrival time
|
|
double acqPAPR; ///< last acquisition peak-average ration
|
|
uint8_t acqPhase; ///< last acquisition phase estimation
|
|
uint8_t acqFreqCh; ///< last acquisition frequency deviation estimation
|
|
double fsyncPAPR; ///< last frame sync peak-average ration
|
|
uint8_t fsyncFreqCh; ///< last frame sync frequency estimation
|
|
uint16_t deintlvAmpEst; ///< de-interleave amplitude estimation
|
|
uint8_t antControl; ///< current antenna rf mode
|
|
uint8_t reserve[2]; ///< reserved data
|
|
} PHYLOG;
|
|
|
|
/**
|
|
* @struct HWSTATE
|
|
* @brief Hardware Status Log struct holds all hardware status
|
|
*/
|
|
typedef struct __attribute__((packed))
|
|
{
|
|
bool isSpOk; ///< signal processor state
|
|
bool isAntOk; ///< antenna state
|
|
// -- Signal processor status
|
|
uint8_t spFpgaVolt; ///< Signal processor voltage state indicator
|
|
uint8_t spClkState; ///< Signal processor clock state indicator
|
|
uint8_t spAdLockState; ///< Signal processor adc lock state indicator
|
|
int8_t spAdTemp_0; ///< Signal processor adc0 temperature
|
|
int8_t spAdTemp_1; ///< Signal processor adc1 temperature
|
|
int8_t spFpgaTemp; ///< Signal processor FPGA temperature
|
|
// -- Antenna status
|
|
uint16_t ant1Freq; ///< Antenna 1 frequency
|
|
uint16_t ant2Freq; ///< Antenna 2 frequency
|
|
uint16_t ant3Freq; ///< Antenna 3 frequency
|
|
uint8_t antPll; ///< Antenna pll lock state indicator
|
|
uint8_t antMode; ///< Antenna mode indicator
|
|
int8_t antTemp; ///< Antenna rf temperature
|
|
uint8_t antRsvd; ///< Antenna reserved status register
|
|
uint8_t phyId;
|
|
uint8_t reserve[3];
|
|
} HWSTATE;
|
|
|
|
/**
|
|
* @struct SYSMON_CONFIG
|
|
* @brief System monitor config struct holds system monitor initialization parameters
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint32_t sendQueueMax; ///< maximum send queue length
|
|
uint32_t recvQueueMax; ///< maximum receive queue length
|
|
} SYSMON_CONFIG;
|
|
|
|
/**
|
|
* @struct SYSMON_SVC_PAYLOAD
|
|
* @brief Payload struct that holds the service payload
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint32_t dataId; ///< data identifier
|
|
uint8_t nodeId; ///< destination ID for tx, source ID for rx
|
|
uint16_t dataLen; ///< data length
|
|
uint8_t data[PAYLOAD_LEN_MAX];
|
|
} SYSMON_SVC_PAYLOAD;
|
|
|
|
/************************** Function Prototypes ******************************/
|
|
int32_t SysMonitor_Init(SYSMON_CONFIG *config);
|
|
void SysMonitor_Destroy(void);
|
|
|
|
void SysMonitor_UpdateSysinfo(const SYSINFO *info);
|
|
void SysMonitor_GetSysinfo(SYSINFO *info);
|
|
|
|
int32_t SysMonitor_UpdateSendPayload(SYSMON_SVC_PAYLOAD *payload);
|
|
void SysMonitor_GetSendPayload(SYSMON_SVC_PAYLOAD *payload);
|
|
int32_t SysMonitor_GenRecvRsp(SYSMON_SVC_PAYLOAD *payload);
|
|
|
|
void SysMonitor_UpdateLinklayerLog(const LINKLOG *log);
|
|
void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log);
|
|
void SysMonitor_UpdateHardwareStatus(const HWSTATE *state);
|
|
void SysMonitor_GetLinklayerLog(LINKLOG *log);
|
|
void SysMonitor_GetPhysicalLayerLog(PHYLOG *log);
|
|
void SysMonitor_GetHardwareStatus(HWSTATE *state);
|
|
|
|
#endif //__SYSTEM_MONITOR_H_
|
|
|
|
/** @} */
|