first attempt at cpu monitor

This commit is contained in:
2026-09-29 21:45:29 -04:00
parent 5b5357c2c4
commit 3ae48990b5
2 changed files with 117 additions and 110 deletions
-13
View File
@@ -61,9 +61,6 @@ class cpu_driver #(
$error($stime, " Drv: external write address 0x%0x is not word aligned\n", addr);
end
// TODO: Drive one external write through the clocking block for one request,
// then return the port to idle
cpuVif.cb.addr <= addr;
cpuVif.cb.wdata <= data;
@@ -81,9 +78,6 @@ class cpu_driver #(
$error($stime, " Drv: external read address 0x%0x is not word aligned\n", addr);
end
// TODO: Keep the request stable until rready, capture the returned
// data, and set a timeout for the response
timed_out = 1'b0;
count = 0;
@@ -109,7 +103,6 @@ class cpu_driver #(
// Drive a start request for one CPU run
task start_cpu();
// TODO: Pulse en_cpu
cpuVif.cb.en_cpu <= 1;
@(cpuVif.cb) cpuVif.cb.en_cpu <= 0;
@@ -122,10 +115,6 @@ class cpu_driver #(
limit = (max_cycles == 0) ? run_timeout : max_cycles;
cycles = 0;
// TODO: Check cpu_halted on each cycle and report how many cycles
// ran. Set last_run_completed only after a real halt. On a timeout, increment
// timeouts and leave the flag low so the testbench can recover.
repeat (limit) begin
@(cpuVif.cb) cycles++;
if (cpuVif.cb.cpu_halted) begin
@@ -154,8 +143,6 @@ class cpu_driver #(
// Stop a program through an external halt and wait for memory ownership
// to return to the external port
task halt_cpu_now();
// TODO: Assert an external halt request and wait, with a bound,
// until ownership returns to the external port
cpuVif.cb.halt_cpu <= 1;
@(cpuVif.cb);
+29 -9
View File
@@ -3,9 +3,15 @@
* keeps enough state to match requests with responses, including responses
* that take more than one cycle.
*/
class cpu_monitor #(int DataSize=32, int AddrSize=14);
class cpu_monitor #(
int DataSize = 32,
int AddrSize = 14
);
virtual interface cpu_if #(.DataSize(DataSize), .AddrSize(AddrSize)) cpuVif;
virtual interface cpu_if #(
.DataSize(DataSize),
.AddrSize(AddrSize)
) cpuVif;
mailbox #(cpu_xbar_item #(DataSize, AddrSize)) mon_box;
@@ -46,13 +52,17 @@ class cpu_monitor #(int DataSize=32, int AddrSize=14);
endfunction : new
// Create a transaction for an observed event and send it to the scoreboard
task send(input trans_kind_e kind,
input logic [AddrSize-1:0] addr, input logic [DataSize-1:0] data,
input logic is_write=1'b0);
task send(input trans_kind_e kind, input logic [AddrSize-1:0] addr,
input logic [DataSize-1:0] data, input logic is_write = 1'b0);
// TODO: Create and send an xbar transaction through the mailbox
$fatal(1, "TODO: Implement cpu_monitor.send");
cpu_xbar_item #(DataSize, AddrSize) txn = new();
txn.kind = kind;
txn.addr = addr;
txn.is_write = is_write;
mon_box.put(txn);
endtask : send
// Match each external read request with its response
@@ -62,7 +72,15 @@ class cpu_monitor #(int DataSize=32, int AddrSize=14);
// shows that rdata is valid. How should you handle register file vs SRAM
// reads?
$fatal(1, "Implement cpu_monitor.observe_external_read");
if (!pending_read) begin
pending_read = 1'b1;
pending_read_addr = cpuVif.cb.addr;
end
if (cpuVif.cb.rready) begin
send(XBAR_READ, pending_read_addr, cpuVif.cb.rdata);
pending_read = 1'b0;
end
endtask : observe_external_read
// Report each CPU data-memory request once
@@ -72,6 +90,7 @@ class cpu_monitor #(int DataSize=32, int AddrSize=14);
// even if the request stays active during an SRAM wait. Clear saved state
// after the request ends.
$fatal(1, "Implement cpu_monitor.observe_cpu_memory");
endtask : observe_cpu_memory
@@ -102,8 +121,8 @@ class cpu_monitor #(int DataSize=32, int AddrSize=14);
if (cpuVif.cb.w_en && !cpuVif.cb.cpu_active) begin
if (log_transactions) begin
$display($stime, " Mon: External write Addr: 0x%04x, Data: 0x%08x\n",
cpuVif.cb.addr, cpuVif.cb.wdata);
$display($stime, " Mon: External write Addr: 0x%04x, Data: 0x%08x\n", cpuVif.cb.addr,
cpuVif.cb.wdata);
end
send(XBAR_WRITE, cpuVif.cb.addr, cpuVif.cb.wdata, 1'b1);
@@ -124,3 +143,4 @@ class cpu_monitor #(int DataSize=32, int AddrSize=14);
endtask : run
endclass : cpu_monitor