aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-12-15 14:16:22 +0100
committerRon Evans <[email protected]>2020-01-20 21:19:12 +0100
commita5ed993f8dda8cfc71de549e60323236feb85c05 (patch)
treeabd0d3577cf13a6e3a2d61379b689e744bda7ef6 /tools
parent3729fcfa9edba2230aba65bcd607621d3285704f (diff)
downloadtinygo-a5ed993f8dda8cfc71de549e60323236feb85c05.tar.gz
tinygo-a5ed993f8dda8cfc71de549e60323236feb85c05.zip
all: add compiler support for interrupts
This commit lets the compiler know about interrupts and allows optimizations to be performed based on that: interrupts are eliminated when they appear to be unused in a program. This is done with a new pseudo-call (runtime/interrupt.New) that is treated specially by the compiler.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-avr/gen-device-avr.go7
-rwxr-xr-xtools/gen-device-svd/gen-device-svd.go19
2 files changed, 21 insertions, 5 deletions
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go
index ac4c8b996..8f9298a21 100755
--- a/tools/gen-device-avr/gen-device-avr.go
+++ b/tools/gen-device-avr/gen-device-avr.go
@@ -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}}
diff --git a/tools/gen-device-svd/gen-device-svd.go b/tools/gen-device-svd/gen-device-svd.go
index cef0365d5..f5aebcfe8 100755
--- a/tools/gen-device-svd/gen-device-svd.go
+++ b/tools/gen-device-svd/gen-device-svd.go
@@ -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(`