diff --git a/components/esp_hw_support/dma/gdma.c b/components/esp_hw_support/dma/gdma.c index 1d55e466d5..0cbd5ae455 100644 --- a/components/esp_hw_support/dma/gdma.c +++ b/components/esp_hw_support/dma/gdma.c @@ -359,6 +359,24 @@ err: return ret; } +esp_err_t gdma_set_priority(gdma_channel_handle_t dma_chan, uint32_t priority) +{ + gdma_pair_t *pair = NULL; + gdma_group_t *group = NULL; + ESP_RETURN_ON_FALSE(dma_chan && priority <= GDMA_LL_CHANNEL_MAX_PRIORITY, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); + pair = dma_chan->pair; + group = pair->group; + + if (dma_chan->direction == GDMA_CHANNEL_DIRECTION_TX) { + gdma_ll_tx_set_priority(group->hal.dev, pair->pair_id, priority); + } else { + gdma_ll_rx_set_priority(group->hal.dev, pair->pair_id, priority); + } + + return ESP_OK; + +} + esp_err_t gdma_register_tx_event_callbacks(gdma_channel_handle_t dma_chan, gdma_tx_event_callbacks_t *cbs, void *user_data) { esp_err_t ret = ESP_OK; @@ -651,6 +669,8 @@ static esp_err_t gdma_del_tx_channel(gdma_channel_t *dma_channel) ESP_LOGD(TAG, "uninstall interrupt service for tx channel (%d,%d)", group_id, pair_id); } + gdma_ll_tx_set_priority(group->hal.dev, pair_id, 0); // reset the priority to 0 (lowest) + free(tx_chan); ESP_LOGD(TAG, "del tx channel (%d,%d)", group_id, pair_id); // channel has a reference on pair, release it now @@ -679,6 +699,8 @@ static esp_err_t gdma_del_rx_channel(gdma_channel_t *dma_channel) ESP_LOGD(TAG, "uninstall interrupt service for rx channel (%d,%d)", group_id, pair_id); } + gdma_ll_rx_set_priority(group->hal.dev, pair_id, 0); // reset the priority to 0 (lowest) + free(rx_chan); ESP_LOGD(TAG, "del rx channel (%d,%d)", group_id, pair_id); gdma_release_pair_handle(pair); diff --git a/components/esp_hw_support/include/esp_private/gdma.h b/components/esp_hw_support/include/esp_private/gdma.h index d71f3c6fc8..08c3f8f688 100644 --- a/components/esp_hw_support/include/esp_private/gdma.h +++ b/components/esp_hw_support/include/esp_private/gdma.h @@ -177,14 +177,28 @@ esp_err_t gdma_set_transfer_ability(gdma_channel_handle_t dma_chan, const gdma_t /** * @brief Apply channel strategy for GDMA channel * - * @param dma_chan GDMA channel handle, allocated by `gdma_new_channel` - * @param config Configuration of GDMA channel strategy + * @param[in] dma_chan GDMA channel handle, allocated by `gdma_new_channel` + * @param[in] config Configuration of GDMA channel strategy * - ESP_OK: Apply channel strategy successfully * - ESP_ERR_INVALID_ARG: Apply channel strategy failed because of invalid argument * - ESP_FAIL: Apply channel strategy failed because of other error */ esp_err_t gdma_apply_strategy(gdma_channel_handle_t dma_chan, const gdma_strategy_config_t *config); +/** + * @brief Set GDMA channel priority + * + * @note By default, all GDMA channels are with the same priority: 0. Channels with the same priority are served in round-robin manner. + * + * @param[in] dma_chan GDMA channel handle, allocated by `gdma_new_channel` + * @param[in] priority Priority of GDMA channel, higher value means higher priority + * @return + * - ESP_OK: Set GDMA channel priority successfully + * - ESP_ERR_INVALID_ARG: Set GDMA channel priority failed because of invalid argument, e.g. priority out of range [0,GDMA_LL_CHANNEL_MAX_PRIORITY] + * - ESP_FAIL: Set GDMA channel priority failed because of other error + */ +esp_err_t gdma_set_priority(gdma_channel_handle_t dma_chan, uint32_t priority); + /** * @brief Delete GDMA channel * @note If you call `gdma_new_channel` several times for a same peripheral, make sure you call this API the same times. diff --git a/components/hal/esp32c2/include/hal/gdma_ll.h b/components/hal/esp32c2/include/hal/gdma_ll.h index 639309f972..966e7836f0 100644 --- a/components/hal/esp32c2/include/hal/gdma_ll.h +++ b/components/hal/esp32c2/include/hal/gdma_ll.h @@ -18,6 +18,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x06A7) #define GDMA_LL_TX_EVENT_MASK (0x1958) diff --git a/components/hal/esp32c3/include/hal/gdma_ll.h b/components/hal/esp32c3/include/hal/gdma_ll.h index 617b118f21..3ccb5a0fac 100644 --- a/components/hal/esp32c3/include/hal/gdma_ll.h +++ b/components/hal/esp32c3/include/hal/gdma_ll.h @@ -18,6 +18,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x06A7) #define GDMA_LL_TX_EVENT_MASK (0x1958) diff --git a/components/hal/esp32c6/include/hal/gdma_ll.h b/components/hal/esp32c6/include/hal/gdma_ll.h index 21c55bfdad..57969ca513 100644 --- a/components/hal/esp32c6/include/hal/gdma_ll.h +++ b/components/hal/esp32c6/include/hal/gdma_ll.h @@ -19,6 +19,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x7F) #define GDMA_LL_TX_EVENT_MASK (0x3F) diff --git a/components/hal/esp32h2/include/hal/gdma_ll.h b/components/hal/esp32h2/include/hal/gdma_ll.h index 21c55bfdad..57969ca513 100644 --- a/components/hal/esp32h2/include/hal/gdma_ll.h +++ b/components/hal/esp32h2/include/hal/gdma_ll.h @@ -19,6 +19,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x7F) #define GDMA_LL_TX_EVENT_MASK (0x3F) diff --git a/components/hal/esp32h4/include/hal/gdma_ll.h b/components/hal/esp32h4/include/hal/gdma_ll.h index 617b118f21..3ccb5a0fac 100644 --- a/components/hal/esp32h4/include/hal/gdma_ll.h +++ b/components/hal/esp32h4/include/hal/gdma_ll.h @@ -18,6 +18,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x06A7) #define GDMA_LL_TX_EVENT_MASK (0x1958) diff --git a/components/hal/esp32s3/include/hal/gdma_ll.h b/components/hal/esp32s3/include/hal/gdma_ll.h index 2fc7029303..88ca2b91c4 100644 --- a/components/hal/esp32s3/include/hal/gdma_ll.h +++ b/components/hal/esp32s3/include/hal/gdma_ll.h @@ -18,6 +18,8 @@ extern "C" { #define GDMA_LL_GET_HW(id) (((id) == 0) ? (&GDMA) : NULL) +#define GDMA_LL_CHANNEL_MAX_PRIORITY 5 // supported priority levels: [0,5] + #define GDMA_LL_RX_EVENT_MASK (0x3FF) #define GDMA_LL_TX_EVENT_MASK (0xFF)