esp_serial_slave_link.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. For more details about ESP32 SDIO slave protocol, see document :doc:`/api-reference/peripherals/esp_slave_protocol`.
  12. Terminology
  13. -----------
  14. - ESSL: Abbreviation for ESP Serial Slave Link, the component described by this document.
  15. - Master: The device running the `esp_serial_slave_link` component.
  16. - ESSL device: a virtual device on the master associated with an ESP slave device. The device
  17. context has the knowledge of the slave protocol above the bus, relying on some bus drivers to
  18. communicate with the slave.
  19. - ESSL device handle: a handle to ESSL device context containing the configuration, status and
  20. data required by the ESSL component. The context stores the driver configurations,
  21. communication state, data shared by master and slave, etc.
  22. The context should be initialized before it is used, and get deinitialized if not used any more. The
  23. master application operates on the ESSL device through this handle.
  24. - ESP slave: the slave device connected to the bus, which ESSL component is designed to
  25. communicate with.
  26. - Bus: The bus over which the master and the slave communicate with each other.
  27. - Slave protocol: The special communication protocol specified by Espressif HW/SW over the bus.
  28. - TX buffer num: a counter, which is on the slave and can be read by the master, indicates the
  29. accumulated buffer numbers that the slave has loaded to the hardware to receive data from the
  30. master.
  31. - RX data size: a counter, which is on the slave and can be read by the master, indicates the
  32. accumulated data size that the slave has loaded to the hardware to send to the master.
  33. Services provided by ESP slave
  34. ------------------------------
  35. There are some common services provided by the Espressif slaves:
  36. 1. Tohost Interrupts: The slave can inform the master about certain events by the interrupt line.
  37. 2. Frhost Interrupts: The master can inform the slave about certain events.
  38. 3. Tx FIFO (master to slave): the slave can send data in stream to the master. The SDIO slave can
  39. also indicate it has new data to send to master by the interrupt line.
  40. The slave updates the TX buffer num to inform the master how much data it can receive, and the
  41. master then read the TX buffer num, and take off the used buffer number to know how many buffers are remaining.
  42. 4. Rx FIFO (slave to master): the slave can receive data from the master in units of receiving
  43. buffers.
  44. The slave updates the RX data size to inform the master how much data it has prepared to
  45. send, and then the master read the data size, and take off the data length it has already received to know how many
  46. data is remaining.
  47. 5. Shared registers: the master can read some part of the registers on the slave, and also write
  48. these registers to let the slave read.
  49. Initialization of ESP SDIO Slave Link
  50. -------------------------------------
  51. The ESP SDIO slave link (ESSL SDIO) devices relies on the sdmmc component. The ESSL device should
  52. be initialized as below:
  53. 1. Initialize a sdmmc card (see :doc:` Document of SDMMC driver </api-reference/storage/sdmmc>`)
  54. structure.
  55. 2. Call :cpp:func:`sdmmc_card_init` to initialize the card.
  56. 3. Initialize the ESSL device with :cpp:type:`essl_sdio_config_t`. The `card` member should be
  57. the :cpp:type:`sdmmc_card_t` got in step 2, and the `recv_buffer_size` member should be filled
  58. correctly according to pre-negotiated value.
  59. 4. Call :cpp:func:`essl_init` to do initialization of the SDIO part.
  60. 5. Call :cpp:func:`essl_wait_for_ready` to wait for the slave to be ready.
  61. APIs
  62. ----
  63. After the initialization process above is performed, you can call the APIs below to make use of
  64. the services provided by the slave:
  65. Interrupts
  66. ^^^^^^^^^^
  67. 1. Call :cpp:func:`essl_get_intr_ena` to know which events will trigger the interrupts to the master.
  68. 2. Call :cpp:func:`essl_set_intr_ena` to set the events that will trigger interrupts to the master.
  69. 3. Call :cpp:func:`essl_wait_int` to wait until interrupt from the slave, or timeout.
  70. 4. When interrupt is triggered, call :cpp:func:`essl_get_intr` to know which events are active,
  71. and call :cpp:func:`essl_clear_intr` to clear them.
  72. 5. Call :cpp:func:`essl_send_slave_intr` to trigger general purpose interrupt of the slave.
  73. TX FIFO
  74. ^^^^^^^
  75. 1. Call :cpp:func:`essl_get_tx_buffer_num` to know how many buffers the slave has prepared to
  76. receive data from the master. This is optional. The master will poll `tx_buffer_num` when it try
  77. to send packets to the slave, until the slave has enough buffer or timeout.
  78. 2. Call :cpp:func:`essl_send_paket` to send data to the slave.
  79. RX FIFO
  80. ^^^^^^^
  81. 1. Call :cpp:func:`essl_get_rx_data_size` to know how many data the slave has prepared to send to
  82. the master. This is optional. When the master tries to receive data from the slave, it will update
  83. the `rx_data_size` for once, if the current `rx_data_size` is shorter than the buffer size the
  84. master prepared to receive. And it may poll the `rx_data_size` if the `rx_dat_size` keeps 0,
  85. until timeout.
  86. 2. Call :cpp:func:`essl_get_packet` to receive data from the slave.
  87. Reset counters (Optional)
  88. ^^^^^^^^^^^^^^^^^^^^^^^^^
  89. Call :cpp:func:`essl_reset_cnt` to reset the internal counter if you find the slave has reset its
  90. counter.
  91. Application Example
  92. -------------------
  93. The example below shows how ESP32 SDIO host and slave communicate with each other. The host use the ESSL SDIO.
  94. :example:`peripherals/sdio`.
  95. Please refer to the specific example README.md for details.
  96. API Reference
  97. -------------
  98. .. include:: /_build/inc/essl.inc
  99. .. include:: /_build/inc/essl_sdio.inc