diff --git a/df_datalink_sp/src/system_monitor.c b/df_datalink_sp/src/system_monitor.c index a4c901c..cb549fb 100644 --- a/df_datalink_sp/src/system_monitor.c +++ b/df_datalink_sp/src/system_monitor.c @@ -1,9 +1,10 @@ +/***************************** Include Files *********************************/ #include #include #include #include "common.h" #include "system_monitor.h" - +/************************** Constant Definitions *****************************/ #define BUFF_A 0x00 #define BUFF_B 0x01 #define BUFF_NONE 0xFF @@ -14,6 +15,7 @@ #define PRTCLLOG_PACK_ELN 24 // bytes #define HWSTATE_PACK_ELN 12 // bytes +/************************** Data Type Definitions ****************************/ typedef struct { uint8_t latest; @@ -37,12 +39,14 @@ typedef struct HWSTATE hwState[2]; } SYSMONITOR; +/************************** Function Prototypes ******************************/ +static uint8_t GetWritable(PINGPONG ctrllor); +static uint8_t GetReadable(PINGPONG ctrllor); +/************************** Variable Definitions *****************************/ static SYSMONITOR *sysMonitorInst; -uint8_t GetWritable(PINGPONG ctrllor); -uint8_t GetReadable(PINGPONG ctrllor); - -inline uint8_t GetWritable(PINGPONG ctrllor) +/*********************** Function Implementations ***************************/ +inline static uint8_t GetWritable(PINGPONG ctrllor) { // Allow only one write. ASSERT(ctrllor.wBusy == BUFF_NONE); @@ -52,7 +56,7 @@ inline uint8_t GetWritable(PINGPONG ctrllor) return ((ctrllor.rBusy == BUFF_B) ? BUFF_A : BUFF_B); } -inline uint8_t GetReadable(PINGPONG ctrllor) +inline static uint8_t GetReadable(PINGPONG ctrllor) { if (ctrllor.wBusy == BUFF_NONE || ctrllor.wBusy != ctrllor.latest) return ((ctrllor.latest == BUFF_NONE) ? BUFF_A : BUFF_B); @@ -126,6 +130,10 @@ void SysMonitor_GetSysinfo(SYSINFO *info) void SysMonitor_UpdateSendPayload(const uint8_t *buff, size_t len) { ASSERT(sysMonitorInst != NULL); + if (len > PAYLOAD_LEN_MAX) + { + return; + } uint8_t buffIndx; buffIndx = GetWritable(sysMonitorInst->sendCtrl); sysMonitorInst->sendCtrl.wBusy = buffIndx; @@ -141,6 +149,12 @@ void SysMonitor_UpdateSendPayload(const uint8_t *buff, size_t len) void SysMonitor_GetSendPayload(uint8_t *buff, uint32_t *id, size_t len) { ASSERT(sysMonitorInst != NULL); + ASSERT(buff != NULL); + ASSERT(id != NULL); + if (len > PAYLOAD_LEN_MAX) + { + return; + } uint8_t buffIndx, buffIndex_old; buffIndex_old = sysMonitorInst->sendCtrl.rBusy; if (buffIndex_old != BUFF_NONE) @@ -160,14 +174,19 @@ void SysMonitor_GetSendPayload(uint8_t *buff, uint32_t *id, size_t len) /** * Update receive payload. */ -void SysMonitor_UpdateRecvPayload(const uint8_t *buff, size_t len) +void SysMonitor_UpdateRecvPayload(const uint8_t *buff, uint32_t id, size_t len) { ASSERT(sysMonitorInst != NULL); + ASSERT(buff != NULL); + if (id == DATA_ID_NONE || len > PAYLOAD_LEN_MAX) + { + return; + } uint8_t buffIndx; buffIndx = GetWritable(sysMonitorInst->recvCtrl); sysMonitorInst->recvCtrl.wBusy = buffIndx; memcpy(sysMonitorInst->recv[buffIndx].data, buff, len); - sysMonitorInst->recv[buffIndx].dataId++; + sysMonitorInst->recv[buffIndx].dataId = id; sysMonitorInst->recvCtrl.latest = buffIndx; sysMonitorInst->recvCtrl.wBusy = BUFF_NONE; } @@ -178,6 +197,12 @@ void SysMonitor_UpdateRecvPayload(const uint8_t *buff, size_t len) void SysMonitor_GetRecvPayload(uint8_t *buff, uint32_t *id, size_t len) { ASSERT(sysMonitorInst != NULL); + ASSERT(buff != NULL); + ASSERT(id != NULL); + if(len > PAYLOAD_LEN_MAX) + { + return; + } uint8_t buffIndx, buffIndex_old; buffIndex_old = sysMonitorInst->recvCtrl.rBusy; if (buffIndex_old != BUFF_NONE) @@ -200,6 +225,7 @@ void SysMonitor_GetRecvPayload(uint8_t *buff, uint32_t *id, size_t len) void SysMonitor_UpdateLinklayerLog(const LINKLOG *log) { ASSERT(sysMonitorInst != NULL); + ASSERT(log != NULL); uint8_t buffIndx; buffIndx = GetWritable(sysMonitorInst->linkLogCtrl); sysMonitorInst->linkLogCtrl.wBusy = buffIndx; @@ -214,6 +240,7 @@ void SysMonitor_UpdateLinklayerLog(const LINKLOG *log) void SysMonitor_GetLinklayerLog(LINKLOG *log) { ASSERT(sysMonitorInst != NULL); + ASSERT(log != NULL); uint8_t buffIndx, buffIndex_old; buffIndex_old = sysMonitorInst->linkLogCtrl.rBusy; if (buffIndex_old != BUFF_NONE) @@ -232,6 +259,7 @@ void SysMonitor_GetLinklayerLog(LINKLOG *log) void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log) { ASSERT(sysMonitorInst != NULL); + ASSERT(log != NULL); uint8_t buffIndx; buffIndx = GetWritable(sysMonitorInst->phyLogCtrl); sysMonitorInst->phyLogCtrl.wBusy = buffIndx; @@ -246,6 +274,7 @@ void SysMonitor_UpdatePhysicalLayerLog(const PHYLOG *log) void SysMonitor_GetPhysicalLayerLog(PHYLOG *log) { ASSERT(sysMonitorInst != NULL); + ASSERT(log != NULL); uint8_t buffIndx, buffIndex_old; buffIndex_old = sysMonitorInst->phyLogCtrl.rBusy; if (buffIndex_old != BUFF_NONE) @@ -257,7 +286,6 @@ void SysMonitor_GetPhysicalLayerLog(PHYLOG *log) sysMonitorInst->phyLogCtrl.rBusy = buffIndex_old; } - // @Hardware state /** * Log hardware running status. @@ -265,6 +293,7 @@ void SysMonitor_GetPhysicalLayerLog(PHYLOG *log) void SysMonitor_UpdateHardwareStatus(const HWSTATE *state) { ASSERT(sysMonitorInst != NULL); + ASSERT(state != NULL); uint8_t buffIndx; buffIndx = GetWritable(sysMonitorInst->hwStateCtrl); sysMonitorInst->hwStateCtrl.wBusy = buffIndx; @@ -279,6 +308,7 @@ void SysMonitor_UpdateHardwareStatus(const HWSTATE *state) void SysMonitor_GetHardwareStatus(HWSTATE *state) { ASSERT(sysMonitorInst != NULL); + ASSERT(state != NULL); uint8_t buffIndx, buffIndex_old; buffIndex_old = sysMonitorInst->hwStateCtrl.rBusy; if (buffIndex_old != BUFF_NONE) diff --git a/df_datalink_sp/src/system_monitor.h b/df_datalink_sp/src/system_monitor.h index dfe0592..888d3b0 100644 --- a/df_datalink_sp/src/system_monitor.h +++ b/df_datalink_sp/src/system_monitor.h @@ -1,10 +1,12 @@ #ifndef __SYSTEM_MONITOR_H_ #define __SYSTEM_MONITOR_H_ +/***************************** Include Files *********************************/ #include #include #include "util.h" +/************************** Constant Definitions *****************************/ #define PAYLOAD_LEN_MAX 256 #define PAYLOAD_LEN_FLJ_RX 168 #define PAYLOAD_LEN_FLJ_TX 66 @@ -36,12 +38,19 @@ #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.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_PL_VALID(x) (x <= 1.03 && x >= 0.96) #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71) -#define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97) +#define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.96) #define CLK_SP_PLL0_LOCK BIT(0) #define CLK_SP_PLL1_LOCK BIT(2) @@ -59,6 +68,9 @@ #define TEMPERATURE_MAX 127.0 // Celsius degree #define TEMPERATURE_MIN -128.0 // Celsius degree +/************************** Data Type Definitions ****************************/ +/** @name System Info + */ typedef struct __attribute__((packed)) { // -- unit: ms, 0~604799999 @@ -98,6 +110,8 @@ typedef struct __attribute__((packed)) float roll; } SYSINFO; +/** @name System Bus Log + */ typedef struct __attribute__((packed)) { // SystemBus log @@ -110,6 +124,8 @@ typedef struct __attribute__((packed)) uint32_t remoteCnt; } SYSBUSLOG; +/** @name Linklayer Log + */ typedef struct __attribute__((packed)) { // Network log @@ -138,6 +154,8 @@ typedef struct __attribute__((packed)) uint8_t reserve[4]; } LINKLOG; +/** @name Physical layer Log + */ typedef struct __attribute__((packed)) { uint32_t acqCnt; @@ -156,6 +174,8 @@ typedef struct __attribute__((packed)) uint8_t reserve[3]; } PHYLOG; +/** @name Hardware Status Log + */ typedef struct __attribute__((packed)) { // Hardware status @@ -177,12 +197,15 @@ typedef struct __attribute__((packed)) uint8_t reserve[2]; } HWSTATE; +/** @name Payload + */ typedef struct { uint32_t dataId; uint8_t data[PAYLOAD_LEN_MAX]; } PAYLOAD; +/************************** Function Prototypes ******************************/ int32_t SysMonitor_Init(void); void SysMonitor_Destroy(void); @@ -190,7 +213,7 @@ void SysMonitor_UpdateSysinfo(const SYSINFO *info); void SysMonitor_GetSysinfo(SYSINFO *info); void SysMonitor_UpdateSendPayload(const uint8_t *buff, size_t len); -void SysMonitor_UpdateRecvPayload(const uint8_t *buff, size_t len); +void SysMonitor_UpdateRecvPayload(const uint8_t *buff, uint32_t id, size_t len); void SysMonitor_GetSendPayload(uint8_t *buff, uint32_t *id, size_t len); void SysMonitor_GetRecvPayload(uint8_t *buff, uint32_t *id, size_t len);