XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
master.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <xwos/osal/lock/mtx.h>
23#include <xwcd/ds/i2c/master.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_i2cm_vop_probe,
48 .start = (void *)xwds_i2cm_vop_start,
49 .stop = (void *)xwds_i2cm_vop_stop,
50#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
51 .suspend = (void *)xwds_i2cm_vop_suspend,
53#endif
54};
55
56/******** ******** ******** constructor & destructor ******** ******** ********/
58void xwds_i2cm_construct(struct xwds_i2cm * i2cm)
59{
61 i2cm->dev.vop = &xwds_i2cm_vop;
62}
63
65void xwds_i2cm_destruct(struct xwds_i2cm * i2cm)
66{
68}
69
72{
73 return xwds_device_grab(&i2cm->dev);
74}
75
78{
79 return xwds_device_put(&i2cm->dev);
80}
81
82/******** ******** base virtual operations ******** ********/
88static __xwds_vop
90{
91 xwer_t rc;
92
93 XWDS_VALIDATE(i2cm->xwccfg, "nullptr", -EFAULT);
94
96 if (rc < 0) {
97 goto err_xfer_mtx_init;
98 }
100 if (rc < 0) {
101 goto err_abort_mtx_init;
102 }
103 rc = xwds_device_vop_probe(&i2cm->dev);
104 if (rc < 0) {
105 goto err_dev_vop_probe;
106 }
107 return XWOK;
108
109err_dev_vop_probe:
110 xwos_mtx_fini(&i2cm->abort.apimtx);
111err_abort_mtx_init:
112 xwos_mtx_fini(&i2cm->xfer.apimtx);
113err_xfer_mtx_init:
114 return rc;
115}
116
123static __xwds_vop
125{
126 xwer_t rc;
127
128 rc = xwds_device_vop_remove(&i2cm->dev);
129 if (rc < 0) {
130 goto err_dev_vop_remove;
131 }
132 xwos_mtx_fini(&i2cm->abort.apimtx);
133 xwos_mtx_fini(&i2cm->xfer.apimtx);
134 return XWOK;
135
136err_dev_vop_remove:
137 return rc;
138}
139
145static __xwds_vop
147{
148 xwer_t rc;
149
150 rc = xwds_device_vop_start(&i2cm->dev);
151 return rc;
152}
153
159static __xwds_vop
161{
162 xwer_t rc;
163
164 rc = xwds_device_vop_stop(&i2cm->dev);
165 return rc;
166}
167
168/******** ******** pm ******** ********/
169#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
175static __xwds_vop
177{
178 xwer_t rc;
179
180 rc = xwds_device_vop_suspend(&i2cm->dev);
181 return rc;
182}
183
189static __xwds_vop
191{
192 xwer_t rc;
193
194 rc = xwds_device_vop_resume(&i2cm->dev);
195 return rc;
196}
197#endif
198
199/******** ******** ******** APIs ******** ******** ********/
201xwer_t xwds_i2cm_xfer(struct xwds_i2cm * i2cm, struct xwds_i2c_msg * msg, xwtm_t to)
202{
203 xwer_t rc;
204 const struct xwds_i2cm_driver * drv;
205
206 XWDS_VALIDATE(i2cm, "nullptr", -EFAULT);
207 XWDS_VALIDATE(msg, "nullptr", -EFAULT);
208 XWDS_VALIDATE((msg->flag & XWDS_I2C_F_DIRMSK), "no-direction", -EINVAL);
209
210 rc = xwds_i2cm_grab(i2cm);
211 if (rc < 0) {
212 goto err_i2cm_grab;
213 }
214 rc = xwos_mtx_lock_to(&i2cm->xfer.apimtx, to);
215 if (rc < 0) {
216 goto err_i2cm_lock;
217 }
218 drv = xwds_cast(const struct xwds_i2cm_driver *, i2cm->dev.drv);
219 if ((drv) && (drv->xfer)) {
220 rc = drv->xfer(i2cm, msg, to);
221 } else {
222 rc = -ENOSYS;
223 }
224 if (rc < 0) {
225 goto err_drv_xfer;
226 }
228 xwds_i2cm_put(i2cm);
229 return XWOK;
230
231err_drv_xfer:
233err_i2cm_lock:
234 xwds_i2cm_put(i2cm);
235err_i2cm_grab:
236 return rc;
237}
238
241 xwu16_t address, xwu16_t addrmode,
242 xwtm_t to)
243{
244 xwer_t rc;
245 const struct xwds_i2cm_driver * drv;
246
247 XWDS_VALIDATE(i2cm, "nullptr", -EFAULT);
248
249 rc = xwds_i2cm_grab(i2cm);
250 if (rc < 0) {
251 goto err_i2cm_grab;
252 }
253 rc = xwos_mtx_lock_to(&i2cm->abort.apimtx, to);
254 if (rc < 0) {
255 goto err_i2cm_lock;
256 }
257 drv = xwds_cast(const struct xwds_i2cm_driver *, i2cm->dev.drv);
258 if ((drv) && (drv->abort)) {
259 rc = drv->abort(i2cm, address, addrmode, to);
260 } else {
261 rc = -ENOSYS;
262 }
263 if (rc < 0) {
264 goto err_drv_abort;
265 }
267 xwds_i2cm_put(i2cm);
268 return XWOK;
269
270err_drv_abort:
272err_i2cm_lock:
273 xwds_i2cm_put(i2cm);
274err_i2cm_grab:
275 return rc;
276}
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_i2cm_construct(struct xwds_i2cm *i2cm)
XWDS API:I2C主机控制器的构造函数
Definition master.c:58
xwer_t xwds_i2cm_xfer(struct xwds_i2cm *i2cm, struct xwds_i2c_msg *msg, xwtm_t to)
XWDS API:传输I2C消息
Definition master.c:201
xwer_t xwds_i2cm_put(struct xwds_i2cm *i2cm)
XWDS API:减少对象的引用计数
Definition master.c:77
void xwds_i2cm_destruct(struct xwds_i2cm *i2cm)
XWDS API:I2C主机控制器对象的析构函数
Definition master.c:65
xwer_t xwds_i2cm_abort(struct xwds_i2cm *i2cm, xwu16_t address, xwu16_t addrmode, xwtm_t to)
XWDS API:中止I2C总线传输
Definition master.c:240
xwer_t xwds_i2cm_grab(struct xwds_i2cm *i2cm)
XWDS API:增加对象的引用计数
Definition master.c:71
@ XWDS_I2C_F_DIRMSK
Definition common.h:44
#define xwds_cast(type, dev)
Definition standard.h:40
#define __xwds_vop
Definition standard.h:36
#define __xwds_api
Definition standard.h:33
#define XWDS_VALIDATE(exp, errstr,...)
Definition standard.h:51
#define __xwds_rodata
Definition standard.h:38
#define EINVAL
Invalid argument
Definition errno.h:52
#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
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
signed long xwer_t
Definition type.h:554
uint16_t xwu16_t
Definition type.h:230
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_i2cm_vop_resume(struct xwds_i2cm *i2cm)
XWDS VOP:继续I2C主机控制器
Definition master.c:190
static xwer_t xwds_i2cm_vop_stop(struct xwds_i2cm *i2cm)
XWDS VOP:停止I2C主机控制器
Definition master.c:160
static xwer_t xwds_i2cm_vop_remove(struct xwds_i2cm *i2cm)
XWDS VOP:移除I2C主机控制器
Definition master.c:124
static xwer_t xwds_i2cm_vop_probe(struct xwds_i2cm *i2cm)
XWDS VOP:探测I2C主机控制器
Definition master.c:89
static xwer_t xwds_i2cm_vop_start(struct xwds_i2cm *i2cm)
XWDS VOP:启动I2C主机控制器
Definition master.c:146
const struct xwds_virtual_operation xwds_i2cm_vop
Definition master.c:45
static xwer_t xwds_i2cm_vop_suspend(struct xwds_i2cm *i2cm)
XWDS VOP:暂停I2C主机控制器
Definition master.c:176
玄武设备栈:I2C:主机
操作系统抽象层:互斥锁
const struct xwds_driver * drv
Definition device.h:133
const struct xwds_virtual_operation * vop
Definition device.h:138
I2C消息
Definition common.h:62
xwu16_t flag
Definition common.h:66
BSP中需要提供的I2C主机驱动函数表
Definition master.h:40
xwer_t(* xfer)(struct xwds_i2cm *, struct xwds_i2c_msg *, xwtm_t)
Definition master.h:42
xwer_t(* abort)(struct xwds_i2cm *, xwu16_t, xwu16_t, xwtm_t)
Definition master.h:45
I2C主机
Definition master.h:53
struct xwds_i2cm::@17 xfer
void * xwccfg
Definition master.h:57
struct xwds_device dev
Definition master.h:54
struct xwds_i2cm::@18 abort
struct xwos_mtx apimtx
Definition master.h:61
基本操作的虚函数表(类似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
玄武设备栈:顶级头文件