📄 switchsyncfifo.v
字号:
//// Module SwitchSyncFIFO//// the differences between this FIFO and the general one are listed below// 1. because there is no any write and read acknowledgements, the user should take advantage of the status flags to generate the write and read requests.// 2. after the full flag has been asserted, the word can not be written into the FIFO even if the reacd request is being asserted at the same cycle.//// Created:// by - Xinchun Liu// at - 2006-09-25// History: // 2007-1-31 9:50 change iReset to nReset Revised By Wang Dawei wangdawei@ncic.ac.cn//`resetall`timescale 1ns/10psmodule SwitchSyncFIFO ( nReset, iClk, iWEn, ivDataIn, iREn, ovDataOut, qEmpty, qFull, qvCount);// Default address and data widthparameter pDepthWidth = 5 ; parameter pWordWidth = 16 ; input nReset ;input iClk ;input iWEn ;input [pWordWidth-1:0] ivDataIn ;input iREn ;output [pWordWidth-1:0] ovDataOut ;output qEmpty ;output qFull ;output [pDepthWidth:0] qvCount ;wire nReset ;wire iClk ;wire iWEn ;wire [pWordWidth-1:0] ivDataIn ;wire iREn ;wire [pWordWidth-1:0] ovDataOut_i ;wire qEmpty ;wire qFull ;wire [pDepthWidth:0] qvCount ;wire MemWEn;wire MemREn;wire [pDepthWidth-1:0] vWriteAddr ;wire [pDepthWidth-1:0] vReadAddr ;DualPortRAM #( pDepthWidth, pWordWidth ) Fifo_Storage // Generic synchronous two-port RAM interface ( .clock ( iClk ) , .MemWEn ( MemWEn ) , .qvWAddr ( vWriteAddr ) , .vDataIn ( ivDataIn ) , .qvRAddr ( vReadAddr ) , .vDataOut ( ovDataOut_i ) );reg [pWordWidth-1:0] ovDataOut ;always @ ( posedge iClk ) if ( MemREn ) ovDataOut <= ovDataOut_i ; else ovDataOut <= 0; FifoControl #( pDepthWidth ) Fifo_Ctrl ( .Reset ( nReset ) , .clock ( iClk ) , .iWEn ( iWEn ) , .MemWEn ( MemWEn ) , .MemREn (MemREn), .qvWAddr ( vWriteAddr ) , .iREn ( iREn ) , .qvRAddr ( vReadAddr ) , .qEmpty ( qEmpty ) , .qFull ( qFull ) , .qvCount ( qvCount ) ) ;endmodule module FifoControl( Reset , clock , iWEn , MemWEn , MemREn, qvWAddr , iREn , qvRAddr , qEmpty , qFull , qvCount ) ;parameter pDepthWidth = 5; input Reset ;input clock ;input iWEn ;output MemWEn ;output MemREn ;output [pDepthWidth-1:0] qvWAddr ;input iREn ;output [pDepthWidth-1:0] qvRAddr ;output qEmpty ; output qFull ;output [pDepthWidth:0] qvCount ;wire Reset ;wire clock ;wire iWEn ;wire MemWEn ;reg [pDepthWidth-1:0] qvWAddr ;wire iREn ;reg [pDepthWidth-1:0] qvRAddr ;reg qEmpty ; reg qFull ;reg [pDepthWidth:0] qvCount ;wire MemREn ;// write allow wire - writes are allowed when fifo is not full// read allow wire - reads are allowed when fifo is not emptyassign MemWEn = iWEn && ( ~qFull ) ;assign MemREn = iREn && ( ~qEmpty ) ;// write address modulealways @ ( posedge clock or negedge Reset) begin if( ~Reset ) begin qvWAddr <= 0 ; end else begin if( MemWEn ) qvWAddr <= qvWAddr + 1'b1 ; endend// read address modulealways @ ( posedge clock or negedge Reset) begin if( ~Reset ) begin qvRAddr <= 0 ; end else begin if( MemREn ) qvRAddr <= qvRAddr + 1'b1 ; endend// flags modulealways @ ( posedge clock or negedge Reset) begin if( ~Reset ) begin qFull <= 0 ; qEmpty <= 1 ; qvCount <= 0 ; end else begin if( MemWEn ) begin if( qEmpty ) qEmpty <= 0 ; if ( ~MemREn ) begin qvCount <= qvCount + 1'b1 ; if( qvCount[pDepthWidth-1:0] == { pDepthWidth{1'b1} } ) qFull <= 1 ; end end else begin if( MemREn ) begin qvCount <= qvCount - 1'b1 ; if( qvCount == 1'b1 ) qEmpty <= 1; if( qFull ) qFull <= 0; end end endendendmodule//============================================================================================================= module DualPortRAM ( clock , MemWEn , qvWAddr , vDataIn , qvRAddr , vDataOut );// Default address and data widthparameter pDepthWidth = 5 ; parameter pWordWidth = 16 ; // Generic synchronous two-port RAM interfaceinput clock ; // clockinput MemWEn ; // write enable inputinput [pDepthWidth-1:0] qvWAddr ; // write address businput [pWordWidth-1:0] vDataIn ; // input data businput [pDepthWidth-1:0] qvRAddr ; // read address busoutput [pWordWidth-1:0] vDataOut ; // output data bus// Generic two-port synchronous RAM model// Generic RAM's registers and wiresreg [pWordWidth-1:0] mem[(1<<pDepthWidth)-1:0] /*synthesis syn_ramstyle="no_rw_check"*/; always @ ( posedge clock ) if ( MemWEn ) mem[qvWAddr] <= vDataIn ;assign vDataOut = mem[qvRAddr] ;endmodule ///**********************************************************************// FIFO ///**********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -