312
社区成员
发帖
与我相关
我的任务
分享
项目中有57个故障要处理,在故障模块中定义了位域结构体来管理故障位,因为用的是32位单片机,最长无符号整型只用到uint32_t,就设计了两个位域结构体来处理57个故障,用底32位和高32位来区分,代码如下,请教各路大神,有没有更好的设计方法?
typedef union
{
struct
{
uint32_t hpc_com_err :1;
uint32_t coresen_com_err :1;
uint32_t fan_com_err :1;
uint32_t freq_fault :1;
uint32_t hi_refg_pres :1;
uint32_t hi_temp_cmpdis :1;
uint32_t pres_trans_err :1;
uint32_t inwat_sens_err :1;
uint32_t outwat_sens_err :1;
uint32_t distemp_err :1;
uint32_t suctemp_sens_err :1;
uint32_t evap1_coiltemp_err :1;
uint32_t evap2_coiltemp_err :1;
uint32_t evap1_temp_err :1;
uint32_t evap2_temp_err :1;
uint32_t lo_refg_pres :1;
uint32_t hi_wat_temp :1;
uint32_t ambient_temp_err :1;
uint32_t rsrv :14;
}LoFaultBit;
uint32_t all;
}LoFaultFlag;
typedef union
{
struct
{
uint32_t rsrv :32;
}HiFaultBit;
uint32_t all;
}HiFaultFlag;
typedef struct
{
LoFaultFlag lofaults;
HiFaultFlag hifaults;
}FaultBits;