IO4: Reliable firmware: interrupts, RTOS tasks, watchdogs and safe state

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

RTOS tasks, queues and priorities

🎯You'll be able to

Explain how a real-time operating system runs tasks, and use queues and mutexes to share work safely.

🏠The everyday picture

A small restaurant has a cook, a waiter and a cashier. Each has their own job; orders pass on slips. If two people need the one knife, they take turns.

📘What it really is

📝A worked example

Input: a device with a sensor task (every second) and a network task (every minute) that both use the I2C bus.

Steps:

  1. Give the sensor task a higher priority so readings stay on schedule.
  2. Put readings in a queue; the network task sends a batch each minute.
  3. Protect the I2C bus with a mutex, held only for each transaction.

Expected output: a design where a slow network doesn't delay readings and the bus isn't used by two tasks at once.

🌍Where it's used

📝Case scenario

A device froze once a week. Two tasks each took one mutex and waited for the other's. Rewriting both to take the mutexes in the same order removed the deadlock.

🖱️Try it

Sketch JalSetu as three RTOS tasks (sensor, storage, network). Draw the queues between them and mark any shared resource that needs a mutex. Success: a diagram with at least one queue and one mutex.

⚠️Common mistakes

🛠️For your project

JalSetu's practice firmware runs one task per wake; the capstone design notes ask whether you'd use an RTOS on a real board.

✅Quick check

What does "real-time" mean in an RTOS?

Show the answer

Predictably on time, not simply fast.

How should two RTOS tasks pass readings to each other?

Show the answer

Through a queue.

← PreviousInterrupts: reacting on time
ProLearners Assist