avr: fix time.Sleep() in init code
In the early days of TinyGo, the idea of `postinit` was to enable interrupts only after initializers have run. Which kind of makes sense... except that `time.Sleep` is allowed in init code and `time.Sleep` requires interrupts to be enabled. Therefore, interrupts must be enabled while initializers are being run. This commit simply moves the enabling of interrupts to a point right before running package initializers. It also removes `runtime.postinit`, which is not necessary anymore (and was only used on AVR).
Этот коммит содержится в:
родитель
e536676a67
коммит
fcd88356db
22 изменённых файлов: 5 добавлений и 47 удалений
|
@ -171,9 +171,6 @@ func TestCompiler(t *testing.T) {
|
||||||
case "float.go", "math.go", "print.go":
|
case "float.go", "math.go", "print.go":
|
||||||
// Stuck in runtime.printfloat64.
|
// Stuck in runtime.printfloat64.
|
||||||
|
|
||||||
case "goroutines.go":
|
|
||||||
// The main() never runs.
|
|
||||||
|
|
||||||
case "interface.go":
|
case "interface.go":
|
||||||
// Several comparison tests fail.
|
// Several comparison tests fail.
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ var _sidata [0]byte
|
||||||
//go:extern _edata
|
//go:extern _edata
|
||||||
var _edata [0]byte
|
var _edata [0]byte
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
// Entry point for Go. Initialize all packages and call main.main().
|
// Entry point for Go. Initialize all packages and call main.main().
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -13,8 +13,6 @@ import (
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -12,8 +12,6 @@ import (
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//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
|
||||||
|
|
|
@ -42,6 +42,7 @@ var _ebss [0]byte
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
initHardware()
|
||||||
run()
|
run()
|
||||||
exit(0)
|
exit(0)
|
||||||
}
|
}
|
||||||
|
@ -55,15 +56,13 @@ func preinit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func postinit() {
|
func initHardware() {
|
||||||
// Enable interrupts after initialization.
|
|
||||||
avr.Asm("sei")
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
initUART()
|
initUART()
|
||||||
machine.InitMonotonicTimer()
|
machine.InitMonotonicTimer()
|
||||||
nextTimerRecalibrate = ticks() + timerRecalibrateInterval
|
nextTimerRecalibrate = ticks() + timerRecalibrateInterval
|
||||||
|
|
||||||
|
// Enable interrupts after initialization.
|
||||||
|
avr.Asm("sei")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||||
|
|
|
@ -15,8 +15,6 @@ type timeUnit int64
|
||||||
|
|
||||||
var timestamp timeUnit
|
var timestamp timeUnit
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -14,8 +14,6 @@ func putchar(c byte) {
|
||||||
machine.Serial.WriteByte(c)
|
machine.Serial.WriteByte(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
// 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() {
|
||||||
|
|
|
@ -23,8 +23,6 @@ func putchar(c byte) {
|
||||||
//export rom_i2c_writeReg
|
//export rom_i2c_writeReg
|
||||||
func rom_i2c_writeReg(block, host_id, reg_add, data uint8)
|
func rom_i2c_writeReg(block, host_id, reg_add, data uint8)
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
// Clear .bss section. .data has already been loaded by the ROM bootloader.
|
// Clear .bss section. .data has already been loaded by the ROM bootloader.
|
||||||
|
|
|
@ -16,8 +16,6 @@ import (
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//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.
|
||||||
|
|
|
@ -15,8 +15,6 @@ import (
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@ var _svectors [0]byte
|
||||||
//go:extern _flexram_cfg
|
//go:extern _flexram_cfg
|
||||||
var _flexram_cfg [0]byte
|
var _flexram_cfg [0]byte
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,6 @@ var (
|
||||||
totalHeap = uint64(0)
|
totalHeap = uint64(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
func preinit() {
|
func preinit() {
|
||||||
// Unsafe to use heap here
|
// Unsafe to use heap here
|
||||||
setupEnv()
|
setupEnv()
|
||||||
|
|
|
@ -15,8 +15,6 @@ type timeUnit int64
|
||||||
//go:linkname systemInit SystemInit
|
//go:linkname systemInit SystemInit
|
||||||
func systemInit()
|
func systemInit()
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
if nrf.FPUPresent {
|
if nrf.FPUPresent {
|
||||||
|
|
|
@ -226,8 +226,6 @@ func initInternal() {
|
||||||
// analog_init();
|
// analog_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
func putchar(c byte) {
|
func putchar(c byte) {
|
||||||
machine.PutcharUART(machine.UART0, c)
|
machine.PutcharUART(machine.UART0, c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,6 @@ func init() {
|
||||||
machine.Serial.Configure(machine.UARTConfig{})
|
machine.Serial.Configure(machine.UARTConfig{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -6,8 +6,6 @@ import "device/arm"
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export Reset_Handler
|
//export Reset_Handler
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -15,8 +15,6 @@ type timeUnit int64
|
||||||
|
|
||||||
var timestamp timeUnit
|
var timestamp timeUnit
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export main
|
//export main
|
||||||
func main() {
|
func main() {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -22,8 +22,6 @@ func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (e
|
||||||
//export proc_exit
|
//export proc_exit
|
||||||
func proc_exit(exitcode uint32)
|
func proc_exit(exitcode uint32)
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
putcharBufferSize = 120
|
putcharBufferSize = 120
|
||||||
stdout = 1
|
stdout = 1
|
||||||
|
|
|
@ -65,8 +65,6 @@ type timespec struct {
|
||||||
|
|
||||||
var stackTop uintptr
|
var stackTop uintptr
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
// Entry point for Go. Initialize all packages and call main.main().
|
// Entry point for Go. Initialize all packages and call main.main().
|
||||||
//export main
|
//export main
|
||||||
func main(argc int32, argv *unsafe.Pointer) int {
|
func main(argc int32, argv *unsafe.Pointer) int {
|
||||||
|
|
|
@ -41,8 +41,6 @@ func __p___argc() *int32
|
||||||
//export __p___argv
|
//export __p___argv
|
||||||
func __p___argv() **unsafe.Pointer
|
func __p___argv() **unsafe.Pointer
|
||||||
|
|
||||||
func postinit() {}
|
|
||||||
|
|
||||||
//export mainCRTStartup
|
//export mainCRTStartup
|
||||||
func mainCRTStartup() int {
|
func mainCRTStartup() int {
|
||||||
preinit()
|
preinit()
|
||||||
|
|
|
@ -22,7 +22,6 @@ func run() {
|
||||||
initHeap()
|
initHeap()
|
||||||
go func() {
|
go func() {
|
||||||
initAll()
|
initAll()
|
||||||
postinit()
|
|
||||||
callMain()
|
callMain()
|
||||||
schedulerDone = true
|
schedulerDone = true
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -23,7 +23,6 @@ func getSystemStackPointer() uintptr {
|
||||||
func run() {
|
func run() {
|
||||||
initHeap()
|
initHeap()
|
||||||
initAll()
|
initAll()
|
||||||
postinit()
|
|
||||||
callMain()
|
callMain()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче