XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
peripheral.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
23
24static __xwds_vop
26
27static __xwds_vop
29
30static __xwds_vop
32
33static __xwds_vop
35
36#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
37static __xwds_vop
39
40static __xwds_vop
42#endif
43
45 .probe = (void *)xwds_spip_vop_probe,
47 .start = (void *)xwds_spip_vop_start,
48 .stop = (void *)xwds_spip_vop_stop,
49#if defined(XWCDCFG_ds_PM) && (1 == XWCDCFG_ds_PM)
50 .suspend = (void *)xwds_spip_vop_suspend,
52#endif
53};
54
55/******** ******** ******** constructor & destructor ******** ******** ********/
57void xwds_spip_construct(struct xwds_spip * spip)
58{
60 spip->dev.vop = &xwds_spip_vop;
61}
62
64void xwds_spip_destruct(struct xwds_spip * spip)
65{
67}
68
71{
72 return xwds_device_grab(&spip->dev);
73}
74
77{
78 return xwds_device_put(&spip->dev);
79}
80
81/******** ******** base virtual operations ******** ********/
86static __xwds_vop
88{
89 xwer_t rc;
90
91 rc = xwds_device_vop_probe(&spip->dev);
92 if (rc < 0) {
93 goto err_dev_vop_probe;
94 }
95 return XWOK;
96
97err_dev_vop_probe:
98 return rc;
99}
100
105static __xwds_vop
107{
108 xwer_t rc;
109
110 XWDS_VALIDATE(spip->bus, "nullptr", -EHOSTUNREACH);
111
112 rc = xwds_device_vop_remove(&spip->dev);
113 if (rc < 0) {
114 goto err_dev_vop_remove;
115 }
116 return XWOK;
117
118err_dev_vop_remove:
119 return rc;
120}
121
126static __xwds_vop
128{
129 xwer_t rc;
130
131 if (spip->bus) {
132 rc = xwds_spim_grab(spip->bus);
133 } else {
134 rc = -EHOSTUNREACH;
135 }
136 if (rc < 0) {
137 goto err_spim_grab;
138 }
139 rc = xwds_device_vop_start(&spip->dev);
140 if (rc < 0) {
141 goto err_dev_vop_start;
142 }
143 return XWOK;
144
145err_dev_vop_start:
146 xwds_spim_put(spip->bus);
147err_spim_grab:
148 return rc;
149}
150
155static __xwds_vop
157{
158 xwer_t rc;
159
160 XWDS_VALIDATE(spip->bus, "nullptr", -EHOSTUNREACH);
161
162 rc = xwds_device_vop_stop(&spip->dev);
163 if (rc < 0) {
164 goto err_dev_vop_stop;
165 }
166 xwds_spim_put(spip->bus);
167 return XWOK;
168
169err_dev_vop_stop:
170 return rc;
171}
172
173#if (defined(XWCDCFG_ds_PM)) && (1 == XWCDCFG_ds_PM)
174/******** ******** pm ******** ********/
179static __xwds_vop
181{
182 xwer_t rc;
183
184 XWDS_VALIDATE(spip->bus, "nullptr", -EHOSTUNREACH);
185
186 rc = xwds_device_vop_suspend(&spip->dev);
187 if (rc < 0) {
188 goto err_dev_vop_suspend;
189 }
190 xwds_spim_put(spip->bus);
191 return XWOK;
192
193err_dev_vop_suspend:
194 return rc;
195}
196
201static __xwds_vop
203{
204 xwer_t rc;
205
206 if (spip->bus) {
207 rc = xwds_spim_grab(spip->bus);
208 } else {
209 rc = -EHOSTUNREACH;
210 }
211 if (rc < 0) {
212 goto err_spim_grab;
213 }
214 rc = xwds_device_vop_resume(&spip->dev);
215 if (rc < 0) {
216 goto err_dev_vop_resume;
217 }
218 return XWOK;
219
220err_dev_vop_resume:
221 xwds_spim_put(spip->bus);
222err_spim_grab:
223 return rc;
224}
225#endif
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
xwer_t xwds_spim_grab(struct xwds_spim *spim)
XWDS API:增加对象的引用计数
Definition master.c:75
void xwds_spip_construct(struct xwds_spip *spip)
XWDS API:SPI外设控制器对象的构造函数
Definition peripheral.c:57
void xwds_spip_destruct(struct xwds_spip *spip)
XWDS API:SPI外设控制器对象的析构函数
Definition peripheral.c:64
xwer_t xwds_spip_grab(struct xwds_spip *spip)
XWDS API:增加对象的引用计数
Definition peripheral.c:70
xwer_t xwds_spip_put(struct xwds_spip *spip)
XWDS API:减少对象的引用计数
Definition peripheral.c:76
#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 EHOSTUNREACH
Host is unreachable
Definition errno.h:131
#define XWOK
No error
Definition errno.h:182
signed long xwer_t
Definition type.h:554
static xwer_t xwds_spip_vop_stop(struct xwds_spip *spip)
XWDS VOP:停止设备
Definition peripheral.c:156
static xwer_t xwds_spip_vop_start(struct xwds_spip *spip)
XWDS VOP:启动设备
Definition peripheral.c:127
const struct xwds_virtual_operation xwds_spip_vop
Definition peripheral.c:44
static xwer_t xwds_spip_vop_remove(struct xwds_spip *spip)
XWDS VOP:删除设备
Definition peripheral.c:106
static xwer_t xwds_spip_vop_suspend(struct xwds_spip *spip)
XWDS VOP:暂停设备
Definition peripheral.c:180
static xwer_t xwds_spip_vop_resume(struct xwds_spip *spip)
XWDS VOP:继续设备
Definition peripheral.c:202
static xwer_t xwds_spip_vop_probe(struct xwds_spip *spip)
XWDS VOP:探测设备
Definition peripheral.c:87
玄武设备栈:SPI:外设
const struct xwds_virtual_operation * vop
Definition device.h:138
SPI外设控制器
Definition peripheral.h:47
struct xwds_device dev
Definition peripheral.h:48
struct xwds_spim * bus
Definition peripheral.h:51
基本操作的虚函数表(类似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
玄武设备栈:顶级头文件