Skip to content

Commit 4eac212

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent b661882 commit 4eac212

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

src/runtime/runtime_nrf_softdevice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ func waitForEvents() {
2424
if enabled != 0 {
2525
// Now pick the appropriate SVCall number. Hopefully they won't change
2626
// in the future with a different SoftDevice version.
27-
if nrf.DEVICE == "nrf51" {
27+
if nrf.Device == "nrf51" {
2828
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 29
2929
arm.SVCall0(0x2B + 29)
30-
} else if nrf.DEVICE == "nrf52" || nrf.DEVICE == "nrf52840" || nrf.DEVICE == "nrf52833" {
30+
} else if nrf.Device == "nrf52" || nrf.Device == "nrf52840" || nrf.Device == "nrf52833" {
3131
// sd_app_evt_wait: SOC_SVC_BASE_NOT_AVAILABLE + 21
3232
arm.SVCall0(0x2C + 21)
3333
} else {

tools/gen-device-svd/gen-device-svd.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ var validName = regexp.MustCompile("^[a-zA-Z0-9_]+$")
1919
var enumBitSpecifier = regexp.MustCompile("^#[x01]+$")
2020

2121
type SVDFile struct {
22-
XMLName xml.Name `xml:"device"`
23-
Name string `xml:"name"`
24-
Description string `xml:"description"`
25-
LicenseText string `xml:"licenseText"`
22+
XMLName xml.Name `xml:"device"`
23+
Name string `xml:"name"`
24+
Description string `xml:"description"`
25+
LicenseText string `xml:"licenseText"`
26+
CPU *struct {
27+
Name string `xml:"name"`
28+
FPUPresent bool `xml:"fpuPresent"`
29+
NVICPrioBits int `xml:"nvicPrioBits"`
30+
} `xml:"cpu"`
2631
Peripherals []SVDPeripheral `xml:"peripherals>peripheral"`
2732
}
2833

@@ -95,6 +100,11 @@ type Metadata struct {
95100
NameLower string
96101
Description string
97102
LicenseBlock string
103+
104+
HasCPUInfo bool // set if the following fields are populated
105+
CPUName string
106+
FPUPresent bool
107+
NVICPrioBits int
98108
}
99109

100110
type Interrupt struct {
@@ -418,15 +428,22 @@ func readSVD(path, sourceURL string) (*Device, error) {
418428
licenseBlock = regexp.MustCompile(`\s+\n`).ReplaceAllString(licenseBlock, "\n")
419429
}
420430

431+
metadata := &Metadata{
432+
File: filepath.Base(path),
433+
DescriptorSource: sourceURL,
434+
Name: device.Name,
435+
NameLower: strings.ToLower(device.Name),
436+
Description: strings.TrimSpace(device.Description),
437+
LicenseBlock: licenseBlock,
438+
}
439+
if device.CPU != nil {
440+
metadata.HasCPUInfo = true
441+
metadata.CPUName = device.CPU.Name
442+
metadata.FPUPresent = device.CPU.FPUPresent
443+
metadata.NVICPrioBits = device.CPU.NVICPrioBits
444+
}
421445
return &Device{
422-
Metadata: &Metadata{
423-
File: filepath.Base(path),
424-
DescriptorSource: sourceURL,
425-
Name: device.Name,
426-
NameLower: strings.ToLower(device.Name),
427-
Description: strings.TrimSpace(device.Description),
428-
LicenseBlock: licenseBlock,
429-
},
446+
Metadata: metadata,
430447
Interrupts: interruptList,
431448
Peripherals: peripheralsList,
432449
}, nil
@@ -833,7 +850,12 @@ import (
833850
834851
// Some information about this device.
835852
const (
836-
DEVICE = "{{.device.Metadata.Name}}"
853+
Device = "{{.device.Metadata.Name}}"
854+
{{- if .device.Metadata.HasCPUInfo }}
855+
CPU = "{{.device.Metadata.CPUName}}"
856+
FPUPresent = {{.device.Metadata.FPUPresent}}
857+
NVICPrioBits = {{.device.Metadata.NVICPrioBits}}
858+
{{- end }}
837859
)
838860
839861
// Interrupt numbers.

0 commit comments

Comments
 (0)