mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'fix/spi_buslock_unregister_issue_v5.5' into 'release/v5.5'
fix(hw_support): spi buslock fix unregister dev api issue (v5.5) See merge request espressif/esp-idf!51473
This commit is contained in:
@@ -609,6 +609,7 @@ esp_err_t spi_bus_remove_device(spi_device_handle_t handle)
|
|||||||
//catch design errors and aren't meant to be triggered during normal operation.
|
//catch design errors and aren't meant to be triggered during normal operation.
|
||||||
SPI_CHECK(uxQueueMessagesWaiting(handle->trans_queue) == 0, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
SPI_CHECK(uxQueueMessagesWaiting(handle->trans_queue) == 0, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
||||||
SPI_CHECK(handle->host->cur_cs == DEV_NUM_MAX || handle->host->device[handle->host->cur_cs] != handle, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
SPI_CHECK(handle->host->cur_cs == DEV_NUM_MAX || handle->host->device[handle->host->cur_cs] != handle, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
||||||
|
SPI_CHECK(handle->host->device_acquiring_lock != handle, "Device has acquired the bus", ESP_ERR_INVALID_STATE);
|
||||||
if (handle->ret_queue) {
|
if (handle->ret_queue) {
|
||||||
SPI_CHECK(uxQueueMessagesWaiting(handle->ret_queue) == 0, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
SPI_CHECK(uxQueueMessagesWaiting(handle->ret_queue) == 0, "Have unfinished transactions", ESP_ERR_INVALID_STATE);
|
||||||
}
|
}
|
||||||
@@ -1177,7 +1178,7 @@ static SPI_MASTER_ISR_ATTR void uninstall_priv_desc(spi_trans_priv_t* trans_buf)
|
|||||||
|
|
||||||
// copy data from temporary DMA-capable buffer back to trans_desc buffer and free the temporary one.
|
// copy data from temporary DMA-capable buffer back to trans_desc buffer and free the temporary one.
|
||||||
void *orig_rx_buffer = (trans_desc->flags & SPI_TRANS_USE_RXDATA) ? trans_desc->rx_data : trans_desc->rx_buffer;
|
void *orig_rx_buffer = (trans_desc->flags & SPI_TRANS_USE_RXDATA) ? trans_desc->rx_data : trans_desc->rx_buffer;
|
||||||
if (trans_buf->buffer_to_rcv != orig_rx_buffer) {
|
if (trans_buf->buffer_to_rcv && trans_buf->buffer_to_rcv != orig_rx_buffer) {
|
||||||
memcpy(orig_rx_buffer, trans_buf->buffer_to_rcv, (trans_desc->rxlength + 7) / 8);
|
memcpy(orig_rx_buffer, trans_buf->buffer_to_rcv, (trans_desc->rxlength + 7) / 8);
|
||||||
free(trans_buf->buffer_to_rcv);
|
free(trans_buf->buffer_to_rcv);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ static void SPI_SLAVE_ISR_ATTR spi_slave_uninstall_priv_trans(spi_host_device_t
|
|||||||
if (trans->tx_buffer && (trans->tx_buffer != priv_trans->tx_buffer)) {
|
if (trans->tx_buffer && (trans->tx_buffer != priv_trans->tx_buffer)) {
|
||||||
free(priv_trans->tx_buffer);
|
free(priv_trans->tx_buffer);
|
||||||
}
|
}
|
||||||
if (trans->rx_buffer && (trans->rx_buffer != priv_trans->rx_buffer)) {
|
if (priv_trans->rx_buffer && (trans->rx_buffer != priv_trans->rx_buffer)) {
|
||||||
memcpy(trans->rx_buffer, priv_trans->rx_buffer, (trans->length + 7) / 8);
|
memcpy(trans->rx_buffer, priv_trans->rx_buffer, (trans->length + 7) / 8);
|
||||||
free(priv_trans->rx_buffer);
|
free(priv_trans->rx_buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ static void s_spi_slave_hd_destroy_priv_trans(spi_host_device_t host, spi_slave_
|
|||||||
{
|
{
|
||||||
#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
|
||||||
spi_slave_hd_data_t *orig_trans = priv_trans->trans;
|
spi_slave_hd_data_t *orig_trans = priv_trans->trans;
|
||||||
if (priv_trans->aligned_buffer != orig_trans->data) {
|
if (priv_trans->aligned_buffer && priv_trans->aligned_buffer != orig_trans->data) {
|
||||||
if (chan == SPI_SLAVE_CHAN_RX) {
|
if (chan == SPI_SLAVE_CHAN_RX) {
|
||||||
memcpy(orig_trans->data, priv_trans->aligned_buffer, orig_trans->trans_len);
|
memcpy(orig_trans->data, priv_trans->aligned_buffer, orig_trans->trans_len);
|
||||||
}
|
}
|
||||||
@@ -799,7 +799,7 @@ esp_err_t s_spi_slave_hd_append_rxdma(spi_slave_hd_slot_t *host, uint8_t *data,
|
|||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
spicommon_dma_desc_setup_link(hal->rx_cur_desc->desc, data, len, false);
|
spicommon_dma_desc_setup_link(hal->rx_cur_desc->desc, data, len, true);
|
||||||
hal->rx_cur_desc->arg = arg;
|
hal->rx_cur_desc->arg = arg;
|
||||||
|
|
||||||
if (!hal->rx_used_desc_cnt) {
|
if (!hal->rx_used_desc_cnt) {
|
||||||
|
|||||||
@@ -703,10 +703,16 @@ void spi_bus_lock_unregister_dev(spi_bus_lock_dev_handle_t dev_handle)
|
|||||||
|
|
||||||
spi_bus_lock_t* lock = dev_handle->parent;
|
spi_bus_lock_t* lock = dev_handle->parent;
|
||||||
BUS_LOCK_DEBUG_EXECUTE_CHECK(atomic_load(&lock->dev[id]) == (intptr_t)dev_handle);
|
BUS_LOCK_DEBUG_EXECUTE_CHECK(atomic_load(&lock->dev[id]) == (intptr_t)dev_handle);
|
||||||
|
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock->acquiring_dev != dev_handle);
|
||||||
|
BUS_LOCK_DEBUG_EXECUTE_CHECK((lock_status_fetch(lock) & dev_handle->mask) == 0);
|
||||||
|
|
||||||
if (lock->last_dev == dev_handle) {
|
if (lock->last_dev == dev_handle) {
|
||||||
lock->last_dev = NULL;
|
lock->last_dev = NULL;
|
||||||
}
|
}
|
||||||
|
if (lock->acquiring_dev == dev_handle) {
|
||||||
|
lock->acquiring_dev = NULL;
|
||||||
|
lock->acq_dev_bg_active = false;
|
||||||
|
}
|
||||||
|
|
||||||
atomic_store(&lock->dev[id], (intptr_t)NULL);
|
atomic_store(&lock->dev[id], (intptr_t)NULL);
|
||||||
if (dev_handle->semphr) {
|
if (dev_handle->semphr) {
|
||||||
@@ -733,6 +739,11 @@ void spi_bus_lock_set_bg_control(spi_bus_lock_handle_t lock, bg_ctrl_func_t bg_e
|
|||||||
lock->bg_arg = arg;
|
lock->bg_arg = arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IRAM_ATTR spi_bus_lock_handle_t spi_bus_lock_get_parent(spi_bus_lock_dev_handle_t dev_handle)
|
||||||
|
{
|
||||||
|
return (dev_handle ? dev_handle->parent : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
IRAM_ATTR int spi_bus_lock_get_dev_id(spi_bus_lock_dev_handle_t dev_handle)
|
IRAM_ATTR int spi_bus_lock_get_dev_id(spi_bus_lock_dev_handle_t dev_handle)
|
||||||
{
|
{
|
||||||
return (dev_handle ? dev_lock_get_id(dev_handle) : -1);
|
return (dev_handle ? dev_lock_get_id(dev_handle) : -1);
|
||||||
|
|||||||
@@ -448,17 +448,21 @@ esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip)
|
|||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spi_bus_lock_dev_handle_t dev_handle = NULL;
|
||||||
|
esp_err_t ret = esp_flash_deinit_os_functions(chip, &dev_handle);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Disable GPSPI clocks before cleanup
|
// Disable GPSPI clocks before cleanup
|
||||||
deinit_gpspi_clock(chip);
|
deinit_gpspi_clock(chip);
|
||||||
|
|
||||||
spi_bus_lock_dev_handle_t dev_handle = NULL;
|
|
||||||
esp_flash_deinit_os_functions(chip, &dev_handle);
|
|
||||||
if (dev_handle) {
|
if (dev_handle) {
|
||||||
spi_bus_lock_unregister_dev(dev_handle);
|
spi_bus_lock_unregister_dev(dev_handle);
|
||||||
}
|
}
|
||||||
free(chip->host);
|
free(chip->host);
|
||||||
free(chip);
|
free(chip);
|
||||||
return ESP_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default (ie initial boot) no-OS ROM esp_flash_os_functions_t */
|
/* The default (ie initial boot) no-OS ROM esp_flash_os_functions_t */
|
||||||
|
|||||||
@@ -69,7 +69,9 @@ esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, spi_bus_lo
|
|||||||
* @param chip The chip to deinit os functions
|
* @param chip The chip to deinit os functions
|
||||||
* @param out_dev_handle The SPI bus lock passed from `esp_flash_init_os_functions`. The caller should deinitialize
|
* @param out_dev_handle The SPI bus lock passed from `esp_flash_init_os_functions`. The caller should deinitialize
|
||||||
* the lock.
|
* the lock.
|
||||||
* @return always ESP_OK.
|
* @return
|
||||||
|
* - ESP_ERR_INVALID_STATE: the chip is still acquiring the SPI bus lock.
|
||||||
|
* - ESP_OK: success.
|
||||||
*/
|
*/
|
||||||
esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle);
|
esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle);
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ esp_err_t spi_bus_add_flash_device(esp_flash_t **out_chip, const esp_flash_spi_d
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* - ESP_ERR_INVALID_ARG: The chip is invalid.
|
* - ESP_ERR_INVALID_ARG: The chip is invalid.
|
||||||
|
* - ESP_ERR_INVALID_STATE: The chip is still acquiring the SPI bus lock.
|
||||||
* - ESP_OK: success.
|
* - ESP_OK: success.
|
||||||
*/
|
*/
|
||||||
esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip);
|
esp_err_t spi_bus_remove_flash_device(esp_flash_t *chip);
|
||||||
|
|||||||
@@ -484,9 +484,15 @@ esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, spi_bus_lo
|
|||||||
|
|
||||||
esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle)
|
esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle)
|
||||||
{
|
{
|
||||||
|
*out_dev_handle = NULL;
|
||||||
if (chip->os_func_data) {
|
if (chip->os_func_data) {
|
||||||
|
app_func_arg_t *ctx = (app_func_arg_t*)chip->os_func_data;
|
||||||
|
spi_bus_lock_dev_handle_t dev_handle = ctx->dev_lock;
|
||||||
|
if (dev_handle && spi_bus_lock_get_acquiring_dev(spi_bus_lock_get_parent(dev_handle)) == dev_handle) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
// SPI bus lock is possibly not used on SPI1 bus
|
// SPI bus lock is possibly not used on SPI1 bus
|
||||||
*out_dev_handle = ((app_func_arg_t*)chip->os_func_data)->dev_lock;
|
*out_dev_handle = dev_handle;
|
||||||
free(chip->os_func_data);
|
free(chip->os_func_data);
|
||||||
}
|
}
|
||||||
chip->os_func = NULL;
|
chip->os_func = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user