essl_sdio.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "essl_sdio.h"
  15. #include "esp_log.h"
  16. #include "soc/host_reg.h"
  17. #include "freertos/task.h"
  18. #include "essl_internal.h"
  19. static const char TAG[] = "essl_sdio";
  20. #define ESSL_CMD53_END_ADDR 0x1f800
  21. #define TX_BUFFER_MAX 0x1000
  22. #define TX_BUFFER_MASK 0xFFF
  23. #define RX_BYTE_MAX 0x100000
  24. #define RX_BYTE_MASK 0xFFFFF
  25. #define FUNC1_EN_MASK (BIT(1))
  26. /**
  27. * Initialize ``void`` over SDIO by this macro.
  28. */
  29. #define ESSL_SDIO_DEFAULT_CONTEXT() (essl_dev_t){\
  30. .init = essl_sdio_init, \
  31. .wait_for_ready = essl_sdio_wait_for_ready, \
  32. .get_tx_buffer_num = essl_sdio_get_tx_buffer_num,\
  33. .update_tx_buffer_num = essl_sdio_update_tx_buffer_num,\
  34. .get_rx_data_size = essl_sdio_get_rx_data_size,\
  35. .update_rx_data_size = essl_sdio_update_rx_data_size,\
  36. .send_packet = essl_sdio_send_packet,\
  37. .get_packet = essl_sdio_get_packet,\
  38. .write_reg = essl_sdio_write_reg,\
  39. .read_reg = essl_sdio_read_reg,\
  40. .wait_int = essl_sdio_wait_int,\
  41. .send_slave_intr = essl_sdio_send_slave_intr, \
  42. .get_intr = essl_sdio_get_intr, \
  43. .clear_intr = essl_sdio_clear_intr, \
  44. .set_intr_ena = essl_sdio_set_intr_ena, \
  45. .reset_cnt = essl_sdio_reset_cnt, \
  46. }
  47. typedef struct{
  48. //common part
  49. uint16_t buffer_size;
  50. ///< All data that do not fully fill a buffer is still counted as one buffer. E.g. 10 bytes data costs 2 buffers if the size is 8 bytes per buffer.
  51. ///< Buffer size of the slave pre-defined between host and slave before communication.
  52. size_t tx_sent_buffers; ///< Counter holding the amount of buffers already sent to ESP32 slave. Should be set to 0 when initialization.
  53. size_t tx_sent_buffers_latest; ///< The latest reading (from the slave) of counter holding the amount of buffers loaded. Should be set to 0 when initialization.
  54. size_t rx_got_bytes; ///< Counter holding the amount of bytes already received from ESP32 slave. Should be set to 0 when initialization.
  55. size_t rx_got_bytes_latest; ///< The latest reading (from the slave) of counter holding the amount of bytes to send. Should be set to 0 when initialization.
  56. sdmmc_card_t* card; ///< Initialized sdmmc_cmd card
  57. uint16_t block_size;
  58. ///< If this is too large, it takes time to send stuff bits; while if too small, intervals between blocks cost much.
  59. ///< Should be set according to length of data, and larger than ``TRANS_LEN_MAX/511``.
  60. ///< Block size of the SDIO function 1. After the initialization this will hold the value the slave really do. Valid value is 1-2048.
  61. } essl_sdio_context_t;
  62. esp_err_t essl_sdio_update_tx_buffer_num(void *arg, uint32_t wait_ms);
  63. esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms);
  64. static inline esp_err_t essl_sdio_write_byte(sdmmc_card_t *card, uint32_t addr, uint8_t val, uint8_t *val_o)
  65. {
  66. return sdmmc_io_write_byte(card, 1, addr&0x3FF, val, val_o);
  67. }
  68. static inline esp_err_t essl_sdio_write_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val, int len)
  69. {
  70. return sdmmc_io_write_bytes(card, 1, addr&0x3FF, val, len);
  71. }
  72. static inline esp_err_t essl_sdio_read_byte(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o)
  73. {
  74. return sdmmc_io_read_byte(card, 1, addr&0x3FF, val_o);
  75. }
  76. static inline esp_err_t essl_sdio_read_bytes(sdmmc_card_t *card, uint32_t addr, uint8_t *val_o, int len)
  77. {
  78. return sdmmc_io_read_bytes(card, 1, addr&0x3FF, val_o, len);
  79. }
  80. esp_err_t essl_sdio_init_dev(essl_handle_t *out_handle, const essl_sdio_config_t *config)
  81. {
  82. esp_err_t ret = ESP_OK;
  83. essl_sdio_context_t* arg = NULL;
  84. essl_dev_t* dev = NULL;
  85. arg = (essl_sdio_context_t*)heap_caps_malloc(sizeof(essl_sdio_context_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
  86. dev = (essl_dev_t*)heap_caps_malloc(sizeof(essl_dev_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
  87. if (arg == NULL || dev == NULL) {
  88. ret = ESP_ERR_NO_MEM;
  89. goto cleanup;
  90. }
  91. *dev = ESSL_SDIO_DEFAULT_CONTEXT();
  92. dev->args = arg;
  93. *arg = (essl_sdio_context_t) {
  94. .card = config->card,
  95. .block_size = 0x200,
  96. .buffer_size = config->recv_buffer_size,
  97. .tx_sent_buffers = 0,
  98. .rx_got_bytes = 0,
  99. };
  100. *out_handle = dev;
  101. return ESP_OK;
  102. cleanup:
  103. free(arg);
  104. free(dev);
  105. return ret;
  106. }
  107. esp_err_t essl_sdio_deinit_dev(essl_handle_t handle)
  108. {
  109. if (handle) free (handle->args);
  110. free(handle);
  111. return ESP_OK;
  112. }
  113. esp_err_t essl_sdio_init(void *arg, uint32_t wait_ms)
  114. {
  115. essl_sdio_context_t* ctx = arg;
  116. esp_err_t err;
  117. uint8_t ioe;
  118. sdmmc_card_t* card = ctx->card;
  119. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_ENABLE, &ioe);
  120. if (err != ESP_OK) return err;
  121. ESP_LOGD(TAG, "IOE: 0x%02x", ioe);
  122. uint8_t ior = 0;
  123. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
  124. if (err != ESP_OK) return err;
  125. ESP_LOGD(TAG, "IOR: 0x%02x", ior);
  126. // enable function 1
  127. ioe |= FUNC1_EN_MASK;
  128. err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_FN_ENABLE, ioe, &ioe);
  129. if (err != ESP_OK) return err;
  130. ESP_LOGD(TAG, "IOE: 0x%02x", ioe);
  131. // wait for the card to become ready
  132. while ((ior & FUNC1_EN_MASK) == 0) {
  133. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
  134. if (err != ESP_OK) return err;
  135. ESP_LOGD(TAG, "IOR: 0x%02x", ior);
  136. }
  137. // get interrupt status
  138. uint8_t ie;
  139. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_INT_ENABLE, &ie);
  140. if (err != ESP_OK) return err;
  141. ESP_LOGD(TAG,"IE: 0x%02x", ie);
  142. // enable interrupts for function 1&2 and master enable
  143. ie |= BIT(0) | FUNC1_EN_MASK;
  144. err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_INT_ENABLE, ie, &ie);
  145. if (err != ESP_OK) return err;
  146. ESP_LOGD(TAG, "IE: 0x%02x", ie);
  147. // get bus width register
  148. uint8_t bus_width;
  149. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, &bus_width);
  150. if (err != ESP_OK) return err;
  151. ESP_LOGD(TAG,"BUS_WIDTH: 0x%02x", bus_width);
  152. // enable continuous SPI interrupts
  153. bus_width |= CCCR_BUS_WIDTH_ECSI;
  154. err = sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BUS_WIDTH, bus_width, &bus_width);
  155. if (err != ESP_OK) return err;
  156. ESP_LOGD(TAG, "BUS_WIDTH: 0x%02x", bus_width);
  157. uint16_t bs = 512;
  158. const uint8_t* bs_u8 = (const uint8_t*) &bs;
  159. uint16_t bs_read = 0;
  160. uint8_t* bs_read_u8 = (uint8_t*) &bs_read;
  161. // Set block sizes for functions 0 to 512 bytes
  162. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
  163. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
  164. ESP_LOGD(TAG, "Function 0 BS: %04x", (int) bs_read);
  165. ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL));
  166. ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL));
  167. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
  168. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
  169. ESP_LOGD(TAG, "Function 0 BS: %04x", (int) bs_read);
  170. // Set block sizes for functions 1 to given value (default value = 512).
  171. if (ctx->block_size > 0 || ctx->block_size <= 2048) {
  172. bs = ctx->block_size;
  173. } else {
  174. bs = 512;
  175. }
  176. size_t offset = SD_IO_FBR_START * 1;
  177. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
  178. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
  179. ESP_LOGD(TAG, "Function 1 BS: %04x", (int) bs_read);
  180. ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, bs_u8[0], NULL));
  181. ESP_ERROR_CHECK(sdmmc_io_write_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, bs_u8[1], NULL));
  182. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEL, &bs_read_u8[0]));
  183. ESP_ERROR_CHECK(sdmmc_io_read_byte(card, 0, offset + SD_IO_CCCR_BLKSIZEH, &bs_read_u8[1]));
  184. ESP_LOGD(TAG, "Function 1 BS: %04x", (int) bs_read);
  185. if (bs_read != ctx->block_size) {
  186. ESP_LOGW(TAG, "Function1 block size %d different than set value %d", bs_read, ctx->block_size);
  187. ctx->block_size = bs_read;
  188. }
  189. return ESP_OK;
  190. }
  191. esp_err_t essl_sdio_wait_for_ready(void *arg, uint32_t wait_ms)
  192. {
  193. ESP_LOGV(TAG, "wait_for_ioready");
  194. esp_err_t err;
  195. sdmmc_card_t *card = ((essl_sdio_context_t*)arg)->card;
  196. // wait for the card to become ready
  197. uint8_t ior = 0;
  198. while ((ior & FUNC1_EN_MASK) == 0) {
  199. err = sdmmc_io_read_byte(card, 0, SD_IO_CCCR_FN_READY, &ior);
  200. if (err != ESP_OK) return err;
  201. ESP_LOGD(TAG, "IOR: 0x%02x", ior);
  202. }
  203. return ESP_OK;
  204. }
  205. esp_err_t essl_sdio_send_packet(void *arg, const void *start, size_t length, uint32_t wait_ms)
  206. {
  207. essl_sdio_context_t* ctx = arg;
  208. uint16_t buffer_size = ctx->buffer_size;
  209. int buffer_used = (length + buffer_size - 1)/buffer_size;
  210. esp_err_t err;
  211. if (essl_sdio_get_tx_buffer_num(arg) < buffer_used) {
  212. //slave has no enough buffer, try update for once
  213. esp_err_t err = essl_sdio_update_tx_buffer_num(arg, wait_ms);
  214. if (err != ESP_OK) {
  215. return err;
  216. }
  217. if (essl_sdio_get_tx_buffer_num(arg) < buffer_used) {
  218. ESP_LOGV(TAG, "buffer is not enough: %d, %d required.", ctx->tx_sent_buffers_latest, ctx->tx_sent_buffers + buffer_used);
  219. return ESP_ERR_NOT_FOUND;
  220. }
  221. }
  222. ESP_LOGV(TAG, "send_packet: len: %d", length);
  223. uint8_t *start_ptr = (uint8_t*)start;
  224. uint32_t len_remain = length;
  225. do {
  226. const int block_size = 512;
  227. /* Though the driver supports to split packet of unaligned size into
  228. * length of 4x and 1~3, we still send aligned size of data to get
  229. * higher effeciency. The length is determined by the SDIO address, and
  230. * the remainning will be discard by the slave hardware.
  231. */
  232. int block_n = len_remain/block_size;
  233. int len_to_send;
  234. if (block_n) {
  235. len_to_send = block_n * block_size;
  236. err = sdmmc_io_write_blocks(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start_ptr, len_to_send);
  237. } else {
  238. len_to_send = len_remain;
  239. err = sdmmc_io_write_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start_ptr, (len_to_send + 3) & (~3));
  240. }
  241. if (err != ESP_OK) return err;
  242. start_ptr += len_to_send;
  243. len_remain -= len_to_send;
  244. } while (len_remain);
  245. ctx->tx_sent_buffers += buffer_used;
  246. return ESP_OK;
  247. }
  248. esp_err_t essl_sdio_get_packet(void *arg, void *out_data, size_t size, uint32_t wait_ms)
  249. {
  250. essl_sdio_context_t* ctx = arg;
  251. esp_err_t err;
  252. ESP_LOGV(TAG, "get_packet: read size=%d", size);
  253. if (essl_sdio_get_rx_data_size(arg) < size) {
  254. err = essl_sdio_update_rx_data_size(arg, wait_ms);
  255. if (err != ESP_OK) {
  256. return err;
  257. }
  258. if (essl_sdio_get_rx_data_size(arg) < size) {
  259. return ESP_ERR_NOT_FOUND;
  260. }
  261. }
  262. uint8_t *start = out_data;
  263. uint32_t len_remain = size;
  264. do {
  265. const int block_size = 512; //currently our driver don't support block size other than 512
  266. int len_to_send;
  267. int block_n = len_remain/block_size;
  268. if (block_n != 0) {
  269. len_to_send = block_n * block_size;
  270. err = sdmmc_io_read_blocks(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, len_to_send);
  271. } else {
  272. len_to_send = len_remain;
  273. /* though the driver supports to split packet of unaligned size into length
  274. * of 4x and 1~3, we still get aligned size of data to get higher
  275. * effeciency. The length is determined by the SDIO address, and the
  276. * remainning will be ignored by the slave hardware.
  277. */
  278. err = sdmmc_io_read_bytes(ctx->card, 1, ESSL_CMD53_END_ADDR - len_remain, start, (len_to_send + 3) & (~3));
  279. }
  280. if (err != ESP_OK) return err;
  281. start += len_to_send;
  282. len_remain -= len_to_send;
  283. ctx->rx_got_bytes += len_to_send;
  284. } while(len_remain!=0);
  285. return err;
  286. }
  287. uint32_t essl_sdio_get_tx_buffer_num(void *arg)
  288. {
  289. essl_sdio_context_t* ctx = arg;
  290. ESP_LOGV(TAG, "tx latest: %d, sent: %d", ctx->tx_sent_buffers_latest, ctx->tx_sent_buffers);
  291. return (ctx->tx_sent_buffers_latest + TX_BUFFER_MAX - ctx->tx_sent_buffers)%TX_BUFFER_MAX;
  292. }
  293. esp_err_t essl_sdio_update_tx_buffer_num(void *arg, uint32_t wait_ms)
  294. {
  295. essl_sdio_context_t* ctx = arg;
  296. uint32_t len;
  297. esp_err_t err;
  298. err = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_TOKEN_RDATA_REG, (uint8_t *) &len, 4);
  299. if (err != ESP_OK) return err;
  300. len = (len>>16)&TX_BUFFER_MASK;
  301. ctx->tx_sent_buffers_latest = len;
  302. ESP_LOGV(TAG, "update_tx_buffer_num: %d", len);
  303. return ESP_OK;
  304. }
  305. uint32_t essl_sdio_get_rx_data_size(void *arg)
  306. {
  307. essl_sdio_context_t* ctx = arg;
  308. ESP_LOGV(TAG, "rx latest: %d, read: %d", ctx->rx_got_bytes_latest, ctx->rx_got_bytes);
  309. return (ctx->rx_got_bytes_latest + RX_BYTE_MAX - ctx->rx_got_bytes)%RX_BYTE_MAX;
  310. }
  311. esp_err_t essl_sdio_update_rx_data_size(void *arg, uint32_t wait_ms)
  312. {
  313. essl_sdio_context_t* ctx = arg;
  314. uint32_t len;
  315. esp_err_t err;
  316. ESP_LOGV(TAG, "get_rx_data_size: got_bytes: %d", ctx->rx_got_bytes);
  317. err = essl_sdio_read_bytes(ctx->card, HOST_SLCHOST_PKT_LEN_REG, (uint8_t *) &len, 4);
  318. if (err != ESP_OK) return err;
  319. len &= RX_BYTE_MASK;
  320. ctx->rx_got_bytes_latest = len;
  321. return ESP_OK;
  322. }
  323. esp_err_t essl_sdio_write_reg(void *arg, uint8_t addr, uint8_t value, uint8_t *value_o, uint32_t wait_ms)
  324. {
  325. ESP_LOGV(TAG, "write_reg: %08X", value);
  326. // addrress over range
  327. if (addr >= 60) return ESP_ERR_INVALID_ARG;
  328. //W7 is reserved for interrupts
  329. if (addr >= 28) addr += 4;
  330. return essl_sdio_write_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W_REG(addr), value, value_o);
  331. }
  332. esp_err_t essl_sdio_read_reg(void *arg, uint8_t add, uint8_t *value_o, uint32_t wait_ms)
  333. {
  334. ESP_LOGV(TAG, "read_reg");
  335. // address over range
  336. if (add >= 60) return ESP_ERR_INVALID_ARG;
  337. //W7 is reserved for interrupts
  338. if (add >= 28) add += 4;
  339. esp_err_t ret = essl_sdio_read_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W_REG(add), value_o);
  340. ESP_LOGV(TAG, "reg: %08X", *value_o);
  341. return ret;
  342. }
  343. esp_err_t essl_sdio_clear_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms)
  344. {
  345. ESP_LOGV(TAG, "clear_intr: %08X", intr_mask);
  346. return essl_sdio_write_bytes(((essl_sdio_context_t *) arg)->card, HOST_SLC0HOST_INT_CLR_REG, (uint8_t *) &intr_mask, 4);
  347. }
  348. esp_err_t essl_sdio_get_intr(void *arg, uint32_t *intr_raw, uint32_t *intr_st, uint32_t wait_ms)
  349. {
  350. essl_sdio_context_t* ctx = arg;
  351. esp_err_t r;
  352. ESP_LOGV(TAG, "get_intr");
  353. if (intr_raw == NULL && intr_st == NULL) return ESP_ERR_INVALID_ARG;
  354. if (intr_raw != NULL) {
  355. r= essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_RAW_REG, (uint8_t *) intr_raw, 4);
  356. if (r != ESP_OK) return r;
  357. }
  358. if (intr_st != NULL) {
  359. r = essl_sdio_read_bytes(ctx->card, HOST_SLC0HOST_INT_ST_REG, (uint8_t *) intr_st, 4);
  360. if (r != ESP_OK) return r;
  361. }
  362. return ESP_OK;
  363. }
  364. esp_err_t essl_sdio_set_intr_ena(void *arg, uint32_t ena_mask, uint32_t wait_ms)
  365. {
  366. ESP_LOGV(TAG, "set_intr_ena: %08X", ena_mask);
  367. return essl_sdio_write_bytes(((essl_sdio_context_t*)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG,
  368. (uint8_t *) &ena_mask, 4);
  369. }
  370. esp_err_t essl_sdio_get_intr_ena(void *arg, uint32_t *ena_mask_o, uint32_t wait_ms)
  371. {
  372. ESP_LOGV(TAG, "get_intr_ena");
  373. esp_err_t ret = essl_sdio_read_bytes(((essl_sdio_context_t*)arg)->card, HOST_SLC0HOST_FUNC1_INT_ENA_REG,
  374. (uint8_t *) ena_mask_o, 4);
  375. ESP_LOGV(TAG, "ena: %08X", *ena_mask_o);
  376. return ret;
  377. }
  378. esp_err_t essl_sdio_send_slave_intr(void *arg, uint32_t intr_mask, uint32_t wait_ms)
  379. {
  380. ESP_LOGV(TAG, "send_slave_intr: %02x", intr_mask);
  381. return essl_sdio_write_byte(((essl_sdio_context_t*)arg)->card, HOST_SLCHOST_CONF_W7_REG + 0, intr_mask, NULL);
  382. }
  383. esp_err_t essl_sdio_wait_int(void *arg, uint32_t wait_ms)
  384. {
  385. return sdmmc_io_wait_int(((essl_sdio_context_t*)arg)->card, wait_ms);
  386. }
  387. void essl_sdio_reset_cnt(void *arg)
  388. {
  389. essl_sdio_context_t* ctx = arg;
  390. ctx->rx_got_bytes = 0;
  391. ctx->tx_sent_buffers = 0;
  392. }