Commit d7c37209 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

hdl/sim/timestamp.svh: nanoseconds to counters conversion bugfix

parent c1a51eb0
`ifndef __TIMESTAMP_SVH
`define __TIMESTAMP_SVH
class Timestamp;
`include "wb/simdrv_defs.svh"
int utc, coarse, frac, coarse_range, seq_id;
class Timestamp;
uint64_t utc;
int coarse, frac, coarse_range, seq_id, source;
function new(int _utc=0 ,int _coarse=0, int _frac=0,int _seq_id = 0, int _coarse_range = 256);
function new(int _utc=0 ,int _coarse=0, int _frac=0,int _seq_id = 0, int _coarse_range = 125000000);
utc = _utc;
coarse = _coarse;
frac = _frac;
coarse_range = _coarse_range;
seq_id = _seq_id;
source = 0;
endfunction // new
function real flatten();
......@@ -25,20 +28,41 @@ class Timestamp;
frac = x % 4096;
x = x - frac;
x = x/4096;
coarse = x % 256;
coarse = x % coarse_range;
x = x - coarse;
x = x/256;
x = x/coarse_range;
utc = x;
$display("Unflat: %d %d %d %d", t, utc, coarse, frac);
endtask // unflatten
function Timestamp sub(Timestamp b);
function Timestamp add(Timestamp b);
Timestamp r = new;
r.frac = frac+b.frac;
r.coarse = coarse + b.coarse;
r.utc = utc + b.utc;
if(r.frac >= 4096)
begin
r.frac -= 4096;
r.coarse++;
end
if(r.coarse >= coarse_range)
begin
r.utc ++;
r.coarse -= coarse_range;
end
return r;
endfunction
endclass
`endif // `ifndef __TIMESTAMP_SVH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment