update generate_csr_locations
This commit is contained in:
parent
50ef091578
commit
368bbb6e2b
|
@ -1,32 +1,73 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
reg_names = {
|
class CSRGenerator:
|
||||||
"adc" : ("from_slave", "finished", "arm", "conv"),
|
def __init__(self, json, registers, file):
|
||||||
"dac" : ("from_slave", "to_slave", "finished", "arm", "ss")
|
self.registers = registers
|
||||||
}
|
self.j = json.load(open("csr.json"))
|
||||||
max_num = 8
|
self.file = f
|
||||||
# TODO: make dependent on adc, dac
|
|
||||||
|
|
||||||
def get_reg(j, name, num, pos):
|
def get_reg(self, name, num):
|
||||||
return j["csr_registers"][f"{name}{num}_{pos}"]["addr"]
|
if num is None:
|
||||||
|
regname = f"base_{name}"
|
||||||
|
else:
|
||||||
|
regname = f"base_{name}_{num}"
|
||||||
|
return self.j["csr_registers"][regname]["addr"]
|
||||||
|
def print(self, *args):
|
||||||
|
print(*args, end='', file=f)
|
||||||
|
|
||||||
j = json.load(open("csr.json"))
|
def print_array(self, name, num):
|
||||||
|
if num == 1:
|
||||||
|
self.print(f'csr_t {name} = {self.get_reg(name, None)};\n')
|
||||||
|
else:
|
||||||
|
self.print(f'csr_t {name} = {{', self.get_reg(name, 0))
|
||||||
|
for i in range(i,num):
|
||||||
|
self.print(',', self.get_reg(name, i))
|
||||||
|
self.print('}\n\n')
|
||||||
|
|
||||||
print('''
|
def print_registers(self):
|
||||||
#pragma once
|
for name,num in self.registers:
|
||||||
typedef volatile uint32_t *csr_t;
|
self.print_array(name, num)
|
||||||
#define ADC_MAX 8
|
def print_file(self):
|
||||||
#define DAC_MAX 8
|
self.print(f'''
|
||||||
#ifdef CSR_LOCATIONS
|
#pragma once
|
||||||
''')
|
typedef volatile uint32_t *csr_t;
|
||||||
|
#define ADC_MAX {adc_num}
|
||||||
|
#define DAC_MAX {dac_num}
|
||||||
|
''')
|
||||||
|
self.print_registers()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
dac_num = 8
|
||||||
|
adc_num = 8
|
||||||
|
|
||||||
|
registers = [
|
||||||
|
("dac_sel", dac_num),
|
||||||
|
("dac_finished", dac_num),
|
||||||
|
("dac_arm", dac_num),
|
||||||
|
("from_dac", dac_num),
|
||||||
|
("to_dac", dac_num),
|
||||||
|
("wf_arm", dac_num),
|
||||||
|
("wf_halt_on_finish", dac_num),
|
||||||
|
("wf_finished", dac_num),
|
||||||
|
("wf_time_to_wait", dac_num),
|
||||||
|
("wf_refresh_start", dac_num),
|
||||||
|
("wf_refresh_finished", dac_num),
|
||||||
|
("wf_start_addr", dac_num),
|
||||||
|
|
||||||
|
("adc_finished", adc_num),
|
||||||
|
("adc_arm", adc_num),
|
||||||
|
("from_adc", adc_num),
|
||||||
|
|
||||||
|
("adc_sel_0", 1),
|
||||||
|
("cl_in_loop", 1),
|
||||||
|
("cl_cmd", 1),
|
||||||
|
("cl_word_in", 1),
|
||||||
|
("cl_word_out", 1),
|
||||||
|
("cl_start_cmd", 1),
|
||||||
|
("cl_finish_cmd", 1),
|
||||||
|
]
|
||||||
|
|
||||||
|
CSRGenerator(self, "csr.json", registers, sys.stdout)
|
||||||
|
|
||||||
for conv in iter(reg_names):
|
|
||||||
for reg in reg_names[conv]:
|
|
||||||
print(f"static const csr_t {conv}_{reg}[{max_num}] =", "{")
|
|
||||||
for i in range(0,max_num):
|
|
||||||
print("\t (csr_t)", get_reg(j, conv, i, reg), end='')
|
|
||||||
if i != max_num - 1:
|
|
||||||
print(",")
|
|
||||||
print("\n};")
|
|
||||||
print("#endif // CSR_LOCATION")
|
|
||||||
|
|
Loading…
Reference in New Issue