//***************************************************************************** // // Low-Level receive routine. Should allocate a pbuf and transfer the bytes // of the incoming packet from the interface into the pbuf. // //***************************************************************************** struct pbuf * luminaryif_rx(rt_device_t dev) { struct pbuf *p, *q; u16_t len; unsigned long ulTemp; int i; unsigned long *ptr; if(!EthernetPacketAvail(ETH_BASE)) { // // Enable Ethernet RX Interrupt. // EthernetIntEnable(ETH_BASE, ETH_INT_RX); return(NULL); } // // Obtain the size of the packet and put it into the "len" variable. // Note: The length returned in the FIFO length position includes the // two bytes for the length + the 4 bytes for the FCS. // ulTemp = HWREG(ETH_BASE + MAC_O_DATA); len = ulTemp & 0xFFFF; // // We allocate a pbuf chain of pbufs from the pool. // p = pbuf_alloc(PBUF_LINK, len, PBUF_RAM); if(p != NULL) { // // Place the first word into the first pbuf location. // *(unsigned long *)p->payload = ulTemp; p->payload = (char *)(p->payload) + 4; p->len -= 4; // // Process all but the last buffer in the pbuf chain. // q = p; while(q != NULL) { // // Setup a byte pointer into the payload section of the pbuf. // ptr = q->payload; // // Read data from FIFO into the current pbuf // (assume pbuf length is modulo 4) // for(i = 0; i < q->len; i += 4) { *ptr++ = HWREG(ETH_BASE + MAC_O_DATA); } // // Link in the next pbuf in the chain. // q = q->next; } // // Restore the first pbuf parameters to their original values. // p->payload = (char *)(p->payload) - 4; p->len += 4; #if LINK_STATS lwip_stats.link.recv++; #endif } else { // // Just read all of the remaining data from the FIFO and dump it. // for(i = 4; i < len; i+=4) { ulTemp = HWREG(ETH_BASE + MAC_O_DATA); } #if LINK_STATS lwip_stats.link.memerr++; lwip_stats.link.drop++; #endif } return(p); }
unsigned int ethernet_data(void) { return EthernetPacketAvail(ETH_BASE); }