Hardware interview practice
Verify keypad expansion and FIFO draining
Write the ordered-string predictor and transaction plan for a memory-mapped keypad expander with a 16-entry first-in, first-out (FIFO) result queue.
Starting point
Question code
typedef enum { KP_OK, KP_BAD_ARG, KP_HW_ERROR, KP_TIMEOUT } kp_status_t;
kp_status_t keypad_expand(const char *digits, size_t len,
char (*out)[5], size_t out_cap, size_t *out_count,
uint32_t timeout_ticks);
// DIGITS,LENGTH,CONTROL.START,STATUS{BUSY,DONE,ERROR,FIFO_COUNT}
// RESULT_DATA,RESULT_LEN,IRQ_STATUS.DONE,IRQ_CLEARReviewed example
Work through one case
Input
digits="23"Expected output
9 outputs in order: ["ad","ae","af","bd","be","bf","cd","ce","cf"]The 3x3 Cartesian product follows keypad letter order, making the generated stream dictionary ordered.
What to cover
Requirements
- Validate one through four digits from 2 through 9 and calculate the exact output count before MMIO.
- Generate strings in dictionary order using abc through wxyz and drain the 16-entry FIFO while the job is still active.
- Pop exactly one result per accepted data read and publish out_count only after all expected entries and DONE are observed.
- Handle sticky status, busy START rejection, unsigned timer wrap, reset, timeout, and incomplete completion distinctly.
