예제 #1
0
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
  static xSemaphoreHandle xTxSemaphore = NULL;
  struct pbuf *q;
  uint32_t l = 0;
  u8 *buffer ;
  
  if (xTxSemaphore == NULL)
  {
    vSemaphoreCreateBinary (xTxSemaphore);
  } 
   
  if (xSemaphoreTake(xTxSemaphore, netifGUARD_BLOCK_TIME))
  {
    buffer =  (u8 *)(DMATxDescToSet->Buffer1Addr);
    for(q = p; q != NULL; q = q->next) 
    {
      memcpy((u8_t*)&buffer[l], q->payload, q->len);
      l = l + q->len;
    }
    ETH_Prepare_Transmit_Descriptors(l);
    xSemaphoreGive(xTxSemaphore);
  }

  return ERR_OK;
}
예제 #2
0
/* transmit packet. */
rt_err_t rt_stm32_eth_tx( rt_device_t dev, struct pbuf* p)
{
	rt_err_t ret;
	struct pbuf *q;
	uint32_t l = 0;
	u8 *buffer ;
	
	if (( ret = rt_sem_take(&tx_wait, netifGUARD_BLOCK_TIME) ) == RT_EOK)
	{
		buffer =  (u8 *)(DMATxDescToSet->Buffer1Addr);
		for(q = p; q != NULL; q = q->next) 
		{
			//show_frame(q);
			rt_memcpy((u8_t*)&buffer[l], q->payload, q->len);
			l = l + q->len;
		}
		if( ETH_Prepare_Transmit_Descriptors(l) == ETH_ERROR )
			rt_kprintf("Tx Error\n");
		//rt_sem_release(xTxSemaphore);
		rt_sem_release(&tx_wait);
		//rt_kprintf("Tx packet, len = %d\n", l);
	}
	else
	{
		rt_kprintf("Tx Timeout\n");
		return ret;
	}

	/* Return SUCCESS */
	return RT_EOK;
}
예제 #3
0
/*************************************************************************
 * Function Name: eth_packet_write
 * Parameters:
 * Return:
 *
 * Description: write packet to MAC/DMA Controller
 *
 *************************************************************************/
int eth_packet_write( const unsigned char* p_from_user_buffer, int size)
{
   uint32_t l = 0;
	u8 *buffer ;
	
	//
   buffer =  (u8 *)(DMATxDescToSet->Buffer1Addr);
	memcpy((u8*)&buffer[l], p_from_user_buffer, size);
   //
   l=size;
	//
	if( ETH_Prepare_Transmit_Descriptors(l) == ETH_ERROR ){
	   return -1;//error
	}
	
	/* Return SUCCESS */
	return size;
}
예제 #4
0
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
  struct pbuf *q;
  int framelength = 0;
  u8 *buffer =  (u8 *)(DMATxDescToSet->Buffer1Addr);
  
  /* copy frame from pbufs to driver buffers */
  for(q = p; q != NULL; q = q->next) 
  {
    memcpy((u8_t*)&buffer[framelength], q->payload, q->len);
	framelength = framelength + q->len;
  }
  
  /* Note: padding and CRC for transmitted frame 
     are automatically inserted by DMA */

  /* Prepare transmit descriptors to give to DMA*/ 
  ETH_Prepare_Transmit_Descriptors(framelength);

  return ERR_OK;
}
예제 #5
0
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
	static xSemaphoreHandle xTxSemaphore = NULL;
	struct pbuf *q;
	u8 *buffer ;
	__IO ETH_DMADESCTypeDef *DmaTxDesc;
	uint16_t framelength = 0;
	uint32_t bufferoffset = 0;
	uint32_t byteslefttocopy = 0;
	uint32_t payloadoffset = 0;
	
	if (xTxSemaphore == NULL)
	{
		vSemaphoreCreateBinary (xTxSemaphore);
	}
	
	if (xSemaphoreTake(xTxSemaphore, netifGUARD_BLOCK_TIME))
	{
		DmaTxDesc = DMATxDescToSet;
		buffer = (u8 *)(DmaTxDesc->Buffer1Addr);
		bufferoffset = 0;
		
		for(q = p; q != NULL; q = q->next) 
		{
			if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
			{
				goto error;
			}
			
			/* Get bytes in current lwIP buffer  */
			byteslefttocopy = q->len;
			payloadoffset = 0;
			
			/* Check if the length of data to copy is bigger than Tx buffer size*/
			while( (byteslefttocopy + bufferoffset) > ETH_MAX_PACKET_SIZE )
			{
				/* Copy data to Tx buffer*/
				memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), (ETH_MAX_PACKET_SIZE - bufferoffset) );
				
				/* Point to next descriptor */
				DmaTxDesc = (ETH_DMADESCTypeDef *)(DmaTxDesc->Buffer2NextDescAddr);
				
				/* Check if the buffer is available */
				if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
				{
					goto error;
				}
				
				buffer = (u8 *)(DmaTxDesc->Buffer1Addr);
				
				byteslefttocopy = byteslefttocopy - (ETH_MAX_PACKET_SIZE - bufferoffset);
				payloadoffset = payloadoffset + (ETH_MAX_PACKET_SIZE - bufferoffset);
				framelength = framelength + (ETH_MAX_PACKET_SIZE - bufferoffset);
				bufferoffset = 0;
			}
			
			/* Copy the remaining bytes */
			memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), byteslefttocopy );
			bufferoffset = bufferoffset + byteslefttocopy;
			framelength = framelength + byteslefttocopy;
		}
		
		/* Prepare transmit descriptors to give to DMA*/
		ETH_Prepare_Transmit_Descriptors(framelength);
		
		/* Give semaphore and exit */
	error:
		
		xSemaphoreGive(xTxSemaphore);
	}
	
	return ERR_OK;
}
예제 #6
0
파일: ethernetif.c 프로젝트: MIDMX/RaVisual
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
  err_t errval;
  struct pbuf *q;
  uint8_t *buffer =  (uint8_t *)(DMATxDescToSet->Buffer1Addr);
  __IO ETH_DMADESCTypeDef *DmaTxDesc;
  uint16_t framelength = 0;
  uint32_t bufferoffset = 0;
  uint32_t byteslefttocopy = 0;
  uint32_t payloadoffset = 0;

  DmaTxDesc = DMATxDescToSet;
  bufferoffset = 0;

  /* copy frame from pbufs to driver buffers */
  for(q = p; q != NULL; q = q->next)
    {
      /* Is this buffer available? If not, goto error */
      if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (uint32_t)RESET)
      {
        errval = ERR_BUF;
        goto error;
      }

      /* Get bytes in current lwIP buffer */
      byteslefttocopy = q->len;
      payloadoffset = 0;

      /* Check if the length of data to copy is bigger than Tx buffer size*/
      while( (byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE )
      {
        /* Copy data to Tx buffer*/
        memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset) );

        /* Point to next descriptor */
        DmaTxDesc = (ETH_DMADESCTypeDef *)(DmaTxDesc->Buffer2NextDescAddr);

        /* Check if the buffer is available */
        if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (uint32_t)RESET)
        {
          errval = ERR_USE;
          goto error;
        }

        buffer = (uint8_t *)(DmaTxDesc->Buffer1Addr);

        byteslefttocopy = byteslefttocopy - (ETH_TX_BUF_SIZE - bufferoffset);
        payloadoffset = payloadoffset + (ETH_TX_BUF_SIZE - bufferoffset);
        framelength = framelength + (ETH_TX_BUF_SIZE - bufferoffset);
        bufferoffset = 0;
      }

      /* Copy the remaining bytes */
      memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), byteslefttocopy );
      bufferoffset = bufferoffset + byteslefttocopy;
      framelength = framelength + byteslefttocopy;
    }
  
  /* Note: padding and CRC for transmitted frame 
     are automatically inserted by DMA */

  /* Prepare transmit descriptors to give to DMA*/ 
  ETH_Prepare_Transmit_Descriptors(framelength);

  errval = ERR_OK;

error:
  
  /* When Transmit Underflow flag is set, clear it and issue a Transmit Poll Demand to resume transmission */
  if ((ETH->DMASR & ETH_DMASR_TUS) != (uint32_t)RESET)
  {
    /* Clear TUS ETHERNET DMA flag */
    ETH->DMASR = ETH_DMASR_TUS;

    /* Resume DMA transmission*/
    ETH->DMATPDR = 0;
  }
  return errval;
}
예제 #7
0
void net_send(uint8_t *uip_buf, uint16_t uip_len)
{
	memcpy(DMATxDescToSet->Buffer1Addr, uip_buf, uip_len);

	ETH_Prepare_Transmit_Descriptors(uip_len);
}
예제 #8
0
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
	static SemaphoreHandle_t xTxSemaphore = NULL;
	struct pbuf *q;
	u8 *buffer ;
	__IO ETH_DMADESCTypeDef *DmaTxDesc;
	uint16_t framelength = 0;
	uint32_t bufferoffset = 0;
	uint32_t byteslefttocopy = 0;
	uint32_t payloadoffset = 0;
	//volatile uint32_t temp;

	if (xTxSemaphore == NULL)
	{
		vSemaphoreCreateBinary (xTxSemaphore);
		xTxSemaphore = xSemaphoreCreateBinaryNamed("Out low lvl sem");
		xSemaphoreGive(xTxSemaphore);
	}

	if (xSemaphoreTake(xTxSemaphore, netifGUARD_BLOCK_TIME))
	{
		DmaTxDesc = DMATxDescToSet;
		buffer = (u8 *)(DmaTxDesc->Buffer1Addr);
		bufferoffset = 0;

		//do {
			/*temp = ETH_GetTransmitProcessState();
			if(temp != 0) {
				printf("ETH_GetTransmitProcessState: 0x%X\n", temp);
				breakpoint();
			}
			temp = ETH_GetMACITStatus(ETH_MAC_IT_MMCT);
			if(temp == SET) {
				printf("ETH_MAC_IT_MMCT == 1");
				breakpoint();
			}
			temp = ETH_GetMACFlagStatus(ETH_MAC_FLAG_MMCT);
			if(temp == SET) {
				printf("ETH_MAC_FLAG_MMCT == 1");
				breakpoint();
			}*/
			/*temp = ETH_GetDMATxDescFlagStatus(DmaTxDesc, ETH_DMATxDesc_IC);
			if(temp == RESET) {
				printf("ETH_DMAtxdesc_IC == 0");
				breakpoint();
			}*/

		//} while( temp != 0 );

		for(q = p; q != NULL; q = q->next)
		{
			if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
			{
				printf("ERROR, ETH_DMATxDesc_OWN != RESET\n");
				goto error;
			}

			/* Get bytes in current lwIP buffer  */
			byteslefttocopy = q->len;
			payloadoffset = 0;

			/* Check if the length of data to copy is bigger than Tx buffer size*/
			while( (byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE )
			{
				/* Copy data to Tx buffer*/
				memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset) );

				/* Point to next descriptor */
				DmaTxDesc = (ETH_DMADESCTypeDef *)(DmaTxDesc->Buffer2NextDescAddr);

				/* Check if the buffer is available */
				if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
				{
					printf("ERROR, ETH_DMATxDesc_OWN != RESET (2)\n");
					goto error;
				}

				buffer = (u8 *)(DmaTxDesc->Buffer1Addr);

				byteslefttocopy = byteslefttocopy - (ETH_TX_BUF_SIZE - bufferoffset);
				payloadoffset = payloadoffset + (ETH_TX_BUF_SIZE - bufferoffset);
				framelength = framelength + (ETH_TX_BUF_SIZE - bufferoffset);
				bufferoffset = 0;
			}

			/* Copy the remaining bytes */
			memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), byteslefttocopy );
			bufferoffset = bufferoffset + byteslefttocopy;
			framelength = framelength + byteslefttocopy;

		}

		/* Prepare transmit descriptors to give to DMA*/
		ETH_Prepare_Transmit_Descriptors(framelength);

		/* Give semaphore and exit */
		error:

		xSemaphoreGive(xTxSemaphore);
	}

	return ERR_OK;
}