XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
protocol.h
浏览该文件的文档.
1
13#ifndef __xwmd_isc_xwssc_protocol_h__
14#define __xwmd_isc_xwssc_protocol_h__
15
16#include <xwos/standard.h>
17#include <xwos/lib/object.h>
18#include <xwos/lib/xwbop.h>
19#include <xwos/lib/xwaop.h>
20#include <xwos/lib/bclst.h>
21#include <xwos/lib/xwlog.h>
22#include <xwos/mm/bma.h>
23#include <xwos/osal/thd.h>
25#include <xwos/osal/lock/mtx.h>
26#include <xwos/osal/sync/sem.h>
27#include <xwos/osal/sync/cond.h>
29#include <xwmd/isc/xwssc/mif.h>
30
36#define XWSSC_SOF ((xwu8_t)0xAA)
37#define XWSSC_EOF (XWSSC_SOF ^ (xwu8_t)0xFF)
38#define XWSSC_SOF_SIZE (2U)
39#define XWSSC_EOF_SIZE (2U)
40
41#define XWSSC_FRMHEAD_SIZE(size) ((size) & 0xFU)
42#define XWSSC_FRMHEAD_SIZE_MIRROR(size) ((size) & 0xF0U)
43#define XWSSC_FRMHEAD_MAXSIZE (16U)
44#define XWSSC_FRM_ONSTACK_MAXSIZE (64U)
45
46#define XWSSC_ID_MSK (0xFFU)
47#define XWSSC_ID(id) ((xwu8_t)((xwu8_t)(id) & XWSSC_ID_MSK))
48
49#define XWSSC_ECSIZE(head) (XWSSC_FRMHEAD_SIZE((head)->headsize) - \
50 sizeof(struct xwssc_frmhead))
51#define XWSSC_SDUPOS(head) (&((head)->ecsdusz[XWSSC_ECSIZE(head)]))
52#define XWSSC_RXSDUSIZE(slot) ((slot)->frmsize - \
53 XWSSC_FRMHEAD_SIZE((slot)->frm.head.headsize) - \
54 XWSSC_CRC32_SIZE - XWSSC_SOF_SIZE - XWSSC_EOF_SIZE)
55#define XWSSC_CRC32_SIZE (4U)
56#define XWSSC_SDU_MAX_SIZE (XWSSC_MEMPOOL_SIZE / 8)
57
58#define XWSSC_TXTHD_STACK (4096U)
59#define XWSSC_RXTHD_STACK (4096U)
60
61#if defined(XWMDCFG_isc_xwssc_LOG) && (1 == XWMDCFG_isc_xwssc_LOG)
62# define xwssclogf(xwssc, lv, fmt, ...) xwlogf(lv, "%s", \
63 fmt, xwssc->name, ##__VA_ARGS__)
64#else
65# define xwssclogf(xwssc, lv, fmt, ...)
66#endif
67
68#define XWSSC_BUG() XWOS_BUG()
69#define XWSSC_BUG_ON(x) XWOS_BUG_ON(x)
70
71#if defined(XWMDCFG_CHECK_PARAMETERS) && (1 == XWMDCFG_CHECK_PARAMETERS)
72#define XWSSC_VALIDATE(exp, errstr, ...) \
73 if (!(exp)) { \
74 return __VA_ARGS__; \
75 }
76#else
77# define XWSSC_VALIDATE(exp, errstr, ...)
78#endif
79
80#define XWSSC_VALIDATE_FORCE(exp, errstr, ...) \
81 if (!(exp)) { \
82 return __VA_ARGS__; \
83 }
84
93};
94
104};
105
115 xwu8_t ecsdusz[0];
116};
117
123 struct xwssc_frmhead head;
124 /* xwu8_t sdu[x]; 数据 */
125 /* xwu8_t sducrc32[4]; 数据的CRC32校验码 */
126 /* xwu8_t eof[XWSSC_EOF_SIZE]; 帧尾定界符(EOF:End-of-Frame Delimiter) */
127};
128
133 struct {
135 void * cbarg;
137 struct xwssc_frm frm;
138 } tx;
139 struct {
140 struct xwlib_bclst_node node;
141 xwsz_t frmsize;
142 struct xwssc_frm frm;
143 } rx;
144};
145
155};
156
160struct xwssc {
161 /* 基本信息 */
163 const char * name;
166 void * hwifcb;
168 /* 内存池 */
170 struct xwmm_bma * mempool;
172 /* 发送状态机 */
176 struct {
182 struct xwos_splk qlock;
183 struct xwos_sem qsem;
184 struct xwos_mtx csmtx;
185 struct xwos_cond cscond;
186 struct {
189 } remote;
191 struct xwos_splk notiflk;
192 } txq;
194 /* 接收状态机 */
198 struct {
199 atomic_xwu32_t cnt;
203 } rxq;
204};
205
208void xwssc_encode_sdusize(xwsz_t sdusize, xwu8_t * ecsdusz, xwu8_t * ecsize);
209void xwssc_decode_sdusize(xwu8_t * ecsdusz, xwsz_t * sdusize);
211bool xwssc_chk_head(xwu8_t data[], xwsz_t size);
215void xwssc_txq_carrier_free(struct xwssc * xwssc, struct xwssc_carrier * car);
218 const xwu8_t sdu[], xwsz_t sdusize,
219 xwu8_t pri, xwu8_t port, xwu8_t qos,
220 xwssc_ntf_f ntfcb, void * cbarg,
221 xwssc_txh_t * txhbuf);
224
229#endif /* xwmd/isc/xwssc/protocol.h */
XWOS通用库:双循环链表
XWOS内存管理:伙伴算法内存块分配器
#define XWSSC_PRI_NUM
Definition mif.h:41
#define XWSSC_MEMBLK_ODR
Definition mif.h:48
void(* xwssc_ntf_f)(struct xwssc *, xwssc_txh_t, xwer_t, void *)
通知发送结果的回调函数
Definition mif.h:99
#define XWSSC_PORT_NUM
Definition mif.h:44
#define XWSSC_MEMBLK_NUM
Definition mif.h:50
void xwssc_decode_sdusize(xwu8_t *ecsdusz, xwsz_t *sdusize)
xwer_t xwssc_put(struct xwssc *xwssc)
#define XWSSC_RXTHD_STACK
Definition protocol.h:59
xwer_t xwssc_grab(struct xwssc *xwssc)
union xwssc_slot * xwssc_rxq_choose(struct xwssc *xwssc, xwu8_t port)
void xwssc_encode_sdusize(xwsz_t sdusize, xwu8_t *ecsdusz, xwu8_t *ecsize)
struct xwssc_carrier * xwssc_txq_choose(struct xwssc *xwssc)
struct xwssc_carrier * xwssc_txq_carrier_alloc(struct xwssc *xwssc)
#define XWSSC_TXTHD_STACK
Definition protocol.h:58
xwssc_flag_em
协议内部标志
Definition protocol.h:88
xwu8_t xwssc_cal_head_chksum(xwu8_t data[], xwsz_t size)
xwer_t xwssc_eq_msg(struct xwssc *xwssc, const xwu8_t sdu[], xwsz_t sdusize, xwu8_t pri, xwu8_t port, xwu8_t qos, xwssc_ntf_f ntfcb, void *cbarg, xwssc_txh_t *txhbuf)
bool xwssc_chk_head(xwu8_t data[], xwsz_t size)
#define XWSSC_SOF_SIZE
Definition protocol.h:38
xwer_t xwssc_txthd(struct xwssc *xwssc)
xwer_t xwssc_tx_ack_sdu(struct xwssc *xwssc, xwu8_t port, xwu8_t id, xwu8_t ack)
xwer_t xwssc_rxthd(struct xwssc *xwssc)
void xwssc_txq_carrier_free(struct xwssc *xwssc, struct xwssc_carrier *car)
xwssc_frm_ack_em
应答信号枚举
Definition protocol.h:98
#define XWMM_BMA_RAWOBJ_DEF(name, blkodr)
定义伙伴算法内存块分配器结构体的RAW内存空间, 用于初始化伙伴算法内存块分配器结构体
Definition bma.h:55
#define xwlib_bclst_head
双循环链表头
Definition bclst.h:35
#define __xwcc_alignl1cache
Definition compiler.h:123
#define __xwcc_packed
Definition compiler.h:83
signed long xwer_t
Definition type.h:554
__xwcc_atomic xwsq_t atomic_xwsq_t
Definition type.h:448
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
__xwcc_atomic xwu32_t atomic_xwu32_t
Definition type.h:269
uint16_t xwu16_t
Definition type.h:230
#define xwbmpaop_define(name, bits)
XWOS BOPLIB:声明原子位图
Definition xwaop.h:2484
#define xwbmpop_define(name, bits)
XWOS BOPLIB:声明位图
Definition xwbop.h:415
SOC间点对点通讯协议:硬件接口抽象层
操作系统抽象层:互斥锁
操作系统抽象层:自旋锁
@ XWSSC_FLAG_MSK
Definition protocol.h:92
@ XWSSC_FLAG_SDU
Definition protocol.h:91
@ XWSSC_FLAG_ACK
Definition protocol.h:90
@ XWSSC_FLAG_CONNECT
Definition protocol.h:89
@ XWSSC_ACK_EALREADY
Definition protocol.h:101
@ XWSSC_ACK_OK
Definition protocol.h:99
@ XWSSC_ACK_NOMEM
Definition protocol.h:102
@ XWSSC_ACK_ECONNRESET
Definition protocol.h:100
@ XWSSC_ACK_NUM
Definition protocol.h:103
双循环链表的节点
Definition bclst.h:27
伙伴算法内存块分配器
Definition bma.h:80
XWOS API:条件量对象
Definition cond.h:91
XWOS API:互斥锁
Definition mtx.h:82
XWOS对象
Definition object.h:53
XWOS API:信号量对象
Definition sem.h:95
XWOS API:自旋锁
Definition spinlock.h:73
XWOS API:线程对象描述符
Definition thd.h:149
XWOS API:线程对象
Definition thd.h:137
包含待发送帧的发送器
Definition protocol.h:149
xwu16_t idx
Definition protocol.h:152
union xwssc_slot * slot
Definition protocol.h:154
atomic_xwu32_t state
Definition protocol.h:151
struct xwlib_bclst_node node
Definition protocol.h:150
XWSSC的帧
Definition protocol.h:121
XWSSC帧的信息头
Definition protocol.h:109
xwu8_t port
Definition protocol.h:112
xwu8_t headsize
Definition protocol.h:110
xwu8_t chksum
Definition protocol.h:111
硬件接口抽象层操作函数集
Definition hwifal.h:31
XWSSC对象
Definition protocol.h:160
xwu8_t mempool_bma_raw[sizeof(struct xwmm_bma)+sizeof(struct xwmm_bma_orderlist[(((6U)))+1U])+sizeof(struct xwmm_bma_bcb[1U<<(((6U)))])]
Definition protocol.h:169
struct xwos_thd rxthdobj
Definition protocol.h:196
xwu8_t ack
Definition protocol.h:187
atomic_xwsq_t hwifst
Definition protocol.h:164
xwos_thd_d txthd
Definition protocol.h:175
xwos_thd_d rxthd
Definition protocol.h:197
xwu8_t txthd_stack[(4096U)]
Definition protocol.h:173
const char * name
Definition protocol.h:163
struct xwssc::@11 txq
struct xwssc::@12 rxq
struct xwos_object xwobj
Definition protocol.h:162
atomic_xwu32_t cnt
Definition protocol.h:177
xwu8_t id
Definition protocol.h:188
xwu8_t rxthd_stack[(4096U)]
Definition protocol.h:195
const struct xwssc_hwifal_operation * hwifops
Definition protocol.h:165
struct xwmm_bma * mempool
Definition protocol.h:170
struct xwssc_carrier * tmp
Definition protocol.h:190
struct xwos_thd txthdobj
Definition protocol.h:174
void * hwifcb
Definition protocol.h:166
操作系统抽象层:条件量
操作系统抽象层:信号量
操作系统抽象层:线程
XWSSC帧槽
Definition protocol.h:132
xwssc_ntf_f ntfcb
Definition protocol.h:134
struct xwssc_slot::@10 rx
struct xwssc_frm frm
Definition protocol.h:137
void * cbarg
Definition protocol.h:135
struct xwssc_slot::@9 tx
xwsz_t frmsize
Definition protocol.h:136
XWOS通用库:原子操作
XWOS通用库:位操作
XWOS通用库:日志
XWOS通用库:XWOS的对象
XWOS的标准头文件
SOC间点对点通讯协议:用户应用接口层