/** * Should allocate a pbuf and transfer the bytes of the incoming * packet from the interface into the pbuf. * * @param netif the lwip network interface structure for this ethernetif * @return a pbuf filled with the received packet (including MAC header) * NULL on memory error */ static struct pbuf * low_level_input(struct netif *netif) { // struct ethernetif *ethernetif = netif->state; struct pbuf *p, *q; u16_t len; /* Obtain the size of the packet and put it into the "len" variable. */ len = StartReadFrame(); #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 /* We iterate over the pbuf chain until we have read the entire * packet into the pbuf. */ for(q = p; q != NULL; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The * available data in the pbuf is given by the q->len * variable. */ //read data into(q->payload, q->len); CopyFromFrame_EMAC(q->payload, q->len); } // acknowledge that packet has been read(); EndReadFrame(); #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif LINK_STATS_INC(link.recv); } else { // drop packet(); EndReadFrame(); // Drop packet LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); } return p; }
int CCameraOutput::ReadFrame(void* dest, int dest_size) { //default result is 0 - no data available int res = 0; //get buffer const void* buffer; int buffer_len; if(BeginReadFrame(buffer,buffer_len)) { if(dest_size >= buffer_len) { //got space - copy it in and return size memcpy(dest,buffer,buffer_len); res = buffer_len; } else { //not enough space - return failure res = -1; } EndReadFrame(); } return res; }
unsigned int uiGetEMACRxData( unsigned char *ucBuffer ) { unsigned int uiLen = 0; if( MAC_RXPRODUCEINDEX != MAC_RXCONSUMEINDEX ) { uiLen = StartReadFrame(); CopyFromFrame_EMAC( ucBuffer, uiLen ); EndReadFrame(); } return uiLen; }
unsigned int uiGetEMACRxData( unsigned char *ucBuffer ) { unsigned int uiLen = 0; if( RxProduceIndex != RxConsumeIndex ) { uiLen = StartReadFrame(); CopyFromFrame_EMAC( ucBuffer, uiLen ); EndReadFrame(); } return uiLen; }