Interrupt Latency Counter

Medium C Timing Asked at Infineon
Solve this problem

Measure worst-case interrupt latency using a free-running hardware counter. Record the maximum gap between the hardware event timestamp and the moment the ISR body starts.

Constraints

  • `void isr_entry(uint32_t event_ts)` is called at the top of the ISR.
  • `uint32_t worst_latency(void)` returns the maximum observed latency in ticks.
  • The counter is 32-bit and wraps; wrap-around must not produce a bogus huge value.
  • Use the provided `uint32_t read_counter(void)`.
  • No 64-bit arithmetic.
Starter codeC
1#include <stdint.h>2 3extern uint32_t read_counter(void);4 5void isr_entry(uint32_t event_ts);6uint32_t worst_latency(void);