Embedded Software: Everything has an end – Timeouts

Jürgen Welzenbach

09/09/2025

In previous blog posts, I introduced two essential components of a simple and universally applicable software architecture: events with dispatchers, listeners, and data pools. These already make it easy to implement many simple use cases.

But it's rarely easy. When communicating with remote systems (e.g., with a second MCU communicating via UART), timeouts must be repeatedly responded to for safety reasons. This means you have to "wind up" a timer each time and respond accordingly in the timer callback function (which is called when the timer expires). Oh, and if the desired action was successful, don't forget to cancel the timer.

That means a lot of code, plus the necessary error handling and unit tests. And let's be honest: What software developer really wants to do that? I'm honestly way too lazy for that! But what could a minimally labor-intensive solution look like?

Planned delay

The solution is "Delayed Events." The necessary ingredients are:

  1. A delayed event that contains the event to be scheduled at a later time as a payload, along with the timeout time.
  2. A delayed event scheduler: It receives all delayed events and adds them to its internal queue in order of expiration time. A thread simply waits until the timeout of the next delayed event expires.
  3. The delayed event scheduler passes the payload event to the "normal" scheduler after the timeout period has expired.
  4. The delayed event scheduler gets a “cancel” function that removes corresponding timeout events from the queue.

We now have all the important components needed to model even complex, time-dependent processes.

Now some of you might be asking: “How on earth do you model it?” Well, that’s the topic of the next blog post, which deals with the modeling and generation of state machines.

outlook

But here's a (highly simplified) state machine for controlling a defibrillator MCU via a state machine running in the host MCU. The nice thing about this method is that the timeout handling is visualized along with the "good path."

The pattern is always the same: An event with a corresponding delay is "raised" along with the entry action, and it is canceled in the entry action. It doesn't matter whether the state transition occurs due to the Delayed event or another event. In this example, all timeout events lead from the root state to the DefiTimeoutOccured state. If necessary, individual timeouts could, of course, be responded to individually.

Do you need support with designing a software architecture or developing embedded software? Then please contact us. Our experienced MEDtech engineers will be happy to help you develop your medical device or clarify any outstanding questions.


Written by Jürgen Welzenbach

After studying electrical engineering in Erlangen, Jürgen completed his diploma thesis in cooperation with a manufacturer of ophthalmological devices and the University Eye Clinic.

He discovered embedded software in two Erlangen companies and primarily developed HMIs for construction machinery and laboratory analysis devices.


More articles

  • 26/11/2025
  • General, Hardware, Standards, Quality, Testing

Why EMC testing is vital in medical technology: Imagine a patient is lying in the hospital during critical monitoring. Suddenly, a visitor's smartphone rings – and the monitoring device... ...

Read more
  • 20/11/2025
  • General, Hardware, Quality, Technology, Testing

Have you ever considered sourcing inexpensive components from China? The temptation is strong, we know that. And we've already gained some experience, from which I... ...

Read more
  • 13/11/2025
  • General, manufacturing, production, quality, company

In our globalized world, relocating medical technology manufacturing to the Far East seems attractive at first glance: large production capacities and favorable prices. For many years, offshoring has also been ...

Read more
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.