feat: 保存已验证的CH390网络打通基线
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
#include "task_net_poll.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "CH390.h"
|
||||
#include <string.h>
|
||||
|
||||
#if !DIAG_CH390_RAW_POLL
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/ip4_addr.h"
|
||||
#endif
|
||||
|
||||
#include "ethernetif.h"
|
||||
#include "config.h"
|
||||
#include "app_runtime.h"
|
||||
#include "debug_log.h"
|
||||
|
||||
void NetPollTask(void *argument)
|
||||
{
|
||||
const device_config_t *cfg;
|
||||
#if !DIAG_CH390_RAW_POLL
|
||||
ip4_addr_t ipaddr;
|
||||
ip4_addr_t netmask;
|
||||
ip4_addr_t gateway;
|
||||
#else
|
||||
static uint8_t s_diag_rx_buffer[CH390_PKT_MAX];
|
||||
#endif
|
||||
BaseType_t loop_logged = pdFALSE;
|
||||
|
||||
(void)argument;
|
||||
|
||||
debug_log_write("[NET] task-entry\r\n");
|
||||
cfg = config_get();
|
||||
debug_log_write("[NET] config-ok\r\n");
|
||||
|
||||
#if DIAG_CH390_RAW_POLL
|
||||
g_netif_phase = 1u;
|
||||
debug_log_write("[NET] diag-ch390-init enter\r\n");
|
||||
ethernetif_diag_ch390_init();
|
||||
g_netif_phase = 7u;
|
||||
debug_log_write("[NET] diag-ch390-init exit\r\n");
|
||||
|
||||
if (g_netif_init_ok != 1)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
g_netif_ready = pdTRUE;
|
||||
debug_log_write("[NET] diag-ch390-ready\r\n");
|
||||
#else
|
||||
debug_log_write("[NET] tcpip-init enter\r\n");
|
||||
tcpip_init(NULL, NULL);
|
||||
debug_log_write("[NET] tcpip-init exit\r\n");
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
debug_log_write("[NET] post-delay\r\n");
|
||||
|
||||
IP4_ADDR(&ipaddr, cfg->net.ip[0], cfg->net.ip[1], cfg->net.ip[2], cfg->net.ip[3]);
|
||||
IP4_ADDR(&netmask, cfg->net.mask[0], cfg->net.mask[1], cfg->net.mask[2], cfg->net.mask[3]);
|
||||
IP4_ADDR(&gateway, cfg->net.gw[0], cfg->net.gw[1], cfg->net.gw[2], cfg->net.gw[3]);
|
||||
|
||||
g_netif_phase = 1u;
|
||||
debug_log_printf("[NET] netif-call hwm=%lu\r\n", (unsigned long)uxTaskGetStackHighWaterMark(NULL));
|
||||
debug_log_write("[NET] netif-init enter\r\n");
|
||||
lwip_netif_init(&ipaddr, &netmask, &gateway);
|
||||
g_netif_phase = 7u;
|
||||
debug_log_write("[NET] netif-init exit\r\n");
|
||||
|
||||
if (g_netif_init_ok != 1) {
|
||||
for (;;) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
g_netif_ready = pdTRUE;
|
||||
debug_log_write("[NET] netif-ready\r\n");
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
if (loop_logged == pdFALSE) {
|
||||
g_netif_phase = 8u;
|
||||
debug_log_write("[NET] loop-enter\r\n");
|
||||
loop_logged = pdTRUE;
|
||||
}
|
||||
(void)xSemaphoreTake(xNetSemaphore, pdMS_TO_TICKS(2));
|
||||
|
||||
#if DIAG_CH390_RAW_POLL
|
||||
ethernetif_diag_poll_status();
|
||||
|
||||
if (g_eth_last_nsr_rxrdy != 0u)
|
||||
{
|
||||
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,
|
||||
(unsigned int)s_diag_rx_buffer[0],
|
||||
(unsigned int)s_diag_rx_buffer[1],
|
||||
(unsigned int)s_diag_rx_buffer[2],
|
||||
(unsigned int)s_diag_rx_buffer[3]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ethernetif_poll();
|
||||
ethernetif_check_link();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user