|
31 | 31 | #include "py/mperrno.h" |
32 | 32 | #include "ticks.h" |
33 | 33 |
|
34 | | -#if defined(IOMUX_TABLE_ENET) |
| 34 | +#if defined(ENET_PHY_ADDRESS) || defined(ENET_1_PHY_ADDRESS) |
35 | 35 |
|
36 | 36 | #include "pin.h" |
37 | 37 | #include "shared/netutils/netutils.h" |
@@ -75,6 +75,8 @@ typedef struct _iomux_table_t { |
75 | 75 | uint32_t configValue; |
76 | 76 | } iomux_table_t; |
77 | 77 |
|
| 78 | +#if defined(ENET_PHY_ADDRESS) |
| 79 | + |
78 | 80 | // ETH0 buffers and handles |
79 | 81 | static AT_NONCACHEABLE_SECTION_ALIGN(enet_rx_bd_struct_t g_rxBuffDescrip[ENET_RXBD_NUM], ENET_BUFF_ALIGNMENT); |
80 | 82 | static 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[] = { |
111 | 113 |
|
112 | 114 | static uint8_t hw_addr[6]; // The MAC address field |
113 | 115 |
|
114 | | -#if defined(ENET_DUAL_PORT) |
| 116 | +#endif // defined(ENET_PHY_ADDRESS) |
| 117 | + |
| 118 | +#if defined(ENET_1_PHY_ADDRESS) |
115 | 119 |
|
116 | 120 | // ETH1 buffers and handles |
117 | 121 | static 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[] = { |
148 | 152 |
|
149 | 153 | static uint8_t hw_addr_1[6]; // The MAC address field |
150 | 154 |
|
151 | | -#endif |
152 | | - |
153 | | -#if defined(ENET_DUAL_PORT) |
| 155 | +// Define ENET_1 to the appropriate controller for this hardware |
154 | 156 | #if defined MIMXRT117x_SERIES |
155 | 157 | #define ENET_1 ENET_1G |
156 | 158 | #else |
157 | 159 | #define ENET_1 ENET2 |
158 | 160 | #endif |
159 | | -#else |
160 | | -#define ENET_1 ENET |
161 | | -#endif |
| 161 | + |
| 162 | +#endif // defined(ENET_1_PHY_ADDRESS) |
162 | 163 |
|
163 | 164 | #define PHY_AUTONEGO_TIMEOUT_US (5000000) |
164 | 165 | #define PHY_SETTLE_TIME_US (1000) |
@@ -357,6 +358,8 @@ static void eth_phy_init(phy_handle_t *phyHandle, phy_config_t *phy_config, |
357 | 358 | mp_hal_delay_us(phy_settle_time); |
358 | 359 | } |
359 | 360 |
|
| 361 | +#if defined(ENET_PHY_ADDRESS) |
| 362 | + |
360 | 363 | // eth_init: Set up GPIO and the transceiver |
361 | 364 | void eth_init_0(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int phy_addr, bool phy_clock) { |
362 | 365 | // Configuration values |
@@ -411,7 +414,9 @@ void eth_init_0(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int ph |
411 | 414 | ENET_ActiveRead(ENET); |
412 | 415 | } |
413 | 416 |
|
414 | | -#if defined(ENET_DUAL_PORT) |
| 417 | +#endif // defined(ENET_PHY_ADDRESS) |
| 418 | + |
| 419 | +#if defined(ENET_1_PHY_ADDRESS) |
415 | 420 |
|
416 | 421 | // eth_init: Set up GPIO and the transceiver |
417 | 422 | void eth_init_1(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int phy_addr, bool phy_clock) { |
@@ -474,7 +479,8 @@ void eth_init_1(eth_t *self, int eth_id, const phy_operations_t *phy_ops, int ph |
474 | 479 | ENET_ActiveRead(ENET_1); |
475 | 480 | } |
476 | 481 |
|
477 | | -#endif |
| 482 | +#endif // defined(ENET_1_PHY_ADDRESS) |
| 483 | + |
478 | 484 | // Initialize the phy interface |
479 | 485 | static int eth_mac_init(eth_t *self) { |
480 | 486 | return 0; |
@@ -512,14 +518,26 @@ static err_t eth_send_frame_blocking(ENET_Type *base, enet_handle_t *handle, uin |
512 | 518 | static err_t eth_netif_output(struct netif *netif, struct pbuf *p) { |
513 | 519 | // This function should always be called from a context where PendSV-level IRQs are disabled |
514 | 520 | status_t status; |
515 | | - ENET_Type *enet = ENET; |
516 | | - enet_handle_t *handle = &g_handle; |
| 521 | + ENET_Type *enet; |
| 522 | + enet_handle_t *handle; |
517 | 523 |
|
518 | | - #if defined ENET_DUAL_PORT |
| 524 | + #if defined(ENET_PHY_ADDRESS) && defined(ENET_1_PHY_ADDRESS) |
| 525 | + // Dual port: select based on netif->state |
519 | 526 | if (netif->state == ð_instance1) { |
520 | 527 | enet = ENET_1; |
521 | 528 | handle = &g_handle_1; |
| 529 | + } else { |
| 530 | + enet = ENET; |
| 531 | + handle = &g_handle; |
522 | 532 | } |
| 533 | + #elif defined(ENET_1_PHY_ADDRESS) |
| 534 | + // Only ENET_1 available |
| 535 | + enet = ENET_1; |
| 536 | + handle = &g_handle_1; |
| 537 | + #else |
| 538 | + // Only ENET available |
| 539 | + enet = ENET; |
| 540 | + handle = &g_handle; |
523 | 541 | #endif |
524 | 542 |
|
525 | 543 | eth_trace(netif->state, (size_t)-1, p, NETUTILS_TRACE_IS_TX | NETUTILS_TRACE_NEWLINE); |
@@ -562,23 +580,30 @@ static void eth_lwip_init(eth_t *self) { |
562 | 580 | ip_addr_t ipconfig[4]; |
563 | 581 |
|
564 | 582 | self->netif.hwaddr_len = 6; |
| 583 | + #if defined(ENET_PHY_ADDRESS) |
565 | 584 | if (self == ð_instance0) { |
566 | 585 | memcpy(self->netif.hwaddr, hw_addr, 6); |
567 | 586 | IP4_ADDR(&ipconfig[0], 192, 168, 0, 2); |
568 | | - #if defined ENET_DUAL_PORT |
569 | | - } else { |
| 587 | + } |
| 588 | + #endif |
| 589 | + #if defined(ENET_1_PHY_ADDRESS) |
| 590 | + if (self == ð_instance1) { |
570 | 591 | memcpy(self->netif.hwaddr, hw_addr_1, 6); |
571 | 592 | IP4_ADDR(&ipconfig[0], 192, 168, 0, 3); |
572 | | - #endif |
573 | 593 | } |
| 594 | + #endif |
574 | 595 | IP4_ADDR(&ipconfig[1], 255, 255, 255, 0); |
575 | 596 | IP4_ADDR(&ipconfig[2], 192, 168, 0, 1); |
576 | 597 | IP4_ADDR(&ipconfig[3], 8, 8, 8, 8); |
577 | 598 |
|
578 | 599 | MICROPY_PY_LWIP_ENTER |
579 | 600 |
|
580 | 601 | n->name[0] = 'e'; |
| 602 | + #if defined(ENET_PHY_ADDRESS) |
581 | 603 | n->name[1] = (self == ð_instance0 ? '0' : '1'); |
| 604 | + #else |
| 605 | + n->name[1] = '1'; |
| 606 | + #endif |
582 | 607 | netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, eth_netif_init, ethernet_input); |
583 | 608 | netif_set_hostname(n, mod_network_hostname_data); |
584 | 609 | netif_set_default(n); |
@@ -620,8 +645,10 @@ int eth_link_status(eth_t *self) { |
620 | 645 | } |
621 | 646 | } else { |
622 | 647 | bool link; |
623 | | - #if defined ENET_DUAL_PORT |
| 648 | + #if defined(ENET_PHY_ADDRESS) && defined(ENET_1_PHY_ADDRESS) |
624 | 649 | PHY_GetLinkStatus(self == ð_instance0 ? &phyHandle : &phyHandle_1, &link); |
| 650 | + #elif defined(ENET_1_PHY_ADDRESS) |
| 651 | + PHY_GetLinkStatus(&phyHandle_1, &link); |
625 | 652 | #else |
626 | 653 | PHY_GetLinkStatus(&phyHandle, &link); |
627 | 654 | #endif |
@@ -654,10 +681,12 @@ int eth_stop(eth_t *self) { |
654 | 681 | } |
655 | 682 |
|
656 | 683 | void eth_low_power_mode(eth_t *self, bool enable) { |
657 | | - #if defined ENET_DUAL_PORT |
| 684 | + #if defined(ENET_PHY_ADDRESS) && defined(ENET_1_PHY_ADDRESS) |
658 | 685 | ENET_EnableSleepMode(self == ð_instance0 ? ENET : ENET_1, enable); |
| 686 | + #elif defined(ENET_1_PHY_ADDRESS) |
| 687 | + ENET_EnableSleepMode(ENET_1, enable); |
659 | 688 | #else |
660 | 689 | ENET_EnableSleepMode(ENET, enable); |
661 | 690 | #endif |
662 | 691 | } |
663 | | -#endif // defined(IOMUX_TABLE_ENET) |
| 692 | +#endif // defined(ENET_PHY_ADDRESS) || defined(ENET_1_PHY_ADDRESS) |
0 commit comments