57 lines
1.7 KiB
C
57 lines
1.7 KiB
C
#ifndef ERPC_CORE_H_
|
||
#define ERPC_CORE_H_
|
||
|
||
#include "config.h"
|
||
|
||
#define MAX_CMD_LEN (256 - 5) // crc16最大支持256字节
|
||
#define CMD_MAX_RETRY 5 // 最大重发次数
|
||
#define CMD_TIMEOUT 30 // 超时时间 tick
|
||
#define MAX_COM 20 // 最大支持端口打开数量,可认为是同时通讯的号
|
||
|
||
typedef enum erpc_error {
|
||
DEST_SYS_BUSY = 0, // 目标系统繁忙,接收到nack
|
||
DEST_SYS_TIMEOUT, // 目标系统处理超时
|
||
BUS_CRC_ERROR, // 总线CRC错误,可能是总线通讯质量不佳
|
||
};
|
||
typedef enum package_type {
|
||
PACKAGE_TYPE_DEV_POWER_ON = 0,
|
||
PACKAGE_TYPE_CMD_REQ,
|
||
PACKAGE_TYPE_CMD_REQ_ACK,
|
||
PACKAGE_TYPE_CMD_RESP,
|
||
PACKAGE_TYPE_CMD_RESP_ACK,
|
||
PACKAGE_TYPE_CMD_RESP_NACK,
|
||
PACKAGE_TYPE_CMD_REPEAT, // crc校验失败,请求重发
|
||
PACKAGE_TYPE_DEV_POWER_OFF,
|
||
PACKAGE_TYPE_CMD_SERCH_DEV_ONLINE,
|
||
} package_type;
|
||
|
||
typedef struct node_cfg_t {
|
||
u8 local_id;
|
||
struct port_t {
|
||
u16 com_id;
|
||
volatile u32 time_out;
|
||
void (*pre_deal)(u8 *data, u32 len); // 数据预处理接口
|
||
u8 send_ack : 2; // 0:没有ack返回,1:ack返回 2:nack返回
|
||
u8 rec_crc : 1; // 0:crc没有故障, 1: crc有故障
|
||
u8 req_resend : 1; // 1:客户端请求重发
|
||
} port[MAX_COM];
|
||
u32 (*write)(u8 *data, u32 len);
|
||
void (*bus_lock)(void);
|
||
void (*bus_unlock)(void);
|
||
void (*sleep)(void);
|
||
} node_cfg_t;
|
||
|
||
// 广播ID
|
||
#define ERPC_BOARDCAST_ID 0xff
|
||
|
||
typedef struct erpc_cmd_def_t {
|
||
u8 src_id;
|
||
u8 dest_id;
|
||
package_type type;
|
||
u16 port; // 指令号,指令号=端口号
|
||
u8 msg_len;
|
||
u8 crc_16[2];
|
||
u8 *data;
|
||
} erpc_cmd_def_t;
|
||
|
||
#endif /* ERPC_CORE_H_ */ |