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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [de0/] [fm_avalon_wb.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_avalon_wb.v
7
//
8
// Abstract:
9 4 specular
//   AVALON-WISHBONE bus bridge
10 2 specular
//
11
// Author:
12 4 specular
//   Kenji Ishimaru (info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
module fm_avalon_wb(
43
    clk_core,
44
    rst_x,
45
    // AVALON bus
46
    i_av_adr,
47
    i_av_be,
48
    i_av_r,
49
    o_av_rd,
50
    i_av_w,
51
    i_av_wd,
52
    o_av_wait,
53
    // internal side
54
    o_req,
55
    o_wr,
56
    o_adrs,
57
    i_ack,
58
    o_be,
59
    o_wd,
60
    i_rd
61
);
62
parameter P_AVALON_ADR_WIDTH='d10;
63
parameter P_AVALON_BE_WIDTH='d4;
64
parameter P_AVALON_DATA_WIDTH='d32;
65
parameter P_INTERNAL_ADR_WIDTH=P_AVALON_ADR_WIDTH;
66
parameter P_INTERNAL_BE_WIDTH=P_AVALON_BE_WIDTH;
67
parameter P_INTERNAL_DATA_WIDTH=P_AVALON_DATA_WIDTH;
68
 
69
 
70
//////////////////////////////////
71
// I/O port definition
72
//////////////////////////////////
73
    input           clk_core;
74
    input           rst_x;
75
    // AVALON Bus
76
    input  [P_AVALON_ADR_WIDTH-1:0]
77
                   i_av_adr;
78
    input  [P_AVALON_BE_WIDTH-1:0]
79
                   i_av_be;
80
    input          i_av_r;
81
    output [P_AVALON_DATA_WIDTH-1:0]
82
                   o_av_rd;
83
    input          i_av_w;
84
    input  [P_AVALON_DATA_WIDTH-1:0]
85
                   i_av_wd;
86
    output         o_av_wait;
87
    // internal side
88
    output          o_req;
89
    output          o_wr;
90
    output [P_INTERNAL_ADR_WIDTH-1:0]
91
                    o_adrs;
92
    input           i_ack;
93
    output [P_INTERNAL_BE_WIDTH-1:0]
94
                    o_be;
95
    output [P_INTERNAL_DATA_WIDTH-1:0]
96
                    o_wd;
97
    input  [P_INTERNAL_DATA_WIDTH-1:0]
98
                    i_rd;
99
 
100
//////////////////////////////////
101
// parameter definition
102
//////////////////////////////////
103
    localparam P_IDLE         = 2'h0;
104
    localparam P_WAIT_ACK     = 2'h1;
105
    localparam P_R_WAIT_RDATA = 2'h2;
106
    localparam P_ACK_OUT      = 2'h3;
107
//////////////////////////////////
108
// reg
109
//////////////////////////////////
110
    reg  [1:0]  r_state;
111
    reg         r_req;
112
    reg         r_wr;
113
    reg  [P_INTERNAL_ADR_WIDTH-1:0]
114
                r_adrs;
115
    reg  [P_INTERNAL_DATA_WIDTH-1:0]
116
                r_rdata;
117
    reg  [P_INTERNAL_BE_WIDTH-1:0]
118
                r_be;
119
    reg  [P_INTERNAL_DATA_WIDTH-1:0]
120
                r_wd;
121
 
122
//////////////////////////////////
123
// wire
124
//////////////////////////////////
125
    wire  [P_INTERNAL_ADR_WIDTH-1:0]
126
                w_adrs;
127
    wire  [P_INTERNAL_DATA_WIDTH-1:0]
128
                w_rdata;
129
    wire  [P_INTERNAL_BE_WIDTH-1:0]
130
                w_be;
131
    wire  [P_INTERNAL_DATA_WIDTH-1:0]
132
                w_wd;
133
//////////////////////////////////
134
// assign
135
//////////////////////////////////
136
    generate
137
      if (P_INTERNAL_DATA_WIDTH == 'd8) begin
138
        wire [1:0] w_ba;
139
        assign o_av_rd = {'d4{r_rdata}};
140
        assign w_ba = i_av_be[1] ? 2'd1 :
141
                      i_av_be[2] ? 2'd2 :
142
                      i_av_be[3] ? 2'd3 :
143
                                   2'd0 ;
144
         assign w_adrs = {i_av_adr,w_ba};
145
        assign w_be = i_av_be[w_ba];
146
        assign w_wd = (w_ba == 'd1) ? i_av_wd[15:8]:
147
                      (w_ba == 'd2) ? i_av_wd[23:16]:
148
                      (w_ba == 'd3) ? i_av_wd[31:24]:
149
                                      i_av_wd[7:0];
150
 
151
      end else begin
152
        assign o_av_rd = r_rdata;
153
        assign w_adrs = i_av_adr;
154
        assign w_be = i_av_be;
155
        assign w_wd = i_av_wd;
156
      end
157
    endgenerate
158
    assign o_req = r_req;
159
    assign o_wr = r_wr;
160
    assign o_adrs = r_adrs;
161
    assign o_be = r_be;
162
    assign o_wd = r_wd;
163
    assign o_av_wait = !(!(i_av_r|i_av_w) & (r_state == P_IDLE) |
164
                         (r_state == P_ACK_OUT));
165
 
166
 
167
//////////////////////////////////
168
// always
169
//////////////////////////////////
170
    // core clock domain 
171
    always @(posedge clk_core or negedge rst_x) begin
172
      if (~rst_x) begin
173
        r_state <= P_IDLE;
174
        r_req <= 1'b0;
175
        r_wr <= 1'b0;
176
        r_adrs <= {P_INTERNAL_ADR_WIDTH{1'b0}};
177
        r_rdata <= {P_INTERNAL_DATA_WIDTH{1'b0}};
178
        r_be <= {P_INTERNAL_BE_WIDTH{1'b0}};
179
        r_wd <= {P_INTERNAL_DATA_WIDTH{1'b0}};
180
      end else begin
181
        case (r_state)
182
          P_IDLE: begin
183
            if (i_av_w) begin
184
              // write
185
              r_req <= 1'b1;
186
              r_wr <= 1'b1;
187
              r_adrs <= w_adrs;
188
              r_be <= w_be;
189
              r_wd <= w_wd;
190
              r_state <= P_WAIT_ACK;
191
            end else if (i_av_r) begin
192
              // read
193
              r_req <= 1'b1;
194
              r_wr <= 1'b0;
195
              r_adrs <= w_adrs;
196
              r_state <= P_WAIT_ACK;
197
                    end
198
          end
199
          P_WAIT_ACK: begin
200
            if (i_ack) begin
201
              r_req <= 1'b0;
202
              if (r_wr) begin
203
                // write
204
                r_state <= P_ACK_OUT;
205
              end else begin
206
                r_rdata <= i_rd;
207
                r_state <= P_ACK_OUT;
208
              end
209
            end
210
          end
211
          P_ACK_OUT: begin
212
            r_state <= P_IDLE;
213
          end
214
        endcase
215
      end
216
    end
217
 
218
endmodule

powered by: WebSVN 2.1.0

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