Hardware interview practice
Predict and safely read a build-tag prefix service
Write the reference predictor and safe firmware transaction sequence for a memory-mapped I/O (MMIO) service that returns the longest common byte prefix of up to eight bounded build tags.
Starting point
Question code
typedef enum { LCP_OK, LCP_BAD_ARG, LCP_HW_ERROR, LCP_TIMEOUT } lcp_status_t;
lcp_status_t lcp_run(const char tag[8][16], const uint8_t len[8],
uint8_t count, char out[17], uint8_t *out_len);
// TAG_SEL, TAG_DATA, TAG_LEN[0:7], COUNT
// CMD{START,ABORT}, STATUS{BUSY,DONE,ERR}, RESULT_LEN, RESULT_DATAReviewed example
Work through one case
Input
tags=["asic-fyi","asic-flow","asic"], lengths=[8,9,4]Expected output
RESULT_LEN=4; firmware output="asic\0"All three byte strings match through index 3 and the shortest tag ends there; only firmware appends the terminator.
What to cover
Requirements
- Validate pointers, count 1 through 8, and active lengths 0 through 16 before any register access.
- Write each selected tag and length in order; START must snapshot the programmed inputs.
- Read exactly RESULT_LEN bytes, reject a result length above 16, and append one firmware-only terminator.
- Give ERR priority over DONE and preserve both caller outputs after hardware error, timeout, abort, or reset.
