-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusCtrl.sv
More file actions
83 lines (72 loc) · 2 KB
/
Copy pathBusCtrl.sv
File metadata and controls
83 lines (72 loc) · 2 KB
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
81
82
83
module BusCtrl
import BusPkg::*;
(
input logic clk, rst,
BusItf.Slave bCacheIf, //TODO: handle two master access
//peripherals
output logic [15:0] oLed,
output logic oLedWe,
input logic [15:0] iSw,
output logic [31:0] oSeg,
output logic oSegWe,
input logic iEnt,
output logic oEntClr
);
localparam P_MMIO_BASE = 32'h0000_7f00;
localparam P_LED = P_MMIO_BASE; //[15:0]: led
localparam P_SW = P_MMIO_BASE + 4; //[15:0]: sw
localparam P_SEG = P_MMIO_BASE + 8; //[31:0]: seg
localparam P_ENT = P_MMIO_BASE + 12; //[0:0]: enter
logic mmio;
assign mmio = bCacheIf.addr >= P_MMIO_BASE;
assign oLed = bCacheIf.dataM2S[15:0];
assign oSeg = bCacheIf.dataM2S;
typedef enum logic [0:0] {
S_IDLE,
S_MMIO
} type_State;
type_State state, next;
always_ff @(posedge clk, negedge rst) begin
if(!rst) state <= S_IDLE;
else state <= next;
end
type_Data mmioOut, mmioOut_r;
always_comb begin
mmioOut = 32'b0;
case(bCacheIf.addr)
P_SW : mmioOut = {16'b0, iSw};
P_ENT: mmioOut = {31'b0, iEnt};
endcase
end
always_ff @(posedge clk) begin
mmioOut_r <= mmioOut;
end
always_comb begin
next = S_IDLE;
bCacheIf.ready = 0; //set deafult value so that we donnot have to set manually
bCacheIf.dataS2M = 32'b0;
oLedWe = 0;
oSegWe = 0;
oEntClr = 0;
case(state)
S_IDLE: begin
bCacheIf.dataS2M = mmioOut_r;
if(bCacheIf.valid) begin
if(mmio) begin
case(bCacheIf.addr)
P_LED: if(bCacheIf.wr) oLedWe = 1;
P_SW : ;
P_SEG: if(bCacheIf.wr) oSegWe = 1;
P_ENT: oEntClr = 1;
endcase
bCacheIf.ready = 1;
next = S_IDLE;
end
else begin
//TODO: handle normal memory access
end
end
end
endcase
end
endmodule