Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why isn't the new I2C API deemed as thread safe? (IDFGH-14050) #14869

Closed
3 tasks done
wuyuanyi135 opened this issue Nov 12, 2024 · 2 comments
Closed
3 tasks done

Why isn't the new I2C API deemed as thread safe? (IDFGH-14050) #14869

wuyuanyi135 opened this issue Nov 12, 2024 · 2 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@wuyuanyi135
Copy link
Contributor

wuyuanyi135 commented Nov 12, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

According to the doc, only bus creation was deemed as thread safe. Tracing the source code I found that the API are all semaphore-guarded that prevent racing access on the same bus:

For example:

if (xSemaphoreTake(i2c_dev->master_bus->bus_lock_mux, ticks_to_wait) != pdTRUE) {

If so, why are we recommended to put extra locks as per the doc?

@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 12, 2024
@github-actions github-actions bot changed the title Why isn't the new I2C API deemed as thread safe? Why isn't the new I2C API deemed as thread safe? (IDFGH-14050) Nov 12, 2024
@mythbuster5
Copy link
Collaborator

Yes, the doc is wrong and it will be updated soon

The factory function :cpp:func:`i2c_new_master_bus` and :cpp:func:`i2c_new_slave_device` are guaranteed to be thread safe by the driver, which means that the functions can be called from different RTOS tasks without protection by extra locks.

I2C master operation functions are also guaranteed to be thread safe by bus operation semaphore.

- :cpp:func:`i2c_master_transmit`
- :cpp:func:`i2c_master_multi_buffer_transmit`
- :cpp:func:`i2c_master_transmit_receive`
- :cpp:func:`i2c_master_receive`
- :cpp:func:`i2c_master_probe`

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new labels Nov 12, 2024
@wuyuanyi135
Copy link
Contributor Author

@mythbuster5 Thank you for the confirmation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants