aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRon Evans <[email protected]>2019-01-19 18:29:21 +0100
committerAyke van Laethem <[email protected]>2019-01-20 18:40:49 +0100
commitf89c695c8ca527a0a1e5114d86e88bede4a08eeb (patch)
treeab83f1676c90527bc0b8a10b9b2f30e43711f99f
parente2be7ccf76ae9f8548394e715193e03ab47c18d6 (diff)
downloadtinygo-f89c695c8ca527a0a1e5114d86e88bede4a08eeb.tar.gz
tinygo-f89c695c8ca527a0a1e5114d86e88bede4a08eeb.zip
generators: correctly handle clustered subtypes used in Atmel SAMD21 SVD for important peripherals
Signed-off-by: Ron Evans <[email protected]>
-rw-r--r--src/runtime/runtime_atsamd21g18.go24
-rwxr-xr-xtools/gen-device-svd.py27
2 files changed, 39 insertions, 12 deletions
diff --git a/src/runtime/runtime_atsamd21g18.go b/src/runtime/runtime_atsamd21g18.go
index 6de9ce54d..e405286e6 100644
--- a/src/runtime/runtime_atsamd21g18.go
+++ b/src/runtime/runtime_atsamd21g18.go
@@ -187,24 +187,24 @@ func initRTC() {
sam.PM.APBAMASK |= sam.PM_APBAMASK_RTC_
// disable RTC
- sam.RTC.MODE0.CTRL = 0
+ sam.RTC_MODE0.CTRL = 0
waitForSync()
// reset RTC
- sam.RTC.MODE0.CTRL |= sam.RTC_MODE0_CTRL_SWRST
+ sam.RTC_MODE0.CTRL |= sam.RTC_MODE0_CTRL_SWRST
waitForSync()
// set Mode0 to 32-bit counter (mode 0) with prescaler 1 and GCLK2 is 32KHz/1
- sam.RTC.MODE0.CTRL = sam.RegValue16((sam.RTC_MODE0_CTRL_MODE_COUNT32 << sam.RTC_MODE0_CTRL_MODE_Pos) |
+ sam.RTC_MODE0.CTRL = sam.RegValue16((sam.RTC_MODE0_CTRL_MODE_COUNT32 << sam.RTC_MODE0_CTRL_MODE_Pos) |
(sam.RTC_MODE0_CTRL_PRESCALER_DIV1 << sam.RTC_MODE0_CTRL_PRESCALER_Pos) |
sam.RTC_MODE0_CTRL_MATCHCLR)
waitForSync()
- sam.RTC.MODE0.COMP0 = 0xffffffff
+ sam.RTC_MODE0.COMP0 = 0xffffffff
waitForSync()
// re-enable RTC
- sam.RTC.MODE0.CTRL |= sam.RTC_MODE0_CTRL_ENABLE
+ sam.RTC_MODE0.CTRL |= sam.RTC_MODE0_CTRL_ENABLE
waitForSync()
arm.EnableIRQ(sam.IRQ_RTC)
@@ -241,10 +241,10 @@ func sleepTicks(d timeUnit) {
// ticks returns number of microseconds since start.
func ticks() timeUnit {
// request read of count
- sam.RTC.MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
+ sam.RTC_MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
waitForSync()
- rtcCounter := uint64(sam.RTC.MODE0.COUNT) * 30 // each counter tick == 30.5us
+ rtcCounter := uint64(sam.RTC_MODE0.COUNT) * 30 // each counter tick == 30.5us
offset := (rtcCounter - timerLastCounter) // change since last measurement
timerLastCounter = rtcCounter
timestamp += timeUnit(offset) // TODO: not precise
@@ -260,16 +260,16 @@ func timerSleep(ticks uint32) {
}
// request read of count
- sam.RTC.MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
+ sam.RTC_MODE0.READREQ = sam.RTC_MODE0_READREQ_RREQ
waitForSync()
// set compare value
- cnt := sam.RTC.MODE0.COUNT
- sam.RTC.MODE0.COMP0 = sam.RegValue(uint32(cnt) + (ticks / 30)) // each counter tick == 30.5us
+ cnt := sam.RTC_MODE0.COUNT
+ sam.RTC_MODE0.COMP0 = sam.RegValue(uint32(cnt) + (ticks / 30)) // each counter tick == 30.5us
waitForSync()
// enable IRQ for CMP0 compare
- sam.RTC.MODE0.INTENSET |= sam.RTC_MODE0_INTENSET_CMP0
+ sam.RTC_MODE0.INTENSET |= sam.RTC_MODE0_INTENSET_CMP0
for !timerWakeup {
arm.Asm("wfi")
@@ -279,7 +279,7 @@ func timerSleep(ticks uint32) {
//go:export RTC_IRQHandler
func handleRTC() {
// disable IRQ for CMP0 compare
- sam.RTC.MODE0.INTFLAG = sam.RTC_MODE0_INTENSET_CMP0
+ sam.RTC_MODE0.INTFLAG = sam.RTC_MODE0_INTENSET_CMP0
timerWakeup = true
}
diff --git a/tools/gen-device-svd.py b/tools/gen-device-svd.py
index f5e5c857f..37700dd00 100755
--- a/tools/gen-device-svd.py
+++ b/tools/gen-device-svd.py
@@ -81,6 +81,15 @@ def readSVD(path, sourceURL):
}
device.peripherals.append(peripheral)
peripheralDict[name] = peripheral
+ if 'subtypes' in derivedFrom:
+ for subtype in derivedFrom['subtypes']:
+ subp = {
+ 'name': name + "_"+subtype['clusterName'],
+ 'groupName': subtype['groupName'],
+ 'description': subtype['description'],
+ 'baseAddress': baseAddress,
+ }
+ device.peripherals.append(subp)
continue
peripheral = {
@@ -89,6 +98,7 @@ def readSVD(path, sourceURL):
'description': description,
'baseAddress': baseAddress,
'registers': [],
+ 'subtypes': [],
}
device.peripherals.append(peripheral)
peripheralDict[name] = peripheral
@@ -108,6 +118,23 @@ def readSVD(path, sourceURL):
clusterPrefix = clusterName + '_'
clusterOffset = int(getText(cluster.find('addressOffset')), 0)
if cluster.find('dim') is None:
+ if clusterOffset is 0:
+ # make this a separate peripheral
+ cpRegisters = []
+ for regEl in cluster.findall('register'):
+ cpRegisters.extend(parseRegister(groupName, regEl, baseAddress, clusterName+"_"))
+ cpRegisters.sort(key=lambda r: r['address'])
+ clusterPeripheral = {
+ 'name': name+ "_" +clusterName,
+ 'groupName': groupName+ "_" +clusterName,
+ 'description': description+ " - " +clusterName,
+ 'clusterName': clusterName,
+ 'baseAddress': baseAddress,
+ 'registers': cpRegisters,
+ }
+ device.peripherals.append(clusterPeripheral)
+ peripheral['subtypes'].append(clusterPeripheral)
+ continue
dim = None
dimIncrement = None
else: