32 #define TRACE_LEVEL NIC_TRACE_LEVEL
45 #if defined(__ICCARM__)
48 #pragma data_alignment = 8
51 #pragma data_alignment = 8
54 #pragma data_alignment = 4
57 #pragma data_alignment = 4
79 static uint_t txBufferIndex;
81 static uint_t rxBufferIndex;
118 volatile uint32_t status;
121 TRACE_INFO(
"Initializing SAME53 Ethernet MAC...\r\n");
124 nicDriverInterface = interface;
127 MCLK_REGS->MCLK_APBCMASK |= MCLK_APBCMASK_GMAC_Msk;
128 MCLK_REGS->MCLK_AHBMASK |= MCLK_AHBMASK_GMAC_Msk;
131 GMAC_REGS->GMAC_NCR = 0;
137 GMAC_REGS->GMAC_NCFGR = GMAC_NCFGR_CLK(5);
139 GMAC_REGS->GMAC_NCR |= GMAC_NCR_MPE_Msk;
142 if(interface->phyDriver != NULL)
145 error = interface->phyDriver->init(interface);
147 else if(interface->switchDriver != NULL)
150 error = interface->switchDriver->init(interface);
165 GMAC_REGS->SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
166 GMAC_REGS->SA[0].GMAC_SAT = interface->macAddr.w[2];
169 GMAC_REGS->SA[1].GMAC_SAB = 0;
170 GMAC_REGS->SA[2].GMAC_SAB = 0;
171 GMAC_REGS->SA[3].GMAC_SAB = 0;
174 GMAC_REGS->GMAC_HRB = 0;
175 GMAC_REGS->GMAC_HRT = 0;
178 GMAC_REGS->GMAC_NCFGR |= GMAC_NCFGR_MAXFS_Msk | GMAC_NCFGR_MTIHEN_Msk;
184 GMAC_REGS->GMAC_TSR = GMAC_TSR_HRESP_Msk | GMAC_TSR_UND_Msk |
185 GMAC_TSR_TXCOMP_Msk | GMAC_TSR_TFC_Msk | GMAC_TSR_TXGO_Msk |
186 GMAC_TSR_RLE_Msk | GMAC_TSR_COL_Msk | GMAC_TSR_UBR_Msk;
189 GMAC_REGS->GMAC_RSR = GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk |
190 GMAC_RSR_REC_Msk | GMAC_RSR_BNA_Msk;
193 GMAC_REGS->GMAC_IDR = 0xFFFFFFFF;
196 GMAC_REGS->GMAC_IER = GMAC_IER_HRESP_Msk | GMAC_IER_ROVR_Msk |
197 GMAC_IER_TCOMP_Msk | GMAC_IER_TFC_Msk | GMAC_IER_RLEX_Msk |
198 GMAC_IER_TUR_Msk | GMAC_IER_RXUBR_Msk | GMAC_IER_RCOMP_Msk;
201 status = GMAC_REGS->GMAC_ISR;
212 GMAC_REGS->GMAC_NCR |= GMAC_NCR_TXEN_Msk | GMAC_NCR_RXEN_Msk;
230 #if defined(USE_EVB_LAN9255)
234 MCLK_REGS->MCLK_APBBMASK |= MCLK_APBBMASK_PORT_Msk;
237 PORT_REGS->GROUP[0].PORT_PINCFG[12] |= PORT_PINCFG_PMUXEN_Msk;
238 temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXE_Msk;
239 PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXE(MUX_PA12L_GMAC_GRX1);
242 PORT_REGS->GROUP[0].PORT_PINCFG[13] |= PORT_PINCFG_PMUXEN_Msk;
243 temp = PORT_REGS->GROUP[0].PORT_PMUX[6] & ~PORT_PMUX_PMUXO_Msk;
244 PORT_REGS->GROUP[0].PORT_PMUX[6] = temp | PORT_PMUX_PMUXO(MUX_PA13L_GMAC_GRX0);
247 PORT_REGS->GROUP[0].PORT_PINCFG[14] |= PORT_PINCFG_PMUXEN_Msk;
248 temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXE_Msk;
249 PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXE(MUX_PA14L_GMAC_GTXCK);
252 PORT_REGS->GROUP[0].PORT_PINCFG[15] |= PORT_PINCFG_PMUXEN_Msk;
253 temp = PORT_REGS->GROUP[0].PORT_PMUX[7] & ~PORT_PMUX_PMUXO_Msk;
254 PORT_REGS->GROUP[0].PORT_PMUX[7] = temp | PORT_PMUX_PMUXO(MUX_PA15L_GMAC_GRXER);
257 PORT_REGS->GROUP[0].PORT_PINCFG[16] |= PORT_PINCFG_PMUXEN_Msk;
258 temp = PORT_REGS->GROUP[0].PORT_PMUX[8] & ~PORT_PMUX_PMUXE_Msk;
259 PORT_REGS->GROUP[0].PORT_PMUX[8] = temp | PORT_PMUX_PMUXE(MUX_PA16L_GMAC_GRXDV);
262 PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_DRVSTR_Msk;
263 PORT_REGS->GROUP[0].PORT_PINCFG[17] |= PORT_PINCFG_PMUXEN_Msk;
264 temp = PORT_REGS->GROUP[0].PORT_PMUX[8] & ~PORT_PMUX_PMUXO_Msk;
265 PORT_REGS->GROUP[0].PORT_PMUX[8] = temp | PORT_PMUX_PMUXO(MUX_PA17L_GMAC_GTXEN);
268 PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_DRVSTR_Msk;
269 PORT_REGS->GROUP[0].PORT_PINCFG[18] |= PORT_PINCFG_PMUXEN_Msk;
270 temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXE_Msk;
271 PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXE(MUX_PA18L_GMAC_GTX0);
274 PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_DRVSTR_Msk;
275 PORT_REGS->GROUP[0].PORT_PINCFG[19] |= PORT_PINCFG_PMUXEN_Msk;
276 temp = PORT_REGS->GROUP[0].PORT_PMUX[9] & ~PORT_PMUX_PMUXO_Msk;
277 PORT_REGS->GROUP[0].PORT_PMUX[9] = temp | PORT_PMUX_PMUXO(MUX_PA19L_GMAC_GTX1);
280 PORT_REGS->GROUP[0].PORT_PINCFG[20] |= PORT_PINCFG_PMUXEN_Msk;
281 temp = PORT_REGS->GROUP[0].PORT_PMUX[10] & ~PORT_PMUX_PMUXE_Msk;
282 PORT_REGS->GROUP[0].PORT_PMUX[10] = temp | PORT_PMUX_PMUXE(MUX_PA20L_GMAC_GMDC);
285 PORT_REGS->GROUP[0].PORT_PINCFG[21] |= PORT_PINCFG_PMUXEN_Msk;
286 temp = PORT_REGS->GROUP[0].PORT_PMUX[10] & ~PORT_PMUX_PMUXO_Msk;
287 PORT_REGS->GROUP[0].PORT_PMUX[10] = temp | PORT_PMUX_PMUXO(MUX_PA21L_GMAC_GMDIO);
290 GMAC_REGS->GMAC_UR &= ~GMAC_UR_MII_Msk;
329 rxBufferDesc[i].
status = 0;
338 GMAC_REGS->GMAC_TBQB = (uint32_t) txBufferDesc;
340 GMAC_REGS->GMAC_RBQB = (uint32_t) rxBufferDesc;
356 if(interface->phyDriver != NULL)
359 interface->phyDriver->tick(interface);
361 else if(interface->switchDriver != NULL)
364 interface->switchDriver->tick(interface);
381 NVIC_EnableIRQ(GMAC_IRQn);
384 if(interface->phyDriver != NULL)
387 interface->phyDriver->enableIrq(interface);
389 else if(interface->switchDriver != NULL)
392 interface->switchDriver->enableIrq(interface);
409 NVIC_DisableIRQ(GMAC_IRQn);
412 if(interface->phyDriver != NULL)
415 interface->phyDriver->disableIrq(interface);
417 else if(interface->switchDriver != NULL)
420 interface->switchDriver->disableIrq(interface);
436 volatile uint32_t isr;
437 volatile uint32_t tsr;
438 volatile uint32_t rsr;
448 isr = GMAC_REGS->GMAC_ISR;
449 tsr = GMAC_REGS->GMAC_TSR;
450 rsr = GMAC_REGS->GMAC_RSR;
454 if((tsr & (GMAC_TSR_HRESP_Msk | GMAC_TSR_UND_Msk |
455 GMAC_TSR_TXCOMP_Msk | GMAC_TSR_TFC_Msk | GMAC_TSR_TXGO_Msk |
456 GMAC_TSR_RLE_Msk | GMAC_TSR_COL_Msk | GMAC_TSR_UBR_Msk)) != 0)
459 GMAC_REGS->GMAC_TSR = tsr;
462 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
470 if((rsr & (GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk | GMAC_RSR_REC_Msk |
471 GMAC_RSR_BNA_Msk)) != 0)
474 nicDriverInterface->nicEvent =
TRUE;
495 rsr = GMAC_REGS->GMAC_RSR;
498 if((rsr & (GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk | GMAC_RSR_REC_Msk |
499 GMAC_RSR_BNA_Msk)) != 0)
502 GMAC_REGS->GMAC_RSR = rsr;
544 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) == 0)
576 GMAC_REGS->GMAC_NCR |= GMAC_NCR_TSTART_Msk;
579 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
617 j = rxBufferIndex + i;
640 if((rxBufferDesc[j].status &
GMAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
654 if(eofIndex != UINT_MAX)
658 else if(sofIndex != UINT_MAX)
671 for(i = 0; i < j; i++)
674 if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
734 uint32_t hashTable[2];
742 GMAC_REGS->SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
743 GMAC_REGS->SA[0].GMAC_SAT = interface->macAddr.w[2];
759 entry = &interface->macAddrFilter[i];
771 k = (
p[0] >> 6) ^
p[0];
772 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
773 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
774 k ^= (
p[3] >> 6) ^
p[3];
775 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
776 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
782 hashTable[k / 32] |= (1 << (k % 32));
790 unicastMacAddr[j++] = entry->
addr;
800 GMAC_REGS->SA[1].GMAC_SAB = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
801 GMAC_REGS->SA[1].GMAC_SAT = unicastMacAddr[0].w[2];
806 GMAC_REGS->SA[1].GMAC_SAB = 0;
813 GMAC_REGS->SA[2].GMAC_SAB = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
814 GMAC_REGS->SA[2].GMAC_SAT = unicastMacAddr[1].w[2];
819 GMAC_REGS->SA[2].GMAC_SAB = 0;
826 GMAC_REGS->SA[3].GMAC_SAB = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
827 GMAC_REGS->SA[3].GMAC_SAT = unicastMacAddr[2].w[2];
832 GMAC_REGS->SA[3].GMAC_SAB = 0;
836 GMAC_REGS->GMAC_HRB = hashTable[0];
837 GMAC_REGS->GMAC_HRT = hashTable[1];
840 TRACE_DEBUG(
" HRB = %08" PRIX32
"\r\n", GMAC_REGS->GMAC_HRB);
841 TRACE_DEBUG(
" HRT = %08" PRIX32
"\r\n", GMAC_REGS->GMAC_HRT);
859 config = GMAC_REGS->GMAC_NCFGR;
864 config |= GMAC_NCFGR_SPD_Msk;
868 config &= ~GMAC_NCFGR_SPD_Msk;
874 config |= GMAC_NCFGR_FD_Msk;
878 config &= ~GMAC_NCFGR_FD_Msk;
882 GMAC_REGS->GMAC_NCFGR = config;
906 temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(1) | GMAC_MAN_WTN(2);
908 temp |= GMAC_MAN_PHYA(phyAddr);
910 temp |= GMAC_MAN_REGA(
regAddr);
912 temp |= GMAC_MAN_DATA(
data);
915 GMAC_REGS->GMAC_MAN = temp;
917 while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
946 temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(2) | GMAC_MAN_WTN(2);
948 temp |= GMAC_MAN_PHYA(phyAddr);
950 temp |= GMAC_MAN_REGA(
regAddr);
953 GMAC_REGS->GMAC_MAN = temp;
955 while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
960 data = GMAC_REGS->GMAC_MAN & GMAC_MAN_DATA_Msk;