-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathintgen.v
68 lines (56 loc) · 1.39 KB
/
intgen.v
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
/*
*
* Interrupt generation module
*
* A counter is loaded with a value over the Wishbone bus interface, which then
* counts down and issues an interrupt when the value is 1
*
*
* Register 0 - write only - counter value
*
* Register 1 - read/write - interrupt status/clear
*
*/
module intgen(
clk_i,
rst_i,
wb_adr_i,
wb_dat_i,
//wb_sel_i
wb_we_i,
wb_cyc_i,
wb_stb_i,
wb_dat_o,
wb_ack_o,
irq_o
);
input clk_i;
input rst_i;
input wb_adr_i;
input [7:0] wb_dat_i;
input wb_we_i;
input wb_cyc_i;
input wb_stb_i;
output [7:0] wb_dat_o;
output wb_ack_o;
output reg irq_o;
reg [7:0] counter;
always @(posedge clk_i or posedge rst_i)
if (rst_i)
counter <= 0;
else if (wb_stb_i & wb_cyc_i & wb_we_i & !wb_adr_i)
// Write to address 0 loads counter
counter <= wb_dat_i;
else if (|counter)
counter <= counter - 1;
always @(posedge clk_i or posedge rst_i)
if (rst_i)
irq_o <= 0;
else if (wb_stb_i & wb_cyc_i & wb_we_i & wb_adr_i)
// Clear on write to reg 1
irq_o <= 0;
else if (counter==8'd1)
irq_o <= 1;
assign wb_ack_o = wb_stb_i & wb_cyc_i;
assign wb_dat_o = (wb_adr_i) ? {7'd0,irq_o} : counter;
endmodule // intgen