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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [rand_delay.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
//   rand_delay.v
7
//
8
// Abstract:
9
//   Pipeline delay module (without reset)
10
//       parameters :
11
//                WIDTH      data width (default value is 8)
12
//                NUM_DELAY  number of delay cycle  (default value is 8)
13
//
14
// Author:
15 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
16 2 specular
//
17
//======================================================================
18
//
19
// Copyright (c) 2015, Kenji Ishimaru
20
// All rights reserved.
21
//
22
// Redistribution and use in source and binary forms, with or without
23
// modification, are permitted provided that the following conditions are met:
24
//
25
//  -Redistributions of source code must retain the above copyright notice,
26
//   this list of conditions and the following disclaimer.
27
//  -Redistributions in binary form must reproduce the above copyright notice,
28
//   this list of conditions and the following disclaimer in the documentation
29
//   and/or other materials provided with the distribution.
30
//
31
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
35
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
//
43
// Revision History
44
 
45
module rand_delay (
46
    clk_core,
47
    rst_x,
48
    i_en,
49
    i_delay,
50
    i_data,
51
    o_data,
52
    o_en
53
);
54
 
55
////////////////////////////
56
// parameter
57
////////////////////////////
58
    parameter P_WIDTH     = 8;
59
    parameter P_NUM_DELAY = 8;
60
////////////////////////////
61
// I/O definition
62
////////////////////////////
63
    input                clk_core;
64
    input                rst_x;
65
    input                i_en;
66
    input  [7:0]          i_delay;
67
    input  [P_WIDTH-1:0] i_data;
68
    output [P_WIDTH-1:0] o_data;
69
    output o_en;
70
////////////////////////////
71
// wire
72
////////////////////////////
73
  wire w_full;
74
  wire w_ren;
75
  wire [P_WIDTH-1:0] w_dt;
76
  wire w_empty;
77
 
78
////////////////////////////
79
// reg
80
////////////////////////////
81
localparam P_IDLE = 'd0;
82
localparam P_WAIT = 'd1;
83
    reg [1:0] r_state;
84
    reg [7:0] r_cnt;
85
    reg [7:0] r_end;
86
 
87
////////////////////////////
88
// assign
89
////////////////////////////
90
    assign w_ren = ((r_state == P_IDLE) & (i_delay == 'd0))|
91
                   ((r_state == P_WAIT) & (r_end == r_cnt));
92
    // in/out port connection
93
    assign o_data =  (w_empty) ? 'd0 : w_dt;
94
    assign o_en = w_ren & !w_empty;
95
////////////////////////////
96
// always
97
////////////////////////////
98
    always @(posedge clk_core or negedge rst_x) begin
99
      if (~rst_x) begin
100
        r_state <= P_IDLE;
101
      end else begin
102
        case (r_state)
103
          P_IDLE:begin
104
            if (~w_empty) begin
105
              if (i_delay != 0) begin
106
                r_end <= i_delay;
107
                r_cnt <= 'd0;
108
                r_state <= P_WAIT;
109
              end
110
            end
111
          end
112
          P_WAIT:begin
113
            r_cnt <= r_cnt + 1;
114
            if (r_end == r_cnt) begin
115
              r_state <= P_IDLE;
116
            end
117
          end
118
        endcase
119
      end
120
    end
121
 
122
mfifo #(P_WIDTH,8) u_fifo (
123
  .i_wstrobe(i_en),
124
  .i_dt(i_data),
125
  .o_full(w_full),
126
  .i_renable(w_ren),
127
  .o_dt(w_dt),
128
  .o_empty(w_empty),
129
  .o_dnum(),
130
  .clk(clk_core),
131
  .rst_x(rst_x)
132
);
133
 
134
endmodule

powered by: WebSVN 2.1.0

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