Skip to content
Permalink
Browse files

generators: correctly handle clustered subtypes used in Atmel SAMD21 …

…SVD for important peripherals

Signed-off-by: Ron Evans <ron@hybridgroup.com>
  • Loading branch information...
deadprogram authored and aykevl committed Jan 19, 2019
1 parent e2be7cc commit f89c695c8ca527a0a1e5114d86e88bede4a08eeb
Showing with 39 additions and 12 deletions.
  1. +12 −12 src/runtime/runtime_atsamd21g18.go
  2. +27 −0 tools/gen-device-svd.py
@@ -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
}
@@ -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:

0 comments on commit f89c695

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.