S
S
Sergey2021-08-04 19:26:39
Microcontrollers
Sergey, 2021-08-04 19:26:39

How to write a state machine using RTOS primitives?

What does a state machine look like using a message queue ( event/dispatch queue ) with timer state transition support (deferred event processing), written using RTOS primitives?
If you write traditionally, as for AVR, it seems to me that the easiest way is to use two queues: one for messages with a timer, the other for messages without delays; we process the first one in a timer that ticks at a given frequency (for example, 1 ms), the second one - in an infinite loop. Those. in addition to the KA itself, you need to write two queues, two dispatchers. I assume that in RTOS such things should come out of the box along with the scheduler, but I'm just starting to figure it out, and therefore I don't understand how to make KA concise and beautiful.

Why is CA needed? It's easier for me to formalize thoughts and coordinate behavior with end users, so I just like this architectural technique. If it completely contradicts the ideology of RTOS, as you understand it. I'll be happy to hear other suggestions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tugo, 2021-08-05
@Gryphon88

Google by words

"RTOS name" state machine
.
For example, "freertos state machine"
From what I liked:
https://www.sinelabore.de/doku.php/wiki/howto/rtos
https://stackoverflow.com/questions/46927097/state...

A
Alexander Skusnov, 2021-08-05
@AlexSku

If we take Stateflow (state graph) from MatLab/Simulink, then everything goes according to the timer. There are transitions between states both by a logical condition and by an event.
610b657d5d079515562280.png
The same is embedded in the PLC, it is called a scan: polling inputs, calculations, triggering outputs, network interactions.
Although asynchronous interrupt handling can also be enabled in the PLC, as far as I know, this is only for fast counters, and even then, you need to imagine the consequences.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question