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.
Этот коммит содержится в:
Ayke van Laethem 2023-05-16 22:39:30 +02:00 коммит произвёл Ron Evans
родитель 572c22f66a
коммит b43bd9e62a

Просмотреть файл

@ -9,6 +9,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -29,7 +30,7 @@ type AVRToolsDeviceFile struct {
Size string `xml:"size,attr"` Size string `xml:"size,attr"`
} `xml:"memory-segment"` } `xml:"memory-segment"`
} `xml:"address-spaces>address-space"` } `xml:"address-spaces>address-space"`
Interrupts []Interrupt `xml:"interrupts>interrupt"` Interrupts []*XMLInterrupt `xml:"interrupts>interrupt"`
} `xml:"devices>device"` } `xml:"devices>device"`
Modules []struct { Modules []struct {
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
@ -52,6 +53,13 @@ type AVRToolsDeviceFile struct {
} `xml:"modules>module"` } `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 { type Device struct {
metadata map[string]interface{} metadata map[string]interface{}
interrupts []Interrupt interrupts []Interrupt
@ -81,9 +89,9 @@ type MemorySegment struct {
} }
type Interrupt struct { type Interrupt struct {
Index int `xml:"index,attr"` Index int
Name string `xml:"name,attr"` Name string
Caption string `xml:"caption,attr"` Caption string
} }
type Peripheral struct { type Peripheral struct {
@ -247,6 +255,35 @@ func readATDF(path string) (*Device, error) {
return nil, err 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{ return &Device{
metadata: map[string]interface{}{ metadata: map[string]interface{}{
"file": filepath.Base(path), "file": filepath.Base(path),
@ -261,7 +298,7 @@ func readATDF(path string) (*Device, error) {
"ramSize": ramSize, "ramSize": ramSize,
"numInterrupts": len(device.Interrupts), "numInterrupts": len(device.Interrupts),
}, },
interrupts: device.Interrupts, interrupts: interrupts,
peripherals: peripherals, peripherals: peripherals,
}, nil }, nil
} }