-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVertimer.sv
79 lines (67 loc) · 2.46 KB
/
Vertimer.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// SPDX-License-Identifier: CERN-OHL-W-2.0
// SPDX-FileCopyrightText: 2023 Guillaume Savaton <guillaume.savaton@tiliosys.fr>
//
`default_nettype none
module Vertimer (Verbus.read_write_response bus);
import Verdata_pkg::*;
import Vertimer_pkg::*;
local_address_t local_address;
control_reg_t control_reg;
word_t control_reg_as_word;
status_reg_t status_reg;
word_t status_reg_as_word;
word_t refill_reg;
word_t count_reg;
assign local_address = local_address_t'(bus.address[2+:LOCAL_ADDRESS_WIDTH]);
assign control_reg_as_word = word_t'(control_reg);
assign status_reg_as_word = word_t'(status_reg);
always_ff @(posedge bus.clk, posedge bus.reset) begin
if (bus.reset) begin
control_reg <= 0;
end
else if (bus.write_enabled() && local_address == CONTROL_ADDRESS) begin
control_reg <= control_reg_t'(bus.write_into(control_reg_as_word));
end
else if (control_reg.cyclic_mode && count_reg == 0) begin
control_reg.count_enable <= 0;
end
end
always_ff @(posedge bus.clk, posedge bus.reset) begin
if (bus.reset) begin
status_reg <= 0;
end
else if (bus.write_enabled() && local_address == STATUS_ADDRESS) begin
status_reg <= status_reg_t'(bus.clear_into(status_reg_as_word));
end
else if (control_reg.count_enable && count_reg == 0) begin
status_reg.event_flag <= 1;
end
end
always_ff @(posedge bus.clk, posedge bus.reset) begin
if (bus.reset) begin
refill_reg <= 0;
count_reg <= 0;
end
else if (bus.write_enabled() && local_address == REFILL_ADDRESS) begin
refill_reg <= bus.write_into(refill_reg);
count_reg <= bus.write_into(count_reg);
end
else if (control_reg.count_enable && count_reg != 0) begin
count_reg <= count_reg - 1;
end
else begin
count_reg <= refill_reg;
end
end
always_comb begin
case (local_address)
CONTROL_ADDRESS : bus.rdata = control_reg_as_word;
STATUS_ADDRESS : bus.rdata = status_reg_as_word;
REFILL_ADDRESS : bus.rdata = refill_reg;
default : bus.rdata = count_reg;
endcase
end
assign bus.ready = 1;
assign bus.irq = status_reg.event_flag && control_reg.irq_enable;
endmodule