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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [wbufifo.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbufifo.v
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     This was once a FIFO for a UART ... but now it works as a
8
//              synchronous FIFO for JTAG-wishbone conversion 36-bit codewords.  
9
//
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// License:     GPL, v3, as defined and found on www.gnu.org,
29
//              http://www.gnu.org/licenses/gpl.html
30
//
31
//
32
////////////////////////////////////////////////////////////////////////////////
33
//
34
//
35
module wbufifo(i_clk, i_rst, i_wr, i_data, i_rd, o_data, o_empty_n, o_err);
36
        parameter       BW=66, LGFLEN=10, FLEN=(1<<LGFLEN);
37
        input                   i_clk, i_rst;
38
        input                   i_wr;
39
        input   [(BW-1):0]       i_data;
40
        input                   i_rd;
41
        output  reg [(BW-1):0]   o_data;
42
        output  reg             o_empty_n;
43
        output  wire            o_err;
44
 
45
        reg     [(BW-1):0]       fifo[0:(FLEN-1)];
46
        reg     [(LGFLEN-1):0]   r_first, r_last;
47
 
48
        // Write
49
        initial r_first = 0;
50
        always @(posedge i_clk)
51
                if (i_rst)
52
                        r_first <= { (LGFLEN){1'b0} };
53
                else if (i_wr)
54
                begin // Cowardly refuse to overflow
55
                        if (r_first+1 != r_last)
56
                                r_first <= r_first+{{(LGFLEN-1){1'b0}},1'b1};
57
                        // else o_ovfl <= 1'b1;
58
                end
59
        always @(posedge i_clk)
60
                if (i_wr) // Write our new value regardless--on overflow or not
61
                        fifo[r_first] <= i_data;
62
 
63
        initial r_last = 0;
64
        // Reads
65
        //      Following a read, the next sample will be available on the
66
        //      next clock
67
        //      Clock   ReadCMD ReadAddr        Output
68
        //      0        0        0                fifo[0]
69
        //      1       1       0                fifo[0]
70
        //      2       0        1               fifo[1]
71
        //      3       0        1               fifo[1]
72
        //      4       1       1               fifo[1]
73
        //      5       1       2               fifo[2]
74
        //      6       0        3               fifo[3]
75
        //      7       0        3               fifo[3]
76
        always @(posedge i_clk)
77
                if (i_rst)
78
                        r_last <= { (LGFLEN){1'b0} };
79
                else if (i_rd)
80
                begin
81
                        if (r_first != r_last)
82
                                r_last <= r_last+{{(LGFLEN-1){1'b0}},1'b1};
83
                                // Last chases first
84
                                // Need to be prepared for a possible two
85
                                // reads in quick succession
86
                                // o_data <= fifo[r_last+1];
87
                        // else o_unfl <= 1'b1;
88
                end
89
        always @(posedge i_clk)
90
                o_data <= fifo[(i_rd)?(r_last+{{(LGFLEN-1){1'b0}},1'b1})
91
                                        :(r_last)];
92
 
93
        wire    [(LGFLEN-1):0]   nxt_first;
94
        assign  nxt_first = r_first+{{(LGFLEN-1){1'b0}},1'b1};
95
        assign  o_err = ((i_wr)&&(nxt_first == r_last))
96
                                ||((i_rd)&&(r_first == r_last));
97
 
98
        // wire [(LGFLEN-1):0]  fill;
99
        // assign       fill = (r_first-r_last);
100
        wire    [(LGFLEN-1):0]   nxt_last;
101
        assign  nxt_last = r_last+{{(LGFLEN-1){1'b0}},1'b1};
102
        always @(posedge i_clk)
103
                if (i_rst)
104
                        o_empty_n <= 1'b0;
105
                else
106
                        o_empty_n <= (~i_rd)&&(r_first != r_last)
107
                                        ||(i_rd)&&(r_first != nxt_last);
108
endmodule

powered by: WebSVN 2.1.0

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