32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 4
48 #pragma location = XMC4700_ETH_RAM_SECTION
51 #pragma data_alignment = 4
52 #pragma location = XMC4700_ETH_RAM_SECTION
55 #pragma data_alignment = 4
56 #pragma location = XMC4700_ETH_RAM_SECTION
59 #pragma data_alignment = 4
60 #pragma location = XMC4700_ETH_RAM_SECTION
123 TRACE_INFO(
"Initializing XMC4700 Ethernet MAC...\r\n");
126 nicDriverInterface = interface;
129 SCU_PARITY->PETE = 0;
131 PPB->CCR &= ~PPB_CCR_UNALIGN_TRP_Msk;
134 SCU_CLK->CLKSET = SCU_CLK_CLKSET_ETH0CEN_Msk;
140 SCU_RESET->PRSET2 = SCU_RESET_PRSET2_ETH0RS_Msk;
141 SCU_RESET->PRCLR2 = SCU_RESET_PRCLR2_ETH0RS_Msk;
144 ETH0->BUS_MODE |= ETH_BUS_MODE_SWR_Msk;
146 while((ETH0->BUS_MODE & ETH_BUS_MODE_SWR_Msk) != 0)
154 if(interface->phyDriver != NULL)
157 error = interface->phyDriver->init(interface);
159 else if(interface->switchDriver != NULL)
162 error = interface->switchDriver->init(interface);
178 ETH_MAC_CONFIGURATION_DO_Msk;
181 ETH0->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
182 ETH0->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
185 ETH0->MAC_ADDRESS1_LOW = 0;
186 ETH0->MAC_ADDRESS1_HIGH = 0;
187 ETH0->MAC_ADDRESS2_LOW = 0;
188 ETH0->MAC_ADDRESS2_HIGH = 0;
189 ETH0->MAC_ADDRESS3_LOW = 0;
190 ETH0->MAC_ADDRESS3_HIGH = 0;
193 ETH0->HASH_TABLE_LOW = 0;
194 ETH0->HASH_TABLE_HIGH = 0;
197 ETH0->MAC_FRAME_FILTER = ETH_MAC_FRAME_FILTER_HPF_Msk | ETH_MAC_FRAME_FILTER_HMC_Msk;
199 ETH0->FLOW_CONTROL = 0;
201 ETH0->OPERATION_MODE = ETH_OPERATION_MODE_RSF_Msk | ETH_OPERATION_MODE_TSF_Msk;
204 ETH0->BUS_MODE = ETH_BUS_MODE_AAL_Msk | ETH_BUS_MODE_USP_Msk |
212 ETH0->MMC_TRANSMIT_INTERRUPT_MASK = 0xFFFFFFFF;
213 ETH0->MMC_RECEIVE_INTERRUPT_MASK = 0xFFFFFFFF;
214 ETH0->MMC_IPC_RECEIVE_INTERRUPT_MASK = 0xFFFFFFFF;
217 ETH0->INTERRUPT_MASK = ETH_INTERRUPT_MASK_TSIM_Msk | ETH_INTERRUPT_MASK_PMTIM_Msk;
220 ETH0->INTERRUPT_ENABLE = ETH_INTERRUPT_ENABLE_NIE_Msk |
221 ETH_INTERRUPT_ENABLE_RIE_Msk | ETH_INTERRUPT_ENABLE_TIE_Msk;
231 ETH0->MAC_CONFIGURATION |= ETH_MAC_CONFIGURATION_TE_Msk | ETH_MAC_CONFIGURATION_RE_Msk;
233 ETH0->OPERATION_MODE |= ETH_OPERATION_MODE_ST_Msk | ETH_OPERATION_MODE_SR_Msk;
251 #if defined(USE_KIT_XMC4700_RELAX)
256 temp &= ~(PORT2_IOCR0_PC0_Msk | PORT2_IOCR0_PC2_Msk | PORT2_IOCR0_PC3_Msk);
257 temp |= (0UL << PORT2_IOCR0_PC0_Pos) | (0UL << PORT2_IOCR0_PC2_Pos) | (0UL << PORT2_IOCR0_PC3_Pos);
262 temp &= ~(PORT2_IOCR4_PC4_Msk | PORT2_IOCR4_PC5_Msk | PORT2_IOCR4_PC7_Msk);
263 temp |= (0UL << PORT2_IOCR4_PC4_Pos) | (17UL << PORT2_IOCR4_PC5_Pos) | (17UL << PORT2_IOCR4_PC7_Pos);
268 temp &= ~(PORT2_IOCR8_PC8_Msk | PORT2_IOCR8_PC9_Msk);
269 temp |= (17UL << PORT2_IOCR8_PC8_Pos) | (17UL << PORT2_IOCR8_PC9_Pos);
273 temp = PORT15->IOCR8;
274 temp &= ~(PORT15_IOCR8_PC8_Msk | PORT15_IOCR8_PC9_Msk);
275 temp |= (0UL << PORT15_IOCR8_PC8_Pos) | (0UL << PORT15_IOCR8_PC9_Pos);
276 PORT15->IOCR8 = temp;
279 temp = PORT2->HWSEL & ~PORT2_HWSEL_HW0_Msk;
280 PORT2->HWSEL = temp | (1UL << PORT2_HWSEL_HW0_Pos);
284 temp &= ~PORT2_PDR0_PD5_Msk;
285 temp |= (0UL << PORT2_PDR0_PD5_Pos);
290 temp &= ~(PORT2_PDR1_PD8_Msk | PORT2_PDR1_PD9_Msk);
291 temp |= (0UL << PORT2_PDR1_PD8_Pos) | (0UL << PORT2_PDR1_PD9_Pos);
295 PORT15->PDISC &= ~(PORT15_PDISC_PDIS8_Msk | PORT15_PDISC_PDIS9_Msk);
350 ETH0->TRANSMIT_DESCRIPTOR_LIST_ADDRESS = (uint32_t)
txDmaDesc;
352 ETH0->RECEIVE_DESCRIPTOR_LIST_ADDRESS = (uint32_t)
rxDmaDesc;
368 if(interface->phyDriver != NULL)
371 interface->phyDriver->tick(interface);
373 else if(interface->switchDriver != NULL)
376 interface->switchDriver->tick(interface);
393 NVIC_EnableIRQ(ETH0_0_IRQn);
396 if(interface->phyDriver != NULL)
399 interface->phyDriver->enableIrq(interface);
401 else if(interface->switchDriver != NULL)
404 interface->switchDriver->enableIrq(interface);
421 NVIC_DisableIRQ(ETH0_0_IRQn);
424 if(interface->phyDriver != NULL)
427 interface->phyDriver->disableIrq(interface);
429 else if(interface->switchDriver != NULL)
432 interface->switchDriver->disableIrq(interface);
457 status = ETH0->STATUS;
460 if((status & ETH_STATUS_TI_Msk) != 0)
463 ETH0->STATUS = ETH_STATUS_TI_Msk;
474 if((status & ETH_STATUS_RI_Msk) != 0)
477 ETH0->STATUS = ETH_STATUS_RI_Msk;
480 nicDriverInterface->nicEvent =
TRUE;
486 ETH0->STATUS = ETH_STATUS_NIS_Msk;
557 ETH0->STATUS = ETH_STATUS_TU_Msk;
559 ETH0->TRANSMIT_POLL_DEMAND = 0;
637 ETH0->STATUS = ETH_STATUS_RU_Msk;
639 ETH0->RECEIVE_POLL_DEMAND = 0;
658 uint32_t hashTable[2];
666 ETH0->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
667 ETH0->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
683 entry = &interface->macAddrFilter[i];
696 k = (crc >> 26) & 0x3F;
699 hashTable[k / 32] |= (1 << (k % 32));
707 unicastMacAddr[j++] = entry->
addr;
717 ETH0->MAC_ADDRESS1_LOW = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
718 ETH0->MAC_ADDRESS1_HIGH = unicastMacAddr[0].w[2] | ETH_MAC_ADDRESS1_HIGH_AE_Msk;
723 ETH0->MAC_ADDRESS1_LOW = 0;
724 ETH0->MAC_ADDRESS1_HIGH = 0;
731 ETH0->MAC_ADDRESS2_LOW = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
732 ETH0->MAC_ADDRESS2_HIGH = unicastMacAddr[1].w[2] | ETH_MAC_ADDRESS2_HIGH_AE_Msk;
737 ETH0->MAC_ADDRESS2_LOW = 0;
738 ETH0->MAC_ADDRESS2_HIGH = 0;
745 ETH0->MAC_ADDRESS3_LOW = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
746 ETH0->MAC_ADDRESS3_HIGH = unicastMacAddr[2].w[2] | ETH_MAC_ADDRESS3_HIGH_AE_Msk;
751 ETH0->MAC_ADDRESS3_LOW = 0;
752 ETH0->MAC_ADDRESS3_HIGH = 0;
756 ETH0->HASH_TABLE_LOW = hashTable[0];
757 ETH0->HASH_TABLE_HIGH = hashTable[1];
760 TRACE_DEBUG(
" HASH_TABLE_LOW = %08" PRIX32
"\r\n", ETH0->HASH_TABLE_LOW);
761 TRACE_DEBUG(
" HASH_TABLE_HIGH = %08" PRIX32
"\r\n", ETH0->HASH_TABLE_HIGH);
779 config = ETH0->MAC_CONFIGURATION;
784 config |= ETH_MAC_CONFIGURATION_FES_Msk;
788 config &= ~ETH_MAC_CONFIGURATION_FES_Msk;
794 config |= ETH_MAC_CONFIGURATION_DM_Msk;
798 config &= ~ETH_MAC_CONFIGURATION_DM_Msk;
802 ETH0->MAC_CONFIGURATION = config;
826 temp = ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_CR_Msk;
828 temp |= ETH_GMII_ADDRESS_MW_Msk | ETH_GMII_ADDRESS_MB_Msk;
830 temp |= (phyAddr << ETH_GMII_ADDRESS_PA_Pos) & ETH_GMII_ADDRESS_PA_Msk;
832 temp |= (
regAddr << ETH_GMII_ADDRESS_MR_Pos) & ETH_GMII_ADDRESS_MR_Msk;
835 ETH0->GMII_DATA =
data & ETH_GMII_DATA_MD_Msk;
838 ETH0->GMII_ADDRESS = temp;
840 while((ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_MB_Msk) != 0)
869 temp = ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_CR_Msk;
871 temp |= ETH_GMII_ADDRESS_MB_Msk;
873 temp |= (phyAddr << ETH_GMII_ADDRESS_PA_Pos) & ETH_GMII_ADDRESS_PA_Msk;
875 temp |= (
regAddr << ETH_GMII_ADDRESS_MR_Pos) & ETH_GMII_ADDRESS_MR_Msk;
878 ETH0->GMII_ADDRESS = temp;
880 while((ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_MB_Msk) != 0)
885 data = ETH0->GMII_DATA & ETH_GMII_DATA_MD_Msk;
913 p = (uint8_t *)
data;
918 for(i = 0; i <
length; i++)
921 for(j = 0; j < 8; j++)
924 if((((crc >> 31) ^ (
p[i] >> j)) & 0x01) != 0)
926 crc = (crc << 1) ^ 0x04C11DB7;