Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ994
Page ↗
Q994FWMetaASIC interview problem

Bounded MMIO polling helper

TechniquesFWMMIOCTimeout
DifficultyMedium
TopicFirmware
LanguageC
Requirements4 checkpoints
01

Problem

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.

Starting declarationC
int wait_mask(volatile uint32_t *reg, uint32_t mask,
              uint32_t expected, uint32_t max_reads);

Example input and output

Use this case to check your interpretation
Input
mask=0x0F, expected=0x05, max_reads=3; register samples are 0x01, 0x04, 0x15
Output
Return 0 after exactly three volatile reads
Explanation

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

02

Requirements (4)

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