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 MPC5777 Ethernet MAC...\r\n");
103 nicDriverInterface = interface;
109 FEC->ECR = FEC_ECR_RESET_MASK;
111 while((FEC->ECR & FEC_ECR_RESET_MASK) != 0)
117 FEC_RCR_RMII_MODE_MASK | FEC_RCR_MII_MODE_MASK;
122 FEC->MSCR = FEC_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 FEC->PAUR = FEC_PAUR_PADDR2(
value) | FEC_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 FEC->PALR = FEC_PALR_PADDR1(
value);
167 FEC->MIBC = FEC_MIBC_MIB_DIS_MASK;
173 FEC->EIR = 0xFFFFFFFF;
175 FEC->EIMR = FEC_EIMR_TXF_MASK | FEC_EIMR_RXF_MASK | FEC_EIMR_EBERR_MASK;
185 FEC->ECR |= FEC_ECR_ETHER_EN_MASK;
187 FEC->RDAR = FEC_RDAR_RDAR_MASK;
218 osMemset(txBufferDesc, 0,
sizeof(txBufferDesc));
219 osMemset(rxBufferDesc, 0,
sizeof(rxBufferDesc));
252 FEC->ETDSR = (uint32_t) txBufferDesc;
254 FEC->ERDSR = (uint32_t) rxBufferDesc;
272 if(interface->phyDriver != NULL)
275 interface->phyDriver->tick(interface);
277 else if(interface->switchDriver != NULL)
280 interface->switchDriver->tick(interface);
297 INT_SYS_EnableIRQ(FEC_TXF_IRQn);
298 INT_SYS_EnableIRQ(FEC_RXF_IRQn);
299 INT_SYS_EnableIRQ(FEC_ERR_IRQn);
302 if(interface->phyDriver != NULL)
305 interface->phyDriver->enableIrq(interface);
307 else if(interface->switchDriver != NULL)
310 interface->switchDriver->enableIrq(interface);
327 INT_SYS_DisableIRQ(FEC_TXF_IRQn);
328 INT_SYS_DisableIRQ(FEC_RXF_IRQn);
329 INT_SYS_DisableIRQ(FEC_ERR_IRQn);
332 if(interface->phyDriver != NULL)
335 interface->phyDriver->disableIrq(interface);
337 else if(interface->switchDriver != NULL)
340 interface->switchDriver->disableIrq(interface);
364 if((FEC->EIR & FEC_EIR_TXF_MASK) != 0)
367 FEC->EIR = FEC_EIR_TXF_MASK;
370 if((txBufferDesc[txBufferIndex][0] &
FEC_TBD0_R) == 0)
377 FEC->TDAR = FEC_TDAR_TDAR_MASK;
400 if((FEC->EIR & FEC_EIR_RXF_MASK) != 0)
403 FEC->EIMR &= ~FEC_EIMR_RXF_MASK;
406 nicDriverInterface->nicEvent =
TRUE;
431 if((FEC->EIR & FEC_EIR_EBERR_MASK) != 0)
434 FEC->EIMR &= ~FEC_EIMR_EBERR_MASK;
437 nicDriverInterface->nicEvent =
TRUE;
461 if((status & FEC_EIR_RXF_MASK) != 0)
464 FEC->EIR = FEC_EIR_RXF_MASK;
477 if((status & FEC_EIR_EBERR_MASK) != 0)
480 FEC->EIR = FEC_EIR_EBERR_MASK;
483 FEC->ECR &= ~FEC_ECR_ETHER_EN_MASK;
487 FEC->ECR |= FEC_ECR_ETHER_EN_MASK;
489 FEC->RDAR = FEC_RDAR_RDAR_MASK;
493 FEC->EIMR = FEC_EIMR_TXF_MASK | FEC_EIMR_RXF_MASK | FEC_EIMR_EBERR_MASK;
525 if((txBufferDesc[txBufferIndex][0] &
FEC_TBD0_R) != 0)
534 txBufferDesc[txBufferIndex][4] = 0;
557 FEC->TDAR = FEC_TDAR_TDAR_MASK;
560 if((txBufferDesc[txBufferIndex][0] &
FEC_TBD0_R) == 0)
584 if((rxBufferDesc[rxBufferIndex][0] &
FEC_RBD0_E) == 0)
587 if((rxBufferDesc[rxBufferIndex][0] &
FEC_RBD0_L) != 0)
620 rxBufferDesc[rxBufferIndex][4] = 0;
639 FEC->RDAR = FEC_RDAR_RDAR_MASK;
664 uint32_t unicastHashTable[2];
665 uint32_t multicastHashTable[2];
672 value = interface->macAddr.b[5];
673 value |= (interface->macAddr.b[4] << 8);
674 FEC->PAUR = FEC_PAUR_PADDR2(
value) | FEC_PAUR_TYPE(0x8808);
677 value = interface->macAddr.b[3];
678 value |= (interface->macAddr.b[2] << 8);
679 value |= (interface->macAddr.b[1] << 16);
680 value |= (interface->macAddr.b[0] << 24);
681 FEC->PALR = FEC_PALR_PADDR1(
value);
684 unicastHashTable[0] = 0;
685 unicastHashTable[1] = 0;
688 multicastHashTable[0] = 0;
689 multicastHashTable[1] = 0;
696 entry = &interface->macAddrFilter[i];
706 k = (crc >> 26) & 0x3F;
712 multicastHashTable[k / 32] |= (1 << (k % 32));
717 unicastHashTable[k / 32] |= (1 << (k % 32));
723 FEC->IALR = unicastHashTable[0];
724 FEC->IAUR = unicastHashTable[1];
727 FEC->GALR = multicastHashTable[0];
728 FEC->GAUR = multicastHashTable[1];
731 TRACE_DEBUG(
" IALR = %08" PRIX32
"\r\n", FEC->IALR);
732 TRACE_DEBUG(
" IAUR = %08" PRIX32
"\r\n", FEC->IAUR);
733 TRACE_DEBUG(
" GALR = %08" PRIX32
"\r\n", FEC->GALR);
734 TRACE_DEBUG(
" GAUR = %08" PRIX32
"\r\n", FEC->GAUR);
750 FEC->ECR &= ~FEC_ECR_ETHER_EN_MASK;
756 FEC->RCR &= ~FEC_RCR_RMII_10T_MASK;
761 FEC->RCR |= FEC_RCR_RMII_10T_MASK;
768 FEC->TCR |= FEC_TCR_FDEN_MASK;
770 FEC->RCR &= ~FEC_RCR_DRT_MASK;
775 FEC->TCR &= ~FEC_TCR_FDEN_MASK;
777 FEC->RCR |= FEC_RCR_DRT_MASK;
784 FEC->ECR |= FEC_ECR_ETHER_EN_MASK;
786 FEC->RDAR = FEC_RDAR_RDAR_MASK;
810 temp = FEC_MMFR_ST(1) | FEC_MMFR_OP(1) | FEC_MMFR_TA(2);
812 temp |= FEC_MMFR_PA(phyAddr);
816 temp |= FEC_MMFR_DATA(
data);
819 FEC->EIR = FEC_EIR_MII_MASK;
824 while((FEC->EIR & FEC_EIR_MII_MASK) == 0)
853 temp = FEC_MMFR_ST(1) | FEC_MMFR_OP(2) | FEC_MMFR_TA(2);
855 temp |= FEC_MMFR_PA(phyAddr);
860 FEC->EIR = FEC_EIR_MII_MASK;
865 while((FEC->EIR & FEC_EIR_MII_MASK) == 0)
870 data = FEC->MMFR & FEC_MMFR_DATA_MASK;
898 p = (uint8_t *)
data;
903 for(i = 0; i <
length; i++)
909 for(j = 0; j < 8; j++)
911 if((crc & 0x01) != 0)
913 crc = (crc >> 1) ^ 0xEDB88320;