upsilon/firmware/generate_csr_locations.py

27 lines
642 B
Python
Raw Normal View History

2022-07-12 15:36:50 -04:00
#!/usr/bin/python3
import json
reg_names = {
"adc" : ("conv", "sck", "sdo"),
"dac" : ("miso", "ctrl")
}
max_num = 8
def get_reg(j, name, num, pos):
return j["csr_registers"][f"{name}{num}_{pos}"]["addr"]
j = json.load(open("csr.json"))
print('''#pragma once
typedef volatile uint32_t *csr_t;
''')
for conv in iter(reg_names):
for reg in reg_names[conv]:
print(f"const csr_t {conv}_{reg}[{max_num}] =", "{")
for i in range(0,max_num):
2022-07-13 12:11:47 -04:00
print("\t (csr_t)", get_reg(j, conv, i, reg), end='')
2022-07-12 15:36:50 -04:00
if i != max_num - 1:
print(",")
print("\n};")