Skip to content

Commit 70f313d

Browse files
Functioning core program loading and dispatching
1 parent d8c1611 commit 70f313d

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

src/main/scala/main/Core.scala

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,41 @@ import _root_.circt.stage.ChiselStage
44

55
class Core extends Module {
66
val io = IO(new Bundle {
7-
val operation = Input(Operation());
8-
val immediate_a = Input(UInt(8.W));
9-
val immediate_b = Input(UInt(8.W));
7+
val debug_memory_write = Input(Bool());
8+
val debug_memory_write_address = Input(UInt(8.W));
9+
val debug_memory_write_data = Input(UInt(8.W));
10+
11+
val debug_dispatcher_thread_requesting_opcode = Input(Bool());
12+
val debug_dispatcher_thread_program_pointer = Input(UInt(8.W));
13+
14+
val debug_dispatcher_opcode = Output(Operation());
15+
val debug_dispatcher_program_pointer = Output(UInt(8.W));
1016
});
17+
18+
val memory = Module(new Memory());
19+
val dispatcher = Module(new Dispatcher());
20+
21+
memory.io.readPorts(0).enable := dispatcher.io.read_requested;
22+
memory.io.readPorts(0).address := dispatcher.io.read_program_pointer;
23+
24+
memory.io.writePorts(0).enable := io.debug_memory_write;
25+
memory.io.writePorts(0).address := io.debug_memory_write_address;
26+
memory.io.writePorts(0).data := io.debug_memory_write_data;
27+
28+
dispatcher.io.thread_requesting_opcode := io.debug_dispatcher_thread_requesting_opcode;
29+
dispatcher.io.thread_program_pointer := io.debug_dispatcher_thread_program_pointer;
30+
31+
val read_ready_delayed = RegNext(dispatcher.io.read_requested, false.B);
32+
dispatcher.io.read_ready := read_ready_delayed;
33+
dispatcher.io.read_opcode := Operation.safe(memory.io.readPorts(0).data(3, 0))._1;
34+
35+
// when(true.B) {
36+
// printf(p"\t[Core]=====");
37+
// printf(p"\n\tdebug.thread_requesting_opcode=${io.debug_dispatcher_thread_requesting_opcode}");
38+
// printf(p"\n\tdispatcher.read_requested=${dispatcher.io.read_requested}");
39+
// printf(p"\n\tread_ready_delayed=${read_ready_delayed}\n\n");
40+
// }
41+
42+
io.debug_dispatcher_opcode := dispatcher.io.opcode;
43+
io.debug_dispatcher_program_pointer := dispatcher.io.program_pointer;
1144
}

src/main/scala/main/Memory.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ class Memory extends Module {
66
val io = IO(new SRAMInterface(1024, UInt(8.W), 1, 1, 0));
77

88
val memory = SRAM(1024, UInt(8.W), 1, 1, 0);
9+
10+
io.readPorts(0) <> memory.readPorts(0);
11+
io.writePorts(0) <> memory.writePorts(0);
912
}

src/test/scala/main/CoreTest.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import chisel3._
2+
import chiseltest._
3+
import org.scalatest.flatspec.AnyFlatSpec
4+
5+
class CoreTest extends AnyFlatSpec with ChiselScalatestTester {
6+
"Core" should "work" in {
7+
test(new Core) { dut =>
8+
dut.io.debug_memory_write.poke(true.B);
9+
dut.io.debug_memory_write_address.poke(1.U(8.W));
10+
dut.io.debug_memory_write_data.poke(1.U(8.W));
11+
12+
dut.clock.step(1);
13+
14+
dut.io.debug_dispatcher_thread_requesting_opcode.poke(true.B);
15+
dut.io.debug_dispatcher_thread_program_pointer.poke(1.U(8.W));
16+
17+
dut.clock.step(1);
18+
19+
dut.clock.step(1);
20+
21+
dut.clock.step(1);
22+
23+
dut.io.debug_dispatcher_opcode.expect(Operation.Add);
24+
dut.io.debug_dispatcher_program_pointer.expect(1.U(8.W));
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)