mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-19 03:37:57 -04:00
FPGA: Format verilog code
This commit is contained in:
parent
e04aacda48
commit
3514d7ef3c
30 changed files with 3477 additions and 3579 deletions
|
@ -13,54 +13,54 @@
|
|||
|
||||
`default_nettype none
|
||||
|
||||
module timer(
|
||||
input wire clk,
|
||||
input wire reset_n,
|
||||
module timer (
|
||||
input wire clk,
|
||||
input wire reset_n,
|
||||
|
||||
input wire cs,
|
||||
input wire we,
|
||||
input wire cs,
|
||||
input wire we,
|
||||
|
||||
input wire [7 : 0] address,
|
||||
input wire [31 : 0] write_data,
|
||||
output wire [31 : 0] read_data,
|
||||
output wire ready
|
||||
);
|
||||
input wire [ 7 : 0] address,
|
||||
input wire [31 : 0] write_data,
|
||||
output wire [31 : 0] read_data,
|
||||
output wire ready
|
||||
);
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Internal constant and parameter definitions.
|
||||
//----------------------------------------------------------------
|
||||
localparam ADDR_CTRL = 8'h08;
|
||||
localparam CTRL_START_BIT = 0;
|
||||
localparam CTRL_STOP_BIT = 1;
|
||||
localparam ADDR_CTRL = 8'h08;
|
||||
localparam CTRL_START_BIT = 0;
|
||||
localparam CTRL_STOP_BIT = 1;
|
||||
|
||||
localparam ADDR_STATUS = 8'h09;
|
||||
localparam ADDR_STATUS = 8'h09;
|
||||
localparam STATUS_RUNNING_BIT = 0;
|
||||
|
||||
localparam ADDR_PRESCALER = 8'h0a;
|
||||
localparam ADDR_TIMER = 8'h0b;
|
||||
localparam ADDR_PRESCALER = 8'h0a;
|
||||
localparam ADDR_TIMER = 8'h0b;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Registers including update variables and write enable.
|
||||
//----------------------------------------------------------------
|
||||
reg [31 : 0] prescaler_reg;
|
||||
reg prescaler_we;
|
||||
reg [31 : 0] prescaler_reg;
|
||||
reg prescaler_we;
|
||||
|
||||
reg [31 : 0] timer_reg;
|
||||
reg timer_we;
|
||||
reg [31 : 0] timer_reg;
|
||||
reg timer_we;
|
||||
|
||||
reg start_reg;
|
||||
reg start_new;
|
||||
reg start_reg;
|
||||
reg start_new;
|
||||
|
||||
reg stop_reg;
|
||||
reg stop_new;
|
||||
reg stop_reg;
|
||||
reg stop_new;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Wires.
|
||||
//----------------------------------------------------------------
|
||||
reg [31 : 0] tmp_read_data;
|
||||
reg [31 : 0] tmp_read_data;
|
||||
reg tmp_ready;
|
||||
|
||||
wire core_running;
|
||||
|
@ -77,44 +77,43 @@ module timer(
|
|||
//----------------------------------------------------------------
|
||||
// core instantiation.
|
||||
//----------------------------------------------------------------
|
||||
timer_core core(
|
||||
.clk(clk),
|
||||
.reset_n(reset_n),
|
||||
timer_core core (
|
||||
.clk(clk),
|
||||
.reset_n(reset_n),
|
||||
|
||||
.prescaler_init(prescaler_reg),
|
||||
.timer_init(timer_reg),
|
||||
.start(start_reg),
|
||||
.stop(stop_reg),
|
||||
.prescaler_init(prescaler_reg),
|
||||
.timer_init(timer_reg),
|
||||
.start(start_reg),
|
||||
.stop(stop_reg),
|
||||
|
||||
.curr_timer(core_curr_timer),
|
||||
.running(core_running)
|
||||
);
|
||||
.curr_timer(core_curr_timer),
|
||||
.running(core_running)
|
||||
);
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// reg_update
|
||||
//----------------------------------------------------------------
|
||||
always @ (posedge clk)
|
||||
begin : reg_update
|
||||
if (!reset_n) begin
|
||||
start_reg <= 1'h0;
|
||||
stop_reg <= 1'h0;
|
||||
prescaler_reg <= 32'h0;
|
||||
timer_reg <= 32'h0;
|
||||
end
|
||||
else begin
|
||||
start_reg <= start_new;
|
||||
stop_reg <= stop_new;
|
||||
always @(posedge clk) begin : reg_update
|
||||
if (!reset_n) begin
|
||||
start_reg <= 1'h0;
|
||||
stop_reg <= 1'h0;
|
||||
prescaler_reg <= 32'h0;
|
||||
timer_reg <= 32'h0;
|
||||
end
|
||||
else begin
|
||||
start_reg <= start_new;
|
||||
stop_reg <= stop_new;
|
||||
|
||||
if (prescaler_we) begin
|
||||
prescaler_reg <= write_data;
|
||||
end
|
||||
|
||||
if (timer_we) begin
|
||||
timer_reg <= write_data;
|
||||
end
|
||||
if (prescaler_we) begin
|
||||
prescaler_reg <= write_data;
|
||||
end
|
||||
end // reg_update
|
||||
|
||||
if (timer_we) begin
|
||||
timer_reg <= write_data;
|
||||
end
|
||||
end
|
||||
end // reg_update
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -122,56 +121,55 @@ module timer(
|
|||
//
|
||||
// The interface command decoding logic.
|
||||
//----------------------------------------------------------------
|
||||
always @*
|
||||
begin : api
|
||||
start_new = 1'h0;
|
||||
stop_new = 1'h0;
|
||||
prescaler_we = 1'h0;
|
||||
timer_we = 1'h0;
|
||||
tmp_read_data = 32'h0;
|
||||
tmp_ready = 1'h0;
|
||||
always @* begin : api
|
||||
start_new = 1'h0;
|
||||
stop_new = 1'h0;
|
||||
prescaler_we = 1'h0;
|
||||
timer_we = 1'h0;
|
||||
tmp_read_data = 32'h0;
|
||||
tmp_ready = 1'h0;
|
||||
|
||||
if (cs) begin
|
||||
tmp_ready = 1'h1;
|
||||
if (cs) begin
|
||||
tmp_ready = 1'h1;
|
||||
|
||||
if (we) begin
|
||||
if (address == ADDR_CTRL) begin
|
||||
start_new = write_data[CTRL_START_BIT];
|
||||
stop_new = write_data[CTRL_STOP_BIT];
|
||||
end
|
||||
|
||||
if (!core_running) begin
|
||||
if (address == ADDR_PRESCALER) begin
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
|
||||
if (address == ADDR_TIMER) begin
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
end
|
||||
if (we) begin
|
||||
if (address == ADDR_CTRL) begin
|
||||
start_new = write_data[CTRL_START_BIT];
|
||||
stop_new = write_data[CTRL_STOP_BIT];
|
||||
end
|
||||
|
||||
else begin
|
||||
if (address == ADDR_STATUS) begin
|
||||
tmp_read_data[STATUS_RUNNING_BIT] = core_running;
|
||||
end
|
||||
if (!core_running) begin
|
||||
if (address == ADDR_PRESCALER) begin
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
|
||||
if (address == ADDR_PRESCALER) begin
|
||||
tmp_read_data = prescaler_reg;
|
||||
end
|
||||
|
||||
if (address == ADDR_TIMER) begin
|
||||
if (!core_running) begin
|
||||
tmp_read_data = timer_reg;
|
||||
end
|
||||
else begin
|
||||
tmp_read_data = core_curr_timer;
|
||||
end
|
||||
end
|
||||
if (address == ADDR_TIMER) begin
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end // addr_decoder
|
||||
endmodule // timer
|
||||
|
||||
else begin
|
||||
if (address == ADDR_STATUS) begin
|
||||
tmp_read_data[STATUS_RUNNING_BIT] = core_running;
|
||||
end
|
||||
|
||||
if (address == ADDR_PRESCALER) begin
|
||||
tmp_read_data = prescaler_reg;
|
||||
end
|
||||
|
||||
if (address == ADDR_TIMER) begin
|
||||
if (!core_running) begin
|
||||
tmp_read_data = timer_reg;
|
||||
end
|
||||
else begin
|
||||
tmp_read_data = core_curr_timer;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end // addr_decoder
|
||||
endmodule // timer
|
||||
|
||||
//======================================================================
|
||||
// EOF timer.v
|
||||
|
|
|
@ -13,26 +13,26 @@
|
|||
|
||||
`default_nettype none
|
||||
|
||||
module timer_core(
|
||||
input wire clk,
|
||||
input wire reset_n,
|
||||
module timer_core (
|
||||
input wire clk,
|
||||
input wire reset_n,
|
||||
|
||||
input wire [31 : 0] prescaler_init,
|
||||
input wire [31 : 0] timer_init,
|
||||
input wire start,
|
||||
input wire stop,
|
||||
input wire [31 : 0] prescaler_init,
|
||||
input wire [31 : 0] timer_init,
|
||||
input wire start,
|
||||
input wire stop,
|
||||
|
||||
output wire [31 : 0] curr_timer,
|
||||
output wire running
|
||||
);
|
||||
output wire [31 : 0] curr_timer,
|
||||
output wire running
|
||||
);
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Internal constant and parameter definitions.
|
||||
//----------------------------------------------------------------
|
||||
localparam CTRL_IDLE = 2'h0;
|
||||
localparam CTRL_IDLE = 2'h0;
|
||||
localparam CTRL_PRESCALER = 2'h1;
|
||||
localparam CTRL_TIMER = 2'h2;
|
||||
localparam CTRL_TIMER = 2'h2;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -54,8 +54,8 @@ module timer_core(
|
|||
reg timer_set;
|
||||
reg timer_dec;
|
||||
|
||||
reg [1 : 0] core_ctrl_reg;
|
||||
reg [1 : 0] core_ctrl_new;
|
||||
reg [ 1 : 0] core_ctrl_reg;
|
||||
reg [ 1 : 0] core_ctrl_new;
|
||||
reg core_ctrl_we;
|
||||
|
||||
|
||||
|
@ -69,164 +69,158 @@ module timer_core(
|
|||
//----------------------------------------------------------------
|
||||
// reg_update
|
||||
//----------------------------------------------------------------
|
||||
always @ (posedge clk)
|
||||
begin: reg_update
|
||||
if (!reset_n)
|
||||
begin
|
||||
running_reg <= 1'h0;
|
||||
prescaler_reg <= 32'h0;
|
||||
timer_reg <= 32'h0;
|
||||
core_ctrl_reg <= CTRL_IDLE;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (running_we) begin
|
||||
running_reg <= running_new;
|
||||
end
|
||||
always @(posedge clk) begin : reg_update
|
||||
if (!reset_n) begin
|
||||
running_reg <= 1'h0;
|
||||
prescaler_reg <= 32'h0;
|
||||
timer_reg <= 32'h0;
|
||||
core_ctrl_reg <= CTRL_IDLE;
|
||||
end
|
||||
else begin
|
||||
if (running_we) begin
|
||||
running_reg <= running_new;
|
||||
end
|
||||
|
||||
if (prescaler_we) begin
|
||||
prescaler_reg <= prescaler_new;
|
||||
end
|
||||
if (prescaler_we) begin
|
||||
prescaler_reg <= prescaler_new;
|
||||
end
|
||||
|
||||
if (timer_we) begin
|
||||
timer_reg <= timer_new;
|
||||
end
|
||||
if (timer_we) begin
|
||||
timer_reg <= timer_new;
|
||||
end
|
||||
|
||||
if (core_ctrl_we) begin
|
||||
core_ctrl_reg <= core_ctrl_new;
|
||||
end
|
||||
end
|
||||
end // reg_update
|
||||
if (core_ctrl_we) begin
|
||||
core_ctrl_reg <= core_ctrl_new;
|
||||
end
|
||||
end
|
||||
end // reg_update
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// prescaler_ctr
|
||||
//----------------------------------------------------------------
|
||||
always @*
|
||||
begin : prescaler_ctr
|
||||
prescaler_new = 32'h0;
|
||||
prescaler_we = 1'h0;
|
||||
always @* begin : prescaler_ctr
|
||||
prescaler_new = 32'h0;
|
||||
prescaler_we = 1'h0;
|
||||
|
||||
if (prescaler_set) begin
|
||||
prescaler_new = prescaler_init;
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
else if (prescaler_dec) begin
|
||||
prescaler_new = prescaler_reg - 1'h1;
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
if (prescaler_set) begin
|
||||
prescaler_new = prescaler_init;
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
else if (prescaler_dec) begin
|
||||
prescaler_new = prescaler_reg - 1'h1;
|
||||
prescaler_we = 1'h1;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// timer_ctr
|
||||
//----------------------------------------------------------------
|
||||
always @*
|
||||
begin : timer_ctr
|
||||
timer_new = 32'h0;
|
||||
timer_we = 1'h0;
|
||||
always @* begin : timer_ctr
|
||||
timer_new = 32'h0;
|
||||
timer_we = 1'h0;
|
||||
|
||||
if (timer_set) begin
|
||||
timer_new = timer_init;
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
else if (timer_dec) begin
|
||||
timer_new = timer_reg - 1'h1;
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
if (timer_set) begin
|
||||
timer_new = timer_init;
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
else if (timer_dec) begin
|
||||
timer_new = timer_reg - 1'h1;
|
||||
timer_we = 1'h1;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Core control FSM.
|
||||
//----------------------------------------------------------------
|
||||
always @*
|
||||
begin : core_ctrl
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h0;
|
||||
prescaler_set = 1'h0;
|
||||
prescaler_dec = 1'h0;
|
||||
timer_set = 1'h0;
|
||||
timer_dec = 1'h0;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h0;
|
||||
always @* begin : core_ctrl
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h0;
|
||||
prescaler_set = 1'h0;
|
||||
prescaler_dec = 1'h0;
|
||||
timer_set = 1'h0;
|
||||
timer_dec = 1'h0;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h0;
|
||||
|
||||
case (core_ctrl_reg)
|
||||
CTRL_IDLE: begin
|
||||
if (start) begin
|
||||
running_new = 1'h1;
|
||||
running_we = 1'h1;
|
||||
prescaler_set = 1'h1;
|
||||
timer_set = 1'h1;
|
||||
case (core_ctrl_reg)
|
||||
CTRL_IDLE: begin
|
||||
if (start) begin
|
||||
running_new = 1'h1;
|
||||
running_we = 1'h1;
|
||||
prescaler_set = 1'h1;
|
||||
timer_set = 1'h1;
|
||||
|
||||
if (prescaler_init == 0) begin
|
||||
core_ctrl_new = CTRL_TIMER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
if (prescaler_init == 0) begin
|
||||
core_ctrl_new = CTRL_TIMER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
core_ctrl_new = CTRL_PRESCALER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
else begin
|
||||
core_ctrl_new = CTRL_PRESCALER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
CTRL_PRESCALER: begin
|
||||
if (stop) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
if (prescaler_reg == 1) begin
|
||||
core_ctrl_new = CTRL_TIMER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
prescaler_dec = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
CTRL_TIMER: begin
|
||||
if (stop) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
if (timer_reg == 1) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
timer_dec = 1'h1;
|
||||
|
||||
if (prescaler_init > 0) begin
|
||||
prescaler_set = 1'h1;
|
||||
core_ctrl_new = CTRL_PRESCALER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
default: begin
|
||||
CTRL_PRESCALER: begin
|
||||
if (stop) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
endcase // case (core_ctrl_reg)
|
||||
end // core_ctrl
|
||||
|
||||
endmodule // timer_core
|
||||
else begin
|
||||
if (prescaler_reg == 1) begin
|
||||
core_ctrl_new = CTRL_TIMER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
prescaler_dec = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
CTRL_TIMER: begin
|
||||
if (stop) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
if (timer_reg == 1) begin
|
||||
running_new = 1'h0;
|
||||
running_we = 1'h1;
|
||||
core_ctrl_new = CTRL_IDLE;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
|
||||
else begin
|
||||
timer_dec = 1'h1;
|
||||
|
||||
if (prescaler_init > 0) begin
|
||||
prescaler_set = 1'h1;
|
||||
core_ctrl_new = CTRL_PRESCALER;
|
||||
core_ctrl_we = 1'h1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
default: begin
|
||||
end
|
||||
endcase // case (core_ctrl_reg)
|
||||
end // core_ctrl
|
||||
|
||||
endmodule // timer_core
|
||||
|
||||
//======================================================================
|
||||
// EOF timer_core.v
|
||||
|
|
|
@ -13,63 +13,63 @@
|
|||
|
||||
`default_nettype none
|
||||
|
||||
module tb_timer();
|
||||
module tb_timer ();
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Internal constant and parameter definitions.
|
||||
//----------------------------------------------------------------
|
||||
parameter DEBUG = 0;
|
||||
parameter DEBUG = 0;
|
||||
parameter DUMP_WAIT = 0;
|
||||
|
||||
parameter CLK_HALF_PERIOD = 1;
|
||||
parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD;
|
||||
|
||||
localparam ADDR_CTRL = 8'h08;
|
||||
localparam CTRL_START_BIT = 0;
|
||||
localparam CTRL_STOP_BIT = 1;
|
||||
localparam ADDR_CTRL = 8'h08;
|
||||
localparam CTRL_START_BIT = 0;
|
||||
localparam CTRL_STOP_BIT = 1;
|
||||
|
||||
localparam ADDR_STATUS = 8'h09;
|
||||
localparam ADDR_STATUS = 8'h09;
|
||||
localparam STATUS_RUNNING_BIT = 0;
|
||||
|
||||
localparam ADDR_PRESCALER = 8'h0a;
|
||||
localparam ADDR_TIMER = 8'h0b;
|
||||
localparam ADDR_PRESCALER = 8'h0a;
|
||||
localparam ADDR_TIMER = 8'h0b;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Register and Wire declarations.
|
||||
//----------------------------------------------------------------
|
||||
reg [31 : 0] cycle_ctr;
|
||||
reg [31 : 0] error_ctr;
|
||||
reg [31 : 0] tc_ctr;
|
||||
reg tb_monitor;
|
||||
reg [31 : 0] cycle_ctr;
|
||||
reg [31 : 0] error_ctr;
|
||||
reg [31 : 0] tc_ctr;
|
||||
reg tb_monitor;
|
||||
|
||||
reg tb_clk;
|
||||
reg tb_reset_n;
|
||||
reg tb_cs;
|
||||
reg tb_we;
|
||||
reg [7 : 0] tb_address;
|
||||
reg [31 : 0] tb_write_data;
|
||||
reg [ 7 : 0] tb_address;
|
||||
reg [31 : 0] tb_write_data;
|
||||
wire [31 : 0] tb_read_data;
|
||||
wire tb_ready;
|
||||
|
||||
reg [31 : 0] read_data;
|
||||
reg [31 : 0] read_data;
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Device Under Test.
|
||||
//----------------------------------------------------------------
|
||||
timer dut(
|
||||
.clk(tb_clk),
|
||||
.reset_n(tb_reset_n),
|
||||
timer dut (
|
||||
.clk(tb_clk),
|
||||
.reset_n(tb_reset_n),
|
||||
|
||||
.cs(tb_cs),
|
||||
.we(tb_we),
|
||||
.cs(tb_cs),
|
||||
.we(tb_we),
|
||||
|
||||
.address(tb_address),
|
||||
.write_data(tb_write_data),
|
||||
.read_data(tb_read_data),
|
||||
.ready(tb_ready)
|
||||
);
|
||||
.address(tb_address),
|
||||
.write_data(tb_write_data),
|
||||
.read_data(tb_read_data),
|
||||
.ready(tb_ready)
|
||||
);
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -77,11 +77,10 @@ module tb_timer();
|
|||
//
|
||||
// Always running clock generator process.
|
||||
//----------------------------------------------------------------
|
||||
always
|
||||
begin : clk_gen
|
||||
#CLK_HALF_PERIOD;
|
||||
tb_clk = !tb_clk;
|
||||
end // clk_gen
|
||||
always begin : clk_gen
|
||||
#CLK_HALF_PERIOD;
|
||||
tb_clk = !tb_clk;
|
||||
end // clk_gen
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -90,15 +89,13 @@ module tb_timer();
|
|||
// An always running process that creates a cycle counter and
|
||||
// conditionally displays information about the DUT.
|
||||
//----------------------------------------------------------------
|
||||
always
|
||||
begin : sys_monitor
|
||||
cycle_ctr = cycle_ctr + 1;
|
||||
#(CLK_PERIOD);
|
||||
if (tb_monitor)
|
||||
begin
|
||||
dump_dut_state();
|
||||
end
|
||||
always begin : sys_monitor
|
||||
cycle_ctr = cycle_ctr + 1;
|
||||
#(CLK_PERIOD);
|
||||
if (tb_monitor) begin
|
||||
dump_dut_state();
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -113,17 +110,19 @@ module tb_timer();
|
|||
$display("Cycle: %08d", cycle_ctr);
|
||||
$display("");
|
||||
$display("Inputs and outputs:");
|
||||
$display("cs: 0x%1x, we: 0x%1x, address: 0x%02x, write_data: 0x%08x, read_data: 0x%08x, ready: 0x%1x",
|
||||
tb_cs, tb_we, tb_address, tb_write_data, tb_read_data, tb_ready);
|
||||
$display(
|
||||
"cs: 0x%1x, we: 0x%1x, address: 0x%02x, write_data: 0x%08x, read_data: 0x%08x, ready: 0x%1x",
|
||||
tb_cs, tb_we, tb_address, tb_write_data, tb_read_data, tb_ready);
|
||||
$display("");
|
||||
$display("Internal state:");
|
||||
$display("prescaler_reg: 0x%08x, timer_reg: 0x%08x", dut.prescaler_reg, dut.timer_reg);
|
||||
$display("start_reg: 0x%1x, stop_reg: 0x%1x", dut.start_reg, dut.stop_reg);
|
||||
$display("core_running: 0x%1x, core_curr_timer: 0x%08x", dut.core_running, dut.core_curr_timer);
|
||||
$display("core_running: 0x%1x, core_curr_timer: 0x%08x", dut.core_running,
|
||||
dut.core_curr_timer);
|
||||
$display("");
|
||||
$display("");
|
||||
end
|
||||
endtask // dump_dut_state
|
||||
endtask // dump_dut_state
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -138,7 +137,7 @@ module tb_timer();
|
|||
#(2 * CLK_PERIOD);
|
||||
tb_reset_n = 1;
|
||||
end
|
||||
endtask // reset_dut
|
||||
endtask // reset_dut
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -148,17 +147,15 @@ module tb_timer();
|
|||
//----------------------------------------------------------------
|
||||
task display_test_result;
|
||||
begin
|
||||
if (error_ctr == 0)
|
||||
begin
|
||||
$display("--- All %02d test cases completed successfully", tc_ctr);
|
||||
end
|
||||
else
|
||||
begin
|
||||
$display("--- %02d tests completed - %02d test cases did not complete successfully.",
|
||||
tc_ctr, error_ctr);
|
||||
end
|
||||
if (error_ctr == 0) begin
|
||||
$display("--- All %02d test cases completed successfully", tc_ctr);
|
||||
end
|
||||
else begin
|
||||
$display("--- %02d tests completed - %02d test cases did not complete successfully.",
|
||||
tc_ctr, error_ctr);
|
||||
end
|
||||
end
|
||||
endtask // display_test_result
|
||||
endtask // display_test_result
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -169,10 +166,10 @@ module tb_timer();
|
|||
//----------------------------------------------------------------
|
||||
task init_sim;
|
||||
begin
|
||||
cycle_ctr = 0;
|
||||
error_ctr = 0;
|
||||
tc_ctr = 0;
|
||||
tb_monitor = 0;
|
||||
cycle_ctr = 0;
|
||||
error_ctr = 0;
|
||||
tc_ctr = 0;
|
||||
tb_monitor = 0;
|
||||
|
||||
tb_clk = 1'h0;
|
||||
tb_reset_n = 1'h1;
|
||||
|
@ -181,7 +178,7 @@ module tb_timer();
|
|||
tb_address = 8'h0;
|
||||
tb_write_data = 32'h0;
|
||||
end
|
||||
endtask // init_sim
|
||||
endtask // init_sim
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -189,14 +186,12 @@ module tb_timer();
|
|||
//
|
||||
// Write the given word to the DUT using the DUT interface.
|
||||
//----------------------------------------------------------------
|
||||
task write_word(input [11 : 0] address,
|
||||
input [31 : 0] word);
|
||||
task write_word(input [11 : 0] address, input [31 : 0] word);
|
||||
begin
|
||||
if (DEBUG)
|
||||
begin
|
||||
$display("--- Writing 0x%08x to 0x%02x.", word, address);
|
||||
$display("");
|
||||
end
|
||||
if (DEBUG) begin
|
||||
$display("--- Writing 0x%08x to 0x%02x.", word, address);
|
||||
$display("");
|
||||
end
|
||||
|
||||
tb_address = address;
|
||||
tb_write_data = word;
|
||||
|
@ -206,7 +201,7 @@ module tb_timer();
|
|||
tb_cs = 0;
|
||||
tb_we = 0;
|
||||
end
|
||||
endtask // write_word
|
||||
endtask // write_word
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -216,7 +211,7 @@ module tb_timer();
|
|||
// the word read will be available in the global variable
|
||||
// read_data.
|
||||
//----------------------------------------------------------------
|
||||
task read_word(input [11 : 0] address);
|
||||
task read_word(input [11 : 0] address);
|
||||
begin
|
||||
tb_address = address;
|
||||
tb_cs = 1;
|
||||
|
@ -225,13 +220,12 @@ module tb_timer();
|
|||
read_data = tb_read_data;
|
||||
tb_cs = 0;
|
||||
|
||||
if (DEBUG)
|
||||
begin
|
||||
$display("--- Reading 0x%08x from 0x%02x.", read_data, address);
|
||||
$display("");
|
||||
end
|
||||
if (DEBUG) begin
|
||||
$display("--- Reading 0x%08x from 0x%02x.", read_data, address);
|
||||
$display("");
|
||||
end
|
||||
end
|
||||
endtask // read_word
|
||||
endtask // read_word
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -242,10 +236,9 @@ module tb_timer();
|
|||
task wait_ready;
|
||||
begin : wready
|
||||
read_word(ADDR_STATUS);
|
||||
while (read_data == 0)
|
||||
read_word(ADDR_STATUS);
|
||||
while (read_data == 0) read_word(ADDR_STATUS);
|
||||
end
|
||||
endtask // wait_ready
|
||||
endtask // wait_ready
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -273,7 +266,7 @@ module tb_timer();
|
|||
#(2 * CLK_PERIOD);
|
||||
read_word(ADDR_STATUS);
|
||||
while (read_data) begin
|
||||
read_word(ADDR_STATUS);
|
||||
read_word(ADDR_STATUS);
|
||||
end
|
||||
|
||||
time_stop = cycle_ctr;
|
||||
|
@ -286,31 +279,30 @@ module tb_timer();
|
|||
$display("--- test1: completed.");
|
||||
$display("");
|
||||
end
|
||||
endtask // tes1
|
||||
endtask // tes1
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// timer_test
|
||||
//----------------------------------------------------------------
|
||||
initial
|
||||
begin : timer_test
|
||||
$display("");
|
||||
$display(" -= Testbench for timer started =-");
|
||||
$display(" =============================");
|
||||
$display("");
|
||||
initial begin : timer_test
|
||||
$display("");
|
||||
$display(" -= Testbench for timer started =-");
|
||||
$display(" =============================");
|
||||
$display("");
|
||||
|
||||
init_sim();
|
||||
reset_dut();
|
||||
test1();
|
||||
init_sim();
|
||||
reset_dut();
|
||||
test1();
|
||||
|
||||
display_test_result();
|
||||
$display("");
|
||||
$display(" -= Testbench for timer completed =-");
|
||||
$display(" ===============================");
|
||||
$display("");
|
||||
$finish;
|
||||
end // timer_test
|
||||
endmodule // tb_timer
|
||||
display_test_result();
|
||||
$display("");
|
||||
$display(" -= Testbench for timer completed =-");
|
||||
$display(" ===============================");
|
||||
$display("");
|
||||
$finish;
|
||||
end // timer_test
|
||||
endmodule // tb_timer
|
||||
|
||||
//======================================================================
|
||||
// EOF tb_timer.v
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
`default_nettype none
|
||||
|
||||
module tb_timer_core();
|
||||
module tb_timer_core ();
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Internal constant and parameter definitions.
|
||||
//----------------------------------------------------------------
|
||||
parameter DEBUG = 0;
|
||||
parameter DEBUG = 0;
|
||||
parameter DUMP_WAIT = 0;
|
||||
|
||||
parameter CLK_HALF_PERIOD = 1;
|
||||
|
@ -28,10 +28,10 @@ module tb_timer_core();
|
|||
//----------------------------------------------------------------
|
||||
// Register and Wire declarations.
|
||||
//----------------------------------------------------------------
|
||||
reg [31 : 0] cycle_ctr;
|
||||
reg [31 : 0] error_ctr;
|
||||
reg [31 : 0] tc_ctr;
|
||||
reg tb_monitor;
|
||||
reg [31 : 0] cycle_ctr;
|
||||
reg [31 : 0] error_ctr;
|
||||
reg [31 : 0] tc_ctr;
|
||||
reg tb_monitor;
|
||||
|
||||
reg tb_clk;
|
||||
reg tb_reset_n;
|
||||
|
@ -46,16 +46,16 @@ module tb_timer_core();
|
|||
//----------------------------------------------------------------
|
||||
// Device Under Test.
|
||||
//----------------------------------------------------------------
|
||||
timer_core dut(
|
||||
.clk(tb_clk),
|
||||
.reset_n(tb_reset_n),
|
||||
.prescaler_init(tb_prescaler_init),
|
||||
.timer_init(tb_timer_init),
|
||||
.start(tb_start),
|
||||
.stop(tb_stop),
|
||||
.curr_timer(tb_curr_timer),
|
||||
.running(tb_running)
|
||||
);
|
||||
timer_core dut (
|
||||
.clk(tb_clk),
|
||||
.reset_n(tb_reset_n),
|
||||
.prescaler_init(tb_prescaler_init),
|
||||
.timer_init(tb_timer_init),
|
||||
.start(tb_start),
|
||||
.stop(tb_stop),
|
||||
.curr_timer(tb_curr_timer),
|
||||
.running(tb_running)
|
||||
);
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -63,11 +63,10 @@ module tb_timer_core();
|
|||
//
|
||||
// Always running clock generator process.
|
||||
//----------------------------------------------------------------
|
||||
always
|
||||
begin : clk_gen
|
||||
#CLK_HALF_PERIOD;
|
||||
tb_clk = !tb_clk;
|
||||
end // clk_gen
|
||||
always begin : clk_gen
|
||||
#CLK_HALF_PERIOD;
|
||||
tb_clk = !tb_clk;
|
||||
end // clk_gen
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -76,15 +75,13 @@ module tb_timer_core();
|
|||
// An always running process that creates a cycle counter and
|
||||
// conditionally displays information about the DUT.
|
||||
//----------------------------------------------------------------
|
||||
always
|
||||
begin : sys_monitor
|
||||
cycle_ctr = cycle_ctr + 1;
|
||||
#(CLK_PERIOD);
|
||||
if (tb_monitor)
|
||||
begin
|
||||
dump_dut_state();
|
||||
end
|
||||
always begin : sys_monitor
|
||||
cycle_ctr = cycle_ctr + 1;
|
||||
#(CLK_PERIOD);
|
||||
if (tb_monitor) begin
|
||||
dump_dut_state();
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -99,28 +96,23 @@ module tb_timer_core();
|
|||
$display("Cycle: %08d", cycle_ctr);
|
||||
$display("");
|
||||
$display("Inputs and outputs:");
|
||||
$display("prescaler_init: 0x%08x, timer_init: 0x%08x",
|
||||
dut.prescaler_init, dut.timer_init);
|
||||
$display("start: 0x%1x, stop: 0x%1x, running: 0x%1x",
|
||||
dut.start, dut.stop, dut.running);
|
||||
$display("prescaler_init: 0x%08x, timer_init: 0x%08x", dut.prescaler_init, dut.timer_init);
|
||||
$display("start: 0x%1x, stop: 0x%1x, running: 0x%1x", dut.start, dut.stop, dut.running);
|
||||
$display("");
|
||||
$display("Internal state:");
|
||||
$display("prescaler_reg: 0x%08x, prescaler_new: 0x%08x",
|
||||
dut.prescaler_reg, dut.prescaler_new);
|
||||
$display("prescaler_set: 0x%1x, prescaler_dec: 0x%1x",
|
||||
dut.prescaler_set, dut.prescaler_dec);
|
||||
$display("prescaler_reg: 0x%08x, prescaler_new: 0x%08x", dut.prescaler_reg,
|
||||
dut.prescaler_new);
|
||||
$display("prescaler_set: 0x%1x, prescaler_dec: 0x%1x", dut.prescaler_set, dut.prescaler_dec);
|
||||
$display("");
|
||||
$display("timer_reg: 0x%08x, timer_new: 0x%08x",
|
||||
dut.timer_reg, dut.timer_new);
|
||||
$display("timer_set: 0x%1x, timer_dec: 0x%1x",
|
||||
dut.timer_set, dut.timer_dec);
|
||||
$display("timer_reg: 0x%08x, timer_new: 0x%08x", dut.timer_reg, dut.timer_new);
|
||||
$display("timer_set: 0x%1x, timer_dec: 0x%1x", dut.timer_set, dut.timer_dec);
|
||||
$display("");
|
||||
$display("core_ctrl_reg: 0x%02x, core_ctrl_new: 0x%02x, core_ctrl_we: 0x%1x",
|
||||
dut.core_ctrl_reg, dut.core_ctrl_new, dut.core_ctrl_we);
|
||||
dut.core_ctrl_reg, dut.core_ctrl_new, dut.core_ctrl_we);
|
||||
$display("");
|
||||
$display("");
|
||||
end
|
||||
endtask // dump_dut_state
|
||||
endtask // dump_dut_state
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -139,7 +131,7 @@ module tb_timer_core();
|
|||
$display("--- DUT after reset:");
|
||||
dump_dut_state();
|
||||
end
|
||||
endtask // reset_dut
|
||||
endtask // reset_dut
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -154,16 +146,14 @@ module tb_timer_core();
|
|||
task wait_done;
|
||||
begin
|
||||
#(2 * CLK_PERIOD);
|
||||
while (tb_running)
|
||||
begin
|
||||
#(CLK_PERIOD);
|
||||
if (DUMP_WAIT)
|
||||
begin
|
||||
dump_dut_state();
|
||||
end
|
||||
while (tb_running) begin
|
||||
#(CLK_PERIOD);
|
||||
if (DUMP_WAIT) begin
|
||||
dump_dut_state();
|
||||
end
|
||||
end
|
||||
end
|
||||
endtask // wait_ready
|
||||
endtask // wait_ready
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -187,7 +177,7 @@ module tb_timer_core();
|
|||
tb_prescaler_init = 32'h0;
|
||||
tb_timer_init = 32'h0;
|
||||
end
|
||||
endtask // init_sim
|
||||
endtask // init_sim
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -212,7 +202,7 @@ module tb_timer_core();
|
|||
$display("--- test1 completed.");
|
||||
$display("");
|
||||
end
|
||||
endtask // test1
|
||||
endtask // test1
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -220,21 +210,20 @@ module tb_timer_core();
|
|||
//
|
||||
// Test vectors from:
|
||||
//----------------------------------------------------------------
|
||||
initial
|
||||
begin : timer_core_test
|
||||
$display("--- Simulation of timer core started.");
|
||||
$display("");
|
||||
initial begin : timer_core_test
|
||||
$display("--- Simulation of timer core started.");
|
||||
$display("");
|
||||
|
||||
init_sim();
|
||||
reset_dut();
|
||||
init_sim();
|
||||
reset_dut();
|
||||
|
||||
test1();
|
||||
test1();
|
||||
|
||||
$display("");
|
||||
$display("--- Simulation of timer core completed.");
|
||||
$finish;
|
||||
end // timer_core_test
|
||||
endmodule // tb_timer_core
|
||||
$display("");
|
||||
$display("--- Simulation of timer core completed.");
|
||||
$finish;
|
||||
end // timer_core_test
|
||||
endmodule // tb_timer_core
|
||||
|
||||
//======================================================================
|
||||
// EOF tb_timer_core.v
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue