aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-avr/gen-device-avr.go18
-rwxr-xr-xtools/gen-device-svd/gen-device-svd.go46
2 files changed, 47 insertions, 17 deletions
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go
index 9b9c627ae..c553ec30d 100755
--- a/tools/gen-device-avr/gen-device-avr.go
+++ b/tools/gen-device-avr/gen-device-avr.go
@@ -288,7 +288,6 @@ func writeGo(outdir string, device *Device) error {
package {{.pkgName}}
import (
- "runtime/interrupt"
"runtime/volatile"
"unsafe"
)
@@ -306,11 +305,18 @@ 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}}
-)
+// Pseudo function call that is replaced by the compiler with the actual
+// functions registered through interrupt.New.
+//go:linkname callHandlers runtime/interrupt.callHandlers
+func callHandlers(num int)
+
+{{- range .interrupts}}
+//export __vector_{{.Name}}
+//go:interrupt
+func interrupt{{.Name}}() {
+ callHandlers(IRQ_{{.Name}})
+}
+{{- end}}
// Peripherals.
var ({{range .peripherals}}
diff --git a/tools/gen-device-svd/gen-device-svd.go b/tools/gen-device-svd/gen-device-svd.go
index 752286f41..e50ff299f 100755
--- a/tools/gen-device-svd/gen-device-svd.go
+++ b/tools/gen-device-svd/gen-device-svd.go
@@ -831,6 +831,15 @@ func writeGo(outdir string, device *Device, interruptSystem string) error {
}
}
+ interruptHandlerMap := make(map[string]*Interrupt)
+ var interruptHandlers []*Interrupt
+ for _, intr := range device.Interrupts {
+ if _, ok := interruptHandlerMap[intr.HandlerName]; !ok {
+ interruptHandlerMap[intr.HandlerName] = intr
+ interruptHandlers = append(interruptHandlers, intr)
+ }
+ }
+
t := template.Must(template.New("go").Funcs(template.FuncMap{
"bytesNeeded": func(i, j uint64) uint64 { return j - i },
"isMultiline": isMultiline,
@@ -846,7 +855,6 @@ func writeGo(outdir string, device *Device, interruptSystem string) error {
package {{.pkgName}}
import (
-{{if eq .interruptSystem "hardware"}}"runtime/interrupt"{{end}}
"runtime/volatile"
"unsafe"
)
@@ -876,14 +884,29 @@ const (
IRQ_max = {{.interruptMax}}
)
+// Pseudo function call that is replaced by the compiler with the actual
+// functions registered through interrupt.New.
+//go:linkname callHandlers runtime/interrupt.callHandlers
+func callHandlers(num int)
+
{{- if eq .interruptSystem "hardware"}}
-// Map interrupt numbers to function names.
-// These aren't real calls, they're removed by the compiler.
-var (
-{{- range .device.Interrupts}}
- _ = interrupt.Register(IRQ_{{.Name}}, "{{.HandlerName}}")
+{{- range .interruptHandlers}}
+//export {{.HandlerName}}
+func interrupt{{.Name}}() {
+ callHandlers(IRQ_{{.Name}})
+}
{{- end}}
-)
+{{- end}}
+
+{{- if eq .interruptSystem "software"}}
+func HandleInterrupt(num int) {
+ switch num {
+ {{- range .interruptHandlers}}
+ case IRQ_{{.Name}}:
+ callHandlers(IRQ_{{.Name}})
+ {{- end}}
+ }
+}
{{- end}}
// Peripherals.
@@ -901,10 +924,11 @@ var (
`))
err = t.Execute(w, map[string]interface{}{
- "device": device,
- "pkgName": filepath.Base(strings.TrimRight(outdir, "/")),
- "interruptMax": maxInterruptValue,
- "interruptSystem": interruptSystem,
+ "device": device,
+ "pkgName": filepath.Base(strings.TrimRight(outdir, "/")),
+ "interruptMax": maxInterruptValue,
+ "interruptSystem": interruptSystem,
+ "interruptHandlers": interruptHandlers,
})
if err != nil {
return err