hp-saturn/saturn_core.v

208 lines
4 KiB
Coq
Raw Normal View History

2019-02-06 10:40:55 +01:00
/*
* Licence: GPLv3 or later
*/
2019-02-04 20:36:47 +01:00
`default_nettype none //
2019-02-11 21:29:04 +01:00
// `include "bus_commands.v"
// `include "hp48_00_bus.v"
// `include "dbg_module.v"
`include "saturn-decoder.v"
2019-02-04 15:02:33 +01:00
/**************************************************************************************************
*
*
2019-02-05 08:49:14 +01:00
*
*
*
*/
2019-02-06 10:40:55 +01:00
2019-02-04 17:14:08 +01:00
`ifdef SIM
2019-02-04 18:17:14 +01:00
module saturn_core (
2019-02-04 15:02:33 +01:00
input clk,
input reset,
output halt,
2019-02-07 22:54:06 +01:00
output [3:0] busstate,
2019-02-09 19:18:58 +01:00
output [11:0] decstate
2019-02-04 18:17:14 +01:00
);
2019-02-04 17:46:29 +01:00
`else
2019-02-04 18:17:14 +01:00
module saturn_core (
input clk_25mhz,
2019-02-10 12:04:53 +01:00
input [ 6:0] btn,
2019-02-04 22:08:17 +01:00
output [7:0] led
2019-02-04 09:59:35 +01:00
);
2019-02-04 22:08:17 +01:00
wire clk;
wire reset;
2019-02-07 22:54:06 +01:00
reg clk2;
2019-02-04 18:17:14 +01:00
assign clk = clk_25mhz;
assign reset = btn[1];
`endif
2019-02-04 09:59:35 +01:00
2019-02-07 22:54:06 +01:00
// clocks
2019-02-11 20:27:51 +01:00
reg [1:0] clk_phase;
reg en_reset;
2019-02-11 19:24:57 +01:00
reg en_debugger; // phase 0
reg en_bus_send; // phase 0
reg en_bus_recv; // phase 1
reg en_alu_prep; // phase 1
reg en_alu_calc; // phase 2
reg en_inst_dec; // phase 2
2019-02-11 19:49:22 +01:00
reg en_alu_save; // phase 3
2019-02-11 19:24:57 +01:00
reg en_inst_exec; // phase 3
2019-02-11 19:49:22 +01:00
reg clock_end;
2019-02-11 20:27:51 +01:00
reg [31:0] cycle_ctr;
reg [31:0] max_cycle;
2019-02-07 22:54:06 +01:00
2019-02-04 09:59:35 +01:00
// state machine stuff
2019-02-07 22:54:06 +01:00
wire halt;
2019-02-04 09:59:35 +01:00
2019-02-11 19:49:22 +01:00
// hp48_bus bus_ctrl (
// .strobe (bus_strobe),
// .reset (reset),
// .address (bus_address),
// .command (bus_command),
// .nibble_in (bus_nibble_in),
// .nibble_out (bus_nibble_out),
// .bus_error (bus_error)
// );
2019-02-11 21:29:04 +01:00
saturn_decoder i_decoder (
.i_clk (clk),
.i_reset (reset),
.i_cycles (cycle_ctr),
.i_en_dec (en_inst_dec),
.i_en_exec (en_inst_exec),
// .i_stalled (stalled),
.i_nibble (nibble_in)
);
2019-02-07 22:54:06 +01:00
initial
begin
2019-02-11 19:24:57 +01:00
clk_phase = 0;
2019-02-11 19:49:22 +01:00
en_debugger = 0; // phase 0
en_bus_send = 0; // phase 0
en_bus_recv = 0; // phase 1
en_alu_prep = 0; // phase 1
en_alu_calc = 0; // phase 2
en_inst_dec = 0; // phase 2
en_alu_save = 0; // phase 3
en_inst_exec = 0; // phase 3
clock_end = 0;
2019-02-11 09:13:16 +01:00
cycle_ctr = 0;
2019-02-07 22:54:06 +01:00
2019-02-11 20:27:51 +01:00
`ifdef DEBUG_CLOCKS
$monitor("RST %b | CLK %b | CLKP %d | CYCL %d | eRST %b | eDBG %b | eBSND %b | eBRECV %b | eAPR %b | eACALC %b | eINDC %b | eASAVE %b | eINDX %b",
reset, clk, clk_phase, cycle_ctr, en_reset,
en_debugger, en_bus_send,
2019-02-11 19:49:22 +01:00
en_bus_recv, en_alu_prep,
en_alu_calc, en_inst_dec,
en_alu_save, en_inst_exec);
2019-02-11 20:27:51 +01:00
`endif
2019-02-07 22:54:06 +01:00
end
2019-02-07 22:54:06 +01:00
//--------------------------------------------------------------------------------------------------
//
// clock generation
//
//--------------------------------------------------------------------------------------------------
2019-02-04 17:46:29 +01:00
2019-02-11 19:24:57 +01:00
always @(posedge clk) begin
if (!reset) begin
2019-02-11 20:27:51 +01:00
clk_phase <= clk_phase + 1;
2019-02-11 19:49:22 +01:00
en_debugger <= clk_phase[1:0] == 0;
en_bus_send <= clk_phase[1:0] == 0;
en_bus_recv <= clk_phase[1:0] == 1;
en_alu_prep <= clk_phase[1:0] == 1;
en_alu_calc <= clk_phase[1:0] == 2;
en_inst_dec <= clk_phase[1:0] == 2;
en_alu_save <= clk_phase[1:0] == 3;
en_inst_exec <= clk_phase[1:0] == 3;
2019-02-11 20:27:51 +01:00
cycle_ctr <= cycle_ctr + (clk_phase[1:0] == 0);
2019-02-11 19:49:22 +01:00
// stop after 50 clocks
2019-02-11 20:27:51 +01:00
if (cycle_ctr == (max_cycle + 1))
2019-02-11 19:49:22 +01:00
clock_end <= 1;
end else begin
2019-02-11 20:27:51 +01:00
clk_phase <= ~0;
2019-02-11 19:49:22 +01:00
en_debugger <= 0;
en_bus_send <= 0;
en_bus_recv <= 0;
en_alu_prep <= 0;
en_alu_calc <= 0;
en_inst_dec <= 0;
en_alu_save <= 0;
en_inst_exec <= 0;
clock_end <= 0;
2019-02-11 20:27:51 +01:00
cycle_ctr <= ~0;
max_cycle <= 50;
2019-02-11 19:24:57 +01:00
end
end
2019-02-04 09:59:35 +01:00
2019-02-11 21:29:04 +01:00
// always @(posedge clk)
// if (en_debugger)
// $display(cycle_ctr);
reg [3:0] nibble_in;
2019-02-07 22:54:06 +01:00
2019-02-11 21:29:04 +01:00
always @(posedge clk)
if (en_bus_recv)
case (cycle_ctr)
0: nibble_in <= 0;
1: nibble_in <= 0;
2: clock_end <= 1;
endcase
2019-02-07 22:54:06 +01:00
2019-02-11 20:27:51 +01:00
assign halt = clock_end;
2019-02-07 22:54:06 +01:00
2019-02-04 22:08:17 +01:00
// Verilator lint_off UNUSED
//wire [N-1:0] unused;
//assign unused = { };
// Verilator lint_on UNUSED
2019-02-04 09:59:35 +01:00
endmodule
`ifdef SIM
2019-02-04 17:46:29 +01:00
module saturn_tb;
2019-02-04 15:02:33 +01:00
reg clk;
reg reset;
2019-02-04 09:59:35 +01:00
wire halt;
2019-02-07 22:54:06 +01:00
wire [3:0] busstate;
2019-02-09 19:18:58 +01:00
wire [11:0] decstate;
2019-02-04 09:59:35 +01:00
saturn_core saturn (
2019-02-04 15:02:33 +01:00
.clk (clk),
.reset (reset),
.halt (halt),
2019-02-07 22:54:06 +01:00
.busstate (busstate),
2019-02-04 15:02:33 +01:00
.decstate (decstate)
2019-02-04 09:59:35 +01:00
);
always
#10 clk = (clk === 1'b0);
initial begin
2019-02-04 15:02:33 +01:00
//$monitor ("c %b | r %b | run %h | dec %h", clk, reset, runstate, decstate);
2019-02-04 09:59:35 +01:00
end
initial begin
2019-02-04 15:02:33 +01:00
$display("starting the simulation");
2019-02-04 09:59:35 +01:00
clk <= 0;
reset <= 1;
@(posedge clk);
2019-02-07 22:54:06 +01:00
@(posedge clk);
@(posedge clk);
2019-02-04 09:59:35 +01:00
reset <= 0;
@(posedge halt);
$finish;
end
endmodule
2019-02-04 17:46:29 +01:00
`else
2019-02-04 09:59:35 +01:00
`endif