2022-10-19 03:57:24 -04:00
|
|
|
/*
|
2023-06-26 10:06:06 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2022-10-19 03:57:24 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2021-09-02 09:25:34 -04:00
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "freertos/portmacro.h"
|
|
|
|
#include "esp_phy_init.h"
|
2022-12-19 07:29:52 -05:00
|
|
|
#include "esp_private/phy.h"
|
2021-09-02 09:25:34 -04:00
|
|
|
|
|
|
|
#define PHY_ENABLE_VERSION_PRINT 1
|
|
|
|
|
|
|
|
static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED;
|
|
|
|
|
2023-06-26 10:06:06 -04:00
|
|
|
extern void phy_version_print(void);
|
2021-09-02 09:25:34 -04:00
|
|
|
static _lock_t s_phy_access_lock;
|
|
|
|
|
|
|
|
/* Reference count of enabling PHY */
|
|
|
|
static uint8_t s_phy_access_ref = 0;
|
2023-06-26 10:06:06 -04:00
|
|
|
static bool s_phy_is_enabled = false;
|
2021-09-02 09:25:34 -04:00
|
|
|
|
|
|
|
uint32_t IRAM_ATTR phy_enter_critical(void)
|
|
|
|
{
|
|
|
|
if (xPortInIsrContext()) {
|
|
|
|
portENTER_CRITICAL_ISR(&s_phy_int_mux);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
portENTER_CRITICAL(&s_phy_int_mux);
|
|
|
|
}
|
|
|
|
// Interrupt level will be stored in current tcb, so always return zero.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IRAM_ATTR phy_exit_critical(uint32_t level)
|
|
|
|
{
|
|
|
|
// Param level don't need any more, ignore it.
|
|
|
|
if (xPortInIsrContext()) {
|
|
|
|
portEXIT_CRITICAL_ISR(&s_phy_int_mux);
|
|
|
|
} else {
|
|
|
|
portEXIT_CRITICAL(&s_phy_int_mux);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void esp_phy_enable(void)
|
|
|
|
{
|
|
|
|
_lock_acquire(&s_phy_access_lock);
|
|
|
|
if (s_phy_access_ref == 0) {
|
2023-06-26 10:06:06 -04:00
|
|
|
if (!s_phy_is_enabled) {
|
|
|
|
register_chipv7_phy(NULL, NULL, PHY_RF_CAL_FULL);
|
|
|
|
phy_version_print();
|
|
|
|
s_phy_is_enabled = true;
|
|
|
|
} else {
|
|
|
|
phy_wakeup_init();
|
|
|
|
}
|
2021-09-02 09:25:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
s_phy_access_ref++;
|
|
|
|
|
|
|
|
_lock_release(&s_phy_access_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void esp_phy_disable(void)
|
|
|
|
{
|
2023-06-26 10:06:06 -04:00
|
|
|
_lock_acquire(&s_phy_access_lock);
|
|
|
|
|
|
|
|
if (s_phy_access_ref) {
|
|
|
|
s_phy_access_ref--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_phy_access_ref == 0) {
|
|
|
|
phy_close_rf();
|
|
|
|
phy_xpd_tsens();
|
|
|
|
}
|
|
|
|
|
|
|
|
_lock_release(&s_phy_access_lock);
|
2021-09-02 09:25:34 -04:00
|
|
|
}
|