mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
WIP: interrupt API
This commit is contained in:
@@ -260,6 +260,7 @@ func writeGo(outdir string, device *Device) error {
|
||||
package {{.pkgName}}
|
||||
|
||||
import (
|
||||
"runtime/interrupt"
|
||||
"runtime/volatile"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -277,6 +278,12 @@ const ({{range .interrupts}}
|
||||
IRQ_max = {{.interruptMax}} // Highest interrupt number on this device.
|
||||
)
|
||||
|
||||
// Map interrupt numbers to function names.
|
||||
// These aren't real calls, they're removed by the compiler.
|
||||
var ({{range .interrupts}}
|
||||
_ = interrupt.Register(IRQ_{{.Name}}, "__vector_{{.Name}}"){{end}}
|
||||
)
|
||||
|
||||
// Peripherals.
|
||||
var ({{range .peripherals}}
|
||||
// {{.Caption}}
|
||||
|
||||
@@ -82,6 +82,7 @@ type Device struct {
|
||||
|
||||
type interrupt struct {
|
||||
Name string
|
||||
HandlerName string
|
||||
peripheralIndex int
|
||||
Value int // interrupt number
|
||||
Description string
|
||||
@@ -171,12 +172,12 @@ func readSVD(path, sourceURL string) (*Device, error) {
|
||||
groupName := cleanName(periphEl.GroupName)
|
||||
|
||||
for _, interrupt := range periphEl.Interrupts {
|
||||
addInterrupt(interrupts, interrupt.Name, interrupt.Index, description)
|
||||
addInterrupt(interrupts, interrupt.Name, interrupt.Name, interrupt.Index, description)
|
||||
// As a convenience, also use the peripheral name as the interrupt
|
||||
// name. Only do that for the nrf for now, as the stm32 .svd files
|
||||
// don't always put interrupts in the correct peripheral...
|
||||
if len(periphEl.Interrupts) == 1 && strings.HasPrefix(device.Name, "nrf") {
|
||||
addInterrupt(interrupts, periphEl.Name, interrupt.Index, description)
|
||||
addInterrupt(interrupts, periphEl.Name, interrupt.Name, interrupt.Index, description)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +389,7 @@ func readSVD(path, sourceURL string) (*Device, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func addInterrupt(interrupts map[string]*interrupt, name string, index int, description string) {
|
||||
func addInterrupt(interrupts map[string]*interrupt, name, interruptName string, index int, description string) {
|
||||
if _, ok := interrupts[name]; ok {
|
||||
if interrupts[name].Value != index {
|
||||
// Note: some SVD files like the one for STM32H7x7 contain mistakes.
|
||||
@@ -409,6 +410,7 @@ func addInterrupt(interrupts map[string]*interrupt, name string, index int, desc
|
||||
} else {
|
||||
interrupts[name] = &interrupt{
|
||||
Name: name,
|
||||
HandlerName: interruptName + "_IRQHandler",
|
||||
peripheralIndex: len(interrupts),
|
||||
Value: index,
|
||||
Description: description,
|
||||
@@ -619,6 +621,7 @@ func writeGo(outdir string, device *Device) error {
|
||||
package {{.pkgName}}
|
||||
|
||||
import (
|
||||
"runtime/interrupt"
|
||||
"runtime/volatile"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -628,12 +631,18 @@ const (
|
||||
DEVICE = "{{.metadata.name}}"
|
||||
)
|
||||
|
||||
// Interrupt numbers
|
||||
// Interrupt numbers.
|
||||
const ({{range .interrupts}}
|
||||
IRQ_{{.Name}} = {{.Value}} // {{.Description}}{{end}}
|
||||
IRQ_max = {{.interruptMax}} // Highest interrupt number on this device.
|
||||
)
|
||||
|
||||
// Map interrupt numbers to function names.
|
||||
// These aren't real calls, they're removed by the compiler.
|
||||
var ({{range .interrupts}}
|
||||
_ = interrupt.Register(IRQ_{{.Name}}, "{{.HandlerName}}"){{end}}
|
||||
)
|
||||
|
||||
// Peripherals.
|
||||
var (
|
||||
{{range .peripherals}} {{.Name}} = (*{{.GroupName}}_Type)(unsafe.Pointer(uintptr(0x{{printf "%x" .BaseAddress}}))) // {{.Description}}
|
||||
@@ -879,7 +888,7 @@ Default_Handler:
|
||||
num++
|
||||
}
|
||||
num++
|
||||
fmt.Fprintf(w, " .long %s_IRQHandler\n", intr.Name)
|
||||
fmt.Fprintf(w, " .long %s\n", intr.HandlerName)
|
||||
}
|
||||
|
||||
w.WriteString(`
|
||||
|
||||
Reference in New Issue
Block a user