Merge pull request #1038 from TanekLiang/lpc54608_fix2

[bsp] fix bug: emac hardfault when RJ45 not inserted
This commit is contained in:
Bernard Xiong 2017-11-25 23:57:42 +08:00 committed by GitHub
commit 94ba2c0b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 20 deletions

View File

@ -287,9 +287,19 @@ static rt_err_t lpc_emac_phy_init(phy_speed_t * speed, phy_duplex_t * duplex)
bool link = false; bool link = false;
int32_t status; int32_t status;
RT_ASSERT(speed != NULL);
RT_ASSERT(duplex != NULL);
status = PHY_Init(lpc_emac_device.base, lpc_emac_device.phyAddr, 0); status = PHY_Init(lpc_emac_device.base, lpc_emac_device.phyAddr, 0);
if (status != kStatus_Success) if (status != kStatus_Success)
{ {
/* Half duplex. */
*duplex = kPHY_HalfDuplex;
/* 10M speed. */
*speed = kPHY_Speed10M;
eth_device_linkchange(&lpc_emac_device.parent, RT_FALSE);
ETH_PRINTF("PHY_Init failed!\n"); ETH_PRINTF("PHY_Init failed!\n");
return RT_ERROR; return RT_ERROR;
} }
@ -307,11 +317,10 @@ static rt_err_t lpc_emac_phy_init(phy_speed_t * speed, phy_duplex_t * duplex)
PHY_GetLinkStatus(lpc_emac_device.base, lpc_emac_device.phyAddr, &link); PHY_GetLinkStatus(lpc_emac_device.base, lpc_emac_device.phyAddr, &link);
} }
RT_ASSERT(speed != NULL);
RT_ASSERT(duplex != NULL);
PHY_GetLinkSpeedDuplex(lpc_emac_device.base, lpc_emac_device.phyAddr, speed, duplex); PHY_GetLinkSpeedDuplex(lpc_emac_device.base, lpc_emac_device.phyAddr, speed, duplex);
eth_device_linkchange(&lpc_emac_device.parent, RT_TRUE);
return RT_EOK; return RT_EOK;
} }
@ -326,10 +335,7 @@ static rt_err_t lpc_emac_init(rt_device_t dev)
lcp_emac_io_init(); lcp_emac_io_init();
if (lpc_emac_phy_init(&speed, &duplex) != RT_EOK) lpc_emac_phy_init(&speed, &duplex);
{
return RT_ERROR;
}
/* calculate start addresses of all rx buffers */ /* calculate start addresses of all rx buffers */
for (i = 0; i < ENET_RXBD_NUM; i++) for (i = 0; i < ENET_RXBD_NUM; i++)
@ -377,8 +383,6 @@ static rt_err_t lpc_emac_init(rt_device_t dev)
/* Active TX/RX. */ /* Active TX/RX. */
ENET_StartRxTx(lpc_emac_device.base, 1, 1); ENET_StartRxTx(lpc_emac_device.base, 1, 1);
eth_device_linkchange(&lpc_emac_device.parent, RT_TRUE);
return RT_EOK; return RT_EOK;
} }
@ -456,16 +460,10 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p)
result = ENET_SendFrame(enet_base, enet_handle, data, p->len); result = ENET_SendFrame(enet_base, enet_handle, data, p->len);
RT_ASSERT(result != kStatus_ENET_TxFrameBusy); if ((result == kStatus_ENET_TxFrameFail) || (result == kStatus_ENET_TxFrameOverLen) || (result == kStatus_ENET_TxFrameBusy))
if ((result == kStatus_ENET_TxFrameFail) || (result == kStatus_ENET_TxFrameOverLen))
{ {
return RT_ERROR; return RT_ERROR;
} }
else if (result == kStatus_ENET_TxFrameBusy)
{
RT_ASSERT(NULL);
}
return RT_EOK; return RT_EOK;
} }