2024-04-02 08:58:26 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
|
*/
|
2018-09-20 07:26:14 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "sdkconfig.h"
|
2018-09-20 07:26:14 -04:00
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_console.h"
|
2024-04-02 08:58:26 -04:00
|
|
|
#include "esp_event.h"
|
|
|
|
#include "esp_eth.h"
|
|
|
|
#include "esp_netif.h"
|
|
|
|
#include "ethernet_init.h"
|
2018-09-20 07:26:14 -04:00
|
|
|
#include "esp_vfs_fat.h"
|
2020-02-03 05:01:04 -05:00
|
|
|
#include "cmd_system.h"
|
|
|
|
#include "cmd_ethernet.h"
|
2018-09-20 07:26:14 -04:00
|
|
|
|
2024-04-02 08:58:26 -04:00
|
|
|
#include "iperf_cmd.h"
|
|
|
|
|
2019-04-10 04:24:50 -04:00
|
|
|
static const char *TAG = "eth_example";
|
2018-09-20 07:26:14 -04:00
|
|
|
|
2024-04-02 08:58:26 -04:00
|
|
|
static esp_eth_handle_t *s_eth_handles = NULL;
|
|
|
|
static uint8_t s_eth_port_cnt = 0;
|
|
|
|
|
2019-04-10 04:24:50 -04:00
|
|
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
2018-09-20 07:26:14 -04:00
|
|
|
|
|
|
|
#define MOUNT_PATH "/data"
|
|
|
|
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
static void initialize_filesystem(void)
|
2018-09-20 07:26:14 -04:00
|
|
|
{
|
|
|
|
static wl_handle_t wl_handle;
|
|
|
|
const esp_vfs_fat_mount_config_t mount_config = {
|
|
|
|
.max_files = 4,
|
|
|
|
.format_if_mount_failed = true
|
|
|
|
};
|
2022-03-04 14:15:49 -05:00
|
|
|
esp_err_t err = esp_vfs_fat_spiflash_mount_rw_wl(MOUNT_PATH, "storage", &mount_config, &wl_handle);
|
2018-09-20 07:26:14 -04:00
|
|
|
if (err != ESP_OK) {
|
|
|
|
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 04:24:50 -04:00
|
|
|
#endif // CONFIG_EXAMPLE_STORE_HISTORY
|
2018-09-20 07:26:14 -04:00
|
|
|
|
2024-04-02 08:58:26 -04:00
|
|
|
void init_ethernet_and_netif(void)
|
|
|
|
{
|
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(example_eth_init(&s_eth_handles, &s_eth_port_cnt));
|
|
|
|
|
|
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
|
|
|
esp_netif_inherent_config_t esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
|
|
|
|
esp_netif_config_t cfg_spi = {
|
|
|
|
.base = &esp_netif_config,
|
|
|
|
.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH
|
|
|
|
};
|
|
|
|
char if_key_str[10];
|
|
|
|
char if_desc_str[10];
|
|
|
|
char num_str[3];
|
|
|
|
for (int i = 0; i < s_eth_port_cnt; i++) {
|
|
|
|
itoa(i, num_str, 10);
|
|
|
|
strcat(strcpy(if_key_str, "ETH_"), num_str);
|
|
|
|
strcat(strcpy(if_desc_str, "eth"), num_str);
|
|
|
|
esp_netif_config.if_key = if_key_str;
|
|
|
|
esp_netif_config.if_desc = if_desc_str;
|
|
|
|
esp_netif_config.route_prio -= i*5;
|
|
|
|
esp_netif_t *eth_netif = esp_netif_new(&cfg_spi);
|
|
|
|
|
|
|
|
// attach Ethernet driver to TCP/IP stack
|
|
|
|
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(s_eth_handles[i])));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < s_eth_port_cnt; i++) {
|
|
|
|
ESP_ERROR_CHECK(esp_eth_start(s_eth_handles[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 05:33:30 -04:00
|
|
|
void app_main(void)
|
2018-09-20 07:26:14 -04:00
|
|
|
{
|
2024-04-02 08:58:26 -04:00
|
|
|
init_ethernet_and_netif();
|
|
|
|
|
2020-05-27 23:00:56 -04:00
|
|
|
esp_console_repl_t *repl = NULL;
|
2020-02-03 05:01:04 -05:00
|
|
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
2020-05-27 23:00:56 -04:00
|
|
|
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
2019-04-10 04:24:50 -04:00
|
|
|
#if CONFIG_EXAMPLE_STORE_HISTORY
|
2018-09-20 07:26:14 -04:00
|
|
|
initialize_filesystem();
|
2020-02-03 05:01:04 -05:00
|
|
|
repl_config.history_save_path = HISTORY_PATH;
|
2018-09-20 07:26:14 -04:00
|
|
|
#endif
|
2020-05-27 23:00:56 -04:00
|
|
|
repl_config.prompt = "iperf>";
|
|
|
|
// init console REPL environment
|
|
|
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
|
2018-09-20 07:26:14 -04:00
|
|
|
|
|
|
|
/* Register commands */
|
2020-12-14 22:00:02 -05:00
|
|
|
register_system_common();
|
2024-04-02 08:58:26 -04:00
|
|
|
app_register_iperf_commands();
|
|
|
|
register_ethernet_commands();
|
2018-09-20 07:26:14 -04:00
|
|
|
|
|
|
|
printf("\n =======================================================\n");
|
|
|
|
printf(" | Steps to Test Ethernet Bandwidth |\n");
|
|
|
|
printf(" | |\n");
|
|
|
|
printf(" | 1. Enter 'help', check all supported commands |\n");
|
2019-04-10 04:24:50 -04:00
|
|
|
printf(" | 2. Wait ESP32 to get IP from DHCP |\n");
|
|
|
|
printf(" | 3. Enter 'ethernet info', optional |\n");
|
2018-09-20 07:26:14 -04:00
|
|
|
printf(" | 4. Server: 'iperf -u -s -i 3' |\n");
|
2019-04-10 04:24:50 -04:00
|
|
|
printf(" | 5. Client: 'iperf -u -c SERVER_IP -t 60 -i 3' |\n");
|
2018-09-20 07:26:14 -04:00
|
|
|
printf(" | |\n");
|
|
|
|
printf(" =======================================================\n\n");
|
|
|
|
|
2020-02-03 05:01:04 -05:00
|
|
|
// start console REPL
|
2020-05-27 23:00:56 -04:00
|
|
|
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
2018-09-20 07:26:14 -04:00
|
|
|
}
|