OpenCores
URL https://opencores.org/ocsvn/aemb/aemb/trunk

Subversion Repositories aemb

[/] [aemb/] [tags/] [AEMB_7_05/] [rtl/] [verilog/] [aeMB_wbbus.v] - Blame information for rev 206

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 sybreon
/*
2
 * $Id: aeMB_wbbus.v,v 1.1 2007-04-13 13:02:34 sybreon Exp $
3
 *
4
 * AEMB WISHBONE Bus Interface Unit
5
 * Copyright (C) 2006-2007 Shawn Tan Ser Ngiap <shawn.tan@aeste.net>
6
 *
7
 * This library is free software; you can redistribute it and/or modify it
8
 * under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation; either version 2.1 of the License,
10
 * or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
 * License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this library; if not, write to the Free Software Foundation, Inc.,
19
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
 *
21
 * DESCRIPTION
22
 * This contains the internal to external bus unifier as well as cache.
23
 * Cache is implemented as write-thru direct mapped cache.
24
 *
25
 * HISTORY
26
 * $Log: not supported by cvs2svn $
27
 */
28
 
29
// 98@90
30
module aeMB_wbbus (/*AUTOARG*/
31
   // Outputs
32
   wb_adr_o, wb_dat_o, wb_sel_o, wb_stb_o, wb_wre_o, dwb_ack_i,
33
   dwb_dat_i, iwb_ack_i, iwb_dat_i,
34
   // Inputs
35
   wb_dat_i, wb_ack_i, dwb_adr_o, dwb_dat_o, dwb_stb_o, dwb_we_o,
36
   iwb_adr_o, iwb_stb_o, sys_clk_i, sys_rst_i
37
   );
38
   parameter ASIZ = 32;
39
   parameter CSIZ = 7;
40
   /* DO NOT TOUCH */
41
   parameter ISIZ = ASIZ;
42
   parameter DSIZ = ASIZ;
43
 
44
   // External WISHBONE
45
   output [ASIZ-1:0] wb_adr_o;
46
   output [31:0]     wb_dat_o;
47
   output [3:0]      wb_sel_o;
48
   output            wb_stb_o;
49
   output            wb_wre_o;
50
   input [31:0]      wb_dat_i;
51
   input             wb_ack_i;
52
 
53
   // Internal WISHBONE
54
   input [DSIZ-1:0]  dwb_adr_o;
55
   input [31:0]      dwb_dat_o;
56
   input             dwb_stb_o;
57
   input             dwb_we_o;
58
   output            dwb_ack_i;
59
   output [31:0]     dwb_dat_i;
60
 
61
   input [ISIZ-1:0]  iwb_adr_o;
62
   input             iwb_stb_o;
63
   output            iwb_ack_i;
64
   output [31:0]     iwb_dat_i;
65
 
66
   // System
67
   input             sys_clk_i, sys_rst_i;
68
 
69
   wire              nclk = sys_clk_i;
70
   wire              nrst = sys_rst_i;
71
 
72
   // FSM Machine
73
   parameter [1:0]
74
                FSM_STORE = 2'o3,
75
                FSM_LOAD = 2'o2,
76
                FSM_FETCH = 2'o1,
77
                FSM_IDLE = 2'o0;
78
   reg [1:0]          rFSM, rFSM_;
79
 
80
   always @(negedge nclk or negedge nrst)
81
     if (!nrst) rFSM <= FSM_IDLE; else rFSM <= #1 rFSM_;
82
 
83
   always @(/*AUTOSENSE*/dwb_ack_i or dwb_stb_o or dwb_we_o
84
            or iwb_ack_i or iwb_stb_o or rFSM or wb_ack_i or wb_stb_o)
85
     case (rFSM)
86
       FSM_IDLE: rFSM_ <= (iwb_stb_o & !iwb_ack_i) ? FSM_FETCH :
87
                          (dwb_stb_o & !dwb_ack_i & dwb_we_o) ? FSM_STORE :
88
                          (dwb_stb_o & !dwb_ack_i & !dwb_we_o) ? FSM_LOAD :
89
                          FSM_IDLE;
90
       FSM_FETCH, FSM_LOAD, FSM_STORE:
91
         rFSM_ <= (wb_ack_i & wb_stb_o) ? FSM_IDLE : rFSM;
92
     endcase // case (rFSM)
93
 
94
   // WISHBONE LOGIC ////////////////////////////////////////////////////
95
   reg               rSTB, xSTB;
96
   reg               rWRE, xWRE;
97
   reg [ASIZ-1:0]    rADR, xADR;
98
   reg [31:0]         rDAT, xDAT;
99
   reg               rIWE, xIWE;
100
 
101
   assign            wb_stb_o = rSTB;
102
   assign            wb_wre_o = rWRE;
103
   assign            wb_dat_o = rDAT;
104
   assign            wb_adr_o = rADR;
105
 
106
   // STB
107
   always @(/*AUTOSENSE*/dwb_ack_i or dwb_stb_o or iwb_ack_i
108
            or iwb_stb_o or rFSM or rSTB or wb_ack_i or wb_stb_o)
109
     case (rFSM)
110
       FSM_IDLE: xSTB <= (dwb_stb_o & !dwb_ack_i) | (iwb_stb_o & !iwb_ack_i);
111
       default: xSTB <= (wb_ack_i & wb_stb_o) ^ rSTB;
112
     endcase
113
 
114
   // WRE
115
   always @(/*AUTOSENSE*/dwb_ack_i or dwb_stb_o or dwb_we_o
116
            or iwb_ack_i or iwb_stb_o or rFSM or rWRE or wb_ack_i
117
            or wb_stb_o or wb_wre_o)
118
     case (rFSM)
119
       FSM_IDLE: xWRE <= (iwb_stb_o & !iwb_ack_i) ? 1'b0 :
120
                         (dwb_stb_o & dwb_we_o & !dwb_ack_i);
121
       default: xWRE <= (wb_ack_i & wb_stb_o & wb_wre_o) ^ rWRE;
122
     endcase // case (rFSM)
123
 
124
   // DAT
125
   always @(/*AUTOSENSE*/dwb_dat_i or dwb_dat_o or rDAT or rFSM)
126
     case (rFSM)
127
       FSM_IDLE: xDAT <= dwb_dat_o;
128
       FSM_LOAD: xDAT <= dwb_dat_i;
129
       FSM_STORE: xDAT <= rDAT;
130
       FSM_FETCH: xDAT <= dwb_dat_i;
131
     endcase
132
 
133
   // ADR
134
   always @(/*AUTOSENSE*/dwb_adr_o or iwb_ack_i or iwb_adr_o
135
            or iwb_stb_o or rADR or rFSM)
136
     case (rFSM)
137
       FSM_IDLE: xADR <= (iwb_stb_o & !iwb_ack_i) ? iwb_adr_o : dwb_adr_o;
138
       default: xADR <= rADR;
139
     endcase // case (rFSM)
140
 
141
   // ICWE
142
   always @(/*AUTOSENSE*/rFSM or wb_ack_i or wb_stb_o)
143
     case (rFSM)
144
       FSM_FETCH: xIWE <= (wb_ack_i & wb_stb_o);
145
       default: xIWE <= 1'b0;
146
     endcase
147
 
148
   // CACHE LOGIC ///////////////////////////////////////////////////////
149
 
150
   wire [ASIZ-3:CSIZ] wICHK;
151
   wire               wIVAL;
152
   reg [CSIZ-1:0]     rILINE;
153
   reg [ASIZ+32:CSIZ+2] rIMEM[(1<<CSIZ)-1:0];
154
 
155
   assign               {wIVAL, wICHK, iwb_dat_i} = rIMEM[rILINE];
156
   assign               iwb_ack_i = wIVAL & ~|(wICHK ^ iwb_adr_o[ASIZ-1:CSIZ+2]) & iwb_stb_o;
157
 
158
   wire [CSIZ-1:0]       wILINE = rADR[CSIZ+1:2];
159
   wire [ASIZ-3:CSIZ]   wITAG = rADR[ASIZ-1:CSIZ+2];
160
 
161
   always @(posedge nclk) begin
162
      if (rIWE) begin
163
         rIMEM[wILINE] <= {1'b1,wITAG,rDAT};
164
      end
165
      rILINE <= iwb_adr_o[CSIZ+1:2];
166
   end
167
 
168
   assign dwb_dat_i = wb_dat_i;
169
   assign dwb_ack_i = (wb_stb_o & wb_ack_i) & |(rFSM ^ FSM_FETCH);
170
 
171
 
172
   // PIPELINE REGISTERS ///////////////////////////////////////////////
173
   always @(negedge nclk or negedge nrst)
174
     if (!nrst) begin
175
        /*AUTORESET*/
176
        // Beginning of autoreset for uninitialized flops
177
        rADR <= {(1+(ASIZ-1)){1'b0}};
178
        rDAT <= 32'h0;
179
        rIWE <= 1'h0;
180
        rSTB <= 1'h0;
181
        rWRE <= 1'h0;
182
        // End of automatics
183
     end else begin
184
        rDAT <= #1 xDAT;
185
        rADR <= #1 xADR;
186
        rWRE <= #1 xWRE;
187
        rSTB <= #1 xSTB;
188
        rIWE <= #1 xIWE;
189
     end
190
 
191
   // SIMULATION ONLY //////////////////////////////////////////////////
192
   integer i;
193
   initial begin
194
      for (i=0;i<((1<<CSIZ));i=i+1) begin
195
         rIMEM[i] <= 0;
196
      end
197
   end
198
 
199
endmodule // aeMB_wbbus

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.