diff --git a/App/app_runtime.h b/App/app_runtime.h index e447c8d..b1198de 100644 --- a/App/app_runtime.h +++ b/App/app_runtime.h @@ -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 } diff --git a/App/config.c b/App/config.c index 9b233f4..e51d873 100644 --- a/App/config.c +++ b/App/config.c @@ -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); } diff --git a/App/task_net_poll.c b/App/task_net_poll.c index 048de7e..9f9ec96 100644 --- a/App/task_net_poll.c +++ b/App/task_net_poll.c @@ -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, diff --git a/App/tcp_client.c b/App/tcp_client.c index eb30527..d672fc9 100644 --- a/App/tcp_client.c +++ b/App/tcp_client.c @@ -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); diff --git a/App/tcp_server.c b/App/tcp_server.c index d304830..58dbb7d 100644 --- a/App/tcp_server.c +++ b/App/tcp_server.c @@ -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; diff --git a/App/uart_trans.c b/App/uart_trans.c index 6d49d92..48950e0 100644 --- a/App/uart_trans.c +++ b/App/uart_trans.c @@ -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, ¬ify_value, pdMS_TO_TICKS(10)); + notify_value = 0u; + notified = xTaskNotifyWait(0u, 0xFFFFFFFFu, ¬ify_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; } diff --git a/App/uart_trans.h b/App/uart_trans.h index 398b08a..4cbf945 100644 --- a/App/uart_trans.h +++ b/App/uart_trans.h @@ -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); diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index c038aa6..73fc8b8 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -65,7 +65,7 @@ #define configTICK_RATE_HZ ((TickType_t)1000) #define configMAX_PRIORITIES ( 7 ) #define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)14848) +#define configTOTAL_HEAP_SIZE ((size_t)15360) #define configMAX_TASK_NAME_LEN ( 16 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 @@ -165,18 +165,18 @@ standard names. */ /* Application task stack sizes (in words) */ #define TASK_STACK_TCPIP 512 #define TASK_STACK_NET_POLL 384 -#define TASK_STACK_TCP_SERVER 320 -#define TASK_STACK_TCP_CLIENT 224 -#define TASK_STACK_UART_RX 320 +#define TASK_STACK_TCP_SERVER 384 +#define TASK_STACK_TCP_CLIENT 384 +#define TASK_STACK_UART_RX 256 #define TASK_STACK_ROUTE 512 -#define TASK_STACK_CONFIG 384 +#define TASK_STACK_CONFIG 256 #define TASK_STACK_DEFAULT 128 /* Route message pool for zero-copy inter-task communication */ -#define ROUTE_MSG_POOL_SIZE 6 +#define ROUTE_MSG_POOL_SIZE 8 #define ROUTE_MSG_MAX_PAYLOAD 512 -#define DIAG_TASK_ISOLATION 1 +#define DIAG_TASK_ISOLATION 0 /* USER CODE END Defines */ diff --git a/Core/Src/debug_log.c b/Core/Src/debug_log.c index 15308a6..38a4103 100644 --- a/Core/Src/debug_log.c +++ b/Core/Src/debug_log.c @@ -45,7 +45,7 @@ void debug_log_write(const char *msg) void debug_log_printf(const char *fmt, ...) { - char buffer[192]; + char buffer[128]; va_list args; int len; diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index d0c4d73..b5d0aa4 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -29,86 +29,6 @@ volatile int32_t g_netif_set_default_err = 0x7FFFFFFF; volatile int32_t g_netif_set_link_down_err = 0x7FFFFFFF; volatile int32_t g_netif_set_up_err = 0x7FFFFFFF; volatile int32_t g_netif_init_ok = 0; -volatile uint32_t g_eth_poll_count = 0u; -volatile uint32_t g_eth_isr_pr_count = 0u; -volatile uint32_t g_eth_rx_count = 0u; -volatile uint32_t g_eth_rx_drop_count = 0u; -volatile uint32_t g_eth_tx_count = 0u; -volatile uint32_t g_eth_link_up_count = 0u; -volatile uint32_t g_eth_link_down_count = 0u; -volatile uint32_t g_eth_last_isr = 0u; -volatile uint32_t g_eth_last_nsr = 0u; -volatile uint32_t g_eth_last_mrcmdx = 0u; -volatile uint32_t g_eth_last_mrcmdx1 = 0u; -volatile uint32_t g_eth_last_mrrl = 0u; -volatile uint32_t g_eth_last_mrrh = 0u; -volatile uint32_t g_eth_last_bcastcr = 0u; -volatile uint32_t g_eth_last_mar7 = 0u; -volatile uint32_t g_eth_last_nsr_rxrdy = 0u; -volatile uint32_t g_eth_last_rx_ready = 0u; -volatile uint32_t g_eth_last_rx_status = 0u; -volatile uint32_t g_eth_last_rx_len = 0u; -volatile uint32_t g_eth_last_rx_head0 = 0u; -volatile uint32_t g_eth_last_rx_head1 = 0u; -volatile uint32_t g_eth_last_rx_head2 = 0u; -volatile uint32_t g_eth_last_rx_head3 = 0u; -volatile uint32_t g_eth_last_rx_fail_stage = 0u; -volatile uint32_t g_eth_rx_gate_ok_count = 0u; -volatile uint32_t g_eth_rx_fallback_ok_count = 0u; -volatile uint32_t g_eth_rx_fallback_reject_count = 0u; -volatile uint32_t g_eth_probe_attempted = 0u; -volatile uint32_t g_eth_probe_head0 = 0u; -volatile uint32_t g_eth_probe_head1 = 0u; -volatile uint32_t g_eth_probe_head2 = 0u; -volatile uint32_t g_eth_probe_head3 = 0u; -volatile uint32_t g_eth_probe_rx_status = 0u; -volatile uint32_t g_eth_probe_rx_len = 0u; -volatile uint8_t g_eth_probe_dump[32] = {0u}; -volatile uint32_t g_eth_probe_drop_count = 0u; -volatile uint32_t g_eth_reprobe_head0 = 0u; -volatile uint32_t g_eth_reprobe_head1 = 0u; -volatile uint32_t g_eth_reprobe_head2 = 0u; -volatile uint32_t g_eth_reprobe_head3 = 0u; -volatile uint32_t g_eth_reprobe_rx_status = 0u; -volatile uint32_t g_eth_reprobe_rx_len = 0u; -volatile uint32_t g_eth_input_ok_count = 0u; -volatile uint32_t g_eth_input_err_count = 0u; -volatile int32_t g_eth_last_input_err = 0; -volatile uint32_t g_eth_last_frame_len = 0u; -volatile uint8_t g_eth_last_frame_head[14] = {0u}; -volatile uint32_t g_eth_tx_probe_count = 0u; -volatile uint32_t g_eth_last_tx_len = 0u; -volatile uint8_t g_eth_last_tx_head[14] = {0u}; -volatile uint32_t g_eth_last_tcr_after = 0u; -volatile uint32_t g_eth_last_nsr_after = 0u; -volatile uint32_t g_eth_last_tsra = 0u; -volatile uint32_t g_eth_last_tsrb = 0u; -volatile uint32_t g_eth_last_txpll_rb = 0u; -volatile uint32_t g_eth_last_txplh_rb = 0u; -volatile uint32_t g_eth_arp_rx_count = 0u; -volatile uint32_t g_eth_arp_tx_count = 0u; -volatile uint32_t g_eth_arp_rx_op = 0u; -volatile uint32_t g_eth_arp_tx_op = 0u; -volatile uint8_t g_eth_local_ip[4] = {0u}; -volatile uint8_t g_eth_local_mac[6] = {0u}; -volatile uint8_t g_eth_arp_rx_sha[6] = {0u}; -volatile uint8_t g_eth_arp_rx_spa[4] = {0u}; -volatile uint8_t g_eth_arp_rx_tha[6] = {0u}; -volatile uint8_t g_eth_arp_rx_tpa[4] = {0u}; -volatile uint8_t g_eth_arp_tx_sha[6] = {0u}; -volatile uint8_t g_eth_arp_tx_spa[4] = {0u}; -volatile uint8_t g_eth_arp_tx_tha[6] = {0u}; -volatile uint8_t g_eth_arp_tx_tpa[4] = {0u}; -volatile uint32_t g_eth_lwip_arp_seen_count = 0u; -volatile uint32_t g_eth_lwip_arp_opcode = 0u; -volatile uint32_t g_eth_lwip_arp_for_us = 0u; -volatile uint32_t g_eth_lwip_arp_from_us = 0u; -volatile uint8_t g_eth_lwip_arp_sip[4] = {0u}; -volatile uint8_t g_eth_lwip_arp_dip[4] = {0u}; -volatile uint32_t g_eth_lwip_eth_seen_count = 0u; -volatile uint32_t g_eth_lwip_eth_last_type = 0u; -volatile uint32_t g_eth_lwip_eth_last_len = 0u; -volatile uint32_t g_eth_lwip_eth_arp_case_count = 0u; static TaskHandle_t xNetPollTaskHandle = NULL; static TaskHandle_t xTcpSrvTaskS1Handle = NULL; @@ -117,6 +37,54 @@ static TaskHandle_t xTcpCliTaskC1Handle = NULL; static TaskHandle_t xTcpCliTaskC2Handle = NULL; static TaskHandle_t xDefaultTaskHandle = NULL; +void app_start_network_tasks(void) +{ +#if !DIAG_TASK_ISOLATION + BaseType_t rc; + + if (xTcpSrvTaskS1Handle != NULL) { + debug_log_write("[NET] start-network-tasks already\r\n"); + return; + } + + 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); + + 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); + + 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); + + 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); + + debug_log_printf("[NET] start-network-tasks exit free=%lu min=%lu\r\n", + (unsigned long)xPortGetFreeHeapSize(), + (unsigned long)xPortGetMinimumEverFreeHeapSize()); +#endif +} + static void StartDefaultTask(void *argument) { TickType_t last_snapshot = xTaskGetTickCount(); @@ -145,76 +113,6 @@ static void StartDefaultTask(void *argument) (unsigned long)g_netif_phase, (unsigned long)uxTaskGetStackHighWaterMark(xNetPollTaskHandle)); } - debug_log_printf("[ARP] poll=%lu isr=0x%02lX pr=%lu rx=%lu drop=%lu tx=%lu lup=%lu ldn=%lu\r\n", - (unsigned long)g_eth_poll_count, - (unsigned long)g_eth_last_isr, - (unsigned long)g_eth_isr_pr_count, - (unsigned long)g_eth_rx_count, - (unsigned long)g_eth_rx_drop_count, - (unsigned long)g_eth_tx_count, - (unsigned long)g_eth_link_up_count, - (unsigned long)g_eth_link_down_count); - debug_log_printf("[ARP] txp=%lu tlen=%lu\r\n", - (unsigned long)g_eth_tx_probe_count, - (unsigned long)g_eth_last_tx_len); - debug_log_printf("[ARP] txr tcr=0x%02lX nsr=0x%02lX tsra=0x%02lX tsrb=0x%02lX pll=0x%02lX plh=0x%02lX\r\n", - (unsigned long)g_eth_last_tcr_after, - (unsigned long)g_eth_last_nsr_after, - (unsigned long)g_eth_last_tsra, - (unsigned long)g_eth_last_tsrb, - (unsigned long)g_eth_last_txpll_rb, - (unsigned long)g_eth_last_txplh_rb); - debug_log_printf("[ARP] local ip=%lu.%lu.%lu.%lu mac=%02lX:%02lX:%02lX:%02lX:%02lX:%02lX\r\n", - (unsigned long)g_eth_local_ip[0], - (unsigned long)g_eth_local_ip[1], - (unsigned long)g_eth_local_ip[2], - (unsigned long)g_eth_local_ip[3], - (unsigned long)g_eth_local_mac[0], - (unsigned long)g_eth_local_mac[1], - (unsigned long)g_eth_local_mac[2], - (unsigned long)g_eth_local_mac[3], - (unsigned long)g_eth_local_mac[4], - (unsigned long)g_eth_local_mac[5]); - debug_log_printf("[ARP] rxarp c=%lu op=%lu spa=%lu.%lu.%lu.%lu tpa=%lu.%lu.%lu.%lu\r\n", - (unsigned long)g_eth_arp_rx_count, - (unsigned long)g_eth_arp_rx_op, - (unsigned long)g_eth_arp_rx_spa[0], - (unsigned long)g_eth_arp_rx_spa[1], - (unsigned long)g_eth_arp_rx_spa[2], - (unsigned long)g_eth_arp_rx_spa[3], - (unsigned long)g_eth_arp_rx_tpa[0], - (unsigned long)g_eth_arp_rx_tpa[1], - (unsigned long)g_eth_arp_rx_tpa[2], - (unsigned long)g_eth_arp_rx_tpa[3]); - debug_log_printf("[ARP] txarp c=%lu op=%lu spa=%lu.%lu.%lu.%lu tpa=%lu.%lu.%lu.%lu\r\n", - (unsigned long)g_eth_arp_tx_count, - (unsigned long)g_eth_arp_tx_op, - (unsigned long)g_eth_arp_tx_spa[0], - (unsigned long)g_eth_arp_tx_spa[1], - (unsigned long)g_eth_arp_tx_spa[2], - (unsigned long)g_eth_arp_tx_spa[3], - (unsigned long)g_eth_arp_tx_tpa[0], - (unsigned long)g_eth_arp_tx_tpa[1], - (unsigned long)g_eth_arp_tx_tpa[2], - (unsigned long)g_eth_arp_tx_tpa[3]); - debug_log_printf("[ARP] lwip c=%lu op=%lu fu=%lu mu=%lu sip=%lu.%lu.%lu.%lu dip=%lu.%lu.%lu.%lu\r\n", - (unsigned long)g_eth_lwip_arp_seen_count, - (unsigned long)g_eth_lwip_arp_opcode, - (unsigned long)g_eth_lwip_arp_for_us, - (unsigned long)g_eth_lwip_arp_from_us, - (unsigned long)g_eth_lwip_arp_sip[0], - (unsigned long)g_eth_lwip_arp_sip[1], - (unsigned long)g_eth_lwip_arp_sip[2], - (unsigned long)g_eth_lwip_arp_sip[3], - (unsigned long)g_eth_lwip_arp_dip[0], - (unsigned long)g_eth_lwip_arp_dip[1], - (unsigned long)g_eth_lwip_arp_dip[2], - (unsigned long)g_eth_lwip_arp_dip[3]); - debug_log_printf("[ARP] edmx c=%lu type=0x%04lX len=%lu arpc=%lu\r\n", - (unsigned long)g_eth_lwip_eth_seen_count, - (unsigned long)g_eth_lwip_eth_last_type, - (unsigned long)g_eth_lwip_eth_last_len, - (unsigned long)g_eth_lwip_eth_arp_case_count); last_snapshot = xTaskGetTickCount(); } vTaskDelay(pdMS_TO_TICKS(500)); @@ -230,8 +128,8 @@ void MX_FREERTOS_Init(void) debug_log_boot("uart-trans-init"); xNetSemaphore = xSemaphoreCreateBinary(); - xTcpRxQueue = xQueueCreate(8, sizeof(route_msg_t *)); - xConfigQueue = xQueueCreate(4, sizeof(route_msg_t *)); + xTcpRxQueue = xQueueCreate(6, sizeof(route_msg_t *)); + xConfigQueue = xQueueCreate(2, sizeof(route_msg_t *)); for (i = 0; i < CONFIG_LINK_COUNT; ++i) { xLinkTxQueues[i] = xQueueCreate(4, sizeof(route_msg_t *)); } @@ -247,10 +145,6 @@ void MX_FREERTOS_Init(void) configASSERT(xTaskCreate(NetPollTask, "NetPoll", TASK_STACK_NET_POLL, NULL, TASK_PRIORITY_NET_POLL, &xNetPollTaskHandle) == pdPASS); #if !DIAG_TASK_ISOLATION - configASSERT(xTaskCreate(TcpSrvTask_S1, "TcpSrvS1", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS1Handle) == pdPASS); - configASSERT(xTaskCreate(TcpSrvTask_S2, "TcpSrvS2", TASK_STACK_TCP_SERVER, NULL, TASK_PRIORITY_TCP_SERVER, &xTcpSrvTaskS2Handle) == pdPASS); - configASSERT(xTaskCreate(TcpCliTask_C1, "TcpCliC1", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC1Handle) == pdPASS); - configASSERT(xTaskCreate(TcpCliTask_C2, "TcpCliC2", TASK_STACK_TCP_CLIENT, NULL, TASK_PRIORITY_TCP_CLIENT, &xTcpCliTaskC2Handle) == pdPASS); configASSERT(xTaskCreate(UartRxTask, "UartRx", TASK_STACK_UART_RX, NULL, TASK_PRIORITY_UART_RX, &xUartRxTaskHandle) == pdPASS); configASSERT(xTaskCreate(ConfigTask, "Config", TASK_STACK_CONFIG, NULL, TASK_PRIORITY_CONFIG, &xConfigTaskHandle) == pdPASS); #else diff --git a/Drivers/SEGGER/RTT/SEGGER_RTT_Conf.h b/Drivers/SEGGER/RTT/SEGGER_RTT_Conf.h index 9960aec..513e314 100644 --- a/Drivers/SEGGER/RTT/SEGGER_RTT_Conf.h +++ b/Drivers/SEGGER/RTT/SEGGER_RTT_Conf.h @@ -92,7 +92,7 @@ Revision: $Rev: 24316 $ #endif #ifndef BUFFER_SIZE_UP - #define BUFFER_SIZE_UP (2048) // Size of the buffer for terminal output of target, up to host (Default: 1k) + #define BUFFER_SIZE_UP (512) // Size of the buffer for terminal output of target, up to host (Default: 1k) #endif #ifndef BUFFER_SIZE_DOWN