XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
controller.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <xwos/osal/lock/mtx.h>
24
25static __xwds_vop
27
28static __xwds_vop
30
31static __xwds_vop
33
34static __xwds_vop
36
37#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
38static __xwds_vop
40
41static __xwds_vop
43#endif
44
46 .probe = (void *)xwds_linc_vop_probe,
48 .start = (void *)xwds_linc_vop_start,
49 .stop = (void *)xwds_linc_vop_stop,
50#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
51 .suspend = (void *)xwds_linc_vop_suspend,
53#endif
54};
55
56/******** ******** ******** constructor & destructor ******** ******** ********/
58void xwds_linc_construct(struct xwds_linc * linc)
59{
61 linc->dev.vop = &xwds_linc_vop;
62}
63
65void xwds_linc_destruct(struct xwds_linc * linc)
66{
68}
69
72{
73 return xwds_device_grab(&linc->dev);
74}
75
78{
79 return xwds_device_put(&linc->dev);
80}
81
82/******** ******** base virtual operations ******** ********/
87static __xwds_vop
89{
90 xwer_t rc;
91
93 if (rc < 0) {
94 goto err_mtx_init;
95 }
96 if (is_err_or_null(linc->get_msg_size)) {
98 }
99 rc = xwds_device_vop_probe(&linc->dev);
100 if (rc < 0) {
101 goto err_dev_vop_probe;
102 }
103 return XWOK;
104
105err_dev_vop_probe:
106 xwos_mtx_fini(&linc->txlock);
107err_mtx_init:
108 return rc;
109}
110
115static __xwds_vop
117{
118 xwer_t rc;
119
120 rc = xwds_device_vop_remove(&linc->dev);
121 if (rc < 0) {
122 goto err_dev_vop_remove;
123 }
124 xwos_mtx_fini(&linc->txlock);
125 return XWOK;
126
127err_dev_vop_remove:
128 return rc;
129}
130
135static __xwds_vop
137{
138 xwer_t rc;
139
140 rc = xwds_device_vop_start(&linc->dev);
141 return rc;
142}
143
148static __xwds_vop
150{
151 xwer_t rc;
152
153 rc = xwds_device_vop_stop(&linc->dev);
154 return rc;
155}
156
157#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
158/******** ******** pm ******** ********/
163static __xwds_vop
165{
166 xwer_t rc;
167
168 rc = xwds_device_vop_suspend(&linc->dev);
169 return rc;
170}
171
176static __xwds_vop
178{
179 xwer_t rc;
180
181 rc = xwds_device_vop_resume(&linc->dev);
182 return rc;
183}
184#endif
185
186/******** ******** ******** APIs ******** ******** ********/
189 xwu8_t id, struct xwds_lin_msg * msg,
190 xwtm_t to)
191{
192 xwer_t rc;
193 const struct xwds_linc_driver * drv;
194
195 XWDS_VALIDATE(linc, "nullptr", -EFAULT);
196 XWDS_VALIDATE(msg, "nullptr", -EFAULT);
197
198 rc = xwds_linc_grab(linc);
199 if (rc < 0) {
200 goto err_linc_grab;
201 }
202 rc = xwos_mtx_lock_to(&linc->txlock, to);
203 if (rc < 0) {
204 goto err_linc_txlock;
205 }
206 drv = xwds_cast(const struct xwds_linc_driver *, linc->dev.drv);
207 if ((drv) && (drv->msttx)) {
208 rc = drv->msttx(linc, id, msg, to);
209 } else {
210 rc = -ENOSYS;
211 }
212 if (rc < 0) {
213 goto err_drv_msttx;
214 }
215 xwos_mtx_unlock(&linc->txlock);
216 xwds_linc_put(linc);
217 return XWOK;
218
219err_drv_msttx:
220 xwos_mtx_unlock(&linc->txlock);
221err_linc_txlock:
222 xwds_linc_put(linc);
223err_linc_grab:
224 return rc;
225}
226
229 struct xwds_lin_msg * msg,
230 xwtm_t to)
231{
232 xwer_t rc;
233 const struct xwds_linc_driver * drv;
234
235 XWDS_VALIDATE(linc, "nullptr", -EFAULT);
236 XWDS_VALIDATE(msg, "nullptr", -EFAULT);
237
238 rc = xwds_linc_grab(linc);
239 if (rc < 0) {
240 goto err_linc_grab;
241 }
242 rc = xwos_mtx_lock_to(&linc->txlock, to);
243 if (rc < 0) {
244 goto err_linc_txlock;
245 }
246 drv = xwds_cast(const struct xwds_linc_driver *, linc->dev.drv);
247 if ((drv) && (drv->slvtx)) {
248 rc = drv->slvtx(linc, msg, to);
249 } else {
250 rc = -ENOSYS;
251 }
252 if (rc < 0) {
253 goto err_drv_slvtx;
254 }
255 xwos_mtx_unlock(&linc->txlock);
256 xwds_linc_put(linc);
257 return XWOK;
258
259err_drv_slvtx:
260 xwos_mtx_unlock(&linc->txlock);
261err_linc_txlock:
262 xwds_linc_put(linc);
263err_linc_grab:
264 return rc;
265}
266
269 struct xwds_lin_msg * msgbuf,
270 xwtm_t to)
271{
272 xwer_t rc;
273 const struct xwds_linc_driver * drv;
274
275 XWDS_VALIDATE(linc, "nullptr", -EFAULT);
276 XWDS_VALIDATE(msgbuf, "nullptr", -EFAULT);
277
278 rc = xwds_linc_grab(linc);
279 if (rc < 0) {
280 goto err_linc_grab;
281 }
282 drv = xwds_cast(const struct xwds_linc_driver *, linc->dev.drv);
283 if ((drv) && (drv->rx)) {
284 rc = drv->rx(linc, msgbuf, to);
285 } else {
286 rc = -ENOSYS;
287 }
288 if (rc < 0) {
289 goto err_drv_rx;
290 }
291 xwds_linc_put(linc);
292 return XWOK;
293
294err_drv_rx:
295 xwds_linc_put(linc);
296err_linc_grab:
297 return rc;
298}
299
302 xwu8_t protected_id,
303 xwu8_t * ret)
304{
305 const struct xwds_lin_msg_info * msgitbl;
306 xwsz_t itemnum;
307 xwer_t rc;
308 xwsq_t i;
309
310 XWDS_VALIDATE(linc, "nullptr", -EFAULT);
311 XWDS_VALIDATE(ret, "nullptr", -EFAULT);
312
313 msgitbl = linc->msgitable;
314 itemnum = linc->msgitable_itemnum;
315 rc = -ENODEV;
316 if (!is_err_or_null(msgitbl)) {
317 for (i = 0; i < itemnum; i++) {
318 if (protected_id == msgitbl[i].protected_id) {
319 *ret = msgitbl[i].size;
320 rc = XWOK;
321 break;
322 }
323 }
324 if (-ENODEV == rc) {
326 }
327 } else {
328 rc = XWOK;
330 }
331 return rc;
332}
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
void xwds_linc_destruct(struct xwds_linc *linc)
XWDS API:LIN控制器对象的析构函数
Definition controller.c:65
xwer_t xwds_linc_get_msg_size(struct xwds_linc *linc, xwu8_t protected_id, xwu8_t *ret)
XWDS API:通过LIN保护ID查询消息大小
Definition controller.c:301
void xwds_linc_construct(struct xwds_linc *linc)
XWDS API:LIN控制器的构造函数
Definition controller.c:58
xwer_t xwds_linc_grab(struct xwds_linc *linc)
XWDS API:增加对象的引用计数
Definition controller.c:71
xwer_t xwds_linc_rx(struct xwds_linc *linc, struct xwds_lin_msg *msgbuf, xwtm_t to)
XWDS API:接收一条LIN消息
Definition controller.c:268
xwer_t xwds_linc_slvtx(struct xwds_linc *linc, struct xwds_lin_msg *msg, xwtm_t to)
XWDS API:从机节点发送一条LIN消息
Definition controller.c:228
#define XWDS_LIN_DEFAULT_DATA_SIZE
Definition controller.h:37
xwer_t xwds_linc_put(struct xwds_linc *linc)
XWDS API:减少对象的引用计数
Definition controller.c:77
xwer_t xwds_linc_msttx(struct xwds_linc *linc, xwu8_t id, struct xwds_lin_msg *msg, xwtm_t to)
XWDS API:主机节点发送一条LIN消息
Definition controller.c:188
#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 XWOK
No error
Definition errno.h:182
#define ENODEV
No such device
Definition errno.h:49
static __xwcc_inline bool __xwcc_must_check is_err_or_null(const void *ptr)
测试指针的值是否为空或错误码(指针是否为无效指针)
Definition error.h:77
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
signed long xwer_t
Definition type.h:554
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
unsigned long xwsq_t
Definition type.h:445
static xwer_t xwos_mtx_init(struct xwos_mtx *mtx, xwpr_t sprio)
XWOS API:静态方式初始化互斥锁
Definition mtx.h:111
static xwer_t xwos_mtx_lock_to(struct xwos_mtx *mtx, xwtm_t to)
XWOS API:限时等待上锁互斥锁
Definition mtx.h:329
static xwer_t xwos_mtx_fini(struct xwos_mtx *mtx)
XWOS API:销毁静态方式初始化的互斥锁
Definition mtx.h:126
static xwer_t xwos_mtx_unlock(struct xwos_mtx *mtx)
XWOS API:解锁互斥锁
Definition mtx.h:279
#define XWOS_SKD_PRIORITY_RT_MIN
XWOS API:最小实时优先级
Definition skd.h:89
static xwer_t xwds_linc_vop_resume(struct xwds_linc *linc)
XWDS VOP:继续LIN控制器
Definition controller.c:177
const struct xwds_virtual_operation xwds_linc_vop
Definition controller.c:45
static xwer_t xwds_linc_vop_remove(struct xwds_linc *linc)
XWDS VOP:移除LIN控制器
Definition controller.c:116
static xwer_t xwds_linc_vop_start(struct xwds_linc *linc)
XWDS VOP:启动LIN控制器
Definition controller.c:136
static xwer_t xwds_linc_vop_suspend(struct xwds_linc *linc)
XWDS VOP:暂停LIN控制器
Definition controller.c:164
static xwer_t xwds_linc_vop_stop(struct xwds_linc *linc)
XWDS VOP:停止LIN控制器
Definition controller.c:149
static xwer_t xwds_linc_vop_probe(struct xwds_linc *linc)
XWDS VOP:探测LIN控制器
Definition controller.c:88
玄武设备栈:LIN:控制器
操作系统抽象层:互斥锁
const struct xwds_driver * drv
Definition device.h:133
const struct xwds_virtual_operation * vop
Definition device.h:138
LIN消息信息
Definition controller.h:68
LIN消息结构体
Definition controller.h:59
LIN控制器驱动函数表
Definition controller.h:94
xwer_t(* msttx)(struct xwds_linc *, xwu8_t, struct xwds_lin_msg *, xwtm_t)
Definition controller.h:96
xwer_t(* rx)(struct xwds_linc *, struct xwds_lin_msg *, xwtm_t)
Definition controller.h:100
xwer_t(* slvtx)(struct xwds_linc *, struct xwds_lin_msg *, xwtm_t)
Definition controller.h:98
LIN控制器
Definition controller.h:107
xwsz_t msgitable_itemnum
Definition controller.h:113
struct xwds_device dev
Definition controller.h:108
struct xwos_mtx txlock
Definition controller.h:122
xwer_t(* get_msg_size)(struct xwds_linc *, xwu8_t, xwu8_t *)
Definition controller.h:114
const struct xwds_lin_msg_info * msgitable
Definition controller.h:112
基本操作的虚函数表(类似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
玄武设备栈:顶级头文件