32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include "fsl_device_registers.h"
37 #include "fsl_iomuxc.h"
46 #if defined(__ICCARM__)
49 #pragma data_alignment = 4
50 #pragma location = MIMXRT1170_ETH3_RAM_SECTION
53 #pragma data_alignment = 4
54 #pragma location = MIMXRT1170_ETH3_RAM_SECTION
57 #pragma data_alignment = 8
58 #pragma location = MIMXRT1170_ETH3_RAM_SECTION
61 #pragma data_alignment = 8
62 #pragma location = MIMXRT1170_ETH3_RAM_SECTION
126 TRACE_INFO(
"Initializing i.MX RT1170 Ethernet MAC (ENET_QOS)...\r\n");
129 nicDriverInterface = interface;
132 CLOCK_EnableClock(kCLOCK_Enet_Qos);
138 ENET_QOS->DMA_MODE |= ENET_QOS_DMA_MODE_SWR_MASK;
140 while((ENET_QOS->DMA_MODE & ENET_QOS_DMA_MODE_SWR_MASK) != 0)
145 ENET_QOS->MAC_MDIO_ADDRESS = ENET_QOS_MAC_MDIO_ADDRESS_CR(7);
148 if(interface->phyDriver != NULL)
151 error = interface->phyDriver->init(interface);
153 else if(interface->switchDriver != NULL)
156 error = interface->switchDriver->init(interface);
171 ENET_QOS->MAC_CONFIGURATION = ENET_QOS_MAC_CONFIGURATION_GPSLCE_MASK |
172 ENET_QOS_MAC_CONFIGURATION_DO_MASK;
175 temp = ENET_QOS->MAC_EXT_CONFIGURATION & ~ENET_QOS_MAC_EXT_CONFIGURATION_GPSL_MASK;
182 ENET_QOS->MAC_TX_FLOW_CTRL_Q[0] = 0;
183 ENET_QOS->MAC_RX_FLOW_CTRL = 0;
186 ENET_QOS->MAC_RXQ_CTRL[0] = ENET_QOS_MAC_RXQ_CTRL_RXQ0EN(2);
189 ENET_QOS->DMA_MODE = ENET_QOS_DMA_MODE_INTM(0) | ENET_QOS_DMA_MODE_DSPW(0);
191 ENET_QOS->DMA_SYSBUS_MODE |= ENET_QOS_DMA_SYSBUS_MODE_AAL_MASK;
194 ENET_QOS->DMA_CH[0].DMA_CHX_CTRL = ENET_QOS_DMA_CHX_CTRL_DSL(0);
196 ENET_QOS->DMA_CH[0].DMA_CHX_TX_CTRL = ENET_QOS_DMA_CHX_TX_CTRL_TxPBL(32);
199 ENET_QOS->DMA_CH[0].DMA_CHX_RX_CTRL = ENET_QOS_DMA_CHX_RX_CTRL_RxPBL(32) |
203 ENET_QOS->MTL_QUEUE[0].MTL_TXQX_OP_MODE |= ENET_QOS_MTL_TXQX_OP_MODE_TQS(7) |
204 ENET_QOS_MTL_TXQX_OP_MODE_TXQEN(2) | ENET_QOS_MTL_TXQX_OP_MODE_TSF_MASK;
207 ENET_QOS->MTL_QUEUE[0].MTL_RXQX_OP_MODE |= ENET_QOS_MTL_RXQX_OP_MODE_RQS(7) |
208 ENET_QOS_MTL_RXQX_OP_MODE_RSF_MASK;
215 ENET_QOS->MAC_MMC_TX_INTERRUPT_MASK = 0xFFFFFFFF;
216 ENET_QOS->MAC_MMC_RX_INTERRUPT_MASK = 0xFFFFFFFF;
217 ENET_QOS->MAC_MMC_IPC_RX_INTERRUPT_MASK = 0xFFFFFFFF;
220 ENET_QOS->MAC_INTERRUPT_ENABLE = 0;
223 ENET_QOS->DMA_CH[0].DMA_CHX_INT_EN = ENET_QOS_DMA_CHX_INT_EN_NIE_MASK |
224 ENET_QOS_DMA_CHX_INT_EN_RIE_MASK | ENET_QOS_DMA_CHX_INT_EN_TIE_MASK;
234 ENET_QOS->MAC_CONFIGURATION |= ENET_QOS_MAC_CONFIGURATION_TE_MASK |
235 ENET_QOS_MAC_CONFIGURATION_RE_MASK;
238 ENET_QOS->DMA_CH[0].DMA_CHX_TX_CTRL |= ENET_QOS_DMA_CHX_TX_CTRL_ST_MASK;
239 ENET_QOS->DMA_CH[0].DMA_CHX_RX_CTRL |= ENET_QOS_DMA_CHX_RX_CTRL_SR_MASK;
257 #if defined(USE_MIMXRT1170_EVK)
259 gpio_pin_config_t pinConfig;
260 clock_root_config_t rootConfig = {0};
262 clock_sys_pll1_config_t sysPll1Config = {0};
265 sysPll1Config.pllDiv2En =
true;
266 CLOCK_InitSysPll1(&sysPll1Config);
270 rootConfig.clockOff =
false;
271 rootConfig.mux = kCLOCK_ENET_QOS_ClockRoot_MuxSysPll1Div2;
273 CLOCK_SetRootClock(kCLOCK_Root_Enet_Qos, &rootConfig);
277 CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd3, 24);
280 rootConfig.clockOff =
false;
281 rootConfig.mux = kCLOCK_BUS_ClockRoot_MuxSysPll2Pfd3;
283 CLOCK_SetRootClock(kCLOCK_Root_Bus, &rootConfig);
287 temp = IOMUXC_GPR->GPR6 & ~IOMUXC_GPR_GPR6_ENET_QOS_INTF_SEL_MASK;
288 IOMUXC_GPR->GPR6 = temp | IOMUXC_GPR_GPR6_ENET_QOS_INTF_SEL(1);
291 IOMUXC_GPR->GPR6 |= IOMUXC_GPR_GPR6_ENET_QOS_CLKGEN_EN_MASK;
293 IOMUXC_GPR->GPR6 |= IOMUXC_GPR_GPR6_ENET_QOS_RGMII_EN_MASK;
296 CLOCK_EnableClock(kCLOCK_Iomuxc);
299 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_00_ENET_QOS_RX_EN, 0);
302 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_00_ENET_QOS_RX_EN,
303 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
304 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
305 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
306 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
307 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
310 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_01_ENET_QOS_RX_CLK, 0);
313 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_01_ENET_QOS_RX_CLK,
314 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
315 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
316 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
317 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
318 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
321 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_02_ENET_QOS_RX_DATA00, 0);
324 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_02_ENET_QOS_RX_DATA00,
325 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
326 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
327 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
328 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
329 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
332 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_03_ENET_QOS_RX_DATA01, 0);
335 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_03_ENET_QOS_RX_DATA01,
336 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
337 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
338 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
339 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
340 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
343 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_04_ENET_QOS_RX_DATA02, 0);
346 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_04_ENET_QOS_RX_DATA02,
347 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
348 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
349 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
350 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
351 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
354 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_05_ENET_QOS_RX_DATA03, 0);
357 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_05_ENET_QOS_RX_DATA03,
358 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
359 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
360 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
361 IOMUXC_SW_PAD_CTL_PAD_PULL(2) |
362 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
365 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_06_ENET_QOS_TX_DATA03, 0);
368 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_06_ENET_QOS_TX_DATA03,
369 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
370 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
371 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
372 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
373 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
376 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_07_ENET_QOS_TX_DATA02, 0);
379 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_07_ENET_QOS_TX_DATA02,
380 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
381 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
382 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
383 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
384 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
387 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_08_ENET_QOS_TX_DATA01, 0);
390 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_08_ENET_QOS_TX_DATA01,
391 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
392 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
393 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
394 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
395 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
398 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_09_ENET_QOS_TX_DATA00, 0);
401 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_09_ENET_QOS_TX_DATA00,
402 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
403 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
404 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
405 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
406 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
409 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_10_ENET_QOS_TX_EN, 0);
412 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_10_ENET_QOS_TX_EN,
413 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
414 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
415 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
416 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
417 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
420 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B1_11_ENET_QOS_TX_CLK, 0);
423 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B1_11_ENET_QOS_TX_CLK,
424 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
425 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
426 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
427 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
428 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
431 IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_B2_19_ENET_QOS_MDC, 0);
434 IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_B2_19_ENET_QOS_MDC,
435 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
436 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
437 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
438 IOMUXC_SW_PAD_CTL_PAD_PULL(3) |
439 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
442 IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_B2_20_ENET_QOS_MDIO, 0);
445 IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_B2_20_ENET_QOS_MDIO,
446 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
447 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
448 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
449 IOMUXC_SW_PAD_CTL_PAD_PULL(1) |
450 IOMUXC_SW_PAD_CTL_PAD_PDRV(0));
453 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B2_13_GPIO11_IO14, 0);
456 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B2_13_GPIO11_IO14,
457 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
458 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
459 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
460 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
461 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
462 IOMUXC_SW_PAD_CTL_PAD_DSE(1) |
463 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
466 IOMUXC_SetPinMux(IOMUXC_GPIO_DISP_B2_12_GPIO11_IO13, 0);
469 IOMUXC_SetPinConfig(IOMUXC_GPIO_DISP_B2_12_GPIO11_IO13,
470 IOMUXC_SW_PAD_CTL_PAD_DWP_LOCK(0) |
471 IOMUXC_SW_PAD_CTL_PAD_DWP(0) |
472 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
473 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
474 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
475 IOMUXC_SW_PAD_CTL_PAD_DSE(1) |
476 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
479 pinConfig.direction = kGPIO_DigitalOutput;
480 pinConfig.outputLogic = 0;
481 pinConfig.interruptMode = kGPIO_NoIntmode;
482 GPIO_PinInit(GPIO11, 14, &pinConfig);
485 pinConfig.direction = kGPIO_DigitalInput;
486 pinConfig.outputLogic = 0;
487 pinConfig.interruptMode = kGPIO_NoIntmode;
488 GPIO_PinInit(GPIO11, 13, &pinConfig);
491 GPIO_PinWrite(GPIO11, 14, 0);
493 GPIO_PinWrite(GPIO11, 14, 1);
535 ENET_QOS->DMA_CH[0].DMA_CHX_TXDESC_LIST_ADDR = (uint32_t) &
txDmaDesc[0];
540 ENET_QOS->DMA_CH[0].DMA_CHX_RXDESC_LIST_ADDR = (uint32_t) &
rxDmaDesc[0];
558 if(interface->phyDriver != NULL)
561 interface->phyDriver->tick(interface);
563 else if(interface->switchDriver != NULL)
566 interface->switchDriver->tick(interface);
583 NVIC_EnableIRQ(ENET_QOS_IRQn);
586 if(interface->phyDriver != NULL)
589 interface->phyDriver->enableIrq(interface);
591 else if(interface->switchDriver != NULL)
594 interface->switchDriver->enableIrq(interface);
611 NVIC_DisableIRQ(ENET_QOS_IRQn);
614 if(interface->phyDriver != NULL)
617 interface->phyDriver->disableIrq(interface);
619 else if(interface->switchDriver != NULL)
622 interface->switchDriver->disableIrq(interface);
647 status = ENET_QOS->DMA_CH[0].DMA_CHX_STAT;
650 if((status & ENET_QOS_DMA_CHX_STAT_TI_MASK) != 0)
653 ENET_QOS->DMA_CH[0].DMA_CHX_STAT = ENET_QOS_DMA_CHX_STAT_TI_MASK;
664 if((status & ENET_QOS_DMA_CHX_STAT_RI_MASK) != 0)
667 ENET_QOS->DMA_CH[0].DMA_CHX_STAT = ENET_QOS_DMA_CHX_STAT_RI_MASK;
670 nicDriverInterface->nicEvent =
TRUE;
676 ENET_QOS->DMA_CH[0].DMA_CHX_STAT = ENET_QOS_DMA_CHX_STAT_NIS_MASK;
750 ENET_QOS->DMA_CH[0].DMA_CHX_STAT = ENET_QOS_DMA_CHX_STAT_TBU_MASK;
752 ENET_QOS->DMA_CH[0].DMA_CHX_TXDESC_TAIL_PTR = 0;
838 ENET_QOS->DMA_CH[0].DMA_CHX_STAT = ENET_QOS_DMA_CHX_STAT_RBU_MASK;
840 ENET_QOS->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR = 0;
863 ENET_QOS->MAC_PACKET_FILTER = 0;
866 ENET_QOS->MAC_ADDRESS[0].LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
867 ENET_QOS->MAC_ADDRESS[0].HIGH = interface->macAddr.w[2];
874 entry = &interface->macAddrFilter[i];
880 ENET_QOS->MAC_ADDRESS[j].LOW = entry->
addr.w[0] | (entry->
addr.w[1] << 16);
881 ENET_QOS->MAC_ADDRESS[j].HIGH = entry->
addr.w[2] | ENET_QOS_HIGH_AE_MASK;
892 ENET_QOS->MAC_ADDRESS[j].LOW = 0;
893 ENET_QOS->MAC_ADDRESS[j].HIGH = 0;
915 config = ENET_QOS->MAC_CONFIGURATION;
920 config &= ~ENET_QOS_MAC_CONFIGURATION_PS_MASK;
921 config &= ~ENET_QOS_MAC_CONFIGURATION_FES_MASK;
926 config |= ENET_QOS_MAC_CONFIGURATION_PS_MASK;
927 config |= ENET_QOS_MAC_CONFIGURATION_FES_MASK;
932 config |= ENET_QOS_MAC_CONFIGURATION_PS_MASK;
933 config &= ~ENET_QOS_MAC_CONFIGURATION_FES_MASK;
939 config |= ENET_QOS_MAC_CONFIGURATION_DM_MASK;
943 config &= ~ENET_QOS_MAC_CONFIGURATION_DM_MASK;
947 ENET_QOS->MAC_CONFIGURATION = config;
971 temp = ENET_QOS->MAC_MDIO_ADDRESS & ENET_QOS_MAC_MDIO_ADDRESS_CR_MASK;
974 temp |= ENET_QOS_MAC_MDIO_ADDRESS_GOC_0_MASK |
975 ENET_QOS_MAC_MDIO_ADDRESS_GB_MASK;
978 temp |= ENET_QOS_MAC_MDIO_ADDRESS_PA(phyAddr);
980 temp |= ENET_QOS_MAC_MDIO_ADDRESS_RDA(
regAddr);
983 ENET_QOS->MAC_MDIO_DATA =
data & ENET_QOS_MAC_MDIO_DATA_GD_MASK;
986 ENET_QOS->MAC_MDIO_ADDRESS = temp;
988 while((ENET_QOS->MAC_MDIO_ADDRESS & ENET_QOS_MAC_MDIO_ADDRESS_GB_MASK) != 0)
1017 temp = ENET_QOS->MAC_MDIO_ADDRESS & ENET_QOS_MAC_MDIO_ADDRESS_CR_MASK;
1020 temp |= ENET_QOS_MAC_MDIO_ADDRESS_GOC_1_MASK |
1021 ENET_QOS_MAC_MDIO_ADDRESS_GOC_0_MASK | ENET_QOS_MAC_MDIO_ADDRESS_GB_MASK;
1024 temp |= ENET_QOS_MAC_MDIO_ADDRESS_PA(phyAddr);
1026 temp |= ENET_QOS_MAC_MDIO_ADDRESS_RDA(
regAddr);
1029 ENET_QOS->MAC_MDIO_ADDRESS = temp;
1031 while((ENET_QOS->MAC_MDIO_ADDRESS & ENET_QOS_MAC_MDIO_ADDRESS_GB_MASK) != 0)
1036 data = ENET_QOS->MAC_MDIO_DATA & ENET_QOS_MAC_MDIO_DATA_GD_MASK;