Commit dddecd86 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement jiffies.

parent 7ae9a9ea
......@@ -22,6 +22,13 @@ func Microseconds() uint64 {
return Now(1000000)
}
// JiffiesPerSec is the LCM of 48000, 96000 and 65536
const JiffiesPerSec = 24576000
func Jiffies() uint64 {
return Now(JiffiesPerSec)
}
var ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
func NTPToTime(ntp uint64) time.Time {
......
......@@ -24,7 +24,7 @@ func differs(a, b, delta uint64) bool {
return a - b >= delta
}
func TestMono(t *testing.T) {
func TestTime(t *testing.T) {
a := Now(48000)
time.Sleep(4 * time.Millisecond)
b := Now(48000) - a
......@@ -38,6 +38,13 @@ func TestMono(t *testing.T) {
if differs(d, 4000, 1000) {
t.Errorf("Expected %v, got %v", 4000, d)
}
c = Jiffies()
time.Sleep(time.Second * 100000 / JiffiesPerSec)
d = Jiffies() - c
if differs(d, 100000, 10000) {
t.Errorf("Expected %v, got %v", 4000, d)
}
}
func TestNTP(t *testing.T) {
......
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