Home > database >  esp32 SemaphoreTake vs SemaphoreTakeFromISR
esp32 SemaphoreTake vs SemaphoreTakeFromISR

Time:02-22

i want to have a task to calibrate xh711 on esp32. This task has to be triggered either buy button from iSR or by the program on initial start if needed.

On button press i have to user xSemaphoreGiveFromISR() but on automated call from program i can use xSemaphoreGive()

My question is which function should i use to identify the trigger? It is clear that for the button i have to use the xSemaphoreTakeFromISR() but on the automated trigger by the program should i use the xSemaphoreTake() or i can use the ISR version also with no problem?

CodePudding user response:

Functions ending in FromISR can be called from the interrupt service routine. The regular functions can only be used from task context.

See the documentation of xSemaphoreGive and xSemaphoreGiveFromISR.

There are several reasons for having separate functions, for example:

  • Non-ISR functions need to use critical sections.
  • ISR functions have a parameter pxHigherPriorityTaskWoken used for context switching.
  • Some non-ISR functions have xTicksToWait parameter to allow the task to sleep while it waits for a resource to become available. ISR functions do not have this parameter as ISRs cannot be blocked.
  • Related