-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Implement sei/cli using port{EXIT,ENTER}_CRITICAL #835
Conversation
This fixes the library I use to read temperature/humidity from DHT22.
cores/esp32/esp32-hal-timer.c
Outdated
@@ -25,6 +25,8 @@ | |||
#define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock) | |||
#define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock) | |||
|
|||
portMUX_TYPE arduino_mux = portMUX_INITIALIZER_UNLOCKED; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first mayb e move those to esp32-hal.h and esp32-hal-misc.c ? should not be in the timers ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps also rename arduino_mux to interrupt_lock or interrupt_mux ?
cli/sei are defined to just disable/enable interrupts, while the FreeRTOS port{ENTER,EXIT}CRITICAL functions must always match, and can be nested. Deal with this discrepancy by tracking whether interrupts were already disabled, and only call the FreeRTOS function if something will change.
I'm a bit confused by this.... wouldn't you want to actually disable interrupts instead of locking on a mutex? I see there are calls for |
Question is: What do you want to achieve by cli/sei? Protect memory? Make sure nothing interrupts particular code? |
@gtalusan Actually disabling interrupts would be better, although then you might lose things like the watchdog. I suppose that's just inevitable if you're trying to implement Arduino's simple view of the world in a more complex system. @me-no-dev The DHT sensor code needs to disable interrupts so it can count how long its output signal Strangely, now that I've migrated my project to use the Arduino layer as a component in esp-idf, reading the temperature seems to work often enough without applying this patch at all. It works about 93% of the time without this patch. With the patch it works 100% of the time. |
@rtwfroody I did a similar modification to the OneWire library #951 . It seems to work just fine. Chuck. |
Sorry to comment, and forgive me if I am wrong
arduino-esp32/tools/sdk/include/freertos/freertos/portmacro.h Lines 213 to 244 in 600f4c4
portDISABLE_INTERRUPTS() and portENABLE_INTERRUPTS() per my understanding
|
@luc-github you are correct :) closing this. Feel free to add one with the proper defines |
This fixes the library I use to read temperature/humidity from DHT22.
One problem is that the FreeRTOS functions work when nested, while I believe the Arduino sei() enables interrupts regardless of how many times cli() was invoked. Another problem is that these FreeRTOS functions don't work when called from interrupt handlers. (There are others for that.)
These caveats aside, this does seem to work in my thermostat project.
This is probably not ready to merge, but might be a good starting point for a more complete solution. It helps with issue #832.