Q196FreeFirmware
Calculate lane deskew tap settings
Interview prompt
Question
Eight received lanes have measured arrival times. Each programmable tap adds 20 ps, with a maximum setting of 31. Write a C function that aligns every lane to the latest arrival without making any lane early. Target C implementations have a 32-bit int. The taps and aligned_ps output storage must not overlap; arrivals remain stable until read. Staging permits an arrival array to alias aligned_ps.
Candidate starting point
Implementation scaffold
#include <limits.h>
#include <stdint.h>
int deskew(const int arrival_ps[8], uint8_t taps[8], int aligned_ps[8]) {
// Implement here: validate, compute staged taps/aligned times and publish.
}Reviewed example
Trace one case
Input
arrival_ps={100,120,120,120,120,120,120,120}.Expected output
taps={1,0,0,0,0,0,0,0} and aligned_ps is 120 for every lane.The latest arrival is 120 ps; the first lane needs ceil((120-100)/20)=1 tap and every other lane needs zero.
What to cover
Requirements
- Require all pointers and require each arrival_ps[i]>=0; return -1 and preserve outputs otherwise.
- Let target be the largest arrival. For each lane choose taps=ceil((target-arrival)/20).
- Reject with -1 and preserve outputs if any tap count exceeds 31 or an aligned time cannot be represented in int; otherwise aligned=arrival+20*taps.
- On success every aligned time must be in target through target+19 ps, write all outputs, and return 0.
