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 (ENET1)...\r\n");
103 nicDriverInterface = interface;
109 ENET_1->ECR = ENET_ECR_RESET_MASK;
111 while((ENET_1->ECR & ENET_ECR_RESET_MASK) != 0)
117 ENET_RCR_MII_MODE_MASK;
122 ENET_1->MSCR = ENET_MSCR_MII_SPEED(19);
125 if(interface->phyDriver != NULL)
128 error = interface->phyDriver->init(interface);
130 else if(interface->switchDriver != NULL)
133 error = interface->switchDriver->init(interface);
148 value = interface->macAddr.b[5];
149 value |= (interface->macAddr.b[4] << 8);
150 ENET_1->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
153 value = interface->macAddr.b[3];
154 value |= (interface->macAddr.b[2] << 8);
155 value |= (interface->macAddr.b[1] << 16);
156 value |= (interface->macAddr.b[0] << 24);
157 ENET_1->PALR = ENET_PALR_PADDR1(
value);
172 ENET_1->ECR = ENET_ECR_EN1588_MASK;
175 ENET_1->MIBC = ENET_MIBC_MIB_CLEAR_MASK;
182 ENET_1->EIR = 0xFFFFFFFF;
184 ENET_1->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
194 ENET_1->ECR |= ENET_ECR_ETHEREN_MASK;
196 ENET_1->RDAR = ENET_RDAR_RDAR_MASK;
214 #if defined(USE_MPC5748G_GW_RDB)
216 SIUL2->MSCR[76] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
217 SIUL2->IMCR[460] = SIUL2_IMCR_SSS(1);
220 SIUL2->MSCR[140] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
221 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
224 SIUL2->MSCR[11] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
225 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
228 SIUL2->MSCR[10] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
229 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
232 SIUL2->MSCR[115] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
233 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
236 SIUL2->MSCR[141] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
237 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
240 SIUL2->MSCR[27] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
241 SIUL2->IMCR[459] = SIUL2_IMCR_SSS(2);
244 SIUL2->MSCR[21] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
245 SIUL2->IMCR[465] = SIUL2_IMCR_SSS(2);
248 SIUL2->MSCR[58] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
249 SIUL2->IMCR[461] = SIUL2_IMCR_SSS(2);
252 SIUL2->MSCR[57] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
253 SIUL2->IMCR[462] = SIUL2_IMCR_SSS(2);
256 SIUL2->MSCR[23] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
257 SIUL2->IMCR[463] = SIUL2_IMCR_SSS(2);
260 SIUL2->MSCR[22] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
261 SIUL2->IMCR[464] = SIUL2_IMCR_SSS(2);
264 SIUL2->MSCR[139] = SIUL2_MSCR_OBE_MASK | SIUL2_MSCR_SMC_MASK;
267 SIUL2->GPDO[139] = 0;
269 SIUL2->GPDO[139] = 1;
273 #elif defined(USE_SJA1105SMBEVM)
275 SIUL2->MSCR[76] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
276 SIUL2->IMCR[460] = SIUL2_IMCR_SSS(1);
279 SIUL2->MSCR[140] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
280 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
283 SIUL2->MSCR[11] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
284 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
287 SIUL2->MSCR[10] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
288 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
291 SIUL2->MSCR[115] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
292 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(4);
295 SIUL2->MSCR[141] = SIUL2_MSCR_SRC(3) | SIUL2_MSCR_OBE_MASK |
296 SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_SSS(3);
299 SIUL2->MSCR[27] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
300 SIUL2->IMCR[459] = SIUL2_IMCR_SSS(2);
303 SIUL2->MSCR[21] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
304 SIUL2->IMCR[465] = SIUL2_IMCR_SSS(2);
307 SIUL2->MSCR[31] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
308 SIUL2->IMCR[461] = SIUL2_IMCR_SSS(1);
311 SIUL2->MSCR[57] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
312 SIUL2->IMCR[462] = SIUL2_IMCR_SSS(2);
315 SIUL2->MSCR[23] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
316 SIUL2->IMCR[463] = SIUL2_IMCR_SSS(2);
319 SIUL2->MSCR[22] = SIUL2_MSCR_SMC_MASK | SIUL2_MSCR_IBE_MASK;
320 SIUL2->IMCR[464] = SIUL2_IMCR_SSS(2);
323 SIUL2->MSCR[142] = SIUL2_MSCR_OBE_MASK | SIUL2_MSCR_SMC_MASK;
326 SIUL2->GPDO[142] = 0;
328 SIUL2->GPDO[142] = 1;
345 osMemset(txBufferDesc, 0,
sizeof(txBufferDesc));
346 osMemset(rxBufferDesc, 0,
sizeof(rxBufferDesc));
383 ENET_1->TDSR = (uint32_t) txBufferDesc;
385 ENET_1->RDSR = (uint32_t) rxBufferDesc;
403 if(interface->phyDriver != NULL)
406 interface->phyDriver->tick(interface);
408 else if(interface->switchDriver != NULL)
411 interface->switchDriver->tick(interface);
428 INT_SYS_EnableIRQ(ENET1_GROUP2_IRQn);
429 INT_SYS_EnableIRQ(ENET1_GROUP1_IRQn);
430 INT_SYS_EnableIRQ(ENET1_GROUP0_IRQn);
433 if(interface->phyDriver != NULL)
436 interface->phyDriver->enableIrq(interface);
438 else if(interface->switchDriver != NULL)
441 interface->switchDriver->enableIrq(interface);
458 INT_SYS_DisableIRQ(ENET1_GROUP2_IRQn);
459 INT_SYS_DisableIRQ(ENET1_GROUP1_IRQn);
460 INT_SYS_DisableIRQ(ENET1_GROUP0_IRQn);
463 if(interface->phyDriver != NULL)
466 interface->phyDriver->disableIrq(interface);
468 else if(interface->switchDriver != NULL)
471 interface->switchDriver->disableIrq(interface);
495 if((ENET_1->EIR & ENET_EIR_TXF_MASK) != 0)
498 ENET_1->EIR = ENET_EIR_TXF_MASK;
501 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
508 ENET_1->TDAR = ENET_TDAR_TDAR_MASK;
531 if((ENET_1->EIR & ENET_EIR_RXF_MASK) != 0)
534 ENET_1->EIMR &= ~ENET_EIMR_RXF_MASK;
537 nicDriverInterface->nicEvent =
TRUE;
562 if((ENET_1->EIR & ENET_EIR_EBERR_MASK) != 0)
565 ENET_1->EIMR &= ~ENET_EIMR_EBERR_MASK;
568 nicDriverInterface->nicEvent =
TRUE;
589 status = ENET_1->EIR;
592 if((status & ENET_EIR_RXF_MASK) != 0)
595 ENET_1->EIR = ENET_EIR_RXF_MASK;
608 if((status & ENET_EIR_EBERR_MASK) != 0)
611 ENET_1->EIR = ENET_EIR_EBERR_MASK;
614 ENET_1->ECR &= ~ENET_ECR_ETHEREN_MASK;
618 ENET_1->ECR |= ENET_ECR_ETHEREN_MASK;
620 ENET_1->RDAR = ENET_RDAR_RDAR_MASK;
624 ENET_1->EIMR = ENET_EIMR_TXF_MASK | ENET_EIMR_RXF_MASK | ENET_EIMR_EBERR_MASK;
656 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) != 0)
665 txBufferDesc[txBufferIndex][4] = 0;
688 ENET_1->TDAR = ENET_TDAR_TDAR_MASK;
691 if((txBufferDesc[txBufferIndex][0] &
ENET_TBD0_R) == 0)
715 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_E) == 0)
718 if((rxBufferDesc[rxBufferIndex][0] &
ENET_RBD0_L) != 0)
751 rxBufferDesc[rxBufferIndex][4] = 0;
770 ENET_1->RDAR = ENET_RDAR_RDAR_MASK;
795 uint32_t unicastHashTable[2];
796 uint32_t multicastHashTable[2];
803 value = interface->macAddr.b[5];
804 value |= (interface->macAddr.b[4] << 8);
805 ENET_1->PAUR = ENET_PAUR_PADDR2(
value) | ENET_PAUR_TYPE(0x8808);
808 value = interface->macAddr.b[3];
809 value |= (interface->macAddr.b[2] << 8);
810 value |= (interface->macAddr.b[1] << 16);
811 value |= (interface->macAddr.b[0] << 24);
812 ENET_1->PALR = ENET_PALR_PADDR1(
value);
815 unicastHashTable[0] = 0;
816 unicastHashTable[1] = 0;
819 multicastHashTable[0] = 0;
820 multicastHashTable[1] = 0;
827 entry = &interface->macAddrFilter[i];
837 k = (crc >> 26) & 0x3F;
843 multicastHashTable[k / 32] |= (1 << (k % 32));
848 unicastHashTable[k / 32] |= (1 << (k % 32));
854 ENET_1->IALR = unicastHashTable[0];
855 ENET_1->IAUR = unicastHashTable[1];
858 ENET_1->GALR = multicastHashTable[0];
859 ENET_1->GAUR = multicastHashTable[1];
862 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", ENET_1->IALR);
863 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", ENET_1->IAUR);
864 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", ENET_1->GALR);
865 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", ENET_1->GAUR);
881 ENET_1->ECR &= ~ENET_ECR_ETHEREN_MASK;
887 ENET_1->RCR &= ~ENET_RCR_RMII_10T_MASK;
892 ENET_1->RCR |= ENET_RCR_RMII_10T_MASK;
899 ENET_1->TCR |= ENET_TCR_FDEN_MASK;
901 ENET_1->RCR &= ~ENET_RCR_DRT_MASK;
906 ENET_1->TCR &= ~ENET_TCR_FDEN_MASK;
908 ENET_1->RCR |= ENET_RCR_DRT_MASK;
915 ENET_1->ECR |= ENET_ECR_ETHEREN_MASK;
917 ENET_1->RDAR = ENET_RDAR_RDAR_MASK;
941 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(1) | ENET_MMFR_TA(2);
943 temp |= ENET_MMFR_PA(phyAddr);
947 temp |= ENET_MMFR_DATA(
data);
950 ENET_1->EIR = ENET_EIR_MII_MASK;
955 while((ENET_1->EIR & ENET_EIR_MII_MASK) == 0)
984 temp = ENET_MMFR_ST(1) | ENET_MMFR_OP(2) | ENET_MMFR_TA(2);
986 temp |= ENET_MMFR_PA(phyAddr);
991 ENET_1->EIR = ENET_EIR_MII_MASK;
996 while((ENET_1->EIR & ENET_EIR_MII_MASK) == 0)
1001 data = ENET_1->MMFR & ENET_MMFR_DATA_MASK;
1029 p = (uint8_t *)
data;
1034 for(i = 0; i <
length; i++)
1040 for(j = 0; j < 8; j++)
1042 if((crc & 0x01) != 0)
1044 crc = (crc >> 1) ^ 0xEDB88320;