mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +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"
|
||||
|
||||
// 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
|
||||
// package.
|
||||
func initAll()
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
func putchar(c byte) {
|
||||
// dummy, TODO
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export Reset_Handler
|
||||
func main() {
|
||||
preinit()
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export Reset_Handler
|
||||
func main() {
|
||||
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled
|
||||
|
||||
@@ -12,9 +12,6 @@ import (
|
||||
|
||||
const BOARD = "arduino"
|
||||
|
||||
// timeUnit in nanoseconds
|
||||
type timeUnit int64
|
||||
|
||||
// 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
|
||||
// for accurate time keeping.
|
||||
|
||||
@@ -22,8 +22,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export main
|
||||
func main() {
|
||||
// Initialize RTC.
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
var timestamp timeUnit
|
||||
|
||||
//export Reset_Handler
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
// The .data section has already been loaded by the ROM bootloader.
|
||||
func clearbss() {
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
var currentTime timeUnit = 0
|
||||
|
||||
func putchar(c byte) {
|
||||
|
||||
@@ -14,8 +14,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export main
|
||||
func main() {
|
||||
// Zero the PLIC enable bits on startup: they are not zeroed at reset.
|
||||
|
||||
@@ -13,8 +13,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export main
|
||||
func main() {
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
const (
|
||||
lastCycle = SYSTICK_FREQ/1000 - 1
|
||||
cyclesPerMicro = CORE_FREQ / 1000000
|
||||
|
||||
@@ -4,8 +4,6 @@ package runtime
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
const (
|
||||
// Handles
|
||||
infoTypeTotalMemorySize = 6 // Total amount of memory available for process.
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//go:linkname systemInit SystemInit
|
||||
func systemInit()
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//go:linkname systemInit SystemInit
|
||||
func systemInit()
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ func machineTicks() uint64
|
||||
// machineLightSleep is provided by package machine.
|
||||
func machineLightSleep(uint64)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||
func ticks() timeUnit {
|
||||
t := machineTicks()
|
||||
|
||||
@@ -14,8 +14,6 @@ func machineTicks() uint64
|
||||
// machineLightSleep is provided by package machine.
|
||||
func machineLightSleep(uint64)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// ticks returns the number of ticks (microseconds) elapsed since power up.
|
||||
func ticks() timeUnit {
|
||||
t := machineTicks()
|
||||
|
||||
@@ -4,8 +4,6 @@ package runtime
|
||||
|
||||
import "device/arm"
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export Reset_Handler
|
||||
func main() {
|
||||
preinit()
|
||||
|
||||
@@ -11,10 +11,6 @@ import (
|
||||
// This file implements the VirtIO RISC-V interface implemented in QEMU, which
|
||||
// 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
|
||||
func main() {
|
||||
preinit()
|
||||
@@ -61,6 +57,8 @@ func handleInterrupt() {
|
||||
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 {
|
||||
return int64(ticks) * 100 // one tick is 100ns
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
//export main
|
||||
func main() {
|
||||
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
|
||||
// using the time64 variant (see clock_gettime above), so the formats are the
|
||||
// same between 32-bit and 64-bit architectures.
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// libc constructors
|
||||
//
|
||||
//export __wasm_call_ctors
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"internal/cm"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
func init() {
|
||||
wasiclirun.Exports.Run = func() cm.BoolResult {
|
||||
callMain()
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
package runtime
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
var handleEvent func()
|
||||
|
||||
//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
|
||||
// -buildmode=c-shared (and default to it).
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
// libc constructors
|
||||
//
|
||||
//export __wasm_call_ctors
|
||||
@@ -24,9 +22,6 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
||||
return timeUnit(ns)
|
||||
}
|
||||
|
||||
// with the wasm32-unknown-unknown target there is no way to determine any `precision`
|
||||
const timePrecisionNanoseconds = 1000
|
||||
|
||||
func sleepTicks(d timeUnit) {
|
||||
}
|
||||
|
||||
|
||||
@@ -123,8 +123,6 @@ func preinit() {
|
||||
heapEnd = heapStart + heapSize
|
||||
}
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
var stackTop uintptr
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
|
||||
@@ -39,8 +39,6 @@ import (
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
return int64(ticks) * 1000
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user