1# eventfd example
2
3The example demonstrates the use of `eventfd()` to collect events from other tasks and ISRs in a
4`select()` based main loop.  The example starts two tasks and installs a timer interrupt handler:
51. The first task writes to the first `eventfd` periodically.
62. The timer interrupt handler writes to the second `eventfd`.
73. The second task collects the event from two fds with a `select()` loop.
8
9## How to use example
10
11### Hardware Required
12
13This example should be able to run on any commonly available ESP32, ESP32S2, ESP32S3 or ESP32C3 development board.
14
15### Configure the project
16
17```
18idf.py menuconfig
19```
20
21The default config will work.
22
23### Build and Flash
24
25Build the project and flash it to the board, then run monitor tool to view serial output:
26
27```
28idf.py -p PORT flash monitor
29```
30
31(Replace PORT with the name of the serial port to use.)
32
33(To exit the serial monitor, type ``Ctrl-]``.)
34
35See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
36
37## Example Output
38
39The following log output should appear when the example runs (note that the bootloader log has been omitted).
40
41```
42I (4340) eventfd_example: Elapsed since test start: 2003 ms
43I (4340) eventfd_example: Select timeout
44I (4830) eventfd_example: Elapsed since test start: 2499 ms
45I (4830) eventfd_example: TimerEvent fd event triggered
46I (5830) eventfd_example: Elapsed since test start: 3493 ms
47I (5830) eventfd_example: Progress fd event triggered
48I (7330) eventfd_example: Elapsed since test start: 4999 ms
49I (7330) eventfd_example: TimerEvent fd event triggered
50I (7330) eventfd_example: =================================
51I (7340) eventfd_example: Select timeouted for 1 times
52I (7340) eventfd_example: Timer triggerred for 2 times
53I (7350) eventfd_example: Progress triggerred for 1 times
54I (7360) eventfd_example: =================================
55I (9330) eventfd_example: Elapsed since test start: 6993 ms
56I (9330) eventfd_example: Progress fd event triggered
57I (9830) eventfd_example: Elapsed since test start: 7499 ms
58I (9830) eventfd_example: TimerEvent fd event triggered
59I (11840) eventfd_example: Elapsed since test start: 9503 ms
60I (11840) eventfd_example: Select timeout
61I (12330) eventfd_example: Elapsed since test start: 9999 ms
62I (12330) eventfd_example: TimerEvent fd event triggered
63I (12330) eventfd_example: =================================
64I (12340) eventfd_example: Select timeouted for 2 times
65I (12340) eventfd_example: Timer triggerred for 4 times
66I (12350) eventfd_example: Progress triggerred for 2 times
67I (12360) eventfd_example: =================================
68```
69
70## Diagram
71
72The following diagram shows, with a timeline, the order of the events:
73
74![Timeline](timeline.svg)
75