mirror of
https://github.com/sxpert/hp-saturn
synced 2024-11-16 19:50:19 +01:00
we are now up to reading the first instruction nibbles
This commit is contained in:
parent
8ce2d2a993
commit
3cbd6ac5e1
2 changed files with 66 additions and 15 deletions
|
@ -63,14 +63,20 @@ saturn_control_unit control_unit (
|
|||
.i_phase (i_phase),
|
||||
.i_cycle_ctr (i_cycle_ctr),
|
||||
.i_debug_cycle (dbg_debug_cycle),
|
||||
.i_bus_busy (bus_busy),
|
||||
.o_program_address (ctrl_unit_prog_addr),
|
||||
.o_program_data (ctrl_unit_prog_data),
|
||||
|
||||
.o_no_read (ctrl_unit_no_read),
|
||||
.i_nibble (nibble_in),
|
||||
|
||||
.o_error (ctrl_unit_error)
|
||||
);
|
||||
|
||||
wire [0:0] ctrl_unit_error;
|
||||
wire [4:0] ctrl_unit_prog_addr;
|
||||
wire [4:0] ctrl_unit_prog_data;
|
||||
wire [0:0] ctrl_unit_no_read;
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
|
@ -101,6 +107,9 @@ assign o_debug_cycle = dbg_debug_cycle;
|
|||
*/
|
||||
|
||||
reg [0:0] bus_error;
|
||||
reg [0:0] bus_busy;
|
||||
reg [3:0] nibble_in;
|
||||
|
||||
/*
|
||||
* program list for the bus controller
|
||||
* this is used for the control unit to send the bus controller
|
||||
|
@ -108,10 +117,12 @@ reg [0:0] bus_error;
|
|||
*/
|
||||
reg [4:0] bus_prog_addr;
|
||||
reg [4:0] bus_program[0:31];
|
||||
reg [4:0] next_bus_prog_addr;
|
||||
|
||||
always @(*) begin
|
||||
$write("BUSCTRL %0d: [%d] write prog %d : %5b\n", i_phase, i_cycle_ctr, ctrl_unit_prog_addr, ctrl_unit_prog_data);
|
||||
// $write("BUSCTRL0 %0d: [%d] write prog %d : %5b\n", i_phase, i_cycle_ctr, ctrl_unit_prog_addr, ctrl_unit_prog_data);
|
||||
bus_program[ctrl_unit_prog_addr] = ctrl_unit_prog_data;
|
||||
next_bus_prog_addr = bus_prog_addr + 5'd1;
|
||||
end
|
||||
|
||||
/*
|
||||
|
@ -123,6 +134,7 @@ assign o_halt = bus_error || ctrl_unit_error;
|
|||
initial begin
|
||||
bus_error = 1'b0;
|
||||
bus_prog_addr = 5'd31;
|
||||
bus_busy = 1'b0;
|
||||
end
|
||||
|
||||
/*
|
||||
|
@ -141,13 +153,20 @@ always @(posedge i_clk) begin
|
|||
* in this phase, we can send a command or data from the processor
|
||||
*/
|
||||
if (bus_prog_addr != ctrl_unit_prog_addr) begin
|
||||
$write("BUSCTRL %0d: [%d] %d : %5b ", i_phase, i_cycle_ctr, bus_prog_addr + 5'd1, bus_program[bus_prog_addr + 5'd1]);
|
||||
if (bus_program[bus_prog_addr + 5'd1][4]) begin
|
||||
$write("CMD :");
|
||||
$write("BUSCTRL %0d: [%d] %d : %5b ", i_phase, i_cycle_ctr, next_bus_prog_addr, bus_program[next_bus_prog_addr]);
|
||||
if (bus_program[next_bus_prog_addr][4]) $write("CMD : ");
|
||||
else $write("DATA : ");
|
||||
$write("%h\n", bus_program[next_bus_prog_addr][3:0]);
|
||||
bus_prog_addr <= next_bus_prog_addr;
|
||||
o_bus_is_data <= !bus_program[next_bus_prog_addr][4];
|
||||
o_bus_nibble_out <= bus_program[next_bus_prog_addr][3:0];
|
||||
o_bus_clk_en <= 1'b1;
|
||||
bus_busy <= 1'b1;
|
||||
end else begin
|
||||
if (!ctrl_unit_no_read) begin
|
||||
$display("BUSCTRL %0d: [%d] setting up read", i_phase, i_cycle_ctr);
|
||||
o_bus_clk_en <= 1'b1;
|
||||
end
|
||||
else $write("DATA : %h", bus_program[bus_prog_addr + 5'd1][3:0]);
|
||||
$write("\n");
|
||||
bus_prog_addr <= bus_prog_addr + 5'd1;
|
||||
end
|
||||
end
|
||||
4'b0010:
|
||||
|
@ -155,12 +174,24 @@ always @(posedge i_clk) begin
|
|||
/*
|
||||
* this phase is reserved for reading data from the bus
|
||||
*/
|
||||
if (o_bus_clk_en) begin
|
||||
$display("BUSCTRL %0d: [%d] lowering bus clock_en", i_phase, i_cycle_ctr);
|
||||
o_bus_clk_en <= 1'b0;
|
||||
if (!ctrl_unit_no_read) begin
|
||||
$display("BUSCTRL %0d: [%d] read %h", i_phase, i_cycle_ctr, i_bus_nibble_in);
|
||||
nibble_in <= i_bus_nibble_in;
|
||||
end
|
||||
end
|
||||
end
|
||||
4'b0100:
|
||||
begin
|
||||
/*
|
||||
* this phase is when the instruction decoder does it's job
|
||||
*/
|
||||
if ((bus_prog_addr == ctrl_unit_prog_addr) && bus_busy) begin
|
||||
$display("BUSCTRL %0d: [%d] done sending the entire program", i_phase, i_cycle_ctr);
|
||||
bus_busy <= 1'b0;
|
||||
end
|
||||
end
|
||||
4'b1000:
|
||||
begin
|
||||
|
@ -175,6 +206,7 @@ always @(posedge i_clk) begin
|
|||
if (i_reset) begin
|
||||
bus_error <= 1'b0;
|
||||
bus_prog_addr <= 5'd31;
|
||||
bus_busy <= 1'b0;
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,9 +30,14 @@ module saturn_control_unit (
|
|||
i_cycle_ctr,
|
||||
i_debug_cycle,
|
||||
|
||||
i_bus_busy,
|
||||
|
||||
o_program_data,
|
||||
o_program_address,
|
||||
|
||||
o_no_read,
|
||||
i_nibble,
|
||||
|
||||
o_error
|
||||
);
|
||||
|
||||
|
@ -43,9 +48,14 @@ input wire [1:0] i_phase;
|
|||
input wire [31:0] i_cycle_ctr;
|
||||
input wire [0:0] i_debug_cycle;
|
||||
|
||||
input wire [0:0] i_bus_busy;
|
||||
|
||||
output reg [4:0] o_program_data;
|
||||
output reg [4:0] o_program_address;
|
||||
|
||||
output reg [0:0] o_no_read;
|
||||
input wire [3:0] i_nibble;
|
||||
|
||||
output wire [0:0] o_error;
|
||||
assign o_error = control_unit_error;
|
||||
|
||||
|
@ -70,6 +80,7 @@ reg [4:0] bus_prog_addr;
|
|||
initial begin
|
||||
o_program_address = 5'd31;
|
||||
o_program_data = 5'd0;
|
||||
o_no_read = 1'b0;
|
||||
control_unit_error = 1'b0;
|
||||
just_reset = 1'b1;
|
||||
control_unit_ready = 1'b0;
|
||||
|
@ -82,12 +93,12 @@ always @(posedge i_clk) begin
|
|||
/* this happend right after reset */
|
||||
`ifdef SIM
|
||||
if (!i_reset)
|
||||
$display("CTRL %0d: [%d] we are in the control unit", i_phase, i_cycle_ctr);
|
||||
$display("CTRL %0d: [%d] we are in the control unit", i_phase, i_cycle_ctr);
|
||||
`endif
|
||||
just_reset <= 1'b0;
|
||||
o_program_data <= {1'b1, `BUSCMD_LOAD_PC };
|
||||
`ifdef SIM
|
||||
$display("CTRL %0d: [%d] pushing LOAD_PC command to pos %d", i_phase, i_cycle_ctr, bus_prog_addr);
|
||||
$display("CTRL %0d: [%d] pushing LOAD_PC command to pos %d", i_phase, i_cycle_ctr, bus_prog_addr);
|
||||
`endif
|
||||
/* push the current program pointer out,
|
||||
* increment the program pointer
|
||||
|
@ -102,7 +113,7 @@ always @(posedge i_clk) begin
|
|||
o_program_address <= bus_prog_addr;
|
||||
bus_prog_addr <= bus_prog_addr + 1;
|
||||
`ifdef SIM
|
||||
$write("CTRL %0d: [%d] pushing ADDR[%0d] = 0", i_phase, i_cycle_ctr, bus_prog_addr);
|
||||
$write("CTRL %0d: [%d] pushing ADDR[%0d] = 0", i_phase, i_cycle_ctr, bus_prog_addr);
|
||||
`endif
|
||||
if (bus_prog_addr == 5'd5) begin
|
||||
control_unit_ready <= 1'b1;
|
||||
|
@ -116,17 +127,25 @@ always @(posedge i_clk) begin
|
|||
end
|
||||
|
||||
/* this happend otherwise */
|
||||
if (!i_debug_cycle && control_unit_ready) begin
|
||||
if (!i_debug_cycle && control_unit_ready && !i_bus_busy) begin
|
||||
|
||||
`ifdef SIM
|
||||
$display("CTRL %0d: [%d] starting to do things", i_phase, i_cycle_ctr);
|
||||
`endif
|
||||
control_unit_error <= 1'b1;
|
||||
// `ifdef SIM
|
||||
// $display("CTRL %0d: [%d] starting to do things", i_phase, i_cycle_ctr);
|
||||
// `endif
|
||||
if (i_cycle_ctr == 10) begin
|
||||
control_unit_error <= 1'b1;
|
||||
$display("CTRL %0d: [%d] enough cycles for now", i_phase, i_cycle_ctr);
|
||||
end
|
||||
|
||||
if (i_phases[2]) begin
|
||||
$display("CTRL %0d: [%d] interpreting %h", i_phase, i_cycle_ctr, i_nibble);
|
||||
end
|
||||
end
|
||||
|
||||
if (i_reset) begin
|
||||
o_program_address <= 5'd31;
|
||||
o_program_data <= 5'd0;
|
||||
o_no_read <= 1'b0;
|
||||
control_unit_error <= 1'b0;
|
||||
just_reset <= 1'b1;
|
||||
control_unit_ready <= 1'b0;
|
||||
|
|
Loading…
Reference in a new issue