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

Subversion Repositories wb_size_bridge

[/] [wb_size_bridge/] [trunk/] [src/] [async_mem_if.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
 
29
module async_mem_if(  async_dq, async_addr, async_ub_n, async_lb_n,
30
                      async_we_n, async_ce_n, async_oe_n,
31
                      wb_clk_i, wb_rst_i, wb_adr_i, wb_dat_i,
32
                      wb_we_i, wb_stb_i, wb_cyc_i, wb_sel_i,
33
                      wb_dat_o, wb_ack_o,
34
                      ce_setup, op_hold, ce_hold,
35
                      big_endian_if_i, lo_byte_if_i
36
                  );
37
 
38
  parameter AW = 32;
39
  parameter DW = 8;
40
 
41
  inout   [(DW-1):0]  async_dq;
42
  output  [(AW-1):0]  async_addr;
43
  output              async_ub_n;
44
  output              async_lb_n;
45
  output              async_we_n;
46
  output              async_ce_n;
47
  output              async_oe_n;
48
  input           wb_clk_i;
49
  input           wb_rst_i;
50
  input   [31:0]  wb_adr_i;
51
  input   [31:0]  wb_dat_i;
52
  input           wb_we_i;
53
  input           wb_stb_i;
54
  input           wb_cyc_i;
55
  input   [3:0]   wb_sel_i;
56
  output  [31:0]  wb_dat_o;
57
  output          wb_ack_o;
58
  input [3:0]     ce_setup;
59
  input [3:0]     op_hold;  // do not set to zero.
60
  input [3:0]     ce_hold;
61
  input           big_endian_if_i;
62
  input           lo_byte_if_i;
63
 
64
 
65
  //---------------------------------------------------
66
  // big endian bridge
67
 
68
  wire [31:0] beb_wb_dat_i;
69
  assign beb_wb_dat_i[7:0]    = big_endian_if_i ? wb_dat_i[31:24]  : wb_dat_i[7:0];
70
  assign beb_wb_dat_i[15:8]   = big_endian_if_i ? wb_dat_i[23:16]  : wb_dat_i[15:8];
71
  assign beb_wb_dat_i[23:16]  = big_endian_if_i ? wb_dat_i[15:8]   : wb_dat_i[23:16];
72
  assign beb_wb_dat_i[31:24]  = big_endian_if_i ? wb_dat_i[7:0]    : wb_dat_i[31:24];
73
 
74
  wire [31:0] beb_wb_dat_o;
75
  assign wb_dat_o[7:0]    = big_endian_if_i ? beb_wb_dat_o[31:24]  : beb_wb_dat_o[7:0];
76
  assign wb_dat_o[15:8]   = big_endian_if_i ? beb_wb_dat_o[23:16]  : beb_wb_dat_o[15:8];
77
  assign wb_dat_o[23:16]  = big_endian_if_i ? beb_wb_dat_o[15:8]   : beb_wb_dat_o[23:16];
78
  assign wb_dat_o[31:24]  = big_endian_if_i ? beb_wb_dat_o[7:0]    : beb_wb_dat_o[31:24];
79
 
80
  wire [3:0] beb_wb_sel_i;
81
  assign beb_wb_sel_i[0] = big_endian_if_i ? wb_sel_i[3] : wb_sel_i[0];
82
  assign beb_wb_sel_i[1] = big_endian_if_i ? wb_sel_i[2] : wb_sel_i[1];
83
  assign beb_wb_sel_i[2] = big_endian_if_i ? wb_sel_i[1] : wb_sel_i[2];
84
  assign beb_wb_sel_i[3] = big_endian_if_i ? wb_sel_i[0] : wb_sel_i[3];
85
 
86
 
87
  //---------------------------------------------------
88
  // wb_size_bridge
89
  wire [15:0] wb_lo_dat_o;
90
  wire [15:0] wb_lo_dat_i;
91
  wire [31:0] wb_lo_adr_o;
92
  wire        wb_lo_cyc_o;
93
  wire        wb_lo_stb_o;
94
  wire        wb_lo_we_o;
95
  wire [1:0]  wb_lo_sel_o;
96
  wire        wb_lo_ack_i;
97
  wire        wb_lo_err_i = 1'b0;
98
  wire        wb_lo_rty_i = 1'b0;
99
 
100
 
101
  wb_size_bridge i_wb_size_bridge(
102
                                    .wb_hi_clk_i(wb_clk_i),
103
                                    .wb_hi_rst_i(wb_rst_i),
104
                                    .wb_hi_dat_o(beb_wb_dat_o),
105
                                    .wb_hi_dat_i(beb_wb_dat_i),
106
                                    .wb_hi_adr_i( wb_adr_i ),
107
                                    .wb_hi_cyc_i(wb_cyc_i),
108
                                    .wb_hi_stb_i(wb_stb_i),
109
                                    .wb_hi_we_i(wb_we_i),
110
                                    .wb_hi_sel_i(beb_wb_sel_i),
111
                                    .wb_hi_ack_o(wb_ack_o),
112
                                    .wb_hi_err_o(),
113
                                    .wb_hi_rty_o(),
114
 
115
                                    .wb_lo_clk_o(),
116
                                    .wb_lo_rst_o(),
117
                                    .wb_lo_dat_i(wb_lo_dat_i),
118
                                    .wb_lo_dat_o(wb_lo_dat_o),
119
                                    .wb_lo_adr_o(wb_lo_adr_o),
120
                                    .wb_lo_cyc_o(wb_lo_cyc_o),
121
                                    .wb_lo_stb_o(wb_lo_stb_o),
122
                                    .wb_lo_we_o(wb_lo_we_o),
123
                                    .wb_lo_sel_o(wb_lo_sel_o),
124
                                    .wb_lo_ack_i(wb_lo_ack_i),
125
                                    .wb_lo_err_i(wb_lo_err_i),
126
                                    .wb_lo_rty_i(wb_lo_rty_i),
127
 
128
                                    .lo_byte_if_i(lo_byte_if_i)
129
                                  );
130
 
131
 
132
  // --------------------------------------------------------------------
133
  //  state machine inputs
134
 
135
  wire zero_ce_setup  = (ce_setup == 4'h0);
136
  wire zero_ce_hold   = (ce_hold  == 4'h0);
137
  wire wait_for_counter;
138
 
139
 
140
  // --------------------------------------------------------------------
141
  //  state machine
142
 
143
  localparam   STATE_DONT_CARE  = 4'b????;
144
  localparam   STATE_IDLE       = 4'b0001;
145
  localparam   STATE_CE_SETUP   = 4'b0010;
146
  localparam   STATE_OP_HOLD    = 4'b0100;
147
  localparam   STATE_CE_HOLD    = 4'b1000;
148
 
149
  reg [3:0] state;
150
  reg [3:0] next_state;
151
 
152
  always @(posedge wb_clk_i or posedge wb_rst_i)
153
    if(wb_rst_i)
154
      state <= STATE_IDLE;
155
    else
156
      state <= next_state;
157
 
158
  always @(*)
159
    case( state )
160
      STATE_IDLE:     if( wb_stb_i & wb_cyc_i )
161
                        if( zero_ce_setup )
162
                          next_state = STATE_OP_HOLD;
163
                        else
164
                          next_state = STATE_CE_SETUP;
165
                      else
166
                        next_state = STATE_IDLE;
167
 
168
      STATE_CE_SETUP: if( wait_for_counter )
169
                        next_state = STATE_CE_SETUP;
170
                      else
171
                        next_state = STATE_OP_HOLD;
172
 
173
      STATE_OP_HOLD:  if( wait_for_counter )
174
                        next_state = STATE_OP_HOLD;
175
                      else
176
                        if( zero_ce_hold )
177
                          next_state = STATE_IDLE;
178
                        else
179
                          next_state = STATE_CE_HOLD;
180
 
181
      STATE_CE_HOLD:  if( wait_for_counter )
182
                        next_state = STATE_CE_HOLD;
183
                      else
184
                        next_state = STATE_IDLE;
185
 
186
      default:        next_state = STATE_IDLE;
187
    endcase
188
 
189
 
190
  // --------------------------------------------------------------------
191
  //  state machine outputs
192
 
193
  wire assert_ce = (state != STATE_IDLE);
194
  wire assert_op = (state == STATE_OP_HOLD);
195
 
196
  assign wb_lo_ack_i =  ( (state == STATE_OP_HOLD) & ~wait_for_counter & zero_ce_hold) |
197
                        ( (state == STATE_CE_HOLD) & ~wait_for_counter );
198
 
199
 
200
  //---------------------------------------------------
201
  // async_dq_buffer
202
  reg [(DW-1):0] async_dq_buffer;
203
  wire async_dq_buffer_en  = (state == STATE_OP_HOLD);
204
 
205
  always @(posedge wb_clk_i)
206
    if(async_dq_buffer_en)
207
      async_dq_buffer <= async_dq;
208
    else
209
      async_dq_buffer <= async_dq_buffer;
210
 
211
 
212
  //---------------------------------------------------
213
  // bypass_mux
214
 
215
  wire  bypass_mux_en = (state == STATE_OP_HOLD) & zero_ce_hold;
216
  wire [(DW-1):0] bypass_mux;
217
 
218
  assign bypass_mux = bypass_mux_en ? async_dq : async_dq_buffer;
219
 
220
 
221
  // --------------------------------------------------------------------
222
  //  wait counter mux
223
  reg  [3:0] counter_mux;
224
 
225
  always @(*)
226
    case( next_state )
227
      STATE_CE_SETUP: counter_mux = ce_setup;
228
      STATE_OP_HOLD:  counter_mux = op_hold;
229
      STATE_CE_HOLD:  counter_mux = ce_hold;
230
      default:        counter_mux = 4'bxxxx;
231
    endcase
232
 
233
 
234
  // --------------------------------------------------------------------
235
  //  wait counter
236
  reg   [3:0] counter;
237
  wire        counter_load = ~(state == next_state);
238
 
239
  always @(posedge wb_clk_i)
240
    if( counter_load )
241
      counter <= counter_mux - 1'b1;
242
    else
243
      counter <= counter - 1'b1;
244
 
245
  assign wait_for_counter = (counter != 4'h0);
246
 
247
 
248
  //---------------------------------------------------
249
  // outputs
250
 
251
  generate
252
    if( DW == 16 )
253
      begin
254
        assign async_dq    = wb_lo_we_o ? wb_lo_dat_o : 16'hzz;
255
        assign async_addr  = wb_lo_adr_o[AW:1];
256
        assign wb_lo_dat_i = bypass_mux;
257
      end
258
    else
259
      begin
260
        assign async_dq    = wb_lo_we_o ? wb_lo_dat_o : 8'hz;
261
        assign async_addr  = wb_lo_adr_o[(AW-1):0];
262
        assign wb_lo_dat_i = {8'h00, bypass_mux};
263
      end
264
  endgenerate
265
 
266
  assign async_ub_n  = ~wb_lo_sel_o[1];
267
  assign async_lb_n  = ~wb_lo_sel_o[0];
268
  assign async_we_n  = ~( wb_lo_we_o & assert_op );
269
  assign async_ce_n  = ~( wb_stb_i & wb_cyc_i & assert_ce );
270
  assign async_oe_n  = ~( ~wb_lo_we_o & assert_op );
271
 
272
 
273
endmodule
274
 
275
 

powered by: WebSVN 2.1.0

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