esp_eth: added ioctl options to set Ethernet speed and duplex mode

esp_eth_ioctl third argument always acts as untyped pointer to memory now
This commit is contained in:
Ondrej Kosta
2021-11-04 09:10:19 +01:00
parent 4a011f3183
commit d1f2a3dfcc
19 changed files with 1284 additions and 414 deletions
+19 -13
View File
@@ -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-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_eth_com.h"
@@ -50,6 +42,12 @@ typedef struct {
*/
uint32_t check_link_period_ms;
/**
* @brief Configuration status of PHY autonegotiation feature
*
*/
bool auto_nego_en;
/**
* @brief Input frame buffer to user's stack
*
@@ -271,15 +269,23 @@ esp_err_t esp_eth_receive(esp_eth_handle_t hdl, uint8_t *buf, uint32_t *length)
* - ESP_OK: process io command successfully
* - ESP_ERR_INVALID_ARG: process io command failed because of some invalid argument
* - ESP_FAIL: process io command failed because some other error occurred
* - ESP_ERR_NOT_SUPPORTED: requested feature is not supported
*
* The following IO control commands are supported:
* @li @c ETH_CMD_S_MAC_ADDR sets Ethernet interface MAC address. @c data argument is pointer to MAC address buffer with expected size of 6 bytes.
* @li @c ETH_CMD_G_MAC_ADDR gets Ethernet interface MAC address. @c data argument is pointer to a buffer to which MAC address is to be copied. The buffer size must be at least 6 bytes.
* @li @c ETH_CMD_S_PHY_ADDR sets PHY address in range of <0-31>. @c data argument is pointer to memory of uint32_t datatype from where the configuration option is read.
* @li @c ETH_CMD_G_PHY_ADDR gets PHY address. @c data argument is pointer to memory of uint32_t datatype to which the PHY address is to be stored.
* @li @c ETH_CMD_S_AUTONEGO enables or disables Ethernet link speed and duplex mode autonegotiation. @c data argument is pointer to memory of bool datatype from which the configuration option is read.
* Preconditions: Ethernet driver needs to be stopped.
* @li @c ETH_CMD_G_AUTONEGO gets current configuration of the Ethernet link speed and duplex mode autonegotiation. @c data argument is pointer to memory of bool datatype to which the current configuration is to be stored.
* @li @c ETH_CMD_S_SPEED sets the Ethernet link speed. @c data argument is pointer to memory of eth_speed_t datatype from which the configuration option is read.
* Preconditions: Ethernet driver needs to be stopped and auto-negotiation disabled.
* @li @c ETH_CMD_G_SPEED gets current Ethernet link speed. @c data argument is pointer to memory of eth_speed_t datatype to which the speed is to be stored.
* @li @c ETH_CMD_S_PROMISCUOUS sets/resets Ethernet interface promiscuous mode. @c data argument is pointer to memory of bool datatype from which the configuration option is read.
* @li @c ETH_CMD_S_FLOW_CTRL sets/resets Ethernet interface flow control. @c data argument is pointer to memory of bool datatype from which the configuration option is read.
* @li @c ETH_CMD_S_DUPLEX_MODE sets the Ethernet duplex mode. @c data argument is pointer to memory of eth_duplex_t datatype from which the configuration option is read.
* Preconditions: Ethernet driver needs to be stopped and auto-negotiation disabled.
* @li @c ETH_CMD_G_DUPLEX_MODE gets current Ethernet link duplex mode. @c data argument is pointer to memory of eth_duplex_t datatype to which the duplex mode is to be stored.
* @li @c ETH_CMD_S_PHY_LOOPBACK sets/resets PHY to/from loopback mode. @c data argument is pointer to memory of bool datatype from which the configuration option is read.
*
+9 -13
View File
@@ -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-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
@@ -85,10 +77,14 @@ typedef enum {
ETH_CMD_S_MAC_ADDR, /*!< Set MAC address */
ETH_CMD_G_PHY_ADDR, /*!< Get PHY address */
ETH_CMD_S_PHY_ADDR, /*!< Set PHY address */
ETH_CMD_G_AUTONEGO, /*!< Get PHY Auto Negotiation */
ETH_CMD_S_AUTONEGO, /*!< Set PHY Auto Negotiation */
ETH_CMD_G_SPEED, /*!< Get Speed */
ETH_CMD_S_SPEED, /*!< Set Speed */
ETH_CMD_S_PROMISCUOUS, /*!< Set promiscuous mode */
ETH_CMD_S_FLOW_CTRL, /*!< Set flow control */
ETH_CMD_G_DUPLEX_MODE, /*!< Get Duplex mode */
ETH_CMD_S_DUPLEX_MODE, /*!< Set Duplex mode */
ETH_CMD_S_PHY_LOOPBACK,/*!< Set PHY loopback */
} esp_eth_io_cmd_t;
+52 -6
View File
@@ -3,7 +3,6 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdbool.h>
@@ -16,6 +15,17 @@ extern "C" {
#define ESP_ETH_PHY_ADDR_AUTO (-1)
/**
* @brief Auto-negotiation controll commands
*
*/
typedef enum {
ESP_ETH_PHY_AUTONEGO_RESTART,
ESP_ETH_PHY_AUTONEGO_EN,
ESP_ETH_PHY_AUTONEGO_DIS,
ESP_ETH_PHY_AUTONEGO_G_STAT,
} eth_phy_autoneg_cmd_t;
/**
* @brief Ethernet PHY
*
@@ -81,7 +91,7 @@ struct esp_eth_phy_s {
/**
* @brief Deinitialize Ethernet PHY
*
* @param[in] phyL Ethernet PHY instance
* @param[in] phy: Ethernet PHY instance
*
* @return
* - ESP_OK: deinitialize Ethernet PHY successfully
@@ -91,16 +101,20 @@ struct esp_eth_phy_s {
esp_err_t (*deinit)(esp_eth_phy_t *phy);
/**
* @brief Start auto negotiation
* @brief Configure auto negotiation
*
* @param[in] phy: Ethernet PHY instance
* @param[in] cmd: Configuration command, it is possible to Enable (restart), Disable or get current status
* of PHY auto negotiation
* @param[out] autonego_en_stat: Address where to store current status of auto negotiation configuration
*
* @return
* - ESP_OK: restart auto negotiation successfully
* - ESP_FAIL: restart auto negotiation failed because some error occurred
* - ESP_ERR_INVALID_ARG: invalid command
*
*/
esp_err_t (*negotiate)(esp_eth_phy_t *phy);
esp_err_t (*autonego_ctrl)(esp_eth_phy_t *phy, eth_phy_autoneg_cmd_t cmd, bool *autonego_en_stat);
/**
* @brief Get Ethernet PHY link status
@@ -167,18 +181,50 @@ struct esp_eth_phy_s {
esp_err_t (*advertise_pause_ability)(esp_eth_phy_t *phy, uint32_t ability);
/**
* @brief
* @brief Sets the PHY to loopback mode
*
* @param[in] phy: Ethernet PHY instance
* @param[in] enable: enables or disables PHY loopback
*
* @return
* - ESP_OK: configures PHY instance loopback function successfully
* - ESP_OK: PHY instance loopback mode has been configured successfully
* - ESP_FAIL: PHY instance loopback configuration failed because some error occurred
*
*/
esp_err_t (*loopback)(esp_eth_phy_t *phy, bool enable);
/**
* @brief Sets PHY speed mode
*
* @note Autonegotiation feature needs to be disabled prior to calling this function for the new
* setting to be applied
*
* @param[in] phy: Ethernet PHY instance
* @param[in] speed: Speed mode to be set
*
* @return
* - ESP_OK: PHY instance speed mode has been configured successfully
* - ESP_FAIL: PHY instance speed mode configuration failed because some error occurred
*
*/
esp_err_t (*set_speed)(esp_eth_phy_t *phy, eth_speed_t speed);
/**
* @brief Sets PHY duplex mode
*
* @note Autonegotiation feature needs to be disabled prior to calling this function for the new
* setting to be applied
*
* @param[in] phy: Ethernet PHY instance
* @param[in] duplex: Duplex mode to be set
*
* @return
* - ESP_OK: PHY instance duplex mode has been configured successfully
* - ESP_FAIL: PHY instance duplex mode configuration failed because some error occurred
*
*/
esp_err_t (*set_duplex)(esp_eth_phy_t *phy, eth_duplex_t duplex);
/**
* @brief Free memory of Ethernet PHY instance
*