2026-03-31 11:04:43 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "esp_log.h"
|
2026-04-08 14:07:37 +08:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
#include "freertos/task.h"
|
2026-04-09 08:55:43 +08:00
|
|
|
#include "esp_task_wdt.h"
|
2026-03-31 11:04:43 +08:00
|
|
|
|
|
|
|
|
static const char* TAG = "RustApp";
|
|
|
|
|
|
|
|
|
|
extern void rust_app_main();
|
|
|
|
|
|
2026-04-08 14:07:37 +08:00
|
|
|
void rust_app_task(void* pvParameters) {
|
|
|
|
|
ESP_LOGI(TAG, "Rust application task started");
|
2026-04-09 08:55:43 +08:00
|
|
|
|
|
|
|
|
// 订阅看门狗,防止任务被复位
|
|
|
|
|
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
|
|
|
|
|
|
2026-03-31 11:04:43 +08:00
|
|
|
rust_app_main();
|
2026-04-09 08:55:43 +08:00
|
|
|
|
|
|
|
|
// 如果 rust_app_main 返回,记录错误并进入无限循环
|
|
|
|
|
ESP_LOGE(TAG, "Rust application task unexpectedly returned!");
|
|
|
|
|
while (1) {
|
|
|
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
|
|
|
}
|
2026-03-31 11:04:43 +08:00
|
|
|
}
|
2026-04-08 14:07:37 +08:00
|
|
|
|
2026-04-09 08:55:43 +08:00
|
|
|
static TaskHandle_t rust_app_task_handle = NULL;
|
|
|
|
|
|
2026-04-08 14:07:37 +08:00
|
|
|
void rust_app_wrapper_init() {
|
2026-04-09 08:55:43 +08:00
|
|
|
// 使用静态变量确保函数只被调用一次
|
|
|
|
|
static bool initialized = false;
|
|
|
|
|
if (initialized) {
|
|
|
|
|
ESP_LOGI(TAG, "Rust application already initialized");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initialized = true;
|
|
|
|
|
|
2026-04-08 14:07:37 +08:00
|
|
|
ESP_LOGI(TAG, "Initializing Rust application...");
|
|
|
|
|
|
|
|
|
|
// 创建一个新的任务来运行 Rust 应用
|
2026-04-09 08:55:43 +08:00
|
|
|
// 增加栈大小到 16384 (16KB) 以防止栈溢出
|
|
|
|
|
BaseType_t result = xTaskCreate(rust_app_task, "rust_app_task", 16384, NULL, 5, &rust_app_task_handle);
|
2026-04-08 14:07:37 +08:00
|
|
|
|
2026-04-09 08:55:43 +08:00
|
|
|
if (result != pdPASS) {
|
|
|
|
|
ESP_LOGE(TAG, "Failed to create Rust application task!");
|
|
|
|
|
} else {
|
|
|
|
|
ESP_LOGI(TAG, "Rust application task created successfully");
|
|
|
|
|
}
|
2026-04-08 14:07:37 +08:00
|
|
|
}
|