You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/api-reference/network/esp_netif.rst
+42-40Lines changed: 42 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,44 +33,45 @@ It is usually just enough to create a default network interface after startup an
33
33
Initialization
34
34
--------------
35
35
36
-
Since the ESP-NETIF component uses system events, the typical network startup code looks like this (note, that error handling is omitted for clarity, see :example_file:`ethernet/basic/main/ethernet_example_main.c` for complete startup code):
36
+
Since the ESP-NETIF component uses system events, the typical network startup code looks like this (note that error handling is omitted for clarity, see :example_file:`ethernet/basic/main/ethernet_example_main.c` for complete startup code):
37
37
38
38
.. code-block:: c
39
39
40
-
// 1) Initialize the TCP/IP stack and the event loop
41
-
esp_netif_init();
42
-
esp_event_loop_create_default();
40
+
// 1) Initialize the TCP/IP stack and the event loop
41
+
esp_netif_init();
42
+
esp_event_loop_create_default();
43
43
44
-
// 2) Create the network interface handle
45
-
esp_netif = esp_netif_new(&config);
44
+
// 2) Create the network interface handle
45
+
esp_netif = esp_netif_new(&config);
46
46
47
-
// 3) Create the network interface driver (e.g. Ethernet) and it's network layer glue
48
-
// and register the ESP-NETIF event (e.g. to bring the interface up upon link-up event)
49
-
esp_netif_glue_t glue = driver_glue(driver);
47
+
// 3) Create the network interface driver (e.g., Ethernet) and it's network layer glue
48
+
// and register the ESP-NETIF event (e.g., to bring the interface up upon link-up event)
49
+
esp_netif_glue_t glue = driver_glue(driver);
50
50
51
-
// 4) Attach the driver's glue layer to the network interface handle
52
-
esp_netif_attach(esp_netif, glue);
51
+
// 4) Attach the driver's glue layer to the network interface handle
52
+
esp_netif_attach(esp_netif, glue);
53
53
54
-
// 5) Register user-side event handlers
55
-
esp_event_handler_register(DRIVER_EVENT, ...); // to observe driver states, e.g. link-up
56
-
esp_event_handler_register(IP_EVENT, ...); // to observe ESP-NETIF states, e.g. get an IP
54
+
// 5) Register user-side event handlers
55
+
esp_event_handler_register(DRIVER_EVENT, ...); // to observe driver states, e.g., link-up
56
+
esp_event_handler_register(IP_EVENT, ...); // to observe ESP-NETIF states, e.g., get an IP
57
57
58
58
59
59
.. note::
60
60
61
-
These steps must be performed in the exact order shown above, primarily due to the default event loop used by network interface drivers to register system events.
61
+
These steps must be performed in the exact order shown above, as the network interface drivers use the default event loop when registering system events.
62
62
63
-
- The default event loop needs to be created **before** initializing an interface driver, as the driver typically needs to register system event handlers.
64
-
- Registering application event handlers must occur **after** calling :cpp:func:`esp_netif_attach`, because event handlers are called in the order they were registered. To ensure that system handlers are called first, you should register application handlers afterward.
63
+
- The default event loop needs to be created **before** initializing an interface driver, as the driver typically needs to register system event handlers.
64
+
- Registering application event handlers must occur **after** calling :cpp:func:`esp_netif_attach`, because event handlers are called in the order they were registered. To ensure that system handlers are called first, you should register application handlers afterward.
65
65
66
-
Steps ``2)``, ``3)`` and ``4)`` are quite complex for most common use-cases, so ESP-NETIF provides some pre-configured interfaces and convenience functions that create the most common network interfaces in their most common configurations.
66
+
Steps ``2)``, ``3)`` and ``4)`` are quite complex for most common use-cases, so ESP-NETIF provides some pre-configured interfaces and convenience functions that create the most common network interfaces in their most common configurations.
67
67
68
68
.. note::
69
69
70
70
Each network interface needs to be initialized separately, so if you would like to use multiple interfaces, you would have to run steps ``2)`` to ``5)`` for every interface. Set ``1)`` should be performed only once.
71
71
72
72
73
73
Creating and configuring the interface and attaching the network interface driver to it (steps ``2)``, ``3)`` and ``4)``) is described in :ref:`create_esp_netif`.
74
+
74
75
Using the ESP-NETIF event handlers (step ``5)``) is described in :ref:`esp-netif-ip-events`.
75
76
76
77
@@ -120,7 +121,7 @@ The initialization code as well as registering event handlers for default interf
120
121
121
122
.. only:: CONFIG_ESP_WIFI_SOFTAP_SUPPORT
122
123
123
-
* When using Wi-Fi in ``AP+STA`` mode, both these interfaces have to be created. Please refer to the example :example_file:`wifi/softap_sta/main/softap_sta.c`
124
+
* When using Wi-Fi in ``AP+STA`` mode, both these interfaces have to be created. Please refer to the example :example_file:`wifi/softap_sta/main/softap_sta.c`.
124
125
125
126
.. _esp-netif-ip-events:
126
127
@@ -137,7 +138,7 @@ Registering event handlers is crucial due to the asynchronous nature of networki
137
138
138
139
.. note::
139
140
140
-
Lost IP events are triggered by a timer configurable by :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`. The timer is started upon losing the IP address and the event will be raised after the configured interval, which is 120s by default. The event could be disabled when setting the interval to 0.
141
+
Lost IP events are triggered by a timer configurable by :ref:`CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL`. The timer is started upon losing the IP address and the event will be raised after the configured interval, which is 120 s by default. The event could be disabled when setting the interval to 0.
141
142
142
143
.. _esp-netif structure:
143
144
@@ -207,24 +208,24 @@ Overall application interaction with a specific IO driver for the communication
207
208
208
209
A) Initialization code
209
210
210
-
1) Initializes IO driver
211
-
2) Creates a new instance of ESP-NETIF and configure it with
211
+
1) Initializes IO driver
212
+
2) Creates a new instance of ESP-NETIF and configure it with
212
213
213
-
* ESP-NETIF specific options (flags, behavior, name)
214
-
* Network stack options (netif init and input functions, not publicly available)
3) Attaches the IO driver handle to the ESP-NETIF instance created in the above steps
218
-
4) Configures event handlers
218
+
3) Attaches the IO driver handle to the ESP-NETIF instance created in the above steps
219
+
4) Configures event handlers
219
220
220
-
* Use default handlers for common interfaces defined in IO drivers; or define a specific handler for customized behavior or new interfaces
221
-
* Register handlers for app-related events (such as IP lost or acquired)
221
+
* Use default handlers for common interfaces defined in IO drivers; or define a specific handler for customized behavior or new interfaces
222
+
* Register handlers for app-related events (such as IP lost or acquired)
222
223
223
224
B) Interaction with network interfaces using ESP-NETIF API
224
225
225
-
1) Gets and sets TCP/IP-related parameters (DHCP, IP, etc)
226
-
2) Receives IP events (connect or disconnect)
227
-
3) Controls application lifecycle (set interface up or down)
226
+
1) Gets and sets TCP/IP-related parameters (DHCP, IP, etc)
227
+
2) Receives IP events (connect or disconnect)
228
+
3) Controls application lifecycle (set interface up or down)
228
229
229
230
230
231
B) Network Interface Driver
@@ -236,8 +237,8 @@ Network interface driver (also called I/O Driver, or Media Driver) plays these t
236
237
237
238
2) Glue IO layer: Adapts the input or output functions to use ESP-NETIF transmit, receive, and free receive buffer
238
239
239
-
* Installs driver_transmit to the appropriate ESP-NETIF object so that outgoing packets from the network stack are passed to the IO driver
240
-
* Calls :cpp:func:`esp_netif_receive()` to pass incoming data to the network stack
240
+
* Installs driver_transmit to the appropriate ESP-NETIF object so that outgoing packets from the network stack are passed to the IO driver
241
+
* Calls :cpp:func:`esp_netif_receive()` to pass incoming data to the network stack
241
242
242
243
243
244
C) ESP-NETIF
@@ -249,16 +250,16 @@ ESP-NETIF serves as an intermediary between an IO driver and a network stack, co
249
250
2) Input or Output API (for passing data between IO driver and network stack)
250
251
3) Event or Action API
251
252
252
-
* Used for network interface lifecycle management
253
-
* ESP-NETIF provides building blocks for designing event handlers
253
+
* Used for network interface lifecycle management
254
+
* ESP-NETIF provides building blocks for designing event handlers
254
255
255
256
4) Setters and Getters API for basic network interface properties
256
257
5) Network stack abstraction API: enabling user interaction with TCP/IP stack
257
258
258
-
* Set interface up or down
259
-
* DHCP server and client API
260
-
* DNS API
261
-
* :ref:`esp_netif-sntp-api`
259
+
* Set interface up or down
260
+
* DHCP server and client API
261
+
* DNS API
262
+
* :ref:`esp_netif-sntp-api`
262
263
263
264
6) Driver conversion utilities API
264
265
@@ -271,6 +272,7 @@ The network stack has no public interaction with application code with regard to
271
272
272
273
E) ESP-NETIF L2 TAP Interface
273
274
'''''''''''''''''''''''''''''
275
+
274
276
The ESP-NETIF L2 TAP interface is a mechanism in ESP-IDF used to access Data Link Layer (L2 per OSI/ISO) for frame reception and transmission from the user application. Its typical usage in the embedded world might be the implementation of non-IP-related protocols, e.g., PTP, Wake on LAN. Note that only Ethernet (IEEE 802.3) is currently supported. Please read more about L2 TAP in :ref:`esp_netif_l2tap`.
0 commit comments