XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
driver.c 文件参考

SPI Flash W25Qxx Driver 更多...

driver.c 的引用(Include)关系图:

浏览源代码.

函数

xwer_t xwds_w25qxx_drv_start (struct xwds_device *dev)
 W25QXX基本驱动:启动设备
 
xwer_t xwds_w25qxx_drv_stop (struct xwds_device *dev)
 W25QXX基本驱动:停止设备
 
xwer_t xwds_w25qxx_drv_resume (struct xwds_device *dev)
 W25QXX基本驱动:暂停设备
 
xwer_t xwds_w25qxx_drv_suspend (struct xwds_device *dev)
 W25QXX基本驱动:继续设备
 
xwer_t xwds_w25qxx_ctrl (struct xwds_w25qxx *w25qxx, xwu8_t instruction, xwu8_t address_size, xwu32_t address, xwu32_t dummy_cycles, const xwu8_t txd[], xwu8_t *rxb, xwsz_t size, xwtm_t to)
 W25QXX API:向W25QXX发送指令
 
xwer_t xwds_w25qxx_reset (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:向W25QXX发送复位命令
 
xwer_t xwds_w25qxx_init_parameter (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:初始化W25QXX的参数
 
xwer_t xwds_w25qxx_write_enable (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:开启W25QXX的写操作
 
xwer_t xwds_w25qxx_write_disable (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:关闭W25QXX的写操作
 
xwer_t xwds_w25qxx_read_sr (struct xwds_w25qxx *w25qxx, xwu32_t sridx, xwu8_t *srbuf, xwtm_t to)
 W25QXX API:读取W25QXX的SR寄存器
 
xwer_t xwds_w25qxx_check_idle (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:检测W25QXX是否空闲
 
xwer_t xwds_w25qxx_wait_idle (struct xwds_w25qxx *w25qxx, xwtm_t period, xwtm_t to)
 W25QXX API:等待W25QXX是否空闲
 
xwer_t xwds_w25qxx_read_uid (struct xwds_w25qxx *w25qxx, xwu64_t *uidbuf, xwtm_t to)
 W25QXX API:读取W25QXX的UID
 
xwer_t xwds_w25qxx_read_mid (struct xwds_w25qxx *w25qxx, xwu16_t *midbuf, xwtm_t to)
 W25QXX API:读取W25QXX的MID
 
xwer_t xwds_w25qxx_read_jid (struct xwds_w25qxx *w25qxx, xwu32_t *jidbuf, xwtm_t to)
 W25QXX API:读取W25QXX的JID
 
xwer_t xwds_w25qxx_read (struct xwds_w25qxx *w25qxx, xwu32_t address, xwu8_t *rxb, xwsz_t *size, xwtm_t to)
 W25QXX API:向W25QXX读取数据
 
xwer_t xwds_w25qxx_write (struct xwds_w25qxx *w25qxx, xwu32_t address, xwu8_t *txb, xwsz_t *size, xwtm_t to)
 W25QXX API:向W25QXX写入数据
 
xwer_t xwds_w25qxx_erase_sector (struct xwds_w25qxx *w25qxx, xwu32_t address, xwtm_t to)
 W25QXX API:擦除W25QXX的sector
 
xwer_t xwds_w25qxx_erase_32kblk (struct xwds_w25qxx *w25qxx, xwu32_t address, xwtm_t to)
 W25QXX API:擦除W25QXX的32KiB的块
 
xwer_t xwds_w25qxx_erase_64kblk (struct xwds_w25qxx *w25qxx, xwu32_t address, xwtm_t to)
 W25QXX API:擦除W25QXX的64KiB的块
 
xwer_t xwds_w25qxx_erase_chip (struct xwds_w25qxx *w25qxx, xwtm_t to)
 W25QXX API:擦除W25QXX的全部数据
 

详细描述

SPI Flash W25Qxx Driver

作者

在文件 driver.c 中定义.

函数说明

◆ xwds_w25qxx_drv_start()

xwer_t xwds_w25qxx_drv_start ( struct xwds_device dev)

W25QXX基本驱动:启动设备

<No error

在文件 driver.c30 行定义.

31{
32 struct xwds_w25qxx * w25qxx;
33 const struct xwds_w25qxx_driver * drv;
34 const struct xwds_w25qxx_cmd * cmdtbl;
35 xwer_t rc;
36
37 w25qxx = xwds_cast(struct xwds_w25qxx *, dev);
38 drv = xwds_cast(struct xwds_w25qxx_driver *, dev->drv);
39 cmdtbl = w25qxx->cmdtbl;
40 if ((NULL == drv) || (NULL == drv->io) ||
41 (NULL == cmdtbl) || (NULL == w25qxx->spip.bus)) {
42 rc = -EINVAL;
43 goto err_desc_err;
44 }
45 memset(w25qxx->txq, 0, sizeof(w25qxx->txq));
46 memset(w25qxx->rxq, 0, sizeof(w25qxx->rxq));
47 return XWOK;
48
49err_desc_err:
50 return rc;
51}
#define xwds_cast(type, dev)
Definition standard.h:40
#define EINVAL
Invalid argument
Definition errno.h:52
#define XWOK
No error
Definition errno.h:182
signed long xwer_t
Definition type.h:554
#define NULL
Definition type.h:28
const struct xwds_driver * drv
Definition device.h:133
struct xwds_spim * bus
Definition peripheral.h:51
W25QXX Flash 命令
Definition device.h:151
W25QXX驱动函数表
Definition driver.h:37
xwer_t(* io)(struct xwds_w25qxx *, xwu8_t *, xwu8_t *, xwsz_t *, xwtm_t)
Definition driver.h:39
W25QXX Flash 设备
Definition device.h:172
struct xwds_spip spip
Definition device.h:173
xwu8_t rxq[256U+16]
Definition device.h:181
const struct xwds_w25qxx_cmd * cmdtbl
Definition device.h:177
xwu8_t txq[256U+16]
Definition device.h:180

◆ xwds_w25qxx_drv_stop()

xwer_t xwds_w25qxx_drv_stop ( struct xwds_device dev)

W25QXX基本驱动:停止设备

< 去除未使用变量的警告

<No error

在文件 driver.c54 行定义.

55{
56 XWOS_UNUSED(dev);
57 return XWOK;
58}
#define XWOS_UNUSED(x)
Definition standard.h:66

◆ xwds_w25qxx_drv_resume()

xwer_t xwds_w25qxx_drv_resume ( struct xwds_device dev)

W25QXX基本驱动:暂停设备

< 去除未使用变量的警告

<No error

在文件 driver.c62 行定义.

63{
64 XWOS_UNUSED(dev);
65 return XWOK;
66}

◆ xwds_w25qxx_drv_suspend()

xwer_t xwds_w25qxx_drv_suspend ( struct xwds_device dev)

W25QXX基本驱动:继续设备

< 去除未使用变量的警告

<No error

在文件 driver.c69 行定义.

70{
71 XWOS_UNUSED(dev);
72 return XWOK;
73}

◆ xwds_w25qxx_ctrl()

xwer_t xwds_w25qxx_ctrl ( struct xwds_w25qxx w25qxx,
xwu8_t  instruction,
xwu8_t  address_size,
xwu32_t  address,
xwu32_t  dummy_cycles,
const xwu8_t  txd[],
xwu8_t rxb,
xwsz_t  size,
xwtm_t  to 
)

W25QXX API:向W25QXX发送指令

参数
[in]w25qxxW25QXX对象指针
[in]instruction指令
[in]address_size地址信息长度
[in]address地址
[in]dummy_cyclesSPI通讯过程中的无效时钟周期
[in]txdSPI通讯过程中的发送数据的缓冲区
[out]rxbSPI通讯过程中的接收数据的缓冲区
[in]sizeSPI通讯过程中的缓冲区大小
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程
  • 时序由 w25qxx->spip.buscfgid 定义。
  • to 表示等待超时的时间点:
    • to 通常是未来的时间,即 当前系统时间 + delta , 可以使用 xwtm_ft(delta) 表示;
    • 如果 to 是过去的时间点,将直接返回 -ETIMEDOUT

<No error

在文件 driver.c78 行定义.

84{
85 const struct xwds_w25qxx_driver * drv;
86 xwsz_t i, j, idx, rxofs, xfersize;
87 xwer_t rc;
88
89 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
90
91 rc = xwds_w25qxx_grab(w25qxx);
92 if (__xwcc_unlikely(rc < 0)) {
93 goto err_w25qxx_grab;
94 }
95 drv = xwds_cast(struct xwds_w25qxx_driver *, w25qxx->spip.dev.drv);
96 idx = 0;
97 w25qxx->txq[idx] = instruction;
98 idx++;
99 if (address_size) {
100 for (i = 0, j = (xwsz_t)(address_size - 1);
101 i < address_size;
102 i++, j--) {
103 w25qxx->txq[idx] = (xwu8_t)(address >> (j * 8));
104 idx++;
105 }
106 }
107 if (dummy_cycles) {
108 for (i = 0; i < (dummy_cycles / 8); i++) {
109 w25qxx->txq[idx] = 0;
110 idx++;
111 }
112 }
113 rxofs = idx;
114 for (i = 0; i < size; i++) {
115 if (txd) {
116 w25qxx->txq[idx] = txd[i];
117 } else {
118 w25qxx->txq[idx] = 0;
119 }
120 idx++;
121 }
122 xfersize = idx;
123 rc = drv->io(w25qxx,
124 w25qxx->txq, w25qxx->rxq, &xfersize,
125 to);
126 if (rc < 0) {
127 goto err_spim_xfer;
128 }
129 if (rxb) {
130 for (i = 0; i < size; i++) {
131 rxb[i] = w25qxx->rxq[rxofs + i];
132 }
133 }
134 xwds_w25qxx_put(w25qxx);
135 return XWOK;
136
137err_spim_xfer:
138 xwds_w25qxx_put(w25qxx);
139err_w25qxx_grab:
140 return rc;
141}
#define XWDS_VALIDATE(exp, errstr,...)
Definition standard.h:51
static xwer_t xwds_w25qxx_grab(struct xwds_w25qxx *w25qxx)
W25QXX API:增加对象的引用计数
Definition device.h:194
static xwer_t xwds_w25qxx_put(struct xwds_w25qxx *w25qxx)
W25QXX API:减少对象的引用计数
Definition device.h:206
#define __xwcc_unlikely(x)
Definition compiler.h:119
#define EFAULT
Bad address
Definition errno.h:44
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
struct xwds_device dev
Definition peripheral.h:48
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_reset()

xwer_t xwds_w25qxx_reset ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:向W25QXX发送复位命令

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c144 行定义.

145{
146 struct xwds_w25qxx_cmd cmd;
147 xwer_t rc;
148
149 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
150
152 if (cmd.existing) {
153 rc = xwds_w25qxx_ctrl(w25qxx,
154 cmd.instruction,
155 cmd.address_size, cmd.address,
156 cmd.dummy_cycles,
157 NULL, NULL, 0, to);
158 if (rc < 0) {
159 goto err_w25qxx_ctrl;
160 }
161 }
162 cmd = w25qxx->cmdtbl[XWDS_W25QXX_CMD_RESET];
163 if (cmd.existing) {
164 rc = xwds_w25qxx_ctrl(w25qxx,
165 cmd.instruction,
166 cmd.address_size, cmd.address,
167 cmd.dummy_cycles,
168 NULL, NULL, 0, to);
169 if (rc < 0) {
170 goto err_w25qxx_ctrl;
171 }
172 }
173 return XWOK;
174
175err_w25qxx_ctrl:
176 return rc;
177}
@ XWDS_W25QXX_CMD_RESET
Definition device.h:80
@ XWDS_W25QXX_CMD_ENABLE_RESET
Definition device.h:79
xwer_t xwds_w25qxx_ctrl(struct xwds_w25qxx *w25qxx, xwu8_t instruction, xwu8_t address_size, xwu32_t address, xwu32_t dummy_cycles, const xwu8_t txd[], xwu8_t *rxb, xwsz_t size, xwtm_t to)
W25QXX API:向W25QXX发送指令
Definition driver.c:78
函数调用图:

◆ xwds_w25qxx_init_parameter()

xwer_t xwds_w25qxx_init_parameter ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:初始化W25QXX的参数

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

<No error

在文件 driver.c180 行定义.

181{
182 xwu64_t uid;
183 xwu32_t jid;
184 xwu16_t mid;
185 xwer_t rc;
186
187 rc = xwds_w25qxx_read_uid(w25qxx, &uid, to);
188 if (rc < 0) {
189 goto err_read_uid;
190 }
191 rc = xwds_w25qxx_read_mid(w25qxx, &mid, to);
192 if (rc < 0) {
193 goto err_read_mid;
194 }
195 rc = xwds_w25qxx_read_jid(w25qxx, &jid, to);
196 if (rc < 0) {
197 goto err_read_jid;
198 }
199 switch (w25qxx->parameter.mid) {
200 case XWDS_W25Q80_MID:
201 w25qxx->parameter.size = 1 * 1024 * 1024;
202 break;
203 case XWDS_W25Q16_MID:
204 w25qxx->parameter.size = 2 * 1024 * 1024;
205 break;
206 case XWDS_W25Q32_MID:
207 w25qxx->parameter.size = 4 * 1024 * 1024;
208 break;
209 case XWDS_W25Q64_MID:
210 w25qxx->parameter.size = 8 * 1024 * 1024;
211 break;
212 case XWDS_W25Q128_MID:
213 w25qxx->parameter.size = 16 * 1024 * 1024;
214 break;
215 case XWDS_W25Q256_MID:
216 w25qxx->parameter.size = 32 * 1024 * 1024;
217 break;
218 default:
219 break;
220 }
221 return XWOK;
222
223err_read_jid:
224err_read_mid:
225err_read_uid:
226 return rc;
227}
@ XWDS_W25Q128_MID
Definition device.h:93
@ XWDS_W25Q64_MID
Definition device.h:92
@ XWDS_W25Q80_MID
Definition device.h:89
@ XWDS_W25Q32_MID
Definition device.h:91
@ XWDS_W25Q256_MID
Definition device.h:94
@ XWDS_W25Q16_MID
Definition device.h:90
uint64_t xwu64_t
Definition type.h:303
uint16_t xwu16_t
Definition type.h:230
uint32_t xwu32_t
Definition type.h:266
xwer_t xwds_w25qxx_read_uid(struct xwds_w25qxx *w25qxx, xwu64_t *uidbuf, xwtm_t to)
W25QXX API:读取W25QXX的UID
Definition driver.c:377
xwer_t xwds_w25qxx_read_mid(struct xwds_w25qxx *w25qxx, xwu16_t *midbuf, xwtm_t to)
W25QXX API:读取W25QXX的MID
Definition driver.c:407
xwer_t xwds_w25qxx_read_jid(struct xwds_w25qxx *w25qxx, xwu32_t *jidbuf, xwtm_t to)
W25QXX API:读取W25QXX的JID
Definition driver.c:437
struct xwds_w25qxx_parameter parameter
Definition device.h:176
函数调用图:

◆ xwds_w25qxx_write_enable()

xwer_t xwds_w25qxx_write_enable ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:开启W25QXX的写操作

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c230 行定义.

231{
232 struct xwds_w25qxx_cmd cmd;
233 xwer_t rc;
234 xwu8_t sr1;
235
236 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
237
239 if (1 != cmd.existing) {
240 rc = -ENOTSUP;
241 goto err_not_support;
242 }
243 rc = xwds_w25qxx_ctrl(w25qxx,
244 cmd.instruction,
245 cmd.address_size, cmd.address,
246 cmd.dummy_cycles,
247 NULL, NULL, 0, to);
248 if (rc < 0) {
249 goto err_w25qxx_ctrl;
250 }
251 rc = xwds_w25qxx_read_sr(w25qxx,
252 XWDS_W25QXX_SR_1, &sr1,
253 to);
254 if (rc < 0) {
255 goto err_chk_wel;
256 }
257 if (!(sr1 & XWDS_W25QXX_SR1_WEL)) {
258 rc = -EACCES;
259 goto err_chk_wel;
260 }
261 return XWOK;
262
263err_chk_wel:
264err_w25qxx_ctrl:
265err_not_support:
266 return rc;
267}
@ XWDS_W25QXX_SR_1
Definition device.h:101
@ XWDS_W25QXX_SR1_WEL
Definition device.h:112
@ XWDS_W25QXX_CMD_WRITE_ENABLE
Definition device.h:46
#define ENOTSUP
Not supported
Definition errno.h:147
#define EACCES
Permission denied
Definition errno.h:43
xwer_t xwds_w25qxx_read_sr(struct xwds_w25qxx *w25qxx, xwu32_t sridx, xwu8_t *srbuf, xwtm_t to)
W25QXX API:读取W25QXX的SR寄存器
Definition driver.c:298
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_write_disable()

xwer_t xwds_w25qxx_write_disable ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:关闭W25QXX的写操作

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c270 行定义.

271{
272 struct xwds_w25qxx_cmd cmd;
273 xwer_t rc;
274
275 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
276
278 if (cmd.existing) {
279 rc = -ENOTSUP;
280 goto err_not_support;
281 }
282 rc = xwds_w25qxx_ctrl(w25qxx,
283 cmd.instruction,
284 cmd.address_size, cmd.address,
285 cmd.dummy_cycles,
286 NULL, NULL, 0, to);
287 if (rc < 0) {
288 goto err_w25qxx_ctrl;
289 }
290 return XWOK;
291
292err_w25qxx_ctrl:
293err_not_support:
294 return rc;
295}
@ XWDS_W25QXX_CMD_WRITE_DISABLE
Definition device.h:45
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_read_sr()

xwer_t xwds_w25qxx_read_sr ( struct xwds_w25qxx w25qxx,
xwu32_t  sridx,
xwu8_t srbuf,
xwtm_t  to 
)

W25QXX API:读取W25QXX的SR寄存器

参数
[in]w25qxxW25QXX对象指针
[in]sridxSR寄存器的序号
[out]srbuf指向缓冲区的指针,通过此缓冲区返回SR寄存器的值
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c298 行定义.

301{
302 struct xwds_w25qxx_cmd cmd;
303 xwer_t rc;
304
305 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
306 XWDS_VALIDATE((sridx < XWDS_W25QXX_SR_NUM), "out-of-range", -ECHRNG);
307
308 switch (sridx) {
309 case XWDS_W25QXX_SR_2:
311 break;
312 case XWDS_W25QXX_SR_3:
314 break;
315 case XWDS_W25QXX_SR_1:
316 default:
318 break;
319 }
320 if (1 != cmd.existing) {
321 rc = -ENOTSUP;
322 goto err_not_support;
323 }
324 rc = xwds_w25qxx_ctrl(w25qxx,
325 cmd.instruction,
326 cmd.address_size, cmd.address,
327 cmd.dummy_cycles,
328 NULL, srbuf, 1, to);
329 if (rc < 0) {
330 goto err_w25qxx_ctrl;
331 }
332 return XWOK;
333
334err_w25qxx_ctrl:
335err_not_support:
336 return rc;
337}
@ XWDS_W25QXX_SR_2
Definition device.h:102
@ XWDS_W25QXX_SR_3
Definition device.h:103
@ XWDS_W25QXX_SR_NUM
Definition device.h:104
@ XWDS_W25QXX_CMD_READ_STATUS_REG_2
Definition device.h:49
@ XWDS_W25QXX_CMD_READ_STATUS_REG_1
Definition device.h:48
@ XWDS_W25QXX_CMD_READ_STATUS_REG_3
Definition device.h:50
#define ECHRNG
Channel number out of range
Definition errno.h:67
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_check_idle()

xwer_t xwds_w25qxx_check_idle ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:检测W25QXX是否空闲

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
返回值
XWOK空闲
-EBUSY繁忙
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c340 行定义.

341{
342 xwer_t rc;
343 xwu8_t sr1;
344
345 rc = xwds_w25qxx_read_sr(w25qxx,
346 XWDS_W25QXX_SR_1, &sr1,
347 to);
348 if (XWOK == rc) {
349 if (sr1 & XWDS_W25QXX_SR1_BUSY) {
350 rc = -EBUSY;
351 }
352 }
353 return rc;
354}
@ XWDS_W25QXX_SR1_BUSY
Definition device.h:111
#define EBUSY
Device or resource busy
Definition errno.h:46
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_wait_idle()

xwer_t xwds_w25qxx_wait_idle ( struct xwds_w25qxx w25qxx,
xwtm_t  period,
xwtm_t  to 
)

W25QXX API:等待W25QXX是否空闲

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c357 行定义.

358{
359 xwer_t rc;
360 xwtm_t from, sleepto;
361
362 rc = xwds_w25qxx_check_idle(w25qxx, to);
363 from = xwtm_now();
364 while ((-EBUSY == rc) && (xwtm_cmp(to, from) > 0)) {
365 sleepto = xwtm_add_safely(from, period);
366 sleepto = xwtm_cmp(sleepto, to) > 0 ? to : sleepto;
367 rc = xwos_cthd_sleep_to(sleepto);
368 if (XWOK == rc) {
369 rc = xwds_w25qxx_check_idle(w25qxx, to);
370 from = xwtm_now();
371 }
372 }
373 return rc;
374}
static __xwcc_inline xwtm_t xwtm_add_safely(const xwtm_t a, const xwtm_t b)
将两个系统时间相加,并检查溢出
Definition type.h:822
xws64_t xwtm_t
XWOS系统时间 (有符号)
Definition type.h:742
static __xwcc_inline xwer_t xwtm_cmp(const xwtm_t a, const xwtm_t b)
比较两个系统时间
Definition type.h:867
static xwer_t xwos_cthd_sleep_to(xwtm_t to)
XWOS API:线程睡眠到一个时间点
Definition thd.h:777
static xwtm_t xwtm_now(void)
XWOS API:获取当前CPU的系统时间点
Definition time.h:57
xwer_t xwds_w25qxx_check_idle(struct xwds_w25qxx *w25qxx, xwtm_t to)
W25QXX API:检测W25QXX是否空闲
Definition driver.c:340
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_read_uid()

xwer_t xwds_w25qxx_read_uid ( struct xwds_w25qxx w25qxx,
xwu64_t uidbuf,
xwtm_t  to 
)

W25QXX API:读取W25QXX的UID

参数
[in]w25qxxW25QXX对象指针
[out]uidbuf指向缓冲区的指针,通过此缓冲区返回UID
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c377 行定义.

378{
379 struct xwds_w25qxx_cmd cmd;
380 xwer_t rc;
381
382 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
383
384 cmd = w25qxx->cmdtbl[XWDS_W25QXX_CMD_UNIQUE_ID];
385 if (1 != cmd.existing) {
386 rc = -ENOTSUP;
387 goto err_not_support;
388 }
389 rc = xwds_w25qxx_ctrl(w25qxx,
390 cmd.instruction,
391 cmd.address_size, cmd.address,
392 cmd.dummy_cycles,
393 NULL, (xwu8_t *)uidbuf, 8, to);
394 if (rc < 0) {
395 goto err_w25qxx_ctrl;
396 }
397 *uidbuf = xwbop_re(xwu64_t, *uidbuf);
398 w25qxx->parameter.uid = *uidbuf;
399 return XWOK;
400
401err_w25qxx_ctrl:
402err_not_support:
403 return rc;
404}
@ XWDS_W25QXX_CMD_UNIQUE_ID
Definition device.h:69
#define xwbop_re(type, data)
将数据的大小端翻转
Definition xwbop.h:145
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_read_mid()

xwer_t xwds_w25qxx_read_mid ( struct xwds_w25qxx w25qxx,
xwu16_t midbuf,
xwtm_t  to 
)

W25QXX API:读取W25QXX的MID

参数
[in]w25qxxW25QXX对象指针
[out]midbuf指向缓冲区的指针,通过此缓冲区返回MID
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c407 行定义.

408{
409 struct xwds_w25qxx_cmd cmd;
410 xwer_t rc;
411
412 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
413
415 if (1 != cmd.existing) {
416 rc = -ENOTSUP;
417 goto err_not_support;
418 }
419 rc = xwds_w25qxx_ctrl(w25qxx,
420 cmd.instruction,
421 cmd.address_size, cmd.address,
422 cmd.dummy_cycles,
423 NULL, (xwu8_t *)midbuf, 2, to);
424 if (rc < 0) {
425 goto err_w25qxx_ctrl;
426 }
427 *midbuf = xwbop_re(xwu16_t, *midbuf);
428 w25qxx->parameter.mid = *midbuf;
429 return XWOK;
430
431err_w25qxx_ctrl:
432err_not_support:
433 return rc;
434}
@ XWDS_W25QXX_CMD_MANUFACTURER_DEVICE_ID
Definition device.h:70
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_read_jid()

xwer_t xwds_w25qxx_read_jid ( struct xwds_w25qxx w25qxx,
xwu32_t jidbuf,
xwtm_t  to 
)

W25QXX API:读取W25QXX的JID

参数
[in]w25qxxW25QXX对象指针
[out]jidbuf指向缓冲区的指针,通过此缓冲区返回JID
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c437 行定义.

438{
439 struct xwds_w25qxx_cmd cmd;
440 xwer_t rc;
441
442 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
443
445 if (1 != cmd.existing) {
446 rc = -ENOTSUP;
447 goto err_not_support;
448 }
449 rc = xwds_w25qxx_ctrl(w25qxx,
450 cmd.instruction,
451 cmd.address_size, cmd.address,
452 cmd.dummy_cycles,
453 NULL, (xwu8_t *)jidbuf, 3, to);
454 if (rc < 0) {
455 goto err_w25qxx_ctrl;
456 }
457 *jidbuf = xwbop_re(xwu32_t, *jidbuf);
458 *jidbuf >>= 8;
459 w25qxx->parameter.jid = *jidbuf;
460 return XWOK;
461
462err_w25qxx_ctrl:
463err_not_support:
464 return rc;
465}
@ XWDS_W25QXX_CMD_JEDEC_DEVICE_ID
Definition device.h:71
函数调用图:
这是这个函数的调用关系图:

◆ xwds_w25qxx_read()

xwer_t xwds_w25qxx_read ( struct xwds_w25qxx w25qxx,
xwu32_t  address,
xwu8_t rxb,
xwsz_t size,
xwtm_t  to 
)

W25QXX API:向W25QXX读取数据

参数
[in]w25qxxW25QXX对象指针
[in]address起始地址
[out]rxb指向缓冲区的指针,通过此缓冲区返回数据
[in,out]size指向缓冲区的指针,此缓冲区:
  • (I) 作为输入时,表示缓冲区长度
  • (O) 作为输出时,返回实际读取的长度
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c468 行定义.

470{
471 struct xwds_w25qxx_cmd cmd;
472 xwsz_t xfsize;
473 xwer_t rc;
474
475 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
476 XWDS_VALIDATE(rxb, "nullptr", -EFAULT);
477 XWDS_VALIDATE(size, "nullptr", -EFAULT);
478
479 xfsize = *size;
481 if (1 != cmd.existing) {
482 rc = -ENOTSUP;
483 goto err_not_support;
484 }
485 rc = xwds_w25qxx_ctrl(w25qxx,
486 cmd.instruction,
487 cmd.address_size, address,
488 cmd.dummy_cycles,
489 NULL, rxb, xfsize, to);
490 if (rc < 0) {
491 goto err_w25qxx_ctrl;
492 }
493 *size = xfsize;
494 return XWOK;
495
496err_w25qxx_ctrl:
497err_not_support:
498 return rc;
499}
@ XWDS_W25QXX_CMD_FAST_READ_DATA
Definition device.h:56
xwu32_t address
Definition device.h:155
函数调用图:

◆ xwds_w25qxx_write()

xwer_t xwds_w25qxx_write ( struct xwds_w25qxx w25qxx,
xwu32_t  address,
xwu8_t txb,
xwsz_t size,
xwtm_t  to 
)

W25QXX API:向W25QXX写入数据

参数
[in]w25qxxW25QXX对象指针
[in]address起始地址
[in]txb待写入的数据缓冲区
[in,out]size指向缓冲区的指针,此缓冲区:
  • (I) 作为输入时,表示缓冲区长度
  • (O) 作为输出时,返回实际写入的长度
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c502 行定义.

504{
505 struct xwds_w25qxx_cmd cmd;
506 xwsz_t xfsize;
507 xwer_t rc;
508
509 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
510 XWDS_VALIDATE(txb, "nullptr", -EFAULT);
511 XWDS_VALIDATE(size, "nullptr", -EFAULT);
512
513 rc = xwds_w25qxx_write_enable(w25qxx, to);
514 if (rc < 0) {
515 goto err_we;
516 }
517 rc = xwds_w25qxx_wait_idle(w25qxx, XWTM_MS(1), to);
518 if (rc < 0) {
519 goto err_wait_idle;
520 }
521 xfsize = *size;
523 if (1 != cmd.existing) {
524 rc = -ENOTSUP;
525 goto err_not_support;
526 }
527 rc = xwds_w25qxx_ctrl(w25qxx,
528 cmd.instruction,
529 cmd.address_size, address,
530 cmd.dummy_cycles,
531 txb, NULL, xfsize, to);
532 if (rc < 0) {
533 goto err_w25qxx_ctrl;
534 }
535 *size = xfsize;
536 return XWOK;
537
538err_w25qxx_ctrl:
539err_not_support:
540err_wait_idle:
541 xwds_w25qxx_write_disable(w25qxx, to);
542err_we:
543 return rc;
544}
@ XWDS_W25QXX_CMD_PAGE_PROGRAM
Definition device.h:59
#define XWTM_MS(ms)
系统时间的单位:毫秒
Definition type.h:786
xwer_t xwds_w25qxx_wait_idle(struct xwds_w25qxx *w25qxx, xwtm_t period, xwtm_t to)
W25QXX API:等待W25QXX是否空闲
Definition driver.c:357
xwer_t xwds_w25qxx_write_disable(struct xwds_w25qxx *w25qxx, xwtm_t to)
W25QXX API:关闭W25QXX的写操作
Definition driver.c:270
xwer_t xwds_w25qxx_write_enable(struct xwds_w25qxx *w25qxx, xwtm_t to)
W25QXX API:开启W25QXX的写操作
Definition driver.c:230
函数调用图:

◆ xwds_w25qxx_erase_sector()

xwer_t xwds_w25qxx_erase_sector ( struct xwds_w25qxx w25qxx,
xwu32_t  address,
xwtm_t  to 
)

W25QXX API:擦除W25QXX的sector

参数
[in]w25qxxW25QXX对象指针
[in]address起始地址
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

<No error

在文件 driver.c547 行定义.

548{
549 struct xwds_w25qxx_cmd cmd;
550 xwer_t rc;
551
552 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
553
554 rc = xwds_w25qxx_write_enable(w25qxx, to);
555 if (rc < 0) {
556 goto err_we;
557 }
559 if (1 != cmd.existing) {
560 rc = -ENOTSUP;
561 goto err_not_support;
562 }
563 rc = xwds_w25qxx_ctrl(w25qxx,
564 cmd.instruction,
565 cmd.address_size, address,
566 cmd.dummy_cycles,
567 NULL, NULL, 0, to);
568 if (rc < 0) {
569 goto err_w25qxx_ctrl;
570 }
571 rc = xwds_w25qxx_wait_idle(w25qxx, XWTM_MS(400), to);
572 if (rc < 0) {
573 goto err_chk_idle;
574 }
575 return XWOK;
576
577err_chk_idle:
578err_w25qxx_ctrl:
579err_not_support:
580 xwds_w25qxx_write_disable(w25qxx, to);
581err_we:
582 return rc;
583}
@ XWDS_W25QXX_CMD_SECTOR_ERASE
Definition device.h:63
函数调用图:

◆ xwds_w25qxx_erase_32kblk()

xwer_t xwds_w25qxx_erase_32kblk ( struct xwds_w25qxx w25qxx,
xwu32_t  address,
xwtm_t  to 
)

W25QXX API:擦除W25QXX的32KiB的块

参数
[in]w25qxxW25QXX对象指针
[in]address起始地址
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c586 行定义.

587{
588 struct xwds_w25qxx_cmd cmd;
589 xwer_t rc;
590
591 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
592
593 rc = xwds_w25qxx_write_enable(w25qxx, to);
594 if (rc < 0) {
595 goto err_we;
596 }
598 if (1 != cmd.existing) {
599 rc = -ENOTSUP;
600 goto err_not_support;
601 }
602 rc = xwds_w25qxx_ctrl(w25qxx,
603 cmd.instruction,
604 cmd.address_size, address,
605 cmd.dummy_cycles,
606 NULL, NULL, 0, to);
607 if (rc < 0) {
608 goto err_w25qxx_ctrl;
609 }
610 rc = xwds_w25qxx_wait_idle(w25qxx, XWTM_MS(1600), to);
611 if (rc < 0) {
612 goto err_chk_idle;
613 }
614 return XWOK;
615
616err_chk_idle:
617err_w25qxx_ctrl:
618err_not_support:
619 xwds_w25qxx_write_disable(w25qxx, to);
620err_we:
621 return rc;
622}
@ XWDS_W25QXX_CMD_32KBLOCK_ERASE
Definition device.h:61
函数调用图:

◆ xwds_w25qxx_erase_64kblk()

xwer_t xwds_w25qxx_erase_64kblk ( struct xwds_w25qxx w25qxx,
xwu32_t  address,
xwtm_t  to 
)

W25QXX API:擦除W25QXX的64KiB的块

参数
[in]w25qxxW25QXX对象指针
[in]address起始地址
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c625 行定义.

626{
627 struct xwds_w25qxx_cmd cmd;
628 xwer_t rc;
629
630 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
631
632 rc = xwds_w25qxx_write_enable(w25qxx, to);
633 if (rc < 0) {
634 goto err_we;
635 }
637 if (1 != cmd.existing) {
638 rc = -ENOTSUP;
639 goto err_not_support;
640 }
641 rc = xwds_w25qxx_ctrl(w25qxx,
642 cmd.instruction,
643 cmd.address_size, address,
644 cmd.dummy_cycles,
645 NULL, NULL, 0, to);
646 if (rc < 0) {
647 goto err_w25qxx_ctrl;
648 }
649 rc = xwds_w25qxx_wait_idle(w25qxx, XWTM_MS(2000), to);
650 if (rc < 0) {
651 goto err_chk_idle;
652 }
653 return XWOK;
654
655err_chk_idle:
656err_w25qxx_ctrl:
657err_not_support:
658 xwds_w25qxx_write_disable(w25qxx, to);
659err_we:
660 return rc;
661}
@ XWDS_W25QXX_CMD_64KBLOCK_ERASE
Definition device.h:62
函数调用图:

◆ xwds_w25qxx_erase_chip()

xwer_t xwds_w25qxx_erase_chip ( struct xwds_w25qxx w25qxx,
xwtm_t  to 
)

W25QXX API:擦除W25QXX的全部数据

参数
[in]w25qxxW25QXX对象指针
[in]to期望唤醒的时间点
返回
错误码
注解
  • 上下文:线程

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

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

<No error

在文件 driver.c664 行定义.

665{
666 struct xwds_w25qxx_cmd cmd;
667 xwer_t rc;
668
669 XWDS_VALIDATE(w25qxx, "nullptr", -EFAULT);
670
671 rc = xwds_w25qxx_write_enable(w25qxx, to);
672 if (rc < 0) {
673 goto err_we;
674 }
675 cmd = w25qxx->cmdtbl[XWDS_W25QXX_CMD_CHIP_ERASE];
676 if (1 != cmd.existing) {
677 rc = -ENOTSUP;
678 goto err_not_support;
679 }
680 rc = xwds_w25qxx_ctrl(w25qxx,
681 cmd.instruction,
682 cmd.address_size, cmd.address,
683 cmd.dummy_cycles,
684 NULL, NULL, 0, to);
685 if (rc < 0) {
686 goto err_w25qxx_ctrl;
687 }
688 rc = xwds_w25qxx_wait_idle(w25qxx, XWTM_MS(2000), to);
689 if (rc < 0) {
690 goto err_chk_idle;
691 }
692 return XWOK;
693
694err_chk_idle:
695err_w25qxx_ctrl:
696err_not_support:
697 xwds_w25qxx_write_disable(w25qxx, to);
698err_we:
699 return rc;
700}
@ XWDS_W25QXX_CMD_CHIP_ERASE
Definition device.h:64
函数调用图: