tinygo/src/runtime/runtime_fe310_baremetal.go
2022-12-19 23:20:11 +01:00

34 строки
786 Б
Go

//go:build fe310 && !qemu
package runtime
import (
"device/riscv"
)
// ticksToNanoseconds converts RTC ticks (at 32768Hz) 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 / 32768
return int64(ticks) * 1953125 / 64
}
// nanosecondsToTicks converts nanoseconds to RTC ticks (running at 32768Hz).
func nanosecondsToTicks(ns int64) timeUnit {
// The following calculation is actually the following, but with both sides
// reduced to reduce the risk of overflow:
// ns * 32768 / 1e9
return timeUnit(ns * 64 / 1953125)
}
func exit(code int) {
abort()
}
func abort() {
// lock up forever
for {
riscv.Asm("wfi")
}
}