threads in FSM

Hey everyone,

I’m an electronics engineer who has recently found myself diving deep into embedded programming at work (our embedded programmer is on maternity leave, so we’ll let her off the hook for now! 😊).

The device I’m working on uses RTOS and implements a finite state machine (FSM) to manage multiple states. Some states involve lengthy logic, and I wish I could use blocking mechanisms—for example, turning something on, waiting 5 seconds for a response, and if no response is received, returning a failure.

Currently, there’s a single thread running the FSM, and all the logic resides within it. The current design is legacy code that our current embedded programmer didn’t originally implement. She’s open to changes, and I have the freedom to rework it to make it more suitable.

I’m trying to figure out the best way to handle this. Should I:

  1. Start a separate thread for the more complex states?
  2. Keep everything within the FSM and strictly avoid blocking mechanisms?

I’d really appreciate any advice, best practices, or literature recommendations you might have!

Thanks in advance!