diff --git a/fpga_device_manager/Banks.py b/fpga_device_manager/Banks.py new file mode 100644 index 0000000000000000000000000000000000000000..2a63526beb894f4a7d5cb954709d7e7e6cf67f31 --- /dev/null +++ b/fpga_device_manager/Banks.py @@ -0,0 +1,43 @@ +"""Module that manages FPGA banks.""" +import json +from typing import Optional, Tuple, Iterable, Generator, Iterator + +_banks = {} + +VOLTAGES = {1.2, 1.5, 1.8, 2.5, 3.3} + + +class FPGABank: + """Represents a bank on the FPGA.""" + def __init__(self, name, voltage=3.3): + self.name = name + self.voltage = voltage + + +def init(filename: str) -> None: + """ + Initializes the FPGA bank database by loading the bank configuration from the specified filename. The file must be + in JSON format and contains bank settings, indexed by the FPGA's bank names. + + :param filename: FPGA bank configuration file + """ + global _banks + _banks = {} + + try: + with open(filename, "r") as file: + bank_data = json.load(file) + + for bank, bank_args in bank_data.items(): + voltage = bank_args["voltage"] + if voltage in VOLTAGES: + _banks[bank] = FPGABank(name=bank, + voltage=voltage) + else: + raise Exception("invalid voltage") + + except OSError as e: + raise Exception("failed to load bank data file: %s" % e) + +def get_voltage(bank_id: int) -> float: + return _banks.get(str(bank_id), _banks["0"]).voltage diff --git a/fpga_device_manager/res/data/banks.json b/fpga_device_manager/res/data/banks.json new file mode 100644 index 0000000000000000000000000000000000000000..e17e74122b5530e9001d86eb86223b3448098b3c --- /dev/null +++ b/fpga_device_manager/res/data/banks.json @@ -0,0 +1,20 @@ +{ + "0": { + "voltage": 3.3 + }, + "1": { + "voltage": 2.5 + }, + "2": { + "voltage": 3.3 + }, + "3": { + "voltage": 2.5 + }, + "4": { + "voltage": 3.3 + }, + "5": { + "voltage": 3.3 + } +} \ No newline at end of file