XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
master.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <xwos/lib/xwlog.h>
23#include <xwos/osal/lock/mtx.h>
24#include <xwcd/ds/spi/master.h>
25
26static __xwds_vop
28
29static __xwds_vop
31
32static __xwds_vop
34
35static __xwds_vop
37
38#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
39static __xwds_vop
41
42static __xwds_vop
44#endif
45
47 .probe = (void *)xwds_spim_vop_probe,
49 .start = (void *)xwds_spim_vop_start,
50 .stop = (void *)xwds_spim_vop_stop,
51#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
52 .suspend = (void *)xwds_spim_vop_suspend,
54#endif
55};
56
57/******** ******** ******** constructor & destructor ******** ******** ********/
59void xwds_spim_construct(struct xwds_spim * spim)
60{
62 spim->dev.vop = &xwds_spim_vop;
63}
64
66void xwds_spim_destruct(struct xwds_spim * spim)
67{
68 struct xwds_device * dev;
69
70 dev = xwds_cast(struct xwds_device *, spim);
72}
73
76{
77 return xwds_device_grab(&spim->dev);
78}
79
82{
83 return xwds_device_put(&spim->dev);
84}
85
86/******** ******** base virtual operations ******** ********/
92static __xwds_vop
94{
95 xwer_t rc;
96
98 if (rc < 0) {
99 goto err_xfer_apimtx_init;
100 }
101 rc = xwds_device_vop_probe(&spim->dev);
102 if (rc < 0) {
103 goto err_dev_probe;
104 }
105 return XWOK;
106
107err_dev_probe:
108 xwos_mtx_fini(&spim->xfer.apimtx);
109err_xfer_apimtx_init:
110 return rc;
111}
112
118static __xwds_vop
120{
121 xwer_t rc;
122
123 rc = xwds_device_vop_remove(&spim->dev);
124 if (rc < 0) {
125 goto err_dev_vop_remove;
126 }
127 xwos_mtx_fini(&spim->xfer.apimtx);
128 return XWOK;
129
130err_dev_vop_remove:
131 return rc;
132}
133
139static __xwds_vop
141{
142 xwer_t rc;
143
144 rc = xwds_device_vop_start(&spim->dev);
145 return rc;
146}
147
153static __xwds_vop
155{
156 xwer_t rc;
157
158 rc = xwds_device_vop_stop(&spim->dev);
159 return rc;
160}
161
162#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
163/******** ******** pm ******** ********/
169static __xwds_vop
171{
172 xwer_t rc;
173
174 rc = xwds_device_vop_suspend(&spim->dev);
175 return rc;
176}
177
183static __xwds_vop
185{
186 xwer_t rc;
187
188 rc = xwds_device_vop_resume(&spim->dev);
189 return rc;
190}
191#endif
192
193/******** ******** ******** SPI Master mode APIs ******** ******** ********/
196 const xwu8_t txd[], xwu8_t * rxb, xwsz_t * size,
197 xwtm_t to)
198{
199 const struct xwds_spim_driver * drv;
200 xwer_t rc;
201
202 XWDS_VALIDATE(spim, "nullptr", -EFAULT);
203 XWDS_VALIDATE(((txd) || (rxb)), "invalid", -EINVAL);
204 XWDS_VALIDATE((size), "nullptr", -EFAULT);
205
206 rc = xwds_spim_grab(spim);
207 if (rc < 0) {
208 goto err_spim_grab;
209 }
210 if (cfgid >= spim->buscfg_num) {
211 rc = -ECHRNG;
212 goto err_chrng;
213 }
214 rc = xwos_mtx_lock_to(&spim->xfer.apimtx, to);
215 if (rc < 0) {
216 goto err_spim_lock;
217 }
218 drv = xwds_cast(const struct xwds_spim_driver *, spim->dev.drv);
219 if ((drv) && (drv->xfer)) {
220 rc = drv->xfer(spim, cfgid, txd, rxb, size, to);
221 } else {
222 rc = -ENOSYS;
223 }
224 if (rc < 0) {
225 goto err_drv_xfer;
226 }
228 xwds_spim_put(spim);
229 return XWOK;
230
231err_drv_xfer:
233err_spim_lock:
234err_chrng:
235 xwds_spim_put(spim);
236err_spim_grab:
237 return rc;
238}
239
242{
243 const struct xwds_spim_driver * drv;
244 xwer_t rc;
245
246 XWDS_VALIDATE(spim, "nullptr", -EFAULT);
247
248 rc = xwds_spim_grab(spim);
249 if (rc < 0) {
250 goto err_spim_grab;
251 }
252 drv = xwds_cast(const struct xwds_spim_driver *, spim->dev.drv);
253 if ((drv) && (drv->abort)) {
254 rc = drv->abort(spim, to);
255 } else {
256 rc = -ENOSYS;
257 }
258 if (rc < 0) {
259 goto err_drv_abort;
260 }
261 xwds_spim_put(spim);
262 return XWOK;
263
264err_drv_abort:
265 xwds_spim_put(spim);
266err_spim_grab:
267 return rc;
268}
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
xwer_t xwds_spim_put(struct xwds_spim *spim)
XWDS API:减少对象的引用计数
Definition master.c:81
void xwds_spim_construct(struct xwds_spim *spim)
XWDS API:SPI主机模式控制器对象的构造函数
Definition master.c:59
xwer_t xwds_spim_grab(struct xwds_spim *spim)
XWDS API:增加对象的引用计数
Definition master.c:75
void xwds_spim_destruct(struct xwds_spim *spim)
XWDS API:SPI主机模式控制器对象的析构函数
Definition master.c:66
xwer_t xwds_spim_abort(struct xwds_spim *spim, xwtm_t to)
XWDS API:中止SPI总线传输
Definition master.c:241
xwer_t xwds_spim_xfer(struct xwds_spim *spim, xwid_t cfgid, const xwu8_t txd[], xwu8_t *rxb, xwsz_t *size, xwtm_t to)
XWDS API:启动SPI总线传输
Definition master.c:195
#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 ECHRNG
Channel number out of range
Definition errno.h:67
#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
unsigned long xwid_t
Definition type.h:481
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
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_spim_vop_start(struct xwds_spim *spim)
XWDS VOP:启动设备
Definition master.c:140
static xwer_t xwds_spim_vop_resume(struct xwds_spim *spim)
XWDS VOP:继续设备
Definition master.c:184
static xwer_t xwds_spim_vop_suspend(struct xwds_spim *spim)
XWDS VOP:暂停设备
Definition master.c:170
static xwer_t xwds_spim_vop_probe(struct xwds_spim *spim)
XWDS VOP:探测设备
Definition master.c:93
static xwer_t xwds_spim_vop_stop(struct xwds_spim *spim)
XWDS VOP:停止设备
Definition master.c:154
static xwer_t xwds_spim_vop_remove(struct xwds_spim *spim)
XWDS VOP:删除设备
Definition master.c:119
const struct xwds_virtual_operation xwds_spim_vop
Definition master.c:46
玄武设备栈:SPI:主机模式控制器
设备(所有设备的基类)
Definition device.h:127
const struct xwds_driver * drv
Definition device.h:133
const struct xwds_virtual_operation * vop
Definition device.h:138
BSP中需要提供的SPI主机模式控制器驱动函数表
Definition master.h:45
xwer_t(* abort)(struct xwds_spim *, xwtm_t)
Definition master.h:50
xwer_t(* xfer)(struct xwds_spim *, xwid_t, const xwu8_t[], xwu8_t *, xwsz_t *, xwtm_t)
Definition master.h:47
SPI主机模式控制器
Definition master.h:57
struct xwds_device dev
Definition master.h:58
xwsz_t buscfg_num
Definition master.h:62
struct xwds_spim::@25 xfer
struct xwos_mtx apimtx
Definition master.h:66
基本操作的虚函数表(类似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
玄武设备栈:顶级头文件
XWOS通用库:日志