Browse Source

Add timer offset support

development
Andrej Rosano 2 months ago
parent
commit
cc16beda7e
  1. 2
      arm/arm.go
  2. 9
      arm/timer.go
  3. 2
      soc/bcm2835/bcm2835.go
  4. 2
      soc/imx6/imx6.go

2
arm/arm.go

@ -48,6 +48,8 @@ type CPU struct {
// timer multiplier
TimerMultiplier int64
// timer offset in nanoseconds
TimerOffset int64
// timer function
TimerFn func() int64
}

9
arm/timer.go

@ -80,3 +80,12 @@ func (cpu *CPU) InitGenericTimers(base uint32, freq int32) {
cpu.TimerMultiplier = int64(refFreq / timerFreq)
cpu.TimerFn = read_cntpct
}
// SetTimerOffset sets the timer offset in nanoseconds.
func (cpu *CPU) SetTimerOffset(offset int64) {
if cpu.TimerFn == nil || cpu.TimerMultiplier == 0 {
return
}
cpu.TimerOffset = offset - int64(cpu.TimerFn()*cpu.TimerMultiplier)
}

2
soc/bcm2835/bcm2835.go

@ -39,7 +39,7 @@ var ramStackOffset uint32 = 0x100000 // 1 MB
//go:linkname nanotime1 runtime.nanotime1
func nanotime1() int64 {
return read_systimer() * ARM.TimerMultiplier
return read_systimer() * ARM.TimerMultiplier + ARM.TimerOffset
}
// Init takes care of the lower level SoC initialization triggered early in

2
soc/imx6/imx6.go

@ -63,7 +63,7 @@ var ARM = &arm.CPU{}
//go:linkname nanotime1 runtime.nanotime1
func nanotime1() int64 {
return int64(ARM.TimerFn() * ARM.TimerMultiplier)
return int64(ARM.TimerFn() * ARM.TimerMultiplier + ARM.TimerOffset)
}
// Init takes care of the lower level SoC initialization triggered early in

Loading…
Cancel
Save