Line 1... |
Line 1... |
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// WISHBONE rev.B2 compliant VGA/LCD Core; Universal Fifo ////
|
//// generic FIFO, uses LFSRs for read/write pointers ////
|
//// ////
|
|
//// ////
|
//// ////
|
//// Author: Richard Herveille ////
|
//// Author: Richard Herveille ////
|
//// richard@asics.ws ////
|
//// richard@asics.ws ////
|
//// www.asics.ws ////
|
//// www.asics.ws ////
|
//// ////
|
//// ////
|
//// Downloaded from: http://www.opencores.org/projects/vga_lcd ////
|
|
//// ////
|
|
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2001 Richard Herveille ////
|
//// Copyright (C) 2001, 2002 Richard Herveille ////
|
//// richard@asics.ws ////
|
//// richard@asics.ws ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
Line 35... |
Line 32... |
//// ////
|
//// ////
|
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
|
|
// CVS Log
|
// CVS Log
|
//
|
//
|
// $Id: vga_fifo.v,v 1.6 2002-02-07 05:42:10 rherveille Exp $
|
// $Id: vga_fifo.v,v 1.7 2003-05-07 09:48:54 rherveille Exp $
|
//
|
//
|
// $Date: 2002-02-07 05:42:10 $
|
// $Date: 2003-05-07 09:48:54 $
|
// $Revision: 1.6 $
|
// $Revision: 1.7 $
|
// $Author: rherveille $
|
// $Author: rherveille $
|
// $Locker: $
|
// $Locker: $
|
// $State: Exp $
|
// $State: Exp $
|
//
|
//
|
// Change History:
|
// Change History:
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.6 2002/02/07 05:42:10 rherveille
|
|
// Fixed some bugs discovered by modified testbench
|
|
// Removed / Changed some strange logic constructions
|
|
// Started work on hardware cursor support (not finished yet)
|
|
// Changed top-level name to vga_enh_top.v
|
|
//
|
|
|
|
//synopsys translate_off
|
`include "timescale.v"
|
`include "timescale.v"
|
|
//synopsys translate_on
|
|
|
|
|
|
// set FIFO_RW_CHECK to prevent writing to a full and reading from an empty FIFO
|
|
//`define FIFO_RW_CHECK
|
|
|
module vga_fifo (clk, aclr, sclr, d, wreq, q, rreq, empty, hfull, full);
|
// Long Pseudo Random Generators can generate (N^2 -1) combinations. This means
|
|
// 1 FIFO entry is unavailable. This might be a problem, especially for small
|
|
// FIFOs. Setting VGA_FIFO_ALL_ENTRIES creates additional logic that ensures that
|
|
// all FIFO entries are used at the expense of some additional logic.
|
|
`define VGA_FIFO_ALL_ENTRIES
|
|
|
|
module vga_fifo (
|
|
clk,
|
|
aclr,
|
|
sclr,
|
|
wreq,
|
|
rreq,
|
|
d,
|
|
q,
|
|
nword,
|
|
empty,
|
|
full,
|
|
aempty,
|
|
afull
|
|
);
|
|
|
//
|
//
|
// parameters
|
// parameters
|
//
|
//
|
|
parameter aw = 3; // no.of entries (in bits; 2^7=128 entries)
|
parameter AWIDTH = 7; // 128 entries
|
parameter dw = 8; // datawidth (in bits)
|
parameter DWIDTH = 32; // 32bits data
|
|
|
|
//
|
//
|
// inputs & outputs
|
// inputs & outputs
|
//
|
//
|
|
input clk; // master clock
|
|
input aclr; // asynchronous active low reset
|
|
input sclr; // synchronous active high reset
|
|
|
input clk; // clock input
|
|
input aclr; // active low asynchronous clear
|
|
input sclr; // active high synchronous clear
|
|
|
|
input [DWIDTH -1:0] d; // data input
|
|
input wreq; // write request
|
input wreq; // write request
|
|
|
output [DWIDTH -1:0] q; // data output
|
|
// reg [DWIDTH -1:0] q;
|
|
input rreq; // read request
|
input rreq; // read request
|
|
input [dw:1] d; // data-input
|
|
output [dw:1] q; // data-output
|
|
|
output empty; // fifo is empty
|
output [aw:1] nword; // number of words in FIFO
|
output hfull; // fifo is half full
|
|
output full; // fifo is full
|
|
|
|
|
|
//
|
output empty; // fifo empty
|
// variable declarations
|
output full; // fifo full
|
//
|
|
parameter DEPTH = 1 << AWIDTH;
|
|
|
|
reg [DWIDTH -1:0] mem [DEPTH -1:0];
|
output aempty; // fifo asynchronous/almost empty (1 entry left)
|
|
output afull; // fifo asynchronous/almost full (1 entry left)
|
|
|
reg [AWIDTH -1:0] rptr, wptr;
|
reg [aw:1] nword;
|
reg [AWIDTH :0] fifo_cnt;
|
reg empty, full;
|
|
|
//
|
//
|
// Module body
|
// Module body
|
//
|
//
|
|
reg [aw:1] rp, wp;
|
|
wire [dw:1] ramq;
|
|
wire fwreq, frreq;
|
|
|
|
`ifdef VGA_FIFO_ALL_ENTRIES
|
|
function lsb;
|
|
input [aw:1] q;
|
|
case (aw)
|
|
2: lsb = ~q[2];
|
|
3: lsb = &q[aw-1:1] ^ ~(q[3] ^ q[2]);
|
|
4: lsb = &q[aw-1:1] ^ ~(q[4] ^ q[3]);
|
|
5: lsb = &q[aw-1:1] ^ ~(q[5] ^ q[3]);
|
|
6: lsb = &q[aw-1:1] ^ ~(q[6] ^ q[5]);
|
|
7: lsb = &q[aw-1:1] ^ ~(q[7] ^ q[6]);
|
|
8: lsb = &q[aw-1:1] ^ ~(q[8] ^ q[6] ^ q[5] ^ q[4]);
|
|
9: lsb = &q[aw-1:1] ^ ~(q[9] ^ q[5]);
|
|
10: lsb = &q[aw-1:1] ^ ~(q[10] ^ q[7]);
|
|
11: lsb = &q[aw-1:1] ^ ~(q[11] ^ q[9]);
|
|
12: lsb = &q[aw-1:1] ^ ~(q[12] ^ q[6] ^ q[4] ^ q[1]);
|
|
13: lsb = &q[aw-1:1] ^ ~(q[13] ^ q[4] ^ q[3] ^ q[1]);
|
|
14: lsb = &q[aw-1:1] ^ ~(q[14] ^ q[5] ^ q[3] ^ q[1]);
|
|
15: lsb = &q[aw-1:1] ^ ~(q[15] ^ q[14]);
|
|
16: lsb = &q[aw-1:1] ^ ~(q[16] ^ q[15] ^ q[13] ^ q[4]);
|
|
endcase
|
|
endfunction
|
|
`else
|
|
function lsb;
|
|
input [aw:1] q;
|
|
case (aw)
|
|
2: lsb = ~q[2];
|
|
3: lsb = ~(q[3] ^ q[2]);
|
|
4: lsb = ~(q[4] ^ q[3]);
|
|
5: lsb = ~(q[5] ^ q[3]);
|
|
6: lsb = ~(q[6] ^ q[5]);
|
|
7: lsb = ~(q[7] ^ q[6]);
|
|
8: lsb = ~(q[8] ^ q[6] ^ q[5] ^ q[4]);
|
|
9: lsb = ~(q[9] ^ q[5]);
|
|
10: lsb = ~(q[10] ^ q[7]);
|
|
11: lsb = ~(q[11] ^ q[9]);
|
|
12: lsb = ~(q[12] ^ q[6] ^ q[4] ^ q[1]);
|
|
13: lsb = ~(q[13] ^ q[4] ^ q[3] ^ q[1]);
|
|
14: lsb = ~(q[14] ^ q[5] ^ q[3] ^ q[1]);
|
|
15: lsb = ~(q[15] ^ q[14]);
|
|
16: lsb = ~(q[16] ^ q[15] ^ q[13] ^ q[4]);
|
|
endcase
|
|
endfunction
|
|
`endif
|
|
|
|
`ifdef RW_CHECK
|
|
assign fwreq = wreq & ~full;
|
|
assign frreq = rreq & ~empty;
|
|
`else
|
|
assign fwreq = wreq;
|
|
assign frreq = rreq;
|
|
`endif
|
|
|
// read pointer
|
//
|
|
// hookup read-pointer
|
|
//
|
always@(posedge clk or negedge aclr)
|
always@(posedge clk or negedge aclr)
|
if (!aclr)
|
if (~aclr) rp <= #1 0;
|
rptr <= #1 0;
|
else if (sclr) rp <= #1 0;
|
else if (sclr)
|
else if (frreq) rp <= #1 {rp[aw-1:1], lsb(rp)};
|
rptr <= #1 0;
|
|
else if (rreq)
|
|
rptr <= #1 rptr + 1;
|
|
|
|
// write pointer
|
//
|
|
// hookup write-pointer
|
|
//
|
always@(posedge clk or negedge aclr)
|
always@(posedge clk or negedge aclr)
|
if (!aclr)
|
if (~aclr) wp <= #1 0;
|
wptr <= #1 0;
|
else if (sclr) wp <= #1 0;
|
else if (sclr)
|
else if (fwreq) wp <= #1 {wp[aw-1:1], lsb(wp)};
|
wptr <= #1 0;
|
|
else if (wreq)
|
|
wptr <= #1 wptr + 1;
|
//
|
|
// hookup memory-block
|
|
//
|
|
reg [dw:1] mem [(1<<aw) -1:0];
|
|
|
// memory array operations
|
// memory array operations
|
always@(posedge clk)
|
always@(posedge clk)
|
if (wreq)
|
if (fwreq)
|
mem[wptr] <= #1 d;
|
mem[wp] <= #1 d;
|
|
|
|
assign q = mem[rp];
|
|
|
|
|
|
// generate full/empty signals
|
|
assign aempty = (rp[aw-1:1] == wp[aw:2]) & (lsb(rp) == wp[1]) & frreq & ~fwreq;
|
|
always @(posedge clk or negedge aclr)
|
|
if (~aclr)
|
|
empty <= #1 1'b1;
|
|
else if (sclr)
|
|
empty <= #1 1'b1;
|
|
else
|
|
empty <= #1 aempty | (empty & (~fwreq + frreq));
|
|
|
assign q = mem[rptr];
|
assign afull = (wp[aw-1:1] == rp[aw:2]) & (lsb(wp) == rp[1]) & fwreq & ~frreq;
|
|
always @(posedge clk or negedge aclr)
|
|
if (~aclr)
|
|
full <= #1 1'b0;
|
|
else if (sclr)
|
|
full <= #1 1'b0;
|
|
else
|
|
full <= #1 afull | ( full & (~frreq + fwreq) );
|
|
|
// number of words in fifo
|
// number of words in fifo
|
always@(posedge clk or negedge aclr)
|
always@(posedge clk or negedge aclr)
|
if (!aclr)
|
if (~aclr)
|
fifo_cnt <= #1 0;
|
nword <= #1 0;
|
else if (sclr)
|
else if (sclr)
|
fifo_cnt <= #1 0;
|
nword <= #1 0;
|
else
|
else
|
begin
|
begin
|
if (wreq & !rreq)
|
if (wreq & !rreq)
|
fifo_cnt <= #1 fifo_cnt + 1;
|
nword <= #1 nword +1;
|
else if (rreq & !wreq)
|
else if (rreq & !wreq)
|
fifo_cnt <= #1 fifo_cnt - 1;
|
nword <= #1 nword -1;
|
end
|
end
|
|
|
// status flags
|
//
|
assign empty = !(|fifo_cnt);
|
// Simulation checks
|
assign hfull = fifo_cnt[AWIDTH -1] | fifo_cnt[AWIDTH];
|
//
|
assign full = fifo_cnt[AWIDTH];
|
// synopsys translate_off
|
|
always @(posedge clk)
|
|
if (full & fwreq)
|
|
$display("Writing while FIFO full\n");
|
|
|
|
always @(posedge clk)
|
|
if (empty & frreq)
|
|
$display("Reading while FIFO empty\n");
|
|
// synopsys translate_on
|
endmodule
|
endmodule
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|
|
|
No newline at end of file
|
No newline at end of file
|