-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
esp_eth_phy.h
347 lines (318 loc) · 9.54 KB
/
esp_eth_phy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// 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.
#pragma once
#include <stdbool.h>
#include "esp_eth_com.h"
#include "sdkconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
#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 Advertise pause function supported by MAC layer
*
* @param[in] phy: Ethernet PHY instance
* @param[out] addr: Pause ability
*
* @return
* - ESP_OK: Advertise pause ability successfully
* - ESP_ERR_INVALID_ARG: Advertise pause ability failed because of invalid argument
*
*/
esp_err_t (*advertise_pause_ability)(esp_eth_phy_t *phy, uint32_t ability);
/**
* @brief
*
* @param[in] phy: Ethernet PHY instance
* @param[in] enable: enables or disables PHY loopback
*
* @return
* - ESP_OK: configures PHY instance loopback function successfully
* - ESP_FAIL: PHY instance loopback configuration failed because some error occurred
*
*/
esp_err_t (*loopback)(esp_eth_phy_t *phy, bool enable);
/**
* @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 LAN87xx
*
* @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_lan87xx(const eth_phy_config_t *config);
/**
* @brief Create a PHY instance of LAN8720
*
* @note For ESP-IDF backwards compatibility reasons. In all other cases, use esp_eth_phy_new_lan87xx instead.
*
* @param[in] config: configuration of PHY
*
* @return
* - instance: create PHY instance successfully
* - NULL: create PHY instance failed because some error occurred
*/
static inline esp_eth_phy_t *esp_eth_phy_new_lan8720(const eth_phy_config_t *config)
{
return esp_eth_phy_new_lan87xx(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);
/**
* @brief Create a PHY instance of KSZ8041
*
* @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_ksz8041(const eth_phy_config_t *config);
/**
* @brief Create a PHY instance of KSZ8081
*
* @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_ksz8081(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
#if CONFIG_ETH_SPI_ETHERNET_W5500
/**
* @brief Create a PHY instance of W5500
*
* @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_w5500(const eth_phy_config_t *config);
#endif
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
/**
* @brief Create a PHY instance of KSZ8851SNL
*
* @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_ksz8851snl(const eth_phy_config_t *config);
#endif
#ifdef __cplusplus
}
#endif