/* * uIP receive function wrapping the EMAC function. */ static size_t network_device_read(void) { MACReceiveDescriptor rd; size_t size; if (macWaitReceiveDescriptor(ÐD1, &rd, TIME_IMMEDIATE) != RDY_OK) return 0; size = rd.size; macReadReceiveDescriptor(&rd, uip_buf, size); macReleaseReceiveDescriptor(&rd); return size; }
/* * Receives a frame. */ static struct pbuf *low_level_input(struct netif *netif) { MACReceiveDescriptor rd; struct pbuf *p, *q; u16_t len; (void)netif; if (macWaitReceiveDescriptor(ÐD1, &rd, TIME_IMMEDIATE) == MSG_OK) { len = (u16_t)rd.size; #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); if (p != NULL) { #if ETH_PAD_SIZE pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif /* Iterates through the pbuf chain. */ for(q = p; q != NULL; q = q->next) macReadReceiveDescriptor(&rd, (uint8_t *)q->payload, (size_t)q->len); macReleaseReceiveDescriptor(&rd); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { macReleaseReceiveDescriptor(&rd); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } return p; } return NULL; }