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_18xx43xx_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
61 #ifndef LPC_CHECK_SLOWMEM
62 #error LPC_CHECK_SLOWMEM must be 0 or 1
80 #define tskTXCLEAN_PRIORITY (TCPIP_THREAD_PRIO - 1)
81 #define tskRECPKT_PRIORITY (TCPIP_THREAD_PRIO - 1)
122 #if LPC_CHECK_SLOWMEM == 1
123 struct lpc_slowmem_array_t {
146 lpc_netifdata->
rxpbufs[idx] = p;
163 (
"lpc_rxqueue_pbuf: Queueing packet %p at index %d, free %d\n",
185 memset(lpc_netifdata->
prdesc, 0,
sizeof(lpc_netifdata->
prdesc));
192 &lpc_netifdata->
prdesc[idx + 1];
194 lpc_netifdata->
prdesc[LPC_NUM_BUFF_RXDESCS - 1].
CTRL =
196 lpc_netifdata->
prdesc[LPC_NUM_BUFF_RXDESCS - 1].
B2ADD =
204 (
"lpc_rx_setup: Warning, not enough memory for RX pbufs\n"));
217 #ifdef LOCK_RX_THREAD
228 #ifdef LOCK_RX_THREAD
241 #ifdef LOCK_RX_THREAD
250 p = lpc_netifdata->
rxpbufs[ridx];
257 LINK_STATS_INC(link.drop);
261 LINK_STATS_INC(link.err);
267 LINK_STATS_INC(link.lenerr);
273 LINK_STATS_INC(link.chkerr);
279 LINK_STATS_INC(link.err);
286 LINK_STATS_INC(link.err);
305 (
"lpc_low_level_input: RX error condition status 0x%08x\n",
315 LINK_STATS_INC(link.recv);
318 (
"lpc_low_level_input: Packet received, %d bytes, "
319 "status 0x%08x\n", p->len, status));
325 #ifdef LOCK_RX_THREAD
341 memset((
void *) &lpc_netifdata->
ptdesc[0], 0,
sizeof(lpc_netifdata->
ptdesc));
354 lpc_netifdata->
ptdesc[LPC_NUM_BUFF_TXDESCS - 1].
B2ADD =
369 struct pbuf *p = sendp;
371 #if LPC_CHECK_SLOWMEM == 1
379 for (q = p; ((q !=
NULL) && (pcopy == 0)); q = q->next) {
381 for (idx = 0; idx <
sizeof(slmem);
382 idx +=
sizeof(
struct lpc_slowmem_array_t)) {
383 if ((q->payload >= (
void *) slmem[fidx].start) &&
384 (q->payload <= (
void *) slmem[fidx].end)) {
400 dst = (
u8_t *) wp->payload;
402 for (q = p; q !=
NULL; q = q->next) {
403 MEMCPY(dst, (
u8_t *) q->payload, q->len);
405 wp->tot_len += q->len;
407 wp->len = wp->tot_len;
418 dn = (
u32_t) pbuf_clen(p);
453 #if LPC_CHECK_SLOWMEM == 1
473 lpc_netifdata->
txpbufs[idx] = sendp;
489 (
"lpc_low_level_output: pbuf packet %p sent, chain %d,"
490 " size %d, index %d, free %d\n", p, dn, p->len, idx,
505 LINK_STATS_INC(link.xmit);
527 if (netif->flags & NETIF_FLAG_LINK_UP) {
528 return etharp_output(netif, q, ipaddr);
588 #if IP_SOF_BROADCAST_RECV
595 #if defined(USE_RMII)
758 (
"lpc_rx_queue: could not allocate RX pbuf index %d, "
766 LWIP_ASSERT(
"lpc_rx_queue: pbuf is not contiguous (chained)",
782 struct eth_hdr *ethhdr;
795 switch (htons(ethhdr->type)) {
799 case ETHTYPE_PPPOEDISC:
803 if (netif->input(p, netif) != ERR_OK) {
804 LWIP_DEBUGF(NETIF_DEBUG,
805 (
"lpc_enetif_input: IP input error\n"));
840 (
"lpc_tx_reclaim: Reclaiming sent packet %p, index %d\n",
841 lpc_netifdata->
txpbufs[ridx], ridx));
846 (
"lpc_tx_reclaim: TX error condition status 0x%x\n", status));
847 LINK_STATS_INC(link.err);
852 LINK_STATS_INC(link.drop);
867 if (lpc_netifdata->
txpbufs[ridx]) {
868 pbuf_free(lpc_netifdata->
txpbufs[ridx]);
893 return ((
struct lpc_enetdata *) netif->state)->tx_free_descs;
906 NVIC_DisableIRQ((IRQn_Type) ETHERNET_IRQn);
908 signed portBASE_TYPE xRecTaskWoken = pdFALSE, XTXTaskWoken = pdFALSE;
932 portEND_SWITCHING_ISR(xRecTaskWoken || XTXTaskWoken);
964 LWIP_ASSERT(
"netif != NULL", (netif !=
NULL));
970 netif->hwaddr_len = ETHARP_HWADDR_LEN;
976 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_UP |
986 #if LWIP_NETIF_HOSTNAME
988 netif->hostname =
"lwiplpc";
991 netif->name[0] =
'e';
992 netif->name[1] =
'n';
1001 LWIP_ASSERT(
"xTXDCountSem creation error",
1005 LWIP_ASSERT(
"TXLockMutex creation error", (err == ERR_OK));
1009 LWIP_ASSERT(
"RxSem creation error", (err == ERR_OK));
1010 sys_thread_new(
"receive_thread", vPacketReceiveTask, netif->state,
1015 LWIP_ASSERT(
"TxCleanSem creation error", (err == ERR_OK));
1016 sys_thread_new(
"txclean_thread", vTransmitCleanupTask, netif->state,