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).
This commit is contained in:
Ayke van Laethem
2022-01-01 22:54:29 +01:00
committed by Ayke
parent e536676a67
commit fcd88356db
22 changed files with 5 additions and 47 deletions
+5 -6
View File
@@ -42,6 +42,7 @@ var _ebss [0]byte
//export main
func main() {
preinit()
initHardware()
run()
exit(0)
}
@@ -55,15 +56,13 @@ func preinit() {
}
}
func postinit() {
// Enable interrupts after initialization.
avr.Asm("sei")
}
func init() {
func initHardware() {
initUART()
machine.InitMonotonicTimer()
nextTimerRecalibrate = ticks() + timerRecalibrateInterval
// Enable interrupts after initialization.
avr.Asm("sei")
}
func ticksToNanoseconds(ticks timeUnit) int64 {