Example #1
0
/**
 * 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;

  if(EMAC_GetBufferSts(EMAC_RX_BUFF) == EMAC_BUFF_EMPTY)
    return NULL;
    
  /* Obtain the size of the packet and put it into the "len"
     variable. */
  len = EMAC_GetRxFrameSize();

#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. */
    uint8_t *ptr = (uint8_t *)EMAC_GetRxBuffer();
    for(q = p; q != NULL; q = q->next) {
      MEMCPY(q->payload, ptr, q->len);
      ptr += q->len;
    }
    EMAC_UpdateRxConsumeIndex();

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

    LINK_STATS_INC(link.recv);
    
  } else {
//    drop packet();
    LINK_STATS_INC(link.memerr);
    LINK_STATS_INC(link.drop);
  }
  
  return p;
}
Example #2
0
/*********************************************************************//**
 * @brief       
 * @param[in]   
 * @return      
 **********************************************************************/
unsigned int Rdy4Tx(void)
{
    return ((EMAC_GetBufferSts(EMAC_TX_BUFF) == EMAC_BUFF_EMPTY) ? 1:0);
}