-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_spect_ops_constants_c.py
executable file
·66 lines (49 loc) · 2.02 KB
/
gen_spect_ops_constants_c.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
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import yaml
import sys
import os
import argparse
from datetime import datetime
parser = argparse.ArgumentParser(description='TS SPECT headers generator')
parser.add_argument("-f", "--file", type=str, default="spect_ops_constants.h",
help='Destination file name. Default: "%(default)s"')
parser.add_argument("-c", "--cfg", type=str, default="spect_ops_config.yml",
help='Configuration input file name. Default: "%(default)s"')
args = parser.parse_args()
with open(args.cfg, 'r') as f:
cfg = yaml.safe_load(f)
f = open(args.file, 'w')
file_name = os.path.basename(args.file)
NL = '\n'
H_GUARD = file_name.upper().replace(".", "_")
SPECT_DRAM_OUT_BASE_ADDR_OFFSET = 0x1000
now = datetime.now()
f.write("// Generated on " + now.strftime("%Y-%m-%d %H:%M:%S") + NL )
script_path = os.path.abspath(__file__)
script_name = os.path.basename(script_path)
f.write("// By '" + script_name + "' from 'ts-spect-fw.git'" + NL)
f.write("// Do NOT modify this file, changes will be overwritten by next update" + NL)
f.write(NL)
f.write("#ifndef " + H_GUARD + NL )
f.write("#define " + H_GUARD + NL )
for op in cfg:
f.write(NL)
f.write("// " + op["name"] + NL )
n = op["name"].upper()
if "id" in op.keys() :
f.write("#define SPECT_OP_ID_{0} 0x{1:X}".format(n, op["id"]) + NL)
if "input" in op.keys() and op["input"]:
for input in op["input"]:
d = input["name"].upper()
f.write("#define SPECT_INP_{0}_{1} 0x{2:04X}".format(n, d, input["address"]) + NL)
if "output" in op.keys() and op["output"]:
for output in op["output"]:
d = output["name"].upper()
a = output["address"]
if (a >= SPECT_DRAM_OUT_BASE_ADDR_OFFSET) :
a = a - SPECT_DRAM_OUT_BASE_ADDR_OFFSET # TODO: remove offset manipulation after YML fix
f.write("#define SPECT_OUT_{0}_{1} 0x{2:04X}".format(n, d, a) + NL)
f.write(NL)
f.write("#endif // " + H_GUARD + NL )
f.close()
print(f"File {file_name} successfully written.")