32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include "fsl_device_registers.h"
36 #include "fsl_clock.h"
39 #include "fsl_reset.h"
48 #if defined(__ICCARM__)
51 #pragma data_alignment = 4
54 #pragma data_alignment = 4
57 #pragma data_alignment = 4
60 #pragma data_alignment = 4
124 TRACE_INFO(
"Initializing MCX N547 Ethernet MAC...\r\n");
127 nicDriverInterface = interface;
130 CLOCK_EnableClock(kCLOCK_InputMux);
131 CLOCK_AttachClk(kNONE_to_ENETRMII);
134 CLOCK_EnableClock(kCLOCK_Enet);
137 SYSCON0->PRESETCTRL2 = SYSCON_PRESETCTRL2_ENET_RST_MASK;
138 SYSCON0->PRESETCTRL2 &= ~SYSCON_PRESETCTRL2_ENET_RST_MASK;
144 ENET->DMA_MODE |= ENET_DMA_MODE_SWR_MASK;
146 while((ENET->DMA_MODE & ENET_DMA_MODE_SWR_MASK) != 0)
151 ENET->MAC_MDIO_ADDRESS = ENET_MAC_MDIO_ADDRESS_CR(4);
154 if(interface->phyDriver != NULL)
157 error = interface->phyDriver->init(interface);
159 else if(interface->switchDriver != NULL)
162 error = interface->switchDriver->init(interface);
177 ENET->MAC_CONFIGURATION = ENET_MAC_CONFIGURATION_GPSLCE_MASK |
178 ENET_MAC_CONFIGURATION_PS_MASK | ENET_MAC_CONFIGURATION_DO_MASK;
181 temp = ENET->MAC_EXT_CONFIGURATION & ~ENET_MAC_EXT_CONFIGURATION_GPSL_MASK;
185 ENET->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
186 ENET->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
189 ENET->MAC_PACKET_FILTER = 0;
192 ENET->MAC_TX_FLOW_CTRL_Q[0] = 0;
193 ENET->MAC_RX_FLOW_CTRL = 0;
196 ENET->MAC_RXQ_CTRL[0] = ENET_MAC_RXQ_CTRL_RXQ0EN(2);
199 ENET->DMA_MODE = ENET_DMA_MODE_PR(0);
201 ENET->DMA_SYSBUS_MODE |= ENET_DMA_SYSBUS_MODE_AAL_MASK;
204 ENET->DMA_CH[0].DMA_CHX_CTRL = ENET_DMA_CH_DMA_CHX_CTRL_DSL(0);
206 ENET->DMA_CH[0].DMA_CHX_TX_CTRL = ENET_DMA_CH_DMA_CHX_TX_CTRL_TxPBL(32);
209 ENET->DMA_CH[0].DMA_CHX_RX_CTRL = ENET_DMA_CH_DMA_CHX_RX_CTRL_RxPBL(32) |
213 ENET->MTL_QUEUE[0].MTL_TXQX_OP_MODE |= ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TQS(7) |
214 ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TXQEN(2) |
215 ENET_MTL_QUEUE_MTL_TXQX_OP_MODE_TSF_MASK;
218 ENET->MTL_QUEUE[0].MTL_RXQX_OP_MODE |= ENET_MTL_QUEUE_MTL_RXQX_OP_MODE_RQS(7) |
219 ENET_MTL_QUEUE_MTL_RXQX_OP_MODE_RSF_MASK;
225 ENET->MAC_INTERRUPT_ENABLE = 0;
228 ENET->DMA_CH[0].DMA_CHX_INT_EN = ENET_DMA_CH_DMA_CHX_INT_EN_NIE_MASK |
229 ENET_DMA_CH_DMA_CHX_INT_EN_RIE_MASK | ENET_DMA_CH_DMA_CHX_INT_EN_TIE_MASK;
239 ENET->MAC_CONFIGURATION |= ENET_MAC_CONFIGURATION_TE_MASK |
240 ENET_MAC_CONFIGURATION_RE_MASK;
243 ENET->DMA_CH[0].DMA_CHX_TX_CTRL |= ENET_DMA_CH_DMA_CHX_TX_CTRL_ST_MASK;
244 ENET->DMA_CH[0].DMA_CHX_RX_CTRL |= ENET_DMA_CH_DMA_CHX_RX_CTRL_SR_MASK;
262 #if defined(USE_MCX_N5XX_EVK)
263 port_pin_config_t portPinConfig;
266 CLOCK_EnableClock(kCLOCK_Port1);
269 SYSCON0->ENET_PHY_INTF_SEL |= SYSCON_ENET_PHY_INTF_SEL_PHY_SEL_MASK;
272 portPinConfig.pullSelect = kPORT_PullDisable;
273 portPinConfig.pullValueSelect = kPORT_LowPullResistor;
274 portPinConfig.slewRate = kPORT_FastSlewRate;
275 portPinConfig.passiveFilterEnable = kPORT_PassiveFilterDisable;
276 portPinConfig.openDrainEnable = kPORT_OpenDrainDisable;
277 portPinConfig.driveStrength = kPORT_LowDriveStrength;
278 portPinConfig.mux = kPORT_MuxAlt9;
279 portPinConfig.inputBuffer = kPORT_InputBufferEnable;
280 portPinConfig.invertInput = kPORT_InputNormal;
281 portPinConfig.lockRegister = kPORT_UnlockRegister;
284 PORT_SetPinConfig(PORT1, 4, &portPinConfig);
286 PORT_SetPinConfig(PORT1, 5, &portPinConfig);
288 PORT_SetPinConfig(PORT1, 6, &portPinConfig);
290 PORT_SetPinConfig(PORT1, 7, &portPinConfig);
293 PORT_SetPinConfig(PORT1, 13, &portPinConfig);
295 PORT_SetPinConfig(PORT1, 14, &portPinConfig);
297 PORT_SetPinConfig(PORT1, 15, &portPinConfig);
300 PORT_SetPinConfig(PORT1, 20, &portPinConfig);
302 PORT_SetPinConfig(PORT1, 21, &portPinConfig);
343 ENET->DMA_CH[0].DMA_CHX_TXDESC_LIST_ADDR = (uint32_t) &
txDmaDesc[0];
348 ENET->DMA_CH[0].DMA_CHX_RXDESC_LIST_ADDR = (uint32_t) &
rxDmaDesc[0];
366 if(interface->phyDriver != NULL)
369 interface->phyDriver->tick(interface);
371 else if(interface->switchDriver != NULL)
374 interface->switchDriver->tick(interface);
391 NVIC_EnableIRQ(ETHERNET_IRQn);
394 if(interface->phyDriver != NULL)
397 interface->phyDriver->enableIrq(interface);
399 else if(interface->switchDriver != NULL)
402 interface->switchDriver->enableIrq(interface);
419 NVIC_DisableIRQ(ETHERNET_IRQn);
422 if(interface->phyDriver != NULL)
425 interface->phyDriver->disableIrq(interface);
427 else if(interface->switchDriver != NULL)
430 interface->switchDriver->disableIrq(interface);
455 status = ENET->DMA_CH[0].DMA_CHX_STAT;
458 if((status & ENET_DMA_CH_DMA_CHX_STAT_TI_MASK) != 0)
461 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TI_MASK;
472 if((status & ENET_DMA_CH_DMA_CHX_STAT_RI_MASK) != 0)
475 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RI_MASK;
478 nicDriverInterface->nicEvent =
TRUE;
484 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_NIS_MASK;
555 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TBU_MASK;
557 ENET->DMA_CH[0].DMA_CHX_TXDESC_TAIL_PTR = 0;
643 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RBU_MASK;
645 ENET->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR = 0;
667 ENET->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
668 ENET->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
671 acceptMulticast =
FALSE;
678 if(interface->macAddrFilter[i].refCount > 0)
681 acceptMulticast =
TRUE;
690 ENET->MAC_PACKET_FILTER |= ENET_MAC_PACKET_FILTER_PM_MASK;
694 ENET->MAC_PACKET_FILTER &= ~ENET_MAC_PACKET_FILTER_PM_MASK;
713 config = ENET->MAC_CONFIGURATION;
718 config |= ENET_MAC_CONFIGURATION_FES_MASK;
722 config &= ~ENET_MAC_CONFIGURATION_FES_MASK;
728 config |= ENET_MAC_CONFIGURATION_DM_MASK;
732 config &= ~ENET_MAC_CONFIGURATION_DM_MASK;
736 ENET->MAC_CONFIGURATION = config;
760 temp = ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_CR_MASK;
762 temp |= ENET_MAC_MDIO_ADDRESS_GOC_0_MASK | ENET_MAC_MDIO_ADDRESS_GB_MASK;
765 temp |= ENET_MAC_MDIO_ADDRESS_PA(phyAddr);
767 temp |= ENET_MAC_MDIO_ADDRESS_RDA(
regAddr);
770 ENET->MAC_MDIO_DATA =
data & ENET_MAC_MDIO_DATA_GD_MASK;
773 ENET->MAC_MDIO_ADDRESS = temp;
775 while((ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_GB_MASK) != 0)
804 temp = ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_CR_MASK;
807 temp |= ENET_MAC_MDIO_ADDRESS_GOC_1_MASK |
808 ENET_MAC_MDIO_ADDRESS_GOC_0_MASK | ENET_MAC_MDIO_ADDRESS_GB_MASK;
811 temp |= ENET_MAC_MDIO_ADDRESS_PA(phyAddr);
813 temp |= ENET_MAC_MDIO_ADDRESS_RDA(
regAddr);
816 ENET->MAC_MDIO_ADDRESS = temp;
818 while((ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_GB_MASK) != 0)
823 data = ENET->MAC_MDIO_DATA & ENET_MAC_MDIO_DATA_GD_MASK;