fix: preserve current runtime debug state

This commit is contained in:
2026-04-18 05:29:11 +08:00
parent 6aba77df9a
commit cd48a8af68
11 changed files with 138 additions and 265 deletions
+2 -80
View File
@@ -26,86 +26,8 @@ extern volatile int32_t g_netif_set_default_err;
extern volatile int32_t g_netif_set_link_down_err;
extern volatile int32_t g_netif_set_up_err;
extern volatile int32_t g_netif_init_ok;
extern volatile uint32_t g_eth_poll_count;
extern volatile uint32_t g_eth_isr_pr_count;
extern volatile uint32_t g_eth_rx_count;
extern volatile uint32_t g_eth_rx_drop_count;
extern volatile uint32_t g_eth_tx_count;
extern volatile uint32_t g_eth_link_up_count;
extern volatile uint32_t g_eth_link_down_count;
extern volatile uint32_t g_eth_last_isr;
extern volatile uint32_t g_eth_last_nsr;
extern volatile uint32_t g_eth_last_mrcmdx;
extern volatile uint32_t g_eth_last_mrcmdx1;
extern volatile uint32_t g_eth_last_mrrl;
extern volatile uint32_t g_eth_last_mrrh;
extern volatile uint32_t g_eth_last_bcastcr;
extern volatile uint32_t g_eth_last_mar7;
extern volatile uint32_t g_eth_last_nsr_rxrdy;
extern volatile uint32_t g_eth_last_rx_ready;
extern volatile uint32_t g_eth_last_rx_status;
extern volatile uint32_t g_eth_last_rx_len;
extern volatile uint32_t g_eth_last_rx_head0;
extern volatile uint32_t g_eth_last_rx_head1;
extern volatile uint32_t g_eth_last_rx_head2;
extern volatile uint32_t g_eth_last_rx_head3;
extern volatile uint32_t g_eth_last_rx_fail_stage;
extern volatile uint32_t g_eth_rx_gate_ok_count;
extern volatile uint32_t g_eth_rx_fallback_ok_count;
extern volatile uint32_t g_eth_rx_fallback_reject_count;
extern volatile uint32_t g_eth_probe_attempted;
extern volatile uint32_t g_eth_probe_head0;
extern volatile uint32_t g_eth_probe_head1;
extern volatile uint32_t g_eth_probe_head2;
extern volatile uint32_t g_eth_probe_head3;
extern volatile uint32_t g_eth_probe_rx_status;
extern volatile uint32_t g_eth_probe_rx_len;
extern volatile uint8_t g_eth_probe_dump[32];
extern volatile uint32_t g_eth_probe_drop_count;
extern volatile uint32_t g_eth_reprobe_head0;
extern volatile uint32_t g_eth_reprobe_head1;
extern volatile uint32_t g_eth_reprobe_head2;
extern volatile uint32_t g_eth_reprobe_head3;
extern volatile uint32_t g_eth_reprobe_rx_status;
extern volatile uint32_t g_eth_reprobe_rx_len;
extern volatile uint32_t g_eth_input_ok_count;
extern volatile uint32_t g_eth_input_err_count;
extern volatile int32_t g_eth_last_input_err;
extern volatile uint32_t g_eth_last_frame_len;
extern volatile uint8_t g_eth_last_frame_head[14];
extern volatile uint32_t g_eth_tx_probe_count;
extern volatile uint32_t g_eth_last_tx_len;
extern volatile uint8_t g_eth_last_tx_head[14];
extern volatile uint32_t g_eth_last_tcr_after;
extern volatile uint32_t g_eth_last_nsr_after;
extern volatile uint32_t g_eth_last_tsra;
extern volatile uint32_t g_eth_last_tsrb;
extern volatile uint32_t g_eth_last_txpll_rb;
extern volatile uint32_t g_eth_last_txplh_rb;
extern volatile uint32_t g_eth_arp_rx_count;
extern volatile uint32_t g_eth_arp_tx_count;
extern volatile uint32_t g_eth_arp_rx_op;
extern volatile uint32_t g_eth_arp_tx_op;
extern volatile uint8_t g_eth_local_ip[4];
extern volatile uint8_t g_eth_local_mac[6];
extern volatile uint8_t g_eth_arp_rx_sha[6];
extern volatile uint8_t g_eth_arp_rx_spa[4];
extern volatile uint8_t g_eth_arp_rx_tha[6];
extern volatile uint8_t g_eth_arp_rx_tpa[4];
extern volatile uint8_t g_eth_arp_tx_sha[6];
extern volatile uint8_t g_eth_arp_tx_spa[4];
extern volatile uint8_t g_eth_arp_tx_tha[6];
extern volatile uint8_t g_eth_arp_tx_tpa[4];
extern volatile uint32_t g_eth_lwip_arp_seen_count;
extern volatile uint32_t g_eth_lwip_arp_opcode;
extern volatile uint32_t g_eth_lwip_arp_for_us;
extern volatile uint32_t g_eth_lwip_arp_from_us;
extern volatile uint8_t g_eth_lwip_arp_sip[4];
extern volatile uint8_t g_eth_lwip_arp_dip[4];
extern volatile uint32_t g_eth_lwip_eth_seen_count;
extern volatile uint32_t g_eth_lwip_eth_last_type;
extern volatile uint32_t g_eth_lwip_eth_last_len;
extern volatile uint32_t g_eth_lwip_eth_arp_case_count;
void app_start_network_tasks(void);
#ifdef __cplusplus
}
+14 -2
View File
@@ -567,6 +567,7 @@ void config_uart_idle_handler(void)
uint16_t dma_counter = __HAL_DMA_GET_COUNTER(huart1.hdmarx);
uint16_t len = CONFIG_RX_BUFFER_SIZE - dma_counter;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
HAL_StatusTypeDef hal_status;
if (g_uart1_tx_busy) {
return;
@@ -582,8 +583,19 @@ void config_uart_idle_handler(void)
&xHigherPriorityTaskWoken);
}
HAL_UART_DMAStop(&huart1);
HAL_UART_Receive_DMA(&huart1, g_uart1_rx_buffer, CONFIG_RX_BUFFER_SIZE);
hal_status = HAL_UART_DMAStop(&huart1);
if (hal_status != HAL_OK) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return;
}
hal_status = HAL_UART_Receive_DMA(&huart1, g_uart1_rx_buffer, CONFIG_RX_BUFFER_SIZE);
if (hal_status != HAL_OK) {
__HAL_UART_DISABLE_IT(&huart1, UART_IT_IDLE);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
return;
}
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
+13 -2
View File
@@ -50,6 +50,7 @@ void NetPollTask(void *argument)
}
g_netif_ready = pdTRUE;
app_start_network_tasks();
debug_log_write("[NET] diag-ch390-ready\r\n");
#else
debug_log_write("[NET] tcpip-init enter\r\n");
@@ -69,6 +70,11 @@ void NetPollTask(void *argument)
lwip_netif_init(&ipaddr, &netmask, &gateway);
g_netif_phase = 7u;
debug_log_write("[NET] netif-init exit\r\n");
debug_log_printf("[NET] post-init ok=%ld hwm=%lu free=%lu min=%lu\r\n",
(long)g_netif_init_ok,
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
if (g_netif_init_ok != 1) {
for (;;) {
@@ -76,7 +82,13 @@ void NetPollTask(void *argument)
}
}
debug_log_write("[NET] pre-ready\r\n");
g_netif_ready = pdTRUE;
debug_log_write("[NET] start-network-tasks call\r\n");
app_start_network_tasks();
debug_log_printf("[NET] post-ready free=%lu min=%lu\r\n",
(unsigned long)xPortGetFreeHeapSize(),
(unsigned long)xPortGetMinimumEverFreeHeapSize());
debug_log_write("[NET] netif-ready\r\n");
#endif
@@ -91,14 +103,13 @@ void NetPollTask(void *argument)
#if DIAG_CH390_RAW_POLL
ethernetif_diag_poll_status();
if (g_eth_last_nsr_rxrdy != 0u)
if (ch390_read_reg(CH390_NSR) & NSR_RXRDY)
{
uint8_t rx_status = 0u;
uint32_t rx_len = ch390_runtime_receive_packet(s_diag_rx_buffer, &rx_status);
if (rx_len > 0u)
{
g_eth_rx_count += 1u;
debug_log_printf("[RAW] rx len=%lu st=0x%02X h=%02X %02X %02X %02X\r\n",
(unsigned long)rx_len,
(unsigned int)rx_status,
+32 -6
View File
@@ -8,9 +8,10 @@
#include "app_runtime.h"
#include "config.h"
#include "debug_log.h"
#include "route_msg.h"
static void tcp_client_worker(struct netconn *conn, uint8_t link_index)
static err_t tcp_client_worker(struct netconn *conn, uint8_t link_index)
{
struct netbuf *buf;
const device_config_t *cfg = config_get();
@@ -38,17 +39,18 @@ static void tcp_client_worker(struct netconn *conn, uint8_t link_index)
} while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
} else if (err != ERR_TIMEOUT) {
break;
return err;
}
while (xQueueReceive(xLinkTxQueues[link_index], &tx_msg, 0) == pdPASS) {
err = netconn_write(conn, tx_msg->data, tx_msg->len, NETCONN_COPY);
route_msg_free(tx_msg);
if (err != ERR_OK) {
return;
return err;
}
}
}
}
static void tcp_client_task(uint8_t link_index)
@@ -57,6 +59,10 @@ static void tcp_client_task(uint8_t link_index)
struct netconn *conn;
ip_addr_t remote_ip;
uint32_t delay_ms;
err_t err;
uint8_t first_connect_deferred;
first_connect_deferred = (link_index == CONFIG_LINK_C1) ? 1u : 0u;
for (;;) {
while (g_netif_ready == pdFALSE) {
@@ -64,12 +70,26 @@ static void tcp_client_task(uint8_t link_index)
}
cfg = config_get();
debug_log_printf("[CLI] idx=%u hwm=%lu en=%u lport=%u rport=%u\r\n",
(unsigned int)link_index,
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
(unsigned int)cfg->links[link_index].enabled,
(unsigned int)cfg->links[link_index].local_port,
(unsigned int)cfg->links[link_index].remote_port);
if (cfg->links[link_index].enabled == 0u) {
vTaskDelay(pdMS_TO_TICKS(500));
continue;
}
delay_ms = (cfg->reconnect_interval_ms == 0u) ? 3000u : cfg->reconnect_interval_ms;
if (first_connect_deferred != 0u) {
first_connect_deferred = 0u;
debug_log_write("[CLI] C1 first-connect defer\r\n");
vTaskDelay(pdMS_TO_TICKS(delay_ms));
continue;
}
conn = netconn_new(NETCONN_TCP);
if (conn == NULL) {
vTaskDelay(pdMS_TO_TICKS(delay_ms));
@@ -77,7 +97,12 @@ static void tcp_client_task(uint8_t link_index)
}
if (cfg->links[link_index].local_port != 0u) {
(void)netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port);
err = netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port);
if (err != ERR_OK) {
netconn_delete(conn);
vTaskDelay(pdMS_TO_TICKS(delay_ms));
continue;
}
}
IP_ADDR4(&remote_ip,
@@ -86,8 +111,9 @@ static void tcp_client_task(uint8_t link_index)
cfg->links[link_index].remote_ip[2],
cfg->links[link_index].remote_ip[3]);
if (netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port) == ERR_OK) {
tcp_client_worker(conn, link_index);
err = netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port);
if (err == ERR_OK) {
(void)tcp_client_worker(conn, link_index);
}
netconn_close(conn);
+6
View File
@@ -8,6 +8,7 @@
#include "app_runtime.h"
#include "config.h"
#include "debug_log.h"
#include "route_msg.h"
static void tcp_server_worker(struct netconn *conn, uint8_t link_index)
@@ -63,6 +64,11 @@ static void tcp_server_task(uint8_t link_index)
}
cfg = config_get();
debug_log_printf("[SRV] idx=%u hwm=%lu en=%u port=%u\r\n",
(unsigned int)link_index,
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
(unsigned int)cfg->links[link_index].enabled,
(unsigned int)cfg->links[link_index].local_port);
if (cfg->links[link_index].enabled == 0u) {
vTaskDelay(pdMS_TO_TICKS(500));
continue;
+7 -5
View File
@@ -406,6 +406,7 @@ bool uart_mux_encode_frame(uint8_t src_id,
void UartRxTask(void *argument)
{
uint32_t notify_value;
BaseType_t notified;
route_msg_t *msg;
uart_mux_frame_t frame;
const device_config_t *cfg;
@@ -418,18 +419,19 @@ void UartRxTask(void *argument)
debug_log_boot("uart-task-started");
for (;;) {
(void)xTaskNotifyWait(0u, 0xFFFFFFFFu, &notify_value, pdMS_TO_TICKS(10));
notify_value = 0u;
notified = xTaskNotifyWait(0u, 0xFFFFFFFFu, &notify_value, pdMS_TO_TICKS(10));
if ((notify_value & UART_NOTIFY_RX_U0) != 0u) {
if ((notified == pdTRUE) && ((notify_value & UART_NOTIFY_RX_U0) != 0u)) {
process_rx_snapshot(UART_CHANNEL_U0);
}
if ((notify_value & UART_NOTIFY_RX_U1) != 0u) {
if ((notified == pdTRUE) && ((notify_value & UART_NOTIFY_RX_U1) != 0u)) {
process_rx_snapshot(UART_CHANNEL_U1);
}
if ((notify_value & UART_NOTIFY_TX_U0) != 0u) {
if ((notified == pdTRUE) && ((notify_value & UART_NOTIFY_TX_U0) != 0u)) {
g_channels[UART_CHANNEL_U0].tx_busy = 0u;
}
if ((notify_value & UART_NOTIFY_TX_U1) != 0u) {
if ((notified == pdTRUE) && ((notify_value & UART_NOTIFY_TX_U1) != 0u)) {
g_channels[UART_CHANNEL_U1].tx_busy = 0u;
}
+5 -5
View File
@@ -20,13 +20,13 @@ typedef struct {
uint8_t src_id;
uint8_t dst_mask;
uint16_t payload_len;
uint8_t payload[512];
uint8_t payload[256];
} uart_mux_frame_t;
#define UART_RX_DMA_BUFFER_SIZE 256u
#define UART_TX_DMA_BUFFER_SIZE 256u
#define UART_RX_RING_BUFFER_SIZE 512u
#define UART_TX_RING_BUFFER_SIZE 512u
#define UART_RX_DMA_BUFFER_SIZE 128u
#define UART_TX_DMA_BUFFER_SIZE 128u
#define UART_RX_RING_BUFFER_SIZE 256u
#define UART_TX_RING_BUFFER_SIZE 256u
int uart_trans_init(void);
int uart_trans_config(uint8_t uart_index, uint32_t baudrate);