-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebugm.v
80 lines (69 loc) · 1.31 KB
/
debugm.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
69
70
71
72
73
74
75
76
77
78
79
80
`include "dport.vh"
module debugm(
input wire clk,
input wire dpclk,
input wire start,
input wire stop,
input wire [15:0] debugaddr,
input wire debugreq,
output reg debugack,
output reg [31:0] debugrdata,
input wire debugwr,
input wire [31:0] debugwdata
);
parameter NSZ = 12;
localparam SIZE = 1<<NSZ;
reg mode;
reg [31:0] mem[0:SIZE-1];
reg [NSZ:0] addr;
reg we;
reg [31:0] rdata;
reg [31:0] wdata;
always @(*) begin
if(mode) begin
if(stop && running) begin
addr = ctr;
wdata = rdata + 1;
we = 1;
end else begin
addr = ctr + 1;
we = 0;
wdata = 32'bx;
end
end else begin
addr = debugaddr[NSZ+1:2];
wdata = debugwdata;
we = debugwr && debugreq0 && !debugreq00;
end
end
always @(posedge clk)
if(we)
mem[addr] <= wdata;
else
rdata <= mem[addr];
reg [NSZ:0] ctr;
reg running;
always @(posedge clk) begin
if(start && mode) begin
ctr <= 0;
running <= 1;
end else
ctr <= ctr + 1;
if(stop && running)
running <= 0;
end
reg debugreq0, debugreq00;
always @(posedge clk) begin
debugreq0 <= debugreq;
debugreq00 <= debugreq0;
debugack <= 0;
if(debugreq0 && !debugreq00) begin
if(debugwr) begin
if(debugaddr[15])
mode <= debugwdata[0];
end else
debugrdata <= rdata;
debugack <= 1;
end
end
endmodule