Skip to content

Commit

Permalink
Put IO into top level and do address decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
schoeberl committed Oct 8, 2024
1 parent b8660af commit ab1e266
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ TESTPATH=asm/test
hwsim:
sbt -Dprogram=$(APP) "testOnly leros.LerosTest"

sim-blink:
sbt -Dprogram=blink -Dtestpath=asm "testOnly leros.LerosTest"

swsim:
sbt -Dprogram=$(APP) "testOnly leros.sim.LerosSimTest"
Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- [ ] Check if write in Chisel/Verilog is not through a register
* wondering on timing and layout in Quartus
- [ ] Get rid of code duplication in Decode
- [ ] Do memory mapped IO
- [x] Do memory mapped IO
- [ ] Be able to simulate source in asm
- [x] Setup FPGA (Nexys A7)
- [x] Use chipdesign1 for synthesis, OpenOCD for configuration
Expand All @@ -60,7 +60,7 @@
- [ ] Any instruction not used by the compiler?
- [ ] load/store byte indirect
- [ ] Does subi sign extend? Do we need a subi? We could use addi with neg. values
- [ ] Get a simple sequential version done
- [x] Get a simple sequential version done
- [ ] Pipelined version follows after sequential
- [ ] Run Morten's C test programs
- [ ] gcc test suit as in Patmos
Expand Down
6 changes: 6 additions & 0 deletions asm/blink.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
// We need 2.500.000 iterations for a 100 ms tick
//

// set the IO base address to 0x0f00 (in bytes)
loadhi 0x0f
store r2
ldaddr r2
// the counter
loadi 0
store r2
loop:

loadi 255
loadhi 255
loadh2i 38
Expand Down
17 changes: 3 additions & 14 deletions src/main/scala/leros/Leros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
val addr = Output(UInt(memAddrWidth.W))
val instr = Input(UInt(16.W))
})
val dmemIO = IO(Flipped(new DataMemIO(memAddrWidth)))

val io = IO(new Bundle {
// val dout = Output(UInt(32.W))
// val sw = Input(UInt(4.W))
val led = Output(UInt(8.W))
})
val dmemIO = IO(Flipped(new DataMemIO(16)))

val alu = Module(new AluAccu(size))

val accu = alu.io.accu

// The main architectural state
val pcReg = RegInit(0.U(memAddrWidth.W))
val addrReg = RegInit(0.U(memAddrWidth.W))
val addrReg = RegInit(0.U(16.W))

val pcNext = WireDefault(pcReg + 1.U)

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

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

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

val stateReg = RegInit(fetch)

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

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

is (storeIndB) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/leros/LerosTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ class LerosTop(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Modu
dataMem.io <> leros.dmemIO

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

object LerosTop extends App {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/leros/LerosTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LerosTest extends AnyFlatSpec with ChiselScalatestTester {

def testFun(dut: LerosTestTop): Unit = {
var run = true
var maxCycles = 10000
var maxCycles = 1000
while (run) {
val pc = dut.io.dbg.pc.peekInt()
val accu = dut.io.dbg.accu.peekInt()
Expand Down

0 comments on commit ab1e266

Please sign in to comment.