Prechádzať zdrojové kódy

fix(ot sleep): Add a timer to print ot sleepy device status

Xu Si Yu 2 rokov pred
rodič
commit
082cf73602

+ 35 - 0
examples/openthread/ot_sleepy_device/main/esp_ot_sleepy_device.c

@@ -28,6 +28,13 @@
 #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"
 #endif
@@ -68,6 +75,17 @@ static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t
     return netif;
 }
 
+#if CONFIG_ESP_SLEEP_DEBUG
+static esp_sleep_context_t s_sleep_ctx;
+
+static void print_sleep_flag(void *arg)
+{
+    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");
+}
+#endif
+
 static void ot_task_worker(void *aContext)
 {
     esp_openthread_platform_config_t config = {
@@ -90,6 +108,23 @@ static void ot_task_worker(void *aContext)
 
     create_config_network(esp_openthread_get_instance());
 
+#if CONFIG_ESP_SLEEP_DEBUG
+    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));
+#endif
+
     // Run the main loop
     esp_openthread_launch_mainloop();
 

+ 0 - 6
examples/openthread/ot_sleepy_device/sdkconfig.ci.sleepy_c6

@@ -1,6 +0,0 @@
-CONFIG_IDF_TARGET="esp32c6"
-CONFIG_IDF_TARGET_ESP32C6=y
-CONFIG_OPENTHREAD_NETWORK_CHANNEL=12
-CONFIG_OPENTHREAD_NETWORK_MASTERKEY="aabbccddeeff00112233445566778899"
-CONFIG_ESP_SLEEP_DEBUG=y
-CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y

+ 1 - 1
examples/openthread/ot_sleepy_device/sdkconfig.ci.sleepy_h2

@@ -3,4 +3,4 @@ CONFIG_IDF_TARGET_ESP32H2=y
 CONFIG_OPENTHREAD_NETWORK_CHANNEL=12
 CONFIG_OPENTHREAD_NETWORK_MASTERKEY="aabbccddeeff00112233445566778899"
 CONFIG_ESP_SLEEP_DEBUG=y
-CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
+CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y

+ 1 - 2
examples/openthread/pytest_otbr.py

@@ -577,14 +577,13 @@ def test_ot_sleepy_device(dut: Tuple[IdfDut, IdfDut]) -> None:
         leader_para.setextpanid('dead00beef00cafe')
         leader_para.setnetworkkey('aabbccddeeff00112233445566778899')
         leader_para.setpskc('104810e2315100afd6bc9215a6bfac53')
-        ocf.clean_buffer(sleepy_device)
         ocf.joinThreadNetwork(leader, leader_para)
+        ocf.wait(leader, 5)
         ocf.clean_buffer(sleepy_device)
         sleepy_device.serial.hard_reset()
         sleepy_device.expect('detached -> child', timeout=20)
         sleepy_device.expect('PMU_SLEEP_PD_TOP: True', timeout=10)
         sleepy_device.expect('PMU_SLEEP_PD_MODEM: True', timeout=20)
-        ocf.clean_buffer(sleepy_device)
         output = sleepy_device.expect(pexpect.TIMEOUT, timeout=5)
         assert 'rst:' not in str(output) and 'boot:' not in str(output)
     finally: