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 N947 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_FRDM_MCXN947)
263 port_pin_config_t portPinConfig;
264 gpio_pin_config_t gpioPinConfig;
267 CLOCK_EnableClock(kCLOCK_Port1);
270 SYSCON0->ENET_PHY_INTF_SEL |= SYSCON_ENET_PHY_INTF_SEL_PHY_SEL_MASK;
273 portPinConfig.pullSelect = kPORT_PullDisable;
274 portPinConfig.pullValueSelect = kPORT_LowPullResistor;
275 portPinConfig.slewRate = kPORT_FastSlewRate;
276 portPinConfig.passiveFilterEnable = kPORT_PassiveFilterDisable;
277 portPinConfig.openDrainEnable = kPORT_OpenDrainDisable;
278 portPinConfig.driveStrength = kPORT_LowDriveStrength;
279 portPinConfig.mux = kPORT_MuxAlt9;
280 portPinConfig.inputBuffer = kPORT_InputBufferEnable;
281 portPinConfig.invertInput = kPORT_InputNormal;
282 portPinConfig.lockRegister = kPORT_UnlockRegister;
285 PORT_SetPinConfig(PORT1, 4, &portPinConfig);
287 PORT_SetPinConfig(PORT1, 5, &portPinConfig);
289 PORT_SetPinConfig(PORT1, 6, &portPinConfig);
291 PORT_SetPinConfig(PORT1, 7, &portPinConfig);
294 PORT_SetPinConfig(PORT1, 13, &portPinConfig);
296 PORT_SetPinConfig(PORT1, 14, &portPinConfig);
298 PORT_SetPinConfig(PORT1, 15, &portPinConfig);
301 PORT_SetPinConfig(PORT1, 20, &portPinConfig);
303 PORT_SetPinConfig(PORT1, 21, &portPinConfig);
306 gpioPinConfig.pinDirection = kGPIO_DigitalOutput;
307 gpioPinConfig.outputLogic = 0;
308 GPIO_PinInit(GPIO5, 8, &gpioPinConfig);
311 GPIO_PinWrite(GPIO5, 8, 0);
313 GPIO_PinWrite(GPIO5, 8, 1);
317 #elif defined(USE_MCX_N9XX_EVK)
318 port_pin_config_t portPinConfig;
321 CLOCK_EnableClock(kCLOCK_Port1);
324 SYSCON0->ENET_PHY_INTF_SEL |= SYSCON_ENET_PHY_INTF_SEL_PHY_SEL_MASK;
327 portPinConfig.pullSelect = kPORT_PullDisable;
328 portPinConfig.pullValueSelect = kPORT_LowPullResistor;
329 portPinConfig.slewRate = kPORT_FastSlewRate;
330 portPinConfig.passiveFilterEnable = kPORT_PassiveFilterDisable;
331 portPinConfig.openDrainEnable = kPORT_OpenDrainDisable;
332 portPinConfig.driveStrength = kPORT_LowDriveStrength;
333 portPinConfig.mux = kPORT_MuxAlt9;
334 portPinConfig.inputBuffer = kPORT_InputBufferEnable;
335 portPinConfig.invertInput = kPORT_InputNormal;
336 portPinConfig.lockRegister = kPORT_UnlockRegister;
339 PORT_SetPinConfig(PORT1, 4, &portPinConfig);
341 PORT_SetPinConfig(PORT1, 5, &portPinConfig);
343 PORT_SetPinConfig(PORT1, 6, &portPinConfig);
345 PORT_SetPinConfig(PORT1, 7, &portPinConfig);
348 PORT_SetPinConfig(PORT1, 13, &portPinConfig);
350 PORT_SetPinConfig(PORT1, 14, &portPinConfig);
352 PORT_SetPinConfig(PORT1, 15, &portPinConfig);
355 PORT_SetPinConfig(PORT1, 20, &portPinConfig);
357 PORT_SetPinConfig(PORT1, 21, &portPinConfig);
398 ENET->DMA_CH[0].DMA_CHX_TXDESC_LIST_ADDR = (uint32_t) &
txDmaDesc[0];
403 ENET->DMA_CH[0].DMA_CHX_RXDESC_LIST_ADDR = (uint32_t) &
rxDmaDesc[0];
421 if(interface->phyDriver != NULL)
424 interface->phyDriver->tick(interface);
426 else if(interface->switchDriver != NULL)
429 interface->switchDriver->tick(interface);
446 NVIC_EnableIRQ(ETHERNET_IRQn);
449 if(interface->phyDriver != NULL)
452 interface->phyDriver->enableIrq(interface);
454 else if(interface->switchDriver != NULL)
457 interface->switchDriver->enableIrq(interface);
474 NVIC_DisableIRQ(ETHERNET_IRQn);
477 if(interface->phyDriver != NULL)
480 interface->phyDriver->disableIrq(interface);
482 else if(interface->switchDriver != NULL)
485 interface->switchDriver->disableIrq(interface);
510 status = ENET->DMA_CH[0].DMA_CHX_STAT;
513 if((status & ENET_DMA_CH_DMA_CHX_STAT_TI_MASK) != 0)
516 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TI_MASK;
527 if((status & ENET_DMA_CH_DMA_CHX_STAT_RI_MASK) != 0)
530 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RI_MASK;
533 nicDriverInterface->nicEvent =
TRUE;
539 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_NIS_MASK;
610 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_TBU_MASK;
612 ENET->DMA_CH[0].DMA_CHX_TXDESC_TAIL_PTR = 0;
698 ENET->DMA_CH[0].DMA_CHX_STAT = ENET_DMA_CH_DMA_CHX_STAT_RBU_MASK;
700 ENET->DMA_CH[0].DMA_CHX_RXDESC_TAIL_PTR = 0;
722 ENET->MAC_ADDRESS0_LOW = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
723 ENET->MAC_ADDRESS0_HIGH = interface->macAddr.w[2];
726 acceptMulticast =
FALSE;
733 if(interface->macAddrFilter[i].refCount > 0)
736 acceptMulticast =
TRUE;
745 ENET->MAC_PACKET_FILTER |= ENET_MAC_PACKET_FILTER_PM_MASK;
749 ENET->MAC_PACKET_FILTER &= ~ENET_MAC_PACKET_FILTER_PM_MASK;
768 config = ENET->MAC_CONFIGURATION;
773 config |= ENET_MAC_CONFIGURATION_FES_MASK;
777 config &= ~ENET_MAC_CONFIGURATION_FES_MASK;
783 config |= ENET_MAC_CONFIGURATION_DM_MASK;
787 config &= ~ENET_MAC_CONFIGURATION_DM_MASK;
791 ENET->MAC_CONFIGURATION = config;
815 temp = ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_CR_MASK;
817 temp |= ENET_MAC_MDIO_ADDRESS_GOC_0_MASK | ENET_MAC_MDIO_ADDRESS_GB_MASK;
820 temp |= ENET_MAC_MDIO_ADDRESS_PA(phyAddr);
822 temp |= ENET_MAC_MDIO_ADDRESS_RDA(
regAddr);
825 ENET->MAC_MDIO_DATA =
data & ENET_MAC_MDIO_DATA_GD_MASK;
828 ENET->MAC_MDIO_ADDRESS = temp;
830 while((ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_GB_MASK) != 0)
859 temp = ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_CR_MASK;
862 temp |= ENET_MAC_MDIO_ADDRESS_GOC_1_MASK |
863 ENET_MAC_MDIO_ADDRESS_GOC_0_MASK | ENET_MAC_MDIO_ADDRESS_GB_MASK;
866 temp |= ENET_MAC_MDIO_ADDRESS_PA(phyAddr);
868 temp |= ENET_MAC_MDIO_ADDRESS_RDA(
regAddr);
871 ENET->MAC_MDIO_ADDRESS = temp;
873 while((ENET->MAC_MDIO_ADDRESS & ENET_MAC_MDIO_ADDRESS_GB_MASK) != 0)
878 data = ENET->MAC_MDIO_DATA & ENET_MAC_MDIO_DATA_GD_MASK;