T-Box Basic dev
Loading...
Searching...
No Matches
icc_protocol.h
Go to the documentation of this file.
1
10
11#ifndef ICC_PROTOCOL_H
12#define ICC_PROTOCOL_H
13
14#ifdef __cplusplus
15extern "C"
16{
17#endif
18
19#include "icc_config.h"
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
24typedef enum
25{
26 ICC_PROTO_OK = 0,
27 ICC_PROTO_BUSY = 1,
28 ICC_PROTO_FULL = 2,
29 ICC_ERR_STATE = 3,
30 ICC_ERR_PARAM = 4,
31} icc_proto_err_t;
32
33typedef enum
34{
35 ICC_PROTO_STOPPED = 0,
36 ICC_PROTO_HANDSHAKE = 1,
37 ICC_PROTO_RUNNING = 2,
38} icc_proto_state_t;
39
40typedef enum
41{
42 ICC_EVT_HANDSHAKE_OK = 0,
43 ICC_EVT_HEARTBEAT_LOST = 1,
44 ICC_EVT_HANDSHAKE_FAIL = 2,
45} icc_proto_event_t;
46
47typedef struct
48{
49 uint32_t tx;
50 uint32_t tx_state_err;
51 uint32_t tx_param_err;
52 uint32_t tx_full_err;
53 uint32_t retry_count;
54 uint32_t retry_exhausted;
55
56 uint32_t rx;
57 uint32_t rx_len_err;
58 uint32_t rx_crc_err;
59
60 uint32_t tx_hd;
61 uint32_t rx_hb_ack;
62 uint32_t rx_hd;
63 uint32_t handshake_ok;
64 uint32_t handshake_fail;
65 uint32_t heartbeat_lost;
67
68typedef void (*icc_proto_send_func_t)(const uint8_t* buf, uint16_t len, void* userData);
69typedef void (*icc_proto_msg_cb_t)(uint16_t cmd, const uint8_t* data, uint16_t len, void* userData);
70typedef void (*icc_proto_evt_cb_t)(icc_proto_event_t event, void* userData);
71
72typedef struct
73{
74 uint8_t seq;
75 uint16_t cmd;
76 uint8_t data[ICC_ACK_DATA_MAX];
77 uint16_t data_len;
78 uint64_t send_tick;
79 uint8_t retry;
80 volatile uint8_t active;
82
83typedef struct
84{
85 int rxState;
86 uint16_t buf_pos;
87 uint8_t rx_ctrl;
88 uint8_t rx_seq;
89 uint16_t rx_cmd;
90 uint16_t rx_len;
91 uint16_t rx_data_remain;
92 uint8_t buf[ICC_RX_FRAME_MAX];
94
95typedef struct
96{
97 icc_parser_ctx_t parser;
98 icc_proto_state_t state;
99 volatile uint8_t seq_counter;
100 ICC_PROTO_LOCK_T sqp_mutex;
101
102 uint64_t heartbeat_tick;
103 uint64_t last_hb_send_tick;
104
106 ICC_PROTO_LOCK_T ack_mutex;
107
108 icc_proto_stats_t stats;
109
110 icc_proto_send_func_t send_func;
111 icc_proto_msg_cb_t on_message;
112 icc_proto_evt_cb_t on_event;
113 void* user_data;
115
122icc_proto_err_t icc_proto_init(icc_proto_mgr_t* mgr);
123
130
137
144
155icc_proto_err_t icc_proto_send(icc_proto_mgr_t* mgr, uint16_t cmd, uint8_t need_ack, const uint8_t* data, uint16_t len);
156
165icc_proto_err_t icc_proto_send_space_enough(icc_proto_mgr_t* mgr, uint8_t need_ack, uint16_t len);
166
174void icc_proto_feed(icc_proto_mgr_t* mgr, const uint8_t* buf, uint16_t len);
175
182
189void icc_proto_set_send_func(icc_proto_mgr_t* mgr, icc_proto_send_func_t func);
190
197void icc_proto_on_message(icc_proto_mgr_t* mgr, icc_proto_msg_cb_t cb);
198
205void icc_proto_on_event(icc_proto_mgr_t* mgr, icc_proto_evt_cb_t cb);
206
213void icc_proto_set_user_data(icc_proto_mgr_t* mgr, void* user_data);
214
221icc_proto_state_t icc_proto_get_state(icc_proto_mgr_t* mgr);
222
230
237#ifdef __cplusplus
238}
239#endif
240
241#endif
ICC 协议栈配置定义
#define ICC_ACK_DATA_MAX
需要重传的帧 DATA 最大长度,超过则无法重传
Definition icc_config.h:61
#define ICC_RX_FRAME_MAX
接收数据帧最大总长
Definition icc_config.h:37
#define ICC_ACK_TABLE_DEPTH
ACK 等待表深度,同时等待 ACK 的最大帧数
Definition icc_config.h:58
void icc_proto_get_stats(icc_proto_mgr_t *mgr, icc_proto_stats_t *stats)
获取 ICC 协议统计信息。
void icc_proto_reset_stats(icc_proto_mgr_t *mgr)
清空 ICC 协议统计信息。
icc_proto_state_t icc_proto_get_state(icc_proto_mgr_t *mgr)
获取 ICC 协议状态。
void icc_proto_set_user_data(icc_proto_mgr_t *mgr, void *user_data)
设置 ICC 协议用户数据。
void icc_proto_feed(icc_proto_mgr_t *mgr, const uint8_t *buf, uint16_t len)
向 ICC 协议栈输入接收字节流。
void icc_proto_stop(icc_proto_mgr_t *mgr)
停止 ICC 协议栈。
void icc_proto_start(icc_proto_mgr_t *mgr)
启动 ICC 协议栈并进入握手状态。
icc_proto_err_t icc_proto_send(icc_proto_mgr_t *mgr, uint16_t cmd, uint8_t need_ack, const uint8_t *data, uint16_t len)
发送一条 ICC 协议消息。
void icc_proto_set_send_func(icc_proto_mgr_t *mgr, icc_proto_send_func_t func)
设置 ICC 协议底层发送函数。
void icc_proto_deinit(icc_proto_mgr_t *mgr)
反初始化 ICC 协议管理器。
icc_proto_err_t icc_proto_send_space_enough(icc_proto_mgr_t *mgr, uint8_t need_ack, uint16_t len)
检查 ICC 协议发送空间是否充足。
icc_proto_err_t icc_proto_init(icc_proto_mgr_t *mgr)
初始化 ICC 协议管理器。
void icc_proto_on_message(icc_proto_mgr_t *mgr, icc_proto_msg_cb_t cb)
设置 ICC 协议消息接收回调。
void icc_proto_tick(icc_proto_mgr_t *mgr)
驱动 ICC 协议栈周期处理。
void icc_proto_on_event(icc_proto_mgr_t *mgr, icc_proto_evt_cb_t cb)
设置 ICC 协议事件回调。
Definition icc_protocol.h:73
Definition icc_protocol.h:84
Definition icc_protocol.h:96
Definition icc_protocol.h:48