add comment add enhance code coherent
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
/***************************** Include Files *********************************/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user