Skip to content

Commit 141269b

Browse files
author
Sebastien Bourdeauducq
committedMay 16, 2012
Get CSR base addresses from include file
1 parent bb79817 commit 141269b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎cmacros.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import re
2+
3+
def get_macros(filename):
4+
f = open(filename, "r")
5+
r = {}
6+
for line in f:
7+
match = re.match("\w*#define\s+(\w+)\s+(.*)", line, re.IGNORECASE)
8+
if match:
9+
r[match.group(1)] = match.group(2)
10+
return r

‎top.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from migen.bus import wishbone, wishbone2asmi, csr, wishbone2csr, dfi
77

88
from milkymist import m1crg, lm32, norflash, uart, sram, s6ddrphy, dfii, asmicon
9+
from cmacros import get_macros
910
from constraints import Constraints
1011

1112
MHz = 1000000
@@ -56,6 +57,12 @@ def ddrphy_clocking(crg, phy):
5657
comb = [getattr(phy, name).eq(getattr(crg, name)) for name in names]
5758
return Fragment(comb)
5859

60+
csr_macros = get_macros("common/csrbase.h")
61+
def csr_offset(name):
62+
base = int(csr_macros[name + "_BASE"], 0)
63+
assert((base >= 0xe0000000) and (base <= 0xe0010000))
64+
return (base - 0xe0000000)//0x800
65+
5966
def get():
6067
#
6168
# ASMI
@@ -68,7 +75,8 @@ def get():
6875
# DFI
6976
#
7077
ddrphy0 = s6ddrphy.S6DDRPHY(sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d)
71-
dfii0 = dfii.DFIInjector(1, sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d, sdram_phy.nphases)
78+
dfii0 = dfii.DFIInjector(csr_offset("DFII"),
79+
sdram_geom.mux_a, sdram_geom.bank_a, sdram_phy.dfi_d, sdram_phy.nphases)
7280
dficon0 = dfi.Interconnect(dfii0.master, ddrphy0.dfi)
7381
dficon1 = dfi.Interconnect(asmicon0.dfi, dfii0.slave)
7482

@@ -103,7 +111,7 @@ def get():
103111
#
104112
# CSR
105113
#
106-
uart0 = uart.UART(0, clk_freq, baud=115200)
114+
uart0 = uart.UART(csr_offset("UART"), clk_freq, baud=115200)
107115
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
108116
uart0.bank.interface,
109117
dfii0.bank.interface

0 commit comments

Comments
 (0)