提交 5fd89e44 编写于 作者: T tanek liang

[bsp] update eth driver: fix phy init never timeout bug

上级 049ed504
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <netif/ethernetif.h> #include <netif/ethernetif.h>
#include "lwipopts.h" #include "lwipopts.h"
#define ENET_RXBD_NUM (4) #define ENET_RXBD_NUM (4)
#define ENET_TXBD_NUM (4) #define ENET_TXBD_NUM (4)
#define ENET_RXBUFF_SIZE (ENET_FRAME_MAX_FRAMELEN) #define ENET_RXBUFF_SIZE (ENET_FRAME_MAX_FRAMELEN)
...@@ -36,16 +36,17 @@ ...@@ -36,16 +36,17 @@
#define PHY_ADDRESS 0x02u #define PHY_ADDRESS 0x02u
/* debug option */ /* debug option */
//#define DEBUG
//#define ETH_RX_DUMP //#define ETH_RX_DUMP
//#define ETH_TX_DUMP //#define ETH_TX_DUMP
#ifdef DEBUG #define DBG_ENABLE
#define ETH_PRINTF rt_kprintf #define DBG_SECTION_NAME "[ETH]"
#else #define DBG_COLOR
#define ETH_PRINTF(...) #define DBG_LEVEL DBG_INFO
#endif #include <rtdbg.h>
#define MAX_ADDR_LEN 6 #define MAX_ADDR_LEN 6
...@@ -54,12 +55,12 @@ struct rt_imxrt_eth ...@@ -54,12 +55,12 @@ struct rt_imxrt_eth
{ {
/* inherit from ethernet device */ /* inherit from ethernet device */
struct eth_device parent; struct eth_device parent;
enet_handle_t enet_handle; enet_handle_t enet_handle;
ENET_Type *enet_base; ENET_Type *enet_base;
enet_data_error_stats_t error_statistic; enet_data_error_stats_t error_statistic;
rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */
rt_bool_t tx_is_waiting; rt_bool_t tx_is_waiting;
struct rt_semaphore tx_wait; struct rt_semaphore tx_wait;
}; };
...@@ -75,9 +76,9 @@ static struct rt_imxrt_eth imxrt_eth_device; ...@@ -75,9 +76,9 @@ static struct rt_imxrt_eth imxrt_eth_device;
void _enet_rx_callback(struct rt_imxrt_eth * eth) void _enet_rx_callback(struct rt_imxrt_eth * eth)
{ {
rt_err_t result; rt_err_t result;
ENET_DisableInterrupts(eth->enet_base, kENET_RxFrameInterrupt); ENET_DisableInterrupts(eth->enet_base, kENET_RxFrameInterrupt);
result = eth_device_ready(&(eth->parent)); result = eth_device_ready(&(eth->parent));
if( result != RT_EOK ) if( result != RT_EOK )
rt_kprintf("RX err =%d\n", result ); rt_kprintf("RX err =%d\n", result );
...@@ -97,30 +98,30 @@ void _enet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, ...@@ -97,30 +98,30 @@ void _enet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event,
switch(event) switch(event)
{ {
case kENET_RxEvent: case kENET_RxEvent:
_enet_rx_callback((struct rt_imxrt_eth *)userData); _enet_rx_callback((struct rt_imxrt_eth *)userData);
break; break;
case kENET_TxEvent: case kENET_TxEvent:
_enet_tx_callback((struct rt_imxrt_eth *)userData); _enet_tx_callback((struct rt_imxrt_eth *)userData);
break; break;
case kENET_ErrEvent: case kENET_ErrEvent:
//rt_kprintf("kENET_ErrEvent\n"); //rt_kprintf("kENET_ErrEvent\n");
break; break;
case kENET_WakeUpEvent: case kENET_WakeUpEvent:
//rt_kprintf("kENET_WakeUpEvent\n"); //rt_kprintf("kENET_WakeUpEvent\n");
break; break;
case kENET_TimeStampEvent: case kENET_TimeStampEvent:
//rt_kprintf("kENET_TimeStampEvent\n"); //rt_kprintf("kENET_TimeStampEvent\n");
break; break;
case kENET_TimeStampAvailEvent: case kENET_TimeStampAvailEvent:
//rt_kprintf("kENET_TimeStampAvailEvent \n"); //rt_kprintf("kENET_TimeStampAvailEvent \n");
break; break;
default: default:
//rt_kprintf("unknow error\n"); //rt_kprintf("unknow error\n");
break; break;
...@@ -314,21 +315,21 @@ static void _enet_io_init(void) ...@@ -314,21 +315,21 @@ static void _enet_io_init(void)
Pull Up / Down Config. Field: 100K Ohm Pull Up Pull Up / Down Config. Field: 100K Ohm Pull Up
Hyst. Enable Field: Hysteresis Disabled */ Hyst. Enable Field: Hysteresis Disabled */
} }
static void _enet_clk_init(void) static void _enet_clk_init(void)
{ {
const clock_enet_pll_config_t config = {true, false, false, 1, 1}; const clock_enet_pll_config_t config = {true, false, false, 1, 1};
CLOCK_InitEnetPll(&config); CLOCK_InitEnetPll(&config);
IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true); IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1TxClkOutputDir, true);
} }
static void _delay(void) static void _delay(void)
{ {
volatile int i = 1000000; volatile int i = 1000000;
while (i--) while (i--)
i = i; i = i;
} }
...@@ -336,7 +337,7 @@ static void _delay(void) ...@@ -336,7 +337,7 @@ static void _delay(void)
static void _enet_phy_reset_by_gpio(void) static void _enet_phy_reset_by_gpio(void)
{ {
gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode}; gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
GPIO_PinInit(GPIO1, 9, &gpio_config); GPIO_PinInit(GPIO1, 9, &gpio_config);
GPIO_PinInit(GPIO1, 10, &gpio_config); GPIO_PinInit(GPIO1, 10, &gpio_config);
/* pull up the ENET_INT before RESET. */ /* pull up the ENET_INT before RESET. */
...@@ -354,7 +355,7 @@ static void _enet_config(void) ...@@ -354,7 +355,7 @@ static void _enet_config(void)
phy_speed_t speed; phy_speed_t speed;
phy_duplex_t duplex; phy_duplex_t duplex;
bool link = false; bool link = false;
/* prepare the buffer configuration. */ /* prepare the buffer configuration. */
enet_buffer_config_t buffConfig = { enet_buffer_config_t buffConfig = {
ENET_RXBD_NUM, ENET_RXBD_NUM,
...@@ -366,7 +367,7 @@ static void _enet_config(void) ...@@ -366,7 +367,7 @@ static void _enet_config(void)
&g_rxDataBuff[0][0], &g_rxDataBuff[0][0],
&g_txDataBuff[0][0], &g_txDataBuff[0][0],
}; };
/* Get default configuration. */ /* Get default configuration. */
/* /*
* config.miiMode = kENET_RmiiMode; * config.miiMode = kENET_RmiiMode;
...@@ -377,26 +378,36 @@ static void _enet_config(void) ...@@ -377,26 +378,36 @@ static void _enet_config(void)
ENET_GetDefaultConfig(&config); ENET_GetDefaultConfig(&config);
config.interrupt = kENET_TxFrameInterrupt | kENET_RxFrameInterrupt; config.interrupt = kENET_TxFrameInterrupt | kENET_RxFrameInterrupt;
//config.interrupt = 0xFFFFFFFF; //config.interrupt = 0xFFFFFFFF;
/* Set SMI to get PHY link status. */ /* Set SMI to get PHY link status. */
sysClock = CLOCK_GetFreq(kCLOCK_AhbClk); sysClock = CLOCK_GetFreq(kCLOCK_AhbClk);
status = PHY_Init(imxrt_eth_device.enet_base, PHY_ADDRESS, sysClock); status = PHY_Init(imxrt_eth_device.enet_base, PHY_ADDRESS, sysClock);
while (status != kStatus_Success)
if (status == kStatus_Success)
{ {
ETH_PRINTF("\r\nPHY Auto-negotiation failed. Please check the cable connection and link partner setting.\r\n"); PHY_GetLinkStatus(imxrt_eth_device.enet_base, PHY_ADDRESS, &link);
status = PHY_Init(imxrt_eth_device.enet_base, PHY_ADDRESS, sysClock); if (link)
{
/* Get the actual PHY link speed. */
PHY_GetLinkSpeedDuplex(imxrt_eth_device.enet_base, PHY_ADDRESS, &speed, &duplex);
/* Change the MII speed and duplex for actual link status. */
config.miiSpeed = (enet_mii_speed_t)speed;
config.miiDuplex = (enet_mii_duplex_t)duplex;
}
dbg_log(DBG_LOG, "PHY Auto-negotiation success.\n");
eth_device_linkchange(&imxrt_eth_device.parent, RT_TRUE);
} }
else
PHY_GetLinkStatus(imxrt_eth_device.enet_base, PHY_ADDRESS, &link);
if (link)
{ {
/* Get the actual PHY link speed. */ config.miiSpeed = kENET_MiiSpeed10M;
PHY_GetLinkSpeedDuplex(imxrt_eth_device.enet_base, PHY_ADDRESS, &speed, &duplex); config.miiDuplex = kENET_MiiHalfDuplex;
/* Change the MII speed and duplex for actual link status. */
config.miiSpeed = (enet_mii_speed_t)speed; dbg_log(DBG_WARNING, "PHY Auto-negotiation failed. Please check the cable connection and link partner setting.\n");
config.miiDuplex = (enet_mii_duplex_t)duplex; eth_device_linkchange(&imxrt_eth_device.parent, RT_FALSE);
} }
ENET_Init(imxrt_eth_device.enet_base, &imxrt_eth_device.enet_handle, &config, &buffConfig, &imxrt_eth_device.dev_addr[0], sysClock); ENET_Init(imxrt_eth_device.enet_base, &imxrt_eth_device.enet_handle, &config, &buffConfig, &imxrt_eth_device.dev_addr[0], sysClock);
ENET_SetCallback(&imxrt_eth_device.enet_handle, _enet_callback, &imxrt_eth_device); ENET_SetCallback(&imxrt_eth_device.enet_handle, _enet_callback, &imxrt_eth_device);
ENET_ActiveRead(imxrt_eth_device.enet_base); ENET_ActiveRead(imxrt_eth_device.enet_base);
...@@ -408,7 +419,7 @@ static rt_err_t rt_imxrt_eth_init(rt_device_t dev) ...@@ -408,7 +419,7 @@ static rt_err_t rt_imxrt_eth_init(rt_device_t dev)
_enet_io_init(); _enet_io_init();
_enet_clk_init(); _enet_clk_init();
_enet_phy_reset_by_gpio(); _enet_phy_reset_by_gpio();
_enet_config(); _enet_config();
return RT_EOK; return RT_EOK;
...@@ -416,33 +427,33 @@ static rt_err_t rt_imxrt_eth_init(rt_device_t dev) ...@@ -416,33 +427,33 @@ static rt_err_t rt_imxrt_eth_init(rt_device_t dev)
static rt_err_t rt_imxrt_eth_open(rt_device_t dev, rt_uint16_t oflag) static rt_err_t rt_imxrt_eth_open(rt_device_t dev, rt_uint16_t oflag)
{ {
ETH_PRINTF("rt_imxrt_eth_open...\n"); dbg_log(DBG_LOG, "rt_imxrt_eth_open...\n");
return RT_EOK; return RT_EOK;
} }
static rt_err_t rt_imxrt_eth_close(rt_device_t dev) static rt_err_t rt_imxrt_eth_close(rt_device_t dev)
{ {
ETH_PRINTF("rt_imxrt_eth_close...\n"); dbg_log(DBG_LOG, "rt_imxrt_eth_close...\n");
return RT_EOK; return RT_EOK;
} }
static rt_size_t rt_imxrt_eth_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) static rt_size_t rt_imxrt_eth_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{ {
ETH_PRINTF("rt_imxrt_eth_read...\n"); dbg_log(DBG_LOG, "rt_imxrt_eth_read...\n");
rt_set_errno(-RT_ENOSYS); rt_set_errno(-RT_ENOSYS);
return 0; return 0;
} }
static rt_size_t rt_imxrt_eth_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) static rt_size_t rt_imxrt_eth_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
{ {
ETH_PRINTF("rt_imxrt_eth_write...\n"); dbg_log(DBG_LOG, "rt_imxrt_eth_write...\n");
rt_set_errno(-RT_ENOSYS); rt_set_errno(-RT_ENOSYS);
return 0; return 0;
} }
static rt_err_t rt_imxrt_eth_control(rt_device_t dev, int cmd, void *args) static rt_err_t rt_imxrt_eth_control(rt_device_t dev, int cmd, void *args)
{ {
ETH_PRINTF("rt_imxrt_eth_control...\n"); dbg_log(DBG_LOG, "rt_imxrt_eth_control...\n");
switch(cmd) switch(cmd)
{ {
case NIOCTL_GADDR: case NIOCTL_GADDR:
...@@ -468,7 +479,7 @@ rt_err_t rt_imxrt_eth_tx( rt_device_t dev, struct pbuf* p) ...@@ -468,7 +479,7 @@ rt_err_t rt_imxrt_eth_tx( rt_device_t dev, struct pbuf* p)
RT_ASSERT(p != NULL); RT_ASSERT(p != NULL);
RT_ASSERT(enet_handle != RT_NULL); RT_ASSERT(enet_handle != RT_NULL);
ETH_PRINTF("rt_imxrt_eth_tx: %d\n", p->len); dbg_log(DBG_LOG, "rt_imxrt_eth_tx: %d\n", p->len);
#ifdef ETH_TX_DUMP #ifdef ETH_TX_DUMP
{ {
...@@ -477,11 +488,11 @@ rt_err_t rt_imxrt_eth_tx( rt_device_t dev, struct pbuf* p) ...@@ -477,11 +488,11 @@ rt_err_t rt_imxrt_eth_tx( rt_device_t dev, struct pbuf* p)
buf = (uint8_t *)p->payload; buf = (uint8_t *)p->payload;
for (i = 0; i < p->len; i++) for (i = 0; i < p->len; i++)
{ {
ETH_PRINTF("%02X ", buf[i]); dbg_log(DBG_LOG, "%02X ", buf[i]);
if (i % 16 == 15) if (i % 16 == 15)
ETH_PRINTF("\n"); dbg_log(DBG_LOG, "\n");
} }
ETH_PRINTF("\n"); dbg_log(DBG_LOG, "\n");
} }
#endif #endif
...@@ -504,12 +515,12 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev) ...@@ -504,12 +515,12 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev)
{ {
uint32_t length = 0; uint32_t length = 0;
status_t status; status_t status;
struct pbuf* p = RT_NULL; struct pbuf* p = RT_NULL;
enet_handle_t * enet_handle = &imxrt_eth_device.enet_handle; enet_handle_t * enet_handle = &imxrt_eth_device.enet_handle;
ENET_Type *enet_base = imxrt_eth_device.enet_base; ENET_Type *enet_base = imxrt_eth_device.enet_base;
enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic; enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic;
/* Get the Frame size */ /* Get the Frame size */
status = ENET_GetRxFrameSize(enet_handle, &length); status = ENET_GetRxFrameSize(enet_handle, &length);
...@@ -518,7 +529,7 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev) ...@@ -518,7 +529,7 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev)
{ {
/* Received valid frame. Deliver the rx buffer with the size equal to length. */ /* Received valid frame. Deliver the rx buffer with the size equal to length. */
p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL); p = pbuf_alloc(PBUF_RAW, length, PBUF_POOL);
if (p != NULL) if (p != NULL)
{ {
status = ENET_ReadFrame(enet_base, enet_handle, p->payload, length); status = ENET_ReadFrame(enet_base, enet_handle, p->payload, length);
...@@ -532,28 +543,28 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev) ...@@ -532,28 +543,28 @@ struct pbuf *rt_imxrt_eth_rx(rt_device_t dev)
buf = (uint8_t *)p->payload; buf = (uint8_t *)p->payload;
for (i = 0; i < p->len; i++) for (i = 0; i < p->len; i++)
{ {
ETH_PRINTF("%02X ", buf[i]); dbg_log(DBG_LOG, "%02X ", buf[i]);
if (i % 16 == 15) if (i % 16 == 15)
ETH_PRINTF("\n"); dbg_log(DBG_LOG, "\n");
} }
ETH_PRINTF("\n"); dbg_log(DBG_LOG, "\n");
#endif #endif
return p; return p;
} }
else else
{ {
ETH_PRINTF(" A frame read failed\n"); dbg_log(DBG_LOG, " A frame read failed\n");
pbuf_free(p); pbuf_free(p);
} }
} }
else else
{ {
ETH_PRINTF(" pbuf_alloc faild\n"); dbg_log(DBG_LOG, " pbuf_alloc faild\n");
} }
} }
else if (status == kStatus_ENET_RxFrameError) else if (status == kStatus_ENET_RxFrameError)
{ {
ETH_PRINTF("ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n"); dbg_log(DBG_WARNING, "ENET_GetRxFrameSize: kStatus_ENET_RxFrameError\n");
/* Update the received buffer when error happened. */ /* Update the received buffer when error happened. */
/* Get the error information of the received g_frame. */ /* Get the error information of the received g_frame. */
ENET_GetRxErrBeforeReadFrame(enet_handle, error_statistic); ENET_GetRxErrBeforeReadFrame(enet_handle, error_statistic);
...@@ -577,7 +588,7 @@ static int rt_hw_imxrt_eth_init(void) ...@@ -577,7 +588,7 @@ static int rt_hw_imxrt_eth_init(void)
imxrt_eth_device.dev_addr[3] = 0x12; imxrt_eth_device.dev_addr[3] = 0x12;
imxrt_eth_device.dev_addr[4] = 0x34; imxrt_eth_device.dev_addr[4] = 0x34;
imxrt_eth_device.dev_addr[5] = 0x56; imxrt_eth_device.dev_addr[5] = 0x56;
imxrt_eth_device.enet_base = ENET; imxrt_eth_device.enet_base = ENET;
imxrt_eth_device.parent.parent.init = rt_imxrt_eth_init; imxrt_eth_device.parent.parent.init = rt_imxrt_eth_init;
...@@ -591,20 +602,20 @@ static int rt_hw_imxrt_eth_init(void) ...@@ -591,20 +602,20 @@ static int rt_hw_imxrt_eth_init(void)
imxrt_eth_device.parent.eth_rx = rt_imxrt_eth_rx; imxrt_eth_device.parent.eth_rx = rt_imxrt_eth_rx;
imxrt_eth_device.parent.eth_tx = rt_imxrt_eth_tx; imxrt_eth_device.parent.eth_tx = rt_imxrt_eth_tx;
ETH_PRINTF("sem init: tx_wait\r\n"); dbg_log(DBG_LOG, "sem init: tx_wait\r\n");
/* init tx semaphore */ /* init tx semaphore */
rt_sem_init(&imxrt_eth_device.tx_wait, "tx_wait", 0, RT_IPC_FLAG_FIFO); rt_sem_init(&imxrt_eth_device.tx_wait, "tx_wait", 0, RT_IPC_FLAG_FIFO);
/* register eth device */ /* register eth device */
ETH_PRINTF("eth_device_init start\r\n"); dbg_log(DBG_LOG, "eth_device_init start\r\n");
state = eth_device_init(&(imxrt_eth_device.parent), "e0"); state = eth_device_init(&(imxrt_eth_device.parent), "e0");
if (RT_EOK == state) if (RT_EOK == state)
{ {
ETH_PRINTF("eth_device_init success\r\n"); dbg_log(DBG_LOG, "eth_device_init success\r\n");
} }
else else
{ {
ETH_PRINTF("eth_device_init faild: %d\r\n", state); dbg_log(DBG_LOG, "eth_device_init faild: %d\r\n", state);
} }
return state; return state;
} }
...@@ -618,7 +629,7 @@ void phy_read(uint32_t phyReg) ...@@ -618,7 +629,7 @@ void phy_read(uint32_t phyReg)
{ {
uint32_t data; uint32_t data;
status_t status; status_t status;
status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, &data); status = PHY_Read(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, &data);
if (kStatus_Success == status) if (kStatus_Success == status)
{ {
...@@ -633,7 +644,7 @@ void phy_read(uint32_t phyReg) ...@@ -633,7 +644,7 @@ void phy_read(uint32_t phyReg)
void phy_write(uint32_t phyReg, uint32_t data) void phy_write(uint32_t phyReg, uint32_t data)
{ {
status_t status; status_t status;
status = PHY_Write(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, data); status = PHY_Write(imxrt_eth_device.enet_base, PHY_ADDRESS, phyReg, data);
if (kStatus_Success == status) if (kStatus_Success == status)
{ {
...@@ -649,7 +660,7 @@ void phy_dump(void) ...@@ -649,7 +660,7 @@ void phy_dump(void)
{ {
uint32_t data; uint32_t data;
status_t status; status_t status;
int i; int i;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
...@@ -659,7 +670,7 @@ void phy_dump(void) ...@@ -659,7 +670,7 @@ void phy_dump(void)
rt_kprintf("phy_dump: %02X --> faild", i); rt_kprintf("phy_dump: %02X --> faild", i);
break; break;
} }
if (i % 8 == 7) if (i % 8 == 7)
{ {
rt_kprintf("%02X --> %08X ", i, data); rt_kprintf("%02X --> %08X ", i, data);
...@@ -668,17 +679,17 @@ void phy_dump(void) ...@@ -668,17 +679,17 @@ void phy_dump(void)
{ {
rt_kprintf("%02X --> %08X\n", i, data); rt_kprintf("%02X --> %08X\n", i, data);
} }
} }
} }
void enet_reg_dump(void) void enet_reg_dump(void)
{ {
ENET_Type *enet_base = imxrt_eth_device.enet_base; ENET_Type *enet_base = imxrt_eth_device.enet_base;
#define DUMP_REG(__REG) \ #define DUMP_REG(__REG) \
rt_kprintf("%s(%08X): %08X\n", #__REG, (uint32_t)&enet_base->__REG, enet_base->__REG) rt_kprintf("%s(%08X): %08X\n", #__REG, (uint32_t)&enet_base->__REG, enet_base->__REG)
DUMP_REG(EIR); DUMP_REG(EIR);
DUMP_REG(EIMR); DUMP_REG(EIMR);
DUMP_REG(RDAR); DUMP_REG(RDAR);
...@@ -785,16 +796,16 @@ void enet_nvic_tog(void) ...@@ -785,16 +796,16 @@ void enet_nvic_tog(void)
void enet_rx_stat(void) void enet_rx_stat(void)
{ {
enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic; enet_data_error_stats_t *error_statistic = &imxrt_eth_device.error_statistic;
#define DUMP_STAT(__VAR) \ #define DUMP_STAT(__VAR) \
rt_kprintf("%-25s: %08X\n", #__VAR, error_statistic->__VAR); rt_kprintf("%-25s: %08X\n", #__VAR, error_statistic->__VAR);
DUMP_STAT(statsRxLenGreaterErr); DUMP_STAT(statsRxLenGreaterErr);
DUMP_STAT(statsRxAlignErr); DUMP_STAT(statsRxAlignErr);
DUMP_STAT(statsRxFcsErr); DUMP_STAT(statsRxFcsErr);
DUMP_STAT(statsRxOverRunErr); DUMP_STAT(statsRxOverRunErr);
DUMP_STAT(statsRxTruncateErr); DUMP_STAT(statsRxTruncateErr);
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
DUMP_STAT(statsRxProtocolChecksumErr); DUMP_STAT(statsRxProtocolChecksumErr);
DUMP_STAT(statsRxIpHeadChecksumErr); DUMP_STAT(statsRxIpHeadChecksumErr);
...@@ -808,8 +819,8 @@ void enet_rx_stat(void) ...@@ -808,8 +819,8 @@ void enet_rx_stat(void)
DUMP_STAT(statsTxExcessCollisionErr); DUMP_STAT(statsTxExcessCollisionErr);
DUMP_STAT(statsTxUnderFlowErr); DUMP_STAT(statsTxUnderFlowErr);
DUMP_STAT(statsTxTsErr); DUMP_STAT(statsTxTsErr);
#endif #endif
} }
void enet_buf_info(void) void enet_buf_info(void)
...@@ -818,7 +829,7 @@ void enet_buf_info(void) ...@@ -818,7 +829,7 @@ void enet_buf_info(void)
int i = 0; int i = 0;
for (i = 0; i < ENET_RXBD_NUM; i++) for (i = 0; i < ENET_RXBD_NUM; i++)
{ {
rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n", rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n",
i, i,
g_rxBuffDescrip[i].length, g_rxBuffDescrip[i].length,
g_rxBuffDescrip[i].control, g_rxBuffDescrip[i].control,
...@@ -827,7 +838,7 @@ void enet_buf_info(void) ...@@ -827,7 +838,7 @@ void enet_buf_info(void)
for (i = 0; i < ENET_TXBD_NUM; i++) for (i = 0; i < ENET_TXBD_NUM; i++)
{ {
rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n", rt_kprintf("%d: length: %-8d, control: %04X, buffer:%p\n",
i, i,
g_txBuffDescrip[i].length, g_txBuffDescrip[i].length,
g_txBuffDescrip[i].control, g_txBuffDescrip[i].control,
......
...@@ -29,12 +29,13 @@ ...@@ -29,12 +29,13 @@
*/ */
#include "fsl_phy.h" #include "fsl_phy.h"
#include <rtthread.h>
/******************************************************************************* /*******************************************************************************
* Definitions * Definitions
******************************************************************************/ ******************************************************************************/
/*! @brief Defines the timeout macro. */ /*! @brief Defines the timeout macro. */
#define PHY_TIMEOUT_COUNT 0x3FFFFFFU #define PHY_TIMEOUT_COUNT 0xFFFFU
/******************************************************************************* /*******************************************************************************
* Prototypes * Prototypes
...@@ -83,14 +84,14 @@ status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz) ...@@ -83,14 +84,14 @@ status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz)
PHY_Read(base, phyAddr, PHY_ID1_REG, &idReg); PHY_Read(base, phyAddr, PHY_ID1_REG, &idReg);
counter --; counter --;
} }
if (!counter) if (!counter)
{ {
return kStatus_Fail; return kStatus_Fail;
} }
/* Reset PHY. */ /* Reset PHY. */
counter = PHY_TIMEOUT_COUNT; counter = 6;
result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, PHY_BCTL_RESET_MASK); result = PHY_Write(base, phyAddr, PHY_BASICCONTROL_REG, PHY_BCTL_RESET_MASK);
if (result == kStatus_Success) if (result == kStatus_Success)
{ {
...@@ -136,6 +137,9 @@ status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz) ...@@ -136,6 +137,9 @@ status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz)
break; break;
} }
} }
rt_kprintf("[PHY] wait autonegotiation complete...\n");
rt_thread_delay(RT_TICK_PER_SECOND);
if (!counter) if (!counter)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册