A PTP slave locks to its master, and yet it stays 40 ns away. The log says only that. Find the first bad cycle and the cause.
Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.
The design below is a PTP slave port. It uses the delay request-response mechanism.
It reads Sync, Follow_Up and Delay_Resp messages as octets and is told when its own Delay_Req has left.
After each Delay_Resp it gives the meanPathDelay and the offsetFromMaster in nanoseconds.
In the bench the master sends a two-step Sync eight times a second. Its Sync carries a rough origin time, 80 ns early.
Two transparent clocks sit on the path. Each holds a message for 80 ns.
The first one adds its 80 ns to the correctionField of the Sync. The second one reports its 80 ns in the Follow_Up.
Both add to the Delay_Req on the way up. The master copies that sum into the Delay_Resp.
The cable takes 540 ns down and 460 ns up. The port is told its delayAsymmetry: 40 ns.
After each exchange the bench steps the slave's clock by the measured offset.
The log says: ERROR: after 8 exchanges the slave is still 40 ns from the master.
Step 1: find the first cycle where a signal differs from a correct design, and name the signal.
A cycle is one message. Cycle 1 is the first Sync, cycle 2 its Follow_Up, cycle 3 the Delay_Req, cycle 4 the Delay_Resp.
Step 2: choose the cause from five bugs. Each is real, and each one ends in this same log line.
Step 3 is optional: fix the design and run the tests.
This design is a model. It works in whole nanoseconds, and the bench hands it timestamps, not frames.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
test_number | 8 | input of each check |
Full specification
function automatic void ptp_reset(input longint asym, input [79:0] port);
function automatic [63:0] ptp_req_corr(); // the correctionField for the next Delay_Req
function automatic void ptp_req_sent(input [15:0] seq, input [79:0] ts_out);
function automatic void ptp_rx(input [431:0] msg, input [79:0] ts_in); // one received message
| Item | Rule |
|---|---|
| Message | 54 octets, octet 0 in bits 431:424. A field goes most significant octet first. A shorter message ends in zeros |
| Header | messageType: the low four bits of octet 0. In the tests its upper four bits are 0, and domainNumber is 0. flagField at offset 6: bit 1 of its first octet is twoStepFlag. correctionField: 8 octets at offset 8. sourcePortIdentity: 10 octets at 20. sequenceId: 2 octets at 30 (Table 35) |
| Types | 0 Sync, 8 Follow_Up, 9 Delay_Resp. Every other type changes nothing in this model (Table 36) |
| Body | a timestamp of 10 octets at offset 34. It is the originTimestamp of a Sync, the preciseOriginTimestamp of a Follow_Up and the receiveTimestamp of a Delay_Resp. A Delay_Resp also has the requestingPortIdentity at 44 (Tables 44 to 46) |
| Timestamp | {seconds[47:0], nanoseconds[31:0]}. In the tests the seconds stay below 2^31, so a time fits in 64 bits of ns |
| correctionField | signed, in 1/65,536 ns (13.3.2.9). Course choice of the model: each correctionField is turned into whole ns by itself. Its fraction is dropped toward minus infinity. The fields are added after that |
| One-step Sync | twoStepFlag 0. It is ready at once: its originTimestamp is t1, ts_in is t2. There is no Follow_Up correction |
| Two-step Sync | twoStepFlag 1. It waits for its Follow_Up. Until then the Sync in use stays as it was |
| Follow_Up | it belongs to the waiting Sync if the sourcePortIdentity and the sequenceId are the same (9.5.5). Then the Sync is ready: t1 is the preciseOriginTimestamp, t2 is the arrival time of the Sync |
| A newer Sync | course choice (9.5.5 allows any prior Sync): the port keeps only the newest waiting Sync. A newer Sync replaces one that still waits. A one-step Sync also ends the waiting |
ptp_req_corr | the delayAsymmetry is taken off the correctionField of a Delay_Req before it leaves (11.3.2 c). The field starts at 0 |
| Delay_Resp | it belongs to the Delay_Req on its way if the sequenceId is the same and the requestingPortIdentity is this port (9.5.7). It is used once, and only if a Sync is ready |
| meanPathDelay | as 11.3.2 e) gives it. The delayAsymmetry is added to the correction of the Sync (11.2 a). Course choice: the half is rounded toward minus infinity |
| offsetFromMaster | as 11.2 c) gives it, with that meanPathDelay |
| Results | course choice: both are made at each Delay_Resp that is used, from the Sync that is ready then. valid is 1 from the first one on |
| One master | course choice: the port takes a Sync or a Delay_Resp from any source. The random tests send some Syncs from other clocks |
| Reset | ptp_reset clears everything: no Sync ready or waiting, no Delay_Req on its way, results 0, valid 0 |
The clause and table numbers are those of IEEE Std 1588-2019.
Random tests compare every output with a private model after every event.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
One Two-Step Exchange- Input
the slave is 1,500,000 ns ahead; 500 ns each way
- Output
offset_ns = 1500000, mean_delay_ns = 500, times_a_result_changed = 1, check_of_every_event = 0x16eaa5
t2 − t1 is 1,500,500 ns and t4 − t3 is −1,499,500 ns. Half their sum is the delay, 500 ns. The offset is 1,500,500 − 500.
Example 2
The Bench's Exchange- Input
delayAsymmetry 40 ns, and all the corrections of the bench
- Output
offset_ns = 1508000, mean_delay_ns = 500, times_a_result_changed = 1, check_of_every_event = 0x4a765d
The corrections of the way down are 80 + 80 + 40 ns. The Delay_Resp carries 160 − 40 ns. The delay comes out as 500 ns and the offset as the true 1,508,000 ns.
Example 3
One One-Step Exchange- Input
the slave is 250 ns behind; 3,000 ns of residence time in the Sync
- Output
offset_ns = -250, mean_delay_ns = 500, times_a_result_changed = 1, check_of_every_event = 0xfff6c3
The Sync itself carries the exact time and the 3,000 ns. No Follow_Up comes. The offset is −250 ns.
Constraints and Contract
- Keep the four functions with their arguments.
- Keep the names
offset,mean_delayandvalid: the fixture reads them. ptp_resetmust clear all state.- Off limits: the names
ref_s,rng,tb,root, names that begin withfx_and the modules of the bench.
Hints
Hint 1
The log gives the size of the error. Which numbers of the bench are twice that size?
Hint 2
Follow one exchange. For each stored value, ask which message should have set it last.
Hint 3
A two-step master sends its time twice. Which copy does the standard tell the slave to use?
What the grader checks: The failing run is simulated live with the faulty design. The first bad cycle and each option's symptom come from runs of each version on the same bench. The fix is checked on 41 scripted runs, with expected values from a JavaScript model. Each folds the outputs after every event into a check value. Eight more tests compare every output with a private model after every event, on random runs seeded for each submission. Two of them put a near miss in front of each Follow_Up and each Delay_Resp, one bit at a time. In four of them a few exchanges have a precise origin of exactly zero, or one on a whole second. The private model is written in another way than the solution and agrees with the JavaScript model on random scripts. This design is a model in whole nanoseconds with one master. The servo, the timestamping hardware, the Announce messages and the peer delay mechanism are not graded.
49 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone