1 from nmigen
import (Cat
, Const
, Elaboratable
, Module
, Signal
, signed
)
2 from nmigen
.asserts
import (Assert
, AnyConst
, AnySeq
, Assume
)
3 from nmutil
.formaltest
import FHDLTestCase
4 from nmutil
.stageapi
import StageChain
5 from nmigen
.cli
import rtlil
9 from soc
.experiment
.icache
import ICache
11 from nmigen_soc
.wishbone
.sram
import SRAM
12 from nmigen
import Memory
14 class Driver(Elaboratable
):
15 def elaborate(self
, platform
):
20 mem_init
= [(i
*2) |
((i
*2+1) << 32) for i
in range(512)]
21 memory
= Memory(width
=64, depth
=512, init
=mem_init
)
22 sram
= SRAM(memory
=memory
, granularity
=8)
24 m
.submodules
.dut
= dut
= ICache()
25 m
.submodules
.sram
= sram
27 m
.d
.comb
+= sram
.bus
.cyc
.eq(dut
.wb_out
.cyc
)
28 m
.d
.comb
+= sram
.bus
.stb
.eq(dut
.wb_out
.stb
)
29 m
.d
.comb
+= sram
.bus
.we
.eq(dut
.wb_out
.we
)
30 m
.d
.comb
+= sram
.bus
.sel
.eq(dut
.wb_out
.sel
)
31 m
.d
.comb
+= sram
.bus
.adr
.eq(dut
.wb_out
.adr
)
32 m
.d
.comb
+= sram
.bus
.dat_w
.eq(dut
.wb_out
.dat
)
34 m
.d
.comb
+= dut
.wb_in
.ack
.eq(sram
.bus
.ack
)
35 m
.d
.comb
+= dut
.wb_in
.dat
.eq(sram
.bus
.dat_r
)
40 stall_in
= dut
.stall_in
41 stall_out
= dut
.stall_out
42 flush_in
= dut
.flush_in
43 inval_in
= dut
.inval_in
49 class ICacheTestCase(FHDLTestCase
):
50 def test_formal(self
):
51 self
.assertFormal(Driver(), mode
="bmc", depth
=10)
52 self
.assertFormal(Driver(), mode
="cover", depth
=10)
55 vl
= rtlil
.convert(Driver(), ports
=[])
56 with
open("icache_formal.il", "w") as f
:
60 if __name__
== '__main__':