From 6cbc83f1ab68f8a0b8dbfa5c16b8c3ad13f8b6ad Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Tue, 12 Jul 2022 15:36:50 -0400 Subject: [PATCH] add generate_csr_locations --- firmware/Makefile | 3 +++ firmware/generate_csr_locations.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 firmware/generate_csr_locations.py diff --git a/firmware/Makefile b/firmware/Makefile index d1e1f7c..19adbf4 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -8,3 +8,6 @@ clean: overlay.dts overlay.config: csr.json litex_json2dts_zephyr.py # NOTE: Broken in LiteX 2022.4. $(DEVICETREE_GEN_DIR)/litex_json2dts_zephyr.py --dts overlay.dts --config overlay.config csr.json + +pin_io.h: csr.json generate_csr_locations.py + python3 generate_csr_locations.py > pin_io.h diff --git a/firmware/generate_csr_locations.py b/firmware/generate_csr_locations.py new file mode 100644 index 0000000..f7585f3 --- /dev/null +++ b/firmware/generate_csr_locations.py @@ -0,0 +1,26 @@ +#!/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): + print("\t", get_reg(j, conv, i, reg), end='') + if i != max_num - 1: + print(",") + print("\n};")