Skip to content

Commit fcd8835

Browse files
committed
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).
1 parent e536676 commit fcd8835

22 files changed

+5
-47
lines changed

main_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ func TestCompiler(t *testing.T) {
171171
case "float.go", "math.go", "print.go":
172172
// Stuck in runtime.printfloat64.
173173

174-
case "goroutines.go":
175-
// The main() never runs.
176-
177174
case "interface.go":
178175
// Several comparison tests fail.
179176

src/runtime/runtime_arm7tdmi.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ var _sidata [0]byte
2828
//go:extern _edata
2929
var _edata [0]byte
3030

31-
func postinit() {}
32-
3331
// Entry point for Go. Initialize all packages and call main.main().
3432
//export main
3533
func main() {

src/runtime/runtime_atsamd21.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313

1414
type timeUnit int64
1515

16-
func postinit() {}
17-
1816
//export Reset_Handler
1917
func main() {
2018
preinit()

src/runtime/runtime_atsamd51.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
type timeUnit int64
1414

15-
func postinit() {}
16-
1715
//export Reset_Handler
1816
func main() {
1917
arm.SCB.CPACR.Set(0) // disable FPU if it is enabled

src/runtime/runtime_avr.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var _ebss [0]byte
4242
//export main
4343
func main() {
4444
preinit()
45+
initHardware()
4546
run()
4647
exit(0)
4748
}
@@ -55,15 +56,13 @@ func preinit() {
5556
}
5657
}
5758

58-
func postinit() {
59-
// Enable interrupts after initialization.
60-
avr.Asm("sei")
61-
}
62-
63-
func init() {
59+
func initHardware() {
6460
initUART()
6561
machine.InitMonotonicTimer()
6662
nextTimerRecalibrate = ticks() + timerRecalibrateInterval
63+
64+
// Enable interrupts after initialization.
65+
avr.Asm("sei")
6766
}
6867

6968
func ticksToNanoseconds(ticks timeUnit) int64 {

src/runtime/runtime_cortexm_qemu.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ type timeUnit int64
1515

1616
var timestamp timeUnit
1717

18-
func postinit() {}
19-
2018
//export Reset_Handler
2119
func main() {
2220
preinit()

src/runtime/runtime_esp32xx.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ func putchar(c byte) {
1414
machine.Serial.WriteByte(c)
1515
}
1616

17-
func postinit() {}
18-
1917
// Initialize .bss: zero-initialized global variables.
2018
// The .data section has already been loaded by the ROM bootloader.
2119
func clearbss() {

src/runtime/runtime_esp8266.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ func putchar(c byte) {
2323
//export rom_i2c_writeReg
2424
func rom_i2c_writeReg(block, host_id, reg_add, data uint8)
2525

26-
func postinit() {}
27-
2826
//export main
2927
func main() {
3028
// Clear .bss section. .data has already been loaded by the ROM bootloader.

src/runtime/runtime_fe310.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616

1717
type timeUnit int64
1818

19-
func postinit() {}
20-
2119
//export main
2220
func main() {
2321
// Zero the PLIC enable bits on startup: they are not zeroed at reset.

src/runtime/runtime_k210.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515

1616
type timeUnit int64
1717

18-
func postinit() {}
19-
2018
//export main
2119
func main() {
2220

0 commit comments

Comments
 (0)