32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 4
48 #pragma location = XMC4400_ETH_RAM_SECTION
51 #pragma data_alignment = 4
52 #pragma location = XMC4400_ETH_RAM_SECTION
55 #pragma data_alignment = 4
56 #pragma location = XMC4400_ETH_RAM_SECTION
59 #pragma data_alignment = 4
60 #pragma location = XMC4400_ETH_RAM_SECTION
123 TRACE_INFO(
"Initializing XMC4400 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_XMC4400_PLT2GO)
256 temp &= ~PORT0_IOCR4_PC4_Msk;
257 temp |= (17UL << PORT0_IOCR4_PC4_Pos);
262 temp &= ~(PORT2_IOCR0_PC0_Msk | PORT2_IOCR0_PC2_Msk | PORT2_IOCR0_PC3_Msk);
263 temp |= (0UL << PORT2_IOCR0_PC0_Pos) | (0UL << PORT2_IOCR0_PC2_Pos) | (0UL << PORT2_IOCR0_PC3_Pos);
268 temp &= ~(PORT2_IOCR4_PC4_Msk | PORT2_IOCR4_PC7_Msk);
269 temp |= (0UL << PORT2_IOCR4_PC4_Pos) | (17UL << PORT2_IOCR4_PC7_Pos);
274 temp &= ~(PORT2_IOCR8_PC8_Msk | PORT2_IOCR8_PC9_Msk);
275 temp |= (17UL << PORT2_IOCR8_PC8_Pos) | (17UL << PORT2_IOCR8_PC9_Pos);
279 temp = PORT15->IOCR8;
280 temp &= ~(PORT15_IOCR8_PC8_Msk | PORT15_IOCR8_PC9_Msk);
281 temp |= (0UL << PORT15_IOCR8_PC8_Pos) | (0UL << PORT15_IOCR8_PC9_Pos);
282 PORT15->IOCR8 = temp;
285 temp = PORT2->HWSEL & ~PORT2_HWSEL_HW0_Msk;
286 PORT2->HWSEL = temp | (1UL << PORT2_HWSEL_HW0_Pos);
290 temp &= ~PORT2_PDR0_PD5_Msk;
291 temp |= (0UL << PORT2_PDR0_PD5_Pos);
296 temp &= ~(PORT2_PDR1_PD8_Msk | PORT2_PDR1_PD9_Msk);
297 temp |= (0UL << PORT2_PDR1_PD8_Pos) | (0UL << PORT2_PDR1_PD9_Pos);
301 PORT15->PDISC &= ~(PORT15_PDISC_PDIS8_Msk | PORT15_PDISC_PDIS9_Msk);
356 ETH0->TRANSMIT_DESCRIPTOR_LIST_ADDRESS = (uint32_t)
txDmaDesc;
358 ETH0->RECEIVE_DESCRIPTOR_LIST_ADDRESS = (uint32_t)
rxDmaDesc;
374 if(interface->phyDriver != NULL)
377 interface->phyDriver->tick(interface);
379 else if(interface->switchDriver != NULL)
382 interface->switchDriver->tick(interface);
399 NVIC_EnableIRQ(ETH0_0_IRQn);
402 if(interface->phyDriver != NULL)
405 interface->phyDriver->enableIrq(interface);
407 else if(interface->switchDriver != NULL)
410 interface->switchDriver->enableIrq(interface);
427 NVIC_DisableIRQ(ETH0_0_IRQn);
430 if(interface->phyDriver != NULL)
433 interface->phyDriver->disableIrq(interface);
435 else if(interface->switchDriver != NULL)
438 interface->switchDriver->disableIrq(interface);
463 status = ETH0->STATUS;
466 if((status & ETH_STATUS_TI_Msk) != 0)
469 ETH0->STATUS = ETH_STATUS_TI_Msk;
480 if((status & ETH_STATUS_RI_Msk) != 0)
483 ETH0->STATUS = ETH_STATUS_RI_Msk;
486 nicDriverInterface->nicEvent =
TRUE;
492 ETH0->STATUS = ETH_STATUS_NIS_Msk;
563 ETH0->STATUS = ETH_STATUS_TU_Msk;
565 ETH0->TRANSMIT_POLL_DEMAND = 0;
643 ETH0->STATUS = ETH_STATUS_RU_Msk;
645 ETH0->RECEIVE_POLL_DEMAND = 0;
664 uint32_t hashTable[2];
672 ETH0->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
673 ETH0->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
689 entry = &interface->macAddrFilter[i];
702 k = (crc >> 26) & 0x3F;
705 hashTable[k / 32] |= (1 << (k % 32));
713 unicastMacAddr[j++] = entry->
addr;
723 ETH0->MAC_ADDRESS1_LOW = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
724 ETH0->MAC_ADDRESS1_HIGH = unicastMacAddr[0].w[2] | ETH_MAC_ADDRESS1_HIGH_AE_Msk;
729 ETH0->MAC_ADDRESS1_LOW = 0;
730 ETH0->MAC_ADDRESS1_HIGH = 0;
737 ETH0->MAC_ADDRESS2_LOW = unicastMacAddr[1].w[0] | (unicastMacAddr[1].w[1] << 16);
738 ETH0->MAC_ADDRESS2_HIGH = unicastMacAddr[1].w[2] | ETH_MAC_ADDRESS2_HIGH_AE_Msk;
743 ETH0->MAC_ADDRESS2_LOW = 0;
744 ETH0->MAC_ADDRESS2_HIGH = 0;
751 ETH0->MAC_ADDRESS3_LOW = unicastMacAddr[2].w[0] | (unicastMacAddr[2].w[1] << 16);
752 ETH0->MAC_ADDRESS3_HIGH = unicastMacAddr[2].w[2] | ETH_MAC_ADDRESS3_HIGH_AE_Msk;
757 ETH0->MAC_ADDRESS3_LOW = 0;
758 ETH0->MAC_ADDRESS3_HIGH = 0;
762 ETH0->HASH_TABLE_LOW = hashTable[0];
763 ETH0->HASH_TABLE_HIGH = hashTable[1];
766 TRACE_DEBUG(
" HASH_TABLE_LOW = %08" PRIX32
"\r\n", ETH0->HASH_TABLE_LOW);
767 TRACE_DEBUG(
" HASH_TABLE_HIGH = %08" PRIX32
"\r\n", ETH0->HASH_TABLE_HIGH);
785 config = ETH0->MAC_CONFIGURATION;
790 config |= ETH_MAC_CONFIGURATION_FES_Msk;
794 config &= ~ETH_MAC_CONFIGURATION_FES_Msk;
800 config |= ETH_MAC_CONFIGURATION_DM_Msk;
804 config &= ~ETH_MAC_CONFIGURATION_DM_Msk;
808 ETH0->MAC_CONFIGURATION = config;
832 temp = ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_CR_Msk;
834 temp |= ETH_GMII_ADDRESS_MW_Msk | ETH_GMII_ADDRESS_MB_Msk;
836 temp |= (phyAddr << ETH_GMII_ADDRESS_PA_Pos) & ETH_GMII_ADDRESS_PA_Msk;
838 temp |= (
regAddr << ETH_GMII_ADDRESS_MR_Pos) & ETH_GMII_ADDRESS_MR_Msk;
841 ETH0->GMII_DATA =
data & ETH_GMII_DATA_MD_Msk;
844 ETH0->GMII_ADDRESS = temp;
846 while((ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_MB_Msk) != 0)
875 temp = ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_CR_Msk;
877 temp |= ETH_GMII_ADDRESS_MB_Msk;
879 temp |= (phyAddr << ETH_GMII_ADDRESS_PA_Pos) & ETH_GMII_ADDRESS_PA_Msk;
881 temp |= (
regAddr << ETH_GMII_ADDRESS_MR_Pos) & ETH_GMII_ADDRESS_MR_Msk;
884 ETH0->GMII_ADDRESS = temp;
886 while((ETH0->GMII_ADDRESS & ETH_GMII_ADDRESS_MB_Msk) != 0)
891 data = ETH0->GMII_DATA & ETH_GMII_DATA_MD_Msk;
919 p = (uint8_t *)
data;
924 for(i = 0; i <
length; i++)
927 for(j = 0; j < 8; j++)
930 if((((crc >> 31) ^ (
p[i] >> j)) & 0x01) != 0)
932 crc = (crc << 1) ^ 0x04C11DB7;