1 /* 2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdbool.h> 8 #include "esp_attr.h" 9 #include "esp_private/regi2c_ctrl.h" 10 #include "esp_private/sar_periph_ctrl.h" 11 #include "esp_private/sar_periph_ctrl.h" 12 #include <zephyr/kernel.h> 13 14 /* 15 * This file is used to override the hooks provided by the PHY lib for some system features. 16 * Call phy_override() so that this file will be linked. 17 */ 18 19 static bool s_wifi_adc_xpd_flag; 20 static bool s_wifi_pwdet_xpd_flag; 21 static bool s_wifi_tsens_xpd_flag; 22 include_esp_phy_override(void)23void include_esp_phy_override(void) 24 { 25 /* When this empty function is called, all functions below will be linked. */ 26 } 27 28 /* Coordinate ADC power with other modules. */ 29 // It seems that it is only required on ESP32, but we still compile it for all chips, in case it is 30 // called by PHY unexpectedly. set_xpd_sar(bool en)31void set_xpd_sar(bool en) 32 { 33 if (s_wifi_adc_xpd_flag == en) { 34 /* ignore repeated calls to set_xpd_sar when the state is already correct */ 35 return; 36 } 37 38 s_wifi_adc_xpd_flag = en; 39 if (en) { 40 sar_periph_ctrl_pwdet_power_acquire(); 41 } else { 42 sar_periph_ctrl_pwdet_power_release(); 43 } 44 } 45 46 //add spinlock protection phy_i2c_enter_critical(void)47IRAM_ATTR void phy_i2c_enter_critical(void) 48 { 49 regi2c_enter_critical(); 50 } 51 phy_i2c_exit_critical(void)52IRAM_ATTR void phy_i2c_exit_critical(void) 53 { 54 regi2c_exit_critical(); 55 } 56 phy_set_pwdet_power(bool en)57void phy_set_pwdet_power(bool en) 58 { 59 if (s_wifi_pwdet_xpd_flag == en) { 60 /* ignore repeated calls to phy_set_pwdet_power when the state is already correct */ 61 return; 62 } 63 64 s_wifi_pwdet_xpd_flag = en; 65 if (en) { 66 sar_periph_ctrl_pwdet_power_acquire(); 67 } else { 68 sar_periph_ctrl_pwdet_power_release(); 69 } 70 } 71 phy_set_tsens_power(bool en)72void phy_set_tsens_power(bool en) 73 { 74 if (s_wifi_tsens_xpd_flag == en) { 75 /* ignore repeated calls to phy_set_tsens_power when the state is already correct */ 76 return; 77 } 78 79 s_wifi_tsens_xpd_flag = en; 80 if (en) { 81 temperature_sensor_power_acquire(); 82 } else { 83 temperature_sensor_power_release(); 84 } 85 } 86 phy_get_tsens_value(void)87int16_t phy_get_tsens_value(void) 88 { 89 return temp_sensor_get_raw_value(NULL); 90 } 91