1
0
mirror of https://github.com/olofk/serv.git synced 2026-01-20 01:24:56 +00:00
olofk.serv/rtl/riscv_timer.v
2018-11-21 13:15:33 +01:00

22 lines
502 B
Verilog

`default_nettype none
module riscv_timer
(input wire i_clk,
output reg o_irq = 1'b0,
input wire [31:0] i_wb_dat,
input wire i_wb_we,
input wire i_wb_cyc,
output wire [31:0] o_wb_dat);
reg [31:0] mtime = 32'd0;
reg [31:0] mtimecmp = 32'd0;
assign o_wb_dat = mtime;
always @(posedge i_clk) begin
if (i_wb_cyc & i_wb_we)
mtimecmp <= i_wb_dat;
mtime <= mtime + 32'd1;
o_irq <= (mtime >= mtimecmp);
end
endmodule