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

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [bench/] [MODELSIM/] [fifo.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
`include "mips789_defs.v"
15
 
16
module sim_fifo512_cyclone ( //just uesd for simulation in EDA tools
17
        data,
18
        wrreq,
19
        rdreq,
20
        clock,
21
        q,
22
        full,
23
        empty,
24
        rst);
25
 
26
    input       [7:0]  data;
27
    input         rst;
28
    input     wrreq;
29
    input         rdreq;
30
    input         clock;
31
    output      [7:0]  q;
32
    output        full;
33
    output        empty;
34
 
35
    fifo fifo_ff
36
         (
37
             .clk_i(clock),
38
             .rst_i(rst),
39
             .clear_i(1'b0),
40
             .data_i(data),
41
             .wen_i(wrreq),
42
             .ren_i(rdreq),
43
             .data_o(q),
44
             .almost_full_o(),
45
             .full_o(full),
46
             .almost_empty_o(),
47
             .empty_o(empty),
48
             .cnt_o()
49
         );
50
 
51
endmodule
52
 
53
 
54
//created by zhangfeifei
55
//modifined only for simulating by liwei
56
module fifo
57
    (
58
        clk_i,
59
        rst_i,
60
        clear_i,
61
        data_i,
62
        wen_i,
63
        ren_i,
64
        data_o,
65
        almost_full_o,
66
        full_o,
67
        almost_empty_o,
68
        empty_o,
69
        cnt_o
70
    );
71
 
72
    parameter DATA_WIDTH    = 8;
73
    parameter DEPTH         = 512;
74
    parameter CNT_WIDTH     = 12;
75
 
76
    input  clk_i;
77
    input  rst_i;
78
    input  clear_i;
79
 
80
    input  wen_i;
81
    input  [DATA_WIDTH-1:0] data_i;
82
 
83
    input  ren_i;
84
    output reg[DATA_WIDTH-1:0] data_o;
85
    output almost_full_o;
86
    output full_o;
87
    output almost_empty_o;
88
    output empty_o;
89
    output [CNT_WIDTH-1:0] cnt_o;
90
 
91
    reg    [DATA_WIDTH-1:0] mem[0:DEPTH-1];
92
 
93
    reg    [CNT_WIDTH-1:0] cnt;
94
    reg    [CNT_WIDTH-2:0] read_pointer;
95
    reg    [CNT_WIDTH-2:0] write_pointer;
96
    assign cnt_o = cnt;
97
 
98
    integer i;
99
    initial
100
    begin
101
        for(i=0;i<DEPTH;i=i+1)
102
            mem[i] =0;
103
    end
104
 
105
    always @(posedge clk_i)
106
    begin
107
        if(~rst_i)
108
            cnt <=  0;
109
        else if(clear_i)
110
            cnt <=  {{(CNT_WIDTH-1){1'b0}},ren_i^wen_i};
111
        else if(ren_i ^ wen_i)
112
        begin
113
            if(ren_i & ~empty_o)
114
                cnt <= cnt - 1'b1;
115
            else if( wen_i & ~full_o)
116
                cnt <= cnt + 1'b1;
117
        end
118
    end
119
 
120
    always @(posedge clk_i)
121
    begin
122
        if(~rst_i)
123
            read_pointer <= 0;
124
        else if(clear_i)
125
            read_pointer <= { {(CNT_WIDTH-2){1'b0}}, ren_i};
126
        else if(ren_i & ~empty_o)
127
            read_pointer <= read_pointer + 1'b1;
128
    end
129
 
130
    always @ (posedge clk_i )
131
    begin
132
        if(~rst_i)
133
            write_pointer <= 0;
134
        else if(clear_i)
135
            write_pointer <= { {(CNT_WIDTH-2){1'b0}}, wen_i};
136
        else if(wen_i & ~full_o)
137
            write_pointer <= write_pointer + 1'b1;
138
    end
139
 
140
    assign empty_o = ~(|cnt);
141
    assign almost_empty_o = cnt == 1;
142
    assign full_o  = cnt == DEPTH;
143
    assign almost_full_o  = &cnt[CNT_WIDTH-2:0];
144
 
145
    always @ (posedge clk_i)
146
    begin
147
        if(wen_i & clear_i)
148
            mem[0] <= data_i;
149
        else if(wen_i & ~full_o)
150
            mem[write_pointer] <= data_i;
151
    end
152
 
153
    always @ (posedge clk_i)
154
        data_o <= clear_i ? mem[0] : mem[read_pointer];
155
 
156
endmodule
157
 
158
 

powered by: WebSVN 2.1.0

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