From dfff867379835757678acb13f7f1855dbfd4a946 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Wed, 29 Nov 2023 14:25:25 +0800 Subject: [PATCH] fix(tempertuer_sensor): Fix regs on temperature sensor is not volatile due to GCC bug --- .../hal/esp32c2/include/hal/temperature_sensor_ll.h | 9 +++++---- .../hal/esp32c3/include/hal/temperature_sensor_ll.h | 9 +++++---- .../hal/esp32c6/include/hal/temperature_sensor_ll.h | 10 +++++----- .../hal/esp32h2/include/hal/temperature_sensor_ll.h | 12 ++++++------ .../hal/esp32s2/include/hal/temperature_sensor_ll.h | 9 +++++---- .../hal/esp32s3/include/hal/temperature_sensor_ll.h | 9 +++++---- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h b/components/hal/esp32c2/include/hal/temperature_sensor_ll.h index 6f4f58897b..685f77b794 100644 --- a/components/hal/esp32c2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c2/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,6 +23,7 @@ #include "soc/soc_caps.h" #include "hal/temperature_sensor_types.h" #include "hal/assert.h" +#include "hal/misc.h" #ifdef __cplusplus extern "C" { @@ -92,7 +93,7 @@ static inline void temperature_sensor_ll_set_range(uint32_t range) */ static inline uint32_t temperature_sensor_ll_get_raw_value(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_reg_tsens_out); } /** @@ -116,7 +117,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_reg_tsens_clk_div); } /** @@ -129,7 +130,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - APB_SARADC.saradc_apb_tsens_ctrl.saradc_reg_tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_reg_tsens_clk_div, clk_div); } #ifdef __cplusplus diff --git a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h b/components/hal/esp32c3/include/hal/temperature_sensor_ll.h index d39f660d69..4dac4061ae 100644 --- a/components/hal/esp32c3/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c3/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,6 +23,7 @@ #include "soc/soc_caps.h" #include "hal/temperature_sensor_types.h" #include "hal/assert.h" +#include "hal/misc.h" #ifdef __cplusplus extern "C" { @@ -92,7 +93,7 @@ static inline void temperature_sensor_ll_set_range(uint32_t range) */ static inline uint32_t temperature_sensor_ll_get_raw_value(void) { - return APB_SARADC.apb_tsens_ctrl.tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.apb_tsens_ctrl, tsens_out); } /** @@ -116,7 +117,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return APB_SARADC.apb_tsens_ctrl.tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.apb_tsens_ctrl, tsens_clk_div); } /** @@ -129,7 +130,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - APB_SARADC.apb_tsens_ctrl.tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.apb_tsens_ctrl, tsens_clk_div, clk_div); } #ifdef __cplusplus diff --git a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h index a50d56f489..b50ef578f0 100644 --- a/components/hal/esp32c6/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32c6/include/hal/temperature_sensor_ll.h @@ -103,7 +103,7 @@ static inline void temperature_sensor_ll_set_range(uint32_t range) __attribute__((always_inline)) static inline uint32_t temperature_sensor_ll_get_raw_value(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_out); } /** @@ -127,7 +127,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div); } /** @@ -140,7 +140,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div, clk_div); } /** @@ -172,7 +172,7 @@ static inline void temperature_sensor_ll_wakeup_enable(bool en) */ static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low) { - APB_SARADC.tsens_wake.saradc_wakeup_th_low = th_low; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_low, th_low); } /** @@ -182,7 +182,7 @@ static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low) */ static inline void temperature_sensor_ll_set_th_high_val(uint8_t th_high) { - APB_SARADC.tsens_wake.saradc_wakeup_th_high = th_high; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_high, th_high); } /** diff --git a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h index 94c9d4b741..b50ef578f0 100644 --- a/components/hal/esp32h2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32h2/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -103,7 +103,7 @@ static inline void temperature_sensor_ll_set_range(uint32_t range) __attribute__((always_inline)) static inline uint32_t temperature_sensor_ll_get_raw_value(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_out); } /** @@ -127,7 +127,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div); } /** @@ -140,7 +140,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - APB_SARADC.saradc_apb_tsens_ctrl.saradc_tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.saradc_apb_tsens_ctrl, saradc_tsens_clk_div, clk_div); } /** @@ -172,7 +172,7 @@ static inline void temperature_sensor_ll_wakeup_enable(bool en) */ static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low) { - APB_SARADC.tsens_wake.saradc_wakeup_th_low = th_low; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_low, th_low); } /** @@ -182,7 +182,7 @@ static inline void temperature_sensor_ll_set_th_low_val(uint8_t th_low) */ static inline void temperature_sensor_ll_set_th_high_val(uint8_t th_high) { - APB_SARADC.tsens_wake.saradc_wakeup_th_high = th_high; + HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_wake, saradc_wakeup_th_high, th_high); } /** diff --git a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h b/components/hal/esp32s2/include/hal/temperature_sensor_ll.h index 86dcd5dbef..ca444f528b 100644 --- a/components/hal/esp32s2/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32s2/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,6 +21,7 @@ #include "soc/rtc_cntl_reg.h" #include "soc/sens_struct.h" #include "hal/temperature_sensor_types.h" +#include "hal/misc.h" #ifdef __cplusplus extern "C" { @@ -82,7 +83,7 @@ static inline uint32_t temperature_sensor_ll_get_raw_value(void) while (!SENS.sar_tctrl.tsens_ready) { } SENS.sar_tctrl.tsens_dump_out = 0; - return SENS.sar_tctrl.tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_tctrl, tsens_out); } /** @@ -106,7 +107,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return SENS.sar_tctrl.tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_tctrl, tsens_clk_div); } /** @@ -119,7 +120,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - SENS.sar_tctrl.tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_tctrl, tsens_clk_div, clk_div); } #ifdef __cplusplus diff --git a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h b/components/hal/esp32s3/include/hal/temperature_sensor_ll.h index cc14ce96e5..98baca81bb 100644 --- a/components/hal/esp32s3/include/hal/temperature_sensor_ll.h +++ b/components/hal/esp32s3/include/hal/temperature_sensor_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,6 +21,7 @@ #include "soc/rtc_cntl_reg.h" #include "soc/sens_struct.h" #include "hal/temperature_sensor_types.h" +#include "hal/misc.h" #ifdef __cplusplus extern "C" { @@ -82,7 +83,7 @@ static inline uint32_t temperature_sensor_ll_get_raw_value(void) while (!SENS.sar_tctrl.tsens_ready) { } SENS.sar_tctrl.tsens_dump_out = 0; - return SENS.sar_tctrl.tsens_out; + return HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_tctrl, tsens_out); } /** @@ -106,7 +107,7 @@ static inline uint32_t temperature_sensor_ll_get_offset(void) */ static inline uint32_t temperature_sensor_ll_get_clk_div(void) { - return SENS.sar_tctrl.tsens_clk_div; + return HAL_FORCE_READ_U32_REG_FIELD(SENS.sar_tctrl, tsens_clk_div); } /** @@ -119,7 +120,7 @@ static inline uint32_t temperature_sensor_ll_get_clk_div(void) */ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div) { - SENS.sar_tctrl.tsens_clk_div = clk_div; + HAL_FORCE_MODIFY_U32_REG_FIELD(SENS.sar_tctrl, tsens_clk_div, clk_div); } #ifdef __cplusplus