Skip to content

Commit ab1e266

Browse files
committed
Put IO into top level and do address decoding
1 parent b8660af commit ab1e266

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ TESTPATH=asm/test
2727
hwsim:
2828
sbt -Dprogram=$(APP) "testOnly leros.LerosTest"
2929

30+
sim-blink:
31+
sbt -Dprogram=blink -Dtestpath=asm "testOnly leros.LerosTest"
3032

3133
swsim:
3234
sbt -Dprogram=$(APP) "testOnly leros.sim.LerosSimTest"

TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
- [ ] Check if write in Chisel/Verilog is not through a register
4444
* wondering on timing and layout in Quartus
4545
- [ ] Get rid of code duplication in Decode
46-
- [ ] Do memory mapped IO
46+
- [x] Do memory mapped IO
4747
- [ ] Be able to simulate source in asm
4848
- [x] Setup FPGA (Nexys A7)
4949
- [x] Use chipdesign1 for synthesis, OpenOCD for configuration
@@ -60,7 +60,7 @@
6060
- [ ] Any instruction not used by the compiler?
6161
- [ ] load/store byte indirect
6262
- [ ] Does subi sign extend? Do we need a subi? We could use addi with neg. values
63-
- [ ] Get a simple sequential version done
63+
- [x] Get a simple sequential version done
6464
- [ ] Pipelined version follows after sequential
6565
- [ ] Run Morten's C test programs
6666
- [ ] gcc test suit as in Patmos

asm/blink.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
// We need 2.500.000 iterations for a 100 ms tick
44
//
55

6+
// set the IO base address to 0x0f00 (in bytes)
7+
loadhi 0x0f
8+
store r2
9+
ldaddr r2
10+
// the counter
611
loadi 0
712
store r2
813
loop:
14+
915
loadi 255
1016
loadhi 255
1117
loadh2i 38

src/main/scala/leros/Leros.scala

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
1616
val addr = Output(UInt(memAddrWidth.W))
1717
val instr = Input(UInt(16.W))
1818
})
19-
val dmemIO = IO(Flipped(new DataMemIO(memAddrWidth)))
20-
21-
val io = IO(new Bundle {
22-
// val dout = Output(UInt(32.W))
23-
// val sw = Input(UInt(4.W))
24-
val led = Output(UInt(8.W))
25-
})
19+
val dmemIO = IO(Flipped(new DataMemIO(16)))
2620

2721
val alu = Module(new AluAccu(size))
2822

2923
val accu = alu.io.accu
3024

3125
// The main architectural state
3226
val pcReg = RegInit(0.U(memAddrWidth.W))
33-
val addrReg = RegInit(0.U(memAddrWidth.W))
27+
val addrReg = RegInit(0.U(16.W))
3428

3529
val pcNext = WireDefault(pcReg + 1.U)
3630

@@ -54,7 +48,7 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
5448
for (i <- 0 until 4) {
5549
vecAccu(i) := accu(i*8 + 7, i*8)
5650
}
57-
// printf("%x %x %x %x\n", effAddr, effAddrWord, effAddrOff, decout.off)
51+
// printf("%x %x %x %x %x\n", addrReg, effAddr, effAddrWord, effAddrOff, decout.off)
5852

5953
// Data memory, including the register memory
6054
// read in fetch, write in execute
@@ -81,8 +75,6 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
8175

8276
// connection to the external world (for testing)
8377
val exit = RegInit(false.B)
84-
val outReg = RegInit(0.U(32.W))
85-
io.led := outReg
8678

8779
val stateReg = RegInit(fetch)
8880

@@ -114,9 +106,6 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
114106

115107
is (storeInd) {
116108
dmemIO.wr := true.B
117-
// TODO: am I missing here something? See the other store indirect
118-
// TODO: this is a super quick hack to get the LED blinking
119-
outReg := accu
120109
}
121110

122111
is (storeIndB) {

src/main/scala/leros/LerosTop.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ class LerosTop(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Modu
2929
dataMem.io <> leros.dmemIO
3030

3131
// TODO: LED and decoding for it
32-
io.led := leros.io.led
32+
val ledReg = RegInit(0.U(8.W))
33+
io.led := ledReg
34+
// IO is now mapped to 0x0f00, but wrAddr counts in 32-bit words
35+
when((leros.dmemIO.wrAddr === 0x03c0.U) && leros.dmemIO.wr) {
36+
ledReg := leros.dmemIO.wrData(7, 0)
37+
dataMem.io.wr := false.B
38+
}
3339
}
3440

3541
object LerosTop extends App {

src/test/scala/leros/LerosTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LerosTest extends AnyFlatSpec with ChiselScalatestTester {
1919

2020
def testFun(dut: LerosTestTop): Unit = {
2121
var run = true
22-
var maxCycles = 10000
22+
var maxCycles = 1000
2323
while (run) {
2424
val pc = dut.io.dbg.pc.peekInt()
2525
val accu = dut.io.dbg.accu.peekInt()

0 commit comments

Comments
 (0)