-
Notifications
You must be signed in to change notification settings - Fork 11
/
svd2c
executable file
·58 lines (43 loc) · 1.32 KB
/
svd2c
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/env python
# -----------------------------------------------------------------------------
"""
Convert x.svd to x.h
x.svd is a CMSIS System View Description file describing a device.
x.h is the same information presented as C code.
"""
# -----------------------------------------------------------------------------
import os
import sys
import soc
# -----------------------------------------------------------------------------
def pr_err(*args):
sys.stderr.write(' '.join(map(str,args)) + '\n')
sys.stderr.flush()
def pr_usage(argv):
pr_err('Usage: %s <input_file> <output_file>' % argv[0])
def error(msg, usage = False):
pr_err(msg)
if usage:
pr_usage(sys.argv)
sys.exit(1)
def Process_Options(argv):
"""process command line options"""
global infile, outfile
# get the input file
if len(sys.argv) < 2:
error('must specify input file', True)
infile = sys.argv[1]
if not os.path.exists(infile):
error('%s: input file does not exist' % infile, True)
# get the output file
if len(sys.argv) < 3:
error('must specify output file', True)
outfile = sys.argv[2]
def main():
Process_Options(sys.argv)
d = soc.build_device(infile)
f = open(outfile, 'w')
f.write('%s\n' % d.cstr())
f.close()
main()
# -----------------------------------------------------------------------------