kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/ethernet_low_level_output' into 'master'
ethernet: fix some bugs and complete some optimization See merge request idf/esp-idf!3235pull/2429/head
commit
c305bd09dc
|
@ -111,5 +111,4 @@ void emac_mac_init(void)
|
||||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX);
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACDUPLEX);
|
||||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII);
|
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACMII);
|
||||||
REG_CLR_BIT(EMAC_GMACCONFIG_REG, EMAC_EMACFESPEED);
|
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)
|
static void emac_setup_tx_desc(struct dma_extended_desc *tx_desc, uint32_t size)
|
||||||
{
|
{
|
||||||
tx_desc->basic.desc1 = size & 0xfff;
|
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 |
|
tx_desc->basic.desc0 = EMAC_DESC_TX_OWN | EMAC_DESC_INT_COMPL |
|
||||||
EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT |
|
EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT |
|
||||||
EMAC_DESC_SECOND_ADDR_CHAIN;
|
EMAC_DESC_SECOND_ADDR_CHAIN;
|
||||||
|
@ -292,7 +289,7 @@ static void emac_set_user_config_data(eth_config_t *config)
|
||||||
#if DMA_RX_BUF_NUM > 9
|
#if DMA_RX_BUF_NUM > 9
|
||||||
emac_config.emac_flow_ctrl_enable = config->flow_ctrl_enable;
|
emac_config.emac_flow_ctrl_enable = config->flow_ctrl_enable;
|
||||||
#else
|
#else
|
||||||
if(config->flow_ctrl_enable == true) {
|
if (config->flow_ctrl_enable == true) {
|
||||||
ESP_LOGE(TAG, "Can only configure flow_ctrl_enable==true if DMA_RX_BUF_NUM in menuconfig is >9. Disabling flow control.");
|
ESP_LOGE(TAG, "Can only configure flow_ctrl_enable==true if DMA_RX_BUF_NUM in menuconfig is >9. Disabling flow control.");
|
||||||
}
|
}
|
||||||
emac_config.emac_flow_ctrl_enable = false;
|
emac_config.emac_flow_ctrl_enable = false;
|
||||||
|
@ -630,10 +627,10 @@ static void IRAM_ATTR emac_process_intr(void *arg)
|
||||||
|
|
||||||
static void emac_set_macaddr_reg(void)
|
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_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[2] << 24) |
|
REG_WRITE(EMAC_ADDR0LOW_REG, (emac_config.macaddr[3] << 24) |
|
||||||
(emac_config.macaddr[3] << 16) | (emac_config.macaddr[4] << 8) |
|
(emac_config.macaddr[2] << 16) | (emac_config.macaddr[1] << 8) |
|
||||||
(emac_config.macaddr[5]));
|
(emac_config.macaddr[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emac_check_phy_init(void)
|
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);
|
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.
|
* @brief Set mac of ethernet interface.
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
@ -17,21 +17,21 @@
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
* OF SUCH DAMAGE.
|
* OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This file is part of the lwIP TCP/IP stack.
|
* This file is part of the lwIP TCP/IP stack.
|
||||||
*
|
*
|
||||||
* Author: Adam Dunkels <adam@sics.se>
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ethernet_low_level_init(struct netif *netif)
|
ethernet_low_level_init(struct netif *netif)
|
||||||
{
|
{
|
||||||
/* set MAC hardware address length */
|
/* set MAC hardware address length */
|
||||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||||
|
|
||||||
|
@ -103,40 +103,35 @@ ethernet_low_level_init(struct netif *netif)
|
||||||
* to become availale since the stack doesn't retry to send a packet
|
* to become availale since the stack doesn't retry to send a packet
|
||||||
* dropped because of memory failure (except for the TCP timers).
|
* 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)
|
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);
|
esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif);
|
||||||
|
err_t ret;
|
||||||
|
|
||||||
if (eth_if != ESP_IF_ETH) {
|
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));
|
LWIP_DEBUGF(NETIF_DEBUG, ("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len));
|
||||||
|
|
||||||
return ERR_IF;
|
return ERR_IF;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ESP_LWIP
|
if (q->next == NULL) {
|
||||||
q = p;
|
ret = esp_eth_tx(q->payload, q->len);
|
||||||
u16_t pbuf_x_len = 0;
|
} else {
|
||||||
pbuf_x_len = q->len;
|
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
|
||||||
if(q->next !=NULL) {
|
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
|
||||||
//char cnt = 0;
|
if (q != NULL) {
|
||||||
struct pbuf *tmp = q->next;
|
q->l2_owner = NULL;
|
||||||
while(tmp != NULL) {
|
pbuf_copy(q, p);
|
||||||
memcpy( (u8_t *)( (u8_t *)(q->payload) + pbuf_x_len), (u8_t *)tmp->payload , tmp->len );
|
} else {
|
||||||
pbuf_x_len += tmp->len;
|
return ERR_MEM;
|
||||||
//cnt++;
|
|
||||||
tmp = tmp->next;
|
|
||||||
}
|
}
|
||||||
|
ret = esp_eth_tx(q->payload, q->len);
|
||||||
|
pbuf_free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
return esp_eth_tx(q->payload, pbuf_x_len);
|
return ret;
|
||||||
#else
|
|
||||||
for(q = p; q != NULL; q = q->next) {
|
|
||||||
return esp_emac_tx(q->payload, q->len);
|
|
||||||
}
|
|
||||||
return ERR_OK;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,10 +147,10 @@ ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
||||||
*
|
*
|
||||||
* @note When CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE is enabled, a copy of buffer
|
* @note When CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE is enabled, a copy of buffer
|
||||||
* will be made for high layer (LWIP) and ethernet is responsible for
|
* will be made for high layer (LWIP) and ethernet is responsible for
|
||||||
* freeing the buffer. Otherwise, high layer and ethernet share the
|
* freeing the buffer. Otherwise, high layer and ethernet share the
|
||||||
* same buffer and high layer is responsible for freeing the buffer.
|
* 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)
|
ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
|
|
Ładowanie…
Reference in New Issue