how to effectively use ESP timer interrupt callback.
Posted: Tue Nov 01, 2022 4:41 pm
I was working on a project where I should send some data to a cloud infrastructure at a specific frequency.
So I was trying to figure out an apt method to do so.
methods am trying :
1) We could create a task and set up a function to send the data to every specific interval and use task delay for the same.
2) We could create a timer interrupt that will trigger on every interval as set to the timer And will be pushed to call back.
Now I believe timer interrupt will be a better option as we will not need the task to be running all the time.
Now, if we use a timer, we can use a callback function to get triggered every interval.
But upon looking at the esp32 documentation for timer callback:
"ESP_TIMER_TASK. Timer callbacks are dispatched from a high-priority esp_timer task. Because all the callbacks are dispatched from the same task, it is recommended to only do the minimal possible amount of work from the callback itself, posting an event to a lower-priority task using a queue instead.
"
Link: https://docs.espressif.com/projects/esp ... timer.html
So here arise my problems. Should I use a Queue to be sent from the callback function to a low-priority task which will, in turn, process the data as per my requirement, or should I use a binary semaphore to notify the task?
If I am using the Queue, the task will be in waiting, and not sure whether that will be using my resources. If I am using a binary semaphore to notify the task, I believe the task will be in a suspended state till it gets the semaphore. (As per my understanding) And I believe a suspended task will be only using lesser resources.
So if anyone can point out the best method for me, it will be appreciated. Also, any other alternative way which you believe will be the right path to follow? As resource management is a concern for me.
Thanks in advance.
So I was trying to figure out an apt method to do so.
methods am trying :
1) We could create a task and set up a function to send the data to every specific interval and use task delay for the same.
2) We could create a timer interrupt that will trigger on every interval as set to the timer And will be pushed to call back.
Now I believe timer interrupt will be a better option as we will not need the task to be running all the time.
Now, if we use a timer, we can use a callback function to get triggered every interval.
But upon looking at the esp32 documentation for timer callback:
"ESP_TIMER_TASK. Timer callbacks are dispatched from a high-priority esp_timer task. Because all the callbacks are dispatched from the same task, it is recommended to only do the minimal possible amount of work from the callback itself, posting an event to a lower-priority task using a queue instead.
"
Link: https://docs.espressif.com/projects/esp ... timer.html
So here arise my problems. Should I use a Queue to be sent from the callback function to a low-priority task which will, in turn, process the data as per my requirement, or should I use a binary semaphore to notify the task?
If I am using the Queue, the task will be in waiting, and not sure whether that will be using my resources. If I am using a binary semaphore to notify the task, I believe the task will be in a suspended state till it gets the semaphore. (As per my understanding) And I believe a suspended task will be only using lesser resources.
So if anyone can point out the best method for me, it will be appreciated. Also, any other alternative way which you believe will be the right path to follow? As resource management is a concern for me.
Thanks in advance.