另一方面,外置的以太网物理层芯片一般有中断引脚,在系统加电初始化时配置与该引脚连接的MCU GPIO使能中断。 如下。
/*配置物理层芯片中断输入引脚*
gpio _ init structure.gpio _ mode=gpio _ mode _ in;
gpio _ init structure.gpio _ otype=gpio _ otype _ PP;
gpio _ init structure.gpio _ pupd=gpio _ pupd _ up;
gpio _ init structure.gpio _ speed=gpio _ speed _ 100 MHz;
RCC _ ah B1 periphclockcmd (eth _ phy _ interrupt _ gpio _ clk,ENABLE );
gpio _ init structure.gpio _ pin=eth _ phy _ interrupt _ pin;
gpio _ init (eth _ phy _ interrupt _ gpio _ port,GPIO_InitStructure );
sys CFG _ extilineconfig (eth _ phy _ interrupt _ exti _ port _ source,
eth _ phy _ interrupt _ exti _ pin _ source;
exti _ init structure.exti _ mode=exti _ mode _ interrupt;
exti _ init structure.exti _ trigger=exti _ trigger _ falling;
exti _ init structure.exti _ line cmd=enable;
exti _ init structure.exti _ line=eth _ phy _ interrupt _ exti _ line;
EXTI_init(EXTI_initstructure;
nvic _ init structure.nvic _ irqchannelpreemptionpriority=0x0f;
nvic _ init structure.nvic _ irqchannelsubpriority=0x0f;
nvic _ init structure.nvic _ irqchannelcmd=enable;
nvic _ init structure.nvic _ IRQ channel=eth _ phy _ interrupt _ nvic _ IRQ _ channel;
nvic_init(nvic_initstructure;
二、最后该MCU GPIO的中断函数实现如下。
//*
* @无输入参数:
* @无输出参数:
* @返回值:无
* @说明:以太网物理层芯片输入中断处理
*/
voideth _ phy _ interrupt _ IRQ handler (void )
{
rt_uint16_t u16RegValue;
//告知OS进入中断状态
rt_interrupt_enter (;
//读取中断控制状态寄存器
u16 reg value=eth _ readphyregister (stm32 _ eth _ device.u8 phy addr,0x1B );
if(u16regvalue(1ul2 ) )
{
//Link Down中断
eth _ device _ link change ((stm32 _ eth _ device.parent ),RT_FALSE );
}
if(u16regvalue(1ul0) )
{
//Link Up中断
eth _ device _ link change ((stm32 _ eth _ device.parent ),RT_TRUE );
//获取自动协商结果
u16 reg value=eth _ readphyregister (stm32 _ eth _ device.u8 phy addr,0x1F );
安装EMAC控制器
switch () u16regvalue2)0x07 ) )。
{
case 1:
log _ eth _ emac _ duplex _ speed ((rn 10 Mbps半双工) );
ETH-MACCR=~ETH_Mode_FullDuplex;
ETH-MACCR=~ETH_Speed_100M;
布雷克;
case 2:
log _ eth _ emac _ duplex _ speed ((rn 100 Mbps半双工) );
ETH-MACCR=~ETH_Mode_FullDuplex;
ETH-MACCR |=ETH_Speed_100M;
布雷克;
case 5:
log _ eth _ emac _ duplex _ speed ((rn 10 Mbps全双工) );
ETH-MACCR |=ETH_Mode_FullDuplex;
ETH-MACCR=~ETH_Speed_100M;
布雷克;
case 6:
log _ eth _ emac _ duplex _ speed ((rn 100 Mbps全双工) );
ETH-MACCR |=ETH_Mode_FullDuplex;
ETH-MACCR |=ETH_Speed_100M;
布雷克;
默认:
log_eth_emac_duplex_speed ()rn错误的emac自动协商结果! ' );
布雷克;
}
}
//清除中断
exti-pr=eth _ phy _ interrupt _ exti _ line;
//告知OS已离开中断状态
rt_interrupt_leave (;
}