-
Notifications
You must be signed in to change notification settings - Fork 2
/
svd2devicex.py
executable file
·58 lines (46 loc) · 1.79 KB
/
svd2devicex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
"""
svd2devicex.py
Create a device.x linker script containing symbols for ISR functions for
PIC32 MCUs. The device.x file can be included by a main linker script.
"""
import argparse
import xml.etree.ElementTree as ET
import sys
def parseargs():
parser = argparse.ArgumentParser()
parser.add_argument("svd", help="Path to SVD file to load")
parser.add_argument("-o", "--output", help="path to output file")
args = parser.parse_args()
return args
def main():
args = parseargs()
svd = args.svd
svdxml = ET.parse(svd)
if args.output:
out = open(args.output, 'w')
else:
out = sys.stdout
intr = svdxml.getroot().findall('.//peripheral[name="INT"]/interrupt')
irq_vectors = {}
for i in intr:
name = i.find('./name').text
vect = int(i.find('./value').text)
irq_vectors[vect] = name
print('/* ISR symbols for MIPS; generated by svd2devicex */\n', file=out)
for vector in range(0, 64):
if vector in irq_vectors:
name = irq_vectors[vector]
print('/* IRQ vector #{} */'.format(vector), file=out)
print('PROVIDE({} = _default_isr_fn);'.format(name), file=out)
print('PROVIDE({}_CONTEXT = _isr_context);'.format(name), file=out)
print('_vector_{}_fn = {};'.format(vector, name), file=out)
print('_vector_{}_context = {}_CONTEXT;'.format(vector, name), file=out)
print('', file=out)
else:
print('/* IRQ vector #{} (unused) */'.format(vector), file=out)
print('PROVIDE(_vector_{}_fn = _default_isr_fn);'.format(vector), file = out)
print('PROVIDE(_vector_{}_context = _isr_context);'.format(vector), file = out)
print('', file=out)
if __name__ == "__main__":
main()