36 #include "lwip/pbuf.h"
37 #include "lwip/stats.h"
38 #include "lwip/snmp.h"
39 #include "netif/etharp.h"
40 #include "netif/ppp_oe.h"
42 #include "lpc_17xx40xx_emac_config.h"
53 #if LPC_NUM_BUFF_TXDESCS < 2
54 #error LPC_NUM_BUFF_TXDESCS must be at least 2
57 #if LPC_NUM_BUFF_RXDESCS < 3
58 #error LPC_NUM_BUFF_RXDESCS must be at least 3
76 #define tskRECPKT_PRIORITY (DEFAULT_THREAD_PRIO + 4)
77 #define tskTXCLEAN_PRIORITY (DEFAULT_THREAD_PRIO + 5)
94 #define RXINTGROUP (ENET_INT_RXOVERRUN | ENET_INT_RXERROR | ENET_INT_RXDONE)
98 #define TXINTGROUP (ENET_INT_TXUNDERRUN | ENET_INT_TXERROR | ENET_INT_TXDONE)
147 idx = lpc_enetif->rx_fill_desc_index;
151 lpc_enetif->prxd[idx].Packet = (
u32_t) p->payload;
152 lpc_enetif->prxs[idx].StatusInfo = 0xFFFFFFFF;
153 lpc_enetif->prxs[idx].StatusHashCRC = 0xFFFFFFFF;
156 lpc_enetif->rxb[idx] = p;
165 lpc_enetif->rx_free_descs -= 1;
166 lpc_enetif->rx_fill_desc_index = idx;
169 (
"lpc_rxqueue_pbuf: pbuf packet queued: %p (free desc=%d)\n", p,
170 lpc_enetif->rx_free_descs));
191 struct pbuf *p =
NULL;
194 #ifdef LOCK_RX_THREAD
207 LINK_STATS_INC(link.err);
208 LINK_STATS_INC(link.drop);
219 if (lpc_enetif->
rxb[idx] !=
NULL) {
220 pbuf_free(lpc_enetif->
rxb[idx]);
231 #ifdef LOCK_RX_THREAD
250 LINK_STATS_INC(link.chkerr);
253 LINK_STATS_INC(link.lenerr);
258 LINK_STATS_INC(link.drop);
262 p = lpc_enetif->
rxb[idx];
267 (
"lpc_low_level_input: Packet dropped with errors (0x%x)\n",
277 p = lpc_enetif->
rxb[idx];
278 p->len = (
u16_t) length;
291 LINK_STATS_INC(link.drop);
294 (
"lpc_low_level_input: Packet dropped since it could not allocate Rx Buffer\n"));
301 (
"lpc_low_level_input: Packet received: %p, size %d (index=%d)\n",
305 p->tot_len = (
u16_t) length;
306 LINK_STATS_INC(link.recv);
314 #ifdef LOCK_RX_THREAD
325 #if defined(CHIP_LPC175X_6X)
327 if ((((
u32_t) addr >= 0x10000000) && ((
u32_t) addr < 0x10008000))
328 || (((
u32_t) addr >= 0x1FFF0000) && ((
u32_t) addr < 0x1FFF2000))
329 || (((
u32_t) addr >= 0x2007C000) && ((
u32_t) addr < 0x20084000))
336 if ((((
u32_t) addr >= 0x20000000) && ((
u32_t) addr < 0x20008000)) ||
337 (((
u32_t) addr >= 0x80000000) && ((
u32_t) addr < 0xF0000000))) {
374 (
"lpc_tx_reclaim_st: Freeing packet %p (index %d)\n",
403 #if LPC_TX_PBUF_BOUNCE_EN == 1
408 u32_t dn, notdmasafe = 0;
413 dn = (
u32_t) pbuf_clen(p);
418 for (q = p; q !=
NULL; q = q->next) {
422 #if LPC_TX_PBUF_BOUNCE_EN == 1
428 np = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
431 (
"lpc_low_level_output: could not allocate TX pbuf\n"));
436 LWIP_ASSERT(
"lpc_low_level_output: New transmit pbuf is chained",
437 (pbuf_clen(np) == 1));
440 dst = (
u8_t *) np->payload;
441 for (q = p; q !=
NULL; q = q->next) {
443 MEMCPY(dst, (
u8_t *) q->payload, q->len);
446 np->len = p->tot_len;
449 (
"lpc_low_level_output: Switched to DMA safe buffer, old=%p, new=%p\n",
459 LWIP_ASSERT(
"lpc_low_level_output: Not a DMA safe pbuf",
498 lpc_enetif->
txb[idx] = p;
507 (
"lpc_low_level_output: pbuf packet(%p) sent, chain#=%d,"
508 " size = %d (index=%d)\n", q->payload, dn, q->len, idx));
517 LINK_STATS_INC(link.xmit);
558 LINK_STATS_INC(link.err);
559 LINK_STATS_INC(link.drop);
571 if (lpc_enetif->
txb[idx] !=
NULL) {
572 pbuf_free(lpc_enetif->
txb[idx]);
603 #if defined(USE_RMII)
625 #if IP_SOF_BROADCAST_RECV
647 if (netif->flags & NETIF_FLAG_LINK_UP) {
648 return etharp_output(netif, q, ipaddr);
673 (
"lpc_rx_queue: could not allocate RX pbuf (free desc=%d)\n",
679 LWIP_ASSERT(
"lpc_rx_queue: pbuf is not contiguous (chained)",
695 struct eth_hdr *ethhdr;
708 switch (htons(ethhdr->type)) {
712 case ETHTYPE_PPPOEDISC:
716 if (netif->input(p, netif) != ERR_OK) {
717 LWIP_DEBUGF(NETIF_DEBUG, (
"lpc_enetif_input: IP input error\n"));
758 NVIC_DisableIRQ(ETHERNET_IRQn);
760 signed portBASE_TYPE xRecTaskWoken = pdFALSE, XTXTaskWoken = pdFALSE;
773 xSemaphoreGiveFromISR(
lpc_enetdata.rx_sem, &xRecTaskWoken);
780 xSemaphoreGiveFromISR(
lpc_enetdata.tx_clean_sem, &XTXTaskWoken);
787 portEND_SWITCHING_ISR(xRecTaskWoken || XTXTaskWoken);
818 LWIP_ASSERT(
"netif != NULL", (netif !=
NULL));
824 netif->hwaddr_len = ETHARP_HWADDR_LEN;
830 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_UP |
840 #if LWIP_NETIF_HOSTNAME
842 netif->hostname =
"lwiplpc";
845 netif->name[0] =
'e';
846 netif->name[1] =
'n';
855 LWIP_ASSERT(
"xtx_count_sem creation error",
859 LWIP_ASSERT(
"tx_lock_mutex creation error", (err == ERR_OK));
862 LWIP_ASSERT(
"rx_lock_mutex creation error", (err == ERR_OK));
866 LWIP_ASSERT(
"rx_sem creation error", (err == ERR_OK));
867 sys_thread_new(
"receive_thread", vPacketReceiveTask, netif->state,
872 LWIP_ASSERT(
"tx_clean_sem creation error", (err == ERR_OK));
873 sys_thread_new(
"txclean_thread", vTransmitCleanupTask, netif->state,