gen-device: add extra constants and rename them to be Go style

- Add some extra fields: FPUPresent, CPU and NVICPrioBits which may
    come in handy at a later time (and are easy to add).
  - Rename DEVICE to Device, to match Go style.

This is in preparation to the next commit, which requires the FPUPresent
flag.
Этот коммит содержится в:
Ayke van Laethem 2021-04-24 01:50:06 +02:00 коммит произвёл Ron Evans
родитель b661882391
коммит 4eac212695
2 изменённых файлов: 37 добавлений и 15 удалений

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

@ -24,10 +24,10 @@ func waitForEvents() {
if enabled != 0 {
// Now pick the appropriate SVCall number. Hopefully they won't change
// in the future with a different SoftDevice version.
if nrf.DEVICE == "nrf51" {
if nrf.Device == "nrf51" {
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 29
arm.SVCall0(0x2B + 29)
} else if nrf.DEVICE == "nrf52" || nrf.DEVICE == "nrf52840" || nrf.DEVICE == "nrf52833" {
} else if nrf.Device == "nrf52" || nrf.Device == "nrf52840" || nrf.Device == "nrf52833" {
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 21
arm.SVCall0(0x2C + 21)
} else {

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

@ -19,10 +19,15 @@ var validName = regexp.MustCompile("^[a-zA-Z0-9_]+$")
var enumBitSpecifier = regexp.MustCompile("^#[x01]+$")
type SVDFile struct {
XMLName xml.Name `xml:"device"`
Name string `xml:"name"`
Description string `xml:"description"`
LicenseText string `xml:"licenseText"`
XMLName xml.Name `xml:"device"`
Name string `xml:"name"`
Description string `xml:"description"`
LicenseText string `xml:"licenseText"`
CPU *struct {
Name string `xml:"name"`
FPUPresent bool `xml:"fpuPresent"`
NVICPrioBits int `xml:"nvicPrioBits"`
} `xml:"cpu"`
Peripherals []SVDPeripheral `xml:"peripherals>peripheral"`
}
@ -95,6 +100,11 @@ type Metadata struct {
NameLower string
Description string
LicenseBlock string
HasCPUInfo bool // set if the following fields are populated
CPUName string
FPUPresent bool
NVICPrioBits int
}
type Interrupt struct {
@ -418,15 +428,22 @@ func readSVD(path, sourceURL string) (*Device, error) {
licenseBlock = regexp.MustCompile(`\s+\n`).ReplaceAllString(licenseBlock, "\n")
}
metadata := &Metadata{
File: filepath.Base(path),
DescriptorSource: sourceURL,
Name: device.Name,
NameLower: strings.ToLower(device.Name),
Description: strings.TrimSpace(device.Description),
LicenseBlock: licenseBlock,
}
if device.CPU != nil {
metadata.HasCPUInfo = true
metadata.CPUName = device.CPU.Name
metadata.FPUPresent = device.CPU.FPUPresent
metadata.NVICPrioBits = device.CPU.NVICPrioBits
}
return &Device{
Metadata: &Metadata{
File: filepath.Base(path),
DescriptorSource: sourceURL,
Name: device.Name,
NameLower: strings.ToLower(device.Name),
Description: strings.TrimSpace(device.Description),
LicenseBlock: licenseBlock,
},
Metadata: metadata,
Interrupts: interruptList,
Peripherals: peripheralsList,
}, nil
@ -833,7 +850,12 @@ import (
// Some information about this device.
const (
DEVICE = "{{.device.Metadata.Name}}"
Device = "{{.device.Metadata.Name}}"
{{- if .device.Metadata.HasCPUInfo }}
CPU = "{{.device.Metadata.CPUName}}"
FPUPresent = {{.device.Metadata.FPUPresent}}
NVICPrioBits = {{.device.Metadata.NVICPrioBits}}
{{- end }}
)
// Interrupt numbers.