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
|
type GPIOMode uint8
|
||||||
|
|
||||||
const (
|
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 = (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.P0_PIN_CNF_PULL_Pullup << nrf.P0_PIN_CNF_PULL_Pos)
|
GPIO_INPUT_PULLUP = GPIO_INPUT | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos)
|
||||||
GPIO_INPUT_PULLDOWN = GPIO_INPUT | (nrf.P0_PIN_CNF_PULL_Pulldown << nrf.P0_PIN_CNF_PULL_Pos)
|
GPIO_INPUT_PULLDOWN = GPIO_INPUT | (nrf.GPIO_PIN_CNF_PULL_Pulldown << nrf.GPIO_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_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)
|
// LEDs on the PCA10040 (nRF52832 dev board)
|
||||||
|
@ -35,7 +35,7 @@ const (
|
||||||
|
|
||||||
// Configure this pin with the given configuration.
|
// Configure this pin with the given configuration.
|
||||||
func (p GPIO) Configure(config GPIOConfig) {
|
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)
|
nrf.P0.PIN_CNF[p.Pin] = nrf.RegValue(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initUART() {
|
func initUART() {
|
||||||
nrf.UART0.ENABLE = nrf.UART0_ENABLE_ENABLE_Enabled
|
nrf.UART0.ENABLE = nrf.UART_ENABLE_ENABLE_Enabled
|
||||||
nrf.UART0.BAUDRATE = nrf.UART0_BAUDRATE_BAUDRATE_Baud115200
|
nrf.UART0.BAUDRATE = nrf.UART_BAUDRATE_BAUDRATE_Baud115200
|
||||||
nrf.UART0.TASKS_STARTTX = 1
|
nrf.UART0.TASKS_STARTTX = 1
|
||||||
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
|
nrf.UART0.PSELTXD = 6 // pin 6 for NRF52840-DK
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ type __volatile bool
|
||||||
var rtc_wakeup __volatile
|
var rtc_wakeup __volatile
|
||||||
|
|
||||||
func rtc_sleep(ticks uint32) {
|
func rtc_sleep(ticks uint32) {
|
||||||
nrf.RTC0.INTENSET = nrf.RTC0_INTENSET_COMPARE0_Msk
|
nrf.RTC0.INTENSET = nrf.RTC_INTENSET_COMPARE0_Msk
|
||||||
rtc_wakeup = false
|
rtc_wakeup = false
|
||||||
if ticks == 1 {
|
if ticks == 1 {
|
||||||
// Race condition (even in hardware) at ticks == 1.
|
// Race condition (even in hardware) at ticks == 1.
|
||||||
|
@ -155,7 +155,7 @@ func rtc_sleep(ticks uint32) {
|
||||||
|
|
||||||
//go:export RTC0_IRQHandler
|
//go:export RTC0_IRQHandler
|
||||||
func handleRTC0() {
|
func handleRTC0() {
|
||||||
nrf.RTC0.INTENCLR = nrf.RTC0_INTENSET_COMPARE0_Msk
|
nrf.RTC0.INTENCLR = nrf.RTC_INTENSET_COMPARE0_Msk
|
||||||
nrf.RTC0.EVENTS_COMPARE[0] = 0
|
nrf.RTC0.EVENTS_COMPARE[0] = 0
|
||||||
rtc_wakeup = true
|
rtc_wakeup = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ def readSVD(path):
|
||||||
raise ValueError('multiple <licenseText> elements')
|
raise ValueError('multiple <licenseText> elements')
|
||||||
|
|
||||||
device.peripherals = []
|
device.peripherals = []
|
||||||
|
peripheralDict = {}
|
||||||
|
|
||||||
interrupts = OrderedDict()
|
interrupts = OrderedDict()
|
||||||
|
|
||||||
|
@ -50,14 +51,32 @@ def readSVD(path):
|
||||||
if descriptionTags:
|
if descriptionTags:
|
||||||
description = formatText(getText(descriptionTags[0]))
|
description = formatText(getText(descriptionTags[0]))
|
||||||
baseAddress = int(getText(periphEl.getElementsByTagName('baseAddress')[0]), 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 = {
|
peripheral = {
|
||||||
'name': name,
|
'name': name,
|
||||||
|
'groupName': groupName,
|
||||||
'description': description,
|
'description': description,
|
||||||
'baseAddress': baseAddress,
|
'baseAddress': baseAddress,
|
||||||
'registers': [],
|
'registers': [],
|
||||||
}
|
}
|
||||||
device.peripherals.append(peripheral)
|
device.peripherals.append(peripheral)
|
||||||
|
peripheralDict[name] = peripheral
|
||||||
|
|
||||||
for interrupt in periphEl.getElementsByTagName('interrupt'):
|
for interrupt in periphEl.getElementsByTagName('interrupt'):
|
||||||
intrName = getText(interrupt.getElementsByTagName('name')[0])
|
intrName = getText(interrupt.getElementsByTagName('name')[0])
|
||||||
|
@ -77,7 +96,7 @@ def readSVD(path):
|
||||||
if regsEls:
|
if regsEls:
|
||||||
for el in regsEls[0].childNodes:
|
for el in regsEls[0].childNodes:
|
||||||
if el.nodeName == 'register':
|
if el.nodeName == 'register':
|
||||||
peripheral['registers'].append(parseSVDRegister(name, el, baseAddress))
|
peripheral['registers'].append(parseSVDRegister(groupName, el, baseAddress))
|
||||||
elif el.nodeName == 'cluster':
|
elif el.nodeName == 'cluster':
|
||||||
if el.getElementsByTagName('dim'):
|
if el.getElementsByTagName('dim'):
|
||||||
continue # TODO
|
continue # TODO
|
||||||
|
@ -85,7 +104,7 @@ def readSVD(path):
|
||||||
clusterOffset = int(getText(el.getElementsByTagName('addressOffset')[0]), 0)
|
clusterOffset = int(getText(el.getElementsByTagName('addressOffset')[0]), 0)
|
||||||
for regEl in el.childNodes:
|
for regEl in el.childNodes:
|
||||||
if regEl.nodeName == 'register':
|
if regEl.nodeName == 'register':
|
||||||
peripheral['registers'].append(parseSVDRegister(name, regEl, baseAddress + clusterOffset, clusterPrefix))
|
peripheral['registers'].append(parseSVDRegister(groupName, regEl, baseAddress + clusterOffset, clusterPrefix))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -105,7 +124,7 @@ def readSVD(path):
|
||||||
|
|
||||||
return device
|
return device
|
||||||
|
|
||||||
def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
def parseSVDRegister(groupName, regEl, baseAddress, namePrefix=''):
|
||||||
regName = getText(regEl.getElementsByTagName('name')[0])
|
regName = getText(regEl.getElementsByTagName('name')[0])
|
||||||
regDescription = getText(regEl.getElementsByTagName('description')[0])
|
regDescription = getText(regEl.getElementsByTagName('description')[0])
|
||||||
offsetEls = regEl.getElementsByTagName('offset')
|
offsetEls = regEl.getElementsByTagName('offset')
|
||||||
|
@ -138,12 +157,12 @@ def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
||||||
else:
|
else:
|
||||||
msb = int(getText(fieldEl.getElementsByTagName('bitWidth')[0])) + lsb - 1
|
msb = int(getText(fieldEl.getElementsByTagName('bitWidth')[0])) + lsb - 1
|
||||||
fields.append({
|
fields.append({
|
||||||
'name': '{}_{}{}_{}_Pos'.format(peripheralName, namePrefix, regName, fieldName),
|
'name': '{}_{}{}_{}_Pos'.format(groupName, namePrefix, regName, fieldName),
|
||||||
'description': 'Position of %s field.' % fieldName,
|
'description': 'Position of %s field.' % fieldName,
|
||||||
'value': lsb,
|
'value': lsb,
|
||||||
})
|
})
|
||||||
fields.append({
|
fields.append({
|
||||||
'name': '{}_{}{}_{}_Msk'.format(peripheralName, namePrefix, regName, fieldName),
|
'name': '{}_{}{}_{}_Msk'.format(groupName, namePrefix, regName, fieldName),
|
||||||
'description': 'Bit mask of %s field.' % fieldName,
|
'description': 'Bit mask of %s field.' % fieldName,
|
||||||
'value': (0xffffffff >> (31 - (msb - lsb))) << lsb,
|
'value': (0xffffffff >> (31 - (msb - lsb))) << lsb,
|
||||||
})
|
})
|
||||||
|
@ -152,7 +171,7 @@ def parseSVDRegister(peripheralName, regEl, baseAddress, namePrefix=''):
|
||||||
enumDescription = getText(enumEl.getElementsByTagName('description')[0])
|
enumDescription = getText(enumEl.getElementsByTagName('description')[0])
|
||||||
enumValue = int(getText(enumEl.getElementsByTagName('value')[0]), 0)
|
enumValue = int(getText(enumEl.getElementsByTagName('value')[0]), 0)
|
||||||
fields.append({
|
fields.append({
|
||||||
'name': '{}_{}{}_{}_{}'.format(peripheralName, namePrefix, regName, fieldName, enumName),
|
'name': '{}_{}{}_{}_{}'.format(groupName, namePrefix, regName, fieldName, enumName),
|
||||||
'description': enumDescription,
|
'description': enumDescription,
|
||||||
'value': enumValue,
|
'value': enumValue,
|
||||||
})
|
})
|
||||||
|
@ -201,8 +220,13 @@ const (
|
||||||
out.write('\tIRQ_max = {} // Highest interrupt number on this device.\n'.format(intrMax))
|
out.write('\tIRQ_max = {} // Highest interrupt number on this device.\n'.format(intrMax))
|
||||||
out.write(')\n')
|
out.write(')\n')
|
||||||
|
|
||||||
|
# Define peripheral struct types.
|
||||||
for peripheral in device.peripherals:
|
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']
|
address = peripheral['baseAddress']
|
||||||
padNumber = 0
|
padNumber = 0
|
||||||
for register in peripheral['registers']:
|
for register in peripheral['registers']:
|
||||||
|
@ -233,12 +257,18 @@ const (
|
||||||
address = register['address'] + 4
|
address = register['address'] + 4
|
||||||
out.write('}\n')
|
out.write('}\n')
|
||||||
|
|
||||||
|
# Define actual peripheral pointers.
|
||||||
out.write('\n// Peripherals.\nvar (\n')
|
out.write('\n// Peripherals.\nvar (\n')
|
||||||
for peripheral in device.peripherals:
|
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')
|
out.write(')\n')
|
||||||
|
|
||||||
|
# Define bitfields.
|
||||||
for peripheral in device.peripherals:
|
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
|
if not sum(map(lambda r: len(r['bitfields']), peripheral['registers'])): continue
|
||||||
out.write('\n// Bitfields for {name}: {description}\nconst('.format(**peripheral))
|
out.write('\n// Bitfields for {name}: {description}\nconst('.format(**peripheral))
|
||||||
for register in peripheral['registers']:
|
for register in peripheral['registers']:
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче