3 /* Service MAC IRQ here */
5 /* Allocate pbuf from pool (avoid using heap in interrupts) */
6 struct pbuf
* p
= pbuf_alloc(PBUF_RAW
, eth_data_count
, PBUF_POOL
);
9 /* Copy ethernet frame into pbuf */
10 pbuf_take(p
, eth_data
, eth_data_count
);
12 /* Put in a queue which is processed in main loop */
13 if(!queue_try_put(&queue
, p
)) {
14 /* queue is full -> packet loss */
20 static err_t
netif_output(struct netif
*netif
, struct pbuf
*p
)
22 LINK_STATS_INC(link
.xmit
);
24 /* Update SNMP stats (only if you use SNMP) */
25 MIB2_STATS_NETIF_ADD(netif
, ifoutoctets
, p
->tot_len
);
26 int unicast
= ((p
->payload
[0] & 0x01) == 0);
28 MIB2_STATS_NETIF_INC(netif
, ifoutucastpkts
);
30 MIB2_STATS_NETIF_INC(netif
, ifoutnucastpkts
);
34 pbuf_copy_partial(p
, mac_send_buffer
, p
->tot_len
, 0);
35 /* Start MAC transmit here */
41 static void netif_status_callback(struct netif
*netif
)
43 printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif
)));
46 static err_t
netif_init(struct netif
*netif
)
48 netif
->linkoutput
= netif_output
;
49 netif
->output
= etharp_output
;
50 netif
->output_ip6
= ethip6_output
;
51 netif
->mtu
= ETHERNET_MTU
;
52 netif
->flags
= NETIF_FLAG_BROADCAST
| NETIF_FLAG_ETHARP
| NETIF_FLAG_ETHERNET
| NETIF_FLAG_IGMP
| NETIF_FLAG_MLD6
;
53 MIB2_INIT_NETIF(netif
, snmp_ifType_ethernet_csmacd
, 100000000);
55 SMEMCPY(netif
->hwaddr
, your_mac_address_goes_here
, sizeof(netif
->hwaddr
));
56 netif
->hwaddr_len
= sizeof(netif
->hwaddr
);
67 netif_add(&netif
, IP4_ADDR_ANY
, IP4_ADDR_ANY
, IP4_ADDR_ANY
, NULL
, netif_init
, netif_input
);
70 netif_create_ip6_linklocal_address(&netif
, 1);
71 netif
.ip6_autoconfig_enabled
= 1;
72 netif_set_status_callback(&netif
, netif_status_callback
);
73 netif_set_default(&netif
);
76 /* Start DHCP and HTTPD */
81 /* Check link state, e.g. via MDIO communication with PHY */
82 if(link_state_changed()) {
84 netif_set_link_up(&netif
);
86 netif_set_link_down(&netif
);
90 /* Check for received frames, feed them to lwIP */
92 struct pbuf
* p
= queue_try_get(&queue
);
96 LINK_STATS_INC(link
.recv
);
98 /* Update SNMP stats (only if you use SNMP) */
99 MIB2_STATS_NETIF_ADD(netif
, ifinoctets
, p
->tot_len
);
100 int unicast
= ((p
->payload
[0] & 0x01) == 0);
102 MIB2_STATS_NETIF_INC(netif
, ifinucastpkts
);
104 MIB2_STATS_NETIF_INC(netif
, ifinnucastpkts
);
107 if(netif
.input(p
, &netif
) != ERR_OK
) {
112 /* Cyclic lwIP timers check */
113 sys_check_timeouts();
115 /* your application goes here */