XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
transceiver.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <string.h>
23#include <xwos/lib/xwlog.h>
24#include <xwos/lib/xwaop.h>
26
27static __xwds_vop
29
30static __xwds_vop
32
33static __xwds_vop
35
36static __xwds_vop
38
39#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
40static __xwds_vop
42
43static __xwds_vop
45#endif
46
50 .start = (void *)xwds_cantrcv_vop_start,
51 .stop = (void *)xwds_cantrcv_vop_stop,
52#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
53 .suspend = (void *)xwds_cantrcv_vop_suspend,
55#endif
56};
57
58/******** ******** ******** constructor & destructor ******** ******** ********/
61{
62 xwds_device_construct(&cantrcv->bc.dev);
63 cantrcv->bc.dev.vop = &xwds_cantrcv_vop;
64}
65
67void xwds_cantrcv_destruct(struct xwds_cantrcv * cantrcv)
68{
69 xwds_device_destruct(&cantrcv->bc.dev);
70}
71
74{
75 return xwds_device_grab(&cantrcv->bc.dev);
76}
77
80{
81 return xwds_device_put(&cantrcv->bc.dev);
82}
83
84/******** ******** base virtual operations ******** ********/
89static __xwds_vop
91{
92 xwer_t rc;
93
94 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
95 XWDS_VALIDATE(cantrcv->cfg, "nullptr", -EFAULT);
96
97 rc = xwds_device_vop_probe(&cantrcv->bc.dev);
98 return rc;
99}
100
105static __xwds_vop
107{
108 xwer_t rc;
109
110 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
111 XWDS_VALIDATE(cantrcv->cfg, "nullptr", -EFAULT);
112
113 rc = xwds_device_vop_remove(&cantrcv->bc.dev);
114 return rc;
115}
116
121static __xwds_vop
123{
124 xwer_t rc;
125
126 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
127 XWDS_VALIDATE(cantrcv->cfg, "nullptr", -EFAULT);
128
129 rc = xwds_device_vop_start(&cantrcv->bc.dev);
130 if (rc < 0) {
131 goto err_dev_vop_start;
132 }
134 rc = xwds_cantrcv_set_opmode(cantrcv, cantrcv->cfg->init_opmode);
135 if (rc < 0) {
136 goto err_set_opmode;
137 }
138 return XWOK;
139
140err_set_opmode:
141 xwds_device_vop_stop(&cantrcv->bc.dev);
142err_dev_vop_start:
143 return rc;
144}
145
150static __xwds_vop
152{
153 xwer_t rc;
154
155 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
156
157 rc = xwds_device_vop_stop(&cantrcv->bc.dev);
158 return rc;
159}
160
161#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
162/******** ******** pm ******** ********/
167static __xwds_vop
169{
170 xwer_t rc;
171
172 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
173
174 rc = xwds_device_vop_suspend(&cantrcv->bc.dev);
175 return rc;
176}
177
182static __xwds_vop
184{
185 xwer_t rc;
186
187 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
188
189 rc = xwds_device_vop_resume(&cantrcv->bc.dev);
190 return rc;
191}
192#endif
193
194/******** ******** ******** CAN operations ******** ******** ********/
197{
198 xwer_t rc;
199 const struct xwds_cantrcv_driver * drv;
200
201 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
202 XWDS_VALIDATE((opmode < XWDS_CANTRCV_OPMODE_NUM), "out-of-range", -ERANGE);
203
204 drv = xwds_cast(const struct xwds_cantrcv_driver *, cantrcv->bc.dev.drv);
205 if ((drv) && (drv->set_opmode)) {
206 rc = drv->set_opmode(cantrcv, opmode);
207 } else {
208 rc = -ENOSYS;
209 }
210 if (rc < 0) {
211 goto err_ops_set_opmode;
212 }
213 cantrcv->opmode = opmode;
214 return XWOK;
215
216err_ops_set_opmode:
217 return rc;
218}
219
221void xwds_cantrcv_get_opmode(struct xwds_cantrcv * cantrcv, xwsq_t * opmode)
222{
223 XWDS_VALIDATE(cantrcv, "nullptr");
224 XWDS_VALIDATE(opmode, "nullptr");
225
226 *opmode = cantrcv->opmode;
227}
228
231{
232 xwer_t rc;
233 const struct xwds_cantrcv_driver * drv;
234 const struct xwds_cantrcv_cfg * cfg;
235
236 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
237
238 cfg = cantrcv->cfg;
239 if (cfg->wkup_supported) {
240 drv = xwds_cast(const struct xwds_cantrcv_driver *,
241 cantrcv->bc.dev.drv);
242 if ((drv) && (drv->enable_wkup)) {
243 rc = drv->enable_wkup(cantrcv);
244 } else {
245 rc = -ENOSYS;
246 }
247 } else {
248 rc = -EOPNOTSUPP;
249 }
250 return rc;
251}
252
255{
256 xwer_t rc;
257 const struct xwds_cantrcv_driver * drv;
258 const struct xwds_cantrcv_cfg * cfg;
259
260 XWDS_VALIDATE(cantrcv, "nullptr", -EFAULT);
261
262 cfg = cantrcv->cfg;
263 if (cfg->wkup_supported) {
264 drv = xwds_cast(const struct xwds_cantrcv_driver *,
265 cantrcv->bc.dev.drv);
266 if ((drv) && (drv->disable_wkup)) {
267 rc = drv->disable_wkup(cantrcv);
268 } else {
269 rc = -ENOSYS;
270 }
271 } else {
272 rc = -EOPNOTSUPP;
273 }
274 return rc;
275}
276
280{
281 cantrcv->wkup_isr = isr;
282}
283
285void xwds_cantrcv_get_wkuprs(struct xwds_cantrcv * cantrcv, xwsq_t * wkuprs)
286{
287 const struct xwds_cantrcv_cfg * cfg;
288
289 XWDS_VALIDATE(cantrcv, "nullptr");
290 XWDS_VALIDATE(wkuprs, "nullptr");
291
292 cfg = cantrcv->cfg;
293 if (cfg->wkup_supported) {
294 *wkuprs = cantrcv->wkuprs;
295 } else {
297 }
298}
299
302{
303 XWDS_VALIDATE(cantrcv, "nullptr");
304
306}
307
310{
311 if (cantrcv->wkup_isr) {
312 cantrcv->wkup_isr(cantrcv, cantrcv->canc);
313 }/* else {} */
314}
void xwds_cantrcv_destruct(struct xwds_cantrcv *cantrcv)
XWDS API:CAN接收器对象的析构函数
Definition transceiver.c:67
void xwds_cantrcv_set_wkup_isr(struct xwds_cantrcv *cantrcv, xwds_cantrcv_wkup_isr_f isr)
XWDS API:设置唤醒中断的回调函数
void xwds_cantrcv_drvcb_wakeup_notification(struct xwds_cantrcv *cantrcv)
CAN接收器回调函数:CAN接收器的唤醒通知
void(* xwds_cantrcv_wkup_isr_f)(struct xwds_cantrcv *, struct xwds_canc *)
唤醒中断回调函数
Definition transceiver.h:80
xwer_t xwds_cantrcv_put(struct xwds_cantrcv *cantrcv)
XWDS API:减少对象的引用计数
Definition transceiver.c:79
void xwds_cantrcv_get_wkuprs(struct xwds_cantrcv *cantrcv, xwsq_t *wkuprs)
XWDS API:获取CAN接收器的唤醒原因
xwer_t xwds_cantrcv_enable_wkup(struct xwds_cantrcv *cantrcv)
XWDS API:开启CAN接收器的唤醒
void xwds_cantrcv_construct(struct xwds_cantrcv *cantrcv)
XWDS API:CAN接收器的构造函数
Definition transceiver.c:60
void xwds_cantrcv_clear_wkuprs(struct xwds_cantrcv *cantrcv)
XWDS API:清除CAN接收器的唤醒原因
xwer_t xwds_cantrcv_disable_wkup(struct xwds_cantrcv *cantrcv)
XWDS API:关闭CAN接收器的唤醒
xwer_t xwds_cantrcv_set_opmode(struct xwds_cantrcv *cantrcv, xwsq_t opmode)
XWDS API:设置CAN接收器的运行模式
void xwds_cantrcv_get_opmode(struct xwds_cantrcv *cantrcv, xwsq_t *opmode)
XWDS API:设置CAN接收器的模式
xwer_t xwds_cantrcv_grab(struct xwds_cantrcv *cantrcv)
XWDS API:增加对象的引用计数
Definition transceiver.c:73
@ XWDS_CANTRCV_OPMODE_NUM
Definition transceiver.h:44
@ XWDS_CANTRCV_WKUPRS_NOT_SUPPORTED
Definition transceiver.h:61
@ XWDS_CANTRCV_WKUPRS_NONE
Definition transceiver.h:51
static xwer_t xwds_device_grab(struct xwds_device *dev)
XWDS API:增加对象的引用计数
Definition device.h:268
xwer_t xwds_device_vop_start(struct xwds_device *dev)
设备基本操作函数:启动设备
Definition device.c:105
void xwds_device_construct(struct xwds_device *dev)
XWDS API:设备的构造函数
Definition device.c:48
void xwds_device_destruct(struct xwds_device *dev)
XWDS API:设备的析构函数
Definition device.c:56
static xwer_t xwds_device_put(struct xwds_device *dev)
XWDS API:减少对象的引用计数
Definition device.h:281
xwer_t xwds_device_vop_stop(struct xwds_device *dev)
设备基本操作函数:停止设备
Definition device.c:124
xwer_t xwds_device_vop_remove(struct xwds_device *dev)
设备基本操作函数:删除设备
Definition device.c:86
xwer_t xwds_device_vop_resume(struct xwds_device *dev)
设备基本操作函数:继续设备
Definition device.c:163
xwer_t xwds_device_vop_probe(struct xwds_device *dev)
设备基本操作函数:探测设备
Definition device.c:67
xwer_t xwds_device_vop_suspend(struct xwds_device *dev)
设备基本操作函数:暂停设备
Definition device.c:144
#define xwds_cast(type, dev)
Definition standard.h:40
#define __xwds_vop
Definition standard.h:36
#define __xwds_code
Definition standard.h:31
#define __xwds_api
Definition standard.h:33
#define XWDS_VALIDATE(exp, errstr,...)
Definition standard.h:51
#define __xwds_rodata
Definition standard.h:38
#define EFAULT
Bad address
Definition errno.h:44
#define ENOSYS
Function not implemented
Definition errno.h:110
#define EOPNOTSUPP
Operation not supported on socket
Definition errno.h:115
#define XWOK
No error
Definition errno.h:182
#define ERANGE
Result too large
Definition errno.h:64
signed long xwer_t
Definition type.h:554
unsigned long xwsq_t
Definition type.h:445
CAN接收器配置
Definition transceiver.h:85
BSP中需要提供的CAN接收器驱动函数表
Definition transceiver.h:96
xwer_t(* disable_wkup)(struct xwds_cantrcv *)
xwer_t(* enable_wkup)(struct xwds_cantrcv *)
Definition transceiver.h:99
xwer_t(* set_opmode)(struct xwds_cantrcv *, xwsq_t)
Definition transceiver.h:98
CAN接收器
struct xwds_canc * canc
union xwds_cantrcv::@16 bc
struct xwds_device dev
const struct xwds_cantrcv_cfg * cfg
xwds_cantrcv_wkup_isr_f wkup_isr
const struct xwds_driver * drv
Definition device.h:133
const struct xwds_virtual_operation * vop
Definition device.h:138
基本操作的虚函数表(类似C++的虚函数表)
Definition device.h:99
xwer_t(* stop)(struct xwds_device *)
Definition device.h:103
xwer_t(* remove)(struct xwds_device *)
Definition device.h:101
xwer_t(* probe)(struct xwds_device *)
Definition device.h:100
xwer_t(* resume)(struct xwds_device *)
Definition device.h:106
static xwer_t xwds_cantrcv_vop_stop(struct xwds_cantrcv *cantrcv)
XWDS VOP:停止CAN接收器
static xwer_t xwds_cantrcv_vop_start(struct xwds_cantrcv *cantrcv)
XWDS VOP:启动CAN接收器
static xwer_t xwds_cantrcv_vop_remove(struct xwds_cantrcv *cantrcv)
XWDS VOP:移除CAN接收器
static xwer_t xwds_cantrcv_vop_suspend(struct xwds_cantrcv *cantrcv)
XWDS VOP:暂停CAN接收器
static xwer_t xwds_cantrcv_vop_resume(struct xwds_cantrcv *cantrcv)
XWDS VOP:继续CAN接收器
const struct xwds_virtual_operation xwds_cantrcv_vop
Definition transceiver.c:47
static xwer_t xwds_cantrcv_vop_probe(struct xwds_cantrcv *cantrcv)
XWDS VOP:探测CAN接收器
Definition transceiver.c:90
玄武设备栈:CAN:总线接收器
XWOS通用库:原子操作
玄武设备栈:顶级头文件
XWOS通用库:日志