|
| 1 | +# Semaphore Example |
| 2 | + |
| 3 | +This example demonstrates the basic usage of FreeRTOS Semaphores and queue sets for coordination between tasks for multi-threading. |
| 4 | +Please refer to other examples in this folder to better understand the usage of tasks. |
| 5 | +It is also advised to read the documentation on FreeRTOS web pages: |
| 6 | +[https://www.freertos.org/a00106.html](https://www.freertos.org/a00106.html) |
| 7 | + |
| 8 | +### Theory: |
| 9 | +Semaphore is in essence a variable. Tasks can set the value, wait until one or more |
| 10 | +semaphores are set and thus communicate between each other their state. |
| 11 | +A binary semaphore is a semaphore that has a maximum count of 1, hence the 'binary' name. |
| 12 | +A task can only 'take' the semaphore if it is available, and the semaphore is only available if its count is 1. |
| 13 | + |
| 14 | +Semaphores can be controlled by any number of tasks. If you use semaphore as a one-way |
| 15 | +signalization with only one task giving and only one task taking there is a much faster option |
| 16 | +called Task Notifications - please see FreeRTOS documentation and read more about them: [https://www.freertos.org/RTOS-task-notifications.html](https://www.freertos.org/RTOS-task-notifications.html) |
| 17 | + |
| 18 | +This example uses a semaphore to signal when a package is delivered to a warehouse by multiple |
| 19 | +delivery trucks, and multiple workers are waiting to receive the package. |
| 20 | + |
| 21 | +# Supported Targets |
| 22 | + |
| 23 | +This example supports all ESP32 SoCs. |
| 24 | + |
| 25 | +## How to Use Example |
| 26 | + |
| 27 | +Read the code and try to understand it, then flash and observe the Serial output. |
| 28 | + |
| 29 | +* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide). |
| 30 | + |
| 31 | +#### Using Arduino IDE |
| 32 | + |
| 33 | +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). |
| 34 | + |
| 35 | +* Before Compile/Verify, select the correct board: `Tools -> Board`. |
| 36 | +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. |
| 37 | + |
| 38 | +#### Using Platform IO |
| 39 | + |
| 40 | +* Select the COM port: `Devices` or set the `upload_port` option on the `platformio.ini` file. |
| 41 | + |
| 42 | +## Example Log Output |
| 43 | + |
| 44 | +``` |
| 45 | +Anything you write will return as echo. |
| 46 | +Maximum line length is 63 characters (+ terminating '0'). |
| 47 | +Anything longer will be sent as a separate line. |
| 48 | +
|
| 49 | +``` |
| 50 | +< Input text "Short input" |
| 51 | + |
| 52 | +``Echo line of size 11: "Short input"`` |
| 53 | + |
| 54 | +< Input text "An example of very long input which is longer than default 63 characters will be split." |
| 55 | + |
| 56 | +``` |
| 57 | +Echo line of size 63: "An example of very long input which is longer than default 63 c" |
| 58 | +Echo line of size 24: "haracters will be split." |
| 59 | +``` |
| 60 | + |
| 61 | +## Troubleshooting |
| 62 | + |
| 63 | +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** |
| 64 | + |
| 65 | +## Contribute |
| 66 | + |
| 67 | +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) |
| 68 | + |
| 69 | +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! |
| 70 | + |
| 71 | +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. |
| 72 | + |
| 73 | +## Resources |
| 74 | + |
| 75 | +* Official ESP32 Forum: [Link](https://esp32.com) |
| 76 | +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) |
| 77 | +* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) |
| 78 | +* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) |
| 79 | +* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) |
| 80 | +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) |
0 commit comments