⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 91x_enet.c

📁 STR912 arm9实现的以太网通信程序
💻 C
📖 第 1 页 / 共 3 页
字号:
  
  /* Give the buffer back to the ENET DMA */
  ENET_UpdateRxDscr();

  /* Return no error */
  return (size);
}

/*******************************************************************************
* Function Name  : ENET_UpdateTxDscr
* Description    : Update the current ENET DMA descriptor to start sending frame
* Input          : FrameSize: the size of the frame to be sent 
* Output         : None
* Return         : None
* Precondition   : Frame to be sent, must has been copied in the ENET DMA buffer
*******************************************************************************/
void ENET_UpdateTxDscr(u16 FrameSize)
{    
  static u32 i=0;
  
  /* Setting the Frame Length*/
  dmaTxDscrBase[TxBC].dmaCntl = (FrameSize&0xFFF) | ENET_TXCR_NXTEN;
    
  /* Start the transmission by setting the VALID bit in the dmaPackStatus word*/
  /* of the current descriptor */
  dmaTxDscrBase[TxBC].dmaPackStatus = ENET_DSCR_TX_STATUS_VALID_MSK;
  
  /* Update the Tx Buffers Counter */
  TxBC++;
  if(TxBC >= ENET_TXBUFNB)
  {
    TxBC=0;
  }
  
  /* If it's the first frame to be sent, we start the ENET_DMA descriptor */
  /* fetch. After that, as soon as a DMA transfer is completed, a new ENET */
  /* DMA descriptor is fetched */
  if(i==0)
  {
    ENET_DMA->TXSTR|= ENET_TXSTR_FETCH;
    i++;
  }
}

/*******************************************************************************
* Function Name  : ENET_HandleTxPkt
* Description    : Transmits a packet, from application buffer, pointed by ppkt.
* Input          : - ppkt: pointer to application packet Buffer.
*                  - size: Tx Packet size.
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_HandleTxPkt(void *ppkt, u16 size)
{ 
  /* If the CPU still work on the buffer, we wait...*/   
  while((dmaTxDscrBase[TxBC].dmaPackStatus & ENET_DSCR_TX_STATUS_VALID_MSK));
  
  /* Copy the frame to be sent into the ENET DMA current Tx buffer */  
  MEMCOPY_L2S_BY4( TxBuff[TxBC], ppkt, size); /* optimized memcopy function */
  //memcpy( TxBuff[TxBC], ppkt, size);  /* string.h library */
  
  /* Update the ENET DMA current descriptor */
  ENET_UpdateTxDscr(size);
   
}

/*******************************************************************************
* Function Name  : ENET_ITConfig
* Description    : Enables or disables the specified ENET DMA interrupt.
* Input          : - ENET_IT: specifies the ENET DMA interrupts sources to be
*                    enabled or disabled. This parameter can be any combination
*                    of the following values:
*                         + ENET_IT_TX_CURR_DONE
*                         + ENET_IT_MAC_INT                  
*                         + ENET_IT_TX_MERR_INT              
*                         + ENET_IT_TX_DONE                  
*                         + ENET_IT_TX_NEXT                  
*                         + ENET_IT_TX_TO                    
*                         + ENET_IT_TX_ENTRY                 
*                         + ENET_IT_TX_FULL                  
*                         + ENET_IT_TX_EMPTY                 
*                         + ENET_IT_RX_CURR_DONE             
*                         + ENET_IT_RX_MERR_INT              
*                         + ENET_IT_RX_DONE                  
*                         + ENET_IT_RX_NEXT                  
*                         + ENET_IT_PACKET_LOST              
*                         + ENET_IT_RX_TO                    
*                         + ENET_IT_RX_ENTRY                 
*                         + ENET_IT_RX_FULL                  
*                         + ENET_IT_RX_EMPTY                 
*
*                  - NewState: new state of the specified ENET DMA interrupt.
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_ITConfig(u32 ENET_IT, FunctionalState NewState)
{
  u32 regValue;
  
  /* Get the ENET_IER register value */
  regValue = ENET_DMA->IER; 
  
  if (NewState == ENABLE) 
  {
    /* Enable the specified interrupt */
    regValue |= ENET_IT;
  }
  else
  {
    /* Disable the specified interrupt */
    regValue &= ~ENET_IT; 
  }
  
  /* Update the ENET_IER register with the new state */
  ENET_DMA->IER = regValue; 
}

/*******************************************************************************
* Function Name  : ENET_GetITSrc
* Description    : Specifies the source of the ENET DMA interrupt.
* Input          : None.
* Output         : None.
* Return         : ENET DMA interrupt source.
*******************************************************************************/
u32 ENET_GetITSrc(void)
{
  u32 regValue;
  
  /* Read the ENET_ISR register to get the source of the interrupt */
  regValue = ENET_DMA->ISR; 
  
  /* Return the source of the interrupt */
  return(regValue);  
}

/*******************************************************************************
* Function Name  : ENET_ClearIT
* Description    : Clears the ENET DMA's interrupt pending bit.
* Input          : ENET_IT: specifies the interrupt pending bit to clear.
*                  This parameter can be any combination of the following values:
*                         + ENET_IT_TX_CURR_DONE
*                         + ENET_IT_MAC_INT                  
*                         + ENET_IT_TX_MERR_INT              
*                         + ENET_IT_TX_DONE                  
*                         + ENET_IT_TX_NEXT                  
*                         + ENET_IT_TX_TO                    
*                         + ENET_IT_TX_ENTRY                 
*                         + ENET_IT_TX_FULL                  
*                         + ENET_IT_TX_EMPTY                 
*                         + ENET_IT_RX_CURR_DONE             
*                         + ENET_IT_RX_MERR_INT              
*                         + ENET_IT_RX_DONE                  
*                         + ENET_IT_RX_NEXT                  
*                         + ENET_IT_PACKET_LOST              
*                         + ENET_IT_RX_TO                    
*                         + ENET_IT_RX_ENTRY                 
*                         + ENET_IT_RX_FULL                  
*                         + ENET_IT_RX_EMPTY              
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_ClearIT(u32 ENET_IT)
{
  /* Clear the specified interrupt by writing 1 in the corresponding pending */
  /* bit */
  ENET_DMA->ISR |= ENET_IT; 
}

/*******************************************************************************
* Function Name  : ENET_PHYITConfig
* Description    : Enables or disables the specified PHY interrupt.
* Input          : - phyDev: specifies the PHY device address.
*                  - PHY_IT: specifies the PHY interrupt source to be configured.
*                  - NewState: new state of the specified PHY interrupt.
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_PHYITConfig(u8 phyDev, u32 PHY_IT, FunctionalState NewState)
{
  u32 regValue;
  
  if( NewState == ENABLE )                             
  {
    /* Enable the specified PHY_IT */
    ENET_MIIWriteReg(phyDev,PHY_XIE, PHY_IT);  
  }  
  else                               
  {
    /* Get the XIE register valur */
    regValue = ENET_MIIReadReg(phyDev,PHY_XIE);
    
    /* Disable, only, the specified PHY_IT */
    regValue &= ~PHY_IT;
    ENET_MIIWriteReg(phyDev,PHY_XIE, regValue); 
  }
}

/*******************************************************************************
* Function Name  : ENET_PHYGetITSrc
* Description    : Specifies the source of the PHY interrupt.
* Input          : phyDev: specifies the PHY device address.
* Output         : None
* Return         : PHY source interrupt.
*******************************************************************************/
u32 ENET_PHYGetITSrc(u8 phyDev)
{
  u32 regValue;
  
  /* Read the XCIIS register */
  regValue = ENET_MIIReadReg(phyDev,PHY_XCIIS); 
  
  /* Subtract the configuration part */
  regValue &= ~PHY_ConfigurationMask; 
  
  /* Return the interrupt status */
  return (regValue);
}

/*******************************************************************************
* Function Name  : ENET_PHYIsolate
* Description    : Isolates PHY from MII.
* Input          : - phyDev: specifies the PHY device address.
*                  - NewState: new state of the link PHY/MII.
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_PHYIsolate(u8 phyDev, FunctionalState NewState)
{
  u32 regValue;
  
  /* Get the PHY configuration to update it */
  regValue = ENET_MIIReadReg(phyDev, PHY_XCR); 
  
  if (NewState == ENABLE)
  {
    /* Isolate the PHY from the MII */
    regValue |= PHY_Isolate;  
  }
  else
  {
    /* Restablish the link MII/PHY */
    regValue &= ~PHY_Isolate;  
  }
  
  /* Update the PHY control register with the new configuration */
  ENET_MIIWriteReg(phyDev, PHY_XCR, regValue); 
}

/*******************************************************************************
* Function Name  : ENET_PHYPowerdown
* Description    : Puts the PHY device in the power-down mode.
* Input          : - phyDev: specifies the PHY device address.
*                  - NewState: new state of the PHY power mode.
* Output         : None
* Return         : None
*******************************************************************************/
void ENET_PHYPowerdown(u8 phyDev, FunctionalState NewState)
{
  u32 regValue;
  
  /* Get the PHY configuration to update it */
  regValue = ENET_MIIReadReg(phyDev, PHY_XCR); 
  
  if (NewState == ENABLE)       
  {
    /* Put the PHY in the power-down mode */
    regValue |= PHY_Powerdown;  
  }
  else
  {
    /* Put the PHY in the normal power mode */
    regValue &= ~PHY_Powerdown; 
  }
  
  /* Update the PHY control register with the new configuration */
  ENET_MIIWriteReg(phyDev, PHY_XCR, regValue);                                               
}

/*******************************************************************************
* Function Name  : ENET_PHYLoopBack
* Description    : Enables or disables the PHY loopBack mode.
* Input          : - phyDev: specifies the PHY device address.
*                  - NewState: new state of the PHY peripheral.
* Output         : Non
* Return         : None
*******************************************************************************/
void ENET_PHYLoopBack(u8 phyDev, FunctionalState NewState)
{
  u32 regValue;
  
  /* Get the PHY configuration to update it */
  regValue = ENET_MIIReadReg(phyDev, PHY_XCR); 
  
  if (NewState == ENABLE)
  {
    /* Enable the loopback mode */
    regValue |= PHY_Loopback;  
  }
  else
  {
    /* Put the PHY in the normal mode */
    regValue &= ~PHY_Loopback;
  }
  
  /* Update the PHY control register with the new configuration */
  ENET_MIIWriteReg(phyDev, PHY_XCR, regValue);
  ENET_MIIReadReg(phyDev, PHY_XCR);
}

/*******************************************************************************
* Function Name  : ENET_PHYReset
* Description    : PHY software reset.
* Input          : phyDev: specifies the PHY device address.
* Output         : None.
* Return         : None.
*******************************************************************************/
void ENET_PHYReset(u8 phyDev)
{
  /* Reset the PHY device */
  ENET_MIIWriteReg(phyDev, PHY_XCR, PHY_Reset_Control);
  
  /* Wait until the reset will be completed */
  while( ENET_MIIReadReg(phyDev, PHY_XCR) & PHY_Reset_Control);
}

/******************** (C) COPYRIGHT 2007 STMicroelectronics *******************/


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -