//go:build esp32s3 package runtime import ( "device/esp" "machine" "runtime/interrupt" "runtime/volatile" "unsafe" ) //type timeUnit int64 func putchar(c byte) { machine.Serial.WriteByte(c) } func getchar() byte { for machine.Serial.Buffered() == 0 { Gosched() } v, _ := machine.Serial.ReadByte() return v } func buffered() int { return machine.Serial.Buffered() } // Initialize .bss: zero-initialized global variables. // The .data section has already been loaded by the ROM bootloader. func clearbss() { ptr := unsafe.Pointer(&_sbss) for ptr != unsafe.Pointer(&_ebss) { *(*uint32)(ptr) = 0 ptr = unsafe.Add(ptr, 4) } } func initTimer() { // Configure timer 0 in timer group 0, for timekeeping. // EN: Enable the timer. // INCREASE: Count up every tick (as opposed to counting down). // DIVIDER: 16-bit prescaler, set to 2 for dividing the APB clock by two // (40MHz). // esp.TIMG0.T0CONFIG.Set(0 << esp.TIMG_T0CONFIG_T0_EN_Pos) esp.TIMG0.T0CONFIG.Set(esp.TIMG_TCONFIG_EN | esp.TIMG_TCONFIG_INCREASE | 2<> 32)) // Enable the alarm (auto-clears when alarm fires). esp.TIMG0.T0CONFIG.SetBits(esp.TIMG_TCONFIG_ALARM_EN) // Re-enable the timer interrupt (handler disables INT_ENA). esp.TIMG0.INT_CLR_TIMERS.Set(1) esp.TIMG0.INT_ENA_TIMERS.SetBits(1) // Wait for any interrupt (timer alarm or other) or timeout. for interruptPending.Get() == 0 { if ticks() >= target { return } } } } func exit(code int) { abort() }