32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 4
50 #pragma data_alignment = 4
53 #pragma data_alignment = 4
56 #pragma data_alignment = 4
119 TRACE_INFO(
"Initializing M487 Ethernet MAC...\r\n");
122 nicDriverInterface = interface;
125 CLK_EnableModuleClock(EMAC_MODULE);
127 CLK_SetModuleClock(EMAC_MODULE, 0, CLK_CLKDIV3_EMAC(200));
130 EMAC->CTL |= EMAC_CTL_RST_Msk;
132 while((EMAC->CTL & EMAC_CTL_RST_Msk) != 0)
140 if(interface->phyDriver != NULL)
143 error = interface->phyDriver->init(interface);
145 else if(interface->switchDriver != NULL)
148 error = interface->switchDriver->init(interface);
163 EMAC->CAM0M = interface->macAddr.b[3] |
164 (interface->macAddr.b[2] << 8) |
165 (interface->macAddr.b[1] << 16) |
166 (interface->macAddr.b[0] << 24);
169 EMAC->CAM0L = (interface->macAddr.b[5] << 16) |
170 (interface->macAddr.b[4] << 24);
173 EMAC->CAMEN = EMAC_CAMEN_CAMxEN_Msk << 0;
175 EMAC->CAMCTL = EMAC_CAMCTL_CMPEN_Msk | EMAC_CAMCTL_ABP_Msk;
184 EMAC->INTEN = EMAC_INTEN_TXCPIEN_Msk | EMAC_INTEN_TXIEN_Msk |
185 EMAC_INTEN_RXGDIEN_Msk | EMAC_INTEN_RXIEN_Msk;
199 EMAC->CTL |= EMAC_CTL_TXON_Msk | EMAC_CTL_RXON_Msk;
217 #if defined(USE_NUMAKER_PFM_M487) || defined(USE_NUMAKER_IOT_M487)
221 EMAC->CTL |= EMAC_CTL_RMIIEN_Msk;
224 temp = SYS->GPA_MFPL;
225 temp = (temp & ~SYS_GPA_MFPL_PA6MFP_Msk) | SYS_GPA_MFPL_PA6MFP_EMAC_RMII_RXERR;
226 temp = (temp & ~SYS_GPA_MFPL_PA7MFP_Msk) | SYS_GPA_MFPL_PA7MFP_EMAC_RMII_CRSDV;
227 SYS->GPA_MFPL = temp;
230 temp = SYS->GPC_MFPL;
231 temp = (temp & ~SYS_GPC_MFPL_PC6MFP_Msk) | SYS_GPC_MFPL_PC6MFP_EMAC_RMII_RXD1;
232 temp = (temp & ~SYS_GPC_MFPL_PC7MFP_Msk) | SYS_GPC_MFPL_PC7MFP_EMAC_RMII_RXD0;
233 SYS->GPC_MFPL = temp;
236 temp = SYS->GPC_MFPH;
237 temp = (temp & ~SYS_GPC_MFPH_PC8MFP_Msk) | SYS_GPC_MFPH_PC8MFP_EMAC_RMII_REFCLK;
238 SYS->GPC_MFPH = temp;
243 temp = SYS->GPE_MFPH;
244 temp = (temp & ~SYS_GPE_MFPH_PE8MFP_Msk) | SYS_GPE_MFPH_PE8MFP_EMAC_RMII_MDC;
245 temp = (temp & ~SYS_GPE_MFPH_PE9MFP_Msk) | SYS_GPE_MFPH_PE9MFP_EMAC_RMII_MDIO;
246 temp = (temp & ~SYS_GPE_MFPH_PE10MFP_Msk) | SYS_GPE_MFPH_PE10MFP_EMAC_RMII_TXD0;
247 temp = (temp & ~SYS_GPE_MFPH_PE11MFP_Msk) | SYS_GPE_MFPH_PE11MFP_EMAC_RMII_TXD1;
248 temp = (temp & ~SYS_GPE_MFPH_PE12MFP_Msk) | SYS_GPE_MFPH_PE12MFP_EMAC_RMII_TXEN;
249 SYS->GPE_MFPH = temp;
253 temp = (temp & ~GPIO_SLEWCTL_HSREN10_Msk) | (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN10_Pos);
254 temp = (temp & ~GPIO_SLEWCTL_HSREN11_Msk) | (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN11_Pos);
255 temp = (temp & ~GPIO_SLEWCTL_HSREN12_Msk) | (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN11_Pos);
325 if(interface->phyDriver != NULL)
328 interface->phyDriver->tick(interface);
330 else if(interface->switchDriver != NULL)
333 interface->switchDriver->tick(interface);
350 NVIC_EnableIRQ(EMAC_TX_IRQn);
351 NVIC_EnableIRQ(EMAC_RX_IRQn);
354 if(interface->phyDriver != NULL)
357 interface->phyDriver->enableIrq(interface);
359 else if(interface->switchDriver != NULL)
362 interface->switchDriver->enableIrq(interface);
379 NVIC_DisableIRQ(EMAC_TX_IRQn);
380 NVIC_DisableIRQ(EMAC_RX_IRQn);
383 if(interface->phyDriver != NULL)
386 interface->phyDriver->disableIrq(interface);
388 else if(interface->switchDriver != NULL)
391 interface->switchDriver->disableIrq(interface);
415 if((EMAC->INTSTS & EMAC_INTSTS_TXCPIF_Msk) != 0)
418 EMAC->INTSTS = EMAC_INTSTS_TXCPIF_Msk;
448 if((EMAC->INTSTS & EMAC_INTSTS_RXGDIF_Msk) != 0)
451 EMAC->INTSTS = EMAC_INTSTS_RXGDIF_Msk;
454 nicDriverInterface->nicEvent =
TRUE;
522 txNextIndex = txIndex + 1;
545 txIndex = txNextIndex;
599 rxNextIndex = rxIndex + 1;
615 rxIndex = rxNextIndex;
646 acceptMulticast =
FALSE;
653 if(interface->macAddrFilter[i].refCount > 0)
656 acceptMulticast =
TRUE;
665 EMAC->CAMCTL |= EMAC_CAMCTL_AMP_Msk;
669 EMAC->CAMCTL &= ~EMAC_CAMCTL_AMP_Msk;
693 config |= EMAC_CTL_OPMODE_Msk;
697 config &= ~EMAC_CTL_OPMODE_Msk;
703 config |= EMAC_CTL_FUDUP_Msk;
707 config &= ~EMAC_CTL_FUDUP_Msk;
735 temp = EMAC_MIIMCTL_MDCON_Msk | EMAC_MIIMCTL_BUSY_Msk | EMAC_MIIMCTL_WRITE_Msk;
737 temp |= (phyAddr << EMAC_MIIMCTL_PHYADDR_Pos) & EMAC_MIIMCTL_PHYADDR_Msk;
739 temp |= (
regAddr << EMAC_MIIMCTL_PHYREG_Pos) & EMAC_MIIMCTL_PHYREG_Msk;
742 EMAC->MIIMDAT =
data & EMAC_MIIMDAT_DATA_Msk;
745 EMAC->MIIMCTL = temp;
747 while((EMAC->MIIMCTL & EMAC_MIIMCTL_BUSY_Msk) != 0)
776 temp = EMAC_MIIMCTL_MDCON_Msk | EMAC_MIIMCTL_BUSY_Msk;
778 temp |= (phyAddr << EMAC_MIIMCTL_PHYADDR_Pos) & EMAC_MIIMCTL_PHYADDR_Msk;
780 temp |= (
regAddr << EMAC_MIIMCTL_PHYREG_Pos) & EMAC_MIIMCTL_PHYREG_Msk;
783 EMAC->MIIMCTL = temp;
785 while((EMAC->MIIMCTL & EMAC_MIIMCTL_BUSY_Msk) != 0)
790 data = EMAC->MIIMDAT & EMAC_MIIMDAT_DATA_Msk;