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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_8/] [apps/] [crt/] [rtl/] [verilog/] [ssvga_fifo.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 mihad
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Simple Small VGA IP Core                                    ////
4
////                                                              ////
5
////  This file is part of the Simple Small VGA project           ////
6
////                                                              ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  512 entry FIFO for storing line video data. It uses one     ////
10
////  clock for reading and writing.                              ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   Nothing                                                    ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Damjan Lampret, lampret@opencores.org                 ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48
//
49
 
50
// synopsys translate_off
51
`include "timescale.v"
52
// synopsys translate_on
53
 
54
module ssvga_fifo(
55
        clk, crt_clk, rst, dat_i, wr_en, rd_en,
56
        dat_o, full, empty, ssvga_en
57
);
58
 
59
//
60
// I/O ports
61
//
62
input                   clk;            // Clock
63
input           crt_clk;    // Clock for monitor
64
input                   rst;            // Reset
65
input   [31:0]   dat_i;          // Input data
66
input                   wr_en;          // Write enable
67
input                   rd_en;          // Read enable
68
output  [7:0]    dat_o;          // Output data
69
output                  full;           // Full flag
70
output                  empty;          // Empty flag
71
input           ssvga_en ;  // vga enable
72
 
73
//
74
// Internal wires and regs
75
//
76
reg     [7:0]            wr_ptr;             // Write pointer
77
reg     [7:0]            wr_ptr_plus1;   // Write pointer
78
reg     [9:0]            rd_ptr;             // Read pointer
79
reg     [9:0]            rd_ptr_plus1;   // Read pointer plus1
80
wire                    rd_en_int;          // FIFO internal read enable
81
 
82
wire [9:0]      gray_rd_ptr;      // gray code of read pointer
83
wire [9:0]      gray_wr_ptr;      // gray code of write pointer
84
wire [7:0]      gray_wr_ptr_plus1;// gray code of write + 1 pointer
85
 
86
reg  [9:0]      gray_read_ptr;    // sinchronized gray read pointer on clk clock
87
wire [9:0]      sync_gray_rd_ptr; // intermediate sinc. of gray read pointer
88
 
89
reg             rd_ssvga_en;    // sinchronized ssvga enable on crt_clk clock
90
wire            sync_ssvga_en;  // intermediate sinc. of ssvga enable signal
91
 
92
//
93
// Write pointer + 1
94
//
95
 
96
always @(posedge clk or posedge rst)
97
    if (rst)
98
                wr_ptr_plus1 <= #1 8'b0000_0001 ;
99
    else if (~ssvga_en)
100
        wr_ptr_plus1 <= #1 8'b0000_0001 ;
101
        else if (wr_en)
102
                wr_ptr_plus1 <= #1 wr_ptr_plus1 + 1;
103
 
104
//
105
// Write pointer
106
//
107
always @(posedge clk or posedge rst)
108
        if (rst)
109
                wr_ptr <= #1 8'b0000_0000;
110
    else if (~ssvga_en)
111
        wr_ptr <= #1 8'b0000_0000;
112
        else if (wr_en)
113
                wr_ptr <= #1 wr_ptr_plus1 ;
114
 
115
//
116
// Read pointer
117
//
118
always @(posedge crt_clk or posedge rst)
119
        if (rst)
120
                rd_ptr <= #1 10'b00_0000_0000;
121
    else if (~rd_ssvga_en)
122
        rd_ptr <= #1 10'b00_0000_0000;
123
        else if (rd_en_int)
124
                rd_ptr <= #1 rd_ptr_plus1 ;
125
 
126
always @(posedge crt_clk or posedge rst)
127
        if (rst)
128
                rd_ptr_plus1 <= #1 10'b00_0000_0001;
129
    else if (~rd_ssvga_en)
130
        rd_ptr_plus1 <= #1 10'b00_0000_0001;
131
        else if (rd_en_int)
132
                rd_ptr_plus1 <= #1 rd_ptr_plus1 + 1 ;
133
 
134
//
135
// Empty is asserted when both pointers match
136
//
137
//assign empty = ( rd_ptr == {wr_ptr, 2'b00} ) ;
138
assign empty = ( gray_wr_ptr == gray_read_ptr ) ;
139
 
140
//
141
// Full is asserted when both pointers match
142
// and wr_ptr did increment in previous clock cycle
143
//
144
//assign full = ( wr_ptr_plus1 == rd_ptr[9:2] ) ;
145
assign full = ( gray_wr_ptr_plus1 == gray_read_ptr[9:2] ) ;
146
 
147
wire valid_pix = 1'b1 ;
148
 
149
//
150
// Read enable for FIFO
151
//
152
assign rd_en_int = rd_en & !empty & valid_pix;
153
 
154
wire [8:0] ram_pix_address = rd_en_int ? {rd_ptr_plus1[9:2], rd_ptr_plus1[0]} : {rd_ptr[9:2], rd_ptr[0]} ;
155
 
156
wire [7:0] dat_o_low ;
157
wire [7:0] dat_o_high ;
158
 
159
assign dat_o = rd_ptr[1] ? dat_o_high : dat_o_low ;
160
 
161
//#############################################################################
162
// binary to gray converters for counter of different clock domain comparison
163
assign gray_rd_ptr          = (rd_ptr >> 1)          ^ rd_ptr ;
164
assign gray_wr_ptr          = ({1'b0, wr_ptr, 1'b0}) ^ ({wr_ptr, 2'b00}) ;
165
assign gray_wr_ptr_plus1    = (wr_ptr_plus1 >> 1)    ^ wr_ptr_plus1 ;
166
 
167
//#############################################################################
168
// interemediate stage to clk synchronization flip - flops - this ones are prone to metastability
169
synchronizer_flop   #(10) read_ptr_sync
170
(
171
    .data_in        (gray_rd_ptr),
172
    .clk_out        (clk),
173
    .sync_data_out  (sync_gray_rd_ptr),
174
    .async_reset    (rst)
175
) ;
176
always@(posedge clk or posedge rst)
177
begin
178
    if (rst)
179
        gray_read_ptr <= #1 10'b0 ;
180
    else
181
        gray_read_ptr <= #1 sync_gray_rd_ptr ;
182
end
183
 
184
//##############################################################################
185
// interemediate stage ssvga_en synchronization flip - flop - this one is prone to metastability
186
synchronizer_flop   ssvga_enable_sync
187
(
188
    .data_in        (ssvga_en),
189
    .clk_out        (crt_clk),
190
    .sync_data_out  (sync_ssvga_en),
191
    .async_reset    (rst)
192
) ;
193
// crt side ssvga enable flip flop - gets a value from intermediate stage sync flip flop
194
always@(posedge crt_clk or posedge rst)
195
begin
196
    if (rst)
197
        rd_ssvga_en <= #1 1'b0 ;
198
    else
199
        rd_ssvga_en <= #1 sync_ssvga_en ;
200
end
201
 
202
 
203
RAMB4_S8_S16 ramb4_s8_0(
204
        .CLKA(crt_clk),
205
        .RSTA(rst),
206
        .ADDRA(ram_pix_address),
207
        .DIA(8'h00),
208
        .ENA(1'b1),
209
        .WEA(1'b0),
210
        .DOA(dat_o_low),
211
 
212
        .CLKB(clk),
213
        .RSTB(rst),
214
        .ADDRB(wr_ptr),
215
        .DIB(dat_i[15:0]),
216
        .ENB(1'b1),
217
        .WEB(wr_en),
218
        .DOB()
219
);
220
 
221
RAMB4_S8_S16 ramb4_s8_1(
222
        .CLKA(crt_clk),
223
        .RSTA(rst),
224
        .ADDRA(ram_pix_address),
225
        .DIA(8'h00),
226
        .ENA(1'b1),
227
        .WEA(1'b0),
228
        .DOA(dat_o_high),
229
 
230
        .CLKB(clk),
231
        .RSTB(rst),
232
        .ADDRB(wr_ptr),
233
        .DIB(dat_i[31:16]),
234
        .ENB(1'b1),
235
        .WEB(wr_en),
236
        .DOB()
237
);
238
 
239
endmodule

powered by: WebSVN 2.1.0

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