fix: start only enabled links and move config buffers off stack

This commit is contained in:
2026-04-23 00:00:06 +08:00
parent e3450fd0ad
commit eeccfb84a0
3 changed files with 59 additions and 54 deletions
+47 -46
View File
@@ -36,48 +36,70 @@ static TaskHandle_t xTcpSrvTaskS2Handle = NULL;
static TaskHandle_t xTcpCliTaskC1Handle = NULL;
static TaskHandle_t xTcpCliTaskC2Handle = NULL;
static TaskHandle_t xDefaultTaskHandle = NULL;
static BaseType_t xNetworkTasksStarted = pdFALSE;
void app_start_network_tasks(void)
{
#if !DIAG_TASK_ISOLATION
BaseType_t rc;
const device_config_t *cfg;
if (xTcpSrvTaskS1Handle != NULL) {
if (xNetworkTasksStarted != pdFALSE) {
debug_log_write("[NET] start-network-tasks already\r\n");
return;
}
cfg = config_get();
debug_log_printf("[NET] start-network-tasks enter free=%lu min=%lu\r\n",
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
rc = xTaskCreate(TcpSrvTask_S1, "TcpSrvS1", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS1Handle);
debug_log_printf("[NET] create TcpSrvS1 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
if (cfg->links[CONFIG_LINK_S1].enabled != 0u) {
rc = xTaskCreate(TcpSrvTask_S1, "TcpSrvS1", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS1Handle);
debug_log_printf("[NET] create TcpSrvS1 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpSrvS1 en=0\r\n");
}
rc = xTaskCreate(TcpSrvTask_S2, "TcpSrvS2", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS2Handle);
debug_log_printf("[NET] create TcpSrvS2 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
if (cfg->links[CONFIG_LINK_S2].enabled != 0u) {
rc = xTaskCreate(TcpSrvTask_S2, "TcpSrvS2", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS2Handle);
debug_log_printf("[NET] create TcpSrvS2 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpSrvS2 en=0\r\n");
}
rc = xTaskCreate(TcpCliTask_C1, "TcpCliC1", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC1Handle);
debug_log_printf("[NET] create TcpCliC1 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
if (cfg->links[CONFIG_LINK_C1].enabled != 0u) {
rc = xTaskCreate(TcpCliTask_C1, "TcpCliC1", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC1Handle);
debug_log_printf("[NET] create TcpCliC1 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpCliC1 en=0\r\n");
}
rc = xTaskCreate(TcpCliTask_C2, "TcpCliC2", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC2Handle);
debug_log_printf("[NET] create TcpCliC2 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
if (cfg->links[CONFIG_LINK_C2].enabled != 0u) {
rc = xTaskCreate(TcpCliTask_C2, "TcpCliC2", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC2Handle);
debug_log_printf("[NET] create TcpCliC2 rc=%ld free=%lu min=%lu\r\n",
(long)rc,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
configASSERT(rc == pdPASS);
} else {
debug_log_write("[NET] skip TcpCliC2 en=0\r\n");
}
xNetworkTasksStarted = pdTRUE;
debug_log_printf("[NET] start-network-tasks exit free=%lu min=%lu\r\n",
(unsigned long)xPortGetFreeHeapSize(),
@@ -87,8 +109,6 @@ void app_start_network_tasks(void)
static void StartDefaultTask(void *argument)
{
TickType_t last_snapshot = xTaskGetTickCount();
BaseType_t alive_logged = pdFALSE;
BaseType_t iwdg_ready = pdFALSE;
(void)argument;
@@ -106,25 +126,6 @@ static void StartDefaultTask(void *argument)
if (iwdg_ready == pdTRUE) {
HAL_IWDG_Refresh(&hiwdg);
}
if (alive_logged == pdFALSE) {
debug_log_write("[RTOS] alive\r\n");
alive_logged = pdTRUE;
}
if ((xTaskGetTickCount() - last_snapshot) >= pdMS_TO_TICKS(5000)) {
debug_log_printf("[RTOS] seq=%lu drops=%lu last=%lu free=%lu min=%lu self_hwm=%lu\r\n",
(unsigned long)g_rtt_log_seq,
(unsigned long)g_rtt_log_drop_count,
(unsigned long)g_rtt_log_last_drop_seq,
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize(),
(unsigned long)uxTaskGetStackHighWaterMark(NULL));
if (xNetPollTaskHandle != NULL) {
debug_log_printf("[RTOS] net_phase=%lu net_hwm=%lu\r\n",
(unsigned long)g_netif_phase,
(unsigned long)uxTaskGetStackHighWaterMark(xNetPollTaskHandle));
}
last_snapshot = xTaskGetTickCount();
}
vTaskDelay(pdMS_TO_TICKS(500));
}
}