📄 eth_ctl.c
字号:
* 主调函数: 建议 *========================================================================*/void ETH_SetPHYFrequency(In UINT32 u32PHYFreq) { PHY_Conf_U SetPHYFreq; SetPHYFreq.w32 = *(UINT32 *) ETH_MDIO_REG(0); SetPHYFreq.bits.frq_dv = u32PHYFreq; *(UINT32 *) ETH_MDIO_REG(0) = SetPHYFreq.w32;}/*======================================================================= * 函数名称:void ETH_SetPHYChipInformationAddress(In UINT32 u32PHYCInfAddr, In UINT32 u32PHYSpeOffsAddr, * In UINT32 u32PHYLinOffsAddr, In UINT32 u32PHYDupOffsAddr) * 初稿完成:2005/1/7 * 作 者: * 函数功能:设置PHY芯片存储状态信息(速度、链接和双工)的寄存器地址 * 输入参数:PHY芯片存储状态信息(速度、链接和双工)的寄存器地址u32PHYCInfAddr; * PHY芯片状态寄存器中存储速度信息的偏移地址u32PHYSpeOffsAddr; * PHY芯片状态寄存器中存储链接信息的偏移地址u32PHYLinOffsAddr; * PHY芯片状态寄存器中存储双工信息的偏移地址u32PHYDupOffsAddr * 输出参数: * 返回类型: 无 * 其他说明: * 调用函数: 建议 * 主调函数: 建议 *========================================================================*/void ETH_SetPHYChipInformationAddress(In UINT32 u32PHYCInfAddr, In UINT32 u32PHYSpeOffsAddr, In UINT32 u32PHYLinOffsAddr, In UINT32 u32PHYDupOffsAddr){ PHY_Stat_Addr_U SetPHYChipInfAddr; SetPHYChipInfAddr.w32 = *(UINT32 *) ETH_MDIO_REG(4); SetPHYChipInfAddr.bits.duplex_index = u32PHYDupOffsAddr; SetPHYChipInfAddr.bits.link_index = u32PHYLinOffsAddr; SetPHYChipInfAddr.bits.speed_index = u32PHYSpeOffsAddr; SetPHYChipInfAddr.bits.internal_addr = u32PHYCInfAddr; *(UINT32 *) ETH_MDIO_REG(4) = SetPHYChipInfAddr.w32;}/*======================================================================= * 函数名称:void ETH_ReadPHYPortInformation(In UINT8 u8PHYPortNo, Out UINT32 *pu32PHYPortSpeed, * Out UINT32 *pu32PHYPortLink, Out UINT32 *pu32PHYPortDupMode) * 初稿完成:2005/1/7 * 作 者: * 函数功能:读取PHY的各个端口的端口速度,链接状态,双工工作状态 * 输入参数: * * 输出参数: * 返回类型: 无 * 其他说明: * 调用函数: 建议 * 主调函数: 建议 *========================================================================*/void ETH_ReadPHYPortInformation( Out UINT32 *pu32PHYPortSpeed, Out UINT32 *pu32PHYPortLink, Out UINT32 *pu32PHYPortDupMode) { PHY_Read_SpeLinDup_U ReadPHYPortInf; ReadPHYPortInf.w32 = *(UINT32 *) ETH_MDIO_REG(3); *pu32PHYPortSpeed = ReadPHYPortInf.bits.speed_mdio2mac; *pu32PHYPortLink = ReadPHYPortInf.bits.link_mdio2mac ; *pu32PHYPortDupMode = ReadPHYPortInf.bits.duplex_mdio2mac ; *(UINT32 *) ETH_MDIO_REG(3) = ReadPHYPortInf.w32;}/*======================================================================= * 函数名称: UINT32 ETH_PhyWrite(In UINT32 u32PhyRegIndex , In UINT32 u32PhyData ) * 初稿完成: 2004/01/07 * 作 者: * 函数功能: 向指定PHY芯片的指定寄存器写入值 * 输入参数: u32PhyIndex- PHY芯片的索引号 * u32PhyRegIndex-PHY芯片内的寄存器号 * u32PhyData-要写的寄存器数据 * 输出参数: 无 * 返回类型: * 其他说明: * 调用函数: * 主调函数: *========================================================================*/UINT32 ETH_PhyWrite(In UINT32 u32PhyRegIndex , In UINT32 u32PhyData ){ PHY_Conf_U PhyWhiteReg ; UINT16 u16Count = 0; while( u16Count < 1000 ) { /*get the control register state*/ PhyWhiteReg.w32 = *(UINT32 *)ETH_MDIO_REG(0); if ( PhyWhiteReg.bits.finish == 1 ) { PhyWhiteReg.bits.finish = 0; PhyWhiteReg.bits.rw = 1; PhyWhiteReg.bits.phy_exaddr = *(UINT32 *)ETH_MDIO_REG(2);/*the phy extern address register*/ PhyWhiteReg.bits.phy_inaddr = u32PhyRegIndex; PhyWhiteReg.bits.cpu_data_in = u32PhyData; *( UINT32 *)ETH_MDIO_REG(0) = PhyWhiteReg.w32 ; break; } u16Count++ ; } if( u16Count >= 1000 ) { #ifdef ETHTest dbg_info("ETH write content of phy failure\n"); #endif return Failure; } u16Count = 0 ; while( u16Count < 1000 ) { /*Write finish?*/ PhyWhiteReg.w32 = *(UINT32 *)ETH_MDIO_REG(0) ; if ( PhyWhiteReg.bits.finish == 1 ) { return Success; } u16Count++ ; } return Failure;}/*======================================================================= * 函数名称:UINT32 ETH_PhyRead(In UINT32 u32PhyIndex , In UINT32 u32PhyRegIndex , Out UINT32 *pu32PhyDataAddr ) * 初稿完成: 2004/01/07 * 作 者: * 函数功能: 从指定PHY芯片的指定寄存器读出值 * 输入参数: u32PhyIndex- PHY芯片的索引号 * u32PhyRegIndex-PHY芯片内的寄存器号 * *pu32PhyDataAddr-读取要输出的寄存器数据 * 输出参数: 无 * 返回类型: * 其他说明: * 调用函数: * 主调函数: *========================================================================*/UINT32 ETH_PhyRead(In UINT32 u32PhyRegIndex , Out UINT32 *pu32PhyDataAddr ){ PHY_Conf_U PhyReadReg ; Read_PHY_Data_U PhyReadData; UINT16 u16Count = 0; while( u16Count < 1000 ) { /*get the control register state*/ PhyReadReg.w32 = *(UINT32 *)ETH_MDIO_REG(0) ; if ( PhyReadReg.bits.finish == 1 ) { /*set the mdio register reading command*/ PhyReadReg.bits.rw = 0 ; PhyReadReg.bits.finish = 0 ; PhyReadReg.bits.phy_exaddr = *(UINT32 *)ETH_MDIO_REG(2);/*the phy extern address register*/ PhyReadReg.bits.phy_inaddr = u32PhyRegIndex ; PhyReadReg.bits.cpu_data_in = 0 ; *(UINT32 *)ETH_MDIO_REG(0) = PhyReadReg.w32; break ; } u16Count++ ; } if( u16Count >= 1000 ) { #ifdef ETHTest dbg_info("ETH read content of phy failure\n"); #endif return Failure; } u16Count = 0 ; while( u16Count < 1000 ) { /*get the control register state*/ PhyReadReg.w32 = *(UINT32 *)ETH_MDIO_REG(0) ; if ( PhyReadReg.bits.finish == 1 ) { /*get the mdio register data*/ PhyReadData.w32 = *( UINT32 *)ETH_MDIO_REG(1) ; *pu32PhyDataAddr = PhyReadData.bits.cpu_data_out; #ifdef ETHTest dbg_info("ETH_MDIO_REG(1)-ETH read content of phy is : %lx\n",*pu32PhyDataAddr); #endif return Success; } u16Count++ ; } #ifdef ETHTest dbg_info("ETH read content of phy failure\n"); #endif return Failure;}/*=======================================================================* FILTER Control*过滤优先级是:总体过滤使能>表内过滤控制>*广播帧,组播帧,单播控制>表外过滤控制*=======================================================================*//*======================================================================= * 函数名称:void ETH_SetMACFiltEnable(In UINT32 u32FilterEnable) * 初稿完成:2005/1/7 * 作 者: * 函数功能:总体过滤使能。1->使能;0->禁止。 * 输出参数: * 返回类型: 无 * 其他说明: * 调用函数: 建议 * 主调函数: 建议 *========================================================================*/void ETH_SetMACFiltEnable(In UINT32 u32FilterEnable) { Set_FrameFilt_U MACFiltCtrl; MACFiltCtrl.w32 = *(UINT32 *) ETH_GLB_REG(5); MACFiltCtrl.bits.flt_en = u32FilterEnable; *(UINT32 *) ETH_GLB_REG(5) = MACFiltCtrl.w32;}/*======================================================================= * 函数名称:void ETH_SetOutMACFiltEnable(In UINT32 u32OutFilterEnable) * 初稿完成:2005/1/7 * 作 者: * 函数功能:过滤表外帧过滤控制。1->接收;0->丢弃。 * 输出参数: * 返回类型: 无 * 其他说明: * 调用函数: 建议 * 主调函数: 建议 *========================================================================*/void ETH_SetOutMACFiltEnable(In UINT32 u32OutFilterEnable) { Set_FrameFilt_U MACFiltCtrl; MACFiltCtrl.w32 = *(UINT32 *) ETH_GLB_REG(5); MACFiltCtrl.bits.outtab_ctrl = u32OutFilterEnable; *(UINT32 *) ETH_GLB_REG(5) = MACFiltCtrl.w32;}/*======================================================================= * 函数名称:UINT32 ETH_AddMACFiltFormContent(In UINT32 u32Index, In UINT32 u32MACLow, In UINT32 u32MACMiddle, In UINT32 u32MACHigh) * 初稿完成:2005/1/7 * 作 者: * 函数功能:写MAC过滤表内容 * 输入参数:u32Index->添加内容索引,u32MACLow->MAC低16位,u32MACMiddle->MAC中16位,u32MACHigh->MAC高16位 * 输出参数: * 返回类型: return 0->reset fail; return 1->reset success. * 其他说明: * 调用函数: 建议 * 主调函数: 建议 *========================================================================*/UINT32 ETH_AddMACFiltFormContent(In UINT32 u32Index, In UINT32 u32MACLow, In UINT32 u32MACMiddle, In UINT32 u32MACHigh) { UINT32 *pu32Filter; #if 0 switch (u32Index) { case 0 : pu32Filter = (UINT32 *) ETH_FLT_TAB0; break; case 1 : pu32Filter = (UINT32 *) ETH_FLT_TAB1; break; case 2: pu32Filter = (UINT32 *) ETH_FLT_TAB2; break; case 3 : pu32Filter = (UINT32 *) ETH_FLT_TAB3; break; case 4 : pu32Filter = (UINT32 *) ETH_FLT_TAB4; break; case 5 : pu32Filter = (UINT32 *) ETH_FLT_TAB5; break; case 6 : pu32Filter = (UINT32 *) ETH_FLT_TAB6; break; case 7 : pu32Filter = (UINT32 *) ETH_FLT_TAB7; break; case 8 : pu32Filter = (UINT32 *) ETH_FLT_TAB8; break; case 9 : pu32Filter = (UINT32 *) ETH_FLT_TAB9; break; case 10 : pu32Filter = (UINT32 *) ETH_FLT_TAB10; break; case 11 : pu32Filter = (UINT32 *) ETH_FLT_TAB11; break; case 12 : pu32Filter = (UINT32 *) ETH_FLT_TAB12; break; case 13 : pu32Filter = (UINT32 *) ETH_FLT_TAB13; break; case 14 : pu32Filter = (UINT32 *) ETH_FLT_TAB14; break; case 15 : pu32Filter = (UINT32 *) ETH_FLT_TAB15; break; case 16 : pu32Filter = (UINT32 *) ETH_FLT_TAB16; break; case 17 : pu32Filter = (UINT32 *) ETH_FLT_TAB17; break; case 18 : pu32Filter = (UINT32 *) ETH_FLT_TAB18; break; case 19 : pu32Filter = (UINT32 *) ETH_FLT_TAB19; break; case 20 : pu32Filter = (UINT32 *) ETH_FLT_TAB20; break; default : return 0;; } if ((u32Index & 0x1) != 0) {/*the index is odd number*/ *pu32Filter= ((*pu32Filter & 0xFFFF) | u32MACLow << 16); pu32Filter ++; *pu32Filter = (u32MACMiddle | (u32MACHigh << 16)); } else { *pu32Filter ++ = (u32MACLow | (u32MACMiddle << 16)); *pu32Filter= (*pu32Filter & 0xFFFF0000) | u32MACHigh; } #endif if (u32Index > 20) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -