riscv-lab/chisel/playground/src/pipeline/fetch/FetchUnit.scala

47 lines
1.0 KiB
Scala

package cpu.pipeline
import chisel3._
import chisel3.util._
import cpu.defines.Const._
import cpu.CpuConfig
import cpu.defines._
class FetchUnit extends Module {
val io = IO(new Bundle {
val ctrl = new FetchUnitCtrl()
val decodeStage = new FetchUnitDecodeUnit()
val instSram = new InstSram()
})
val boot :: send :: receive :: Nil = Enum(3)
val state = RegInit(boot)
switch(state) {
is(boot) {
state := send
}
is(send) {
state := receive
}
is(receive) {}
}
val pc = RegEnable(io.instSram.addr, (PC_INIT - 4.U), state =/= boot)
io.instSram.addr := MuxCase(
pc + 4.U,
Seq(
io.ctrl.ctrlSignal.do_flush -> io.ctrl.target,
!io.ctrl.ctrlSignal.allow_to_go -> pc
)
)
io.decodeStage.data.valid := state === receive
io.decodeStage.data.pc := pc
io.decodeStage.data.inst := io.instSram.rdata
io.instSram.en := !reset.asBool
io.instSram.wen := 0.U
io.instSram.wdata := 0.U
}