/**
 * 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 pbuf *p, *q;
  u16_t len;
  //uint32_t l=0,i =0;
  //FrameTypeDef frame;
  //u8_t *buffer;
  
  p = NULL;
  
/* Obtain the size of the packet and put it into the "len"
     variable. */
  len = enc28j60BeginPacketReceive();
	if(!len) {
#ifdef DEBUG
	debug_printf("ETH DEBUG: low_level_input %d\n\r", len);
#endif

	return NULL;
	}
#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);
			enc28j60PacketReceive(q->payload, q->len);
    }
			
    //acknowledge that packet has been read();
		enc28j60EndPacketReceive();

#if ETH_PAD_SIZE
    pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif

   // LINK_STATS_INC(link.recv);
  } else {
    //drop packet();
		enc28j60EndPacketReceive();
    //LINK_STATS_INC(link.memerr);
    //LINK_STATS_INC(link.drop);
  }
  
  return p;
}
Пример #2
0
uint16_t nic_poll(void)
{
	uint16_t packetLength;
	
	packetLength = enc28j60BeginPacketReceive();

	// if there's no packet or an error - exit without ending the operation
	if( !packetLength )
	  return 0;

	// drop anything too big for the buffer
	if( packetLength > UIP_BUFSIZE )
	{
#ifdef DEBUG_SERIAL
          printf("Recieved big packet %i bytes, dropping \r\n",(int)uip_len);
#endif
	  enc28j60EndPacketReceive();
    return 0;
	}
	
	// copy the packet data into the uIP packet buffer
	enc28j60PacketReceive( uip_buf, packetLength );
	enc28j60EndPacketReceive();

#ifdef DEBUG_SERIAL
          printf("Recieved & transferred to uip, packet %i bytes\r\n",(int)uip_len);
#endif

	return packetLength;
}