esp_serial_slave_link.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ESP Serial Slave Link
  2. =====================
  3. Overview
  4. --------
  5. Espressif provides several chips that can work as slaves. These slave devices rely on some
  6. common buses, and have their own communication protocols over those buses. The `esp_serial_slave_link` component is
  7. designed for the master to communicate with ESP slave devices through those protocols over the
  8. bus drivers.
  9. After an `esp_serial_slave_link` device is initialized properly, the application can use it to communicate with the ESP
  10. slave devices conveniently.
  11. Espressif Device protocols
  12. --------------------------
  13. For more details about Espressif device protocols, see the following documents.
  14. .. toctree::
  15. :maxdepth: 1
  16. :SOC_SDIO_SLAVE_SUPPORTED: esp_sdio_slave_protocol
  17. esp_spi_slave_protocol
  18. Terminology
  19. -----------
  20. - ESSL: Abbreviation for ESP Serial Slave Link, the component described by this document.
  21. - Master: The device running the `esp_serial_slave_link` component.
  22. - ESSL device: a virtual device on the master associated with an ESP slave device. The device
  23. context has the knowledge of the slave protocol above the bus, relying on some bus drivers to
  24. communicate with the slave.
  25. - ESSL device handle: a handle to ESSL device context containing the configuration, status and
  26. data required by the ESSL component. The context stores the driver configurations,
  27. communication state, data shared by master and slave, etc.
  28. The context should be initialized before it is used, and get deinitialized if not used any more. The
  29. master application operates on the ESSL device through this handle.
  30. - ESP slave: the slave device connected to the bus, which ESSL component is designed to
  31. communicate with.
  32. - Bus: The bus over which the master and the slave communicate with each other.
  33. - Slave protocol: The special communication protocol specified by Espressif HW/SW over the bus.
  34. - TX buffer num: a counter, which is on the slave and can be read by the master, indicates the
  35. accumulated buffer numbers that the slave has loaded to the hardware to receive data from the
  36. master.
  37. - RX data size: a counter, which is on the slave and can be read by the master, indicates the
  38. accumulated data size that the slave has loaded to the hardware to send to the master.
  39. Services provided by ESP slave
  40. ------------------------------
  41. There are some common services provided by the Espressif slaves:
  42. 1. Tohost Interrupts: The slave can inform the master about certain events by the interrupt line. (optional)
  43. 2. Frhost Interrupts: The master can inform the slave about certain events.
  44. 3. Tx FIFO (master to slave): the slave can send data in stream to the master. The SDIO slave can
  45. also indicate it has new data to send to master by the interrupt line.
  46. The slave updates the TX buffer num to inform the master how much data it can receive, and the
  47. master then read the TX buffer num, and take off the used buffer number to know how many buffers are remaining.
  48. 4. Rx FIFO (slave to master): the slave can receive data from the master in units of receiving
  49. buffers.
  50. The slave updates the RX data size to inform the master how much data it has prepared to
  51. send, and then the master read the data size, and take off the data length it has already received to know how many
  52. data is remaining.
  53. 5. Shared registers: the master can read some part of the registers on the slave, and also write
  54. these registers to let the slave read.
  55. .. only:: SOC_SDIO_SLAVE_SUPPORTED
  56. The services provided by the slave depends on the slave's model. See :ref:`esp_sdio_slave_caps` and :ref:`esp_spi_slave_caps` for more details.
  57. .. only:: not SOC_SDIO_SLAVE_SUPPORTED
  58. The services provided by the slave depends on the slave's model. See :ref:`esp_spi_slave_caps` for more details.
  59. Initialization of ESP Serial Slave Link
  60. ---------------------------------------
  61. .. _essl_sdio_slave_init:
  62. ESP SDIO Slave
  63. ^^^^^^^^^^^^^^
  64. The ESP SDIO slave link (ESSL SDIO) devices relies on the sdmmc component. It includes the usage
  65. of communicating with ESP SDIO Slave device via SDSPI feature. The ESSL device should be
  66. initialized as below:
  67. 1. Initialize a sdmmc card (see :doc:` Document of SDMMC driver </api-reference/storage/sdmmc>`)
  68. structure.
  69. 2. Call :cpp:func:`sdmmc_card_init` to initialize the card.
  70. 3. Initialize the ESSL device with :cpp:type:`essl_sdio_config_t`. The `card` member should be
  71. the :cpp:type:`sdmmc_card_t` got in step 2, and the `recv_buffer_size` member should be filled
  72. correctly according to pre-negotiated value.
  73. 4. Call :cpp:func:`essl_init` to do initialization of the SDIO part.
  74. 5. Call :cpp:func:`essl_wait_for_ready` to wait for the slave to be ready.
  75. ESP SPI Slave
  76. ^^^^^^^^^^^^^
  77. .. note::
  78. If you are communicating with the ESP SDIO Slave device through SPI interface, you should use
  79. the :ref:`SDIO interface <essl_sdio_slave_init>` instead.
  80. Hasn't been supported yet.
  81. APIs
  82. ----
  83. After the initialization process above is performed, you can call the APIs below to make use of
  84. the services provided by the slave:
  85. Tohost Interrupts (optional)
  86. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  87. 1. Call :cpp:func:`essl_get_intr_ena` to know which events will trigger the interrupts to the master.
  88. 2. Call :cpp:func:`essl_set_intr_ena` to set the events that will trigger interrupts to the master.
  89. 3. Call :cpp:func:`essl_wait_int` to wait until interrupt from the slave, or timeout.
  90. 4. When interrupt is triggered, call :cpp:func:`essl_get_intr` to know which events are active,
  91. and call :cpp:func:`essl_clear_intr` to clear them.
  92. Frhost Interrupts
  93. ^^^^^^^^^^^^^^^^^
  94. 1. Call :cpp:func:`essl_send_slave_intr` to trigger general purpose interrupt of the slave.
  95. TX FIFO
  96. ^^^^^^^
  97. 1. Call :cpp:func:`essl_get_tx_buffer_num` to know how many buffers the slave has prepared to
  98. receive data from the master. This is optional. The master will poll `tx_buffer_num` when it try
  99. to send packets to the slave, until the slave has enough buffer or timeout.
  100. 2. Call :cpp:func:`essl_send_packet` to send data to the slave.
  101. RX FIFO
  102. ^^^^^^^
  103. 1. Call :cpp:func:`essl_get_rx_data_size` to know how many data the slave has prepared to send to
  104. the master. This is optional. When the master tries to receive data from the slave, it will update
  105. the `rx_data_size` for once, if the current `rx_data_size` is shorter than the buffer size the
  106. master prepared to receive. And it may poll the `rx_data_size` if the `rx_dat_size` keeps 0,
  107. until timeout.
  108. 2. Call :cpp:func:`essl_get_packet` to receive data from the slave.
  109. Reset counters (Optional)
  110. ^^^^^^^^^^^^^^^^^^^^^^^^^
  111. Call :cpp:func:`essl_reset_cnt` to reset the internal counter if you find the slave has reset its
  112. counter.
  113. Application Example
  114. -------------------
  115. The example below shows how {IDF_TARGET_NAME} SDIO host and slave communicate with each other. The host use the ESSL SDIO.
  116. :example:`peripherals/sdio`.
  117. Please refer to the specific example README.md for details.
  118. API Reference
  119. -------------
  120. .. include-build-file:: inc/essl.inc
  121. .. include-build-file:: inc/essl_sdio.inc
  122. .. include-build-file:: inc/essl_spi.inc