Open martijnbastiaan opened 8 months ago
Having talked about this offline, we envision something like this possible:
-- A circuit mapping registers:
[foo, bar, wibble] <- mmInterconnect @8
( (0x0, 4)
:> (0x4, 4)
:> (0x8, 4)
:> Nil
) -< mainBus
mmReg "foo" -< foo
mmReg "bar" -< bar
mmReg "wibble" -< wibble
-- A circuit mapping devices:
[uartBus, timerBus, wibbleBus] <-
mmInterconnect @16
-- addr size
( (0xA, sMiB 1) -- UART
:> (0xC, sMiB 16) -- Timer
:> (0x8, sMiB 32) -- Wibble
:> Nil) -< mainBus
uartWb -< uartBus
timerWb -< timerBus
wibbleWb -< wibbleBus
where
mmReg :: String -> Circuit (MemoryMapped ...) ()
mmInterconnect :: Vec n (Offset, Size) -> Circuit (MemoryMapped ...) (Vec n (MemoryMapped ...))
Because we don't use the MemoryMap
for the circuit, we sidestep any issues with Clash constant folding.
FWIW, I have handled register space layout at the type level with seemingly good results in my (now mis-named) axi-register. Type inference is decent (although I think can be improved) and the RTL generated seems sensible.
We currently hard code memory addresses all across our code base. As far as I can tell, they are scattered across three parts of our code base:
clash-vexriscv
. It contains a (hard coded) reset vector (which we patch in this repo to be somewhere else, but that's another story).bittide-instances
firmware-binaries
a. Pointers in the rust code b. contents ofmemory.x
describing the addresses and sizes of available memoriesThis has always been undesirable, but lately it has been reaching a boiling point due our stack maturing and us wanting to do more and more in software. To solve this, we basically have two options:
Define a memory map, and integrate it in our hardware designs. This is what https://github.com/bittide/bittide-hardware/pull/315 has proposed, based on https://github.com/bittide/bittide-hardware/issues/47.
Use the power of Clash to create a protocol agnostic wrapper for memory mapped protocols, see a proposal below.
Originally (2) was just a weekend project of mine and I wouldn't have proposed it as an alternative to (1). However, during its implementation I found that:
I'm not sure how much work there is left to be done, but it seems worthwhile to at least investigate to see how much time it would take to get to an MVP.
Entirely untested hackery: