|
2 | 2 | #include "u_nx_ethernet.h" |
3 | 3 | #include "nx_stm32_eth_driver.h" |
4 | 4 | #include "nxd_ptp_client.h" |
| 5 | +#include "tx_api.h" |
5 | 6 | #include "u_nx_debug.h" |
6 | 7 | #include "u_tx_debug.h" |
7 | 8 | #include "c_utils.h" |
|
14 | 15 | #endif |
15 | 16 |
|
16 | 17 | /* PRIVATE MACROS */ |
17 | | -#define _IP_THREAD_STACK_SIZE 2048 |
18 | | -#define _ARP_CACHE_SIZE 1024 |
| 18 | +#define _IP_THREAD_STACK_SIZE 4096 |
| 19 | +#define _ARP_CACHE_SIZE 2048 |
19 | 20 | #define _IP_THREAD_PRIORITY 1 |
20 | 21 | #define _IP_NETWORK_MASK IP_ADDRESS(255, 255, 255, 0) |
21 | 22 | #define _UDP_QUEUE_MAXIMUM 12 |
@@ -210,6 +211,15 @@ UINT ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_ |
210 | 211 | return status; |
211 | 212 | } |
212 | 213 |
|
| 214 | + // behold the magic |
| 215 | + // this is a poll function to wait until the driver has completely initialized |
| 216 | + // without it the arp module and the TCP module fail silently and confusingly |
| 217 | + ULONG current_status; |
| 218 | + do { |
| 219 | + nx_ip_driver_direct_command(&device.ip, 51, ¤t_status); |
| 220 | + tx_thread_sleep(100); |
| 221 | + } while (current_status != 4);// NX_DRIVER_STATE_LINK_ENABLED |
| 222 | + |
213 | 223 | /* Enable ARP */ |
214 | 224 | status = nx_arp_enable( |
215 | 225 | &device.ip, // IP instance |
@@ -372,11 +382,6 @@ UINT ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_ |
372 | 382 | /* Mark device as initialized. */ |
373 | 383 | device.is_initialized = true; |
374 | 384 |
|
375 | | - ETH_MACFilterConfigTypeDef filter; |
376 | | - HAL_ETH_GetMACFilterConfig(&heth, &filter); |
377 | | - filter.BroadcastFilter = DISABLE; |
378 | | - HAL_ETH_SetMACFilterConfig(&heth, &filter); |
379 | | - |
380 | 385 | PRINTLN_INFO("Ran ethernet_init()."); |
381 | 386 | return NX_SUCCESS; |
382 | 387 | } |
@@ -507,4 +512,31 @@ NX_PTP_DATE_TIME ethernet_get_time(void) { |
507 | 512 | return date; |
508 | 513 | } |
509 | 514 |
|
| 515 | +UINT ethernet_print_arp_status(void) { |
| 516 | + ULONG arp_requests_sent = 100; |
| 517 | + ULONG arp_requests_received = 100; |
| 518 | + |
| 519 | + ULONG arp_responses_sent = 100; |
| 520 | + ULONG arp_responses_received; |
| 521 | + ULONG arp_dynamic_entries= 100; |
| 522 | + ULONG arp_static_entries= 100; |
| 523 | + ULONG arp_aged_entries= 100; |
| 524 | + ULONG arp_invalid_messages= 100; |
| 525 | + UINT status = nx_arp_info_get(&device.ip, &arp_requests_sent, &arp_requests_received, |
| 526 | + &arp_responses_sent, &arp_responses_received, |
| 527 | + &arp_dynamic_entries, &arp_static_entries, |
| 528 | + &arp_aged_entries, &arp_invalid_messages); |
| 529 | + if(status != NX_SUCCESS) { |
| 530 | + PRINTLN_ERROR("Failed to retrieve ARP info (Status: %d/%s)", status, nx_status_toString(status)); |
| 531 | + return status; |
| 532 | + } |
| 533 | + PRINTLN_INFO("ARP info REQ SENT %lu, REQ RECV %lu, RESP SENT %lu, RESP RECV %lu, DYN ENTRY %lu, S ENTRY %lu, AGED %lu, INVALID %lu", arp_requests_sent, arp_requests_received, |
| 534 | + arp_responses_sent, arp_responses_received, |
| 535 | + arp_dynamic_entries, arp_static_entries, |
| 536 | + arp_aged_entries, arp_invalid_messages); |
| 537 | + |
| 538 | + return status; |
| 539 | +} |
| 540 | + |
| 541 | + |
510 | 542 | // clang-format on |
0 commit comments