How do you safely share data between interrupt handlers and tasks while keeping interrupt latency low?
What the interviewer wants to hear
- Keep ISRs short and defer work to tasks
- Use RTOS FromISR queues or task notifications
- Lock-free single-producer single-consumer ring buffers
- Short critical sections only when needed, measured
- Understand atomicity, volatile and memory barriers
- Respect the RTOS max syscall interrupt priority
Model answer
My rule is that ISRs capture data and signal, and tasks do the processing. For low rates I use RTOS queues or task notifications with the FromISR APIs and yield if a higher-priority task woke. For streams like UART or ADC data, I use a single-producer single-consumer ring buffer: only the ISR writes the head, only the task writes the tail, and indices are aligned 32-bit values, so no locks are needed on a single core. Data is written before the index is published, with volatile and barriers where reordering is possible. When a multi-word structure must be updated together, I use a very short critical section, or BASEPRI masking that leaves the highest-priority interrupts running, and I measure how long interrupts are disabled. I also make sure ISRs that call the kernel are at or below the RTOS max syscall priority.
Can you answer it under time pressure?
Take a timed hard round and get scored on every answer.
More hard Embedded Systems Engineer questions
- Design the firmware for a battery-powered sensor that must run for 5 years on a coin cell and report data every 15 minutes.
- How would you secure an IoT device's firmware against tampering and cloning?
- How do you make sure a real-time system always meets its deadlines?
- How do you build a strong automated testing strategy for embedded firmware?
- How do you choose a microcontroller for a new product?
- Design a secure, fail-safe over-the-air firmware update system for a fleet of IoT devices.
- You receive the first prototype of a new custom board. How do you bring it up?
- What changes when you write firmware for a safety-critical product, such as automotive or medical?
- A variable is randomly overwritten in devices running in the field, but you cannot reproduce it on your desk. How do you find the cause?