blob: ad60913c83fcb5ada805a11480ba5796c3a89b75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//go:build k210 && !qemu
package runtime
import (
"device/riscv"
)
// ticksToNanoseconds converts CPU ticks to nanoseconds.
func ticksToNanoseconds(ticks timeUnit) int64 {
// The following calculation is actually the following, but with both sides
// reduced to reduce the risk of overflow:
// ticks * 1e9 / (390000000 / 50)
// 50 is the CLINT divider and 390000000 is the CPU frequency.
return int64(ticks) * 5000 / 39
}
// nanosecondsToTicks converts nanoseconds to CPU ticks.
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns * 39 / 5000)
}
func exit(code int) {
abort()
}
func abort() {
// lock up forever
for {
riscv.Asm("wfi")
}
}
|