I’m writing a linux-based app using posix timers (not FreeRTOS) but I believe the approach to this problem should be similar to how it’d have been done in FreeRTOS. Feel free to delete this question if it violates any rules. Apologies in advance but any help is greatly appreciated.
The idea is there’s an app that needs to send certain commands over UART every specific intervals. For instance,
<CMD-A> needs to be sent every X seconds whereas
<CMD-B> every Y seconds.
My initial thought was having a timer for each command (via
timer_create()) and setting the expiry/reload time accordingly. So if I have 5 different commands, I’d have 5 different timers that would invoke a callback within a new thread every expiry time, and the callback sends the passed-in command over to serial port.
I have a couple questions:
- Would it sound feasible to have timers instantiated for each command? Say,
<CMD_A>every X seconds whereas
<CMD_B>every Y seconds. This way these two timers are independently invoking a callback that sends a corresponding command over to serial port. Are there better ways around it? Could I really make it work with a single timer? I have been able to run it fine on my end but i’m uncertain of consequences as I scale up the app.
- Given I could have timer for each function, in what scenario would it make sense to have timers defined inside respective threads?