32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include "device_registers.h"
36 #include "interrupt_manager.h"
58 static uint_t txBufferIndex;
60 static uint_t rxBufferIndex;
100 TRACE_INFO(
"Initializing MPC5748 Ethernet MAC (ENET0)...\r\n");
103 nicDriverInterface = interface;
109 ENET_0->ECR = ENET_ECR_RESET_MASK;
111 while((ENET_0->ECR & ENET_ECR_RESET_MASK) != 0)
115 #if defined(USE_DEVKIT_MPC5748G)
118 ENET_RCR_RMII_MODE_MASK | ENET_RCR_MII_MODE_MASK;
122 ENET_RCR_MII_MODE_MASK;
128 ENET_0->MSCR = ENET_MSCR_MII_SPEED(19);
131 if(interface->phyDriver != NULL)
134 error = interface->phyDriver->init(interface);
136 else if(interface->switchDriver != NULL)
139 error = interface->switchDriver->init(interface);
154 value = interface->macAddr.b[5];
155 value |= (interface->macAddr.b[4] << 8);
156 ENET_0->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
159 value = interface->macAddr.b[3];
160 value |= (interface->macAddr.b[2] << 8);
161 value |= (interface->macAddr.b[1] << 16);
162 value |= (interface->macAddr.b[0] << 24);
163 ENET_0->PALR = ENET_PALR_PADDR1(
value);
178 ENET_0->ECR = ENET_ECR_EN1588_MASK;
181 ENET_0->MIBC = ENET_MIBC_MIB_CLEAR_MASK;
188 ENET_0->EIR = 0xFFFFFFFF;
190 ENET_0->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
200 ENET_0->ECR |= ENET_ECR_ETHEREN_MASK;
202 ENET_0->RDAR = ENET_RDAR_RDAR_MASK;
220 #if defined(USE_DEVKIT_MPC5748G)
222 SIUL2->MSCR[94] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
223 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK | SIUL2_MSCR_PUS_MASK |
224 SIUL2_MSCR_PUE_MASK | SIUL2_MSCR_SSS(4);
225 SIUL2->IMCR[450] = SIUL2_IMCR_SSS(1);
228 SIUL2->MSCR[96] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
229 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
232 SIUL2->MSCR[97] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
233 SIUL2->IMCR[449] = SIUL2_IMCR_SSS(1);
236 SIUL2->MSCR[114] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
237 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
240 SIUL2->MSCR[113] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
241 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
244 SIUL2->MSCR[112] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
245 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
248 SIUL2->MSCR[95] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
249 SIUL2->IMCR[457] = SIUL2_IMCR_SSS(1);
252 SIUL2->MSCR[11] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
253 SIUL2->IMCR[455] = SIUL2_IMCR_SSS(1);
256 SIUL2->MSCR[9] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
257 SIUL2->IMCR[451] = SIUL2_IMCR_SSS(1);
260 SIUL2->MSCR[8] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
261 SIUL2->IMCR[452] = SIUL2_IMCR_SSS(1);
264 #elif defined(USE_MPC5748G_LCEVB)
266 SIUL2->MSCR[94] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
267 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK | SIUL2_MSCR_PUS_MASK |
268 SIUL2_MSCR_PUE_MASK | SIUL2_MSCR_SSS(4);
269 SIUL2->IMCR[450] = SIUL2_IMCR_SSS(1);
272 SIUL2->MSCR[96] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
273 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
276 SIUL2->MSCR[97] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
277 SIUL2->IMCR[449] = SIUL2_IMCR_SSS(1);
280 SIUL2->MSCR[114] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
281 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
284 SIUL2->MSCR[113] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
285 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
288 SIUL2->MSCR[112] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
289 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
292 SIUL2->MSCR[108] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
293 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
296 SIUL2->MSCR[109] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
297 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
300 SIUL2->MSCR[3] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
301 SIUL2->IMCR[448] = SIUL2_IMCR_SSS(1);
304 SIUL2->MSCR[95] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
305 SIUL2->IMCR[457] = SIUL2_IMCR_SSS(1);
308 SIUL2->MSCR[11] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
309 SIUL2->IMCR[455] = SIUL2_IMCR_SSS(1);
312 SIUL2->MSCR[10] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
313 SIUL2->IMCR[456] = SIUL2_IMCR_SSS(1);
316 SIUL2->MSCR[9] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
317 SIUL2->IMCR[451] = SIUL2_IMCR_SSS(1);
320 SIUL2->MSCR[8] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
321 SIUL2->IMCR[452] = SIUL2_IMCR_SSS(1);
324 SIUL2->MSCR[7] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
325 SIUL2->IMCR[453] = SIUL2_IMCR_SSS(1);
328 SIUL2->MSCR[77] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
329 SIUL2->IMCR[454] = SIUL2_IMCR_SSS(1);
332 SIUL2->MSCR[139] = SIUL2_MSCR_OBE_MASK | SIUL2_MSCR_SMC_MASK;
335 SIUL2->GPDO[139] = 0;
337 SIUL2->GPDO[139] = 1;
341 #elif defined(USE_MPC5748G_GW_RDB)
343 SIUL2->MSCR[94] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
344 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK | SIUL2_MSCR_PUS_MASK |
345 SIUL2_MSCR_PUE_MASK | SIUL2_MSCR_SSS(4);
346 SIUL2->IMCR[450] = SIUL2_IMCR_SSS(1);
349 SIUL2->MSCR[96] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
350 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
353 SIUL2->MSCR[97] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
354 SIUL2->IMCR[449] = SIUL2_IMCR_SSS(1);
357 SIUL2->MSCR[114] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
358 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
361 SIUL2->MSCR[113] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
362 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
365 SIUL2->MSCR[112] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
366 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
369 SIUL2->MSCR[108] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
370 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
373 SIUL2->MSCR[109] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
374 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
377 SIUL2->MSCR[3] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
378 SIUL2->IMCR[448] = SIUL2_IMCR_SSS(1);
381 SIUL2->MSCR[95] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
382 SIUL2->IMCR[457] = SIUL2_IMCR_SSS(1);
385 SIUL2->MSCR[9] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
386 SIUL2->IMCR[451] = SIUL2_IMCR_SSS(1);
389 SIUL2->MSCR[8] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
390 SIUL2->IMCR[452] = SIUL2_IMCR_SSS(1);
393 SIUL2->MSCR[7] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
394 SIUL2->IMCR[453] = SIUL2_IMCR_SSS(1);
397 SIUL2->MSCR[77] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
398 SIUL2->IMCR[454] = SIUL2_IMCR_SSS(1);
401 SIUL2->MSCR[31] = SIUL2_MSCR_OBE_MASK | SIUL2_MSCR_SMC_MASK;
410 #elif defined(USE_SJA1105SMBEVM)
412 SIUL2->MSCR[94] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
413 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK | SIUL2_MSCR_PUS_MASK |
414 SIUL2_MSCR_PUE_MASK | SIUL2_MSCR_SSS(4);
415 SIUL2->IMCR[450] = SIUL2_IMCR_SSS(1);
418 SIUL2->MSCR[96] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
419 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
422 SIUL2->MSCR[97] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
423 SIUL2->IMCR[449] = SIUL2_IMCR_SSS(1);
426 SIUL2->MSCR[114] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
427 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
430 SIUL2->MSCR[113] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
431 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
434 SIUL2->MSCR[112] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
435 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
438 SIUL2->MSCR[108] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
439 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
442 SIUL2->MSCR[109] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
443 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
446 SIUL2->MSCR[3] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
447 SIUL2->IMCR[448] = SIUL2_IMCR_SSS(1);
450 SIUL2->MSCR[95] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
451 SIUL2->IMCR[457] = SIUL2_IMCR_SSS(1);
454 SIUL2->MSCR[9] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
455 SIUL2->IMCR[451] = SIUL2_IMCR_SSS(1);
458 SIUL2->MSCR[8] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
459 SIUL2->IMCR[452] = SIUL2_IMCR_SSS(1);
462 SIUL2->MSCR[7] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
463 SIUL2->IMCR[453] = SIUL2_IMCR_SSS(1);
466 SIUL2->MSCR[77] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
467 SIUL2->IMCR[454] = SIUL2_IMCR_SSS(1);
483 osMemset(txBufferDesc, 0,
sizeof(txBufferDesc));
484 osMemset(rxBufferDesc, 0,
sizeof(rxBufferDesc));
521 ENET_0->TDSR = (uint32_t) txBufferDesc;
523 ENET_0->RDSR = (uint32_t) rxBufferDesc;
541 if(interface->phyDriver != NULL)
544 interface->phyDriver->tick(interface);
546 else if(interface->switchDriver != NULL)
549 interface->switchDriver->tick(interface);
566 INT_SYS_EnableIRQ(ENET0_GROUP2_IRQn);
567 INT_SYS_EnableIRQ(ENET0_GROUP1_IRQn);
568 INT_SYS_EnableIRQ(ENET0_GROUP0_IRQn);
571 if(interface->phyDriver != NULL)
574 interface->phyDriver->enableIrq(interface);
576 else if(interface->switchDriver != NULL)
579 interface->switchDriver->enableIrq(interface);
596 INT_SYS_DisableIRQ(ENET0_GROUP2_IRQn);
597 INT_SYS_DisableIRQ(ENET0_GROUP1_IRQn);
598 INT_SYS_DisableIRQ(ENET0_GROUP0_IRQn);
601 if(interface->phyDriver != NULL)
604 interface->phyDriver->disableIrq(interface);
606 else if(interface->switchDriver != NULL)
609 interface->switchDriver->disableIrq(interface);
633 if((ENET_0->EIR & ENET_EIR_TXF_MASK) != 0)
636 ENET_0->EIR = ENET_EIR_TXF_MASK;
639 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
646 ENET_0->TDAR = ENET_TDAR_TDAR_MASK;
669 if((ENET_0->EIR & ENET_EIR_RXF_MASK) != 0)
672 ENET_0->EIMR &= ~ENET_EIMR_RXF_MASK;
675 nicDriverInterface->nicEvent =
TRUE;
700 if((ENET_0->EIR & ENET_EIR_EBERR_MASK) != 0)
703 ENET_0->EIMR &= ~ENET_EIMR_EBERR_MASK;
706 nicDriverInterface->nicEvent =
TRUE;
727 status = ENET_0->EIR;
730 if((status & ENET_EIR_RXF_MASK) != 0)
733 ENET_0->EIR = ENET_EIR_RXF_MASK;
746 if((status & ENET_EIR_EBERR_MASK) != 0)
749 ENET_0->EIR = ENET_EIR_EBERR_MASK;
752 ENET_0->ECR &= ~ENET_ECR_ETHEREN_MASK;
756 ENET_0->ECR |= ENET_ECR_ETHEREN_MASK;
758 ENET_0->RDAR = ENET_RDAR_RDAR_MASK;
762 ENET_0->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
794 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) != 0)
803 txBufferDesc[txBufferIndex][4] = 0;
826 ENET_0->TDAR = ENET_TDAR_TDAR_MASK;
829 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
853 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_E) == 0)
856 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_L) != 0)
889 rxBufferDesc[rxBufferIndex][4] = 0;
908 ENET_0->RDAR = ENET_RDAR_RDAR_MASK;
933 uint32_t unicastHashTable[2];
934 uint32_t multicastHashTable[2];
941 value = interface->macAddr.b[5];
942 value |= (interface->macAddr.b[4] << 8);
943 ENET_0->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
946 value = interface->macAddr.b[3];
947 value |= (interface->macAddr.b[2] << 8);
948 value |= (interface->macAddr.b[1] << 16);
949 value |= (interface->macAddr.b[0] << 24);
950 ENET_0->PALR = ENET_PALR_PADDR1(
value);
953 unicastHashTable[0] = 0;
954 unicastHashTable[1] = 0;
957 multicastHashTable[0] = 0;
958 multicastHashTable[1] = 0;
965 entry = &interface->macAddrFilter[i];
975 k = (crc >> 26) & 0x3F;
981 multicastHashTable[k / 32] |= (1 << (k % 32));
986 unicastHashTable[k / 32] |= (1 << (k % 32));
992 ENET_0->IALR = unicastHashTable[0];
993 ENET_0->IAUR = unicastHashTable[1];
996 ENET_0->GALR = multicastHashTable[0];
997 ENET_0->GAUR = multicastHashTable[1];
1000 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", ENET_0->IALR);
1001 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", ENET_0->IAUR);
1002 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", ENET_0->GALR);
1003 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", ENET_0->GAUR);
1019 ENET_0->ECR &= ~ENET_ECR_ETHEREN_MASK;
1025 ENET_0->RCR &= ~ENET_RCR_RMII_10T_MASK;
1030 ENET_0->RCR |= ENET_RCR_RMII_10T_MASK;
1037 ENET_0->TCR |= ENET_TCR_FDEN_MASK;
1039 ENET_0->RCR &= ~ENET_RCR_DRT_MASK;
1044 ENET_0->TCR &= ~ENET_TCR_FDEN_MASK;
1046 ENET_0->RCR |= ENET_RCR_DRT_MASK;
1053 ENET_0->ECR |= ENET_ECR_ETHEREN_MASK;
1055 ENET_0->RDAR = ENET_RDAR_RDAR_MASK;
1079 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
1081 temp |= ENET_MMFR_PA(phyAddr);
1083 temp |= ENET_MMFR_RA(
regAddr);
1085 temp |= ENET_MMFR_DATA(
data);
1088 ENET_0->EIR = ENET_EIR_MII_MASK;
1090 ENET_0->MMFR = temp;
1093 while((ENET_0->EIR & ENET_EIR_MII_MASK) == 0)
1122 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
1124 temp |= ENET_MMFR_PA(phyAddr);
1126 temp |= ENET_MMFR_RA(
regAddr);
1129 ENET_0->EIR = ENET_EIR_MII_MASK;
1131 ENET_0->MMFR = temp;
1134 while((ENET_0->EIR & ENET_EIR_MII_MASK) == 0)
1139 data = ENET_0->MMFR & ENET_MMFR_DATA_MASK;
1167 p = (uint8_t *)
data;
1172 for(i = 0; i <
length; i++)
1178 for(j = 0; j < 8; j++)
1180 if((crc & 0x01) != 0)
1182 crc = (crc >> 1) ^ 0xEDB88320;