mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 10:43:29 +00:00
runtime: move timeUnit to a single place
The timeUnit is now the same type everywhere. Move it to a single place and add some documentation to it.
This commit is contained in:
committed by
Ron Evans
parent
abc373dc73
commit
41e501aaf4
@@ -8,6 +8,17 @@ import (
|
|||||||
|
|
||||||
const Compiler = "tinygo"
|
const Compiler = "tinygo"
|
||||||
|
|
||||||
|
// Unit for the 'ticks' and 'sleepTicks' functions.
|
||||||
|
//
|
||||||
|
// This is the native time unit for the given system. One timeUnit tick might be
|
||||||
|
// 1ns or 100ns on a desktop system, or 1/32768s on baremetal systems with a
|
||||||
|
// low-power RTC. Many other tick durations are possible.
|
||||||
|
//
|
||||||
|
// Conversion from time units to nanoseconds and back is done using
|
||||||
|
// ticksToNanoseconds and nanosecondsToTicks, which need to be implemented for
|
||||||
|
// each system as needed.
|
||||||
|
type timeUnit int64
|
||||||
|
|
||||||
// The compiler will fill this with calls to the initialization function of each
|
// The compiler will fill this with calls to the initialization function of each
|
||||||
// package.
|
// package.
|
||||||
func initAll()
|
func initAll()
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
// dummy, TODO
|
// dummy, TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
|
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ import (
|
|||||||
|
|
||||||
const BOARD = "arduino"
|
const BOARD = "arduino"
|
||||||
|
|
||||||
// timeUnit in nanoseconds
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// Watchdog timer periods. These can be off by a large margin (hence the jump
|
// Watchdog timer periods. These can be off by a large margin (hence the jump
|
||||||
// between 64ms and 125ms which is not an exact double), so don't rely on this
|
// between 64ms and 125ms which is not an exact double), so don't rely on this
|
||||||
// for accurate time keeping.
|
// for accurate time keeping.
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
// Initialize RTC.
|
// Initialize RTC.
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
var timestamp timeUnit
|
var timestamp timeUnit
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// Initialize .bss: zero-initialized global variables.
|
// Initialize .bss: zero-initialized global variables.
|
||||||
// The .data section has already been loaded by the ROM bootloader.
|
// The .data section has already been loaded by the ROM bootloader.
|
||||||
func clearbss() {
|
func clearbss() {
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
var currentTime timeUnit = 0
|
var currentTime timeUnit = 0
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
// Zero the PLIC enable bits on startup: they are not zeroed at reset.
|
// Zero the PLIC enable bits on startup: they are not zeroed at reset.
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
lastCycle = SYSTICK_FREQ/1000 - 1
|
lastCycle = SYSTICK_FREQ/1000 - 1
|
||||||
cyclesPerMicro = CORE_FREQ / 1000000
|
cyclesPerMicro = CORE_FREQ / 1000000
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ package runtime
|
|||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Handles
|
// Handles
|
||||||
infoTypeTotalMemorySize = 6 // Total amount of memory available for process.
|
infoTypeTotalMemorySize = 6 // Total amount of memory available for process.
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//go:linkname systemInit SystemInit
|
//go:linkname systemInit SystemInit
|
||||||
func systemInit()
|
func systemInit()
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//go:linkname systemInit SystemInit
|
//go:linkname systemInit SystemInit
|
||||||
func systemInit()
|
func systemInit()
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ func machineTicks() uint64
|
|||||||
// machineLightSleep is provided by package machine.
|
// machineLightSleep is provided by package machine.
|
||||||
func machineLightSleep(uint64)
|
func machineLightSleep(uint64)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||||
func ticks() timeUnit {
|
func ticks() timeUnit {
|
||||||
t := machineTicks()
|
t := machineTicks()
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ func machineTicks() uint64
|
|||||||
// machineLightSleep is provided by package machine.
|
// machineLightSleep is provided by package machine.
|
||||||
func machineLightSleep(uint64)
|
func machineLightSleep(uint64)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||||
func ticks() timeUnit {
|
func ticks() timeUnit {
|
||||||
t := machineTicks()
|
t := machineTicks()
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ package runtime
|
|||||||
|
|
||||||
import "device/arm"
|
import "device/arm"
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ import (
|
|||||||
// This file implements the VirtIO RISC-V interface implemented in QEMU, which
|
// This file implements the VirtIO RISC-V interface implemented in QEMU, which
|
||||||
// is an interface designed for emulation.
|
// is an interface designed for emulation.
|
||||||
|
|
||||||
// One tick is 100ns by default in QEMU.
|
|
||||||
// (This is not a standard, just the default used by QEMU).
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
@@ -61,6 +57,8 @@ func handleInterrupt() {
|
|||||||
riscv.MCAUSE.Set(0)
|
riscv.MCAUSE.Set(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// One tick is 100ns by default in QEMU.
|
||||||
|
// (This is not a standard, just the default used by QEMU).
|
||||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
return int64(ticks) * 100 // one tick is 100ns
|
return int64(ticks) * 100 // one tick is 100ns
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ func clock_gettime(clk_id int32, ts *timespec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// Note: tv_sec and tv_nsec normally vary in size by platform. However, we're
|
// Note: tv_sec and tv_nsec normally vary in size by platform. However, we're
|
||||||
// using the time64 variant (see clock_gettime above), so the formats are the
|
// using the time64 variant (see clock_gettime above), so the formats are the
|
||||||
// same between 32-bit and 64-bit architectures.
|
// same between 32-bit and 64-bit architectures.
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// libc constructors
|
// libc constructors
|
||||||
//
|
//
|
||||||
//export __wasm_call_ctors
|
//export __wasm_call_ctors
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import (
|
|||||||
"internal/cm"
|
"internal/cm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
wasiclirun.Exports.Run = func() cm.BoolResult {
|
wasiclirun.Exports.Run = func() cm.BoolResult {
|
||||||
callMain()
|
callMain()
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
var handleEvent func()
|
var handleEvent func()
|
||||||
|
|
||||||
//go:linkname setEventHandler syscall/js.setEventHandler
|
//go:linkname setEventHandler syscall/js.setEventHandler
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ package runtime
|
|||||||
// TODO: this is essentially reactor mode wasm. So we might want to support
|
// TODO: this is essentially reactor mode wasm. So we might want to support
|
||||||
// -buildmode=c-shared (and default to it).
|
// -buildmode=c-shared (and default to it).
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
// libc constructors
|
// libc constructors
|
||||||
//
|
//
|
||||||
//export __wasm_call_ctors
|
//export __wasm_call_ctors
|
||||||
@@ -24,9 +22,6 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
|||||||
return timeUnit(ns)
|
return timeUnit(ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// with the wasm32-unknown-unknown target there is no way to determine any `precision`
|
|
||||||
const timePrecisionNanoseconds = 1000
|
|
||||||
|
|
||||||
func sleepTicks(d timeUnit) {
|
func sleepTicks(d timeUnit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ func preinit() {
|
|||||||
heapEnd = heapStart + heapSize
|
heapEnd = heapStart + heapSize
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
var stackTop uintptr
|
var stackTop uintptr
|
||||||
|
|
||||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ import (
|
|||||||
"runtime/volatile"
|
"runtime/volatile"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeUnit int64
|
|
||||||
|
|
||||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
return int64(ticks) * 1000
|
return int64(ticks) * 1000
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user