@@ -75,6 +75,8 @@ typedef struct _iomux_table_t {
7575 uint32_t configValue ;
7676} iomux_table_t ;
7777
78+ #if defined(ENET_PHY_ADDRESS )
79+
7880// ETH0 buffers and handles
7981static AT_NONCACHEABLE_SECTION_ALIGN (enet_rx_bd_struct_t g_rxBuffDescrip [ENET_RXBD_NUM ], ENET_BUFF_ALIGNMENT );
8082static AT_NONCACHEABLE_SECTION_ALIGN (enet_tx_bd_struct_t g_txBuffDescrip [ENET_TXBD_NUM ], ENET_BUFF_ALIGNMENT );
@@ -111,7 +113,9 @@ static const iomux_table_t iomux_table_enet[] = {
111113
112114static uint8_t hw_addr [6 ]; // The MAC address field
113115
114- #if defined(ENET_DUAL_PORT )
116+ #endif // defined(ENET_PHY_ADDRESS)
117+
118+ #if defined(ENET_1_PHY_ADDRESS )
115119
116120// ETH1 buffers and handles
117121static AT_NONCACHEABLE_SECTION_ALIGN (enet_rx_bd_struct_t g_rxBuffDescrip_1 [ENET_RXBD_NUM ], ENET_BUFF_ALIGNMENT );
@@ -148,17 +152,14 @@ static const iomux_table_t iomux_table_enet_1[] = {
148152
149153static uint8_t hw_addr_1 [6 ]; // The MAC address field
150154
151- #endif
152-
153- #if defined(ENET_DUAL_PORT )
155+ // Define ENET_1 to the appropriate controller for this hardware
154156#if defined MIMXRT117x_SERIES
155157#define ENET_1 ENET_1G
156158#else
157159#define ENET_1 ENET2
158160#endif
159- #else
160- #define ENET_1 ENET
161- #endif
161+
162+ #endif // defined(ENET_1_PHY_ADDRESS)
162163
163164#define PHY_AUTONEGO_TIMEOUT_US (5000000)
164165#define PHY_SETTLE_TIME_US (1000)
@@ -411,7 +412,7 @@ void eth_init_0(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int ph
411412 ENET_ActiveRead (ENET );
412413}
413414
414- #if defined(ENET_DUAL_PORT )
415+ #if defined(ENET_1_PHY_ADDRESS )
415416
416417// eth_init: Set up GPIO and the transceiver
417418void eth_init_1 (eth_t * self , int eth_id , const phy_operations_t * phy_ops , int phy_addr , bool phy_clock ) {
@@ -474,7 +475,8 @@ void eth_init_1(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int ph
474475 ENET_ActiveRead (ENET_1 );
475476}
476477
477- #endif
478+ #endif // defined(ENET_1_PHY_ADDRESS)
479+
478480// Initialize the phy interface
479481static int eth_mac_init (eth_t * self ) {
480482 return 0 ;
@@ -512,14 +514,26 @@ static err_t eth_send_frame_blocking(ENET_Type *base, enet_handle_t *handle, uin
512514static err_t eth_netif_output (struct netif * netif , struct pbuf * p ) {
513515 // This function should always be called from a context where PendSV-level IRQs are disabled
514516 status_t status ;
515- ENET_Type * enet = ENET ;
516- enet_handle_t * handle = & g_handle ;
517+ ENET_Type * enet ;
518+ enet_handle_t * handle ;
517519
518- #if defined ENET_DUAL_PORT
520+ #if defined(ENET_PHY_ADDRESS ) && defined(ENET_1_PHY_ADDRESS )
521+ // Dual port: select based on netif->state
519522 if (netif -> state == & eth_instance1 ) {
520523 enet = ENET_1 ;
521524 handle = & g_handle_1 ;
525+ } else {
526+ enet = ENET ;
527+ handle = & g_handle ;
522528 }
529+ #elif defined(ENET_1_PHY_ADDRESS )
530+ // Only ENET_1 available
531+ enet = ENET_1 ;
532+ handle = & g_handle_1 ;
533+ #else
534+ // Only ENET available
535+ enet = ENET ;
536+ handle = & g_handle ;
523537 #endif
524538
525539 eth_trace (netif -> state , (size_t )-1 , p , NETUTILS_TRACE_IS_TX | NETUTILS_TRACE_NEWLINE );
@@ -562,23 +576,30 @@ static void eth_lwip_init(eth_t *self) {
562576 ip_addr_t ipconfig [4 ];
563577
564578 self -> netif .hwaddr_len = 6 ;
579+ #if defined(ENET_PHY_ADDRESS )
565580 if (self == & eth_instance0 ) {
566581 memcpy (self -> netif .hwaddr , hw_addr , 6 );
567582 IP4_ADDR (& ipconfig [0 ], 192 , 168 , 0 , 2 );
568- #if defined ENET_DUAL_PORT
569- } else {
583+ }
584+ #endif
585+ #if defined(ENET_1_PHY_ADDRESS )
586+ if (self == & eth_instance1 ) {
570587 memcpy (self -> netif .hwaddr , hw_addr_1 , 6 );
571588 IP4_ADDR (& ipconfig [0 ], 192 , 168 , 0 , 3 );
572- #endif
573589 }
590+ #endif
574591 IP4_ADDR (& ipconfig [1 ], 255 , 255 , 255 , 0 );
575592 IP4_ADDR (& ipconfig [2 ], 192 , 168 , 0 , 1 );
576593 IP4_ADDR (& ipconfig [3 ], 8 , 8 , 8 , 8 );
577594
578595 MICROPY_PY_LWIP_ENTER
579596
580597 n -> name [0 ] = 'e' ;
598+ #if defined(ENET_PHY_ADDRESS )
581599 n -> name [1 ] = (self == & eth_instance0 ? '0' : '1' );
600+ #else
601+ n -> name [1 ] = '1' ;
602+ #endif
582603 netif_add (n , & ipconfig [0 ], & ipconfig [1 ], & ipconfig [2 ], self , eth_netif_init , ethernet_input );
583604 netif_set_hostname (n , mod_network_hostname_data );
584605 netif_set_default (n );
@@ -620,8 +641,10 @@ int eth_link_status(eth_t *self) {
620641 }
621642 } else {
622643 bool link ;
623- #if defined ENET_DUAL_PORT
644+ #if defined( ENET_PHY_ADDRESS ) && defined( ENET_1_PHY_ADDRESS )
624645 PHY_GetLinkStatus (self == & eth_instance0 ? & phyHandle : & phyHandle_1 , & link );
646+ #elif defined(ENET_1_PHY_ADDRESS )
647+ PHY_GetLinkStatus (& phyHandle_1 , & link );
625648 #else
626649 PHY_GetLinkStatus (& phyHandle , & link );
627650 #endif
@@ -654,8 +677,10 @@ int eth_stop(eth_t *self) {
654677}
655678
656679void eth_low_power_mode (eth_t * self , bool enable ) {
657- #if defined ENET_DUAL_PORT
680+ #if defined( ENET_PHY_ADDRESS ) && defined( ENET_1_PHY_ADDRESS )
658681 ENET_EnableSleepMode (self == & eth_instance0 ? ENET : ENET_1 , enable );
682+ #elif defined(ENET_1_PHY_ADDRESS )
683+ ENET_EnableSleepMode (ENET_1 , enable );
659684 #else
660685 ENET_EnableSleepMode (ENET , enable );
661686 #endif
0 commit comments