/* * @file hv_vos_Conn.h * @brief Header file of connect. * * @verbatim * ============================================================================== * ##### How to use ##### * ============================================================================== * (+) Use () * * @endverbatim * @author HiView SoC Software Team * @version 1.0.0 * @date 2023-03-01 */ /** @file vos_conn.h * @brief VOS board connection functions */ #ifndef _HV_VOS_CONN_H #define _HV_VOS_CONN_H #include "hv_vos_Types.h" #include "hv_vos_Macro.h" #include "hv_vos_Endian.h" #include "hv_vos_Log.h" VOS_EXTERN_C_BEGIN /** @brief forward declaration of connection type */ typedef struct _HV_VOS_CONN_S Hv_Vos_CONN_S; /** @defgroup VOS_CONN VOS_CONN * VOS board connection functions * @{ */ /** @brief board connection type */ typedef enum _HV_VOS_CONN_TYPE_E { HV_VOS_CONN_SIM, //!< simulate connection HV_VOS_CONN_ETHERNET, //!< connect via ETHERNET HV_VOS_CONN_I2C, //!< connect via I2C, need unlock HV_VOS_CONN_DSUI2C, //!< connect via normal I2C HV_VOS_CONN_AUTO, //field) /// read register field #define HV_R8_FIELD_EX(addr, base, field) \ (_reg_val = HV_R8(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W8_FIELD(addr, field, value) do { \ UCHAR8 _val = HV_R8(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W8(addr, _val); \ } while (0) #define HV_W8_FIELD_EX(addr, base, field, value) do { \ UCHAR8 _val = HV_R8(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W8(addr + base, _val); \ } while (0) /// read register field, need HV_R8_DECL_VAR first #define HV_R8_BE_FIELD(addr, field) \ (_reg_val = HV_R8_BE(addr), ((addr##_struct*)(void*)&(_reg_val))->field) /// read register field #define HV_R8_BE_FIELD_EX(addr, base, field) \ (_reg_val = HV_R8_BE(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W8_BE_FIELD(addr, field, value) do { \ UCHAR8 _val = HV_R8_BE(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W8_BE(addr, _val); \ } while (0) #define HV_W8_FIELD_EX(addr, base, field, value) do { \ UCHAR8 _val = HV_R8(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W8(addr + base, _val); \ } while (0) /// define a variable for HV_R16_FIELD #define HV_R16_DECL_VAR() USHORT16 _reg_val /// read register field, need HV_R16_DECL_VAR first #define HV_R16_FIELD(addr, field) \ (_reg_val = HV_R16(addr), ((addr##_struct*)(void*)&(_reg_val))->field) /// read register field #define HV_R16_FIELD_EX(addr, base, field) \ (_reg_val = HV_R16(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W16_FIELD(addr, field, value) do { \ UCHAR8 _val = HV_R16(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W16(addr, _val); \ } while (0) #define HV_W16_FIELD_EX(addr, base, field, value) do { \ USHORT16 _val = HV_R16(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W16(addr + base, _val); \ } while (0) /// read register field, need HV_R16_DECL_VAR first #define HV_R16_BE_FIELD(addr, field) \ (_reg_val = HV_R16_BE(addr), ((addr##_struct*)(void*)&(_reg_val))->field) /// read register field #define HV_R16_BE_FIELD_EX(addr, base, field) \ (_reg_val = HV_R16_BE(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W16_BE_FIELD(addr, field, value) do { \ UCHAR8 _val = HV_R16_BE(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W16_BE(addr, _val); \ } while (0) #define HV_W16_BE_FIELD_EX(addr, base, field, value) do { \ USHORT16 _val = HV_R16_BE(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W16_BE(addr + base, _val); \ } while (0) /// define a variable for HV_R32_FIELD #define HV_R32_DECL_VAR() UINT32 _reg_val /// read register field, need HV_R32_DECL_VAR first #define HV_R32_FIELD(addr, field) \ (_reg_val = HV_R32(addr), ((addr##_struct*)(void*)&(_reg_val))->field) /// read register field #define HV_R32_FIELD_EX(addr, base, field) \ (_reg_val = HV_R32(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W32_FIELD(addr, field, value) do { \ UINT32 _val = HV_R32(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W32(addr, _val); \ } while (0) #define HV_W32_FIELD_EX(addr, base, field, value) do { \ UINT32 _val = HV_R32(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W32(addr + base, _val); \ } while (0) /// read register field, need HV_R32_DECL_VAR first #define HV_R32_BE_FIELD(addr, field) \ (_reg_val = HV_R32_BE(addr), ((addr##_struct*)(void*)&(_reg_val))->field) /// read register field #define HV_R32_BE_FIELD_EX(addr, base, field) \ (_reg_val = HV_R32_BE(addr + base), ((addr##_struct*)&(_reg_val))->field) #define HV_W32_BE_FIELD(addr, field, value) do { \ UINT32 _val = HV_R32_BE(addr); \ ((addr##_struct*)&(_val))->field = value; \ HV_W32_BE(addr, _val); \ } while (0) #define HV_W32_BE_FIELD_EX(addr, base, field, value) do { \ UINT32 _val = HV_R32_BE(addr + base); \ ((addr##_struct*)&(_val))->field = value; \ HV_W32_BE(addr + base, _val); \ } while (0) /// convert register structure to UINT32 #define HV_REG_VAL(reg) (*(UINT32*)&(reg)) /// express way to write a register struct data value #define HV_W32_REG(addr, reg) HV_W32(addr, HV_REG_VAL(reg)) #define HV_W32_BE_REG(addr, reg) HV_W32_BE(addr, HV_REG_VAL(reg)) /// express way to read register to struct data value #define HV_R32_REG(addr, reg) HV_REG_VAL(reg) = HV_R32(addr) #define HV_R32_BE_REG(addr, reg) HV_REG_VAL(reg) = HV_R32_BE(addr) #define HV_W32_SET_BIT(addr, bit) HV_W32_MASK(addr, 1 << (bit), 1 << (bit)) #define HV_W32_CLR_BIT(addr, bit) HV_W32_MASK(addr, 1 << (bit), 0x00000000) #define HV_R32_GET_BIT(addr, bit) ((HV_R32(addr) >> bit) & 1) #define HV_W_FEILD_REG(addr, startbit,endbit, reg) do{ \ UINT32 _val = HV_R32(addr); \ if((endbit-startbit) != 31) \ { \ UINT32 _mask = ~(0xFFFFFFFF << (endbit - startbit + 1)) << startbit;\ _val &= ~_mask; \ _val |= (reg<