Last active
October 2, 2017 19:56
-
-
Save martinribelotta/1aed47d8a65145de501255afe8f83140 to your computer and use it in GitHub Desktop.
Create ARMv7M vendor interrupt table from SVD description file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
if len(sys.argv) < 1: | |
print("Usage: {} <svdfile.svd>".format(sys.argv[0])) | |
regex = r"<interrupt>\s*<name>(\S+)<\/name>\s*<value>(\S+)<\/value>\s*<\/interrupt>" | |
def intname(name): return "0" if not name else "{}_IRQHandler".format(name) | |
def declname(name): return "void {} __attribute__((weak));".format(intname(name)) | |
with open(sys.argv[1]) as f: | |
vector = {int(m.group(2)): m.group(1) for m in re.finditer(regex, f.read())} | |
vector.update(armv7m_handlers) | |
print(vector) | |
print('\n'.join([declname(v) for k, v in vector.items()])); | |
vt = [None] * (max(vector.keys()) + 1) | |
for k, v in vector.items(): vt[k]=v | |
print("\nvoid *vendor_vector_table[] = {{\n{},\n}}".format(',\n'.join(" "+intname(name) for name in vt))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment