Hardware interview practice
Build an interrupt-safe sliding-maximum telemetry filter
Build a fixed-memory sliding maximum written by one interrupt service routine (ISR) and read by a task, with bounded retries, wrap-safe sequence ages, newest-equal tie behavior, and atomic publication.
Starting point
Question code
typedef struct { int32_t value; uint32_t seq; } tm_node_t;
typedef struct telemetry_max_ref telemetry_max_ref;
bool telemetry_max_configure(telemetry_max_ref *filter, uint32_t window);
void telemetry_max_isr_push(telemetry_max_ref *filter, int32_t value);
bool telemetry_max_read(const telemetry_max_ref *filter,
int32_t *maximum, uint32_t *maximum_seq);Reviewed example
Work through one case
Input
window=3; ISR samples by sequence=[4,2,5,5]Expected output
published maxima=[4,4,5,5]; newest equal maximum is the final 5Removing older values less than or equal to each new sample keeps the deque decreasing and gives equal values newest-wins behavior.
What to cover
Requirements
- Initialization accepts windows 1 through 64, publishes window last, and leaves the object unchanged after invalid reconfiguration.
- Maintain a decreasing queue, remove older values less than or equal to the new sample, and expire by unsigned sequence age.
- Publish full, maximum, and sequence between odd and even generation values using release semantics.
- A reader uses acquire loads, accepts only the same even generation before and after, tries at most three snapshots, and preserves outputs on every failure.
