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 = 64
50 #pragma location = MCIMX6UL_ETH1_RAM_SECTION
53 #pragma data_alignment = 64
54 #pragma location = MCIMX6UL_ETH1_RAM_SECTION
57 #pragma data_alignment = 64
58 #pragma location = MCIMX6UL_ETH1_RAM_SECTION
61 #pragma data_alignment = 64
62 #pragma location = MCIMX6UL_ETH1_RAM_SECTION
84 static uint_t txBufferIndex;
86 static uint_t rxBufferIndex;
126 TRACE_INFO(
"Initializing i.MX6UL Ethernet MAC (ENET1)...\r\n");
129 nicDriverInterface = interface;
132 CLOCK_EnableClock(kCLOCK_Enet);
138 ENET1->ECR = ENET_ECR_RESET_MASK;
140 while((ENET1->ECR & ENET_ECR_RESET_MASK) != 0)
146 ENET_RCR_RMII_MODE_MASK | ENET_RCR_MII_MODE_MASK;
151 ENET1->MSCR = ENET_MSCR_HOLDTIME(10) | ENET_MSCR_MII_SPEED(120);
154 if(interface->phyDriver != NULL)
157 error = interface->phyDriver->init(interface);
159 else if(interface->switchDriver != NULL)
162 error = interface->switchDriver->init(interface);
177 value = interface->macAddr.b[5];
178 value |= (interface->macAddr.b[4] << 8);
179 ENET1->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
182 value = interface->macAddr.b[3];
183 value |= (interface->macAddr.b[2] << 8);
184 value |= (interface->macAddr.b[1] << 16);
185 value |= (interface->macAddr.b[0] << 24);
186 ENET1->PALR = ENET_PALR_PADDR1(
value);
201 ENET1->ECR = ENET_ECR_DBSWP_MASK | ENET_ECR_EN1588_MASK;
204 ENET1->MIBC = ENET_MIBC_MIB_CLEAR_MASK;
211 ENET1->EIR = 0xFFFFFFFF;
213 ENET1->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
219 ENET1->ECR |= ENET_ECR_ETHEREN_MASK;
221 ENET1->RDAR = ENET_RDAR_RDAR_MASK;
239 #if defined(USE_MCIMX6UL_EVKB) || defined(USE_MCIMX6ULL_EVK)
240 gpio_pin_config_t pinConfig;
241 clock_enet_pll_config_t pllConfig;
244 pllConfig.enableClkOutput0 =
true;
245 pllConfig.enableClkOutput1 =
true;
246 pllConfig.enableClkOutput2 =
false;
247 pllConfig.loopDivider0 = 1;
248 pllConfig.loopDivider1 = 1;
249 CLOCK_InitEnetPll(&pllConfig);
252 IOMUXC_GPR->GPR1 |= IOMUXC_GPR_GPR1_ENET1_TX_CLK_DIR(1);
255 CLOCK_EnableClock(kCLOCK_Iomuxc);
258 IOMUXC_SetPinMux(IOMUXC_ENET1_TX_CLK_ENET1_REF_CLK1, 1);
261 IOMUXC_SetPinConfig(IOMUXC_ENET1_TX_CLK_ENET1_REF_CLK1,
262 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
263 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
264 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
265 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
266 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
267 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
268 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
269 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
272 IOMUXC_SetPinMux(IOMUXC_ENET1_TX_EN_ENET1_TX_EN, 0);
275 IOMUXC_SetPinConfig(IOMUXC_ENET1_TX_EN_ENET1_TX_EN,
276 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
277 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
278 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
279 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
280 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
281 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
282 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
283 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
286 IOMUXC_SetPinMux(IOMUXC_ENET1_TX_DATA0_ENET1_TDATA00, 0);
289 IOMUXC_SetPinConfig(IOMUXC_ENET1_TX_DATA0_ENET1_TDATA00,
290 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
291 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
292 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
293 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
294 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
295 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
296 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
297 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
300 IOMUXC_SetPinMux(IOMUXC_ENET1_TX_DATA1_ENET1_TDATA01, 0);
303 IOMUXC_SetPinConfig(IOMUXC_ENET1_TX_DATA1_ENET1_TDATA01,
304 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
305 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
306 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
307 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
308 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
309 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
310 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
311 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
314 IOMUXC_SetPinMux(IOMUXC_ENET1_RX_EN_ENET1_RX_EN, 0);
317 IOMUXC_SetPinConfig(IOMUXC_ENET1_RX_EN_ENET1_RX_EN,
318 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
319 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
320 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
321 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
322 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
323 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
324 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
325 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
328 IOMUXC_SetPinMux(IOMUXC_ENET1_RX_ER_ENET1_RX_ER, 0);
331 IOMUXC_SetPinConfig(IOMUXC_ENET1_RX_ER_ENET1_RX_ER,
332 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
333 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
334 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
335 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
336 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
337 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
338 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
339 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
342 IOMUXC_SetPinMux(IOMUXC_ENET1_RX_DATA0_ENET1_RDATA00, 0);
345 IOMUXC_SetPinConfig(IOMUXC_ENET1_RX_DATA0_ENET1_RDATA00,
346 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
347 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
348 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
349 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
350 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
351 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
352 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
353 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
356 IOMUXC_SetPinMux(IOMUXC_ENET1_RX_DATA1_ENET1_RDATA01, 0);
359 IOMUXC_SetPinConfig(IOMUXC_ENET1_RX_DATA1_ENET1_RDATA01,
360 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
361 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
362 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
363 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
364 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
365 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
366 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
367 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
370 IOMUXC_SetPinMux(IOMUXC_GPIO1_IO06_ENET1_MDIO, 0);
373 IOMUXC_SetPinConfig(IOMUXC_GPIO1_IO06_ENET1_MDIO,
374 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
375 IOMUXC_SW_PAD_CTL_PAD_PUS(2) |
376 IOMUXC_SW_PAD_CTL_PAD_PUE(1) |
377 IOMUXC_SW_PAD_CTL_PAD_PKE(1) |
378 IOMUXC_SW_PAD_CTL_PAD_ODE(1) |
379 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
380 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
381 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
384 IOMUXC_SetPinMux(IOMUXC_GPIO1_IO07_ENET1_MDC, 0);
387 IOMUXC_SetPinConfig(IOMUXC_GPIO1_IO07_ENET1_MDC,
388 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
389 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
390 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
391 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
392 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
393 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
394 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
395 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
397 #if defined(USE_MCIMX6UL_EVKB)
399 IOMUXC_SetPinMux(IOMUXC_SNVS_TAMPER5_GPIO5_IO05, 0);
402 IOMUXC_SetPinConfig(IOMUXC_SNVS_TAMPER5_GPIO5_IO05,
403 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
404 IOMUXC_SW_PAD_CTL_PAD_PUS(2) |
405 IOMUXC_SW_PAD_CTL_PAD_PUE(1) |
406 IOMUXC_SW_PAD_CTL_PAD_PKE(1) |
407 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
408 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
409 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
410 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
412 #elif defined(USE_MCIMX6ULL_EVK)
414 IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER5_GPIO5_IO05, 0);
417 IOMUXC_SetPinConfig(IOMUXC_SNVS_SNVS_TAMPER5_GPIO5_IO05,
418 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
419 IOMUXC_SW_PAD_CTL_PAD_PUS(2) |
420 IOMUXC_SW_PAD_CTL_PAD_PUE(1) |
421 IOMUXC_SW_PAD_CTL_PAD_PKE(1) |
422 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
423 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
424 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
425 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
429 pinConfig.direction = kGPIO_DigitalInput;
430 pinConfig.outputLogic = 0;
431 pinConfig.interruptMode = kGPIO_NoIntmode;
432 GPIO_PinInit(GPIO5, 5, &pinConfig);
448 osMemset(txBufferDesc, 0,
sizeof(txBufferDesc));
449 osMemset(rxBufferDesc, 0,
sizeof(rxBufferDesc));
486 ENET1->TDSR = (uint32_t) txBufferDesc;
488 ENET1->RDSR = (uint32_t) rxBufferDesc;
506 if(interface->phyDriver != NULL)
509 interface->phyDriver->tick(interface);
511 else if(interface->switchDriver != NULL)
514 interface->switchDriver->tick(interface);
531 GIC_EnableIRQ(ENET1_IRQn);
534 if(interface->phyDriver != NULL)
537 interface->phyDriver->enableIrq(interface);
539 else if(interface->switchDriver != NULL)
542 interface->switchDriver->enableIrq(interface);
559 GIC_DisableIRQ(ENET1_IRQn);
562 if(interface->phyDriver != NULL)
565 interface->phyDriver->disableIrq(interface);
567 else if(interface->switchDriver != NULL)
570 interface->switchDriver->disableIrq(interface);
599 if((events & ENET_EIR_TXF_MASK) != 0)
602 ENET1->EIR = ENET_EIR_TXF_MASK;
605 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
612 ENET1->TDAR = ENET_TDAR_TDAR_MASK;
616 if((events & ENET_EIR_RXF_MASK) != 0)
619 ENET1->EIMR &= ~ENET_EIMR_RXF_MASK;
622 nicDriverInterface->nicEvent =
TRUE;
628 if((events & ENET_EIR_EBERR_MASK) != 0)
631 ENET1->EIMR &= ~ENET_EIMR_EBERR_MASK;
634 nicDriverInterface->nicEvent =
TRUE;
658 if((status & ENET_EIR_RXF_MASK) != 0)
661 ENET1->EIR = ENET_EIR_RXF_MASK;
674 if((status & ENET_EIR_EBERR_MASK) != 0)
677 ENET1->EIR = ENET_EIR_EBERR_MASK;
680 ENET1->ECR &= ~ENET_ECR_ETHEREN_MASK;
684 ENET1->ECR |= ENET_ECR_ETHEREN_MASK;
686 ENET1->RDAR = ENET_RDAR_RDAR_MASK;
690 ENET1->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
723 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) != 0)
733 txBufferDesc[txBufferIndex][4] = 0;
759 ENET1->TDAR = ENET_TDAR_TDAR_MASK;
762 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
787 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_E) == 0)
790 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_L) != 0)
826 rxBufferDesc[rxBufferIndex][4] = 0;
845 ENET1->RDAR = ENET_RDAR_RDAR_MASK;
870 uint32_t unicastHashTable[2];
871 uint32_t multicastHashTable[2];
878 value = interface->macAddr.b[5];
879 value |= (interface->macAddr.b[4] << 8);
880 ENET1->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
883 value = interface->macAddr.b[3];
884 value |= (interface->macAddr.b[2] << 8);
885 value |= (interface->macAddr.b[1] << 16);
886 value |= (interface->macAddr.b[0] << 24);
887 ENET1->PALR = ENET_PALR_PADDR1(
value);
890 unicastHashTable[0] = 0;
891 unicastHashTable[1] = 0;
894 multicastHashTable[0] = 0;
895 multicastHashTable[1] = 0;
902 entry = &interface->macAddrFilter[i];
912 k = (crc >> 26) & 0x3F;
918 multicastHashTable[k / 32] |= (1 << (k % 32));
923 unicastHashTable[k / 32] |= (1 << (k % 32));
929 ENET1->IALR = unicastHashTable[0];
930 ENET1->IAUR = unicastHashTable[1];
933 ENET1->GALR = multicastHashTable[0];
934 ENET1->GAUR = multicastHashTable[1];
937 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", ENET1->IALR);
938 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", ENET1->IAUR);
939 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", ENET1->GALR);
940 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", ENET1->GAUR);
956 ENET1->ECR &= ~ENET_ECR_ETHEREN_MASK;
962 ENET1->RCR &= ~ENET_RCR_RMII_10T_MASK;
967 ENET1->RCR |= ENET_RCR_RMII_10T_MASK;
974 ENET1->TCR |= ENET_TCR_FDEN_MASK;
976 ENET1->RCR &= ~ENET_RCR_DRT_MASK;
981 ENET1->TCR &= ~ENET_TCR_FDEN_MASK;
983 ENET1->RCR |= ENET_RCR_DRT_MASK;
990 ENET1->ECR |= ENET_ECR_ETHEREN_MASK;
992 ENET1->RDAR = ENET_RDAR_RDAR_MASK;
1016 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
1018 temp |= ENET_MMFR_PA(phyAddr);
1020 temp |= ENET_MMFR_RA(
regAddr);
1022 temp |= ENET_MMFR_DATA(
data);
1025 ENET1->EIR = ENET_EIR_MII_MASK;
1030 while((ENET1->EIR & ENET_EIR_MII_MASK) == 0)
1059 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
1061 temp |= ENET_MMFR_PA(phyAddr);
1063 temp |= ENET_MMFR_RA(
regAddr);
1066 ENET1->EIR = ENET_EIR_MII_MASK;
1071 while((ENET1->EIR & ENET_EIR_MII_MASK) == 0)
1076 data = ENET1->MMFR & ENET_MMFR_DATA_MASK;
1104 p = (uint8_t *)
data;
1109 for(i = 0; i <
length; i++)
1115 for(j = 0; j < 8; j++)
1117 if((crc & 0x01) != 0)
1119 crc = (crc >> 1) ^ 0xEDB88320;