예제 #1
0
파일: fec.c 프로젝트: alexrayne/freemodbus
err_t
mcf523xfec_output_raw( struct netif *netif, struct pbuf *p )
{
    err_t           res;
    nbuf_t         *pNBuf;
    mcf523xfec_if_t *fecif = netif->state;
    int             i;
    struct pbuf    *q;

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


    /* Test if we can handle such big frames. If not drop it. */
    if( p->tot_len > MCF_FEC_MTU )
    {
#if LINK_STATS
        lwip_stats.link.lenerr++;
#endif
        res = ERR_BUF;
    }
    /* Test if our network buffer scheme can handle a packet of this size. If
     * not drop it and return a memory error. */
    else if( p->tot_len > TX_BUFFER_SIZE )
    {
#ifdef LINK_STATS
        lwip_stats.link.memerr++;
#endif
        res = ERR_MEM;
    }
    /* Allocate a transmit buffer. If no buffer is available drop the frame. */
    else if( ( pNBuf = nbuf_tx_allocate(  ) ) == NULL )
    {
        LWIP_ASSERT( "mcf523xfec_output_raw: pNBuf != NULL\n", pNBuf != NULL );
#ifdef LINK_STATS
        lwip_stats.link.memerr++;
#endif
        res = ERR_MEM;
    }
    else
    {
        q = p;
        i = 0;
        do
        {
            memcpy( &pNBuf->data[i], q->payload, q->len );
            i += q->len;
        }
        while( ( q = q->next ) != NULL );
        pNBuf->length = p->tot_len;

        /* Set Frame ready for transmission. */
        pNBuf->status |= TX_BD_R;
        /* Mark the buffer as not in use so the FEC can take it. */
        nbuf_tx_release( pNBuf );
        /* Indicate that a new transmit buffer has been produced. */
        MCF_FEC_TDAR = 1;
#if LINK_STATS
        lwip_stats.link.xmit++;
#endif
        res = ERR_OK;
    }

    sys_sem_signal( fecif->tx_sem );
#if ETH_PAD_SIZE
    buf_header( p, ETH_PAD_SIZE );
#endif

    return res;
}
예제 #2
0
파일: mac_rtos.c 프로젝트: ifreecarve/Main
/**
 * Output information thru Ethernet
 *
 * @param MAC interface descriptor
 * @param network buffer to send
 * @return error code
 */
err_t
MAC_output_raw( struct netif *netif, struct pbuf *p )
{
    err_t           res;
    nbuf_t          *pNBuf;
    mcf5xxxfec_if_t *fecif = netif->state;
    uint16          i;
    struct pbuf     *q;
    uint32 timeout = FEC_TX_TIMEOUT;

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

    /* Test if we can handle such big frames. If not drop it. */
    if( p->tot_len > MCF_FEC_MTU )
    {
#if LINK_STATS
        lwip_stats.link.lenerr++;
#endif
        res = ERR_BUF;
    }
    /* Test if our network buffer scheme can handle a packet of this size. If
     * not drop it and return a memory error. */
    else if( p->tot_len > TX_BUFFER_SIZE )
    {
#if LINK_STATS
        lwip_stats.link.memerr++;
#endif
        res = ERR_MEM;
    }
    /* Allocate a transmit buffer */
    else 
    {
	    /*FSL:don't block it. More packets produced than consumed*/
	    while( (pNBuf = NBUF_AllocTX() ) == NULL )
	    {
	    	if(!(timeout--))
	    	{
				LWIP_ASSERT( "MAC_output_raw: out of memory\n", FALSE );				
	    	}
	    }
		  /* wait until we have a free Tx buffer */

      q = p;
      i = 0;
      do
      {
          memcpy( &pNBuf->data[i], q->payload, q->len );
          i += q->len;
      }
      while( ( q = q->next ) != NULL );
      pNBuf->length = p->tot_len;

      /* Set Frame ready for transmission. */
      NBUF_ReadyTx( pNBuf );
      /* Mark the buffer as not in use so the FEC can take it. */
      NBUF_ReleaseTX( pNBuf );
      /* Indicate that a new transmit buffer has been produced. */
      FEC_ReadyTx();
#if LINK_STATS
      lwip_stats.link.xmit++;
#endif
      res = ERR_OK;
    }

    sys_sem_signal( fecif->tx_sem );
#if ETH_PAD_SIZE
    buf_header( p, ETH_PAD_SIZE );
#endif

    return res;
}