add support for CPU interrupts for ESP32-C3

This commit is contained in:
Dmitriy
2021-10-22 21:13:24 -04:00
committed by Ayke
parent b5b2600b7b
commit 43efe94041
5 changed files with 167 additions and 1 deletions
+30
View File
@@ -5,6 +5,8 @@ package runtime
import (
"device/esp"
"device/riscv"
"runtime/volatile"
"unsafe"
)
// This is the function called on startup after the flash (IROM/DROM) is
@@ -47,6 +49,9 @@ func main() {
clearbss()
// Configure interrupt handler
interruptInit()
// Initialize main system timer used for time.Now.
initTimer()
@@ -63,3 +68,28 @@ func abort() {
riscv.Asm("wfi")
}
}
// interruptInit initialize the interrupt controller and called from runtime once.
func interruptInit() {
mie := riscv.DisableInterrupts()
// Reset all interrupt source priorities to zero.
priReg := &esp.INTERRUPT_CORE0.CPU_INT_PRI_1
for i := 0; i < 31; i++ {
priReg.Set(0)
priReg = (*volatile.Register32)(unsafe.Pointer(uintptr(unsafe.Pointer(priReg)) + uintptr(4)))
}
// default threshold for interrupts is 5
esp.INTERRUPT_CORE0.CPU_INT_THRESH.Set(5)
// Set the interrupt address.
// Set MODE field to 1 - a vector base address (only supported by ESP32C3)
// Note that this address must be aligned to 256 bytes.
riscv.MTVEC.Set((uintptr(unsafe.Pointer(&_vector_table))) | 1)
riscv.EnableInterrupts(mie)
}
//go:extern _vector_table
var _vector_table [0]uintptr