From fc1d6cb7d8304f9a6ec3a574f52a0ebb5591dc48 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Wed, 5 Mar 2025 15:58:04 +0800 Subject: [PATCH] change(esp_hw_support): optimize regi2c ctrl memory (iram or flash) usage control by REGI2C_CTRL_FUNC_IN_IRAM --- components/esp_hw_support/Kconfig | 7 +++++++ components/esp_hw_support/linker.lf | 7 +++++++ components/esp_hw_support/regi2c_ctrl.c | 12 ++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 1079a3334d..32ed2b8f06 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -225,6 +225,13 @@ menu "Hardware Settings" help Place peripheral control functions (e.g. periph_module_reset) into IRAM, so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context. + + config REGI2C_CTRL_FUNC_IN_IRAM + bool "Place regi2c control functions into IRAM" + default y + help + Place analog i2c master control functions (e.g. regi2c_ctrl_read_reg, regi2c_ctrl_write_reg) into IRAM, + so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context. endmenu menu "ETM Configuration" diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 39c09b7d65..012490c468 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -51,6 +51,13 @@ entries: if PERIPH_CTRL_FUNC_IN_IRAM = y && ESP_WIFI_ENABLED = y: periph_ctrl: wifi_module_enable (noflash) periph_ctrl: wifi_module_disable (noflash) + if REGI2C_CTRL_FUNC_IN_IRAM = y: + regi2c_ctrl:regi2c_ctrl_read_reg (noflash) + regi2c_ctrl:regi2c_ctrl_read_reg_mask (noflash) + regi2c_ctrl:regi2c_ctrl_write_reg (noflash) + regi2c_ctrl:regi2c_ctrl_write_reg_mask (noflash) + regi2c_ctrl:regi2c_enter_critical (noflash) + regi2c_ctrl:regi2c_exit_critical (noflash) if SOC_SYSTIMER_SUPPORTED = y: systimer (noflash) if SOC_ADC_SHARED_POWER = y: diff --git a/components/esp_hw_support/regi2c_ctrl.c b/components/esp_hw_support/regi2c_ctrl.c index 38ad924d45..b25c954356 100644 --- a/components/esp_hw_support/regi2c_ctrl.c +++ b/components/esp_hw_support/regi2c_ctrl.c @@ -18,7 +18,7 @@ static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; static DRAM_ATTR __attribute__((unused)) const char *TAG = "REGI2C"; -uint8_t IRAM_ATTR regi2c_ctrl_read_reg(uint8_t block, uint8_t host_id, uint8_t reg_add) +uint8_t regi2c_ctrl_read_reg(uint8_t block, uint8_t host_id, uint8_t reg_add) { REGI2C_CLOCK_ENABLE(); portENTER_CRITICAL_SAFE(&mux); @@ -28,7 +28,7 @@ uint8_t IRAM_ATTR regi2c_ctrl_read_reg(uint8_t block, uint8_t host_id, uint8_t r return value; } -uint8_t IRAM_ATTR regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb) +uint8_t regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb) { REGI2C_CLOCK_ENABLE(); portENTER_CRITICAL_SAFE(&mux); @@ -38,7 +38,7 @@ uint8_t IRAM_ATTR regi2c_ctrl_read_reg_mask(uint8_t block, uint8_t host_id, uint return value; } -void IRAM_ATTR regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data) +void regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data) { REGI2C_CLOCK_ENABLE(); portENTER_CRITICAL_SAFE(&mux); @@ -47,7 +47,7 @@ void IRAM_ATTR regi2c_ctrl_write_reg(uint8_t block, uint8_t host_id, uint8_t reg REGI2C_CLOCK_DISABLE(); } -void IRAM_ATTR regi2c_ctrl_write_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data) +void regi2c_ctrl_write_reg_mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data) { REGI2C_CLOCK_ENABLE(); portENTER_CRITICAL_SAFE(&mux); @@ -56,12 +56,12 @@ void IRAM_ATTR regi2c_ctrl_write_reg_mask(uint8_t block, uint8_t host_id, uint8_ REGI2C_CLOCK_DISABLE(); } -void IRAM_ATTR regi2c_enter_critical(void) +void regi2c_enter_critical(void) { portENTER_CRITICAL_SAFE(&mux); } -void IRAM_ATTR regi2c_exit_critical(void) +void regi2c_exit_critical(void) { portEXIT_CRITICAL_SAFE(&mux); }