更新 OTA 位置,移除测试文件

This commit is contained in:
LokLiang
2025-07-09 14:02:53 +08:00
parent 9110aeabf0
commit ea4f688ba0
7 changed files with 7 additions and 167 deletions

View File

@@ -12,6 +12,7 @@ list(APPEND incs "lib-out")
list(APPEND srcs "app_main.c")
list(APPEND srcs "app_info.c")
list(APPEND srcs "ota.c")
list(APPEND srcs "console.c")
list(APPEND srcs "drivers/data_port/sb_data_port.c")
list(APPEND srcs "drivers/data_port/uart/uart_port.c")

View File

@@ -6,6 +6,7 @@
#include <string.h>
/* 配置 */
#include "ota.h"
#include "config/board_config.h"
#include "config/app_config.h"
@@ -50,6 +51,9 @@ void work_app_main(void *arg)
board_cfg_init(); // 板级配置
app_cfg_init(); // 应用配置
/* 初始化 OTA 功能*/
ota_partition_check();
/* 初始化其他优先级的工作队列 */
_init_work_q();
@@ -87,9 +91,9 @@ static void _init_work_q(void)
static void _init_ws2812(void)
{
#if (CONFIG_LED_STRIP_MAX_LEDS)
ws2812_spi_led_strip_init(SPI2_HOST, CONFIG_LED_STRIP_MAX_LEDS);
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, CONFIG_LED_STRIP_MAX_LEDS);
#else
ws2812_spi_led_strip_init(SPI2_HOST, 10);
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, 10);
#endif
}

View File

@@ -5,7 +5,6 @@ list(APPEND incs "../components/system/include")
# SRCS
list(APPEND srcs "main.c")
list(APPEND srcs "ota.c")
# idf_component_register

View File

@@ -33,9 +33,6 @@ static void _init_prev_nvs(void)
int app_main(void)
{
/* ota */
ota_partition_check();
/* 初始化平台相关 */
_init_prev_nvs();

View File

@@ -1,161 +0,0 @@
#include <stdio.h>
#include <stdatomic.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_log.h"
// 调试宏
#define SHOW_TIME_TOKEN 1 // 耗时测试开关
#ifdef SHOW_TIME_TOKEN
#define RECURSIVE_NUM 100 // 递归进入和退出临界区次数
#endif
#define COUT_TO_NS(x) ((x * 1000) / 160)
static struct
{
atomic_int suspend_count;
TaskHandle_t task_handle;
} cores_suspend_handle[portNUM_PROCESSORS] = {0};
void cores_suspend(void *arg)
{
while (1)
{
while (atomic_load(&cores_suspend_handle[xPortGetCoreID()].suspend_count) > 0)
{
__asm__ __volatile__("nop");
}
vTaskSuspend(NULL);
}
}
void enter_critical(void)
{
if (atomic_fetch_add(&cores_suspend_handle[xPortGetCoreID()].suspend_count, 1) == 0)
{
// 唤醒其他核的高优先级任务
for (int i = 0; i < portNUM_PROCESSORS; i++)
{
if (i == xPortGetCoreID())
{
continue;
}
vTaskResume(cores_suspend_handle[i].task_handle);
}
vTaskSuspendAll();
}
}
void exit_critical(void)
{
if (atomic_fetch_sub(&cores_suspend_handle[xPortGetCoreID()].suspend_count, 1) == 1)
{
xTaskResumeAll();
}
}
/* 竞争测试,验证互斥 */
static int shared_data = 0;
void taskA(void *pvParameters)
{
int cnt = 0;
while (1)
{
enter_critical();
int before = shared_data;
shared_data++;
exit_critical();
if (shared_data != before + 1)
{
ESP_LOGE("TaskA", "发生竞争");
}
else
{
if (++cnt % 100 == 0)
{
ESP_LOGI("TaskA", "未发生竞争");
}
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}
void taskB(void *pvParameters)
{
int cnt = 0;
while (1)
{
enter_critical();
enter_critical();
// 临界区开始
int before = shared_data;
shared_data++;
// 临界区结束
exit_critical();
exit_critical();
if (shared_data != before + 1)
{
ESP_LOGE("TaskB", "发生竞争");
}
else
{
if (++cnt % 100 == 0)
{
ESP_LOGI("TaskB", "未发生竞争");
}
}
vTaskDelay(pdMS_TO_TICKS(1));
}
}
int app_main(void)
{
// 初始化
for (int i = 0; i < portNUM_PROCESSORS; i++)
{
xTaskCreatePinnedToCore(cores_suspend, "cores_suspend", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, &cores_suspend_handle[i].task_handle, i);
}
// 竞争测试
xTaskCreatePinnedToCore(taskA, "TaskA", 4096, NULL, 5, NULL, 0);
xTaskCreatePinnedToCore(taskB, "TaskB", 4096, NULL, 6, NULL, 1);
#ifdef SHOW_TIME_TOKEN
// 单次耗时测试
uint32_t start_time = esp_cpu_get_cycle_count();
enter_critical();
int32_t enter_time = (esp_cpu_get_cycle_count() - start_time);
start_time = esp_cpu_get_cycle_count();
exit_critical();
int32_t exit_time = (esp_cpu_get_cycle_count() - start_time);
ESP_LOGI("单次耗时", "进入时间:%ld ns, 退出时间:%ld ns", COUT_TO_NS(enter_time), COUT_TO_NS(exit_time));
printf("\r\n");
// 递归测试
start_time = esp_cpu_get_cycle_count();
for (int i = 0; i < RECURSIVE_NUM; i++)
{
enter_critical();
}
enter_time = (esp_cpu_get_cycle_count() - start_time);
start_time = esp_cpu_get_cycle_count();
for (int i = 0; i < RECURSIVE_NUM; i++)
{
exit_critical();
}
exit_time = (esp_cpu_get_cycle_count() - start_time);
ESP_LOGI("递归耗时", "递归次数:%d, 进入总时间:%ld ns, 退出总时间: %ld ns", RECURSIVE_NUM, COUT_TO_NS(enter_time), COUT_TO_NS(exit_time));
#endif
return 0;
}