esp_slave_protocol.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ESP SDIO slave protocol
  2. =======================
  3. The protocol is based on Function 1 access by CMD52 and CMD53, offering 3 services: (1) sending and receiving FIFO, (2) 52 8-bit R/W
  4. register shared by host and slave, (3) 8 general purpose interrupt sources from host to slave and 8 in the oppsite direction.
  5. The host should access the registers below as described to communicate with slave.
  6. Slave register table
  7. --------------------
  8. 32-bit
  9. ^^^^^^^
  10. - 0x044 (TOKEN_RDATA): in which bit 27-16 holds the receiving buffer number.
  11. - 0x058 (INT_ST): holds the interrupt source bits from slave to host.
  12. - 0x060 (PKT_LEN): holds the accumulated length (by byte) to be sent from slave to host.
  13. - 0x0D4 (INT_CLR): write 1 to clear interrupt bits corresponding to INT_ST.
  14. - 0x0DC (INT_ENA): mask bits for interrupts from slave to host.
  15. 8-bit
  16. ^^^^^
  17. Shared general purpose registers:
  18. - 0x06C-0x077: R/W registers 0-11 shared by slave and host.
  19. - 0x07A-0x07B: R/W registers 14-15 shared by slave and host.
  20. - 0x07E-0x07F: R/W registers 18-19 shared by slave and host.
  21. - 0x088-0x08B: R/W registers 24-27 shared by slave and host.
  22. - 0x09C-0x0BB: R/W registers 32-63 shared by slave and host.
  23. Interrupt Registers:
  24. - 0x08D (SLAVE_INT): bits for host to interrupt slave. auto clear.
  25. FIFO (sending and receiving)
  26. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  27. 0x090 - 0x1F7FF are reserved for FIFOs.
  28. The address of CMD53 is related to the length requested to read from/write to
  29. the slave in a single transfer:
  30. *requested length = 0x1F800-address*
  31. The slave will respond with the length according to the length field in
  32. CMD53, with the data longer than *requested length* filled with 0 (sending)
  33. or discard (receiving).
  34. .. note:: This includes both the block and the byte mode of CMD53.
  35. The function number should be set to 1, OP Code should be set to 1 (for CMD53).
  36. It is allowed to use CMD53 mode combination of block+byte to get higher
  37. effeciency when accessing the FIFO by arbitrary length. E.g. The block
  38. size is set to 512 by default, you can write/get 1031 bytes of data
  39. to/from the FIFO by:
  40. 1. Send CMD53 in block mode, block count=2 (1024 bytes) to address
  41. 0x1F3F9=0x1F800-**1031**.
  42. 2. Then send CMD53 in byte mode, byte count=8 (or 7 if your controller
  43. supports that) to address 0x1F7F9=0x1F800-**7**.
  44. Interrupts
  45. ----------
  46. For the host interrupts, the slave raise the interrupt by pulling DAT1 line down at a proper time (level sensitive).
  47. The host detect this and read the INT_ST register to see the source. Then the host can clear it by writing the INT_CLR
  48. register and do something with the interrupt. The host can also mask unneeded sources by clearing the bits in INT_ENA
  49. register corresponding to the sources. If all the sources are cleared (or masked), the DAT1 line goes inactive.
  50. ``sdio_slave_hostint_t`` (:doc:`sdio_slave`) shows the bit definition corresponding to host interrupt sources.
  51. For the slave interrupts, the host send transfers to write the SLAVE_INT register. Once a bit is written from 0 to 1,
  52. the slave hardware and driver will detect it and inform the app.
  53. Receiving FIFO
  54. --------------
  55. To write the receiving FIFO in the slave, host should work in the following steps:
  56. 1. Read the TOKEN1 field (bits 27-16) of TOKEN_RDATA (0x044) register. The buffer number remaining is TOKEN1 minus
  57. the number of buffers used by host.
  58. 2. Make sure the buffer number is sufficient (*buffer_size* * *buffer_num* is greater than data to write, *buffer_size*
  59. is pre-defined between the host and the slave before the communication starts). Or go back to step 1 until the buffer
  60. is enough.
  61. 3. Write to the FIFO address with CMD53. Note that the *requested length* should not be larger than calculated in step 2,
  62. and the FIFO address is related to *rquested length*.
  63. 4. Calculate used buffers, note that non-full buffer at the tail should be seen as one that is used.
  64. Sending FIFO
  65. ------------
  66. To read the sending FIFO in the slave, host should work in the following steps:
  67. 1. Wait for the interrupt line to be active (optional, low by default).
  68. 2. Read (poll) the interrupt bits in INT_ST register to see whether new packets exists.
  69. 3. If new packets are ready, reads the PKT_LEN reg. The data length to read from slave is PKT_LEN minuses the length
  70. that has been read from the host. If the PKT_LEN is not larger than used, wait and poll until the slave is ready and
  71. update the PKT_LEN.
  72. 4. Read from the FIFO with CMD53. Note that the *requested length* should not be larger than calculated in step3, and
  73. the FIFO address is related to *requested length*.
  74. 5. Recored read length.