XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
I2C主机 的协作图:

结构体

struct  xwds_i2cm_driver
 BSP中需要提供的I2C主机驱动函数表 更多...
 
struct  xwds_i2cm
 I2C主机 更多...
 

函数

void xwds_i2cm_construct (struct xwds_i2cm *i2cm)
 XWDS API:I2C主机控制器的构造函数
 
void xwds_i2cm_destruct (struct xwds_i2cm *i2cm)
 XWDS API:I2C主机控制器对象的析构函数
 
xwer_t xwds_i2cm_grab (struct xwds_i2cm *i2cm)
 XWDS API:增加对象的引用计数
 
xwer_t xwds_i2cm_put (struct xwds_i2cm *i2cm)
 XWDS API:减少对象的引用计数
 
xwer_t xwds_i2cm_xfer (struct xwds_i2cm *i2cm, struct xwds_i2c_msg *msg, xwsz_t num, xwtm_t to)
 XWDS API:传输I2C消息
 

详细描述

函数说明

◆ xwds_i2cm_construct()

void xwds_i2cm_construct ( struct xwds_i2cm i2cm)

XWDS API:I2C主机控制器的构造函数

参数
[in]i2cmI2C主机控制器对象指针

在文件 master.c58 行定义.

59{
61 i2cm->dev.vop = &xwds_i2cm_vop;
62}
void xwds_device_construct(struct xwds_device *dev)
XWDS API:设备的构造函数
Definition device.c:48
const struct xwds_virtual_operation xwds_i2cm_vop
Definition master.c:45
const struct xwds_virtual_operation * vop
Definition device.h:138
struct xwds_device dev
Definition master.h:54
函数调用图:

◆ xwds_i2cm_destruct()

void xwds_i2cm_destruct ( struct xwds_i2cm i2cm)

XWDS API:I2C主机控制器对象的析构函数

参数
[in]i2cmI2C主机控制器对象指针

在文件 master.c65 行定义.

66{
68}
void xwds_device_destruct(struct xwds_device *dev)
XWDS API:设备的析构函数
Definition device.c:56
函数调用图:

◆ xwds_i2cm_grab()

xwer_t xwds_i2cm_grab ( struct xwds_i2cm i2cm)

XWDS API:增加对象的引用计数

参数
[in]i2cmI2C主机控制器对象指针

在文件 master.c71 行定义.

72{
73 return xwds_device_grab(&i2cm->dev);
74}
static xwer_t xwds_device_grab(struct xwds_device *dev)
XWDS API:增加对象的引用计数
Definition device.h:268
函数调用图:
这是这个函数的调用关系图:

◆ xwds_i2cm_put()

xwer_t xwds_i2cm_put ( struct xwds_i2cm i2cm)

XWDS API:减少对象的引用计数

参数
[in]i2cmI2C主机控制器对象指针

在文件 master.c77 行定义.

78{
79 return xwds_device_put(&i2cm->dev);
80}
static xwer_t xwds_device_put(struct xwds_device *dev)
XWDS API:减少对象的引用计数
Definition device.h:281
函数调用图:
这是这个函数的调用关系图:

◆ xwds_i2cm_xfer()

xwer_t xwds_i2cm_xfer ( struct xwds_i2cm i2cm,
struct xwds_i2c_msg msg,
xwsz_t  num,
xwtm_t  to 
)

XWDS API:传输I2C消息

参数
[in]i2cmI2C主机控制器对象指针
[in,out]msgI2C消息结构体的指针
  • (I) addr: 地址,只作为输入
  • (I) flag: 传输标志,只作为输入,取值:
    • 地址标志:
      • XWDS_I2C_F_10BITADDR:
        • 置1:10位地址
        • 清0:7位地址
    • 方向标志:
    • 产生开始条件标志:

data: 数据缓冲区:

  • (I) 当方向标志为读时,只作为输入缓冲区
  • (O) 当方向标志为写时,只作为输出缓冲区

size: 传输的字节数

  • (I) 当作为输入时,表示请求传输的字节数
  • (O) 当作为输出时,返回实际传输的字节数
    参数
    [in]numI2C消息结构体的数量
    [in]to期望唤醒的时间点
    返回
    错误码
    返回值
    XWOK没有错误
    -EINVAL设备对象不可引用
    -ESHUTDOWN设备没有运行
    -EADDRNOTAVAIL地址无响应
    -ETIMEDOUT超时
    注解

上下文:线程

to 表示等待超时的时间点:

  • to 通常是未来的时间,即 当前系统时间 + delta , 可以使用 xwtm_ft(delta) 表示;
  • 如果 to 是过去的时间点,将直接返回 -ETIMEDOUT

<No error

在文件 master.c201 行定义.

204{
205 xwer_t rc;
206 const struct xwds_i2cm_driver * drv;
207
208 XWDS_VALIDATE(i2cm, "nullptr", -EFAULT);
209 XWDS_VALIDATE(msg, "nullptr", -EFAULT);
210 XWDS_VALIDATE((msg->flag & XWDS_I2C_F_DIRMSK), "no-direction", -EINVAL);
211
212 rc = xwds_i2cm_grab(i2cm);
213 if (rc < 0) {
214 goto err_i2cm_grab;
215 }
216 rc = xwos_mtx_lock_to(&i2cm->xfer.apimtx, to);
217 if (rc < 0) {
218 goto err_i2cm_lock;
219 }
220 drv = xwds_cast(const struct xwds_i2cm_driver *, i2cm->dev.drv);
221 if ((drv) && (drv->xfer)) {
222 rc = drv->xfer(i2cm, msg, num, to);
223 } else {
224 rc = -ENOSYS;
225 }
226 if (rc < 0) {
227 goto err_drv_xfer;
228 }
230 xwds_i2cm_put(i2cm);
231 return XWOK;
232
233err_drv_xfer:
235err_i2cm_lock:
236 xwds_i2cm_put(i2cm);
237err_i2cm_grab:
238 return rc;
239}
xwer_t xwds_i2cm_put(struct xwds_i2cm *i2cm)
XWDS API:减少对象的引用计数
Definition master.c:77
xwer_t xwds_i2cm_grab(struct xwds_i2cm *i2cm)
XWDS API:增加对象的引用计数
Definition master.c:71
@ XWDS_I2C_F_DIRMSK
Definition common.h:40
#define xwds_cast(type, dev)
Definition standard.h:40
#define XWDS_VALIDATE(exp, errstr,...)
Definition standard.h:51
#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
signed long xwer_t
Definition type.h:554
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_unlock(struct xwos_mtx *mtx)
XWOS API:解锁互斥锁
Definition mtx.h:279
const struct xwds_driver * drv
Definition device.h:133
xwu16_t flag
Definition common.h:53
BSP中需要提供的I2C主机驱动函数表
Definition master.h:40
xwer_t(* xfer)(struct xwds_i2cm *, struct xwds_i2c_msg *, xwsz_t, xwtm_t)
Definition master.h:42
struct xwds_i2cm::@17 xfer
struct xwos_mtx apimtx
Definition master.h:61
函数调用图:
这是这个函数的调用关系图: