32 #define TRACE_LEVEL NIC_TRACE_LEVEL
45 #if defined(__ICCARM__)
48 #pragma data_alignment = 8
49 #pragma location = SAMV71_ETH_RAM_SECTION
52 #pragma data_alignment = 8
53 #pragma location = SAMV71_ETH_RAM_SECTION
56 #pragma data_alignment = 4
57 #pragma location = SAMV71_ETH_RAM_SECTION
60 #pragma data_alignment = 4
61 #pragma location = SAMV71_ETH_RAM_SECTION
65 #pragma data_alignment = 8
66 #pragma location = SAMV71_ETH_RAM_SECTION
69 #pragma data_alignment = 8
70 #pragma location = SAMV71_ETH_RAM_SECTION
73 #pragma data_alignment = 4
74 #pragma location = SAMV71_ETH_RAM_SECTION
77 #pragma data_alignment = 4
78 #pragma location = SAMV71_ETH_RAM_SECTION
113 static uint_t txBufferIndex;
115 static uint_t rxBufferIndex;
152 volatile uint32_t status;
155 TRACE_INFO(
"Initializing SAMV71 Ethernet MAC...\r\n");
158 nicDriverInterface = interface;
161 PMC_REGS->PMC_PCER1 = (1 << (ID_GMAC - 32));
164 GMAC_REGS->GMAC_NCR = 0;
170 GMAC_REGS->GMAC_NCFGR = GMAC_NCFGR_CLK_MCK_96;
172 GMAC_REGS->GMAC_NCR |= GMAC_NCR_MPE_Msk;
175 if(interface->phyDriver != NULL)
178 error = interface->phyDriver->init(interface);
180 else if(interface->switchDriver != NULL)
183 error = interface->switchDriver->init(interface);
198 GMAC_REGS->GMAC_SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
199 GMAC_REGS->GMAC_SA[0].GMAC_SAT = interface->macAddr.w[2];
202 GMAC_REGS->GMAC_SA[1].GMAC_SAB = 0;
203 GMAC_REGS->GMAC_SA[2].GMAC_SAB = 0;
204 GMAC_REGS->GMAC_SA[3].GMAC_SAB = 0;
207 GMAC_REGS->GMAC_HRB = 0;
208 GMAC_REGS->GMAC_HRT = 0;
211 GMAC_REGS->GMAC_NCFGR |= GMAC_NCFGR_MAXFS_Msk | GMAC_NCFGR_MTIHEN_Msk;
215 GMAC_DCFGR_TXPBMS_Msk | GMAC_DCFGR_RXBMS_FULL | GMAC_DCFGR_FBLDO_INCR4;
227 GMAC_REGS->GMAC_TSR = GMAC_TSR_HRESP_Msk | GMAC_TSR_TXCOMP_Msk |
228 GMAC_TSR_TFC_Msk | GMAC_TSR_TXGO_Msk | GMAC_TSR_RLE_Msk |
229 GMAC_TSR_COL_Msk | GMAC_TSR_UBR_Msk;
232 GMAC_REGS->GMAC_RSR = GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk |
233 GMAC_RSR_REC_Msk | GMAC_RSR_BNA_Msk;
236 GMAC_REGS->GMAC_IDR = 0xFFFFFFFF;
237 GMAC_REGS->GMAC_IDRPQ[0] = 0xFFFFFFFF;
238 GMAC_REGS->GMAC_IDRPQ[1] = 0xFFFFFFFF;
239 GMAC_REGS->GMAC_IDRPQ[2] = 0xFFFFFFFF;
240 GMAC_REGS->GMAC_IDRPQ[3] = 0xFFFFFFFF;
241 GMAC_REGS->GMAC_IDRPQ[4] = 0xFFFFFFFF;
244 GMAC_REGS->GMAC_IER = GMAC_IER_HRESP_Msk | GMAC_IER_ROVR_Msk |
245 GMAC_IER_TCOMP_Msk | GMAC_IER_TFC_Msk | GMAC_IER_RLEX_Msk |
246 GMAC_IER_TUR_Msk | GMAC_IER_RXUBR_Msk | GMAC_IER_RCOMP_Msk;
249 status = GMAC_REGS->GMAC_ISR;
250 status = GMAC_REGS->GMAC_ISRPQ[0];
251 status = GMAC_REGS->GMAC_ISRPQ[1];
252 status = GMAC_REGS->GMAC_ISRPQ[2];
253 status = GMAC_REGS->GMAC_ISRPQ[3];
254 status = GMAC_REGS->GMAC_ISRPQ[4];
265 GMAC_REGS->GMAC_NCR |= GMAC_NCR_TXEN_Msk | GMAC_NCR_RXEN_Msk;
283 #if defined(USE_SAMV71_XPLAINED_ULTRA)
285 PMC_REGS->PMC_PCER0 = (1 << ID_PIOC) | (1 << ID_PIOD);
298 GMAC_REGS->GMAC_UR &= ~GMAC_UR_RMII_Msk;
301 PIOC_REGS->PIO_PER = PIO_PC10;
302 PIOC_REGS->PIO_OER = PIO_PC10;
305 PIOC_REGS->PIO_CODR = PIO_PC10;
307 PIOC_REGS->PIO_SODR = PIO_PC10;
347 rxBufferDesc[i].
status = 0;
359 address = (uint32_t) dummyTxBuffer[i];
373 address = (uint32_t) dummyRxBuffer[i];
377 dummyRxBufferDesc[i].
status = 0;
384 GMAC_REGS->GMAC_TBQB = (uint32_t) txBufferDesc;
385 GMAC_REGS->GMAC_TBQBAPQ[0] = (uint32_t) dummyTxBufferDesc;
386 GMAC_REGS->GMAC_TBQBAPQ[1] = (uint32_t) dummyTxBufferDesc;
387 GMAC_REGS->GMAC_TBQBAPQ[2] = (uint32_t) dummyTxBufferDesc;
388 GMAC_REGS->GMAC_TBQBAPQ[3] = (uint32_t) dummyTxBufferDesc;
389 GMAC_REGS->GMAC_TBQBAPQ[4] = (uint32_t) dummyTxBufferDesc;
392 GMAC_REGS->GMAC_RBQB = (uint32_t) rxBufferDesc;
393 GMAC_REGS->GMAC_RBQBAPQ[0] = (uint32_t) dummyRxBufferDesc;
394 GMAC_REGS->GMAC_RBQBAPQ[1] = (uint32_t) dummyRxBufferDesc;
395 GMAC_REGS->GMAC_RBQBAPQ[2] = (uint32_t) dummyRxBufferDesc;
396 GMAC_REGS->GMAC_RBQBAPQ[3] = (uint32_t) dummyRxBufferDesc;
397 GMAC_REGS->GMAC_RBQBAPQ[4] = (uint32_t) dummyRxBufferDesc;
413 if(interface->phyDriver != NULL)
416 interface->phyDriver->tick(interface);
418 else if(interface->switchDriver != NULL)
421 interface->switchDriver->tick(interface);
438 NVIC_EnableIRQ(GMAC_IRQn);
441 if(interface->phyDriver != NULL)
444 interface->phyDriver->enableIrq(interface);
446 else if(interface->switchDriver != NULL)
449 interface->switchDriver->enableIrq(interface);
466 NVIC_DisableIRQ(GMAC_IRQn);
469 if(interface->phyDriver != NULL)
472 interface->phyDriver->disableIrq(interface);
474 else if(interface->switchDriver != NULL)
477 interface->switchDriver->disableIrq(interface);
493 volatile uint32_t isr;
494 volatile uint32_t tsr;
495 volatile uint32_t rsr;
505 isr = GMAC_REGS->GMAC_ISRPQ[0];
506 isr = GMAC_REGS->GMAC_ISRPQ[1];
507 isr = GMAC_REGS->GMAC_ISRPQ[2];
508 isr = GMAC_REGS->GMAC_ISRPQ[3];
509 isr = GMAC_REGS->GMAC_ISRPQ[4];
510 isr = GMAC_REGS->GMAC_ISR;
511 tsr = GMAC_REGS->GMAC_TSR;
512 rsr = GMAC_REGS->GMAC_RSR;
516 if((tsr & (GMAC_TSR_HRESP_Msk | GMAC_TSR_TXCOMP_Msk |
517 GMAC_TSR_TFC_Msk | GMAC_TSR_TXGO_Msk | GMAC_TSR_RLE_Msk |
518 GMAC_TSR_COL_Msk | GMAC_TSR_UBR_Msk)) != 0)
521 GMAC_REGS->GMAC_TSR = tsr;
524 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
532 if((rsr & (GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk | GMAC_RSR_REC_Msk |
533 GMAC_RSR_BNA_Msk)) != 0)
536 nicDriverInterface->nicEvent =
TRUE;
557 rsr = GMAC_REGS->GMAC_RSR;
560 if((rsr & (GMAC_RSR_HNO_Msk | GMAC_RSR_RXOVR_Msk | GMAC_RSR_REC_Msk |
561 GMAC_RSR_BNA_Msk)) != 0)
564 GMAC_REGS->GMAC_RSR = rsr;
606 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) == 0)
638 GMAC_REGS->GMAC_NCR |= GMAC_NCR_TSTART_Msk;
641 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
679 j = rxBufferIndex + i;
702 if((rxBufferDesc[j].status &
GMAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
716 if(eofIndex != UINT_MAX)
720 else if(sofIndex != UINT_MAX)
733 for(i = 0; i < j; i++)
736 if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
796 uint32_t hashTable[2];
804 GMAC_REGS->GMAC_SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
805 GMAC_REGS->GMAC_SA[0].GMAC_SAT = interface->macAddr.w[2];
821 entry = &interface->macAddrFilter[i];
833 k = (
p[0] >> 6) ^
p[0];
834 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
835 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
836 k ^= (
p[3] >> 6) ^
p[3];
837 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
838 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
844 hashTable[k / 32] |= (1 << (k % 32));
852 unicastMacAddr[j] = entry->
addr;
860 k = (
p[0] >> 6) ^
p[0];
861 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
862 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
863 k ^= (
p[3] >> 6) ^
p[3];
864 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
865 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
871 hashTable[k / 32] |= (1 << (k % 32));
884 GMAC_REGS->GMAC_SA[1].GMAC_SAB = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
885 GMAC_REGS->GMAC_SA[1].GMAC_SAT = unicastMacAddr[0].w[2];
890 GMAC_REGS->GMAC_SA[1].GMAC_SAB = 0;
897 GMAC_REGS->GMAC_SA[2].GMAC_SAB = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
898 GMAC_REGS->GMAC_SA[2].GMAC_SAT = unicastMacAddr[1].w[2];
903 GMAC_REGS->GMAC_SA[2].GMAC_SAB = 0;
910 GMAC_REGS->GMAC_SA[3].GMAC_SAB = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
911 GMAC_REGS->GMAC_SA[3].GMAC_SAT = unicastMacAddr[2].w[2];
916 GMAC_REGS->GMAC_SA[3].GMAC_SAB = 0;
922 GMAC_REGS->GMAC_NCFGR |= GMAC_NCFGR_UNIHEN_Msk;
926 GMAC_REGS->GMAC_NCFGR &= ~GMAC_NCFGR_UNIHEN_Msk;
930 GMAC_REGS->GMAC_HRB = hashTable[0];
931 GMAC_REGS->GMAC_HRT = hashTable[1];
934 TRACE_DEBUG(
" HRB = %08" PRIX32
"\r\n", GMAC_REGS->GMAC_HRB);
935 TRACE_DEBUG(
" HRT = %08" PRIX32
"\r\n", GMAC_REGS->GMAC_HRT);
953 config = GMAC_REGS->GMAC_NCFGR;
958 config |= GMAC_NCFGR_SPD_Msk;
962 config &= ~GMAC_NCFGR_SPD_Msk;
968 config |= GMAC_NCFGR_FD_Msk;
972 config &= ~GMAC_NCFGR_FD_Msk;
976 GMAC_REGS->GMAC_NCFGR = config;
1000 temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(1) | GMAC_MAN_WTN(2);
1002 temp |= GMAC_MAN_PHYA(phyAddr);
1004 temp |= GMAC_MAN_REGA(
regAddr);
1006 temp |= GMAC_MAN_DATA(
data);
1009 GMAC_REGS->GMAC_MAN = temp;
1011 while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
1040 temp = GMAC_MAN_CLTTO_Msk | GMAC_MAN_OP(2) | GMAC_MAN_WTN(2);
1042 temp |= GMAC_MAN_PHYA(phyAddr);
1044 temp |= GMAC_MAN_REGA(
regAddr);
1047 GMAC_REGS->GMAC_MAN = temp;
1049 while((GMAC_REGS->GMAC_NSR & GMAC_NSR_IDLE_Msk) == 0)
1054 data = GMAC_REGS->GMAC_MAN & GMAC_MAN_DATA_Msk;