编码规范

1. 编码格式

2. 变量命名规范

3. 结构体规范

结构体手动对齐示例:

typedef struct
{
    uint8_t MsgType;        /* 偏移0:消息类型 */
    uint8_t Reserved0;      /* 偏移1:手动补齐,使Length从偏移2开始 */
    uint16_t Length;        /* 偏移2:长度字段 */
    uint32_t SeqNo;         /* 偏移4:序号字段,手动保证四字节对齐 */
    uint8_t Status;         /* 偏移8:状态 */
    uint8_t Reserved1[3];   /* 偏移9-11:手动补齐,使结构体总长度为12字节 */
} __PACKED ExampleFrame_t;

结构体未手动对齐的反例:

typedef struct
{
    uint8_t MsgType;        /* 偏移0:消息类型 */
    uint32_t SeqNo;         /* 偏移1:序号字段,未按四字节对齐 */
    uint8_t Status;         /* 偏移5:状态 */
} __PACKED BadFrame_t;

4. 枚举规范

5. 头文件管理

6. 宏定义规范

7. 函数设计规范

函数注释示例:

/**
 * @brief 判断操作的数据标识序号是否合法
 *
 * @param [in] ItemSeq 序号
 * @return true 序号合法,false 序号不合法
 */
static bool is_valid_item_seq(uint8_t ItemSeq);

8. 其他编码规范

编译方法

编译路径

cd SDK/make/

临时编译方法

make clean && make venus2m_v7_riscv_sta -j P=HU_NAN CHIPVER=CHIP_V7

正式编译方法

bash ./build_18_sta.sh