4 /* Service MAC IRQ here */
6 /* Allocate pbuf from pool (avoid using heap in interrupts) */
7 struct pbuf* p = pbuf_alloc(PBUF_RAW, eth_data_count, PBUF_POOL);
10 /* Copy ethernet frame into pbuf */
11 pbuf_take(p, eth_data, eth_data_count);
13 /* Put in a queue which is processed in main loop */
14 if(!queue_try_put(&queue, p)) {
15 /* queue is full -> packet loss */
22 netif_output(struct netif *netif, struct pbuf *p)
24 LINK_STATS_INC(link.xmit);
26 /* Update SNMP stats (only if you use SNMP) */
27 MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
28 int unicast = ((p->payload[0] & 0x01) == 0);
30 MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
32 MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts);
36 pbuf_copy_partial(p, mac_send_buffer, p->tot_len, 0);
37 /* Start MAC transmit here */
44 netif_status_callback(struct netif *netif)
46 printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
50 netif_init(struct netif *netif)
52 netif->linkoutput = netif_output;
53 netif->output = etharp_output;
54 netif->output_ip6 = ethip6_output;
55 netif->mtu = ETHERNET_MTU;
56 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;
57 MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, 100000000);
59 SMEMCPY(netif->hwaddr, your_mac_address_goes_here, sizeof(netif->hwaddr));
60 netif->hwaddr_len = sizeof(netif->hwaddr);
72 netif_add(&netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, netif_init, netif_input);
75 netif_create_ip6_linklocal_address(&netif, 1);
76 netif.ip6_autoconfig_enabled = 1;
77 netif_set_status_callback(&netif, netif_status_callback);
78 netif_set_default(&netif);
81 /* Start DHCP and HTTPD */
86 /* Check link state, e.g. via MDIO communication with PHY */
87 if(link_state_changed()) {
89 netif_set_link_up(&netif);
91 netif_set_link_down(&netif);
95 /* Check for received frames, feed them to lwIP */
97 struct pbuf* p = queue_try_get(&queue);
101 LINK_STATS_INC(link.recv);
103 /* Update SNMP stats (only if you use SNMP) */
104 MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
105 int unicast = ((p->payload[0] & 0x01) == 0);
107 MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
109 MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
112 if(netif.input(p, &netif) != ERR_OK) {
117 /* Cyclic lwIP timers check */
118 sys_check_timeouts();
120 /* your application goes here */