Skip to content
Snippets Groups Projects
Commit b0bc05ed authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Add banks

parent 42929451
No related branches found
No related tags found
2 merge requests!5Master,!2Resolve "Add support for banks on FPGA"
"""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
{
"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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment