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_ETH2_RAM_SECTION
53 #pragma data_alignment = 64
54 #pragma location = MCIMX6UL_ETH2_RAM_SECTION
57 #pragma data_alignment = 64
58 #pragma location = MCIMX6UL_ETH2_RAM_SECTION
61 #pragma data_alignment = 64
62 #pragma location = MCIMX6UL_ETH2_RAM_SECTION
84 static uint_t txBufferIndex;
86 static uint_t rxBufferIndex;
126 TRACE_INFO(
"Initializing i.MX6UL Ethernet MAC (ENET2)...\r\n");
129 nicDriverInterface = interface;
132 CLOCK_EnableClock(kCLOCK_Enet);
138 ENET2->ECR = ENET_ECR_RESET_MASK;
140 while((ENET2->ECR & ENET_ECR_RESET_MASK) != 0)
146 ENET_RCR_RMII_MODE_MASK | ENET_RCR_MII_MODE_MASK;
151 ENET2->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 ENET2->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 ENET2->PALR = ENET_PALR_PADDR1(
value);
201 ENET2->ECR = ENET_ECR_DBSWP_MASK | ENET_ECR_EN1588_MASK;
204 ENET2->MIBC = ENET_MIBC_MIB_CLEAR_MASK;
211 ENET2->EIR = 0xFFFFFFFF;
213 ENET2->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
219 ENET2->ECR |= ENET_ECR_ETHEREN_MASK;
221 ENET2->RDAR = ENET_RDAR_RDAR_MASK;
239 #if defined(USE_MCIMX6UL_EVKB) || defined(USE_MCIMX6ULL_EVK)
240 gpio_pin_config_t pinConfig;
243 IOMUXC_GPR->GPR1 |= IOMUXC_GPR_GPR1_ENET2_TX_CLK_DIR(1);
246 CLOCK_EnableClock(kCLOCK_Iomuxc);
249 IOMUXC_SetPinMux(IOMUXC_ENET2_TX_CLK_ENET2_REF_CLK2, 1);
252 IOMUXC_SetPinConfig(IOMUXC_ENET2_TX_CLK_ENET2_REF_CLK2,
253 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
254 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
255 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
256 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
257 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
258 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
259 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
260 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
263 IOMUXC_SetPinMux(IOMUXC_ENET2_TX_EN_ENET2_TX_EN, 0);
266 IOMUXC_SetPinConfig(IOMUXC_ENET2_TX_EN_ENET2_TX_EN,
267 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
268 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
269 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
270 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
271 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
272 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
273 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
274 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
277 IOMUXC_SetPinMux(IOMUXC_ENET2_TX_DATA0_ENET2_TDATA00, 0);
280 IOMUXC_SetPinConfig(IOMUXC_ENET2_TX_DATA0_ENET2_TDATA00,
281 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
282 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
283 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
284 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
285 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
286 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
287 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
288 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
291 IOMUXC_SetPinMux(IOMUXC_ENET2_TX_DATA1_ENET2_TDATA01, 0);
294 IOMUXC_SetPinConfig(IOMUXC_ENET2_TX_DATA1_ENET2_TDATA01,
295 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
296 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
297 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
298 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
299 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
300 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
301 IOMUXC_SW_PAD_CTL_PAD_DSE(5) |
302 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
305 IOMUXC_SetPinMux(IOMUXC_ENET2_RX_EN_ENET2_RX_EN, 0);
308 IOMUXC_SetPinConfig(IOMUXC_ENET2_RX_EN_ENET2_RX_EN,
309 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
310 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
311 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
312 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
313 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
314 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
315 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
316 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
319 IOMUXC_SetPinMux(IOMUXC_ENET2_RX_ER_ENET2_RX_ER, 0);
322 IOMUXC_SetPinConfig(IOMUXC_ENET2_RX_ER_ENET2_RX_ER,
323 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
324 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
325 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
326 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
327 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
328 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
329 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
330 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
333 IOMUXC_SetPinMux(IOMUXC_ENET2_RX_DATA0_ENET2_RDATA00, 0);
336 IOMUXC_SetPinConfig(IOMUXC_ENET2_RX_DATA0_ENET2_RDATA00,
337 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
338 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
339 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
340 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
341 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
342 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
343 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
344 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
347 IOMUXC_SetPinMux(IOMUXC_ENET2_RX_DATA1_ENET2_RDATA01, 0);
350 IOMUXC_SetPinConfig(IOMUXC_ENET2_RX_DATA1_ENET2_RDATA01,
351 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
352 IOMUXC_SW_PAD_CTL_PAD_PUS(0) |
353 IOMUXC_SW_PAD_CTL_PAD_PUE(0) |
354 IOMUXC_SW_PAD_CTL_PAD_PKE(0) |
355 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
356 IOMUXC_SW_PAD_CTL_PAD_SPEED(3) |
357 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
358 IOMUXC_SW_PAD_CTL_PAD_SRE(1));
360 #if defined(USE_MCIMX6UL_EVKB)
362 IOMUXC_SetPinMux(IOMUXC_SNVS_TAMPER6_GPIO5_IO06, 0);
365 IOMUXC_SetPinConfig(IOMUXC_SNVS_TAMPER6_GPIO5_IO06,
366 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
367 IOMUXC_SW_PAD_CTL_PAD_PUS(2) |
368 IOMUXC_SW_PAD_CTL_PAD_PUE(1) |
369 IOMUXC_SW_PAD_CTL_PAD_PKE(1) |
370 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
371 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
372 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
373 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
375 #elif defined(USE_MCIMX6ULL_EVK)
377 IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER6_GPIO5_IO06, 0);
380 IOMUXC_SetPinConfig(IOMUXC_SNVS_SNVS_TAMPER6_GPIO5_IO06,
381 IOMUXC_SW_PAD_CTL_PAD_HYS(0) |
382 IOMUXC_SW_PAD_CTL_PAD_PUS(2) |
383 IOMUXC_SW_PAD_CTL_PAD_PUE(1) |
384 IOMUXC_SW_PAD_CTL_PAD_PKE(1) |
385 IOMUXC_SW_PAD_CTL_PAD_ODE(0) |
386 IOMUXC_SW_PAD_CTL_PAD_SPEED(0) |
387 IOMUXC_SW_PAD_CTL_PAD_DSE(0) |
388 IOMUXC_SW_PAD_CTL_PAD_SRE(0));
392 pinConfig.direction = kGPIO_DigitalInput;
393 pinConfig.outputLogic = 0;
394 pinConfig.interruptMode = kGPIO_NoIntmode;
395 GPIO_PinInit(GPIO5, 6, &pinConfig);
411 osMemset(txBufferDesc, 0,
sizeof(txBufferDesc));
412 osMemset(rxBufferDesc, 0,
sizeof(rxBufferDesc));
449 ENET2->TDSR = (uint32_t) txBufferDesc;
451 ENET2->RDSR = (uint32_t) rxBufferDesc;
469 if(interface->phyDriver != NULL)
472 interface->phyDriver->tick(interface);
474 else if(interface->switchDriver != NULL)
477 interface->switchDriver->tick(interface);
494 GIC_EnableIRQ(ENET2_IRQn);
497 if(interface->phyDriver != NULL)
500 interface->phyDriver->enableIrq(interface);
502 else if(interface->switchDriver != NULL)
505 interface->switchDriver->enableIrq(interface);
522 GIC_DisableIRQ(ENET2_IRQn);
525 if(interface->phyDriver != NULL)
528 interface->phyDriver->disableIrq(interface);
530 else if(interface->switchDriver != NULL)
533 interface->switchDriver->disableIrq(interface);
562 if((events & ENET_EIR_TXF_MASK) != 0)
565 ENET2->EIR = ENET_EIR_TXF_MASK;
568 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
575 ENET2->TDAR = ENET_TDAR_TDAR_MASK;
579 if((events & ENET_EIR_RXF_MASK) != 0)
582 ENET2->EIMR &= ~ENET_EIMR_RXF_MASK;
585 nicDriverInterface->nicEvent =
TRUE;
591 if((events & ENET_EIR_EBERR_MASK) != 0)
594 ENET2->EIMR &= ~ENET_EIMR_EBERR_MASK;
597 nicDriverInterface->nicEvent =
TRUE;
621 if((status & ENET_EIR_RXF_MASK) != 0)
624 ENET2->EIR = ENET_EIR_RXF_MASK;
637 if((status & ENET_EIR_EBERR_MASK) != 0)
640 ENET2->EIR = ENET_EIR_EBERR_MASK;
643 ENET2->ECR &= ~ENET_ECR_ETHEREN_MASK;
647 ENET2->ECR |= ENET_ECR_ETHEREN_MASK;
649 ENET2->RDAR = ENET_RDAR_RDAR_MASK;
653 ENET2->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
686 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) != 0)
696 txBufferDesc[txBufferIndex][4] = 0;
722 ENET2->TDAR = ENET_TDAR_TDAR_MASK;
725 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
750 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_E) == 0)
753 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_L) != 0)
789 rxBufferDesc[rxBufferIndex][4] = 0;
808 ENET2->RDAR = ENET_RDAR_RDAR_MASK;
833 uint32_t unicastHashTable[2];
834 uint32_t multicastHashTable[2];
841 value = interface->macAddr.b[5];
842 value |= (interface->macAddr.b[4] << 8);
843 ENET2->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
846 value = interface->macAddr.b[3];
847 value |= (interface->macAddr.b[2] << 8);
848 value |= (interface->macAddr.b[1] << 16);
849 value |= (interface->macAddr.b[0] << 24);
850 ENET2->PALR = ENET_PALR_PADDR1(
value);
853 unicastHashTable[0] = 0;
854 unicastHashTable[1] = 0;
857 multicastHashTable[0] = 0;
858 multicastHashTable[1] = 0;
865 entry = &interface->macAddrFilter[i];
875 k = (crc >> 26) & 0x3F;
881 multicastHashTable[k / 32] |= (1 << (k % 32));
886 unicastHashTable[k / 32] |= (1 << (k % 32));
892 ENET2->IALR = unicastHashTable[0];
893 ENET2->IAUR = unicastHashTable[1];
896 ENET2->GALR = multicastHashTable[0];
897 ENET2->GAUR = multicastHashTable[1];
900 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", ENET2->IALR);
901 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", ENET2->IAUR);
902 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", ENET2->GALR);
903 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", ENET2->GAUR);
919 ENET2->ECR &= ~ENET_ECR_ETHEREN_MASK;
925 ENET2->RCR &= ~ENET_RCR_RMII_10T_MASK;
930 ENET2->RCR |= ENET_RCR_RMII_10T_MASK;
937 ENET2->TCR |= ENET_TCR_FDEN_MASK;
939 ENET2->RCR &= ~ENET_RCR_DRT_MASK;
944 ENET2->TCR &= ~ENET_TCR_FDEN_MASK;
946 ENET2->RCR |= ENET_RCR_DRT_MASK;
953 ENET2->ECR |= ENET_ECR_ETHEREN_MASK;
955 ENET2->RDAR = ENET_RDAR_RDAR_MASK;
979 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
981 temp |= ENET_MMFR_PA(phyAddr);
985 temp |= ENET_MMFR_DATA(
data);
988 ENET2->EIR = ENET_EIR_MII_MASK;
993 while((ENET2->EIR & ENET_EIR_MII_MASK) == 0)
1022 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
1024 temp |= ENET_MMFR_PA(phyAddr);
1026 temp |= ENET_MMFR_RA(
regAddr);
1029 ENET2->EIR = ENET_EIR_MII_MASK;
1034 while((ENET2->EIR & ENET_EIR_MII_MASK) == 0)
1039 data = ENET2->MMFR & ENET_MMFR_DATA_MASK;
1067 p = (uint8_t *)
data;
1072 for(i = 0; i <
length; i++)
1078 for(j = 0; j < 8; j++)
1080 if((crc & 0x01) != 0)
1082 crc = (crc >> 1) ^ 0xEDB88320;