doc: remove left-over legacy event loop docs

This commit is contained in:
Jakob Hasse 2023-03-13 18:53:36 +08:00
parent ca5dd7f0b3
commit a44671c11a
10 changed files with 19 additions and 167 deletions

View File

@ -1,152 +0,0 @@
Event Handling
==============
Several ESP-IDF components use *events* to inform application about state changes, such as connection or disconnection. This document gives an overview of these event mechanisms.
Wi-Fi, Ethernet, and IP Events
------------------------------
Before the introduction of :doc:`esp_event library<../api-reference/system/esp_event>`, events from Wi-Fi driver, Ethernet driver, and TCP/IP stack were dispatched using the so-called *legacy event loop*. The following sections explain each of the methods.
esp_event Library Event Loop
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
esp_event library is designed to supersede the legacy event loop for the purposes of event handling in ESP-IDF. In the legacy event loop, all possible event types and event data structures had to be defined in :cpp:type:`system_event_id_t` enumeration and :cpp:type:`system_event_info_t` union, which made it impossible to send custom events to the event loop, and use the event loop for other kinds of events (e.g. Mesh). Legacy event loop also supported only one event handler function, therefore application components could not handle some of Wi-Fi or IP events themselves, and required application to forward these events from its event handler function.
See :doc:`esp_event library API reference<../api-reference/system/esp_event>` for general information on using this library. Wi-Fi, Ethernet, and IP events are sent to the :ref:`default event loop <esp-event-default-loops>` provided by this library.
.. _legacy-event-loop:
Legacy Event Loop
~~~~~~~~~~~~~~~~~
This event loop implementation is started using :cpp:func:`esp_event_loop_init` function. Application typically supplies an *event handler*, a function with the following signature::
esp_err_t event_handler(void *ctx, system_event_t *event)
{
}
Both the pointer to event handler function, and an arbitrary context pointer are passed to :cpp:func:`esp_event_loop_init`.
When Wi-Fi, Ethernet, or IP stack generate an event, this event is sent to a high-priority ``event`` task via a queue. Application-provided event handler function is called in the context of this task. Event task stack size and event queue size can be adjusted using :ref:`CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE` and :ref:`CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE` options, respectively.
Event handler receives a pointer to the event structure (:cpp:type:`system_event_t`) which describes current event. This structure follows a *tagged union* pattern: ``event_id`` member indicates the type of event, and ``event_info`` member is a union of description structures. Application event handler will typically use ``switch(event->event_id)`` to handle different kinds of events.
If application event handler needs to relay the event to some other task, it is important to note that event pointer passed to the event handler is a pointer to temporary structure. To pass the event to another task, application has to make a copy of the entire structure.
Event IDs and Corresponding Data Structures
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+------------------------------------+-----------------------------------------------+
| Event ID | Event data structure |
| (legacy event ID) | |
+------------------------------------+-----------------------------------------------+
| **Wi-Fi** |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_WIFI_READY | n/a |
| (SYSTEM_EVENT_WIFI_READY) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_SCAN_DONE | :cpp:class:`wifi_event_sta_scan_done_t` |
| (SYSTEM_EVENT_SCAN_DONE) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_START | n/a |
| (SYSTEM_EVENT_STA_START) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_STOP | n/a |
| (SYSTEM_EVENT_STA_STOP) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_CONNECTED | :cpp:class:`wifi_event_sta_connected_t` |
| (SYSTEM_EVENT_STA_CONNECTED) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_DISCONNECTED | :cpp:class:`wifi_event_sta_disconnected_t` |
| (SYSTEM_EVENT_STA_DISCONNECTED) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_AUTHMODE_CHANGE | :cpp:class:`wifi_event_sta_authmode_change_t` |
| (SYSTEM_EVENT_STA_AUTHMODE_CHANGE) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_WPS_ER_SUCCESS | n/a |
| (SYSTEM_EVENT_STA_WPS_ER_SUCCESS) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_WPS_ER_FAILED | :cpp:type:`wifi_event_sta_wps_fail_reason_t` |
| (SYSTEM_EVENT_STA_WPS_ER_FAILED) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_WPS_ER_TIMEOUT | n/a |
| (SYSTEM_EVENT_STA_WPS_ER_TIMEOUT) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_STA_WPS_ER_PIN | :cpp:class:`wifi_event_sta_wps_er_pin_t` |
| (SYSTEM_EVENT_STA_WPS_ER_PIN) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_AP_START | n/a |
| (SYSTEM_EVENT_AP_START) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_AP_STOP | n/a |
| (SYSTEM_EVENT_AP_STOP) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_AP_STACONNECTED | :cpp:class:`wifi_event_ap_staconnected_t` |
| (SYSTEM_EVENT_AP_STACONNECTED) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_AP_STADISCONNECTED | :cpp:class:`wifi_event_ap_stadisconnected_t` |
| (SYSTEM_EVENT_AP_STADISCONNECTED) | |
+------------------------------------+-----------------------------------------------+
| WIFI_EVENT_AP_PROBEREQRECVED | :cpp:class:`wifi_event_ap_probe_req_rx_t` |
| (SYSTEM_EVENT_AP_PROBEREQRECVED) | |
+------------------------------------+-----------------------------------------------+
| **Ethernet** |
+------------------------------------+-----------------------------------------------+
| ETHERNET_EVENT_START | n/a |
| (SYSTEM_EVENT_ETH_START) | |
+------------------------------------+-----------------------------------------------+
| ETHERNET_EVENT_STOP | n/a |
| (SYSTEM_EVENT_ETH_STOP) | |
+------------------------------------+-----------------------------------------------+
| ETHERNET_EVENT_CONNECTED | n/a |
| (SYSTEM_EVENT_ETH_CONNECTED) | |
+------------------------------------+-----------------------------------------------+
| ETHERNET_EVENT_DISCONNECTED | n/a |
| (SYSTEM_EVENT_ETH_DISCONNECTED) | |
+------------------------------------+-----------------------------------------------+
| **IP** |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_STA_GOT_IP | :cpp:class:`ip_event_got_ip_t` |
| (SYSTEM_EVENT_STA_GOT_IP) | |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_STA_LOST_IP | n/a |
| (SYSTEM_EVENT_STA_LOST_IP) | |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_AP_STAIPASSIGNED | n/a |
| (SYSTEM_EVENT_AP_STAIPASSIGNED) | |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_GOT_IP6 | :cpp:class:`ip_event_got_ip6_t` |
| (SYSTEM_EVENT_GOT_IP6) | |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_ETH_GOT_IP | :cpp:class:`ip_event_got_ip_t` |
| (SYSTEM_EVENT_ETH_GOT_IP) | |
+------------------------------------+-----------------------------------------------+
| IP_EVENT_ETH_LOST_IP | n/a |
| (SYSTEM_EVENT_ETH_LOST_IP) | |
+------------------------------------+-----------------------------------------------+
.. only:: SOC_WIFI_MESH_SUPPORT
Mesh Events
-----------
ESP-WIFI-MESH uses a system similar to the :ref:`legacy-event-loop` to deliver events to the application. See :ref:`mesh-events` for details.
Bluetooth Events
----------------
Various modules of the Bluetooth stack deliver events to applications via dedicated callback functions. Callback functions receive the event type (enumerated value) and event data (union of structures for each event type). The following list gives the registration API name, event enumeration type, and event parameters type.
* BLE GAP: :cpp:func:`esp_ble_gap_register_callback`, :cpp:type:`esp_gap_ble_cb_event_t`, :cpp:type:`esp_ble_gap_cb_param_t`.
* BT GAP: :cpp:func:`esp_bt_gap_register_callback`, :cpp:type:`esp_bt_gap_cb_event_t`, :cpp:type:`esp_bt_gap_cb_param_t`.
* GATTC: :cpp:func:`esp_ble_gattc_register_callback`, :cpp:type:`esp_ble_gattc_cb_event_t`, :cpp:type:`esp_ble_gattc_cb_param_t`.
* GATTS: :cpp:func:`esp_ble_gatts_register_callback`, :cpp:type:`esp_ble_gatts_cb_event_t`, :cpp:type:`esp_ble_gatts_cb_param_t`.
* SPP: :cpp:func:`esp_spp_register_callback`, :cpp:type:`esp_spp_cb_event_t`, :cpp:type:`esp_spp_cb_param_t`.
* Blufi: :cpp:func:`esp_blufi_register_callbacks`, :cpp:type:`esp_blufi_cb_event_t`, :cpp:type:`esp_blufi_cb_param_t`.
* A2DP: :cpp:func:`esp_a2d_register_callback`, :cpp:type:`esp_a2d_cb_event_t`, :cpp:type:`esp_a2d_cb_param_t`.
* AVRC: :cpp:func:`esp_avrc_ct_register_callback`, :cpp:type:`esp_avrc_ct_cb_event_t`, :cpp:type:`esp_avrc_ct_cb_param_t`.
* HFP Client: :cpp:func:`esp_hf_client_register_callback`, :cpp:type:`esp_hf_client_cb_event_t`, :cpp:type:`esp_hf_client_cb_param_t`.
* HFP AG: :cpp:func:`esp_bt_hf_register_callback`, :cpp:type:`esp_hf_cb_event_t`, :cpp:type:`esp_hf_cb_param_t`.

View File

@ -18,7 +18,6 @@ API Guides
error-handling
:SOC_BLE_MESH_SUPPORTED: esp-ble-mesh/ble-mesh-index
:SOC_WIFI_MESH_SUPPORT: esp-wifi-mesh
event-handling
:SOC_SPIRAM_SUPPORTED: external-ram
fatal-errors
../security/flash-encryption

View File

@ -76,7 +76,7 @@ The default stack sizes for these tasks are usually set conservatively high, to
- :ref:`Main task that executes app_main function <app-main-task>` has stack size :ref:`CONFIG_ESP_MAIN_TASK_STACK_SIZE`.
- :doc:`/api-reference/system/esp_timer` system task which executes callbacks has stack size :ref:`CONFIG_ESP_TIMER_TASK_STACK_SIZE`.
- FreeRTOS Timer Task to handle FreeRTOS timer callbacks has stack size :ref:`CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH`.
- :doc:`/api-guides/event-handling` system task to execute callbacks for the default system event loop has stack size :ref:`CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE`.
- :doc:`/api-reference/system/esp_event` system task to execute callbacks for the default system event loop has stack size :ref:`CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE`.
- :doc:`/api-guides/lwip` TCP/IP task has stack size :ref:`CONFIG_LWIP_TCPIP_TASK_STACK_SIZE`
:SOC_BT_SUPPORTED: - :doc:`Bluedroid Bluetooth Host </api-reference/bluetooth/index>` have task stack sizes :ref:`CONFIG_BT_BTC_TASK_STACK_SIZE`, :ref:`CONFIG_BT_BTU_TASK_STACK_SIZE`.
:SOC_BT_SUPPORTED: - :doc:`NimBLE Bluetooth Host </api-reference/bluetooth/nimble/index>` has task stack size :ref:`CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE`

View File

@ -162,7 +162,7 @@ Common priorities are:
- :ref:`Main task that executes app_main function <app-main-task>` has minimum priority (1).
- :doc:`/api-reference/system/esp_timer` system task to manage timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``)
- FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`).
- :doc:`/api-guides/event-handling` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``). This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``). This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``).
:SOC_WIFI_SUPPORTED: - :doc:`Wi-Fi Driver </api-guides/wifi>` task has high priority (23).
:SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2).
@ -179,7 +179,7 @@ Common priorities are:
- :ref:`Main task that executes app_main function <app-main-task>` has minimum priority (1). This task is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_MAIN_TASK_AFFINITY>`).
- :doc:`/api-reference/system/esp_timer` system task to manage high precision timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``). This task is pinned to Core 0.
- FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable <CONFIG_FREERTOS_TIMER_TASK_PRIORITY>`). This task is pinned to Core 0.
- :doc:`/api-guides/event-handling` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``) and pinned to Core 0. This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``) and pinned to Core 0. This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it's possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead.
- :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``) and is not pinned to any core (:ref:`configurable<CONFIG_LWIP_TCPIP_TASK_AFFINITY>`).
:SOC_WIFI_SUPPORTED: - :doc:`Wi-Fi Driver </api-guides/wifi>` task has high priority (23) and is pinned to Core 0 by default (:ref:`configurable<CONFIG_ESP_WIFI_TASK_CORE_ID>`).
:SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2) and are not pinned to any core.
@ -256,4 +256,4 @@ These functions are designed to be portable, so they are not necessarily optimiz
- To increase speed of buffered reading functions like ``fread`` and ``fgets``, you can increase a size of the file buffer (Newlib's default is 128 bytes) to a higher number like 4096, 8192 or 16384. This can be done locally via ``setvbuf`` function used on a certain file pointer or globally applied to all files via modifying :ref:`CONFIG_FATFS_VFS_FSTAT_BLKSIZE`.
.. note::
Setting a bigger buffer size will also increase the heap memory usage.
Setting a bigger buffer size will also increase the heap memory usage.

View File

@ -59,7 +59,7 @@ Refer to `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_ and `{IDF_TARGET_NA
Event-Handling
++++++++++++++
Generally, it is easy to write code in "sunny-day" scenarios, such as `WIFI_EVENT_STA_START`_ and `WIFI_EVENT_STA_CONNECTED`_. The hard part is to write routines in "rainy-day" scenarios, such as `WIFI_EVENT_STA_DISCONNECTED`_. Good handling of "rainy-day" scenarios is fundamental to robust Wi-Fi applications. Refer to `{IDF_TARGET_NAME} Wi-Fi Event Description`_, `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_, and `{IDF_TARGET_NAME} Wi-Fi AP General Scenario`_. See also :doc:`an overview of event handling in ESP-IDF<event-handling>`.
Generally, it is easy to write code in "sunny-day" scenarios, such as `WIFI_EVENT_STA_START`_ and `WIFI_EVENT_STA_CONNECTED`_. The hard part is to write routines in "rainy-day" scenarios, such as `WIFI_EVENT_STA_DISCONNECTED`_. Good handling of "rainy-day" scenarios is fundamental to robust Wi-Fi applications. Refer to `{IDF_TARGET_NAME} Wi-Fi Event Description`_, `{IDF_TARGET_NAME} Wi-Fi station General Scenario`_, and `{IDF_TARGET_NAME} Wi-Fi AP General Scenario`_. See also the :doc:`overview of the Event Loop Library in ESP-IDF<../api-reference/system/esp_event>`.
Write Error-Recovery Routines Correctly at All Times
++++++++++++++++++++++++++++++++++++++++++++++++++++

View File

@ -4,11 +4,17 @@ Event Loop Library
Overview
--------
The event loop library allows components to declare events to which other components can register handlers -- code which will
execute when those events occur. This allows loosely coupled components to attach desired behavior to changes in state of other components
without application involvement. For instance, a high level connection handling library may subscribe to events produced
by the Wi-Fi subsystem directly and act on those events. This also simplifies event processing by serializing and deferring
code execution to another context.
The event loop library allows components to declare events to which other components can register handlers -- code which will execute when those events occur. This allows loosely coupled components to attach desired behavior to state changes of other components without application involvement. This also simplifies event processing by serializing and deferring code execution to another context.
.. only:: SOC_WIFI_SUPPORTED
One common use case is if a high level library is using the WiFi library: it may subscribe to :ref:`events produced by the Wi-Fi subsystem <wifi-programming-model>` directly and act on those events.
.. only:: SOC_BT_SUPPORTED
.. note::
Various modules of the Bluetooth stack deliver events to applications via dedicated callback functions instead of via the Event Loop Library.
Using ``esp_event`` APIs
------------------------

View File

@ -69,6 +69,7 @@ api-guides/ulps2_instruction_set api-reference/system/ulp_instruc
api-guides/ulp_macros api-reference/system/ulp_macros
api-guides/ulp-risc-v api-reference/system/ulp-risc-v
api-guides/console api-reference/system/console
api-guides/event-handling api-reference/system/esp_event
api-reference/network/tcpip_adapter migration-guides/tcpip-adapter
api-reference/system/system api-reference/system/misc_system_api

View File

@ -1 +0,0 @@
.. include:: ../../en/api-guides/event-handling.rst

View File

@ -18,7 +18,6 @@ API 指南
error-handling
:SOC_BLE_MESH_SUPPORTED: esp-ble-mesh/ble-mesh-index
:SOC_WIFI_MESH_SUPPORT: esp-wifi-mesh
event-handling
:SOC_SPIRAM_SUPPORTED: external-ram
fatal-errors
../security/flash-encryption

View File

@ -1,4 +1,4 @@
Wi-Fi 驱动程序
Wi-Fi 驱动程序
==================
:link_to_translation:`en:[English]`
@ -59,7 +59,7 @@ Wi-Fi 初始化
事件处理
++++++++++++++
通常,在理想环境下编写代码难度并不大,如 `WIFI_EVENT_STA_START`_、`WIFI_EVENT_STA_CONNECTED`_ 中所述。难度在于如何在现实的困难环境下编写代码,如 `WIFI_EVENT_STA_DISCONNECTED`_ 中所述。能否在后者情况下完美地解决各类事件冲突,是编写一个强健的 Wi-Fi 应用程序的根本。请参阅 `{IDF_TARGET_NAME} Wi-Fi 事件描述`_, `{IDF_TARGET_NAME} Wi-Fi station 一般情况`_, `{IDF_TARGET_NAME} Wi-Fi AP 一般情况`_。另可参阅 ESP-IDF 中的 `事件处理概述 <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/event-handling.html?highlight=event%20handling>`_
通常,在理想环境下编写代码难度并不大,如 `WIFI_EVENT_STA_START`_`WIFI_EVENT_STA_CONNECTED`_ 中所述。难度在于如何在现实的困难环境下编写代码,如 `WIFI_EVENT_STA_DISCONNECTED`_ 中所述。能否在后者情况下完美地解决各类事件冲突,是编写一个强健的 Wi-Fi 应用程序的根本。请参阅 `{IDF_TARGET_NAME} Wi-Fi 事件描述`_, `{IDF_TARGET_NAME} Wi-Fi station 一般情况`_, `{IDF_TARGET_NAME} Wi-Fi AP 一般情况`_。另可参阅 ESP-IDF 中的 :doc:`事件处理概述 <../api-reference/system/esp_event>`
编写错误恢复程序
++++++++++++++++++++++++++++++++++++++++++++++++++++