| 268 | } |
| 269 | |
| 270 | static rt_err_t _wait_token(struct rt_spi_device *device, uint8_t token) |
| 271 | { |
| 272 | struct rt_spi_message message; |
| 273 | rt_tick_t tick_start; |
| 274 | uint8_t send, recv; |
| 275 | |
| 276 | tick_start = rt_tick_get(); |
| 277 | |
| 278 | /* wati token */ |
| 279 | /* initial message */ |
| 280 | send = DUMMY; |
| 281 | message.send_buf = &send; |
| 282 | message.recv_buf = &recv; |
| 283 | message.length = 1; |
| 284 | message.cs_take = message.cs_release = 0; |
| 285 | |
| 286 | while (1) |
| 287 | { |
| 288 | /* transfer message */ |
| 289 | device->bus->ops->xfer(device, &message); |
| 290 | |
| 291 | if (recv == token) |
| 292 | { |
| 293 | return RT_EOK; |
| 294 | } |
| 295 | |
| 296 | if (rt_tick_timeout(tick_start, rt_tick_from_millisecond(CARD_WAIT_TOKEN_TIMES))) |
| 297 | { |
| 298 | MSD_DEBUG("[err] wait data start token timeout!\r\n"); |
| 299 | return -RT_ETIMEOUT; |
| 300 | } |
| 301 | } /* wati token */ |
| 302 | } |
| 303 | |
| 304 | static rt_err_t _wait_ready(struct rt_spi_device *device) |
| 305 | { |
no test coverage detected