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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [implement/] [rtl/] [de0/] [fm_avalon.v] - Blame information for rev 9

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_3d_wrapper.v
7
//
8
// Abstract:
9
//   Monophony core top module AVALON version
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.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(
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_rstr,
61
    i_rd
62
);
63
parameter P_AVALON_ADR_WIDTH='d10;
64
parameter P_AVALON_BE_WIDTH='d4;
65
parameter P_AVALON_DATA_WIDTH='d32;
66
parameter P_INTERNAL_ADR_WIDTH=P_AVALON_ADR_WIDTH;
67
parameter P_INTERNAL_BE_WIDTH=P_AVALON_BE_WIDTH;
68
parameter P_INTERNAL_DATA_WIDTH=P_AVALON_DATA_WIDTH;
69
 
70
 
71
//////////////////////////////////
72
// I/O port definition
73
//////////////////////////////////
74
    input           clk_core;
75
    input           rst_x;
76
    // AVALON Bus
77
    input  [P_AVALON_ADR_WIDTH-1:0]
78
                   i_av_adr;
79
    input  [P_AVALON_BE_WIDTH-1:0]
80
                   i_av_be;
81
    input          i_av_r;
82
    output [P_AVALON_DATA_WIDTH-1:0]
83
                   o_av_rd;
84
    input          i_av_w;
85
    input  [P_AVALON_DATA_WIDTH-1:0]
86
                   i_av_wd;
87
    output         o_av_wait;
88
    // internal side
89
    output          o_req;
90
    output          o_wr;
91
    output [P_INTERNAL_ADR_WIDTH-1:0]
92
                    o_adrs;
93
    input           i_ack;
94
    output [P_INTERNAL_BE_WIDTH-1:0]
95
                    o_be;
96
    output [P_INTERNAL_DATA_WIDTH-1:0]
97
                    o_wd;
98
    input           i_rstr;
99
    input  [P_INTERNAL_DATA_WIDTH-1:0]
100
                    i_rd;
101
 
102
//////////////////////////////////
103
// parameter definition
104
//////////////////////////////////
105
    localparam P_IDLE         = 2'h0;
106
    localparam P_WAIT_ACK     = 2'h1;
107
    localparam P_R_WAIT_RDATA = 2'h2;
108
    localparam P_ACK_OUT      = 2'h3;
109
//////////////////////////////////
110
// reg
111
//////////////////////////////////
112
    reg  [1:0]  r_state;
113
    reg         r_req;
114
    reg         r_wr;
115
    reg  [P_INTERNAL_ADR_WIDTH-1:0]
116
                r_adrs;
117
    reg  [P_INTERNAL_DATA_WIDTH-1:0]
118
                r_rdata;
119
    reg  [P_INTERNAL_BE_WIDTH-1:0]
120
                r_be;
121
    reg  [P_INTERNAL_DATA_WIDTH-1:0]
122
                r_wd;
123
 
124
//////////////////////////////////
125
// wire
126
//////////////////////////////////
127
    wire  [P_INTERNAL_ADR_WIDTH-1:0]
128
                w_adrs;
129
    wire  [P_INTERNAL_DATA_WIDTH-1:0]
130
                w_rdata;
131
    wire  [P_INTERNAL_BE_WIDTH-1:0]
132
                w_be;
133
    wire  [P_INTERNAL_DATA_WIDTH-1:0]
134
                w_wd;
135
//////////////////////////////////
136
// assign
137
//////////////////////////////////
138
    generate
139
      if (P_INTERNAL_DATA_WIDTH == 'd8) begin
140
        wire [1:0] w_ba;
141
        assign o_av_rd = {'d4{r_rdata}};
142
        assign w_ba = i_av_be[1] ? 2'd1 :
143
                      i_av_be[2] ? 2'd2 :
144
                      i_av_be[3] ? 2'd3 :
145
                                   2'd0 ;
146
         assign w_adrs = {i_av_adr,w_ba};
147
        assign w_be = i_av_be[w_ba];
148
        assign w_wd = (w_ba == 'd1) ? i_av_wd[15:8]:
149
                      (w_ba == 'd2) ? i_av_wd[23:16]:
150
                      (w_ba == 'd3) ? i_av_wd[31:24]:
151
                                      i_av_wd[7:0];
152
 
153
      end else begin
154
        assign o_av_rd = r_rdata;
155
        assign w_adrs = i_av_adr;
156
        assign w_be = i_av_be;
157
        assign w_wd = i_av_wd;
158
      end
159
    endgenerate
160
    assign o_req = r_req;
161
    assign o_wr = r_wr;
162
    assign o_adrs = r_adrs;
163
    assign o_be = r_be;
164
    assign o_wd = r_wd;
165
    assign o_av_wait = !(!(i_av_r|i_av_w) & (r_state == P_IDLE) |
166
                         (r_state == P_ACK_OUT));
167
 
168
 
169
//////////////////////////////////
170
// always
171
//////////////////////////////////
172
    // core clock domain 
173
    always @(posedge clk_core or negedge rst_x) begin
174
      if (~rst_x) begin
175
        r_state <= P_IDLE;
176
        r_req <= 1'b0;
177
        r_wr <= 1'b0;
178
        r_adrs <= {P_INTERNAL_ADR_WIDTH{1'b0}};
179
        r_rdata <= {P_INTERNAL_DATA_WIDTH{1'b0}};
180
        r_be <= {P_INTERNAL_BE_WIDTH{1'b0}};
181
        r_wd <= {P_INTERNAL_DATA_WIDTH{1'b0}};
182
      end else begin
183
        case (r_state)
184
          P_IDLE: begin
185
            if (i_av_w) begin
186
              // write
187
              r_req <= 1'b1;
188
              r_wr <= 1'b1;
189
              r_adrs <= w_adrs;
190
              r_be <= w_be;
191
              r_wd <= w_wd;
192
              r_state <= P_WAIT_ACK;
193
            end else if (i_av_r) begin
194
              // read
195
              r_req <= 1'b1;
196
              r_wr <= 1'b0;
197
              r_adrs <= w_adrs;
198
              r_state <= P_WAIT_ACK;
199
                    end
200
          end
201
          P_WAIT_ACK: begin
202
            if (i_ack) begin
203
              r_req <= 1'b0;
204
              if (r_wr) begin
205
                // write
206
                r_state <= P_ACK_OUT;
207
              end else begin
208
                if (i_rstr) begin
209
                  r_rdata <= i_rd;
210
                  r_state <= P_ACK_OUT;
211
                end else begin
212
                  r_state <= P_R_WAIT_RDATA;
213
                end
214
              end
215
            end
216
          end
217
          P_R_WAIT_RDATA: begin
218
            if (i_rstr) begin
219
              r_rdata <= i_rd;
220
              r_state <= P_ACK_OUT;
221
            end
222
          end
223
          P_ACK_OUT: begin
224
            r_state <= P_IDLE;
225
          end
226
        endcase
227
      end
228
    end
229
 
230
endmodule

powered by: WebSVN 2.1.0

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