forked from espressif/esp-idf
Merge branch 'feature/reduce-overhead-of-xQueueSendFromISR' into 'master'
SPI Master: add callback feature to reducing overhead Closes IDFGH-7584 See merge request espressif/esp-idf!18969
This commit is contained in:
@@ -43,7 +43,7 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
#define SPI_DEVICE_NO_DUMMY (1<<6)
|
#define SPI_DEVICE_NO_DUMMY (1<<6)
|
||||||
#define SPI_DEVICE_DDRCLK (1<<7)
|
#define SPI_DEVICE_DDRCLK (1<<7)
|
||||||
|
#define SPI_DEVICE_NO_RETURN_RESULT (1<<8) ///< Don't return the descriptor to the host on completion (use post_cb to notify instead)
|
||||||
|
|
||||||
typedef struct spi_transaction_t spi_transaction_t;
|
typedef struct spi_transaction_t spi_transaction_t;
|
||||||
typedef void(*transaction_cb_t)(spi_transaction_t *trans);
|
typedef void(*transaction_cb_t)(spi_transaction_t *trans);
|
||||||
@@ -166,7 +166,8 @@ typedef struct spi_device_t *spi_device_handle_t; ///< Handle for a device on a
|
|||||||
* @param dev_config SPI interface protocol config for the device
|
* @param dev_config SPI interface protocol config for the device
|
||||||
* @param handle Pointer to variable to hold the device handle
|
* @param handle Pointer to variable to hold the device handle
|
||||||
* @return
|
* @return
|
||||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
* - ESP_ERR_INVALID_ARG if parameter is invalid or configuration combination is not supported (e.g.
|
||||||
|
* `dev_config->post_cb` isn't set while flag `SPI_DEVICE_NO_RETURN_RESULT` is enabled)
|
||||||
* - ESP_ERR_NOT_FOUND if host doesn't have any free CS slots
|
* - ESP_ERR_NOT_FOUND if host doesn't have any free CS slots
|
||||||
* - ESP_ERR_NO_MEM if out of memory
|
* - ESP_ERR_NO_MEM if out of memory
|
||||||
* - ESP_OK on success
|
* - ESP_OK on success
|
||||||
|
@@ -329,6 +329,12 @@ esp_err_t spi_bus_add_device(spi_host_device_t host_id, const spi_device_interfa
|
|||||||
SPI_CHECK(dev_config->cs_ena_pretrans <= 1 || (dev_config->address_bits == 0 && dev_config->command_bits == 0) ||
|
SPI_CHECK(dev_config->cs_ena_pretrans <= 1 || (dev_config->address_bits == 0 && dev_config->command_bits == 0) ||
|
||||||
(dev_config->flags & SPI_DEVICE_HALFDUPLEX), "In full-duplex mode, only support cs pretrans delay = 1 and without address_bits and command_bits", ESP_ERR_INVALID_ARG);
|
(dev_config->flags & SPI_DEVICE_HALFDUPLEX), "In full-duplex mode, only support cs pretrans delay = 1 and without address_bits and command_bits", ESP_ERR_INVALID_ARG);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//Check post_cb status when `SPI_DEVICE_NO_RETURN_RESULT` flag is set.
|
||||||
|
if (dev_config->flags & SPI_DEVICE_NO_RETURN_RESULT) {
|
||||||
|
SPI_CHECK(dev_config->post_cb != NULL, "use feature flag 'SPI_DEVICE_NO_RETURN_RESULT' but no post callback function sets", ESP_ERR_INVALID_ARG);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t lock_flag = ((dev_config->spics_io_num != -1)? SPI_BUS_LOCK_DEV_FLAG_CS_REQUIRED: 0);
|
uint32_t lock_flag = ((dev_config->spics_io_num != -1)? SPI_BUS_LOCK_DEV_FLAG_CS_REQUIRED: 0);
|
||||||
|
|
||||||
spi_bus_lock_dev_config_t lock_config = {
|
spi_bus_lock_dev_config_t lock_config = {
|
||||||
@@ -612,9 +618,13 @@ static void SPI_MASTER_ISR_ATTR spi_intr(void *arg)
|
|||||||
|
|
||||||
//cur_cs is changed to DEV_NUM_MAX here
|
//cur_cs is changed to DEV_NUM_MAX here
|
||||||
spi_post_trans(host);
|
spi_post_trans(host);
|
||||||
// spi_bus_lock_bg_pause(bus_attr->lock);
|
|
||||||
|
if (!(host->device[cs]->cfg.flags & SPI_DEVICE_NO_RETURN_RESULT)) {
|
||||||
//Return transaction descriptor.
|
//Return transaction descriptor.
|
||||||
xQueueSendFromISR(host->device[cs]->ret_queue, &host->cur_trans_buf, &do_yield);
|
xQueueSendFromISR(host->device[cs]->ret_queue, &host->cur_trans_buf, &do_yield);
|
||||||
|
}
|
||||||
|
|
||||||
|
// spi_bus_lock_bg_pause(bus_attr->lock);
|
||||||
#ifdef CONFIG_PM_ENABLE
|
#ifdef CONFIG_PM_ENABLE
|
||||||
//Release APB frequency lock
|
//Release APB frequency lock
|
||||||
esp_pm_lock_release(bus_attr->pm_lock);
|
esp_pm_lock_release(bus_attr->pm_lock);
|
||||||
|
Reference in New Issue
Block a user