github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/runtime_k210_baremetal.go (about) 1 //go:build k210 && !qemu 2 3 package runtime 4 5 import ( 6 "device/riscv" 7 ) 8 9 // ticksToNanoseconds converts CPU ticks 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 / (390000000 / 50) 14 // 50 is the CLINT divider and 390000000 is the CPU frequency. 15 return int64(ticks) * 5000 / 39 16 } 17 18 // nanosecondsToTicks converts nanoseconds to CPU ticks. 19 func nanosecondsToTicks(ns int64) timeUnit { 20 return timeUnit(ns * 39 / 5000) 21 } 22 23 func exit(code int) { 24 abort() 25 } 26 27 func abort() { 28 // lock up forever 29 for { 30 riscv.Asm("wfi") 31 } 32 }