mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 03:58:12 +00:00
refactor(emac): add LL functions for bus clock control
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -242,7 +242,7 @@ static esp_err_t emac_esp32_transmit_multiple_bufs(esp_eth_mac_t *mac, uint32_t
|
||||
uint32_t len[argc];
|
||||
uint32_t exp_len = 0;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
bufs[i] = va_arg(args, uint8_t*);
|
||||
bufs[i] = va_arg(args, uint8_t *);
|
||||
len[i] = va_arg(args, uint32_t);
|
||||
exp_len += len[i];
|
||||
}
|
||||
@@ -295,7 +295,7 @@ static void emac_esp32_rx_task(void *arg)
|
||||
ESP_LOGD(TAG, "receive len= %d", recv_len);
|
||||
emac->eth->stack_input(emac->eth, buffer, recv_len);
|
||||
}
|
||||
/* if allocation failed and there is a waiting frame */
|
||||
/* if allocation failed and there is a waiting frame */
|
||||
} else if (frame_len) {
|
||||
ESP_LOGE(TAG, "no mem for receive buffer");
|
||||
/* ensure that interface to EMAC does not get stuck with unprocessed frames */
|
||||
@@ -342,7 +342,7 @@ static esp_err_t emac_config_apll_clock(void)
|
||||
}
|
||||
// If the difference of real APLL frequency is not within 50 ppm, i.e. 2500 Hz, the APLL is unavailable
|
||||
ESP_RETURN_ON_FALSE(abs((int)real_freq - (int)expt_freq) <= 2500,
|
||||
ESP_ERR_INVALID_STATE, TAG, "The APLL is working at an unusable frequency");
|
||||
ESP_ERR_INVALID_STATE, TAG, "The APLL is working at an unusable frequency");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -381,9 +381,9 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac)
|
||||
esp_pm_lock_acquire(emac->pm_lock);
|
||||
#endif
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
||||
periph_module_disable(PERIPH_EMAC_MODULE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -427,7 +427,10 @@ static esp_err_t emac_esp32_del(esp_eth_mac_t *mac)
|
||||
{
|
||||
emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent);
|
||||
esp_emac_free_driver_obj(emac, emac_hal_get_desc_chain(&emac->hal));
|
||||
periph_module_disable(PERIPH_EMAC_MODULE);
|
||||
/// disable bus clock
|
||||
PERIPH_RCC_ATOMIC() {
|
||||
emac_ll_enable_bus_clock(0, false);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -601,12 +604,16 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config
|
||||
esp_eth_mac_t *ret = NULL;
|
||||
void *descriptors = NULL;
|
||||
emac_esp32_t *emac = NULL;
|
||||
ESP_GOTO_ON_FALSE(config, NULL, err, TAG, "can't set mac config to null");
|
||||
ESP_RETURN_ON_FALSE(config, NULL, TAG, "can't set mac config to null");
|
||||
ret_code = esp_emac_alloc_driver_obj(config, &emac, &descriptors);
|
||||
ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err, TAG, "alloc driver object failed");
|
||||
ESP_RETURN_ON_FALSE(ret_code == ESP_OK, NULL, TAG, "alloc driver object failed");
|
||||
|
||||
/* enable APB to access Ethernet peripheral registers */
|
||||
periph_module_enable(PERIPH_EMAC_MODULE);
|
||||
// enable bus clock for the EMAC module, and reset the registers into default state
|
||||
// this must be called before HAL layer initialization
|
||||
PERIPH_RCC_ATOMIC() {
|
||||
emac_ll_enable_bus_clock(0, true);
|
||||
emac_ll_reset_register(0);
|
||||
}
|
||||
/* initialize hal layer driver */
|
||||
emac_hal_init(&emac->hal, descriptors, emac->rx_buf, emac->tx_buf);
|
||||
/* alloc interrupt */
|
||||
@@ -619,7 +626,7 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config
|
||||
}
|
||||
ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err, TAG, "alloc emac interrupt failed");
|
||||
ret_code = esp_emac_config_data_interface(esp32_config, emac);
|
||||
ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err_interf, TAG, "config emac interface failed");
|
||||
ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err, TAG, "config emac interface failed");
|
||||
|
||||
emac->dma_burst_len = esp32_config->dma_burst_len;
|
||||
emac->sw_reset_timeout_ms = config->sw_reset_timeout_ms;
|
||||
@@ -649,8 +656,6 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config
|
||||
emac->parent.receive = emac_esp32_receive;
|
||||
return &(emac->parent);
|
||||
|
||||
err_interf:
|
||||
periph_module_disable(PERIPH_EMAC_MODULE);
|
||||
err:
|
||||
esp_emac_free_driver_obj(emac, descriptors);
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user