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
+15 -109
View File
@@ -11,8 +11,6 @@
******************************************************************************/ ******************************************************************************/
#include "CH390.h" #include "CH390.h"
#include "CH390_Interface.h" #include "CH390_Interface.h"
#include "../../App/app_runtime.h"
#include "../../Core/Inc/debug_log.h"
void ch390_probe_rx_header(uint8_t *head) void ch390_probe_rx_header(uint8_t *head)
{ {
@@ -34,9 +32,6 @@ void ch390_probe_rx_header(uint8_t *head)
*/ */
uint32_t ch390_receive_packet(uint8_t *buff, uint8_t *rx_status) uint32_t ch390_receive_packet(uint8_t *buff, uint8_t *rx_status)
{ {
static uint32_t s_rxrdy_miss_log_count = 0u;
uint32_t i;
uint8_t rx_ready;
uint8_t nsr; uint8_t nsr;
uint16_t rx_len = 0; uint16_t rx_len = 0;
uint8_t ReceiveData[4]; uint8_t ReceiveData[4];
@@ -45,122 +40,30 @@ uint32_t ch390_receive_packet(uint8_t *buff, uint8_t *rx_status)
{ {
*rx_status = 0u; *rx_status = 0u;
} }
g_eth_last_rx_fail_stage = 0u;
g_eth_last_rx_status = 0u;
g_eth_last_rx_len = 0u;
g_eth_last_rx_head0 = 0u;
g_eth_last_rx_head1 = 0u;
g_eth_last_rx_head2 = 0u;
g_eth_last_rx_head3 = 0u;
g_eth_probe_rx_status = 0u;
g_eth_probe_rx_len = 0u;
g_eth_probe_head0 = 0u;
g_eth_probe_head1 = 0u;
g_eth_probe_head2 = 0u;
g_eth_probe_head3 = 0u;
for (i = 0u; i < 32u; ++i)
{
g_eth_probe_dump[i] = 0u;
}
g_eth_reprobe_rx_status = 0u;
g_eth_reprobe_rx_len = 0u;
g_eth_reprobe_head0 = 0u;
g_eth_reprobe_head1 = 0u;
g_eth_reprobe_head2 = 0u;
g_eth_reprobe_head3 = 0u;
nsr = ch390_read_reg(CH390_NSR); nsr = ch390_read_reg(CH390_NSR);
g_eth_last_nsr = nsr;
if ((nsr & NSR_RXRDY) == 0u) if ((nsr & NSR_RXRDY) == 0u)
{ {
g_eth_last_rx_fail_stage = 2u;
return 0; return 0;
} }
rx_ready = 0u;
g_eth_last_rx_ready = 0u;
g_eth_last_mrcmdx = 0u;
g_eth_last_mrcmdx1 = 0u;
g_eth_last_mrrl = 0u;
g_eth_last_mrrh = 0u;
ch390_read_mem(ReceiveData, 4); ch390_read_mem(ReceiveData, 4);
g_eth_last_rx_head0 = ReceiveData[0];
g_eth_last_rx_head1 = ReceiveData[1];
g_eth_last_rx_head2 = ReceiveData[2];
g_eth_last_rx_head3 = ReceiveData[3];
if (rx_status != 0) if (rx_status != 0)
{ {
*rx_status = ReceiveData[1]; *rx_status = ReceiveData[1];
} }
rx_len = (uint16_t)ReceiveData[2] | ((uint16_t)ReceiveData[3] << 8); rx_len = (uint16_t)ReceiveData[2] | ((uint16_t)ReceiveData[3] << 8);
g_eth_last_rx_status = ReceiveData[1];
g_eth_last_rx_len = rx_len;
if (((ReceiveData[1] & 0x3Fu) != 0u) || if (((ReceiveData[1] & 0x3Fu) != 0u) ||
(rx_len < 14u) || (rx_len < 14u) ||
(rx_len > CH390_PKT_MAX)) (rx_len > CH390_PKT_MAX))
{ {
g_eth_last_rx_ready = rx_ready;
g_eth_last_mrcmdx = 0u;
g_eth_last_mrcmdx1 = 0u;
g_eth_last_mrrl = 0u;
g_eth_last_mrrh = 0u;
g_eth_last_rx_fail_stage = 2u;
g_eth_probe_attempted += 1u;
g_eth_probe_head0 = ReceiveData[0];
g_eth_probe_head1 = ReceiveData[1];
g_eth_probe_head2 = ReceiveData[2];
g_eth_probe_head3 = ReceiveData[3];
g_eth_probe_rx_status = ReceiveData[1];
for (i = 0u; i < 32u; ++i)
{
g_eth_probe_dump[i] = 0u;
}
g_eth_probe_rx_len = (uint32_t)rx_len;
g_eth_rx_fallback_reject_count += 1u;
s_rxrdy_miss_log_count += 1u;
if ((s_rxrdy_miss_log_count & 0xFFu) == 1u)
{
debug_log_printf("[ETH] rxhdr-bad #%lu nsr=0x%02X rr=0x%02X mrx=0x%02X mrx1=0x%02X mrr=0x%02X%02X h=%02X %02X %02X %02X\r\n",
(unsigned long)s_rxrdy_miss_log_count,
(unsigned int)nsr,
(unsigned int)rx_ready,
(unsigned int)g_eth_last_mrcmdx,
(unsigned int)g_eth_last_mrcmdx1,
(unsigned int)g_eth_last_mrrh,
(unsigned int)g_eth_last_mrrl,
(unsigned int)ReceiveData[0],
(unsigned int)ReceiveData[1],
(unsigned int)ReceiveData[2],
(unsigned int)ReceiveData[3]);
}
return 0; return 0;
} }
g_eth_rx_gate_ok_count += 1u; ch390_read_mem(buff, rx_len);
g_eth_rx_fallback_ok_count += 1u;
if(rx_len <= CH390_PKT_MAX)
{
ch390_read_mem(buff, rx_len);
}
else
{
g_eth_last_rx_fail_stage = 3u;
}
if ((rx_len > CH390_PKT_MAX))
{
g_eth_last_rx_fail_stage = 4u;
return 0;
}
g_eth_last_rx_fail_stage = 5u;
return rx_len; return rx_len;
} }
@@ -170,24 +73,27 @@ uint32_t ch390_receive_packet(uint8_t *buff, uint8_t *rx_status)
* @param buff - Data to be sent * @param buff - Data to be sent
* @param length - Less than 3k bytes. * @param length - Less than 3k bytes.
*/ */
void ch390_send_packet(uint8_t *buff, uint16_t length) int ch390_send_packet(uint8_t *buff, uint16_t length)
{ {
uint32_t spin_count = 0u;
// Write data to SRAM // Write data to SRAM
ch390_write_mem(buff, length); ch390_write_mem(buff, length);
// Wait until last transmit complete // Wait until last transmit complete
while(ch390_read_reg(CH390_TCR) & TCR_TXREQ); while ((ch390_read_reg(CH390_TCR) & TCR_TXREQ) != 0u)
{
++spin_count;
if (spin_count >= 4096u)
{
return -1;
}
}
// Set current packet length // Set current packet length
ch390_write_reg(CH390_TXPLL, length & 0xff); ch390_write_reg(CH390_TXPLL, length & 0xff);
ch390_write_reg(CH390_TXPLH, (length >> 8) & 0xff); ch390_write_reg(CH390_TXPLH, (length >> 8) & 0xff);
// Issue transmit request // Issue transmit request
ch390_send_request(); ch390_send_request();
return 0;
g_eth_last_tcr_after = (uint32_t)ch390_read_reg(CH390_TCR);
g_eth_last_nsr_after = (uint32_t)ch390_read_reg(CH390_NSR);
g_eth_last_tsra = (uint32_t)ch390_read_reg(CH390_TSRA);
g_eth_last_tsrb = (uint32_t)ch390_read_reg(CH390_TSRB);
g_eth_last_txpll_rb = (uint32_t)ch390_read_reg(CH390_TXPLL);
g_eth_last_txplh_rb = (uint32_t)ch390_read_reg(CH390_TXPLH);
} }
/** /**
@@ -760,7 +666,7 @@ uint32_t ch390_runtime_receive_packet(uint8_t *buff, uint8_t *rx_status)
return ch390_receive_packet(buff, rx_status); return ch390_receive_packet(buff, rx_status);
} }
void ch390_runtime_send_packet(uint8_t *buff, uint16_t length) int ch390_runtime_send_packet(uint8_t *buff, uint16_t length)
{ {
ch390_send_packet(buff, length); return ch390_send_packet(buff, length);
} }
+2 -2
View File
@@ -392,7 +392,7 @@ uint32_t ch390_receive_packet(uint8_t *buff, uint8_t *rx_status);
* @param buff - Data to be sent * @param buff - Data to be sent
* @param length - Less than 3k bytes. * @param length - Less than 3k bytes.
*/ */
void ch390_send_packet(uint8_t *buff, uint16_t length); int ch390_send_packet(uint8_t *buff, uint16_t length);
/** /**
* @name ch390_send_request * @name ch390_send_request
@@ -672,6 +672,6 @@ uint32_t ch390_runtime_receive_packet(uint8_t *buff, uint8_t *rx_status);
* @param buff - Data to be sent * @param buff - Data to be sent
* @param length - Less than 3k bytes. * @param length - Less than 3k bytes.
*/ */
void ch390_runtime_send_packet(uint8_t *buff, uint16_t length); int ch390_runtime_send_packet(uint8_t *buff, uint16_t length);
#endif /* __CH390_H */ #endif /* __CH390_H */
-14
View File
@@ -55,7 +55,6 @@
#include "lwip/acd.h" #include "lwip/acd.h"
#include "lwip/prot/iana.h" #include "lwip/prot/iana.h"
#include "netif/ethernet.h" #include "netif/ethernet.h"
#include "../../../../../App/app_runtime.h"
#include <string.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)); 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? /* ARP message directed to us?
-> add IP address in ARP cache; assume requester wants to talk 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. 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. /* Heap size for dynamic memory allocation.
* With netconn: larger heap needed for netbuf allocation and connection management. * With netconn: larger heap needed for netbuf allocation and connection management.
* 8KB provides headroom for 4 concurrent TCP connections. */ * 8KB provides headroom for 4 concurrent TCP connections. */
#define MEM_SIZE (6 * 1024) #define MEM_SIZE (7 * 1024)
/* Number of pbufs in pool. /* Number of pbufs in pool.
* 10 pools for 4 concurrent connections with some headroom. */ * 10 pools for 4 concurrent connections with some headroom. */
@@ -77,20 +77,20 @@
/* Number of simultaneously queued TCP segments /* Number of simultaneously queued TCP segments
* Increased for 4 concurrent connections */ * Increased for 4 concurrent connections */
#define MEMP_NUM_TCP_SEG 16 #define MEMP_NUM_TCP_SEG 12
/* Number of simultaneously active timeouts */ /* 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) */ /* 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 */ /* 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) */ /* TCPIP message queue size (must be >= max simultaneous API calls) */
#define MEMP_NUM_TCPIP_MSG_API 6 #define MEMP_NUM_TCPIP_MSG_API 8
#define MEMP_NUM_TCPIP_MSG_INPKT 6 #define MEMP_NUM_TCPIP_MSG_INPKT 8
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* IP Configuration * IP Configuration
@@ -149,7 +149,7 @@
#define TCP_MSS 536 /* Conservative value for compatibility */ #define TCP_MSS 536 /* Conservative value for compatibility */
/* TCP sender buffer space - increased for bridge throughput */ /* 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) */ /* TCP sender buffer space (pbufs) */
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
@@ -162,7 +162,7 @@
#define LWIP_DISABLE_TCP_SANITY_CHECKS 1 #define LWIP_DISABLE_TCP_SANITY_CHECKS 1
/* TCP receive window - increased for bridge throughput */ /* TCP receive window - increased for bridge throughput */
#define TCP_WND (4 * TCP_MSS) #define TCP_WND (2 * TCP_MSS)
/* TCP writable space threshold */ /* TCP writable space threshold */
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) #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) #define DEFAULT_THREAD_PRIO (configMAX_PRIORITIES - 3)
/* Mailbox sizes */ /* Mailbox sizes */
#define TCPIP_MBOX_SIZE 6 #define TCPIP_MBOX_SIZE 12
#define DEFAULT_RAW_RECVMBOX_SIZE 4 #define DEFAULT_RAW_RECVMBOX_SIZE 4
#define DEFAULT_UDP_RECVMBOX_SIZE 4 #define DEFAULT_UDP_RECVMBOX_SIZE 4
#define DEFAULT_TCP_RECVMBOX_SIZE 4 #define DEFAULT_TCP_RECVMBOX_SIZE 6
#define DEFAULT_ACCEPTMBOX_SIZE 4 #define DEFAULT_ACCEPTMBOX_SIZE 6
/* Thread name length */ /* Thread name length */
#define LWIP_NETCONN_SEM_PER_THREAD 1 #define LWIP_NETCONN_SEM_PER_THREAD 1
-5
View File
@@ -14,7 +14,6 @@
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/prot/ethernet.h" #include "lwip/prot/ethernet.h"
#include "../../../../App/app_runtime.h"
#include <string.h> #include <string.h>
@@ -77,14 +76,10 @@ err_t ethernet_input(struct pbuf *p, struct netif *netif)
ethhdr = (struct eth_hdr *)p->payload; ethhdr = (struct eth_hdr *)p->payload;
type = lwip_htons(ethhdr->type); 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) { switch (type) {
#if LWIP_IPV4 && LWIP_ARP #if LWIP_IPV4 && LWIP_ARP
case ETHTYPE_ARP: case ETHTYPE_ARP:
g_eth_lwip_eth_arp_case_count += 1u;
if (netif->flags & NETIF_FLAG_ETHARP) { if (netif->flags & NETIF_FLAG_ETHARP) {
if (pbuf_remove_header(p, SIZEOF_ETH_HDR)) { if (pbuf_remove_header(p, SIZEOF_ETH_HDR)) {
pbuf_free(p); pbuf_free(p);
+34 -153
View File
@@ -23,9 +23,9 @@
#include "task.h" #include "task.h"
#include "semphr.h" #include "semphr.h"
#include "app_runtime.h"
#include "debug_log.h" #include "debug_log.h"
#include "config.h" #include "config.h"
#include "app_runtime.h"
#include <string.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_tx_buffer[CH390_PKT_MAX];
static uint8_t s_garp_sent = 0u; 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 */ /* 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 err_t low_level_output(struct netif *netif, struct pbuf *p);
static struct pbuf *low_level_input(struct netif *netif); static struct pbuf *low_level_input(struct netif *netif);
static void ethernetif_update_link(uint8_t link_status); 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 * @brief Initialize the CH390 hardware
* @param netif Network interface structure * @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; struct ethernetif *ethernetif = netif->state;
const device_config_t *cfg = config_get(); const device_config_t *cfg = config_get();
@@ -107,6 +65,10 @@ static void low_level_init(struct netif *netif)
if (spi_mutex == NULL) if (spi_mutex == NULL)
{ {
spi_mutex = xSemaphoreCreateMutex(); spi_mutex = xSemaphoreCreateMutex();
if (spi_mutex == NULL)
{
return ERR_MEM;
}
} }
/* Initialize CH390 GPIO and SPI */ /* Initialize CH390 GPIO and SPI */
@@ -147,6 +109,8 @@ static void low_level_init(struct netif *netif)
/* Enable CH390 interrupt */ /* Enable CH390 interrupt */
ch390_interrupt_init(); 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; struct pbuf *q;
uint16_t offset; uint16_t offset;
uint16_t copy_len;
uint16_t i;
uint16_t tx_len; uint16_t tx_len;
int tx_rc;
(void)netif; (void)netif;
/* Take SPI mutex */ /* Take SPI mutex */
@@ -199,27 +162,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
} }
tx_len = p->tot_len; tx_len = p->tot_len;
eth_diag_store_local_netif(netif);
g_eth_last_tx_len = tx_len; tx_rc = ch390_runtime_send_packet(s_tx_buffer, 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;
/* Release SPI mutex */ /* Release SPI mutex */
if (spi_mutex != NULL) if (spi_mutex != NULL)
@@ -231,6 +175,14 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
pbuf_add_header(p, ETH_PAD_SIZE); pbuf_add_header(p, ETH_PAD_SIZE);
#endif #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); LINK_STATS_INC(link.xmit);
return ERR_OK; return ERR_OK;
@@ -298,17 +250,10 @@ static struct pbuf *low_level_input(struct netif *netif)
pbuf_free(p); pbuf_free(p);
p = NULL; p = NULL;
LINK_STATS_INC(link.drop); LINK_STATS_INC(link.drop);
g_eth_rx_drop_count += 1u;
} }
else 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); LINK_STATS_INC(link.recv);
g_eth_rx_count += 1u;
} }
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
@@ -324,7 +269,6 @@ static struct pbuf *low_level_input(struct netif *netif)
ch390_drop_packet(ethernetif->rx_len); ch390_drop_packet(ethernetif->rx_len);
LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop); LINK_STATS_INC(link.drop);
g_eth_rx_drop_count += 1u;
} }
/* Release SPI mutex */ /* Release SPI mutex */
@@ -348,35 +292,19 @@ void ethernetif_input(struct netif *netif)
{ {
struct pbuf *p; struct pbuf *p;
err_t input_err; err_t input_err;
uint16_t copy_len;
uint16_t i;
/* Get received packet */ /* Get received packet */
p = low_level_input(netif); p = low_level_input(netif);
if (p != NULL) 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 */ /* Pass to LwIP stack */
input_err = netif->input(p, netif); input_err = netif->input(p, netif);
g_eth_last_input_err = (int32_t)input_err;
if (input_err != ERR_OK) if (input_err != ERR_OK)
{ {
g_eth_input_err_count += 1u;
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p); 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; netif->linkoutput = low_level_output;
/* Initialize hardware */ /* 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; return ERR_OK;
} }
@@ -505,8 +438,6 @@ void ethernetif_diag_poll_status(void)
{ {
struct ch390_runtime_status runtime_status; struct ch390_runtime_status runtime_status;
g_eth_poll_count += 1u;
if (spi_mutex != NULL) if (spi_mutex != NULL)
{ {
xSemaphoreTake(spi_mutex, portMAX_DELAY); xSemaphoreTake(spi_mutex, portMAX_DELAY);
@@ -519,29 +450,6 @@ void ethernetif_diag_poll_status(void)
{ {
xSemaphoreGive(spi_mutex); 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(); UNLOCK_TCPIP_CORE();
s_garp_sent = 1u; s_garp_sent = 1u;
} }
g_eth_link_up_count += 1u;
} }
} }
else else
@@ -570,7 +477,6 @@ static void ethernetif_update_link(uint8_t link_status)
{ {
netif_set_link_down(&ch390_netif); netif_set_link_down(&ch390_netif);
s_garp_sent = 0u; 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 ch390_runtime_status runtime_status;
struct pbuf *p; struct pbuf *p;
err_t input_err; err_t input_err;
uint16_t copy_len; uint8_t rx_budget = 4u;
uint16_t i;
g_eth_poll_count += 1u;
/* Take SPI mutex */ /* Take SPI mutex */
if (spi_mutex != NULL) if (spi_mutex != NULL)
@@ -602,16 +506,6 @@ void ethernetif_poll(void)
xSemaphoreGive(spi_mutex); 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 */ /* Handle link change */
if ((runtime_status.int_status & ISR_LNKCHG) != 0u) if ((runtime_status.int_status & ISR_LNKCHG) != 0u)
{ {
@@ -625,14 +519,8 @@ void ethernetif_poll(void)
LINK_STATS_INC(link.err); 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. */ /* 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); p = low_level_input(&ch390_netif);
if (p == NULL) if (p == NULL)
@@ -640,25 +528,18 @@ void ethernetif_poll(void)
break; 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); input_err = ch390_netif.input(p, &ch390_netif);
g_eth_last_input_err = (int32_t)input_err;
if (input_err != ERR_OK) if (input_err != ERR_OK)
{ {
g_eth_input_err_count += 1u;
pbuf_free(p); pbuf_free(p);
} }
else
{ --rx_budget;
g_eth_input_ok_count += 1u; }
}
if (rx_budget == 0u)
{
taskYIELD();
} }
} }