From ad4c597208c009e586de3b464679183c1da1bdc3 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Wed, 7 Feb 2024 17:14:14 -0500 Subject: [PATCH] Update xmlgen.py --- src/xmlgen.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/xmlgen.py b/src/xmlgen.py index e562dcd..4706ffb 100755 --- a/src/xmlgen.py +++ b/src/xmlgen.py @@ -12,6 +12,7 @@ import argparse import os import pprint +from typing import IO, Any, Tuple import yaml import utils # local import @@ -40,6 +41,50 @@ def type_to_format(thedict: dict) -> str: return None return fmt +def open_C_file(fname: str) -> IO[Any]: + """open the C file and write the header""" + fout = open(fname, 'w', encoding='ascii') + print(r"// This file is generated by mcu_generate.py", file=fout) + print(r"// Do not edit this file directly", file=fout) + print(r"// Edit the yaml files in the data directory and run mcu_generate.py", file=fout) + print(r"// to generate this file", file=fout) + print(r"//", file=fout) + print(r"// This file contains the addresses of the zynqmon data", file=fout) + print(r"// and the C calls to initialize the zynqmon data", file=fout) + print(r"//", file=fout) + print("#include \"Tasks.h\"", file=fout) + # include the header file we will write later + header_fname = args.output.replace('.c', '.h') + print(f"#include \"{header_fname}\"", file=fout) + return fout + +def write_C_header(fout: IO[Any], fname: str) -> None: + """write the header file""" + with open(header_fname, encoding="ascii", mode='w') as fheader: + print(r"// This file is generated by mcu_generate.py", file=fheader) + print(r"// Do not edit this file directly", file=fheader) + print(r"// Edit the yaml files in the data directory and run mcu_generate.py", file=fheader) + print(r"// to generate this file", file=fheader) + print(r"//", file=fheader) + print("#ifndef ZYNQMON_ADDRESSES_H", file=fheader) + print("#define ZYNQMON_ADDRESSES_H", file=fheader) + print("#ifdef REV1", file=fheader) + print(f"#define ZMON_VALID_ENTRIES {ZMON_VALID_ENTRIES[0]}", file=fheader) + print("#elif defined(REV2)", file=fheader) + print(f"#define ZMON_VALID_ENTRIES {ZMON_VALID_ENTRIES[1]}", file=fheader) + print("#endif // REV1", file=fheader) + print("#endif // ZYNQMON_ADDRESSES_H", file=fheader) + + +def write_C_call(fout: IO[Any], c: dict, size: int) -> Tuple[int, int]: + """write the C call to generate the filling of the data structures """ + if c['mcu_extra_call'] is None: + print(f"zm_set_{c['mcu_call']}(&zynqmon_data[{size}], {c['start']});", file=fout) + else : + print(f"zm_set_{c['mcu_call']}(&zynqmon_data[{size}], {c['start']}, " + f"{c['mcu_extra_call']});", file=fout) + return (c['start'], c['start'] + int(c['count'])-1) + def make_node(parent: ET.Element, myid: str, thedict: dict, address: int) -> ET.Element: """create the node to be inserted into the xml tree""" @@ -60,6 +105,7 @@ def make_node(parent: ET.Element, myid: str, thedict: dict, address: int) -> ET. print(f"char_count: {thedict['char_count']}, val: {val}") thenode.set('size', str(hex(val))) else: # all other types have masks + # the masks here will be either 32 or 16 bits mask = (1 << width) - 1 is_odd = address % 2 == 1 if not is_odd : @@ -109,6 +155,8 @@ def main(): # start processing the yaml file config = y['config'] sensor_count = 0 # in 16 bit words + summary = [] + categories = [] for c in config: # loop over entries in configuration (sensor category) if args.verbose: print("category:",) @@ -133,6 +181,7 @@ def main(): print(f"sensor: {device}.{sensor}") make_node(pp, sensor, c, sensor_count) sensor_count += sensor_size(c) // 2 + summary.append((device + "." + sensor if device != "" else sensor, sensor_count)) if devices: device = devices.pop(0) else: @@ -146,6 +195,6 @@ def main(): print("writing to file", out_name) tree.write(out_name) - + pprinter.pprint(summary) if __name__ == "__main__": main()