中级会员
 
- 积分
- 374
- 金钱
- 374
- 注册时间
- 2019-8-7
- 在线时间
- 90 小时
|
1金钱
ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum, enet_frmrecept_enum recept)
{
uint32_t reg_value=0U, reg_temp = 0U, temp = 0U;
uint32_t media_temp = 0U;
uint32_t timeout = 0U;
uint16_t phy_value = 0U;
ErrStatus phy_state= ERROR, enet_state = ERROR;
/* PHY interface configuration, configure SMI clock and reset PHY chip */
if(ERROR == enet_phy_config()){
_ENET_DELAY_(PHY_RESETDELAY);
if(ERROR == enet_phy_config()){
return enet_state;
}
}
/* initialize ENET peripheral with generally concerned parameters */
enet_default_init();
/* 1st, configure mediamode */
media_temp = (uint32_t)mediamode;
/* if is PHY auto negotiation */
if((uint32_t)ENET_AUTO_NEGOTIATION == media_temp){
/* wait for PHY_LINKED_STATUS bit be set */
do{
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
phy_value &= PHY_LINKED_STATUS;
timeout++;
}while((RESET == phy_value) && (timeout < PHY_READ_TO));
/* return ERROR due to timeout */
if(PHY_READ_TO == timeout){
return enet_state;
}
/* reset timeout counter */
timeout = 0U;
/* enable auto-negotiation */
phy_value = PHY_AUTONEGOTIATION;
phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value);
if(!phy_state){
/* return ERROR due to write timeout */
return enet_state;
}
/* wait for the PHY_AUTONEGO_COMPLETE bit be set */
do{
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
phy_value &= PHY_AUTONEGO_COMPLETE;
timeout++;
}while((RESET == phy_value) && (timeout < (uint32_t)PHY_READ_TO));
/* return ERROR due to timeout */
if(PHY_READ_TO == timeout){
return enet_state;
}
/* reset timeout counter */
timeout = 0U;
|
|