|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | +#pragma once |
| 7 | + |
| 8 | +#include "esp_err.h" |
| 9 | +#include "esp_event.h" |
| 10 | +#include "iot_eth_interface.h" |
| 11 | + |
| 12 | +#ifdef __cplusplus |
| 13 | +extern "C" { |
| 14 | +#endif |
| 15 | + |
| 16 | +/** |
| 17 | +* @brief iot_eth event declarations |
| 18 | +* |
| 19 | +*/ |
| 20 | +typedef enum { |
| 21 | + IOT_ETH_EVENT_START, /*!< IOT_ETH driver start */ |
| 22 | + IOT_ETH_EVENT_STOP, /*!< IOT_ETH driver stop */ |
| 23 | + IOT_ETH_EVENT_CONNECTED, /*!< IOT_ETH got a valid link */ |
| 24 | + IOT_ETH_EVENT_DISCONNECTED, /*!< IOT_ETH lost a valid link */ |
| 25 | +} iot_eth_event_t; |
| 26 | + |
| 27 | +/** |
| 28 | +* @brief iot_eth event base declaration |
| 29 | +* |
| 30 | +*/ |
| 31 | +/** @cond **/ |
| 32 | +ESP_EVENT_DECLARE_BASE(IOT_ETH_EVENT); |
| 33 | +/** @endcond **/ |
| 34 | + |
| 35 | +/** |
| 36 | + * @brief Ethernet handle type |
| 37 | + * |
| 38 | + * This is a handle to an Ethernet instance, used for managing Ethernet operations. |
| 39 | + */ |
| 40 | +typedef void *iot_eth_handle_t; |
| 41 | + |
| 42 | +/** |
| 43 | + * @brief Static input callback function type |
| 44 | + * |
| 45 | + * This type defines a function pointer for a static input callback. |
| 46 | + * It takes an Ethernet handle, a pointer to data, the length of the data, |
| 47 | + * and a user data pointer as arguments. |
| 48 | + */ |
| 49 | +typedef esp_err_t (*static_input_cb_t)(iot_eth_handle_t handle, uint8_t *data, size_t len, void *user_data); |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief Ethernet configuration structure |
| 53 | + * |
| 54 | + * This structure holds the configuration for initializing an Ethernet instance. |
| 55 | + */ |
| 56 | +typedef struct { |
| 57 | + iot_eth_driver_t *driver; /*!< Pointer to the Ethernet driver */ |
| 58 | + static_input_cb_t stack_input; /*!< Function pointer for stack input */ |
| 59 | + void *user_data; /*!< User data for callbacks */ |
| 60 | +} iot_eth_config_t; |
| 61 | + |
| 62 | +/* |
| 63 | + * @brief Install Ethernet driver |
| 64 | + * |
| 65 | + * This function initializes the Ethernet driver and network interface. |
| 66 | + * |
| 67 | + * @param config Ethernet configuration |
| 68 | + * @param handle Pointer to the Ethernet handle |
| 69 | + * |
| 70 | + * @return |
| 71 | + * - ESP_OK on success |
| 72 | + * - ESP_ERR_INVALID_ARG if arguments are invalid |
| 73 | + * - ESP_ERR_NO_MEM if memory allocation fails |
| 74 | + * - Other error codes from initialization functions |
| 75 | + */ |
| 76 | +esp_err_t iot_eth_install(iot_eth_config_t *config, iot_eth_handle_t *handle); |
| 77 | + |
| 78 | +/* |
| 79 | + * @brief Uninstall Ethernet driver |
| 80 | + * |
| 81 | + * This function deinitializes the Ethernet driver and frees resources. |
| 82 | + * |
| 83 | + * @param handle Ethernet handle |
| 84 | + * |
| 85 | + * @return |
| 86 | + * - ESP_OK on success |
| 87 | + * - Error code from driver deinitialization |
| 88 | + */ |
| 89 | +esp_err_t iot_eth_uninstall(iot_eth_handle_t handle); |
| 90 | + |
| 91 | +/* |
| 92 | + * @brief Start Ethernet driver |
| 93 | + * |
| 94 | + * This function starts the Ethernet driver. |
| 95 | + * |
| 96 | + * @param handle Ethernet handle |
| 97 | + * |
| 98 | + * @return |
| 99 | + * - ESP_OK on success |
| 100 | + * - Error code from driver start function |
| 101 | + */ |
| 102 | +esp_err_t iot_eth_start(iot_eth_handle_t handle); |
| 103 | + |
| 104 | +/* |
| 105 | + * @brief Stop Ethernet driver |
| 106 | + * |
| 107 | + * This function stops the Ethernet driver. |
| 108 | + * |
| 109 | + * @param handle Ethernet handle |
| 110 | + * |
| 111 | + * @return |
| 112 | + * - ESP_OK on success |
| 113 | + * - Error code from driver stop function |
| 114 | + */ |
| 115 | +esp_err_t iot_eth_stop(iot_eth_handle_t handle); |
| 116 | + |
| 117 | +/* |
| 118 | + * @brief Transmit data over Ethernet |
| 119 | + * |
| 120 | + * This function sends data through the Ethernet driver. |
| 121 | + * |
| 122 | + * @param handle Ethernet handle |
| 123 | + * @param data Pointer to the data to be sent |
| 124 | + * @param len Length of the data to be sent |
| 125 | + * |
| 126 | + * @return |
| 127 | + * - ESP_OK on success |
| 128 | + * - ESP_ERR_INVALID_ARG if arguments are invalid |
| 129 | + * - ESP_ERR_INVALID_STATE if Ethernet link is down |
| 130 | + */ |
| 131 | +esp_err_t iot_eth_transmit(iot_eth_handle_t handle, void *data, size_t len); |
| 132 | + |
| 133 | +/* |
| 134 | + * @brief Get Ethernet MAC address |
| 135 | + * |
| 136 | + * This function retrieves the MAC address of the Ethernet interface. |
| 137 | + * |
| 138 | + * @param handle Ethernet handle |
| 139 | + * @param mac Pointer to the MAC address buffer |
| 140 | + * |
| 141 | + * @return |
| 142 | + * - ESP_OK on success |
| 143 | + * - Error code from driver get address function |
| 144 | + */ |
| 145 | +esp_err_t iot_eth_get_addr(iot_eth_handle_t handle, uint8_t *mac); |
| 146 | + |
| 147 | +/* |
| 148 | + * @brief Update the input path for Ethernet data |
| 149 | + * |
| 150 | + * This function updates the stack input callback function and user data pointer |
| 151 | + * that will be used when receiving Ethernet packets. |
| 152 | + * |
| 153 | + * @param[in] handle Ethernet handle |
| 154 | + * @param[in] stack_input Function pointer for stack input callback |
| 155 | + * @param[in] user_data User data to be passed to stack input callback |
| 156 | + * |
| 157 | + * @return |
| 158 | + * - ESP_OK: Successfully updated input path |
| 159 | + * - ESP_ERR_INVALID_ARG: Invalid handle argument |
| 160 | + */ |
| 161 | +esp_err_t iot_eth_update_input_path(iot_eth_handle_t handle, static_input_cb_t stack_input, void *user_data); |
| 162 | + |
| 163 | +#ifdef __cplusplus |
| 164 | +} |
| 165 | +#endif |
0 commit comments