-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDesign.v
70 lines (59 loc) · 1.47 KB
/
Design.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
module AMBA_APB(PSEL,PENABLE,PADDR,PWRITE,PRESET,
PWDATA,PCLK,PREADY,PRDATA);
input bit PSEL;
input bit PENABLE;
input bit [31:0] PADDR;
input bit PWRITE;
input bit [31:0] PWDATA;
input bit PCLK;
// input [3:0] PSTRB;
input bit PRESET; //Active low
output reg [31:0] PRDATA;
output reg PREADY;
// output reg PSLVERR;
parameter IDLE=2'b00;
parameter SETUP=2'b01;
parameter ACCESS=2'b10;
reg [1:0] ps,ns;
reg [31:0]mem [31:0];
always @(posedge PCLK)
begin
if(PRESET)
ps = IDLE;
else
ps = ns;
end
always @(*)
begin
case(ps)
IDLE:begin
if(PSEL==1 & PENABLE==0)
ns = SETUP;
if(PSEL==0 & PENABLE==0)
ns = IDLE;
end
SETUP:begin
if(PSEL==1 & PENABLE==1) begin
ns = ACCESS;
PREADY = 1;
if(PWRITE) begin
mem[PADDR] = PWDATA;
end
else begin
PRDATA = mem[PADDR];
end
//ns = SETUP;
end
if(PSEL==0 & PENABLE==0)
ns = IDLE;
end
ACCESS:begin
if(PSEL==0 & PENABLE==0)
ns = IDLE;
PREADY = 0;
if(PSEL==1 & PENABLE==1)
ns=ACCESS;
end
endcase
end
enmodule