XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
dma.c
浏览该文件的文档.
1
21#include <xwcd/ds/standard.h>
22#include <string.h>
23#include <xwos/lib/xwaop.h>
24#include <xwcd/ds/soc/dma.h>
25
28{
29 const struct xwds_soc_driver * drv;
30 xwer_t rc;
31
32 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
33 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
34
35 rc = xwds_soc_grab(soc);
36 if (rc < 0) {
37 goto err_soc_grab;
38 }
39 rc = xwbmpaop_t0i_then_s1i(soc->dma.chstatus, ch);
40 if (rc < 0) {
41 rc = -EBUSY;
42 goto err_busy;
43 }
44 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
45 if ((drv) && (drv->dma_req)) {
46 rc = drv->dma_req(soc, ch);
47 if (rc < 0) {
48 goto err_drv_dma_req;
49 }
50 }
51 return XWOK;
52
53err_drv_dma_req:
54 xwbmpaop_s1i(soc->dma.chstatus, ch);
55err_busy:
56 xwds_soc_put(soc);
57err_soc_grab:
58 return rc;
59}
60
63{
64 const struct xwds_soc_driver * drv;
65 xwer_t rc;
66
67 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
68 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
69
70 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
71 rc = -EPERM;
72 goto err_notreq;
73 }
74 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
75 if ((drv) && (drv->dma_rls)) {
76 rc = drv->dma_rls(soc, ch);
77 if (rc < 0) {
78 goto err_drv_dma_rls;
79 }
80 }
81 xwbmpaop_c0i(soc->dma.chstatus, ch);
82 xwds_soc_put(soc);
83 return XWOK;
84
85err_drv_dma_rls:
86err_notreq:
87 return rc;
88}
89
91xwer_t xwds_dma_cfg(struct xwds_soc * soc, xwid_t ch, void * cfg,
93{
94 const struct xwds_soc_driver * drv;
95 xwer_t rc;
96
97 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
98 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
99
100 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
101 rc = -EPERM;
102 goto err_notreq;
103 }
104#if defined(XWCDCFG_ds_SOC_DMA_ROCBT) && (1 == XWCDCFG_ds_SOC_DMA_ROCBT)
105 XWOS_UNUSED(cb);
106 XWOS_UNUSED(arg);
107#else
108 if (soc->dma.chcbs) {
109 soc->dma.chcbs[ch] = cb;
110 }
111 if (soc->dma.chcbargs) {
112 soc->dma.chcbargs[ch] = arg;
113 }
114#endif
115 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
116 if ((drv) && (drv->dma_cfg)) {
117 rc = drv->dma_cfg(soc, ch, cfg);
118 if (rc < 0) {
119 goto err_drv_dma_cfg;
120 }
121 }
122 return XWOK;
123
124err_drv_dma_cfg:
125#if !defined(XWCDCFG_ds_SOC_DMA_ROCBT) || (1 != XWCDCFG_ds_SOC_DMA_ROCBT)
126 if (soc->dma.chcbs) {
127 soc->dma.chcbs[ch] = NULL;
128 }
129 if (soc->dma.chcbargs) {
130 soc->dma.chcbargs[ch] = NULL;
131 }
132#endif
133err_notreq:
134 return rc;
135}
136
139{
140 const struct xwds_soc_driver * drv;
141 xwer_t rc;
142
143 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
144 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
145
146 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
147 rc = -EPERM;
148 goto err_notreq;
149 }
150 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
151 if ((drv) && (drv->dma_enable)) {
152 rc = drv->dma_enable(soc, ch);
153 if (rc < 0) {
154 goto err_drv_dma_enable;
155 }
156 }
157 return XWOK;
158
159err_drv_dma_enable:
160err_notreq:
161 return rc;
162}
163
166{
167 const struct xwds_soc_driver * drv;
168 xwer_t rc;
169
170 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
171 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
172
173 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
174 rc = -EPERM;
175 goto err_notreq;
176 }
177 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
178 if ((drv) && (drv->dma_disable)) {
179 rc = drv->dma_disable(soc, ch);
180 if (rc < 0) {
181 goto err_drv_dma_disable;
182 }
183 }
184 return XWOK;
185
186err_drv_dma_disable:
187err_notreq:
188 return rc;
189}
190
193{
194 const struct xwds_soc_driver * drv;
195 xwer_t rc;
196
197 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
198 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
199
200 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
201 rc = -EPERM;
202 goto err_notreq;
203 }
204 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
205 if ((drv) && (drv->dma_start)) {
206 rc = drv->dma_start(soc, ch);
207 if (rc < 0) {
208 goto err_drv_dma_start;
209 }
210 }
211 return XWOK;
212
213err_drv_dma_start:
214err_notreq:
215 return rc;
216}
217
220{
221 const struct xwds_soc_driver * drv;
222 xwer_t rc;
223
224 XWDS_VALIDATE(soc, "nullptr", -EFAULT);
225 XWDS_VALIDATE(((xwid_t)ch < soc->dma.ch_num), "out-of-range", -ERANGE);
226
227 if (!xwbmpaop_t1i(soc->dma.chstatus, ch)) {
228 rc = -EPERM;
229 goto err_notreq;
230 }
231 drv = xwds_cast(const struct xwds_soc_driver *, soc->dev.drv);
232 if ((drv) && (drv->dma_stop)) {
233 rc = drv->dma_stop(soc, ch);
234 if (rc < 0) {
235 goto err_drv_dma_stop;
236 }
237 }
238 return XWOK;
239
240err_drv_dma_stop:
241err_notreq:
242 return rc;
243}
xwer_t xwds_dma_disable(struct xwds_soc *soc, xwid_t ch)
XWDS API:关闭DMA的通道
Definition dma.c:165
xwer_t xwds_dma_start(struct xwds_soc *soc, xwid_t ch)
XWDS API:启动DMA的通道
Definition dma.c:192
xwer_t xwds_dma_req(struct xwds_soc *soc, xwid_t ch)
XWDS API:申请DMA的通道
Definition dma.c:27
xwer_t xwds_dma_cfg(struct xwds_soc *soc, xwid_t ch, void *cfg, xwds_dma_f cb, xwds_dma_cbarg_t arg)
XWDS API:配置DMA的通道
Definition dma.c:91
xwer_t xwds_dma_rls(struct xwds_soc *soc, xwid_t ch)
XWDS API:释放DMA的通道
Definition dma.c:62
xwer_t xwds_dma_enable(struct xwds_soc *soc, xwid_t ch)
XWDS API:打开DMA的通道
Definition dma.c:138
xwer_t xwds_dma_stop(struct xwds_soc *soc, xwid_t ch)
XWDS API:停止DMA的通道
Definition dma.c:219
玄武设备栈:SOC:DMA
xwer_t xwds_soc_grab(struct xwds_soc *soc)
XWDS API:增加对象的引用计数
Definition chip.c:71
void * xwds_dma_cbarg_t
DMA完成回调函数参数
Definition chip.h:148
void(* xwds_dma_f)(struct xwds_soc *, xwid_t, xwu32_t, xwds_dma_cbarg_t)
DMA完成回调函数类型
Definition chip.h:153
xwer_t xwds_soc_put(struct xwds_soc *soc)
XWDS API:减少对象的引用计数
Definition chip.c:77
#define xwds_cast(type, dev)
Definition standard.h:40
#define __xwds_api
Definition standard.h:33
#define XWDS_VALIDATE(exp, errstr,...)
Definition standard.h:51
#define EFAULT
Bad address
Definition errno.h:44
#define XWOK
No error
Definition errno.h:182
#define EBUSY
Device or resource busy
Definition errno.h:46
#define ERANGE
Result too large
Definition errno.h:64
#define EPERM
Operation not permitted
Definition errno.h:31
signed long xwer_t
Definition type.h:554
#define NULL
Definition type.h:28
unsigned long xwid_t
Definition type.h:481
bool xwbmpaop_t1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:测试位图中的某位是否被置1
Definition bmp.c:18
void xwbmpaop_c0i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:将位图中某位清0
Definition bmp.c:40
xwer_t xwbmpaop_t0i_then_s1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:测试位图中某位是否为0,如果是,就将它置1
Definition bmp.c:58
void xwbmpaop_s1i(atomic_xwbmp_t *bmp, xwsq_t idx)
XWOS AOPLIB:将位图中某位置1
Definition bmp.c:31
#define XWOS_UNUSED(x)
Definition standard.h:66
const struct xwds_driver * drv
Definition device.h:133
BSP中需要提供的SOC设备驱动函数表
Definition chip.h:51
SOC设备
Definition chip.h:161
struct xwds_device dev
Definition chip.h:162
XWOS通用库:原子操作
玄武设备栈:顶级头文件