Skip to content

Commit

Permalink
Merge branch 'backport/phy_track_pll_to_v51' into 'release/v5.1'
Browse files Browse the repository at this point in the history
Backport: phy track pll logic refactor to V5.1(Backport v5.1)

See merge request espressif/esp-idf!24689
  • Loading branch information
chshu committed Jul 11, 2023
2 parents 7f69e29 + 2bee46a commit 6b2209c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/esp_phy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
idf_build_get_property(idf_target IDF_TARGET)

set(srcs "src/phy_override.c" "src/lib_printf.c")
set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c")

if(CONFIG_APP_NO_BLOBS)
set(link_binary_libs 0)
Expand Down
13 changes: 12 additions & 1 deletion components/esp_phy/include/esp_phy_init.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -271,6 +271,17 @@ esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
*/
char * get_phy_version_str(void);

/**
* @brief Enable phy track pll
*
*/
void phy_track_pll_init(void);

/**
* @brief Disable phy track pll
*
*/
void phy_track_pll_deinit(void);
#ifdef __cplusplus
}
#endif
46 changes: 46 additions & 0 deletions components/esp_phy/src/phy_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "esp_timer.h"
#include <stdint.h>


extern void bt_track_pll_cap(void);
static esp_timer_handle_t phy_track_pll_timer;
static volatile int64_t s_previous_timestamp;
#define PHY_TRACK_PLL_PERIOD_IN_US 1000000

static void phy_track_pll_timer_callback(void* arg)
{
#if IEEE802154_ENABLED || BT_ENABLED
bt_track_pll_cap();
#endif
s_previous_timestamp = esp_timer_get_time();
}

void phy_track_pll_init(void)
{
// Light sleep scenario: enabling and disabling PHY frequently, the timer will not get triggered.
// Using a variable to record the previously tracked time when PLL was last called.
// If the duration is larger than PHY_TRACK_PLL_PERIOD_IN_US, then track PLL.
int64_t now = esp_timer_get_time();
if (now - s_previous_timestamp > PHY_TRACK_PLL_PERIOD_IN_US) {
phy_track_pll_timer_callback((void* )0);
}

const esp_timer_create_args_t phy_track_pll_timer_args = {
.callback = &phy_track_pll_timer_callback,
.name = "phy-track-pll-timer"
};
ESP_ERROR_CHECK(esp_timer_create(&phy_track_pll_timer_args, &phy_track_pll_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(phy_track_pll_timer, PHY_TRACK_PLL_PERIOD_IN_US));
}

void phy_track_pll_deinit(void)
{
ESP_ERROR_CHECK(esp_timer_stop(phy_track_pll_timer));
ESP_ERROR_CHECK(esp_timer_delete(phy_track_pll_timer));
}
2 changes: 2 additions & 0 deletions components/esp_phy/src/phy_init_esp32hxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void esp_phy_enable(void)
} else {
phy_wakeup_init();
}
phy_track_pll_init();
}

s_phy_access_ref++;
Expand All @@ -69,6 +70,7 @@ void esp_phy_disable(void)
}

if (s_phy_access_ref == 0) {
phy_track_pll_deinit();
phy_close_rf();
phy_xpd_tsens();
}
Expand Down

0 comments on commit 6b2209c

Please sign in to comment.