mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ethernet: fix some bugs in ethernet driver
1. create a new pbuf to squash linked pbuf 2. optimize emac driver by adding ESP_IRAM_ATTR 3. remove duplicated function declare in esp_eth.h 4. remove duplicated code in emac_setup_tx_desc 5. disable Promiscuous mode
This commit is contained in:
parent
61af7f3903
commit
3063a62e3e
@ -111,5 +111,4 @@ void emac_mac_init(void)
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX);
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII);
|
||||
REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED);
|
||||
REG_SET_BIT(EMAC_GMACFF_REG, EMAC_PMODE);
|
||||
}
|
||||
|
@ -104,9 +104,6 @@ esp_err_t esp_eth_set_mac(const uint8_t mac[6])
|
||||
static void emac_setup_tx_desc(struct dma_extended_desc *tx_desc, uint32_t size)
|
||||
{
|
||||
tx_desc->basic.desc1 = size & 0xfff;
|
||||
tx_desc->basic.desc0 = EMAC_DESC_INT_COMPL | EMAC_DESC_LAST_SEGMENT |
|
||||
EMAC_DESC_FIRST_SEGMENT |
|
||||
EMAC_DESC_SECOND_ADDR_CHAIN;
|
||||
tx_desc->basic.desc0 = EMAC_DESC_TX_OWN | EMAC_DESC_INT_COMPL |
|
||||
EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT |
|
||||
EMAC_DESC_SECOND_ADDR_CHAIN;
|
||||
@ -630,10 +627,10 @@ static void IRAM_ATTR emac_process_intr(void *arg)
|
||||
|
||||
static void emac_set_macaddr_reg(void)
|
||||
{
|
||||
REG_SET_FIELD(EMAC_ADDR0HIGH_REG, EMAC_ADDRESS0_HI, (emac_config.macaddr[0] << 8) | (emac_config.macaddr[1]));
|
||||
REG_WRITE(EMAC_ADDR0LOW_REG, (emac_config.macaddr[2] << 24) |
|
||||
(emac_config.macaddr[3] << 16) | (emac_config.macaddr[4] << 8) |
|
||||
(emac_config.macaddr[5]));
|
||||
REG_SET_FIELD(EMAC_ADDR0HIGH_REG, EMAC_ADDRESS0_HI, (emac_config.macaddr[5] << 8) | (emac_config.macaddr[4]));
|
||||
REG_WRITE(EMAC_ADDR0LOW_REG, (emac_config.macaddr[3] << 24) |
|
||||
(emac_config.macaddr[2] << 16) | (emac_config.macaddr[1] << 8) |
|
||||
(emac_config.macaddr[0]));
|
||||
}
|
||||
|
||||
static void emac_check_phy_init(void)
|
||||
|
@ -260,14 +260,6 @@ static inline esp_err_t esp_eth_smi_wait_set(uint32_t reg_num, uint16_t value_ma
|
||||
*/
|
||||
void esp_eth_free_rx_buf(void *buf);
|
||||
|
||||
/**
|
||||
* @brief Get mac of ethernet interface.
|
||||
*
|
||||
* @param[out] mac: store mac of the interface.
|
||||
*
|
||||
*/
|
||||
void esp_eth_get_mac(uint8_t mac[6]);
|
||||
|
||||
/**
|
||||
* @brief Set mac of ethernet interface.
|
||||
*
|
||||
|
@ -103,11 +103,12 @@ ethernet_low_level_init(struct netif *netif)
|
||||
* to become availale since the stack doesn't retry to send a packet
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
static err_t
|
||||
static err_t ESP_IRAM_ATTR
|
||||
ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct pbuf *q;
|
||||
struct pbuf *q = p;
|
||||
esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif);
|
||||
err_t ret;
|
||||
|
||||
if (eth_if != ESP_IF_ETH) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len));
|
||||
@ -115,28 +116,22 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
||||
return ERR_IF;
|
||||
}
|
||||
|
||||
#if ESP_LWIP
|
||||
q = p;
|
||||
u16_t pbuf_x_len = 0;
|
||||
pbuf_x_len = q->len;
|
||||
if(q->next !=NULL) {
|
||||
//char cnt = 0;
|
||||
struct pbuf *tmp = q->next;
|
||||
while(tmp != NULL) {
|
||||
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
|
||||
pbuf_x_len += tmp->len;
|
||||
//cnt++;
|
||||
tmp = tmp->next;
|
||||
if (q->next == NULL) {
|
||||
ret = esp_eth_tx(q->payload, q->len);
|
||||
} else {
|
||||
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
|
||||
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
|
||||
if (q != NULL) {
|
||||
q->l2_owner = NULL;
|
||||
pbuf_copy(q, p);
|
||||
} else {
|
||||
return ERR_MEM;
|
||||
}
|
||||
ret = esp_eth_tx(q->payload, q->len);
|
||||
pbuf_free(q);
|
||||
}
|
||||
|
||||
return esp_eth_tx(q->payload, pbuf_x_len);
|
||||
#else
|
||||
for(q = p; q != NULL; q = q->next) {
|
||||
return esp_emac_tx(q->payload, q->len);
|
||||
}
|
||||
return ERR_OK;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +150,7 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
||||
* freeing the buffer. Otherwise, high layer and ethernet share the
|
||||
* same buffer and high layer is responsible for freeing the buffer.
|
||||
*/
|
||||
void
|
||||
void ESP_IRAM_ATTR
|
||||
ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
|
||||
{
|
||||
struct pbuf *p;
|
||||
|
Loading…
x
Reference in New Issue
Block a user