mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-02 13:45:46 +00:00
spi: refactor spi_common dma allocator
This commit is contained in:
@@ -29,6 +29,8 @@ extern "C"
|
||||
|
||||
//Maximum amount of bytes that can be put in one DMA descriptor
|
||||
#define SPI_MAX_DMA_LEN (4096-4)
|
||||
//Set the ``dma_chan`` to this, then driver will auto-alloc a DMA channel
|
||||
#define DMA_AUTO_CHAN (-2)
|
||||
|
||||
/**
|
||||
* Transform unsigned integer of length <= 32 bits to the format which can be
|
||||
@@ -103,13 +105,15 @@ typedef struct {
|
||||
*
|
||||
* @warning For now, only supports HSPI and VSPI.
|
||||
*
|
||||
* @param host_id SPI peripheral that controls this bus
|
||||
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
|
||||
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
|
||||
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
|
||||
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
|
||||
* the SPI flash uses this bus. Set -1 to let the driver to allocate the DMA channel.
|
||||
* @param host_id SPI peripheral that controls this bus
|
||||
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
|
||||
* @param dma_chan - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
|
||||
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
|
||||
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
|
||||
* the SPI flash uses this bus. Set to DMA_AUTO_CHAN to let the driver to allocate the DMA channel.
|
||||
*
|
||||
* @warning If a DMA channel is selected, any transmit and receive buffer used should be allocated in
|
||||
* DMA-capable memory.
|
||||
@@ -120,7 +124,8 @@ typedef struct {
|
||||
*
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if configuration is invalid
|
||||
* - ESP_ERR_INVALID_STATE if host already is in use or DMA channel is not available
|
||||
* - ESP_ERR_INVALID_STATE if host already is in use
|
||||
* - ESP_ERR_NOT_FOUND if there is no available DMA channel
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
|
||||
@@ -118,41 +118,29 @@ bool spicommon_periph_in_use(spi_host_device_t host);
|
||||
bool spicommon_periph_free(spi_host_device_t host);
|
||||
|
||||
/**
|
||||
* @brief Check whether the spi DMA channel is in use.
|
||||
*
|
||||
* @param dma_chan DMA channel to check.
|
||||
*
|
||||
* @note This public API is deprecated.
|
||||
*
|
||||
* @return True if in use, otherwise false.
|
||||
*/
|
||||
bool spicommon_dma_chan_in_use(int dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Configure DMA for SPI Slave
|
||||
* @brief Alloc DMA for SPI Slave
|
||||
*
|
||||
* @param host_id SPI host ID
|
||||
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
* @param dma_chan DMA_AUTO_CHAN: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
* @param[out] out_actual_tx_dma_chan Actual TX DMA channel (if you choose to assign a specific DMA channel, this will be the channel you assigned before)
|
||||
* @param[out] out_actual_rx_dma_chan Actual RX DMA channel (if you choose to assign a specific DMA channel, this will be the channel you assigned before)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
* - ESP_ERR_NO_MEM: No enough memory
|
||||
* - ESP_ERR_INVALID_STATE: Driver invalid state, check the log message for details
|
||||
* - ESP_ERR_NOT_FOUND: There is no available DMA channel
|
||||
*/
|
||||
esp_err_t spicommon_slave_alloc_dma(spi_host_device_t host_id, int dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan);
|
||||
esp_err_t spicommon_slave_dma_chan_alloc(spi_host_device_t host_id, int dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Free DMA for SPI Slave
|
||||
*
|
||||
* @param host_id SPI host ID
|
||||
* @param dma_chan Actual used DMA channel
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
*/
|
||||
esp_err_t spicommon_slave_free_dma(spi_host_device_t host_id, int dma_chan);
|
||||
esp_err_t spicommon_slave_free_dma(spi_host_device_t host_id);
|
||||
|
||||
/**
|
||||
* @brief Connect a SPI peripheral to GPIO pins
|
||||
|
||||
@@ -90,14 +90,16 @@ struct spi_slave_transaction_t {
|
||||
*
|
||||
* @warning For now, only supports HSPI and VSPI.
|
||||
*
|
||||
* @param host SPI peripheral to use as a SPI slave interface
|
||||
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
|
||||
* @param slave_config Pointer to a spi_slave_interface_config_t struct specifying the details for the slave interface
|
||||
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
|
||||
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
|
||||
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
|
||||
* the SPI flash uses this bus. Set -1 to let the driver to allocate the DMA channel.
|
||||
* @param host SPI peripheral to use as a SPI slave interface
|
||||
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
|
||||
* @param slave_config Pointer to a spi_slave_interface_config_t struct specifying the details for the slave interface
|
||||
* @param dma_chan - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
|
||||
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
|
||||
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
|
||||
* the SPI flash uses this bus. Set to DMA_AUTO_CHAN to let the driver to allocate the DMA channel.
|
||||
*
|
||||
* @warning If a DMA channel is selected, any transmit and receive buffer used should be allocated in
|
||||
* DMA-capable memory.
|
||||
@@ -108,7 +110,8 @@ struct spi_slave_transaction_t {
|
||||
*
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if configuration is invalid
|
||||
* - ESP_ERR_INVALID_STATE if host already is in use or DMA channel is not available
|
||||
* - ESP_ERR_INVALID_STATE if host already is in use
|
||||
* - ESP_ERR_NOT_FOUND if there is no available DMA channel
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
|
||||
@@ -86,7 +86,11 @@ typedef struct {
|
||||
uint32_t address_bits; ///< address field bits, multiples of 8 and at least 8.
|
||||
uint32_t dummy_bits; ///< dummy field bits, multiples of 8 and at least 8.
|
||||
uint32_t queue_size; ///< Transaction queue size. This sets how many transactions can be 'in the air' (queued using spi_slave_hd_queue_trans but not yet finished using spi_slave_hd_get_trans_result) at the same time
|
||||
int dma_chan; ///< DMA channel used. -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
int dma_chan; /**< DMA channel to used.
|
||||
* - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
*/
|
||||
spi_slave_hd_callback_config_t cb_config; ///< Callback configuration
|
||||
} spi_slave_hd_slot_config_t;
|
||||
|
||||
@@ -97,10 +101,11 @@ typedef struct {
|
||||
* @param bus_config Bus configuration for the bus used
|
||||
* @param config Configuration for the SPI Slave HD driver
|
||||
* @return
|
||||
* - ESP_OK: on success
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument given
|
||||
* - ESP_OK: on success
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument given
|
||||
* - ESP_ERR_INVALID_STATE: function called in invalid state, may be some resources are already in use
|
||||
* - ESP_ERR_NO_MEM: memory allocation failed
|
||||
* - ESP_ERR_NOT_FOUND if there is no available DMA channel
|
||||
* - ESP_ERR_NO_MEM: memory allocation failed
|
||||
* - or other return value from `esp_intr_alloc`
|
||||
*/
|
||||
esp_err_t spi_slave_hd_init(spi_host_device_t host_id, const spi_bus_config_t *bus_config,
|
||||
|
||||
Reference in New Issue
Block a user