fix: capture current ch390 and lwip debug changes

This commit is contained in:
2026-04-18 05:29:32 +08:00
parent cd48a8af68
commit 70e78a6ef6
6 changed files with 63 additions and 295 deletions
-14
View File
@@ -55,7 +55,6 @@
#include "lwip/acd.h"
#include "lwip/prot/iana.h"
#include "netif/ethernet.h"
#include "../../../../../App/app_runtime.h"
#include <string.h>
@@ -695,19 +694,6 @@ etharp_input(struct pbuf *p, struct netif *netif)
from_us = (u8_t)ip4_addr_eq(&sipaddr, netif_ip4_addr(netif));
}
g_eth_lwip_arp_seen_count += 1u;
g_eth_lwip_arp_opcode = (uint32_t)lwip_htons(hdr->opcode);
g_eth_lwip_arp_for_us = (uint32_t)for_us;
g_eth_lwip_arp_from_us = (uint32_t)from_us;
g_eth_lwip_arp_sip[0] = ip4_addr1(&sipaddr);
g_eth_lwip_arp_sip[1] = ip4_addr2(&sipaddr);
g_eth_lwip_arp_sip[2] = ip4_addr3(&sipaddr);
g_eth_lwip_arp_sip[3] = ip4_addr4(&sipaddr);
g_eth_lwip_arp_dip[0] = ip4_addr1(&dipaddr);
g_eth_lwip_arp_dip[1] = ip4_addr2(&dipaddr);
g_eth_lwip_arp_dip[2] = ip4_addr3(&dipaddr);
g_eth_lwip_arp_dip[3] = ip4_addr4(&dipaddr);
/* ARP message directed to us?
-> add IP address in ARP cache; assume requester wants to talk to us,
can result in directly sending the queued packets for this host.
+12 -12
View File
@@ -51,7 +51,7 @@
/* Heap size for dynamic memory allocation.
* With netconn: larger heap needed for netbuf allocation and connection management.
* 8KB provides headroom for 4 concurrent TCP connections. */
#define MEM_SIZE (6 * 1024)
#define MEM_SIZE (7 * 1024)
/* Number of pbufs in pool.
* 10 pools for 4 concurrent connections with some headroom. */
@@ -77,20 +77,20 @@
/* Number of simultaneously queued TCP segments
* Increased for 4 concurrent connections */
#define MEMP_NUM_TCP_SEG 16
#define MEMP_NUM_TCP_SEG 12
/* Number of simultaneously active timeouts */
#define MEMP_NUM_SYS_TIMEOUT 8
#define MEMP_NUM_SYS_TIMEOUT 12
/* Number of netbufs (for netconn API, one per pending recv) */
#define MEMP_NUM_NETBUF 4
#define MEMP_NUM_NETBUF 8
/* Number of netconns: 2 listeners + 2 accepted + 2 clients + 2 margin = 8 */
#define MEMP_NUM_NETCONN 6
#define MEMP_NUM_NETCONN 8
/* TCPIP message queue size (must be >= max simultaneous API calls) */
#define MEMP_NUM_TCPIP_MSG_API 6
#define MEMP_NUM_TCPIP_MSG_INPKT 6
#define MEMP_NUM_TCPIP_MSG_API 8
#define MEMP_NUM_TCPIP_MSG_INPKT 8
/*-----------------------------------------------------------------------------
* IP Configuration
@@ -149,7 +149,7 @@
#define TCP_MSS 536 /* Conservative value for compatibility */
/* TCP sender buffer space - increased for bridge throughput */
#define TCP_SND_BUF (4 * TCP_MSS)
#define TCP_SND_BUF (2 * TCP_MSS)
/* TCP sender buffer space (pbufs) */
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
@@ -162,7 +162,7 @@
#define LWIP_DISABLE_TCP_SANITY_CHECKS 1
/* TCP receive window - increased for bridge throughput */
#define TCP_WND (4 * TCP_MSS)
#define TCP_WND (2 * TCP_MSS)
/* TCP writable space threshold */
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1)
@@ -281,11 +281,11 @@
#define DEFAULT_THREAD_PRIO (configMAX_PRIORITIES - 3)
/* Mailbox sizes */
#define TCPIP_MBOX_SIZE 6
#define TCPIP_MBOX_SIZE 12
#define DEFAULT_RAW_RECVMBOX_SIZE 4
#define DEFAULT_UDP_RECVMBOX_SIZE 4
#define DEFAULT_TCP_RECVMBOX_SIZE 4
#define DEFAULT_ACCEPTMBOX_SIZE 4
#define DEFAULT_TCP_RECVMBOX_SIZE 6
#define DEFAULT_ACCEPTMBOX_SIZE 6
/* Thread name length */
#define LWIP_NETCONN_SEM_PER_THREAD 1
-5
View File
@@ -14,7 +14,6 @@
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/prot/ethernet.h"
#include "../../../../App/app_runtime.h"
#include <string.h>
@@ -77,14 +76,10 @@ err_t ethernet_input(struct pbuf *p, struct netif *netif)
ethhdr = (struct eth_hdr *)p->payload;
type = lwip_htons(ethhdr->type);
g_eth_lwip_eth_seen_count += 1u;
g_eth_lwip_eth_last_type = (uint32_t)type;
g_eth_lwip_eth_last_len = (uint32_t)p->len;
switch (type) {
#if LWIP_IPV4 && LWIP_ARP
case ETHTYPE_ARP:
g_eth_lwip_eth_arp_case_count += 1u;
if (netif->flags & NETIF_FLAG_ETHARP) {
if (pbuf_remove_header(p, SIZEOF_ETH_HDR)) {
pbuf_free(p);
+34 -153
View File
@@ -23,9 +23,9 @@
#include "task.h"
#include "semphr.h"
#include "app_runtime.h"
#include "debug_log.h"
#include "config.h"
#include "app_runtime.h"
#include <string.h>
@@ -42,50 +42,8 @@ static uint8_t s_rx_buffer[CH390_PKT_MAX];
static uint8_t s_tx_buffer[CH390_PKT_MAX];
static uint8_t s_garp_sent = 0u;
static void eth_diag_store_local_netif(const struct netif *netif)
{
uint16_t i;
const ip4_addr_t *ipaddr = netif_ip4_addr(netif);
const uint8_t *ipbytes = (const uint8_t *)&ipaddr->addr;
for (i = 0u; i < 6u; ++i)
{
g_eth_local_mac[i] = netif->hwaddr[i];
}
g_eth_local_ip[0] = ipbytes[0];
g_eth_local_ip[1] = ipbytes[1];
g_eth_local_ip[2] = ipbytes[2];
g_eth_local_ip[3] = ipbytes[3];
}
static void eth_diag_store_arp_fields(uint8_t is_tx, const uint8_t *arp)
{
uint16_t i;
volatile uint32_t *op_ptr = is_tx ? &g_eth_arp_tx_op : &g_eth_arp_rx_op;
volatile uint32_t *count_ptr = is_tx ? &g_eth_arp_tx_count : &g_eth_arp_rx_count;
volatile uint8_t *sha = is_tx ? g_eth_arp_tx_sha : g_eth_arp_rx_sha;
volatile uint8_t *spa = is_tx ? g_eth_arp_tx_spa : g_eth_arp_rx_spa;
volatile uint8_t *tha = is_tx ? g_eth_arp_tx_tha : g_eth_arp_rx_tha;
volatile uint8_t *tpa = is_tx ? g_eth_arp_tx_tpa : g_eth_arp_rx_tpa;
*op_ptr = (uint32_t)(((uint16_t)arp[6] << 8) | arp[7]);
*count_ptr += 1u;
for (i = 0u; i < 6u; ++i)
{
sha[i] = arp[8u + i];
tha[i] = arp[18u + i];
}
for (i = 0u; i < 4u; ++i)
{
spa[i] = arp[14u + i];
tpa[i] = arp[24u + i];
}
}
/* Forward declarations */
static void low_level_init(struct netif *netif);
static err_t low_level_init(struct netif *netif);
static err_t low_level_output(struct netif *netif, struct pbuf *p);
static struct pbuf *low_level_input(struct netif *netif);
static void ethernetif_update_link(uint8_t link_status);
@@ -98,7 +56,7 @@ static void ethernetif_update_link(uint8_t link_status);
* @brief Initialize the CH390 hardware
* @param netif Network interface structure
*/
static void low_level_init(struct netif *netif)
static err_t low_level_init(struct netif *netif)
{
struct ethernetif *ethernetif = netif->state;
const device_config_t *cfg = config_get();
@@ -107,6 +65,10 @@ static void low_level_init(struct netif *netif)
if (spi_mutex == NULL)
{
spi_mutex = xSemaphoreCreateMutex();
if (spi_mutex == NULL)
{
return ERR_MEM;
}
}
/* Initialize CH390 GPIO and SPI */
@@ -147,6 +109,8 @@ static void low_level_init(struct netif *netif)
/* Enable CH390 interrupt */
ch390_interrupt_init();
return ERR_OK;
}
/**
@@ -159,9 +123,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
uint16_t offset;
uint16_t copy_len;
uint16_t i;
uint16_t tx_len;
int tx_rc;
(void)netif;
/* Take SPI mutex */
@@ -199,27 +162,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
}
tx_len = p->tot_len;
eth_diag_store_local_netif(netif);
g_eth_last_tx_len = tx_len;
copy_len = (tx_len < (uint16_t)sizeof(g_eth_last_tx_head)) ? tx_len : (uint16_t)sizeof(g_eth_last_tx_head);
for (i = 0u; i < (uint16_t)sizeof(g_eth_last_tx_head); ++i)
{
g_eth_last_tx_head[i] = 0u;
}
for (i = 0u; i < copy_len; ++i)
{
g_eth_last_tx_head[i] = s_tx_buffer[i];
}
g_eth_tx_probe_count += 1u;
if ((tx_len >= 42u) && (s_tx_buffer[12] == 0x08u) && (s_tx_buffer[13] == 0x06u))
{
eth_diag_store_arp_fields(1u, &s_tx_buffer[14]);
}
ch390_runtime_send_packet(s_tx_buffer, tx_len);
g_eth_tx_count += 1u;
tx_rc = ch390_runtime_send_packet(s_tx_buffer, tx_len);
/* Release SPI mutex */
if (spi_mutex != NULL)
@@ -230,6 +174,14 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
#if ETH_PAD_SIZE
pbuf_add_header(p, ETH_PAD_SIZE);
#endif
if (tx_rc != 0)
{
LINK_STATS_INC(link.drop);
LINK_STATS_INC(link.err);
debug_log_write("[ETH] tx timeout\r\n");
return ERR_TIMEOUT;
}
LINK_STATS_INC(link.xmit);
@@ -298,17 +250,10 @@ static struct pbuf *low_level_input(struct netif *netif)
pbuf_free(p);
p = NULL;
LINK_STATS_INC(link.drop);
g_eth_rx_drop_count += 1u;
}
else
{
eth_diag_store_local_netif(netif);
if ((rx_len >= 42u) && (s_rx_buffer[12] == 0x08u) && (s_rx_buffer[13] == 0x06u))
{
eth_diag_store_arp_fields(0u, &s_rx_buffer[14]);
}
LINK_STATS_INC(link.recv);
g_eth_rx_count += 1u;
}
#if ETH_PAD_SIZE
@@ -324,7 +269,6 @@ static struct pbuf *low_level_input(struct netif *netif)
ch390_drop_packet(ethernetif->rx_len);
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
g_eth_rx_drop_count += 1u;
}
/* Release SPI mutex */
@@ -348,35 +292,19 @@ void ethernetif_input(struct netif *netif)
{
struct pbuf *p;
err_t input_err;
uint16_t copy_len;
uint16_t i;
/* Get received packet */
p = low_level_input(netif);
if (p != NULL)
{
g_eth_last_frame_len = p->tot_len;
copy_len = (p->tot_len < (uint16_t)sizeof(g_eth_last_frame_head)) ? (uint16_t)p->tot_len : (uint16_t)sizeof(g_eth_last_frame_head);
for (i = 0u; i < (uint16_t)sizeof(g_eth_last_frame_head); ++i)
{
g_eth_last_frame_head[i] = 0u;
}
pbuf_copy_partial(p, (void *)g_eth_last_frame_head, copy_len, 0u);
/* Pass to LwIP stack */
input_err = netif->input(p, netif);
g_eth_last_input_err = (int32_t)input_err;
if (input_err != ERR_OK)
{
g_eth_input_err_count += 1u;
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
}
else
{
g_eth_input_ok_count += 1u;
}
}
}
@@ -419,7 +347,12 @@ err_t ethernetif_init(struct netif *netif)
netif->linkoutput = low_level_output;
/* Initialize hardware */
low_level_init(netif);
if (low_level_init(netif) != ERR_OK)
{
mem_free(ethernetif);
netif->state = NULL;
return ERR_MEM;
}
return ERR_OK;
}
@@ -505,8 +438,6 @@ void ethernetif_diag_poll_status(void)
{
struct ch390_runtime_status runtime_status;
g_eth_poll_count += 1u;
if (spi_mutex != NULL)
{
xSemaphoreTake(spi_mutex, portMAX_DELAY);
@@ -519,29 +450,6 @@ void ethernetif_diag_poll_status(void)
{
xSemaphoreGive(spi_mutex);
}
g_eth_last_isr = runtime_status.int_status;
g_eth_last_nsr = runtime_status.nsr;
g_eth_last_nsr_rxrdy = ((runtime_status.nsr & NSR_RXRDY) != 0u) ? 1u : 0u;
g_eth_last_mrcmdx = runtime_status.mrcmdx;
g_eth_last_mrcmdx1 = runtime_status.mrcmdx1;
g_eth_last_mrrl = runtime_status.mrrl;
g_eth_last_mrrh = runtime_status.mrrh;
g_eth_last_bcastcr = runtime_status.bcastcr;
g_eth_last_mar7 = runtime_status.mar7;
if ((runtime_status.int_status & ISR_PR) != 0u)
{
g_eth_isr_pr_count += 1u;
}
if (runtime_status.link_up != 0u)
{
if (g_eth_last_nsr != 0u)
{
g_eth_link_up_count += 0u;
}
}
}
/**
@@ -561,7 +469,6 @@ static void ethernetif_update_link(uint8_t link_status)
UNLOCK_TCPIP_CORE();
s_garp_sent = 1u;
}
g_eth_link_up_count += 1u;
}
}
else
@@ -570,7 +477,6 @@ static void ethernetif_update_link(uint8_t link_status)
{
netif_set_link_down(&ch390_netif);
s_garp_sent = 0u;
g_eth_link_down_count += 1u;
}
}
}
@@ -583,9 +489,7 @@ void ethernetif_poll(void)
struct ch390_runtime_status runtime_status;
struct pbuf *p;
err_t input_err;
uint16_t copy_len;
uint16_t i;
g_eth_poll_count += 1u;
uint8_t rx_budget = 4u;
/* Take SPI mutex */
if (spi_mutex != NULL)
@@ -601,16 +505,6 @@ void ethernetif_poll(void)
{
xSemaphoreGive(spi_mutex);
}
g_eth_last_isr = runtime_status.int_status;
g_eth_last_nsr = runtime_status.nsr;
g_eth_last_nsr_rxrdy = ((runtime_status.nsr & NSR_RXRDY) != 0u) ? 1u : 0u;
g_eth_last_mrcmdx = runtime_status.mrcmdx;
g_eth_last_mrcmdx1 = runtime_status.mrcmdx1;
g_eth_last_mrrl = runtime_status.mrrl;
g_eth_last_mrrh = runtime_status.mrrh;
g_eth_last_bcastcr = runtime_status.bcastcr;
g_eth_last_mar7 = runtime_status.mar7;
/* Handle link change */
if ((runtime_status.int_status & ISR_LNKCHG) != 0u)
@@ -625,40 +519,27 @@ void ethernetif_poll(void)
LINK_STATS_INC(link.err);
}
/* Process received packets */
if ((runtime_status.int_status & ISR_PR) != 0u)
{
g_eth_isr_pr_count += 1u;
}
/* Always attempt to drain RX FIFO so packet handling does not depend only on ISR_PR timing. */
while (1)
while (rx_budget > 0u)
{
p = low_level_input(&ch390_netif);
if (p == NULL)
{
break;
}
g_eth_last_frame_len = p->tot_len;
copy_len = (p->tot_len < (uint16_t)sizeof(g_eth_last_frame_head)) ? (uint16_t)p->tot_len : (uint16_t)sizeof(g_eth_last_frame_head);
for (i = 0u; i < (uint16_t)sizeof(g_eth_last_frame_head); ++i)
{
g_eth_last_frame_head[i] = 0u;
}
pbuf_copy_partial(p, (void *)g_eth_last_frame_head, copy_len, 0u);
input_err = ch390_netif.input(p, &ch390_netif);
g_eth_last_input_err = (int32_t)input_err;
if (input_err != ERR_OK)
{
g_eth_input_err_count += 1u;
pbuf_free(p);
}
else
{
g_eth_input_ok_count += 1u;
}
--rx_budget;
}
if (rx_budget == 0u)
{
taskYIELD();
}
}