32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include "fsl_device_registers.h"
36 #include "fsl_power.h"
37 #include "fsl_reset.h"
38 #include "fsl_clock.h"
39 #include "fsl_iocon.h"
49 #if defined(__ICCARM__)
52 #pragma data_alignment = 4
55 #pragma data_alignment = 4
58 #pragma data_alignment = 4
61 #pragma data_alignment = 4
125 TRACE_INFO(
"Initializing LPC54xxx Ethernet MAC...\r\n");
128 nicDriverInterface = interface;
131 CLOCK_EnableClock(kCLOCK_Eth);
133 RESET_PeripheralReset(kETH_RST_SHIFT_RSTn);
139 ENET->DMA_MODE |= ENET_DMA_MODE_SWR_MASK;
141 while((ENET->DMA_MODE & ENET_DMA_MODE_SWR_MASK) != 0)
146 ENET->MAC_MDIO_ADDR = ENET_MAC_MDIO_ADDR_CR(4);
149 if(interface->phyDriver != NULL)
152 error = interface->phyDriver->init(interface);
154 else if(interface->switchDriver != NULL)
157 error = interface->switchDriver->init(interface);
172 ENET->MAC_CONFIG = ENET_MAC_CONFIG_GPSLCE_MASK | ENET_MAC_CONFIG_PS_MASK |
173 ENET_MAC_CONFIG_DO_MASK;
176 temp = ENET->MAC_EXT_CONFIG & ~ENET_MAC_EXT_CONFIG_GPSL_MASK;
180 ENET->MAC_ADDR_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
181 ENET->MAC_ADDR_HIGH = interface->macAddr.w[2];
184 ENET->MAC_FRAME_FILTER = 0;
187 ENET->MAC_TX_FLOW_CTRL_Q[0] = 0;
188 ENET->MAC_RX_FLOW_CTRL = 0;
191 ENET->MAC_RXQ_CTRL[0] = ENET_MAC_RXQ_CTRL_RXQ0EN(2);
194 ENET->DMA_MODE = ENET_DMA_MODE_PR(0);
196 ENET->DMA_SYSBUS_MODE |= ENET_DMA_SYSBUS_MODE_AAL_MASK;
199 ENET->DMA_CH[0].DMA_CHX_CTRL = ENET_DMA_CH_DMA_CHX_CTRL_DSL(0);
201 ENET->DMA_CH[0].DMA_CHX_TX_CTRL = ENET_DMA_CH_DMA_CHX_TX_CTRL_TxPBL(32);
204 ENET->DMA_CH[0].DMA_CHX_RX_CTRL = ENET_DMA_CH_DMA_CHX_RX_CTRL_RxPBL(32) |
208 ENET->MTL_QUEUE[0].MTL_TXQX_OP_MODE |= ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TQS(7) |
209 ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TXQEN(2) |
210 ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TSF_MASK;
213 ENET->MTL_QUEUE[0].MTL_RXQX_OP_MODE |= ENET_MTL_QUEUE_MTL_RXQX_OP_MODE_RQS(7) |
214 ENET_MTL_QUEUE_MTL_RXQX_OP_MODE_RSF_MASK;
220 ENET->MAC_INTR_EN = 0;
223 ENET->DMA_CH[0].DMA_CHX_INT_EN = ENET_DMA_CH_DMA_CHX_INT_EN_NIE_MASK |
224 ENET_DMA_CH_DMA_CHX_INT_EN_RIE_MASK | ENET_DMA_CH_DMA_CHX_INT_EN_TIE_MASK;
234 ENET->MAC_CONFIG |= ENET_MAC_CONFIG_TE_MASK | ENET_MAC_CONFIG_RE_MASK;
237 ENET->DMA_CH[0].DMA_CHX_TX_CTRL |= ENET_DMA_CH_DMA_CHX_TX_CTRL_ST_MASK;
238 ENET->DMA_CH[0].DMA_CHX_RX_CTRL |= ENET_DMA_CH_DMA_CHX_RX_CTRL_SR_MASK;
257 #if defined(USE_LPCXPRESSO_54S018) || defined(USE_LPCXPRESSO_54608) || \
258 defined(USE_LPCXPRESSO_54628) || defined(USE_LPC54018_IOT_MODULE)
259 gpio_pin_config_t pinConfig;
262 SYSCON->ETHPHYSEL |= SYSCON_ETHPHYSEL_PHY_SEL_MASK;
265 CLOCK_EnableClock(kCLOCK_Iocon);
268 CLOCK_EnableClock(kCLOCK_Gpio0);
269 CLOCK_EnableClock(kCLOCK_Gpio2);
270 CLOCK_EnableClock(kCLOCK_Gpio4);
273 IOCON_PinMuxSet(IOCON, 0, 17, IOCON_FUNC7 | IOCON_MODE_INACT |
274 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
277 IOCON_PinMuxSet(IOCON, 4, 8, IOCON_FUNC1 | IOCON_MODE_INACT |
278 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
281 IOCON_PinMuxSet(IOCON, 4, 10, IOCON_FUNC1 | IOCON_MODE_INACT |
282 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
285 IOCON_PinMuxSet(IOCON, 4, 11, IOCON_FUNC1 | IOCON_MODE_INACT |
286 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
289 IOCON_PinMuxSet(IOCON, 4, 12, IOCON_FUNC1 | IOCON_MODE_INACT |
290 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
293 IOCON_PinMuxSet(IOCON, 4, 13, IOCON_FUNC1 | IOCON_MODE_INACT |
294 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
297 IOCON_PinMuxSet(IOCON, 4, 14, IOCON_FUNC1 | IOCON_MODE_INACT |
298 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
301 IOCON_PinMuxSet(IOCON, 4, 15, IOCON_FUNC1 | IOCON_MODE_INACT |
302 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
305 IOCON_PinMuxSet(IOCON, 4, 16, IOCON_FUNC1 | IOCON_MODE_PULLUP |
306 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
309 pinConfig.pinDirection = kGPIO_DigitalOutput;
310 pinConfig.outputLogic = 0;
311 GPIO_PinInit(GPIO, 2, 26, &pinConfig);
314 GPIO_PinWrite(GPIO, 2, 26, 0);
316 GPIO_PinWrite(GPIO, 2, 26, 1);
320 #elif defined(USE_LPCXPRESSO_54S018M)
321 gpio_pin_config_t pinConfig;
324 SYSCON->ETHPHYSEL |= SYSCON_ETHPHYSEL_PHY_SEL_MASK;
327 CLOCK_EnableClock(kCLOCK_Iocon);
330 CLOCK_EnableClock(kCLOCK_Gpio0);
331 CLOCK_EnableClock(kCLOCK_Gpio1);
332 CLOCK_EnableClock(kCLOCK_Gpio2);
333 CLOCK_EnableClock(kCLOCK_Gpio4);
336 IOCON_PinMuxSet(IOCON, 0, 17, IOCON_FUNC7 | IOCON_MODE_INACT |
337 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
340 IOCON_PinMuxSet(IOCON, 1, 16, IOCON_FUNC1 | IOCON_MODE_INACT |
341 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
344 IOCON_PinMuxSet(IOCON, 1, 23, IOCON_FUNC4 | IOCON_MODE_PULLUP |
345 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
348 IOCON_PinMuxSet(IOCON, 4, 8, IOCON_FUNC1 | IOCON_MODE_INACT |
349 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
352 IOCON_PinMuxSet(IOCON, 4, 10, IOCON_FUNC1 | IOCON_MODE_INACT |
353 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
356 IOCON_PinMuxSet(IOCON, 4, 11, IOCON_FUNC1 | IOCON_MODE_INACT |
357 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
360 IOCON_PinMuxSet(IOCON, 4, 12, IOCON_FUNC1 | IOCON_MODE_INACT |
361 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
364 IOCON_PinMuxSet(IOCON, 4, 13, IOCON_FUNC1 | IOCON_MODE_INACT |
365 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
368 IOCON_PinMuxSet(IOCON, 4, 14, IOCON_FUNC1 | IOCON_MODE_INACT |
369 IOCON_DIGITAL_EN | IOCON_INPFILT_OFF);
372 pinConfig.pinDirection = kGPIO_DigitalOutput;
373 pinConfig.outputLogic = 0;
374 GPIO_PinInit(GPIO, 2, 26, &pinConfig);
377 GPIO_PinWrite(GPIO, 2, 26, 0);
379 GPIO_PinWrite(GPIO, 2, 26, 1);
421 ENET->DMA_CH[0].DMA_CHX_TXDESC_LIST_ADDR = (uint32_t) &
txDmaDesc[0];
426 ENET->DMA_CH[0].DMA_CHX_RXDESC_LIST_ADDR = (uint32_t) &
rxDmaDesc[0];
444 if(interface->phyDriver != NULL)
447 interface->phyDriver->tick(interface);
449 else if(interface->switchDriver != NULL)
452 interface->switchDriver->tick(interface);
469 NVIC_EnableIRQ(ETHERNET_IRQn);
472 if(interface->phyDriver != NULL)
475 interface->phyDriver->enableIrq(interface);
477 else if(interface->switchDriver != NULL)
480 interface->switchDriver->enableIrq(interface);
497 NVIC_DisableIRQ(ETHERNET_IRQn);
500 if(interface->phyDriver != NULL)
503 interface->phyDriver->disableIrq(interface);
505 else if(interface->switchDriver != NULL)
508 interface->switchDriver->disableIrq(interface);
533 status = ENET->DMA_CH[0].DMA_CHX_STAT;
536 if((status & ENET_DMA_CH_DMA_CHX_STAT_TI_MASK) != 0)
539 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TI_MASK;
550 if((status & ENET_DMA_CH_DMA_CHX_STAT_RI_MASK) != 0)
553 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RI_MASK;
556 nicDriverInterface->nicEvent =
TRUE;
562 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_NIS_MASK;
633 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TBU_MASK;
635 ENET->DMA_CH[0].DMA_CHX_TXDESC_TAIL_PTR = 0;
721 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RBU_MASK;
723 ENET->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR = 0;
745 ENET->MAC_ADDR_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
746 ENET->MAC_ADDR_HIGH = interface->macAddr.w[2];
749 acceptMulticast =
FALSE;
756 if(interface->macAddrFilter[i].refCount > 0)
759 acceptMulticast =
TRUE;
768 ENET->MAC_FRAME_FILTER |= ENET_MAC_FRAME_FILTER_PM_MASK;
772 ENET->MAC_FRAME_FILTER &= ~ENET_MAC_FRAME_FILTER_PM_MASK;
791 config = ENET->MAC_CONFIG;
796 config |= ENET_MAC_CONFIG_FES_MASK;
800 config &= ~ENET_MAC_CONFIG_FES_MASK;
806 config |= ENET_MAC_CONFIG_DM_MASK;
810 config &= ~ENET_MAC_CONFIG_DM_MASK;
814 ENET->MAC_CONFIG = config;
838 temp = ENET->MAC_MDIO_ADDR & ENET_MAC_MDIO_ADDR_CR_MASK;
840 temp |= ENET_MAC_MDIO_ADDR_MOC(1) | ENET_MAC_MDIO_ADDR_MB_MASK;
842 temp |= ENET_MAC_MDIO_ADDR_PA(phyAddr);
844 temp |= ENET_MAC_MDIO_ADDR_RDA(
regAddr);
847 ENET->MAC_MDIO_DATA =
data & ENET_MAC_MDIO_DATA_MD_MASK;
850 ENET->MAC_MDIO_ADDR = temp;
852 while((ENET->MAC_MDIO_ADDR & ENET_MAC_MDIO_ADDR_MB_MASK) != 0)
881 temp = ENET->MAC_MDIO_ADDR & ENET_MAC_MDIO_ADDR_CR_MASK;
883 temp |= ENET_MAC_MDIO_ADDR_MOC(3) | ENET_MAC_MDIO_ADDR_MB_MASK;
885 temp |= ENET_MAC_MDIO_ADDR_PA(phyAddr);
887 temp |= ENET_MAC_MDIO_ADDR_RDA(
regAddr);
890 ENET->MAC_MDIO_ADDR = temp;
892 while((ENET->MAC_MDIO_ADDR & ENET_MAC_MDIO_ADDR_MB_MASK) != 0)
897 data = ENET->MAC_MDIO_DATA & ENET_MAC_MDIO_DATA_MD_MASK;