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 SAM4E Ethernet MAC...\r\n");
124 nicDriverInterface = interface;
127 PMC->PMC_PCER1 = (1 << (ID_GMAC - 32));
136 GMAC->GMAC_NCFGR = GMAC_NCFGR_CLK_MCK_96;
138 GMAC->GMAC_NCR |= GMAC_NCR_MPE;
141 if(interface->phyDriver != NULL)
144 error = interface->phyDriver->init(interface);
146 else if(interface->switchDriver != NULL)
149 error = interface->switchDriver->init(interface);
164 GMAC->GMAC_SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
165 GMAC->GMAC_SA[0].GMAC_SAT = interface->macAddr.w[2];
168 GMAC->GMAC_SA[1].GMAC_SAB = 0;
169 GMAC->GMAC_SA[2].GMAC_SAB = 0;
170 GMAC->GMAC_SA[3].GMAC_SAB = 0;
177 GMAC->GMAC_NCFGR |= GMAC_NCFGR_MAXFS | GMAC_NCFGR_MTIHEN;
183 GMAC->GMAC_TSR = GMAC_TSR_HRESP | GMAC_TSR_UND | GMAC_TSR_TXCOMP |
184 GMAC_TSR_TFC | GMAC_TSR_TXGO | GMAC_TSR_RLE | GMAC_TSR_COL |
188 GMAC->GMAC_RSR = GMAC_RSR_HNO | GMAC_RSR_RXOVR | GMAC_RSR_REC |
192 GMAC->GMAC_IDR = 0xFFFFFFFF;
195 GMAC->GMAC_IER = GMAC_IER_HRESP | GMAC_IER_ROVR | GMAC_IER_TCOMP |
196 GMAC_IER_TFC | GMAC_IER_RLEX | GMAC_IER_TUR | GMAC_IER_RXUBR |
200 status = GMAC->GMAC_ISR;
211 GMAC->GMAC_NCR |= GMAC_NCR_TXEN | GMAC_NCR_RXEN;
229 #if defined(USE_SAM4E_EK) || defined(USE_SAM4E_XPLAINED_PRO)
231 PMC->PMC_PCER0 = (1 << ID_PIOD);
244 GMAC->GMAC_UR = GMAC_UR_RMIIMII;
283 rxBufferDesc[i].
status = 0;
292 GMAC->GMAC_TBQB = (uint32_t) txBufferDesc;
294 GMAC->GMAC_RBQB = (uint32_t) rxBufferDesc;
310 if(interface->phyDriver != NULL)
313 interface->phyDriver->tick(interface);
315 else if(interface->switchDriver != NULL)
318 interface->switchDriver->tick(interface);
335 NVIC_EnableIRQ(GMAC_IRQn);
338 if(interface->phyDriver != NULL)
341 interface->phyDriver->enableIrq(interface);
343 else if(interface->switchDriver != NULL)
346 interface->switchDriver->enableIrq(interface);
363 NVIC_DisableIRQ(GMAC_IRQn);
366 if(interface->phyDriver != NULL)
369 interface->phyDriver->disableIrq(interface);
371 else if(interface->switchDriver != NULL)
374 interface->switchDriver->disableIrq(interface);
390 volatile uint32_t isr;
391 volatile uint32_t tsr;
392 volatile uint32_t rsr;
402 isr = GMAC->GMAC_ISR;
403 tsr = GMAC->GMAC_TSR;
404 rsr = GMAC->GMAC_RSR;
408 if((tsr & (GMAC_TSR_HRESP | GMAC_TSR_UND | GMAC_TSR_TXCOMP | GMAC_TSR_TFC |
409 GMAC_TSR_TXGO | GMAC_TSR_RLE | GMAC_TSR_COL | GMAC_TSR_UBR)) != 0)
412 GMAC->GMAC_TSR = tsr;
415 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
423 if((rsr & (GMAC_RSR_HNO | GMAC_RSR_RXOVR | GMAC_RSR_REC | GMAC_RSR_BNA)) != 0)
426 nicDriverInterface->nicEvent =
TRUE;
447 rsr = GMAC->GMAC_RSR;
450 if((rsr & (GMAC_RSR_HNO | GMAC_RSR_RXOVR | GMAC_RSR_REC | GMAC_RSR_BNA)) != 0)
453 GMAC->GMAC_RSR = rsr;
495 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) == 0)
524 GMAC->GMAC_NCR |= GMAC_NCR_TSTART;
527 if((txBufferDesc[txBufferIndex].status &
GMAC_TX_USED) != 0)
565 j = rxBufferIndex + i;
588 if((rxBufferDesc[j].status &
GMAC_RX_EOF) != 0 && sofIndex != UINT_MAX)
602 if(eofIndex != UINT_MAX)
606 else if(sofIndex != UINT_MAX)
619 for(i = 0; i < j; i++)
622 if(eofIndex != UINT_MAX && i >= sofIndex && i <= eofIndex)
682 uint32_t hashTable[2];
690 GMAC->GMAC_SA[0].GMAC_SAB = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
691 GMAC->GMAC_SA[0].GMAC_SAT = interface->macAddr.w[2];
707 entry = &interface->macAddrFilter[i];
719 k = (
p[0] >> 6) ^
p[0];
720 k ^= (
p[1] >> 4) ^ (
p[1] << 2);
721 k ^= (
p[2] >> 2) ^ (
p[2] << 4);
722 k ^= (
p[3] >> 6) ^
p[3];
723 k ^= (
p[4] >> 4) ^ (
p[4] << 2);
724 k ^= (
p[5] >> 2) ^ (
p[5] << 4);
730 hashTable[k / 32] |= (1 << (k % 32));
738 unicastMacAddr[j++] = entry->
addr;
748 GMAC->GMAC_SA[1].GMAC_SAB = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
749 GMAC->GMAC_SA[1].GMAC_SAT = unicastMacAddr[0].w[2];
754 GMAC->GMAC_SA[1].GMAC_SAB = 0;
761 GMAC->GMAC_SA[2].GMAC_SAB = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
762 GMAC->GMAC_SA[2].GMAC_SAT = unicastMacAddr[1].w[2];
767 GMAC->GMAC_SA[2].GMAC_SAB = 0;
774 GMAC->GMAC_SA[3].GMAC_SAB = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
775 GMAC->GMAC_SA[3].GMAC_SAT = unicastMacAddr[2].w[2];
780 GMAC->GMAC_SA[3].GMAC_SAB = 0;
784 GMAC->GMAC_HRB = hashTable[0];
785 GMAC->GMAC_HRT = hashTable[1];
788 TRACE_DEBUG(
" HRB = %08" PRIX32
"\r\n", GMAC->GMAC_HRB);
789 TRACE_DEBUG(
" HRT = %08" PRIX32
"\r\n", GMAC->GMAC_HRT);
807 config = GMAC->GMAC_NCFGR;
812 config |= GMAC_NCFGR_SPD;
816 config &= ~GMAC_NCFGR_SPD;
822 config |= GMAC_NCFGR_FD;
826 config &= ~GMAC_NCFGR_FD;
830 GMAC->GMAC_NCFGR = config;
854 temp = GMAC_MAN_CLTTO | GMAC_MAN_OP(1) | GMAC_MAN_WTN(2);
856 temp |= GMAC_MAN_PHYA(phyAddr);
858 temp |= GMAC_MAN_REGA(
regAddr);
860 temp |= GMAC_MAN_DATA(
data);
863 GMAC->GMAC_MAN = temp;
865 while((GMAC->GMAC_NSR & GMAC_NSR_IDLE) == 0)
894 temp = GMAC_MAN_CLTTO | GMAC_MAN_OP(2) | GMAC_MAN_WTN(2);
896 temp |= GMAC_MAN_PHYA(phyAddr);
898 temp |= GMAC_MAN_REGA(
regAddr);
901 GMAC->GMAC_MAN = temp;
903 while((GMAC->GMAC_NSR & GMAC_NSR_IDLE) == 0)
908 data = GMAC->GMAC_MAN & GMAC_MAN_DATA_Msk;