Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Bounded MMIO polling helper

Hardware interview practice

Bounded MMIO polling helper

MediumFirmwareC

Firmware must wait for selected status bits without hanging forever or optimizing away device reads. Implement a C helper with exact validation, read-count, match, and timeout behavior.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

int wait_mask(volatile uint32_t *reg, uint32_t mask,
              uint32_t expected, uint32_t max_reads);
Reviewed example

Work through one case

Input
mask=0x0F, expected=0x05, max_reads=3; register samples are 0x01, 0x04, 0x15
Expected output
Return 0 after exactly three volatile reads

The first two masked samples do not equal 0x05; the third gives 0x15 & 0x0F = 0x05.

What to cover

Requirements

  1. If reg is null or expected contains a 1 outside mask, return -EINVAL without reading reg.
  2. Otherwise perform at most max_reads volatile reads, one per iteration, and return 0 on the first value where (value & mask) equals expected.
  3. If no read matches, return -ETIMEDOUT; max_reads=0 performs no read and returns -ETIMEDOUT.
  4. Do not modify the register or arguments, and do not loop beyond the supplied bound.
Continue practicing

Related questions

FirmwareRead a changing MMIO register→
asic.fyi · Learn silicon end to end.info@asic.fyi