mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ethernet: add pm lock
This commit is contained in:
parent
7c8139734d
commit
57ef88a91f
@ -19,6 +19,7 @@
|
|||||||
#include "esp_attr.h"
|
#include "esp_attr.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_eth.h"
|
#include "esp_eth.h"
|
||||||
|
#include "esp_pm.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
#include "esp_intr_alloc.h"
|
#include "esp_intr_alloc.h"
|
||||||
@ -57,6 +58,9 @@ typedef struct {
|
|||||||
uint8_t *rx_buf[CONFIG_ETH_DMA_RX_BUFFER_NUM];
|
uint8_t *rx_buf[CONFIG_ETH_DMA_RX_BUFFER_NUM];
|
||||||
uint8_t *tx_buf[CONFIG_ETH_DMA_TX_BUFFER_NUM];
|
uint8_t *tx_buf[CONFIG_ETH_DMA_TX_BUFFER_NUM];
|
||||||
bool isr_need_yield;
|
bool isr_need_yield;
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
esp_pm_lock_handle_t pm_lock;
|
||||||
|
#endif
|
||||||
} emac_esp32_t;
|
} emac_esp32_t;
|
||||||
|
|
||||||
static esp_err_t emac_esp32_set_mediator(esp_eth_mac_t *mac, esp_eth_mediator_t *eth)
|
static esp_err_t emac_esp32_set_mediator(esp_eth_mac_t *mac, esp_eth_mediator_t *eth)
|
||||||
@ -314,6 +318,9 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac)
|
|||||||
MAC_CHECK(esp_read_mac(emac->addr, ESP_MAC_ETH) == ESP_OK, "fetch ethernet mac address failed", err, ESP_FAIL);
|
MAC_CHECK(esp_read_mac(emac->addr, ESP_MAC_ETH) == ESP_OK, "fetch ethernet mac address failed", err, ESP_FAIL);
|
||||||
/* set MAC address to emac register */
|
/* set MAC address to emac register */
|
||||||
emac_hal_set_address(&emac->hal, emac->addr);
|
emac_hal_set_address(&emac->hal, emac->addr);
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
esp_pm_lock_acquire(emac->pm_lock);
|
||||||
|
#endif
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
err:
|
err:
|
||||||
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
||||||
@ -325,6 +332,9 @@ static esp_err_t emac_esp32_deinit(esp_eth_mac_t *mac)
|
|||||||
{
|
{
|
||||||
emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent);
|
emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent);
|
||||||
esp_eth_mediator_t *eth = emac->eth;
|
esp_eth_mediator_t *eth = emac->eth;
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
esp_pm_lock_release(emac->pm_lock);
|
||||||
|
#endif
|
||||||
emac_hal_stop(&emac->hal);
|
emac_hal_stop(&emac->hal);
|
||||||
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL);
|
||||||
periph_module_disable(PERIPH_EMAC_MODULE);
|
periph_module_disable(PERIPH_EMAC_MODULE);
|
||||||
@ -335,6 +345,11 @@ static esp_err_t emac_esp32_del(esp_eth_mac_t *mac)
|
|||||||
{
|
{
|
||||||
emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent);
|
emac_esp32_t *emac = __containerof(mac, emac_esp32_t, parent);
|
||||||
esp_intr_free(emac->intr_hdl);
|
esp_intr_free(emac->intr_hdl);
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
if (emac->pm_lock) {
|
||||||
|
esp_pm_lock_delete(emac->pm_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
vTaskDelete(emac->rx_task_hdl);
|
vTaskDelete(emac->rx_task_hdl);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
for (i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
||||||
@ -409,6 +424,10 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config)
|
|||||||
MAC_CHECK(esp_intr_alloc(ETS_ETH_MAC_INTR_SOURCE, ESP_INTR_FLAG_IRAM, emac_esp32_isr_handler,
|
MAC_CHECK(esp_intr_alloc(ETS_ETH_MAC_INTR_SOURCE, ESP_INTR_FLAG_IRAM, emac_esp32_isr_handler,
|
||||||
&emac->hal, &(emac->intr_hdl)) == ESP_OK,
|
&emac->hal, &(emac->intr_hdl)) == ESP_OK,
|
||||||
"alloc emac interrupt failed", err, NULL);
|
"alloc emac interrupt failed", err, NULL);
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
MAC_CHECK(esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "emac_esp32", &emac->pm_lock) == ESP_OK,
|
||||||
|
"create pm lock failed", err, NULL);
|
||||||
|
#endif
|
||||||
/* create rx task */
|
/* create rx task */
|
||||||
BaseType_t xReturned = xTaskCreate(emac_esp32_rx_task, "emac_rx", config->rx_task_stack_size, emac,
|
BaseType_t xReturned = xTaskCreate(emac_esp32_rx_task, "emac_rx", config->rx_task_stack_size, emac,
|
||||||
config->rx_task_prio, &emac->rx_task_hdl);
|
config->rx_task_prio, &emac->rx_task_hdl);
|
||||||
@ -429,6 +448,11 @@ err:
|
|||||||
for (int i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
for (int i = 0; i < CONFIG_ETH_DMA_RX_BUFFER_NUM; i++) {
|
||||||
free(emac->rx_buf[i]);
|
free(emac->rx_buf[i]);
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_PM_ENABLE
|
||||||
|
if (emac->pm_lock) {
|
||||||
|
esp_pm_lock_delete(emac->pm_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
free(emac);
|
free(emac);
|
||||||
}
|
}
|
||||||
if (descriptors) {
|
if (descriptors) {
|
||||||
|
@ -125,7 +125,7 @@ Currently, the following peripheral drivers are aware of DFS and will use the ``
|
|||||||
The following drivers will hold the ``ESP_PM_APB_FREQ_MAX`` lock while the driver is enabled:
|
The following drivers will hold the ``ESP_PM_APB_FREQ_MAX`` lock while the driver is enabled:
|
||||||
|
|
||||||
- **SPI slave**: between calls to :cpp:func:`spi_slave_initialize` and :cpp:func:`spi_slave_free`.
|
- **SPI slave**: between calls to :cpp:func:`spi_slave_initialize` and :cpp:func:`spi_slave_free`.
|
||||||
- **Ethernet**: between calls to :cpp:func:`esp_eth_enable` and :cpp:func:`esp_eth_disable`.
|
- **Ethernet**: between calls to :cpp:func:`esp_eth_driver_install` and :cpp:func:`esp_eth_driver_uninstall`.
|
||||||
- **WiFi**: between calls to :cpp:func:`esp_wifi_start` and :cpp:func:`esp_wifi_stop`. If modem sleep is enabled, the lock will be released for the periods of time when radio is disabled.
|
- **WiFi**: between calls to :cpp:func:`esp_wifi_start` and :cpp:func:`esp_wifi_stop`. If modem sleep is enabled, the lock will be released for the periods of time when radio is disabled.
|
||||||
- **Bluetooth**: between calls to :cpp:func:`esp_bt_controller_enable` and :cpp:func:`esp_bt_controller_disable`. If Bluetooth modem sleep is enabled, the ``ESP_PM_APB_FREQ_MAX`` lock will be released for the periods of time when radio is disabled. However the ``ESP_PM_NO_LIGHT_SLEEP`` lock will still be held, unless :ref:`CONFIG_BTDM_LOW_POWER_CLOCK` option is set to "External 32kHz crystal".
|
- **Bluetooth**: between calls to :cpp:func:`esp_bt_controller_enable` and :cpp:func:`esp_bt_controller_disable`. If Bluetooth modem sleep is enabled, the ``ESP_PM_APB_FREQ_MAX`` lock will be released for the periods of time when radio is disabled. However the ``ESP_PM_NO_LIGHT_SLEEP`` lock will still be held, unless :ref:`CONFIG_BTDM_LOW_POWER_CLOCK` option is set to "External 32kHz crystal".
|
||||||
- **CAN**: between calls to :cpp:func:`can_driver_install` and :cpp:func:`can_driver_uninstall`.
|
- **CAN**: between calls to :cpp:func:`can_driver_install` and :cpp:func:`can_driver_uninstall`.
|
||||||
|
@ -111,7 +111,7 @@ ESP32 支持下表中所述的三种电源管理锁。
|
|||||||
启用以下驱动程序时,将占用 ``ESP_PM_APB_FREQ_MAX`` 锁:
|
启用以下驱动程序时,将占用 ``ESP_PM_APB_FREQ_MAX`` 锁:
|
||||||
|
|
||||||
- **SPI slave**:从调用 :cpp:func:`spi_slave_initialize` 至 :cpp:func:`spi_slave_free` 期间。
|
- **SPI slave**:从调用 :cpp:func:`spi_slave_initialize` 至 :cpp:func:`spi_slave_free` 期间。
|
||||||
- **Ethernet**:从调用 :cpp:func:`esp_eth_enable` 至 :cpp:func:`esp_eth_disable` 期间。
|
- **Ethernet**:从调用 :cpp:func:`esp_eth_driver_install` 至 :cpp:func:`esp_eth_driver_uninstall` 期间。
|
||||||
- **WiFi**:从调用 :cpp:func:`esp_wifi_start` 至 :cpp:func:`esp_wifi_stop` 期间。如果启用了调制解调器睡眠模式,广播关闭时将释放此管理锁。
|
- **WiFi**:从调用 :cpp:func:`esp_wifi_start` 至 :cpp:func:`esp_wifi_stop` 期间。如果启用了调制解调器睡眠模式,广播关闭时将释放此管理锁。
|
||||||
- **Bluetooth**:从调用 :cpp:func:`esp_bt_controller_enable` 至 :cpp:func:`esp_bt_controller_disable` 期间。如果启用了蓝牙调制解调器,广播关闭时将释放此管理锁。但依然占用 ``ESP_PM_NO_LIGHT_SLEEP`` 锁。
|
- **Bluetooth**:从调用 :cpp:func:`esp_bt_controller_enable` 至 :cpp:func:`esp_bt_controller_disable` 期间。如果启用了蓝牙调制解调器,广播关闭时将释放此管理锁。但依然占用 ``ESP_PM_NO_LIGHT_SLEEP`` 锁。
|
||||||
- **CAN**:从调用 :cpp:func:`can_driver_install` 至 :cpp:func:`can_driver_uninstall` 期间。
|
- **CAN**:从调用 :cpp:func:`can_driver_install` 至 :cpp:func:`can_driver_uninstall` 期间。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user