mirror of
				https://github.com/0xFEEDC0DE64/arduino-esp32.git
				synced 2025-10-31 06:01:39 +01:00 
			
		
		
		
	Initial Commit
This commit is contained in:
		
							
								
								
									
										257
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										257
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,257 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include "esp_eth_com.h" | ||||
| #include "esp_eth_mac.h" | ||||
| #include "esp_eth_phy.h" | ||||
|  | ||||
| /** | ||||
| * @brief Handle of Ethernet driver | ||||
| * | ||||
| */ | ||||
| typedef void *esp_eth_handle_t; | ||||
|  | ||||
| /** | ||||
| * @brief Configuration of Ethernet driver | ||||
| * | ||||
| */ | ||||
| typedef struct { | ||||
|     /** | ||||
|     * @brief Ethernet MAC object | ||||
|     * | ||||
|     */ | ||||
|     esp_eth_mac_t *mac; | ||||
|  | ||||
|     /** | ||||
|     * @brief Ethernet PHY object | ||||
|     * | ||||
|     */ | ||||
|     esp_eth_phy_t *phy; | ||||
|  | ||||
|     /** | ||||
|     * @brief Period time of checking Ethernet link status | ||||
|     * | ||||
|     */ | ||||
|     uint32_t check_link_period_ms; | ||||
|  | ||||
|     /** | ||||
|     * @brief Input frame buffer to user's stack | ||||
|     * | ||||
|     * @param[in] eth_handle: handle of Ethernet driver | ||||
|     * @param[in] buffer: frame buffer that will get input to upper stack | ||||
|     * @param[in] length: length of the frame buffer | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: input frame buffer to upper stack successfully | ||||
|     *      - ESP_FAIL: error occurred when inputting buffer to upper stack | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*stack_input)(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t length, void *priv); | ||||
|  | ||||
|     /** | ||||
|     * @brief Callback function invoked when lowlevel initialization is finished | ||||
|     * | ||||
|     * @param[in] eth_handle: handle of Ethernet driver | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: process extra lowlevel initialization successfully | ||||
|     *       - ESP_FAIL: error occurred when processing extra lowlevel initialization | ||||
|     */ | ||||
|     esp_err_t (*on_lowlevel_init_done)(esp_eth_handle_t eth_handle); | ||||
|  | ||||
|     /** | ||||
|     * @brief Callback function invoked when lowlevel deinitialization is finished | ||||
|     * | ||||
|     * @param[in] eth_handle: handle of Ethernet driver | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: process extra lowlevel deinitialization successfully | ||||
|     *       - ESP_FAIL: error occurred when processing extra lowlevel deinitialization | ||||
|     */ | ||||
|     esp_err_t (*on_lowlevel_deinit_done)(esp_eth_handle_t eth_handle); | ||||
|  | ||||
| } esp_eth_config_t; | ||||
|  | ||||
| /** | ||||
|  * @brief Default configuration for Ethernet driver | ||||
|  * | ||||
|  */ | ||||
| #define ETH_DEFAULT_CONFIG(emac, ephy)   \ | ||||
|     {                                    \ | ||||
|         .mac = emac,                     \ | ||||
|         .phy = ephy,                     \ | ||||
|         .check_link_period_ms = 2000,    \ | ||||
|         .stack_input = NULL,             \ | ||||
|         .on_lowlevel_init_done = NULL,   \ | ||||
|         .on_lowlevel_deinit_done = NULL, \ | ||||
|     } | ||||
|  | ||||
| /** | ||||
| * @brief Install Ethernet driver | ||||
| * | ||||
| * @param[in]  config: configuration of the Ethernet driver | ||||
| * @param[out] out_hdl: handle of Ethernet driver | ||||
| * | ||||
| * @return | ||||
| *       - ESP_OK: install esp_eth driver successfully | ||||
| *       - ESP_ERR_INVALID_ARG: install esp_eth driver failed because of some invalid argument | ||||
| *       - ESP_ERR_NO_MEM: install esp_eth driver failed because there's no memory for driver | ||||
| *       - ESP_FAIL: install esp_eth driver failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_driver_install(const esp_eth_config_t *config, esp_eth_handle_t *out_hdl); | ||||
|  | ||||
| /** | ||||
| * @brief Uninstall Ethernet driver | ||||
| * @note It's not recommended to uninstall Ethernet driver unless it won't get used any more in application code. | ||||
| *       To uninstall Ethernet driver, you have to make sure, all references to the driver are released. | ||||
| *       Ethernet driver can only be uninstalled successfully when reference counter equals to one. | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * | ||||
| * @return | ||||
| *       - ESP_OK: uninstall esp_eth driver successfully | ||||
| *       - ESP_ERR_INVALID_ARG: uninstall esp_eth driver failed because of some invalid argument | ||||
| *       - ESP_ERR_INVALID_STATE: uninstall esp_eth driver failed because it has more than one reference | ||||
| *       - ESP_FAIL: uninstall esp_eth driver failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_driver_uninstall(esp_eth_handle_t hdl); | ||||
|  | ||||
| /** | ||||
| * @brief Start Ethernet driver **ONLY** in standalone mode (i.e. without TCP/IP stack) | ||||
| * | ||||
| * @note This API will start driver state machine and internal software timer (for checking link status). | ||||
| * | ||||
| * @param[in] hdl handle of Ethernet driver | ||||
| * | ||||
| * @return | ||||
| *       - ESP_OK: start esp_eth driver successfully | ||||
| *       - ESP_ERR_INVALID_ARG: start esp_eth driver failed because of some invalid argument | ||||
| *       - ESP_ERR_INVALID_STATE: start esp_eth driver failed because driver has started already | ||||
| *       - ESP_FAIL: start esp_eth driver failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_start(esp_eth_handle_t hdl); | ||||
|  | ||||
| /** | ||||
| * @brief Stop Ethernet driver | ||||
| * | ||||
| * @note This function does the oppsite operation of `esp_eth_start`. | ||||
| * | ||||
| * @param[in] hdl handle of Ethernet driver | ||||
| * @return | ||||
| *       - ESP_OK: stop esp_eth driver successfully | ||||
| *       - ESP_ERR_INVALID_ARG: stop esp_eth driver failed because of some invalid argument | ||||
| *       - ESP_ERR_INVALID_STATE: stop esp_eth driver failed because driver has not started yet | ||||
| *       - ESP_FAIL: stop esp_eth driver failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_stop(esp_eth_handle_t hdl); | ||||
|  | ||||
| /** | ||||
| * @brief Update Ethernet data input path (i.e. specify where to pass the input buffer) | ||||
| * | ||||
| * @note After install driver, Ethernet still don't know where to deliver the input buffer. | ||||
| *       In fact, this API registers a callback function which get invoked when Ethernet received new packets. | ||||
| * | ||||
| * @param[in] hdl handle of Ethernet driver | ||||
| * @param[in] stack_input function pointer, which does the actual process on incoming packets | ||||
| * @param[in] priv private resource, which gets passed to `stack_input` callback without any modification | ||||
| * @return | ||||
| *       - ESP_OK: update input path successfully | ||||
| *       - ESP_ERR_INVALID_ARG: update input path failed because of some invalid argument | ||||
| *       - ESP_FAIL: update input path failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_update_input_path( | ||||
|     esp_eth_handle_t hdl, | ||||
|     esp_err_t (*stack_input)(esp_eth_handle_t hdl, uint8_t *buffer, uint32_t length, void *priv), | ||||
|     void *priv); | ||||
|  | ||||
| /** | ||||
| * @brief General Transmit | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * @param[in] buf: buffer of the packet to transfer | ||||
| * @param[in] length: length of the buffer to transfer | ||||
| * | ||||
| * @return | ||||
| *       - ESP_OK: transmit frame buffer successfully | ||||
| *       - ESP_ERR_INVALID_ARG: transmit frame buffer failed because of some invalid argument | ||||
| *       - ESP_FAIL: transmit frame buffer failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_transmit(esp_eth_handle_t hdl, void *buf, uint32_t length); | ||||
|  | ||||
| /** | ||||
| * @brief General Receive | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * @param[out] buf: buffer to preserve the received packet | ||||
| * @param[out] length: length of the received packet | ||||
| * | ||||
| * @note Before this function got invoked, the value of "length" should set by user, equals the size of buffer. | ||||
| *       After the function returned, the value of "length" means the real length of received data. | ||||
| * | ||||
| * @return | ||||
| *       - ESP_OK: receive frame buffer successfully | ||||
| *       - ESP_ERR_INVALID_ARG: receive frame buffer failed because of some invalid argument | ||||
| *       - ESP_ERR_INVALID_SIZE: input buffer size is not enough to hold the incoming data. | ||||
| *                               in this case, value of returned "length" indicates the real size of incoming data. | ||||
| *       - ESP_FAIL: receive frame buffer failed because some other error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_receive(esp_eth_handle_t hdl, uint8_t *buf, uint32_t *length); | ||||
|  | ||||
| /** | ||||
| * @brief Misc IO function of Etherent driver | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * @param[in] cmd: IO control command | ||||
| * @param[in] data: specificed data for command | ||||
| * | ||||
| * @return | ||||
| *       - 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_t esp_eth_ioctl(esp_eth_handle_t hdl, esp_eth_io_cmd_t cmd, void *data); | ||||
|  | ||||
| /** | ||||
| * @brief Increase Ethernet driver reference | ||||
| * @note Ethernet driver handle can be obtained by os timer, netif, etc. | ||||
| *       It's dangerous when thread A is using Ethernet but thread B uninstall the driver. | ||||
| *       Using reference counter can prevent such risk, but care should be taken, when you obtain Ethernet driver, | ||||
| *       this API must be invoked so that the driver won't be uninstalled during your using time. | ||||
| * | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * @return | ||||
| *       - ESP_OK: increase reference successfully | ||||
| *       - ESP_ERR_INVALID_ARG: increase reference failed because of some invalid argument | ||||
| */ | ||||
| esp_err_t esp_eth_increase_reference(esp_eth_handle_t hdl); | ||||
|  | ||||
| /** | ||||
| * @brief Decrease Ethernet driver reference | ||||
| * | ||||
| * @param[in] hdl: handle of Ethernet driver | ||||
| * @return | ||||
| *       - ESP_OK: increase reference successfully | ||||
| *       - ESP_ERR_INVALID_ARG: increase reference failed because of some invalid argument | ||||
| */ | ||||
| esp_err_t esp_eth_decrease_reference(esp_eth_handle_t hdl); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										224
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_com.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_com.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,224 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include "esp_err.h" | ||||
| #include "esp_event_base.h" | ||||
|  | ||||
| /** | ||||
|  * @brief Maximum Ethernet payload size | ||||
|  * | ||||
|  */ | ||||
| #define ETH_MAX_PAYLOAD_LEN (1500) | ||||
|  | ||||
| /** | ||||
|  * @brief Minimum Ethernet payload size | ||||
|  * | ||||
|  */ | ||||
| #define ETH_MIN_PAYLOAD_LEN (46) | ||||
|  | ||||
| /** | ||||
|  * @brief Ethernet frame header size: Dest addr(6 Bytes) + Src addr(6 Bytes) + length/type(2 Bytes) | ||||
|  * | ||||
|  */ | ||||
| #define ETH_HEADER_LEN (14) | ||||
|  | ||||
| /** | ||||
|  * @brief Ethernet frame CRC length | ||||
|  * | ||||
|  */ | ||||
| #define ETH_CRC_LEN (4) | ||||
|  | ||||
| /** | ||||
|  * @brief Optional 802.1q VLAN Tag length | ||||
|  * | ||||
|  */ | ||||
| #define ETH_VLAN_TAG_LEN (4) | ||||
|  | ||||
| /** | ||||
|  * @brief Jumbo frame payload size | ||||
|  * | ||||
|  */ | ||||
| #define ETH_JUMBO_FRAME_PAYLOAD_LEN (9000) | ||||
|  | ||||
| /** | ||||
|  * @brief Maximum frame size (1522 Bytes) | ||||
|  * | ||||
|  */ | ||||
| #define ETH_MAX_PACKET_SIZE (ETH_HEADER_LEN + ETH_VLAN_TAG_LEN + ETH_MAX_PAYLOAD_LEN + ETH_CRC_LEN) | ||||
|  | ||||
| /** | ||||
|  * @brief Minimum frame size (64 Bytes) | ||||
|  * | ||||
|  */ | ||||
| #define ETH_MIN_PACKET_SIZE (ETH_HEADER_LEN + ETH_MIN_PAYLOAD_LEN + ETH_CRC_LEN) | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet driver state | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETH_STATE_LLINIT, /*!< Lowlevel init done */ | ||||
|     ETH_STATE_DEINIT, /*!< Deinit done */ | ||||
|     ETH_STATE_LINK,   /*!< Link status changed */ | ||||
|     ETH_STATE_SPEED,  /*!< Speed updated */ | ||||
|     ETH_STATE_DUPLEX, /*!< Duplex updated */ | ||||
| } esp_eth_state_t; | ||||
|  | ||||
| /** | ||||
| * @brief Command list for ioctl API | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETH_CMD_G_MAC_ADDR,    /*!< Get MAC address */ | ||||
|     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_SPEED,       /*!< Get Speed */ | ||||
|     ETH_CMD_S_PROMISCUOUS, /*!< Set promiscuous mode */ | ||||
| } esp_eth_io_cmd_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet link status | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETH_LINK_UP,  /*!< Ethernet link is up */ | ||||
|     ETH_LINK_DOWN /*!< Ethernet link is down */ | ||||
| } eth_link_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet speed | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETH_SPEED_10M, /*!< Ethernet speed is 10Mbps */ | ||||
|     ETH_SPEED_100M /*!< Ethernet speed is 100Mbps */ | ||||
| } eth_speed_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet duplex mode | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETH_DUPLEX_HALF, /*!< Ethernet is in half duplex */ | ||||
|     ETH_DUPLEX_FULL  /*!< Ethernet is in full duplex */ | ||||
| } eth_duplex_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet mediator | ||||
| * | ||||
| */ | ||||
| typedef struct esp_eth_mediator_s esp_eth_mediator_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet mediator | ||||
| * | ||||
| */ | ||||
| struct esp_eth_mediator_s { | ||||
|     /** | ||||
|     * @brief Read PHY register | ||||
|     * | ||||
|     * @param[in] eth: mediator of Ethernet driver | ||||
|     * @param[in] phy_addr: PHY Chip address (0~31) | ||||
|     * @param[in] phy_reg: PHY register index code | ||||
|     * @param[out] reg_value: PHY register value | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: read PHY register successfully | ||||
|     *       - ESP_FAIL: read PHY register failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*phy_reg_read)(esp_eth_mediator_t *eth, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value); | ||||
|  | ||||
|     /** | ||||
|     * @brief Write PHY register | ||||
|     * | ||||
|     * @param[in] eth: mediator of Ethernet driver | ||||
|     * @param[in] phy_addr: PHY Chip address (0~31) | ||||
|     * @param[in] phy_reg: PHY register index code | ||||
|     * @param[in] reg_value: PHY register value | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: write PHY register successfully | ||||
|     *       - ESP_FAIL: write PHY register failed because some error occurred | ||||
|     */ | ||||
|     esp_err_t (*phy_reg_write)(esp_eth_mediator_t *eth, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value); | ||||
|  | ||||
|     /** | ||||
|     * @brief Deliver packet to upper stack | ||||
|     * | ||||
|     * @param[in] eth: mediator of Ethernet driver | ||||
|     * @param[in] buffer: packet buffer | ||||
|     * @param[in] length: length of the packet | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: deliver packet to upper stack successfully | ||||
|     *       - ESP_FAIL: deliver packet failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*stack_input)(esp_eth_mediator_t *eth, uint8_t *buffer, uint32_t length); | ||||
|  | ||||
|     /** | ||||
|     * @brief Callback on Ethernet state changed | ||||
|     * | ||||
|     * @param[in] eth: mediator of Ethernet driver | ||||
|     * @param[in] state: new state | ||||
|     * @param[in] args: optional argument for the new state | ||||
|     * | ||||
|     * @return | ||||
|     *       - ESP_OK: process the new state successfully | ||||
|     *       - ESP_FAIL: process the new state failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*on_state_changed)(esp_eth_mediator_t *eth, esp_eth_state_t state, void *args); | ||||
| }; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet event declarations | ||||
| * | ||||
| */ | ||||
| typedef enum { | ||||
|     ETHERNET_EVENT_START,        /*!< Ethernet driver start */ | ||||
|     ETHERNET_EVENT_STOP,         /*!< Ethernet driver stop */ | ||||
|     ETHERNET_EVENT_CONNECTED,    /*!< Ethernet got a valid link */ | ||||
|     ETHERNET_EVENT_DISCONNECTED, /*!< Ethernet lost a valid link */ | ||||
| } eth_event_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet event base declaration | ||||
| * | ||||
| */ | ||||
| ESP_EVENT_DECLARE_BASE(ETH_EVENT); | ||||
|  | ||||
| /** | ||||
| * @brief Detect PHY address | ||||
| * | ||||
| * @param[in] eth: mediator of Ethernet driver | ||||
| * @param[out] detected_addr: a valid address after detection | ||||
| * @return | ||||
| *       - ESP_OK: detect phy address successfully | ||||
| *       - ESP_ERR_INVALID_ARG: invalid parameter | ||||
| *       - ESP_ERR_NOT_FOUND: can't detect any PHY device | ||||
| *       - ESP_FAIL: detect phy address failed because some error occurred | ||||
| */ | ||||
| esp_err_t esp_eth_detect_phy_addr(esp_eth_mediator_t *eth, uint32_t *detected_addr); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										334
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_mac.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										334
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_mac.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,334 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <stdbool.h> | ||||
| #include "esp_eth_com.h" | ||||
| #include "sdkconfig.h" | ||||
| #if CONFIG_ETH_USE_SPI_ETHERNET | ||||
| #include "driver/spi_master.h" | ||||
| #endif | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet MAC | ||||
| * | ||||
| */ | ||||
| typedef struct esp_eth_mac_s esp_eth_mac_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet MAC | ||||
| * | ||||
| */ | ||||
| struct esp_eth_mac_s { | ||||
|     /** | ||||
|     * @brief Set mediator for Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] eth: Ethernet mediator | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set mediator for Ethernet MAC successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set mediator for Ethernet MAC failed because of invalid argument | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_mediator)(esp_eth_mac_t *mac, esp_eth_mediator_t *eth); | ||||
|  | ||||
|     /** | ||||
|     * @brief Initialize Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: initialize Ethernet MAC successfully | ||||
|     *      - ESP_ERR_TIMEOUT: initialize Ethernet MAC failed because of timeout | ||||
|     *      - ESP_FAIL: initialize Ethernet MAC failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*init)(esp_eth_mac_t *mac); | ||||
|  | ||||
|     /** | ||||
|     * @brief Deinitialize Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: deinitialize Ethernet MAC successfully | ||||
|     *      - ESP_FAIL: deinitialize Ethernet MAC failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*deinit)(esp_eth_mac_t *mac); | ||||
|  | ||||
|     /** | ||||
|     * @brief Transmit packet from Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] buf: packet buffer to transmit | ||||
|     * @param[in] length: length of packet | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: transmit packet successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: transmit packet failed because of invalid argument | ||||
|     *      - ESP_ERR_INVALID_STATE: transmit packet failed because of wrong state of MAC | ||||
|     *      - ESP_FAIL: transmit packet failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*transmit)(esp_eth_mac_t *mac, uint8_t *buf, uint32_t length); | ||||
|  | ||||
|     /** | ||||
|     * @brief Receive packet from Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[out] buf: packet buffer which will preserve the received frame | ||||
|     * @param[out] length: length of the received packet | ||||
|     * | ||||
|     * @note Memory of buf is allocated in the Layer2, make sure it get free after process. | ||||
|     * @note Before this function got invoked, the value of "length" should set by user, equals the size of buffer. | ||||
|     *       After the function returned, the value of "length" means the real length of received data. | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: receive packet successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: receive packet failed because of invalid argument | ||||
|     *      - ESP_ERR_INVALID_SIZE: input buffer size is not enough to hold the incoming data. | ||||
|     *                              in this case, value of returned "length" indicates the real size of incoming data. | ||||
|     *      - ESP_FAIL: receive packet failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*receive)(esp_eth_mac_t *mac, uint8_t *buf, uint32_t *length); | ||||
|  | ||||
|     /** | ||||
|     * @brief Read PHY register | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] phy_addr: PHY chip address (0~31) | ||||
|     * @param[in] phy_reg: PHY register index code | ||||
|     * @param[out] reg_value: PHY register value | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: read PHY register successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: read PHY register failed because of invalid argument | ||||
|     *      - ESP_ERR_INVALID_STATE: read PHY register failed because of wrong state of MAC | ||||
|     *      - ESP_ERR_TIMEOUT: read PHY register failed because of timeout | ||||
|     *      - ESP_FAIL: read PHY register failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*read_phy_reg)(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value); | ||||
|  | ||||
|     /** | ||||
|     * @brief Write PHY register | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] phy_addr: PHY chip address (0~31) | ||||
|     * @param[in] phy_reg: PHY register index code | ||||
|     * @param[in] reg_value: PHY register value | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: write PHY register successfully | ||||
|     *      - ESP_ERR_INVALID_STATE: write PHY register failed because of wrong state of MAC | ||||
|     *      - ESP_ERR_TIMEOUT: write PHY register failed because of timeout | ||||
|     *      - ESP_FAIL: write PHY register failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*write_phy_reg)(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set MAC address | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] addr: MAC address | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set MAC address successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set MAC address failed because of invalid argument | ||||
|     *      - ESP_FAIL: set MAC address failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_addr)(esp_eth_mac_t *mac, uint8_t *addr); | ||||
|  | ||||
|     /** | ||||
|     * @brief Get MAC address | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[out] addr: MAC address | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: get MAC address successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: get MAC address failed because of invalid argument | ||||
|     *      - ESP_FAIL: get MAC address failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*get_addr)(esp_eth_mac_t *mac, uint8_t *addr); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set speed of MAC | ||||
|     * | ||||
|     * @param[in] ma:c Ethernet MAC instance | ||||
|     * @param[in] speed: MAC speed | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set MAC speed successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set MAC speed failed because of invalid argument | ||||
|     *      - ESP_FAIL: set MAC speed failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_speed)(esp_eth_mac_t *mac, eth_speed_t speed); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set duplex mode of MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] duplex: MAC duplex | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set MAC duplex mode successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set MAC duplex failed because of invalid argument | ||||
|     *      - ESP_FAIL: set MAC duplex failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_duplex)(esp_eth_mac_t *mac, eth_duplex_t duplex); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set link status of MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] link: Link status | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set link status successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set link status failed because of invalid argument | ||||
|     *      - ESP_FAIL: set link status failed because some other error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_link)(esp_eth_mac_t *mac, eth_link_t link); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set promiscuous of MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * @param[in] enable: set true to enable promiscuous mode; set false to disable promiscuous mode | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set promiscuous mode successfully | ||||
|     *      - ESP_FAIL: set promiscuous mode failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_promiscuous)(esp_eth_mac_t *mac, bool enable); | ||||
|  | ||||
|     /** | ||||
|     * @brief Free memory of Ethernet MAC | ||||
|     * | ||||
|     * @param[in] mac: Ethernet MAC instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: free Ethernet MAC instance successfully | ||||
|     *      - ESP_FAIL: free Ethernet MAC instance failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*del)(esp_eth_mac_t *mac); | ||||
| }; | ||||
|  | ||||
| /** | ||||
| * @brief Configuration of Ethernet MAC object | ||||
| * | ||||
| */ | ||||
| typedef struct { | ||||
|     uint32_t sw_reset_timeout_ms; /*!< Software reset timeout value (Unit: ms) */ | ||||
|     uint32_t rx_task_stack_size;  /*!< Stack size of the receive task */ | ||||
|     uint32_t rx_task_prio;        /*!< Priority of the receive task */ | ||||
|     int smi_mdc_gpio_num;         /*!< SMI MDC GPIO number */ | ||||
|     int smi_mdio_gpio_num;        /*!< SMI MDIO GPIO number */ | ||||
|     uint32_t flags;               /*!< Flags that specify extra capability for mac driver */ | ||||
| } eth_mac_config_t; | ||||
|  | ||||
| #define ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE (1 << 0) /*!< MAC driver can work when cache is disabled */ | ||||
|  | ||||
| /** | ||||
|  * @brief Default configuration for Ethernet MAC object | ||||
|  * | ||||
|  */ | ||||
| #define ETH_MAC_DEFAULT_CONFIG()    \ | ||||
|     {                               \ | ||||
|         .sw_reset_timeout_ms = 100, \ | ||||
|         .rx_task_stack_size = 4096, \ | ||||
|         .rx_task_prio = 15,         \ | ||||
|         .smi_mdc_gpio_num = 23,     \ | ||||
|         .smi_mdio_gpio_num = 18,    \ | ||||
|         .flags = 0,                 \ | ||||
|     } | ||||
|  | ||||
| #if CONFIG_ETH_USE_ESP32_EMAC | ||||
| /** | ||||
| * @brief Create ESP32 Ethernet MAC instance | ||||
| * | ||||
| * @param config: Ethernet MAC configuration | ||||
| * | ||||
| * @return | ||||
| *      - instance: create MAC instance successfully | ||||
| *      - NULL: create MAC instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config); | ||||
| #endif // CONFIG_ETH_USE_ESP32_EMAC | ||||
|  | ||||
| #if CONFIG_ETH_SPI_ETHERNET_DM9051 | ||||
| /** | ||||
|  * @brief DM9051 specific configuration | ||||
|  * | ||||
|  */ | ||||
| typedef struct { | ||||
|     spi_device_handle_t spi_hdl; /*!< Handle of SPI device driver */ | ||||
|     int int_gpio_num;            /*!< Interrupt GPIO number */ | ||||
| } eth_dm9051_config_t; | ||||
|  | ||||
| /** | ||||
|  * @brief Default DM9051 specific configuration | ||||
|  * | ||||
|  */ | ||||
| #define ETH_DM9051_DEFAULT_CONFIG(spi_device) \ | ||||
|     {                                         \ | ||||
|         .spi_hdl = spi_device,                \ | ||||
|         .int_gpio_num = 4,                    \ | ||||
|     } | ||||
|  | ||||
| /** | ||||
| * @brief Create DM9051 Ethernet MAC instance | ||||
| * | ||||
| * @param dm9051_config: DM9051 specific configuration | ||||
| * @param mac_config: Ethernet MAC configuration | ||||
| * | ||||
| * @return | ||||
| *      - instance: create MAC instance successfully | ||||
| *      - NULL: create MAC instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_dm9051_config_t *dm9051_config, const eth_mac_config_t *mac_config); | ||||
| #endif // CONFIG_ETH_SPI_ETHERNET_DM9051 | ||||
|  | ||||
| #if CONFIG_ETH_USE_OPENETH | ||||
| /** | ||||
| * @brief Create OpenCores Ethernet MAC instance | ||||
| * | ||||
| * @param config: Ethernet MAC configuration | ||||
| * | ||||
| * @return | ||||
| *      - instance: create MAC instance successfully | ||||
| *      - NULL: create MAC instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_mac_t *esp_eth_mac_new_openeth(const eth_mac_config_t *config); | ||||
| #endif // CONFIG_ETH_USE_OPENETH | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										66
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_netif_glue.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_netif_glue.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include "esp_eth.h" | ||||
|  | ||||
| /** | ||||
|  * @brief Create a netif glue for Ethernet driver | ||||
|  * @note netif glue is used to attach io driver to TCP/IP netif | ||||
|  * | ||||
|  * @param eth_hdl Ethernet driver handle | ||||
|  * @return glue object, which inherits esp_netif_driver_base_t | ||||
|  */ | ||||
| void *esp_eth_new_netif_glue(esp_eth_handle_t eth_hdl); | ||||
|  | ||||
| /** | ||||
|  * @brief Delete netif glue of Ethernet driver | ||||
|  * | ||||
|  * @param glue netif glue | ||||
|  * @return -ESP_OK: delete netif glue successfully | ||||
|  */ | ||||
| esp_err_t esp_eth_del_netif_glue(void *glue); | ||||
|  | ||||
| /** | ||||
|  * @brief Register default IP layer handlers for Ethernet | ||||
|  * | ||||
|  * @note: Ethernet handle might not yet properly initialized when setting up these default handlers | ||||
|  * | ||||
|  * @param[in] esp_netif esp network interface handle created for Ethernet driver | ||||
|  * @return | ||||
|  *      - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) | ||||
|  *      - ESP_OK: set default IP layer handlers successfully | ||||
|  *      - others: other failure occurred during register esp_event handler | ||||
|  */ | ||||
|  | ||||
| esp_err_t esp_eth_set_default_handlers(void *esp_netif); | ||||
|  | ||||
| /** | ||||
|  * @brief Unregister default IP layer handlers for Ethernet | ||||
|  * | ||||
|  * @param[in] esp_netif esp network interface handle created for Ethernet driver | ||||
|  * @return | ||||
|  *      - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) | ||||
|  *      - ESP_OK: clear default IP layer handlers successfully | ||||
|  *      - others: other failure occurred during unregister esp_event handler | ||||
|  */ | ||||
| esp_err_t esp_eth_clear_default_handlers(void *esp_netif); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										257
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_phy.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										257
									
								
								tools/sdk/esp32/include/esp_eth/include/esp_eth_phy.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,257 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <stdbool.h> | ||||
| #include "esp_eth_com.h" | ||||
| #include "sdkconfig.h" | ||||
|  | ||||
| #define ESP_ETH_PHY_ADDR_AUTO (-1) | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet PHY | ||||
| * | ||||
| */ | ||||
| typedef struct esp_eth_phy_s esp_eth_phy_t; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet PHY | ||||
| * | ||||
| */ | ||||
| struct esp_eth_phy_s { | ||||
|     /** | ||||
|     * @brief Set mediator for PHY | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * @param[in] mediator: mediator of Ethernet driver | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set mediator for Ethernet PHY instance successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: set mediator for Ethernet PHY instance failed because of some invalid arguments | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_mediator)(esp_eth_phy_t *phy, esp_eth_mediator_t *mediator); | ||||
|  | ||||
|     /** | ||||
|     * @brief Software Reset Ethernet PHY | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: reset Ethernet PHY successfully | ||||
|     *      - ESP_FAIL: reset Ethernet PHY failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*reset)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Hardware Reset Ethernet PHY | ||||
|     * | ||||
|     * @note Hardware reset is mostly done by pull down and up PHY's nRST pin | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: reset Ethernet PHY successfully | ||||
|     *      - ESP_FAIL: reset Ethernet PHY failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*reset_hw)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Initialize Ethernet PHY | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: initialize Ethernet PHY successfully | ||||
|     *      - ESP_FAIL: initialize Ethernet PHY failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*init)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Deinitialize Ethernet PHY | ||||
|     * | ||||
|     * @param[in] phyL Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: deinitialize Ethernet PHY successfully | ||||
|     *      - ESP_FAIL: deinitialize Ethernet PHY failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*deinit)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Start auto negotiation | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: restart auto negotiation successfully | ||||
|     *      - ESP_FAIL: restart auto negotiation failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*negotiate)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Get Ethernet PHY link status | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: get Ethernet PHY link status successfully | ||||
|     *      - ESP_FAIL: get Ethernet PHY link status failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*get_link)(esp_eth_phy_t *phy); | ||||
|  | ||||
|     /** | ||||
|     * @brief Power control of Ethernet PHY | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * @param[in] enable: set true to power on Ethernet PHY; ser false to power off Ethernet PHY | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: control Ethernet PHY power successfully | ||||
|     *      - ESP_FAIL: control Ethernet PHY power failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*pwrctl)(esp_eth_phy_t *phy, bool enable); | ||||
|  | ||||
|     /** | ||||
|     * @brief Set PHY chip address | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * @param[in] addr: PHY chip address | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: set Ethernet PHY address successfully | ||||
|     *      - ESP_FAIL: set Ethernet PHY address failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*set_addr)(esp_eth_phy_t *phy, uint32_t addr); | ||||
|  | ||||
|     /** | ||||
|     * @brief Get PHY chip address | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * @param[out] addr: PHY chip address | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: get Ethernet PHY address successfully | ||||
|     *      - ESP_ERR_INVALID_ARG: get Ethernet PHY address failed because of invalid argument | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*get_addr)(esp_eth_phy_t *phy, uint32_t *addr); | ||||
|  | ||||
|     /** | ||||
|     * @brief Free memory of Ethernet PHY instance | ||||
|     * | ||||
|     * @param[in] phy: Ethernet PHY instance | ||||
|     * | ||||
|     * @return | ||||
|     *      - ESP_OK: free PHY instance successfully | ||||
|     *      - ESP_FAIL: free PHY instance failed because some error occurred | ||||
|     * | ||||
|     */ | ||||
|     esp_err_t (*del)(esp_eth_phy_t *phy); | ||||
| }; | ||||
|  | ||||
| /** | ||||
| * @brief Ethernet PHY configuration | ||||
| * | ||||
| */ | ||||
| typedef struct { | ||||
|     int32_t phy_addr;             /*!< PHY address, set -1 to enable PHY address detection at initialization stage */ | ||||
|     uint32_t reset_timeout_ms;    /*!< Reset timeout value (Unit: ms) */ | ||||
|     uint32_t autonego_timeout_ms; /*!< Auto-negotiation timeout value (Unit: ms) */ | ||||
|     int reset_gpio_num;           /*!< Reset GPIO number, -1 means no hardware reset */ | ||||
| } eth_phy_config_t; | ||||
|  | ||||
| /** | ||||
|  * @brief Default configuration for Ethernet PHY object | ||||
|  * | ||||
|  */ | ||||
| #define ETH_PHY_DEFAULT_CONFIG()           \ | ||||
|     {                                      \ | ||||
|         .phy_addr = ESP_ETH_PHY_ADDR_AUTO, \ | ||||
|         .reset_timeout_ms = 100,           \ | ||||
|         .autonego_timeout_ms = 4000,       \ | ||||
|         .reset_gpio_num = 5,               \ | ||||
|     } | ||||
|  | ||||
| /** | ||||
| * @brief Create a PHY instance of IP101 | ||||
| * | ||||
| * @param[in] config: configuration of PHY | ||||
| * | ||||
| * @return | ||||
| *      - instance: create PHY instance successfully | ||||
| *      - NULL: create PHY instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_phy_t *esp_eth_phy_new_ip101(const eth_phy_config_t *config); | ||||
|  | ||||
| /** | ||||
| * @brief Create a PHY instance of RTL8201 | ||||
| * | ||||
| * @param[in] config: configuration of PHY | ||||
| * | ||||
| * @return | ||||
| *      - instance: create PHY instance successfully | ||||
| *      - NULL: create PHY instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_phy_t *esp_eth_phy_new_rtl8201(const eth_phy_config_t *config); | ||||
|  | ||||
| /** | ||||
| * @brief Create a PHY instance of LAN8720 | ||||
| * | ||||
| * @param[in] config: configuration of PHY | ||||
| * | ||||
| * @return | ||||
| *      - instance: create PHY instance successfully | ||||
| *      - NULL: create PHY instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_phy_t *esp_eth_phy_new_lan8720(const eth_phy_config_t *config); | ||||
|  | ||||
| /** | ||||
| * @brief Create a PHY instance of DP83848 | ||||
| * | ||||
| * @param[in] config: configuration of PHY | ||||
| * | ||||
| * @return | ||||
| *      - instance: create PHY instance successfully | ||||
| *      - NULL: create PHY instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config); | ||||
|  | ||||
| #if CONFIG_ETH_SPI_ETHERNET_DM9051 | ||||
| /** | ||||
| * @brief Create a PHY instance of DM9051 | ||||
| * | ||||
| * @param[in] config: configuration of PHY | ||||
| * | ||||
| * @return | ||||
| *      - instance: create PHY instance successfully | ||||
| *      - NULL: create PHY instance failed because some error occurred | ||||
| */ | ||||
| esp_eth_phy_t *esp_eth_phy_new_dm9051(const eth_phy_config_t *config); | ||||
| #endif | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
							
								
								
									
										163
									
								
								tools/sdk/esp32/include/esp_eth/include/eth_phy_regs_struct.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								tools/sdk/esp32/include/esp_eth/include/eth_phy_regs_struct.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,163 @@ | ||||
| // 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. | ||||
| #pragma once | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| #include <stdint.h> | ||||
|  | ||||
| /******************Basic PHY Registers*******************/ | ||||
|  | ||||
| /** | ||||
|  * @brief BMCR(Basic Mode Control Register) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t reserved : 7;          /*!< Reserved */ | ||||
|         uint32_t collision_test : 1;    /*!< Collision test */ | ||||
|         uint32_t duplex_mode : 1;       /*!< Duplex mode:Full Duplex(1) and Half Duplex(0) */ | ||||
|         uint32_t restart_auto_nego : 1; /*!< Restart auto-negotiation */ | ||||
|         uint32_t isolate : 1;           /*!< Isolate the PHY from MII except the SMI interface */ | ||||
|         uint32_t power_down : 1;        /*!< Power off PHY except SMI interface */ | ||||
|         uint32_t en_auto_nego : 1;      /*!< Enable auto negotiation */ | ||||
|         uint32_t speed_select : 1;      /*!< Select speed: 100Mbps(1) and 10Mbps(0) */ | ||||
|         uint32_t en_loopback : 1;       /*!< Enables transmit data to be routed to the receive path */ | ||||
|         uint32_t reset : 1;             /*!< Reset PHY registers. This bit is self-clearing. */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } bmcr_reg_t; | ||||
| #define ETH_PHY_BMCR_REG_ADDR (0x00) | ||||
|  | ||||
| /** | ||||
|  * @brief BMSR(Basic Mode Status Register) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t ext_capability : 1;       /*!< Extended register capability */ | ||||
|         uint32_t jabber_detect : 1;        /*!< Jabber condition detected */ | ||||
|         uint32_t link_status : 1;          /*!< Link status */ | ||||
|         uint32_t auto_nego_ability : 1;    /*!< Auto negotiation ability */ | ||||
|         uint32_t remote_fault : 1;         /*!< Remote fault detected */ | ||||
|         uint32_t auto_nego_complete : 1;   /*!< Auto negotiation completed */ | ||||
|         uint32_t mf_preamble_suppress : 1; /*!< Preamble suppression capability for management frame */ | ||||
|         uint32_t reserved : 1;             /*!< Reserved */ | ||||
|         uint32_t ext_status : 1;           /*!< Extended Status */ | ||||
|         uint32_t base100_t2_hdx : 1;       /*!< 100Base-T2 Half Duplex capability */ | ||||
|         uint32_t base100_t2_fdx : 1;       /*!< 100Base-T2 Full Duplex capability */ | ||||
|         uint32_t base10_t_hdx : 1;         /*!< 10Base-T Half Duplex capability */ | ||||
|         uint32_t base10_t_fdx : 1;         /*!< 10Base-T Full Duplex capability */ | ||||
|         uint32_t base100_tx_hdx : 1;       /*!< 100Base-Tx Half Duplex capability */ | ||||
|         uint32_t base100_tx_fdx : 1;       /*!< 100Base-Tx Full Duplex capability */ | ||||
|         uint32_t based100_t4 : 1;          /*!< 100Base-T4 capability */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } bmsr_reg_t; | ||||
| #define ETH_PHY_BMSR_REG_ADDR (0x01) | ||||
|  | ||||
| /** | ||||
|  * @brief PHYIDR1(PHY Identifier Register 1) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t oui_msb : 16; /*!< Organizationally Unique Identifier(OUI) most significant bits */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } phyidr1_reg_t; | ||||
| #define ETH_PHY_IDR1_REG_ADDR (0x02) | ||||
|  | ||||
| /** | ||||
|  * @brief PHYIDR2(PHY Identifier Register 2) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t model_revision : 4; /*!< Model revision number */ | ||||
|         uint32_t vendor_model : 6;   /*!< Vendor model number */ | ||||
|         uint32_t oui_lsb : 6;        /*!< Organizationally Unique Identifier(OUI) least significant bits */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } phyidr2_reg_t; | ||||
| #define ETH_PHY_IDR2_REG_ADDR (0x03) | ||||
|  | ||||
| /** | ||||
|  * @brief ANAR(Auto-Negotiation Advertisement Register) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t protocol_select : 5;  /*!< Binary encoded selector supported by this PHY */ | ||||
|         uint32_t base10_t : 1;         /*!< 10Base-T support */ | ||||
|         uint32_t base10_t_fd : 1;      /*!< 10Base-T full duplex support */ | ||||
|         uint32_t base100_tx : 1;       /*!< 100Base-TX support */ | ||||
|         uint32_t base100_tx_fd : 1;    /*!< 100Base-TX full duplex support */ | ||||
|         uint32_t base100_t4 : 1;       /*!< 100Base-T4 support */ | ||||
|         uint32_t symmetric_pause : 1;  /*!< Symmetric pause support for full duplex links */ | ||||
|         uint32_t asymmetric_pause : 1; /*!< Asymmetric pause support for full duplex links */ | ||||
|         uint32_t reserved1 : 1;        /*!< Reserved */ | ||||
|         uint32_t remote_fault : 1;     /*!< Advertise remote fault detection capability */ | ||||
|         uint32_t acknowledge : 1;      /*!< Link partner ability data reception acknowledged */ | ||||
|         uint32_t next_page : 1;        /*!< Next page indication, if set, next page transfer is desired */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } anar_reg_t; | ||||
| #define ETH_PHY_ANAR_REG_ADDR (0x04) | ||||
|  | ||||
| /** | ||||
|  * @brief ANLPAR(Auto-Negotiation Link Partner Ability Register) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t protocol_select : 5;  /*!< Link Partner’s binary encoded node selector */ | ||||
|         uint32_t base10_t : 1;         /*!< 10Base-T support */ | ||||
|         uint32_t base10_t_fd : 1;      /*!< 10Base-T full duplex support */ | ||||
|         uint32_t base100_tx : 1;       /*!< 100Base-TX support */ | ||||
|         uint32_t base100_tx_fd : 1;    /*!< 100Base-TX full duplex support */ | ||||
|         uint32_t base100_t4 : 1;       /*!< 100Base-T4 support */ | ||||
|         uint32_t symmetric_pause : 1;  /*!< Symmetric pause supported by Link Partner */ | ||||
|         uint32_t asymmetric_pause : 1; /*!< Asymmetric pause supported by Link Partner */ | ||||
|         uint32_t reserved : 1;         /*!< Reserved */ | ||||
|         uint32_t remote_fault : 1;     /*!< Link partner is indicating a remote fault */ | ||||
|         uint32_t acknowledge : 1;      /*!< Acknowledges from link partner */ | ||||
|         uint32_t next_page : 1;        /*!< Next page indication */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } anlpar_reg_t; | ||||
| #define ETH_PHY_ANLPAR_REG_ADDR (0x05) | ||||
|  | ||||
| /** | ||||
|  * @brief ANER(Auto-Negotiate Expansion Register) | ||||
|  * | ||||
|  */ | ||||
| typedef union { | ||||
|     struct { | ||||
|         uint32_t link_partner_auto_nego_able : 1; /*!< Link partner auto-negotiation ability */ | ||||
|         uint32_t link_page_received : 1;          /*!< Link code word page has received */ | ||||
|         uint32_t next_page_able : 1;              /*!< Next page ablility */ | ||||
|         uint32_t link_partner_next_page_able : 1; /*!< Link partner next page ability */ | ||||
|         uint32_t parallel_detection_fault : 1;    /*!< Parallel detection fault */ | ||||
|         uint32_t reserved : 11;                   /*!< Reserved */ | ||||
|     }; | ||||
|     uint32_t val; | ||||
| } aner_reg_t; | ||||
| #define ETH_PHY_ANER_REG_ADDR (0x06) | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user