feat(openthread): use freertos timer for debug logs

This commit is contained in:
Tan Yan Quan
2025-04-09 19:28:03 +08:00
parent a542b2b36a
commit c66fe0a72c
2 changed files with 18 additions and 16 deletions

View File

@ -543,7 +543,7 @@ void otPlatRadioUpdateCslSampleTime(otInstance *aInstance, uint32_t aCslSampleTi
s_csl_sample_time = aCslSampleTime;
}
static IRAM_ATTR uint16_t get_csl_phase()
static IRAM_ATTR uint16_t get_csl_phase(void)
{
uint32_t cur_time = otPlatTimeGet();
uint32_t csl_period_us = s_csl_period * OT_US_PER_TEN_SYMBOLS;

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*
@ -30,14 +30,14 @@
#include "openthread/logging.h"
#include "openthread/thread.h"
#if CONFIG_ESP_SLEEP_DEBUG
#include "esp_timer.h"
#include "esp_sleep.h"
#include "esp_private/esp_pmu.h"
#include "esp_private/esp_sleep_internal.h"
#endif
#ifdef CONFIG_PM_ENABLE
#include "esp_pm.h"
#include "soc/rtc.h"
#include "esp_sleep.h"
#endif
#if !SOC_IEEE802154_SUPPORTED
@ -47,6 +47,7 @@
#define TAG "ot_esp_power_save"
static esp_pm_lock_handle_t s_cli_pm_lock = NULL;
TimerHandle_t xTimer;
#if CONFIG_OPENTHREAD_AUTO_START
static void create_config_network(otInstance *instance)
@ -116,8 +117,10 @@ static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t
#if CONFIG_ESP_SLEEP_DEBUG
static esp_sleep_context_t s_sleep_ctx;
static void print_sleep_flag(void *arg)
void vTimerCallback( TimerHandle_t xTimer )
{
assert(xTimer);
ESP_LOGD(TAG, "sleep_flags %lu", s_sleep_ctx.sleep_flags);
ESP_LOGD(TAG, "PMU_SLEEP_PD_TOP: %s", (s_sleep_ctx.sleep_flags & PMU_SLEEP_PD_TOP) ? "True":"False");
ESP_LOGD(TAG, "PMU_SLEEP_PD_MODEM: %s", (s_sleep_ctx.sleep_flags & PMU_SLEEP_PD_MODEM) ? "True":"False");
@ -165,17 +168,9 @@ static void ot_task_worker(void *aContext)
esp_sleep_set_sleep_context(&s_sleep_ctx);
esp_log_level_set(TAG, ESP_LOG_DEBUG);
// create a timer to print the status of sleepy device
int periods = 2000;
const esp_timer_create_args_t timer_args = {
.name = "print_sleep_flag",
.arg = NULL,
.callback = &print_sleep_flag,
.skip_unhandled_events = true,
};
esp_timer_handle_t periodic_timer;
ESP_ERROR_CHECK(esp_timer_create(&timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, periods * 1000));
// Use freeRTOS timer so that it is lower priority than OpenThread
xTimer = xTimerCreate("print_sleep_flag", pdMS_TO_TICKS(2000), pdTRUE, NULL, vTimerCallback);
xTimerStart( xTimer, 0 );
#endif
// Run the main loop
@ -204,6 +199,13 @@ static esp_err_t ot_power_save_init(void)
};
rc = esp_pm_configure(&pm_config);
soc_rtc_slow_clk_src_t slow_clk_src = rtc_clk_slow_src_get();
if (slow_clk_src != SOC_RTC_SLOW_CLK_SRC_XTAL32K) {
ESP_LOGW(TAG, "32k XTAL not in use");
} else {
ESP_LOGI(TAG, "32k XTAL in use");
}
#endif
return rc;
}