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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [rtl/] [verilog/] [buffers/] [sd_fifo_tail_s.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ghutchis
//----------------------------------------------------------------------
2
// Srdy/Drdy FIFO Head "S"
3
//
4
// Building block for FIFOs.  The "S" (big) FIFO is design for smaller
5
// FIFOs based around memories or flops, with sizes that are a power of 2.
6
//
7
// The "S" FIFO can be used as a two-clock asynchronous FIFO.
8
//
9
// Naming convention: c = consumer, p = producer, i = internal interface
10
//----------------------------------------------------------------------
11
// Author: Guy Hutchison
12
//
13
// This block is uncopyrighted and released into the public domain.
14
//----------------------------------------------------------------------
15
 
16
// Clocking statement for synchronous blocks.  Default is for
17
// posedge clocking and positive async reset
18
`ifndef SDLIB_CLOCKING
19
 `define SDLIB_CLOCKING posedge clk or posedge reset
20
`endif
21
 
22
// delay unit for nonblocking assigns, default is to #1
23
`ifndef SDLIB_DELAY
24
 `define SDLIB_DELAY #1
25
`endif
26
 
27
module sd_fifo_tail_s
28
  #(parameter depth=16,
29
    parameter async=0,
30
    parameter asz=$clog2(depth)
31
    )
32
    (
33
     input                  clk,
34
     input                  reset,
35
 
36
     input [asz:0]          wrptr_head,
37
     output [asz:0]         rdptr_tail,
38
 
39
     output reg             rd_en,
40
     output [asz-1:0]       rd_addr,
41
 
42
     output reg             p_srdy,
43
     input                  p_drdy
44
     );
45
 
46
  reg [asz:0]            rdptr;
47
  reg [asz:0]            nxt_rdptr;
48
  reg [asz:0]            rdptr_p1;
49
  reg                   empty;
50
  reg                   nxt_p_srdy;
51
  wire [asz:0]           wrptr;
52
 
53
  assign rd_addr = nxt_rdptr[asz-1:0];
54
 
55
  always @*
56
    begin
57
      rdptr_p1 = rdptr + 1;
58
 
59
      empty = (wrptr == rdptr);
60
 
61
      if (p_drdy & p_srdy)
62
        nxt_rdptr = rdptr_p1;
63
      else
64
        nxt_rdptr = rdptr;
65
 
66
      nxt_p_srdy = (wrptr != nxt_rdptr);
67
      rd_en = (p_drdy & p_srdy) | (!empty & !p_srdy);
68
    end
69
 
70
  always @(`SDLIB_CLOCKING)
71
    begin
72
      if (reset)
73
        begin
74
          rdptr <= `SDLIB_DELAY 0;
75
          p_srdy  <= `SDLIB_DELAY 0;
76
        end
77
      else
78
        begin
79
          rdptr <= `SDLIB_DELAY nxt_rdptr;
80
          p_srdy <= `SDLIB_DELAY nxt_p_srdy;
81
        end // else: !if(reset)
82
    end // always @ (posedge clk)
83
 
84
  function [asz:0] bin2grey;
85
    input [asz:0] bin_in;
86
    integer       b;
87
    begin
88
      bin2grey[asz] = bin_in[asz];
89
      for (b=0; b<asz; b=b+1)
90
        bin2grey[b] = bin_in[b] ^ bin_in[b+1];
91
    end
92
  endfunction // for
93
 
94
  function [asz:0] grey2bin;
95
    input [asz:0] grey_in;
96
    integer       b;
97
    begin
98
      grey2bin[asz] = grey_in[asz];
99
      for (b=asz-1; b>=0; b=b-1)
100
        grey2bin[b] = grey_in[b] ^ grey2bin[b+1];
101
    end
102
  endfunction
103
 
104
  assign rdptr_tail = (async) ? bin2grey(rdptr) : rdptr;
105
  assign wrptr = (async)? grey2bin(wrptr_head) : wrptr_head;
106
 
107
endmodule // sd_fifo_head_s

powered by: WebSVN 2.1.0

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