all: use groupName in peripherals
This is needed for support for multiple instances of a peripheral type.
Этот коммит содержится в:
родитель
110230a50d
коммит
9fa08bf51d
3 изменённых файлов: 47 добавлений и 17 удалений
|
@ -9,10 +9,10 @@ import (
|
|||
type GPIOMode uint8
|
||||
|
||||
const (
|
||||
GPIO_INPUT = (nrf.P0_PIN_CNF_DIR_Input << nrf.P0_PIN_CNF_DIR_Pos) | (nrf.P0_PIN_CNF_INPUT_Connect << nrf.P0_PIN_CNF_INPUT_Pos)
|
||||
GPIO_INPUT_PULLUP = GPIO_INPUT | (nrf.P0_PIN_CNF_PULL_Pullup << nrf.P0_PIN_CNF_PULL_Pos)
|
||||
GPIO_INPUT_PULLDOWN = GPIO_INPUT | (nrf.P0_PIN_CNF_PULL_Pulldown << nrf.P0_PIN_CNF_PULL_Pos)
|
||||
GPIO_OUTPUT = (nrf.P0_PIN_CNF_DIR_Output << nrf.P0_PIN_CNF_DIR_Pos) | (nrf.P0_PIN_CNF_INPUT_Disconnect << nrf.P0_PIN_CNF_INPUT_Pos)
|
||||
GPIO_INPUT = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos)
|
||||
GPIO_INPUT_PULLUP = GPIO_INPUT | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos)
|
||||
GPIO_INPUT_PULLDOWN = GPIO_INPUT | (nrf.GPIO_PIN_CNF_PULL_Pulldown << nrf.GPIO_PIN_CNF_PULL_Pos)
|
||||
GPIO_OUTPUT = (nrf.GPIO_PIN_CNF_DIR_Output << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Disconnect << nrf.GPIO_PIN_CNF_INPUT_Pos)
|
||||
)
|
||||
|
||||
// LEDs on the PCA10040 (nRF52832 dev board)
|
||||
|
@ -35,7 +35,7 @@ const (
|
|||
|
||||
// Configure this pin with the given configuration.
|
||||
func (p GPIO) Configure(config GPIOConfig) {
|
||||
cfg := config.Mode | nrf.P0_PIN_CNF_DRIVE_S0S1 | nrf.P0_PIN_CNF_SENSE_Disabled
|
||||
cfg := config.Mode | nrf.GPIO_PIN_CNF_DRIVE_S0S1 | nrf.GPIO_PIN_CNF_SENSE_Disabled
|
||||
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ func init() {
|
|||
}
|
||||
|
||||
func initUART() {
|
||||
nrf.UART0.ENABLE = nrf.UART0_ENABLE_ENABLE_Enabled
|
||||
nrf.UART0.BAUDRATE = nrf.UART0_BAUDRATE_BAUDRATE_Baud115200
|
||||
nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled
|
||||
nrf.UART0.BAUDRATE = nrf.UART_BAUDRATE_BAUDRATE_Baud115200
|
||||
nrf.UART0.TASKS_STARTTX = 1
|
||||
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ type __volatile bool
|
|||
var rtc_wakeup __volatile
|
||||
|
||||
func rtc_sleep(ticks uint32) {
|
||||
nrf.RTC0.INTENSET = nrf.RTC0_INTENSET_COMPARE0_Msk
|
||||
nrf.RTC0.INTENSET = nrf.RTC_INTENSET_COMPARE0_Msk
|
||||
rtc_wakeup = false
|
||||
if ticks == 1 {
|
||||
// Race condition (even in hardware) at ticks == 1.
|
||||
|
@ -155,7 +155,7 @@ func rtc_sleep(ticks uint32) {
|
|||
|
||||
//go:export RTC0_IRQHandler
|
||||
func handleRTC0() {
|
||||
nrf.RTC0.INTENCLR = nrf.RTC0_INTENSET_COMPARE0_Msk
|
||||
nrf.RTC0.INTENCLR = nrf.RTC_INTENSET_COMPARE0_Msk
|
||||
nrf.RTC0.EVENTS_COMPARE[0] = 0
|
||||
rtc_wakeup = true
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ def readSVD(path):
|
|||
raise ValueError('multiple <licenseText> elements')
|
||||
|
||||
device.peripherals = []
|
||||
peripheralDict = {}
|
||||
|
||||
interrupts = OrderedDict()
|
||||
|
||||
|
@ -50,14 +51,32 @@ def readSVD(path):
|
|||
if descriptionTags:
|
||||
description = formatText(getText(descriptionTags[0]))
|
||||
baseAddress = int(getText(periphEl.getElementsByTagName('baseAddress')[0]), 0)
|
||||
groupNameTags = periphEl.getElementsByTagName('groupName')
|
||||
groupName = name
|
||||
if groupNameTags:
|
||||
groupName = getText(groupNameTags[0])
|
||||
|
||||
if periphEl.hasAttribute('derivedFrom'):
|
||||
derivedFromName = periphEl.getAttribute('derivedFrom')
|
||||
derivedFrom = peripheralDict[derivedFromName]
|
||||
peripheral = {
|
||||
'name': name,
|
||||
'groupName': derivedFrom['groupName'],
|
||||
'description': description if description is not None else derivedFrom['description'],
|
||||
'baseAddress': baseAddress,
|
||||
}
|
||||
device.peripherals.append(peripheral)
|
||||
continue
|
||||
|
||||
peripheral = {
|
||||
'name': name,
|
||||
'groupName': groupName,
|
||||
'description': description,
|
||||
'baseAddress': baseAddress,
|
||||
'registers': [],
|
||||
}
|
||||
device.peripherals.append(peripheral)
|
||||
peripheralDict[name] = peripheral
|
||||
|
||||
for interrupt in periphEl.getElementsByTagName('interrupt'):
|
||||
intrName = getText(interrupt.getElementsByTagName('name')[0])
|
||||
|
@ -77,7 +96,7 @@ def readSVD(path):
|
|||
if regsEls:
|
||||
for el in regsEls[0].childNodes:
|
||||
if el.nodeName == 'register':
|
||||
peripheral['registers'].append(parseSVDRegister(name, el, baseAddress))
|
||||
peripheral['registers'].append(parseSVDRegister(groupName, el, baseAddress))
|
||||
elif el.nodeName == 'cluster':
|
||||
if el.getElementsByTagName('dim'):
|
||||
continue # TODO
|
||||
|
@ -85,7 +104,7 @@ def readSVD(path):
|
|||
clusterOffset = int(getText(el.getElementsByTagName('addressOffset')[0]), 0)
|
||||
for regEl in el.childNodes:
|
||||
if regEl.nodeName == 'register':
|
||||
peripheral['registers'].append(parseSVDRegister(name, regEl, baseAddress + clusterOffset, clusterPrefix))
|
||||
peripheral['registers'].append(parseSVDRegister(groupName, regEl, baseAddress + clusterOffset, clusterPrefix))
|
||||
else:
|
||||
continue
|
||||
|
||||
|
@ -105,7 +124,7 @@ def readSVD(path):
|
|||
|
||||
return device
|
||||
|
||||
def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
||||
def parseSVDRegister(groupName, regEl, baseAddress, namePrefix=''):
|
||||
regName = getText(regEl.getElementsByTagName('name')[0])
|
||||
regDescription = getText(regEl.getElementsByTagName('description')[0])
|
||||
offsetEls = regEl.getElementsByTagName('offset')
|
||||
|
@ -138,12 +157,12 @@ def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
|||
else:
|
||||
msb = int(getText(fieldEl.getElementsByTagName('bitWidth')[0])) + lsb - 1
|
||||
fields.append({
|
||||
'name': '{}_{}{}_{}_Pos'.format(peripheralName, namePrefix, regName, fieldName),
|
||||
'name': '{}_{}{}_{}_Pos'.format(groupName, namePrefix, regName, fieldName),
|
||||
'description': 'Position of %s field.' % fieldName,
|
||||
'value': lsb,
|
||||
})
|
||||
fields.append({
|
||||
'name': '{}_{}{}_{}_Msk'.format(peripheralName, namePrefix, regName, fieldName),
|
||||
'name': '{}_{}{}_{}_Msk'.format(groupName, namePrefix, regName, fieldName),
|
||||
'description': 'Bit mask of %s field.' % fieldName,
|
||||
'value': (0xffffffff >> (31 - (msb - lsb))) << lsb,
|
||||
})
|
||||
|
@ -152,7 +171,7 @@ def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
|||
enumDescription = getText(enumEl.getElementsByTagName('description')[0])
|
||||
enumValue = int(getText(enumEl.getElementsByTagName('value')[0]), 0)
|
||||
fields.append({
|
||||
'name': '{}_{}{}_{}_{}'.format(peripheralName, namePrefix, regName, fieldName, enumName),
|
||||
'name': '{}_{}{}_{}_{}'.format(groupName, namePrefix, regName, fieldName, enumName),
|
||||
'description': enumDescription,
|
||||
'value': enumValue,
|
||||
})
|
||||
|
@ -201,8 +220,13 @@ const (
|
|||
out.write('\tIRQ_max = {} // Highest interrupt number on this device.\n'.format(intrMax))
|
||||
out.write(')\n')
|
||||
|
||||
# Define peripheral struct types.
|
||||
for peripheral in device.peripherals:
|
||||
out.write('\n// {description}\ntype {name}_Type struct {{\n'.format(**peripheral))
|
||||
if 'registers' not in peripheral:
|
||||
# This peripheral was derived from another peripheral. No new type
|
||||
# needs to be defined for it.
|
||||
continue
|
||||
out.write('\n// {description}\ntype {groupName}_Type struct {{\n'.format(**peripheral))
|
||||
address = peripheral['baseAddress']
|
||||
padNumber = 0
|
||||
for register in peripheral['registers']:
|
||||
|
@ -233,12 +257,18 @@ const (
|
|||
address = register['address'] + 4
|
||||
out.write('}\n')
|
||||
|
||||
# Define actual peripheral pointers.
|
||||
out.write('\n// Peripherals.\nvar (\n')
|
||||
for peripheral in device.peripherals:
|
||||
out.write('\t{name} = (*{name}_Type)(unsafe.Pointer(uintptr(0x{baseAddress:x}))) // {description}\n'.format(**peripheral))
|
||||
out.write('\t{name} = (*{groupName}_Type)(unsafe.Pointer(uintptr(0x{baseAddress:x}))) // {description}\n'.format(**peripheral))
|
||||
out.write(')\n')
|
||||
|
||||
# Define bitfields.
|
||||
for peripheral in device.peripherals:
|
||||
if 'registers' not in peripheral:
|
||||
# This peripheral was derived from another peripheral. Bitfields are
|
||||
# already defined.
|
||||
continue
|
||||
if not sum(map(lambda r: len(r['bitfields']), peripheral['registers'])): continue
|
||||
out.write('\n// Bitfields for {name}: {description}\nconst('.format(**peripheral))
|
||||
for register in peripheral['registers']:
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче