github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/runtime_fe310_baremetal.go (about) 1 //go:build fe310 && !qemu 2 3 package runtime 4 5 import ( 6 "device/riscv" 7 ) 8 9 // ticksToNanoseconds converts RTC ticks (at 32768Hz) to nanoseconds. 10 func ticksToNanoseconds(ticks timeUnit) int64 { 11 // The following calculation is actually the following, but with both sides 12 // reduced to reduce the risk of overflow: 13 // ticks * 1e9 / 32768 14 return int64(ticks) * 1953125 / 64 15 } 16 17 // nanosecondsToTicks converts nanoseconds to RTC ticks (running at 32768Hz). 18 func nanosecondsToTicks(ns int64) timeUnit { 19 // The following calculation is actually the following, but with both sides 20 // reduced to reduce the risk of overflow: 21 // ns * 32768 / 1e9 22 return timeUnit(ns * 64 / 1953125) 23 } 24 25 func exit(code int) { 26 abort() 27 } 28 29 func abort() { 30 // lock up forever 31 for { 32 riscv.Asm("wfi") 33 } 34 }