-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add mgos_invoke_cb() option to use xQueueSendToFront...() #537
Comments
we can add a variant that sends to front instead - |
I can do the PR, but i am not FreeRTOS expert... Can you please confirm this will actualy work in the way i expect? So my callback will get executed immediately instead of waiting for other jobs that might have been queued before that? |
you can add elements to queue front, yes. |
Sure. I will have to first check what causes more trouble in my case. Events already being executed or the events that are queued but not executed yet. BTW is there something else that you would reccomend to tackle my issue with having to do immediate yet complex communication in ISR? I was thinking about using ISR to create new RTOS task instead of mgos event. To handle the communication immediately (while not running in ISR context). That way the slow/blocking mgos event might get preempted and my code might run fast enough. But i am not sure about how fast/realtime this would be... |
Is there way i can check if there's something currently executing and how many events are waiting in mgos queue? So i can use it in ISR to check if that's the case? |
creating a task is possible and might be warranted in your case. if you create it with priority higher than MGOS_TASK_PRIORITY (e.g. MGOS_TASK_PRIORITY+1), it will preempt mgos if you send a queue item to it. just be careful invoking mgos APIs from it, as mgos is not thread-safe. you'll need to use mgos_invoke_cb from your task to interact with mgos. |
I probably only need the following calls to mgos. Is there some reason why it should cause problems?
|
no, those should be fine. |
Maybe i can create high priority RTOS task which would run similar event queue/loop to what mgos uses, but i will only use it for realtime stuff. Maybe this idea might be even generalized and implemented directly in mongoose as some kind of "multiqueue" support. |
yes, that's exactly what i'm suggesting. |
Too baaad, i've already generalized the heck out of it :-) I've came up with relatively elegant and simple (~120 LoC) solution, which offers way to handle tasks with both extremely high and extremely low priority. (extremely medium priority is possible as well of course :-) It looks like this from user perspective: //Configure some basic parameters
pq_handle pqh; //PQH = Parallel Queue Handle
pq_set_defaults(&pqh);
pqh.idle_after_ms = 6000;
pqh.idle_cb = idle_cb;
pqh.idle_cb_arg = "IDLE ARG";
pqh.prio = MGOS_TASK_PRIORITY+1;
//Create new FreeRTOS task running new FreeRTOS queue based event loop very similar to mongoose os
pq_start(&pqh);
//Invoke callback same way the mgos_invoke_cb() does
pq_invoke_cb(&pqh, pq_test_cb, NULL, (void *)"CB ARG", false, false); Benefits when compared to original mongoose event loop:
Drawbacks:
Can i expect some will to adopt this code on the upstream side? Be it as module or integral part of os core... |
I would need to move few mongoose defines (eg. MGOS_TASK_PRIORITY) to header files so i don't have to redefine them in my parallel event loop module, to keep the code compatible with upstream changes. Would you mind looking at it? #554 |
So here is the parallel event loop module i've been talking about: |
What do you think about that pq project? |
I need to use relatively complex code in ESP32 GPIO ISR (to handle complex protocol in time).
But it turned out, i can't just tag everything IRAM_ATTR... It panics and i don't know why.
What is working for me is using mgos_invoke_cb to switch from ISR context to main context, where i can use complex libraries... But i feel like it's slow and other events and timers can mess me up, so i can't handle the communicaton on time. Is there way around this?
mgos_invoke_cb()
currently usesxQueueSendToBackFromISR()
. What if we usedxQueueSendToFrontFromISR()
instead? That way i probably can get more priority over other stuff to be able to handle my communication on time... And get executed ASAP after return from ISR...https://www.freertos.org/xQueueSendToFront.html
The text was updated successfully, but these errors were encountered: