2019-02-24 23:30:57 +01:00
|
|
|
/*
|
|
|
|
(c) Raphaël Jacquot 2019
|
|
|
|
|
|
|
|
This file is part of hp_saturn.
|
|
|
|
|
|
|
|
hp_saturn is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
hp_saturn is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-02-25 09:17:17 +01:00
|
|
|
`default_nettype none
|
2019-02-24 23:30:57 +01:00
|
|
|
|
|
|
|
`ifdef SIM
|
|
|
|
module saturn_top;
|
2019-03-02 22:33:58 +01:00
|
|
|
|
2019-03-03 15:46:21 +01:00
|
|
|
saturn_bus main_bus (
|
2019-03-03 15:19:07 +01:00
|
|
|
.i_clk (clk),
|
2019-03-03 15:46:21 +01:00
|
|
|
.i_clk_en (clk_en),
|
|
|
|
.i_reset (reset),
|
|
|
|
.o_halt (halt),
|
|
|
|
.o_char_to_send (t_led)
|
|
|
|
);
|
|
|
|
|
|
|
|
wire [7:0] t_led;
|
2019-03-03 15:59:02 +01:00
|
|
|
wire [7:0] led;
|
|
|
|
reg [0:0] reset;
|
2019-02-24 23:30:57 +01:00
|
|
|
wire [0:0] halt;
|
2019-03-03 15:59:02 +01:00
|
|
|
reg [0:0] clk;
|
2019-02-24 23:30:57 +01:00
|
|
|
|
|
|
|
initial begin
|
2019-03-02 15:01:00 +01:00
|
|
|
$display("TOP : starting the simulation");
|
2019-03-02 13:22:09 +01:00
|
|
|
clk = 0;
|
|
|
|
reset = 1;
|
2019-02-24 23:30:57 +01:00
|
|
|
@(posedge clk);
|
|
|
|
@(posedge clk);
|
|
|
|
@(posedge clk);
|
2019-03-02 13:22:09 +01:00
|
|
|
reset = 0;
|
2019-03-02 15:01:00 +01:00
|
|
|
$display("TOP : reset done, waiting for instructions");
|
2019-02-24 23:30:57 +01:00
|
|
|
@(posedge halt);
|
2019-03-02 15:01:00 +01:00
|
|
|
$display("TOP : instructed to stop, halt is %b", halt);
|
2019-02-24 23:30:57 +01:00
|
|
|
$finish;
|
|
|
|
end
|
|
|
|
|
2019-03-02 13:22:09 +01:00
|
|
|
always
|
|
|
|
#10 clk = (clk === 1'b0);
|
2019-03-02 22:33:58 +01:00
|
|
|
|
2019-03-03 15:59:02 +01:00
|
|
|
reg [0:0] clk_en;
|
|
|
|
reg [7:0] test;
|
|
|
|
|
|
|
|
initial begin
|
|
|
|
clk_en = 1'b1;
|
|
|
|
test = 8'b1;
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
test <= {test[6:0], test[7]};
|
|
|
|
|
|
|
|
if (reset) begin
|
|
|
|
clk_en <= 1'b1;
|
|
|
|
test <= 8'b1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
`else
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
module saturn_top (
|
|
|
|
clk_25mhz,
|
|
|
|
btn,
|
2019-03-03 17:29:30 +01:00
|
|
|
led,
|
|
|
|
wifi_gpio0
|
2019-03-03 15:59:02 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
input wire [0:0] clk_25mhz;
|
|
|
|
input wire [6:0] btn;
|
|
|
|
output reg [7:0] led;
|
2019-03-04 08:23:53 +01:00
|
|
|
output wire [0:0] wifi_gpio0;
|
2019-03-03 15:59:02 +01:00
|
|
|
|
2019-03-03 17:29:30 +01:00
|
|
|
/* this is necessary, otherwise, the esp32 module reboots the fpga in passthrough */
|
|
|
|
assign wifi_gpio0 = btn[0];
|
2019-03-03 15:59:02 +01:00
|
|
|
|
|
|
|
saturn_bus main_bus (
|
|
|
|
.i_clk (clk_25mhz),
|
|
|
|
.i_clk_en (clk_en),
|
|
|
|
.i_reset (reset),
|
|
|
|
.o_halt (halt),
|
2019-03-03 23:24:50 +01:00
|
|
|
.o_phase (phase),
|
|
|
|
.o_cycle_ctr (cycle_ctr),
|
2019-03-03 15:59:02 +01:00
|
|
|
.o_char_to_send (t_led)
|
|
|
|
);
|
|
|
|
|
2019-03-04 08:23:53 +01:00
|
|
|
reg [25:0] delay;
|
2019-03-03 23:24:50 +01:00
|
|
|
reg [0:0] clk2;
|
2019-03-03 17:29:30 +01:00
|
|
|
reg [0:0] clk_en;
|
|
|
|
reg [0:0] reset;
|
|
|
|
wire [0:0] halt;
|
2019-03-03 23:24:50 +01:00
|
|
|
wire [1:0] phase;
|
|
|
|
wire [31:0] cycle_ctr;
|
2019-03-03 17:29:30 +01:00
|
|
|
wire [7:0] t_led;
|
2019-03-03 15:19:07 +01:00
|
|
|
|
2019-03-04 08:32:34 +01:00
|
|
|
|
|
|
|
/* 1/4 s */
|
2019-03-04 08:44:05 +01:00
|
|
|
// `define DELAY_START 26'h20A1F0
|
|
|
|
// `define TEST_BIT 23
|
|
|
|
|
|
|
|
/* 1/8 s */
|
|
|
|
`define DELAY_START 26'h1050F8
|
|
|
|
`define TEST_BIT 22
|
2019-03-04 08:32:34 +01:00
|
|
|
|
2019-03-04 08:16:27 +01:00
|
|
|
/* 1/16 s */
|
2019-03-04 08:32:34 +01:00
|
|
|
// `define DELAY_START 26'h08287C
|
|
|
|
// `define TEST_BIT 21
|
2019-03-04 08:16:27 +01:00
|
|
|
|
2019-03-04 08:08:02 +01:00
|
|
|
/* 1/32 s */
|
2019-03-04 08:16:27 +01:00
|
|
|
// `define DELAY_START 26'h4143E
|
|
|
|
// `define TEST_BIT 20
|
2019-03-03 15:19:07 +01:00
|
|
|
|
|
|
|
initial begin
|
2019-03-03 17:29:30 +01:00
|
|
|
led = 8'h01;
|
|
|
|
delay = `DELAY_START;
|
|
|
|
reset = 1'b1;
|
2019-03-03 23:24:50 +01:00
|
|
|
clk2 = 1'b0;
|
2019-03-03 15:19:07 +01:00
|
|
|
end
|
|
|
|
|
2019-03-03 15:46:21 +01:00
|
|
|
always @(posedge clk_25mhz) begin
|
2019-03-03 17:29:30 +01:00
|
|
|
delay <= delay + 26'b1;
|
2019-03-04 08:08:02 +01:00
|
|
|
if (delay[`TEST_BIT]) begin
|
2019-03-03 17:29:30 +01:00
|
|
|
delay <= `DELAY_START;
|
|
|
|
reset <= btn[1];
|
2019-03-03 23:24:50 +01:00
|
|
|
clk2 <= ~clk2;
|
|
|
|
end
|
|
|
|
|
|
|
|
if (!clk2) begin
|
2019-03-04 08:44:05 +01:00
|
|
|
// led <= { halt, cycle_ctr[4:0], phase};
|
|
|
|
led <= { halt, cycle_ctr[6:0] };
|
2019-03-03 23:24:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if (clk2 && !halt) begin
|
2019-03-03 15:19:07 +01:00
|
|
|
clk_en <= 1'b1;
|
2019-03-03 23:24:50 +01:00
|
|
|
led <= t_led;
|
2019-03-03 15:19:07 +01:00
|
|
|
end
|
|
|
|
|
2019-03-03 17:29:30 +01:00
|
|
|
if (clk_en)
|
2019-03-03 15:19:07 +01:00
|
|
|
clk_en <= 1'b0;
|
|
|
|
end
|
2019-03-02 13:22:09 +01:00
|
|
|
|
2019-02-24 23:30:57 +01:00
|
|
|
endmodule
|
2019-03-03 15:59:02 +01:00
|
|
|
|
|
|
|
`endif
|