forked from espressif/esp-idf
Merge branch 'feature/emac_start_stop_test_v4.4' into 'release/v4.4'
test_emac: extended Ethernet start/stop stress test (v4.4) See merge request espressif/esp-idf!17306
This commit is contained in:
@@ -533,7 +533,7 @@ UT_006:
|
||||
|
||||
UT_007:
|
||||
extends: .unit_test_esp32_template
|
||||
parallel: 5
|
||||
parallel: 7
|
||||
tags:
|
||||
- ESP32_IDF
|
||||
- UT_T1_1
|
||||
|
@@ -1,16 +1,8 @@
|
||||
// Copyright 2019-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stdatomic.h>
|
||||
@@ -270,13 +262,11 @@ esp_err_t esp_eth_start(esp_eth_handle_t hdl)
|
||||
esp_eth_driver_t *eth_driver = (esp_eth_driver_t *)hdl;
|
||||
ESP_GOTO_ON_FALSE(eth_driver, ESP_ERR_INVALID_ARG, err, TAG, "ethernet driver handle can't be null");
|
||||
esp_eth_phy_t *phy = eth_driver->phy;
|
||||
esp_eth_mac_t *mac = eth_driver->mac;
|
||||
// check if driver has stopped
|
||||
esp_eth_fsm_t expected_fsm = ESP_ETH_FSM_STOP;
|
||||
ESP_GOTO_ON_FALSE(atomic_compare_exchange_strong(ð_driver->fsm, &expected_fsm, ESP_ETH_FSM_START),
|
||||
ESP_ERR_INVALID_STATE, err, TAG, "driver started already");
|
||||
ESP_GOTO_ON_ERROR(phy->negotiate(phy), err, TAG, "phy negotiation failed");
|
||||
ESP_GOTO_ON_ERROR(mac->start(mac), err, TAG, "start mac failed");
|
||||
ESP_GOTO_ON_ERROR(esp_event_post(ETH_EVENT, ETHERNET_EVENT_START, ð_driver, sizeof(esp_eth_driver_t *), 0),
|
||||
err, TAG, "send ETHERNET_EVENT_START event failed");
|
||||
ESP_GOTO_ON_ERROR(phy->get_link(phy), err, TAG, "phy get link status failed");
|
||||
|
@@ -1,16 +1,8 @@
|
||||
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/cdefs.h>
|
||||
@@ -41,7 +33,7 @@
|
||||
static const char *TAG = "esp.emac";
|
||||
|
||||
#define PHY_OPERATION_TIMEOUT_US (1000)
|
||||
#define MAC_STOP_TIMEOUT_MS (100)
|
||||
#define MAC_STOP_TIMEOUT_US (250)
|
||||
#define FLOW_CONTROL_LOW_WATER_MARK (CONFIG_ETH_DMA_RX_BUFFER_NUM / 3)
|
||||
#define FLOW_CONTROL_HIGH_WATER_MARK (FLOW_CONTROL_LOW_WATER_MARK * 2)
|
||||
|
||||
@@ -72,6 +64,8 @@ typedef struct {
|
||||
|
||||
static esp_err_t esp_emac_alloc_driver_obj(const eth_mac_config_t *config, emac_esp32_t **emac_out_hdl, void **out_descriptors);
|
||||
static void esp_emac_free_driver_obj(emac_esp32_t *emac, void *descriptors);
|
||||
static esp_err_t emac_esp32_start(esp_eth_mac_t *mac);
|
||||
static esp_err_t emac_esp32_stop(esp_eth_mac_t *mac);
|
||||
|
||||
static esp_err_t emac_esp32_set_mediator(esp_eth_mac_t *mac, esp_eth_mediator_t *eth)
|
||||
{
|
||||
@@ -158,11 +152,11 @@ static esp_err_t emac_esp32_set_link(esp_eth_mac_t *mac, eth_link_t link)
|
||||
switch (link) {
|
||||
case ETH_LINK_UP:
|
||||
ESP_GOTO_ON_ERROR(esp_intr_enable(emac->intr_hdl), err, TAG, "enable interrupt failed");
|
||||
emac_hal_start(&emac->hal);
|
||||
emac_esp32_start(mac);
|
||||
break;
|
||||
case ETH_LINK_DOWN:
|
||||
ESP_GOTO_ON_ERROR(esp_intr_disable(emac->intr_hdl), err, TAG, "disable interrupt failed");
|
||||
emac_hal_stop(&emac->hal);
|
||||
emac_esp32_stop(mac);
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "unknown link status");
|
||||
@@ -404,9 +398,9 @@ static esp_err_t emac_esp32_stop(esp_eth_mac_t *mac)
|
||||
if ((ret = emac_hal_stop(&emac->hal)) == ESP_OK) {
|
||||
break;
|
||||
}
|
||||
to += 20;
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
} while (to < MAC_STOP_TIMEOUT_MS);
|
||||
to += 25;
|
||||
esp_rom_delay_us(25);
|
||||
} while (to < MAC_STOP_TIMEOUT_US);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,15 @@
|
||||
# EMAC Test
|
||||
| Supported Targets | ESP32 |
|
||||
| ----------------- | ----- |
|
||||
|
||||
This test app is used to test MAC layer behavior with different PHY chips:
|
||||
|
||||
- ip101
|
||||
- lan8720
|
||||
- IP101
|
||||
- LAN8720
|
||||
|
||||
## Prerequisites
|
||||
Install third part Python packages:
|
||||
|
||||
```bash
|
||||
pip install scapy
|
||||
```
|
||||
|
@@ -1,9 +1,12 @@
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
from collections.abc import Callable
|
||||
from threading import Thread
|
||||
|
||||
import tiny_test_fw
|
||||
import ttfw_idf
|
||||
from scapy.all import Ether, raw
|
||||
from ttfw_idf import TestFormat
|
||||
|
||||
try:
|
||||
@@ -39,26 +42,52 @@ def configure_eth_if(func): # type: (typing.Any) -> typing.Any
|
||||
def check_eth_recv_packet(so): # type: (socket.socket) -> None
|
||||
so.settimeout(10)
|
||||
try:
|
||||
pkt = so.recv(1024)
|
||||
for i in range(128, 1024):
|
||||
if pkt[i] != i & 0xff:
|
||||
eth_frame = Ether(so.recv(1024))
|
||||
for i in range(0, 1010):
|
||||
if eth_frame.load[i] != i & 0xff:
|
||||
raise Exception('Packet content mismatch')
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@configure_eth_if
|
||||
def send_eth_packet(so, mac): # type: (socket.socket, bytes) -> None
|
||||
def send_eth_packet(so, mac): # type: (socket.socket, str) -> None
|
||||
so.settimeout(10)
|
||||
pkt = bytearray()
|
||||
pkt += mac # dest
|
||||
pkt += so.getsockname()[4] # src
|
||||
pkt += bytes.fromhex('2222') # proto
|
||||
pkt += bytes(1010) # padding to 1024
|
||||
for i in range(128, 1024):
|
||||
pkt[i] = i & 0xff
|
||||
payload = bytearray(1010)
|
||||
for i, _ in enumerate(payload):
|
||||
payload[i] = i & 0xff
|
||||
eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=0x2222) / raw(payload)
|
||||
try:
|
||||
so.send(pkt)
|
||||
so.send(raw(eth_frame))
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@configure_eth_if
|
||||
def recv_resp_poke(so, i): # type: (socket.socket, int) -> None
|
||||
so.settimeout(10)
|
||||
try:
|
||||
eth_frame = Ether(so.recv(60))
|
||||
|
||||
if eth_frame.type == 0x2222 and eth_frame.load[0] == 0xfa:
|
||||
if eth_frame.load[1] != i:
|
||||
raise Exception('Missed Poke Packet')
|
||||
eth_frame.dst = eth_frame.src
|
||||
eth_frame.src = so.getsockname()[4]
|
||||
eth_frame.load = bytes.fromhex('fb') # POKE_RESP code
|
||||
so.send(raw(eth_frame))
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@configure_eth_if
|
||||
def traffic_gen(so, mac, enabled): # type: (socket.socket, str, Callable) -> None
|
||||
payload = bytes.fromhex('ff') # DUMMY_TRAFFIC code
|
||||
payload += bytes(1485)
|
||||
eth_frame = Ether(dst=mac, src=so.getsockname()[4], type=0x2222) / raw(payload)
|
||||
try:
|
||||
while enabled() == 1:
|
||||
so.send(raw(eth_frame))
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
@@ -78,14 +107,43 @@ def test_component_ut_esp_eth(env, appname): # type: (tiny_test_fw.Env, str) ->
|
||||
stdout = dut.expect("Enter next test, or 'enter' to see menu", full_stdout=True)
|
||||
ttfw_idf.ComponentUTResult.parse_result(stdout, test_format=TestFormat.UNITY_BASIC)
|
||||
dut.write('"recv_pkt"')
|
||||
expect_result = dut.expect(re.compile(r'([\s\S]*)DUT MAC: ([0-9a-zA-Z:]*)'), timeout=10)
|
||||
expect_result = dut.expect(re.compile(
|
||||
r'([\s\S]*)'
|
||||
r'DUT MAC: ([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})'),
|
||||
timeout=10
|
||||
)
|
||||
stdout = expect_result[0]
|
||||
send_eth_packet(bytes.fromhex('ffffffffffff')) # broadcast frame
|
||||
send_eth_packet(bytes.fromhex('010000000000')) # multicast frame
|
||||
send_eth_packet(bytes.fromhex(expect_result[1].replace(':', ''))) # unicast frame
|
||||
send_eth_packet('ff:ff:ff:ff:ff:ff') # broadcast frame
|
||||
send_eth_packet('01:00:00:00:00:00') # multicast frame
|
||||
send_eth_packet(expect_result[1]) # unicast frame
|
||||
stdout += dut.expect("Enter next test, or 'enter' to see menu", full_stdout=True)
|
||||
ttfw_idf.ComponentUTResult.parse_result(stdout, test_format=TestFormat.UNITY_BASIC)
|
||||
|
||||
dut.write('"start_stop_stress_test"')
|
||||
expect_result = dut.expect(re.compile(
|
||||
r'([\s\S]*)'
|
||||
r'DUT MAC: ([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})'),
|
||||
timeout=10
|
||||
)
|
||||
|
||||
# Start/stop under heavy Tx traffic
|
||||
for tx_i in range(10):
|
||||
recv_resp_poke(tx_i)
|
||||
|
||||
# Start/stop under heavy Rx traffic
|
||||
traffic_en = 1
|
||||
thread = Thread(target=traffic_gen, args=(expect_result[1], lambda:traffic_en, ))
|
||||
thread.start()
|
||||
try:
|
||||
for rx_i in range(10):
|
||||
recv_resp_poke(rx_i)
|
||||
finally:
|
||||
traffic_en = 0
|
||||
thread.join()
|
||||
|
||||
stdout = dut.expect("Enter next test, or 'enter' to see menu", full_stdout=True)
|
||||
ttfw_idf.ComponentUTResult.parse_result(stdout, test_format=TestFormat.UNITY_BASIC)
|
||||
|
||||
|
||||
@ttfw_idf.idf_component_unit_test(env_tag='COMPONENT_UT_IP101', target=['esp32'])
|
||||
def test_component_ut_esp_eth_ip101(env, _): # type: (tiny_test_fw.Env, typing.Any) -> None
|
||||
|
@@ -17,6 +17,10 @@
|
||||
#define ETH_MULTICAST_RECV_BIT BIT(1)
|
||||
#define ETH_UNICAST_RECV_BIT BIT(2)
|
||||
|
||||
#define POKE_REQ 0xFA
|
||||
#define POKE_RESP 0xFB
|
||||
#define DUMMY_TRAFFIC 0xFF
|
||||
|
||||
typedef struct {
|
||||
uint8_t dest[6];
|
||||
uint8_t src[6];
|
||||
@@ -170,12 +174,14 @@ TEST_CASE("ethernet_broadcast_transmit", "[esp_eth]")
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_start(eth_handle)); // start Ethernet driver state machine
|
||||
|
||||
TEST_ASSERT(xSemaphoreTake(mutex, pdMS_TO_TICKS(3000)));
|
||||
// even if PHY (IP101) indicates autonegotiation done and link up, it sometimes may miss few packets after atonego reset, hence wait a bit
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
|
||||
emac_frame_t *pkt = malloc(1024);
|
||||
pkt->proto = 0x2222;
|
||||
memset(pkt->dest, 0xff, 6); // broadcast addr
|
||||
for (int i = 128; i < 1024; ++i){
|
||||
((uint8_t*)pkt)[i] = i & 0xff;
|
||||
for (int i = 0; i < (1024 - ETH_HEADER_LEN); ++i){
|
||||
pkt->data[i] = i & 0xff;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_transmit(eth_handle, pkt, 1024));
|
||||
@@ -198,8 +204,8 @@ esp_err_t l2_packet_txrx_test_cb(esp_eth_handle_t hdl, uint8_t *buffer, uint32_t
|
||||
// check header
|
||||
if (pkt->proto == 0x2222 && length == 1024) {
|
||||
// check content
|
||||
for (int i = 128; i < 1024; ++i) {
|
||||
if (buffer[i] != (i & 0xff)) {
|
||||
for (int i = 0; i < (length - ETH_HEADER_LEN); ++i) {
|
||||
if (pkt->data[i] != (i & 0xff)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
}
|
||||
@@ -259,6 +265,171 @@ TEST_CASE("recv_pkt", "[esp_eth]")
|
||||
vEventGroupDelete(eth_event_group);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SemaphoreHandle_t mutex;
|
||||
int rx_pkt_cnt;
|
||||
} recv_info_t;
|
||||
|
||||
TEST_CASE("start_stop_stress_test", "[esp_eth]")
|
||||
{
|
||||
void eth_event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
EventGroupHandle_t eth_event_group = (EventGroupHandle_t)arg;
|
||||
switch (event_id) {
|
||||
case ETHERNET_EVENT_CONNECTED:
|
||||
xEventGroupSetBits(eth_event_group, ETH_CONNECT_BIT);
|
||||
break;
|
||||
case ETHERNET_EVENT_DISCONNECTED:
|
||||
break;
|
||||
case ETHERNET_EVENT_START:
|
||||
xEventGroupSetBits(eth_event_group, ETH_START_BIT);
|
||||
break;
|
||||
case ETHERNET_EVENT_STOP:
|
||||
xEventGroupSetBits(eth_event_group, ETH_STOP_BIT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
esp_err_t eth_recv_cb(esp_eth_handle_t hdl, uint8_t *buffer, uint32_t length, void *priv)
|
||||
{
|
||||
emac_frame_t *pkt = (emac_frame_t *)buffer;
|
||||
recv_info_t *recv_info = (recv_info_t *)priv;
|
||||
|
||||
if (pkt->proto == 0x2222) {
|
||||
switch (pkt->data[0])
|
||||
{
|
||||
case POKE_RESP:
|
||||
xSemaphoreGive(recv_info->mutex);
|
||||
break;
|
||||
|
||||
case DUMMY_TRAFFIC:
|
||||
(recv_info->rx_pkt_cnt)++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buffer);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
recv_info_t recv_info;
|
||||
recv_info.mutex = xSemaphoreCreateBinary();
|
||||
TEST_ASSERT_NOT_NULL(recv_info.mutex);
|
||||
recv_info.rx_pkt_cnt = 0;
|
||||
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance
|
||||
TEST_ASSERT_NOT_NULL(mac);
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration
|
||||
#if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101)
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); // create PHY instance
|
||||
#elif defined(CONFIG_TARGET_ETH_PHY_DEVICE_LAN8720)
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
|
||||
#endif
|
||||
TEST_ASSERT_NOT_NULL(phy);
|
||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); // apply default driver configuration
|
||||
esp_eth_handle_t eth_handle = NULL; // after driver installed, we will get the handle of the driver
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_driver_install(&config, ð_handle)); // install driver
|
||||
TEST_ASSERT_NOT_NULL(eth_handle);
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, mac->get_addr(mac, local_mac_addr));
|
||||
// test app will parse the DUT MAC from this line of log output
|
||||
printf("DUT MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", local_mac_addr[0], local_mac_addr[1], local_mac_addr[2],
|
||||
local_mac_addr[3], local_mac_addr[4], local_mac_addr[5]);
|
||||
|
||||
TEST_ESP_OK(esp_eth_update_input_path(eth_handle, eth_recv_cb, &recv_info));
|
||||
|
||||
EventBits_t bits = 0;
|
||||
EventGroupHandle_t eth_event_group = xEventGroupCreate();
|
||||
TEST_ASSERT(eth_event_group != NULL);
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group));
|
||||
|
||||
// create a control frame to control test flow between the UT and the Python test script
|
||||
emac_frame_t *ctrl_pkt = calloc(1, 60);
|
||||
ctrl_pkt->proto = 0x2222;
|
||||
memset(ctrl_pkt->dest, 0xff, 6); // broadcast addr
|
||||
memcpy(ctrl_pkt->src, local_mac_addr, 6);
|
||||
|
||||
// create dummy data packet used for traffic generation
|
||||
emac_frame_t *pkt = calloc(1, 1500);
|
||||
pkt->proto = 0x2222;
|
||||
// we don't care about dest MAC address much, however it is better to not be broadcast or multifcast to not flood
|
||||
// other network nodes
|
||||
memset(pkt->dest, 0xBA, 6);
|
||||
memcpy(pkt->src, local_mac_addr, 6);
|
||||
|
||||
printf("EMAC start/stop stress test under heavy Tx traffic\n");
|
||||
for (int tx_i = 0; tx_i < 10; tx_i++) {
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_start(eth_handle)); // start Ethernet driver state machine
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_CONNECT_BIT, true, true, pdMS_TO_TICKS(3000));
|
||||
TEST_ASSERT((bits & ETH_CONNECT_BIT) == ETH_CONNECT_BIT);
|
||||
// even if PHY (IP101) indicates autonegotiation done and link up, it sometimes may miss few packets after atonego reset, hence wait a bit
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
|
||||
// at first, check that Tx/Rx path works as expected by poking the test script
|
||||
// this also serves as main PASS/FAIL criteria
|
||||
ctrl_pkt->data[0] = POKE_REQ;
|
||||
ctrl_pkt->data[1] = tx_i;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_transmit(eth_handle, ctrl_pkt, 60));
|
||||
TEST_ASSERT(xSemaphoreTake(recv_info.mutex, pdMS_TO_TICKS(3000)));
|
||||
printf("Tx Test iteration %d\n", tx_i);
|
||||
|
||||
// generate heavy Tx traffic
|
||||
printf("Note: transmit errors are expected...\n");
|
||||
for (int j = 0; j < 150; j++) {
|
||||
// return value is not checked on purpose since it is expected that it may fail time to time because
|
||||
// we may try to queue more packets than hardware is able to handle
|
||||
pkt->data[0] = j & 0xFF;
|
||||
esp_eth_transmit(eth_handle, pkt, 1500);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_stop(eth_handle));
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_STOP_BIT, true, true, pdMS_TO_TICKS(3000));
|
||||
TEST_ASSERT((bits & ETH_STOP_BIT) == ETH_STOP_BIT);
|
||||
printf("Ethernet stopped\n");
|
||||
}
|
||||
|
||||
printf("EMAC start/stop stress test under heavy Rx traffic\n");
|
||||
for (int rx_i = 0; rx_i < 10; rx_i++) {
|
||||
recv_info.rx_pkt_cnt = 0;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_start(eth_handle)); // start Ethernet driver state machine
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_CONNECT_BIT, true, true, pdMS_TO_TICKS(3000));
|
||||
TEST_ASSERT((bits & ETH_CONNECT_BIT) == ETH_CONNECT_BIT);
|
||||
// even if PHY (IP101) indicates autonegotiation done and link up, it sometimes may miss few packets after atonego reset, hence wait a bit
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
|
||||
ctrl_pkt->data[0] = POKE_REQ;
|
||||
ctrl_pkt->data[1] = rx_i;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_transmit(eth_handle, ctrl_pkt, 60));
|
||||
TEST_ASSERT(xSemaphoreTake(recv_info.mutex, pdMS_TO_TICKS(3000)));
|
||||
printf("Rx Test iteration %d\n", rx_i);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_stop(eth_handle));
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_STOP_BIT, true, true, pdMS_TO_TICKS(3000));
|
||||
TEST_ASSERT((bits & ETH_STOP_BIT) == ETH_STOP_BIT);
|
||||
printf("Recv packets: %d\n", recv_info.rx_pkt_cnt);
|
||||
TEST_ASSERT_GREATER_THAN_INT32(0, recv_info.rx_pkt_cnt);
|
||||
printf("Ethernet stopped\n");
|
||||
}
|
||||
|
||||
free(ctrl_pkt);
|
||||
free(pkt);
|
||||
|
||||
TEST_ESP_OK(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_delete_default());
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_eth_driver_uninstall(eth_handle));
|
||||
phy->del(phy);
|
||||
mac->del(mac);
|
||||
vEventGroupDelete(eth_event_group);
|
||||
vSemaphoreDelete(recv_info.mutex);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -337,17 +337,16 @@ void emac_hal_start(emac_hal_context_t *hal)
|
||||
|
||||
/* Flush Transmit FIFO */
|
||||
emac_ll_flush_trans_fifo_enable(hal->dma_regs, true);
|
||||
/* Flush Receive FIFO */
|
||||
emac_ll_flush_recv_frame_enable(hal->dma_regs, true);
|
||||
|
||||
/* Start DMA transmission */
|
||||
emac_ll_start_stop_dma_transmit(hal->dma_regs, true);
|
||||
/* Start DMA reception */
|
||||
emac_ll_start_stop_dma_receive(hal->dma_regs, true);
|
||||
|
||||
/* Enable transmit state machine of the MAC for transmission on the MII */
|
||||
emac_ll_transmit_enable(hal->mac_regs, true);
|
||||
/* Enable receive state machine of the MAC for reception from the MII */
|
||||
emac_ll_receive_enable(hal->mac_regs, true);
|
||||
/* Start DMA transmission */
|
||||
emac_ll_start_stop_dma_transmit(hal->dma_regs, true);
|
||||
/* Start DMA reception */
|
||||
emac_ll_start_stop_dma_receive(hal->dma_regs, true);
|
||||
|
||||
/* Clear all pending interrupts */
|
||||
emac_ll_clear_all_pending_intr(hal->dma_regs);
|
||||
@@ -357,18 +356,24 @@ esp_err_t emac_hal_stop(emac_hal_context_t *hal)
|
||||
{
|
||||
/* Stop DMA transmission */
|
||||
emac_ll_start_stop_dma_transmit(hal->dma_regs, false);
|
||||
/* Stop DMA reception */
|
||||
emac_ll_start_stop_dma_receive(hal->dma_regs, false);
|
||||
|
||||
if (emac_ll_transmit_frame_ctrl_status(hal->mac_regs) != 0x0) {
|
||||
/* Previous transmit in progress */
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
/* Disable receive state machine of the MAC for reception from the MII */
|
||||
emac_ll_transmit_enable(hal->mac_regs, false);
|
||||
/* Disable transmit state machine of the MAC for transmission on the MII */
|
||||
emac_ll_receive_enable(hal->mac_regs, false);
|
||||
/* Disable receive state machine of the MAC for reception from the MII */
|
||||
emac_ll_transmit_enable(hal->mac_regs, false);
|
||||
|
||||
if (emac_ll_receive_read_ctrl_state(hal->mac_regs) != 0x0) {
|
||||
/* Previous receive copy in progress */
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
/* Stop DMA reception */
|
||||
emac_ll_start_stop_dma_receive(hal->dma_regs, false);
|
||||
|
||||
/* Disable Ethernet MAC and DMA Interrupt */
|
||||
emac_ll_disable_all_intr(hal->dma_regs);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -342,6 +342,11 @@ static inline uint32_t emac_ll_transmit_frame_ctrl_status(emac_mac_dev_t *mac_re
|
||||
return mac_regs->emacdebug.mactfcs;
|
||||
}
|
||||
|
||||
static inline uint32_t emac_ll_receive_read_ctrl_state(emac_mac_dev_t *mac_regs)
|
||||
{
|
||||
return mac_regs->emacdebug.mtlrfrcs;
|
||||
}
|
||||
|
||||
/* emacmiidata */
|
||||
static inline void emac_ll_set_phy_data(emac_mac_dev_t *mac_regs, uint32_t data)
|
||||
{
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -225,7 +225,7 @@ void emac_hal_start(emac_hal_context_t *hal);
|
||||
* @param hal EMAC HAL context infostructure
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_INVALID_STATE: previous frame transmission is not completed. When this error occurs,
|
||||
* - ESP_ERR_INVALID_STATE: previous frame transmission/reception is not completed. When this error occurs,
|
||||
* wait and reapeat the EMAC stop again.
|
||||
*/
|
||||
esp_err_t emac_hal_stop(emac_hal_context_t *hal);
|
||||
|
Reference in New Issue
Block a user