aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-05-16 22:39:30 +0200
committerRon Evans <[email protected]>2023-05-20 21:18:02 +0200
commitb43bd9e62a9648b995a397f7a2454799b2d7c9fa (patch)
tree432428fcd2b6174934d237f2d6be93e01e13c57d /tools
parent572c22f66ac70daa61a052d37c6be247e82794d4 (diff)
downloadtinygo-b43bd9e62a9648b995a397f7a2454799b2d7c9fa.tar.gz
tinygo-b43bd9e62a9648b995a397f7a2454799b2d7c9fa.zip
avr: fix interrupt names for newer attiny chips
This only affects chips that aren't supported by TinyGo yet, so this should be a safe change. Importantly, it fixes interrupts on the ATtiny1616.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-avr/gen-device-avr.go47
1 files changed, 42 insertions, 5 deletions
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go
index 7885eef3a..6b7074a25 100755
--- a/tools/gen-device-avr/gen-device-avr.go
+++ b/tools/gen-device-avr/gen-device-avr.go
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "sort"
"strconv"
"strings"
"sync"
@@ -29,7 +30,7 @@ type AVRToolsDeviceFile struct {
Size string `xml:"size,attr"`
} `xml:"memory-segment"`
} `xml:"address-spaces>address-space"`
- Interrupts []Interrupt `xml:"interrupts>interrupt"`
+ Interrupts []*XMLInterrupt `xml:"interrupts>interrupt"`
} `xml:"devices>device"`
Modules []struct {
Name string `xml:"name,attr"`
@@ -52,6 +53,13 @@ type AVRToolsDeviceFile struct {
} `xml:"modules>module"`
}
+type XMLInterrupt struct {
+ Index int `xml:"index,attr"`
+ Name string `xml:"name,attr"`
+ Instance string `xml:"module-instance,attr"`
+ Caption string `xml:"caption,attr"`
+}
+
type Device struct {
metadata map[string]interface{}
interrupts []Interrupt
@@ -81,9 +89,9 @@ type MemorySegment struct {
}
type Interrupt struct {
- Index int `xml:"index,attr"`
- Name string `xml:"name,attr"`
- Caption string `xml:"caption,attr"`
+ Index int
+ Name string
+ Caption string
}
type Peripheral struct {
@@ -247,6 +255,35 @@ func readATDF(path string) (*Device, error) {
return nil, err
}
+ // Process the interrupts to clean up inconsistencies between ATDF files.
+ var interrupts []Interrupt
+ hasResetInterrupt := false
+ for _, intr := range device.Interrupts {
+ name := intr.Name
+ if intr.Instance != "" {
+ // ATDF files for newer chips also have an instance name, which must
+ // be specified to make the interrupt name unique.
+ name = intr.Instance + "_" + name
+ }
+ if name == "RESET" {
+ hasResetInterrupt = true
+ }
+ interrupts = append(interrupts, Interrupt{
+ Index: intr.Index,
+ Name: name,
+ Caption: intr.Caption,
+ })
+ }
+ if !hasResetInterrupt {
+ interrupts = append(interrupts, Interrupt{
+ Index: 0,
+ Name: "RESET",
+ })
+ }
+ sort.SliceStable(interrupts, func(i, j int) bool {
+ return interrupts[i].Index < interrupts[j].Index
+ })
+
return &Device{
metadata: map[string]interface{}{
"file": filepath.Base(path),
@@ -261,7 +298,7 @@ func readATDF(path string) (*Device, error) {
"ramSize": ramSize,
"numInterrupts": len(device.Interrupts),
},
- interrupts: device.Interrupts,
+ interrupts: interrupts,
peripherals: peripherals,
}, nil
}