FIFO的verilog设计测试代码
【CPLD Verilog】CPLD实现同步FIFO

CPLD实现同步FIFO1 实现原理CPLD实现8个字节的同步FIFO,实现8个字节数据的缓存。
CPLD内部模块逻辑框图如下所示。
Data_a_we_pulse写数据到FIFO的使能信号。
Data_a_rd_pulse从FIFO读取数据的使能信号。
Data_a_in和Data_a_out分别表示写入FIFO和从FIFO读出的数据的值。
Data_a_we_full指示FIFO写满的状态。
Data_a_rd_nop指示FIFO读空的状态。
2 CPLD代码module fifo_8B (clk,reset_n,data_a_in,data_a_we_pulse,data_a_we_full,data_a_out,data_a_rd_pulse,data_a_rd_nop);input clk;input reset_n;input [7:0] data_a_in;input data_a_we_pulse;output data_a_we_full;output [7:0] data_a_out;input data_a_rd_pulse;output data_a_rd_nop;//////////////////////////FIFO 写入数据逻辑////////////////////////////reg [7:0] fifo_mem [7:0]; //FIFO空间,8个8bit的空间reg [2:0] fifo_we_addr; //FIFO写地址寄存器reg fifo_we_addr_reverse_pulse; //FIFO写地址翻转状态寄存器,用于指示写//地址是否从最大地址翻转回到最小地址always@(posedge clk or negedge reset_n)beginif(reset_n == 1'b0)beginfifo_we_addr <= 3'h0;fifo_we_addr_reverse_pulse <= 1'b0;endelse if((data_a_we_pulse == 1'b1)&&(fifo_we_addr != 3'h7)&&(data_a_we_full == 1'b0)) beginfifo_mem[fifo_we_addr] <= data_a_in; //对应写地址,写入相应的值fifo_we_addr <= fifo_we_addr+3'h1;endelse if((data_a_we_pulse == 1'b1)&&(fifo_we_addr == 3'h7)&&(data_a_we_full == 1'b0)) beginfifo_mem[fifo_we_addr] <= data_a_in;fifo_we_addr <= fifo_we_addr+3'h1;fifo_we_addr_reverse_pulse <= ~fifo_we_addr_reverse_pulse;endelse;end//////////////////////////FIFO 读出数据逻辑////////////////////////////reg [2:0] fifo_rd_addr; //FIFO读地址寄存器reg fifo_rd_addr_reverse_pulse; //FIFO读地址翻转状态寄存器,用于指示读//地址是否从最大地址翻转回到最小地址reg [7:0] data_a_out;always@(posedge clk or negedge reset_n)beginif(reset_n == 1'b0)beginfifo_rd_addr <= 3'h0;fifo_rd_addr_reverse_pulse <= 1'b0;endelse if((data_a_rd_pulse == 1'b1)&&(fifo_rd_addr != 3'h7)&&(data_a_rd_nop == 1'b0)) begindata_a_out <= fifo_mem[fifo_rd_addr]; //对应读地址,读出相应的值fifo_rd_addr <= fifo_rd_addr+3'h1;endelse if((data_a_rd_pulse == 1'b1)&&(fifo_rd_addr == 3'h7)&&(data_a_rd_nop == 1'b0)) begindata_a_out <= fifo_mem[fifo_rd_addr];fifo_rd_addr <= fifo_rd_addr+3'h1;fifo_rd_addr_reverse_pulse <= ~fifo_rd_addr_reverse_pulse;endelse;end//////////////////////////FIFO 满空逻辑////////////////////////////wire fifo_addr_reverse_flag;assign fifo_addr_reverse_flag = (fifo_we_addr_reverse_pulse^fifo_rd_addr_reverse_pulse == 1'b1) ? 1'b1 : 1'b0;reg data_a_we_full;reg data_a_rd_nop;always@(posedge clk or negedge reset_n)beginif(reset_n == 1'b0)begindata_a_we_full <= 1'b0;data_a_rd_nop <= 1'b1;endelse if((fifo_rd_addr == fifo_we_addr)&&(fifo_addr_reverse_flag ==1'b1))begindata_a_we_full <= 1'b1;data_a_rd_nop <= 1'b0;endelse if((fifo_rd_addr == fifo_we_addr)&&(fifo_addr_reverse_flag ==1'b0))begindata_a_we_full <= 1'b0;data_a_rd_nop <= 1'b1;endelsebegindata_a_we_full <= 1'b0;data_a_rd_nop <= 1'b0;endendendmodule3 仿真结果3.1 正常写入读取FIFO仿真如下红色圆框,红色圆框表示向FIFO写入3个字节数据,红色方框表示从FIFO读取出2个字节数据。
verilogfifo读写详细讲解

verilogfifo读写详细讲解FIFO是一种先进先出的数据结构,其全称为First-In-First-Out。
在Verilog中,可以使用以下代码实现FIFO的读写操作。
首先,我们需要定义FIFO的模块。
如下所示:```verilogmodule fifo #(parameter DATA_WIDTH = 8) (input clk, // 时钟信号input reset, // 复位信号input read, // 读使能信号input write, // 写使能信号input [DATA_WIDTH-1:0] data_in, // 输入数据output reg [DATA_WIDTH-1:0] data_out, // 输出数据output reg empty, // FIFO为空信号output reg full // FIFO为满信号);```在FIFO的模块中,我们定义了以下信号:clk表示时钟信号,reset表示复位信号,read表示读使能信号,write表示写使能信号,data_in表示输入数据,data_out表示输出数据,empty表示FIFO为空信号,full表示FIFO为满信号。
在模块的内部,我们可以使用一个或多个寄存器来实现FIFO的功能。
在这里,我们使用两个寄存器data_reg和next_data_reg来存储数据,使用两个计数器empty_count和full_count来记录FIFO的空和满状态。
```verilogreg [DATA_WIDTH-1:0] data_reg; // 数据寄存器reg [DATA_WIDTH-1:0] next_data_reg; // 下一个数据寄存器reg [DATA_WIDTH-1:0] data_out_reg; // 输出数据寄存器reg empty_count; // 空计数器reg full_count; // 满计数器```接下来,我们定义FIFO的行为。
基于verilog HDL 硬件描语言的FIFO设计

基于verilog HDL 硬件描语言的FIFO设计一、设计描述设计一个宽度为32位,深度为8的FIFO,要求根据读写控制输入输出32位数据,并在输出端以低电平有效给出空态(empyt_n),满态(full_n),几乎空(first_n),几乎满(last_n),以及差2位满(slast_n)的标志信号。
二、RTL schematic三、RTL源代码// -------------------------------------------------------------------------------------------------// File name: fifo_ctrl.v--------xjy// ------------------------------------------------------------------------------------------------//`timescale 1ns/1psmodule fifo_ctrl(clk,rst_n,wrt_strobe_n,rd_strobe_n,// clr_n,rd_ptr,wrt_ptr,full_n,empty_n,last_n,slast_n,first_n);input clk; // FIFO clock domaininput rst_n; // FIFO reset, active lowinput wrt_strobe_n; // fifo write strobe, active lowinput rd_strobe_n; // fifo read strobe, active low//input clr_n; // clear signal, active lowoutput [2:0] rd_ptr; // read pointer to regfileoutput [2:0] wrt_ptr; // write pointer to regfileoutput full_n; // fifo full indicator, active lowoutput empty_n; // fifo empty indicator, active low output last_n; // indicate one space in fifo, active low output slast_n; // indicate two space in fifo, active low output first_n; // indicate only one data in fifo, active low reg [2:0] rd_ptr;reg [2:0] wrt_ptr;wire full_n, empty_n, last_n, slast_n, first_n;reg [3:0] reg_count;///////////////////write pointer////////////////////////always @(posedge clk or negedge rst_n)beginif(!rst_n) wrt_ptr <= 3'b0;else if(wrt_ptr == 3'b111) wrt_ptr <=0;else if((!wrt_strobe_n)&&(full_n)&&(rd_strobe_n))beginwrt_ptr<=(wrt_ptr+1);// wr_mark<=1;endelse beginwrt_ptr<=wrt_ptr;//wr_mark<=0;endend///////////////////read pointer/////////////////////always @(posedge clk or negedge rst_n)beginif(!rst_n) rd_ptr <= 3'b0;else if(rd_ptr == 3'b111) rd_ptr <=0;else if((!rd_strobe_n)&&(empty_n)&&(wrt_strobe_n))beginrd_ptr<= (rd_ptr+1);//rd_mark<=1;endelse beginrd_ptr<=rd_ptr;//rd_mark<=0;endend//////////register counter:from 0(empty) to 8(full)////////always @(posedge clk or negedge rst_n)beginif(!rst_n) reg_count<=0;elsecasez({wrt_strobe_n,rd_strobe_n})2'b01: reg_count <= (full_n) ? (reg_count+1) : reg_count;//write---count+12'b10: reg_count <= (empty_n) ? (reg_count-1) : reg_count;//read---count-1default: reg_count <= reg_count;endcaseend//main blocks--------------------------------------------------assign empty_n=(reg_count==4'b0000)? 0:1;assign full_n=(reg_count==4'b1000)? 0:1;assign last_n=(reg_count==4'b0111)? 0:1;assign slast_n=(reg_count==4'b0110)? 0:1;assign first_n=(reg_count==4'b0001)? 0:1;endmodule// -------------------------------------------------------------------------------------------------// File name : fifo_regfile.v-------xjy// ------------------------------------------------------------------------------------------------//`timescale 1ns/1psmodule fifo_regfile(clk,rst_n,wrt_n,rd_n,rd_addr,wrt_addr,data_in,data_out,full_n,empty_n);input clk; // clk signal.input rst_n; // Low Asserted Reset signal.input rd_n;input wrt_n; // write strobe to fifoinput [2:0] rd_addr; // address for read datainput [2:0] wrt_addr; // address for write datainput [31:0] data_in; // Data into FIFO.input full_n,empty_n; //control read and write/////////////////////// output [31:0] data_out; // FIFO data out.reg [31:0] int_reg_b[7:0];reg [31:0] int_data_out;wire [31:0] data_out = int_data_out[31:0];always @(posedge clk or negedge rst_n)beginif(!rst_n) beginint_reg_b[0] <= 32'h0000;int_reg_b[1] <= 32'h0000;int_reg_b[2] <= 32'h0000;int_reg_b[3] <= 32'h0000;int_reg_b[4] <= 32'h0000;int_reg_b[5] <= 32'h0000;int_reg_b[6] <= 32'h0000;int_reg_b[7] <= 32'h0000; endelse if(!wrt_n)begincasez(wrt_addr[2:0])3'b000: int_reg_b[0] <= (full_n) ? data_in : int_reg_b[0];3'b001: int_reg_b[1] <= (full_n) ? data_in : int_reg_b[1];3'b010: int_reg_b[2] <= (full_n) ? data_in : int_reg_b[2];3'b011: int_reg_b[3] <= (full_n) ? data_in : int_reg_b[3];3'b100: int_reg_b[4] <= (full_n) ? data_in : int_reg_b[4];3'b101: int_reg_b[5] <= (full_n) ? data_in : int_reg_b[5];3'b110: int_reg_b[6] <= (full_n) ? data_in : int_reg_b[6];3'b111: int_reg_b[7] <= (full_n) ? data_in : int_reg_b[7];default: begin //if wrt_addr is x or z.register restainint_reg_b[0] <= int_reg_b[0];int_reg_b[1] <= int_reg_b[1];int_reg_b[2] <= int_reg_b[2];int_reg_b[3] <= int_reg_b[3];int_reg_b[4] <= int_reg_b[4];int_reg_b[5] <= int_reg_b[5];int_reg_b[6] <= int_reg_b[6];int_reg_b[7] <= int_reg_b[7];endendcaseendendalways @(posedge clk or negedge rst_n)beginif(!rst_n)int_data_out<=32'h0000;else if(!rd_n)begincasez(rd_addr[2:0])3'b000: int_data_out <= (empty_n) ? int_reg_b[0] : int_data_out;3'b001: int_data_out <= (empty_n) ? int_reg_b[1] : int_data_out;3'b010: int_data_out <= (empty_n) ? int_reg_b[2] : int_data_out;3'b011: int_data_out <= (empty_n) ? int_reg_b[3] : int_data_out;3'b100: int_data_out <= (empty_n) ? int_reg_b[4] : int_data_out;3'b101: int_data_out <= (empty_n) ? int_reg_b[5] : int_data_out;3'b110: int_data_out <= (empty_n) ? int_reg_b[6] : int_data_out;3'b111: int_data_out <= (empty_n) ? int_reg_b[7] : int_data_out;default: int_data_out <= int_data_out;endcaseendendendmodule// -------------------------------------------------------------------------------------------------------------- // File name: top_fifo.v----------xjy// ---------------------------------------------------------------------------------------------------------------- //`include "fifo_ctrl.v"//`include "fifo_regfile.v"`timescale 1ns/1psmodule top_fifo(clk,rst_n,fifo_data_in,fifo_in_n,fifo_out_n,fifo_data_out,fifo_full_n,fifo_last_n,fifo_slast_n,fifo_first_n,fifo_empty_n);input clk; // clk signal.input rst_n; // Low Asserted Reset signal.input [31:0] fifo_data_in; // Data into FIFO.input fifo_in_n; // Write into FIFO Signal.//input fifo_clr_n; // Clear signal to FIFO.input fifo_out_n; // Read from FIFO signal.output [31:0] fifo_data_out; // FIFO data out.output fifo_full_n; // FIFO full indicating signal.output fifo_empty_n; // FIFO empty indicating signal.output fifo_last_n; // FIFO Last but one signal.output fifo_slast_n; // FIFO SLast but one signal.output fifo_first_n; // Signal indicating only one// word in FIFO.wire [2:0] rd_ptr;wire [2:0] wrt_ptr;wire full_n,empty_n;assign fifo_full_n = full_n;assign fifo_empty_n = empty_n;fifo_regfile u_fifo_regfile(.clk (clk ),.rst_n (rst_n ),.wrt_n (fifo_in_n ),.rd_n (fifo_out_n ),.rd_addr (rd_ptr[2:0] ),.wrt_addr (wrt_ptr[2:0] ),.data_in (fifo_data_in[31:0] ),.data_out (fifo_data_out[31:0] ),.full_n (full_n),.empty_n (empty_n));fifo_ctrl u_fifo_ctrl(.clk (clk ),.rst_n (rst_n ),.wrt_strobe_n (fifo_in_n ),.rd_strobe_n (fifo_out_n ),.rd_ptr (rd_ptr[2:0] ),.wrt_ptr (wrt_ptr[2:0] ),.full_n (full_n ),.empty_n (empty_n ),.last_n (fifo_last_n ),.slast_n (fifo_slast_n ),.first_n (fifo_first_n ));Endmodule附:部分测试文件initialbeginclk=1; rst_n=0; fifo_in_n=1; fifo_out_n=1;#10 rst_n=1; //reset////////formal test////////////#20 fifo_in_n=0; //write enable:in 8 datas#80 fifo_in_n=1; fifo_out_n=0;// read:2 datas#20 fifo_out_n=1; fifo_in_n=0;//write 2#20 fifo_in_n=1; fifo_out_n=0;//read 8 (all)#80 fifo_out_n=1;//---empty///////full---write,empty----read,test#50 fifo_in_n=0; fifo_out_n=1;// write:10 datas only 8 effective #100 fifo_in_n=1; fifo_out_n=0;// read:6 datas#60 fifo_in_n=0; fifo_out_n=1;// write:2 datas#20 fifo_in_n=1; fifo_out_n=0;// read:10 datas only 8 effective #100 fifo_in_n=1; fifo_out_n=1;//#10 $stop;四、综合报告//////////////////////////////////////////SYNTHESIZE REPORT///////////////////////////////////////////////////////////////////// Release 10.1 - xst K.31 (nt)Copyright (c) 1995-2008 Xilinx, Inc. All rights reserved.--> Parameter TMPDIR set to D:/Post-Graduate/CourseWare_10/verilog/FIFO_xjy/xst/projnav.tmpTotal REAL time to Xst completion: 0.00 secsTotal CPU time to Xst completion: 0.16 secs--> Parameter xsthdpdir set to D:/Post-Graduate/CourseWare_10/verilog/FIFO_xjy/xstTotal REAL time to Xst completion: 0.00 secsTotal CPU time to Xst completion: 0.16 secs--> Reading design: top_fifo.prjTABLE OF CONTENTS1) Synthesis Options Summary2) HDL Compilation3) Design Hierarchy Analysis4) HDL Analysis5) HDL Synthesis5.1) HDL Synthesis Report6) Advanced HDL Synthesis6.1) Advanced HDL Synthesis Report7) Low Level Synthesis8) Partition Report9) Final Report9.1) Device utilization summary9.2) Partition Resource Summary9.3) TIMING REPORT=======================================================================* Synthesis Options Summary *=======================================================================---- Source ParametersInput File Name : "top_fifo.prj"Input Format : mixedIgnore Synthesis Constraint File : NO---- Target ParametersOutput File Name : "top_fifo"Output Format : NGCTarget Device : xc3s1500-4-fg456---- Source OptionsTop Module Name : top_fifoAutomatic FSM Extraction : YESFSM Encoding Algorithm : AutoSafe Implementation : NoFSM Style : lutRAM Extraction : YesRAM Style : Auto ROM Extraction : YesMux Style : Auto Decoder Extraction : YES Priority Encoder Extraction : YESShift Register Extraction : YESLogical Shifter Extraction : YESXOR Collapsing : YES ROM Style : Auto Mux Extraction : YES Resource Sharing : YES Asynchronous To Synchronous : NO Multiplier Style : auto Automatic Register Balancing : No---- Target OptionsAdd IO Buffers : YES Global Maximum Fanout : 500Add Generic Clock Buffer(BUFG) : 8Register Duplication : YESSlice Packing : YES Optimize Instantiated Primitives : NOUse Clock Enable : YesUse Synchronous Set : YesUse Synchronous Reset : YesPack IO Registers into IOBs : auto Equivalent register Removal : YES---- General OptionsOptimization Goal : Speed Optimization Effort : 1Library Search Order : top_fifo.lso Keep Hierarchy : NO Netlist Hierarchy : as_optimized RTL Output : Yes Global Optimization : AllClockNets Read Cores : YES Write Timing Constraints : NOCross Clock Analysis : NO Hierarchy Separator : /Bus Delimiter : <>Case Specifier : maintainSlice Utilization Ratio : 100BRAM Utilization Ratio : 100Verilog 2001 : YESAuto BRAM Packing : NOSlice Utilization Ratio Delta : 5=======================================================================* HDL Compilation *=======================================================================Compiling verilog file "fifo_regfile.v" in library workCompiling verilog file "fifo_ctrl.v" in library workModule <fifo_regfile> compiledCompiling verilog file "top_fifo.v" in library workModule <fifo_ctrl> compiledModule <top_fifo> compiledNo errors in compilationAnalysis of file <"top_fifo.prj"> succeeded.=======================================================================* Design Hierarchy Analysis *=======================================================================Analyzing hierarchy for module <top_fifo> in library <work>.Analyzing hierarchy for module <fifo_regfile> in library <work>.Analyzing hierarchy for module <fifo_ctrl> in library <work>.=======================================================================*HDL Analysis *=======================================================================Analyzing top module <top_fifo>.Module <top_fifo> is correct for synthesis.Analyzing module <fifo_regfile> in library <work>.Module <fifo_regfile> is correct for synthesis.Analyzing module <fifo_ctrl> in library <work>.Module <fifo_ctrl> is correct for synthesis.=======================================================================* HDL Synthesis *======================================================================= Performing bidirectional port resolution...Synthesizing Unit <fifo_regfile>.Related source file is "fifo_regfile.v".Found 32-bit register for signal <int_data_out>.Synthesize & Map ReportFound 32-bit 8-to-1 multiplexer for signal <int_data_out$mux0000> created at line 91.Found 256-bit register for signal <int_reg_b>.INFO:Xst:738 - HDL ADVISOR - 256 flip-flops were inferred for signal <int_reg_b>. You may be trying to describe a RAM in a way that is incompatible with block and distributed RAM resources available on Xilinx devices, or with a specific template that is not supported. Please review the Xilinx resources documentation and the XST user manual for coding guidelines. Taking advantage of RAM resources will lead to improved device usage and reduced synthesis time.Summary:inferred 288 D-type flip-flop(s).inferred 32 Multiplexer(s).Unit <fifo_regfile> synthesized.Synthesizing Unit <fifo_ctrl>.Related source file is "fifo_ctrl.v".Found 3-bit up counter for signal <rd_ptr>.Found 3-bit up counter for signal <wrt_ptr>.Found 4-bit register for signal <reg_count>.Found 4-bit 4-to-1 multiplexer for signal <reg_count$mux0000> created at line 79.Found 4-bit addsub for signal <reg_count$share0000> created at line 79.Summary:inferred 2 Counter(s).inferred 4 D-type flip-flop(s).inferred 1 Adder/Subtractor(s).inferred 4 Multiplexer(s).Unit <fifo_ctrl> synthesized.Synthesizing Unit <top_fifo>.Related source file is "top_fifo.v".Unit <top_fifo> synthesized.INFO:Xst:1767 - HDL ADVISOR - Resource sharing has identified that some arithmetic operations in this design can share the same physical resources for reduced device utilization. For improved clock frequency you may try to disable resource sharing.=======================================================================HDL Synthesis ReportMacro Statistics# Adders/Subtractors : 14-bit addsub : 1# Counters : 23-bit up counter : 2# Registers : 1032-bit register : 94-bit register : 1# Multiplexers : 232-bit 8-to-1 multiplexer : 111Synthesize & Map Report4-bit 4-to-1 multiplexer : 1=======================================================================* Advanced HDL Synthesis *=======================================================================Loading device for application Rf_Device from file '3s1500.nph' in environment E:\ProgramFiles\Xilinx\10.1\ISE.=======================================================================Advanced HDL Synthesis ReportMacro Statistics# Adders/Subtractors : 14-bit addsub : 1# Counters : 23-bit up counter : 2# Registers : 292Flip-Flops : 292# Multiplexers : 232-bit 8-to-1 multiplexer : 14-bit 4-to-1 multiplexer : 1=======================================================================* Low Level Synthesis *=======================================================================Optimizing unit <top_fifo> ...Optimizing unit <fifo_regfile> ...Optimizing unit <fifo_ctrl> ...Mapping all equations...Building and optimizing final netlist ...Found area constraint ratio of 100 (+ 5) on block top_fifo, actual ratio is 1.FlipFlop u_fifo_ctrl/rd_ptr_0 has been replicated 1 time(s)Final Macro Processing ...=======================================================================Final Register ReportMacro Statistics# Registers : 299Flip-Flops : 299=======================================================================* Partition Report *=======================================================================Partition Implementation Status-------------------------------12Synthesize & Map ReportNo Partitions were found in this design.------------------------------=======================================================================* Final Report *=======================================================================Final ResultsRTL Top Level Output File Name : top_fifo.ngrTop Level Output File Name : top_fifoOutput Format : NGCOptimization Goal : SpeedKeep Hierarchy : NODesign Statistics# IOs : 73Cell Usage :# BELS : 392# INV : 4# LUT2 : 2# LUT2_D : 2# LUT3 : 258# LUT3_L : 3# LUT4 : 24# LUT4_L : 3# MUXF5 : 64# MUXF6 : 32# FlipFlops/Latches : 299# FDC : 4# FDCE : 295# Clock Buffers : 1# BUFGP : 1# IO Buffers : 72# IBUF : 35# OBUF : 37=======================================================================Device utilization summary:---------------------------Selected Device : 3s1500fg456-4Number of Slices: 226 out of 13312 1%Number of Slice Flip Flops: 299 out of 26624 1%Number of 4 input LUTs: 296 out of 26624 1%Number of IOs: 73Number of bonded IOBs: 73 out of 333 21%Number of GCLKs: 1 out of 8 12%13Synthesize & Map Report---------------------------Partition Resource Summary:---------------------------No Partitions were found in this design.---------------------------=======================================================================TIMING REPORTNOTE: THESE TIMING NUMBERS ARE ONLY A SYNTHESIS ESTIMATE.FOR ACCURATE TIMING INFORMATION PLEASE REFER TO THE TRACE REPORTGENERATED AFTER PLACE-and-ROUTE.Clock Information:-----------------------------------------------------+------------------------+-------+Clock Signal | Clock buffer(FF name) | Load |-----------------------------------+------------------------+-------+clk | BUFGP | 299 |-----------------------------------+------------------------+-------+Asynchronous Control Signals Information:------------------------------------------------------------------------------------------------+------------------------------------+-------+Control Signal | Buffer(FF name) | Load |--------------------------------------------------------+------------------------------------+-------+u_fifo_ctrl/rst_n_inv(u_fifo_regfile/rst_n_inv1_INV_0:O)| NONE(u_fifo_regfile/int_reg_b_0_11)| 299 | --------------------------------------------------------+------------------------------------+-------+Timing Summary:---------------Speed Grade: -4Minimum period: 6.910ns (Maximum Frequency: 144.716MHz)Minimum input arrival time before clock: 6.810nsMaximum output required time after clock: 10.797nsMaximum combinational path delay: No path foundTiming Detail:--------------All values displayed in nanoseconds (ns)=======================================================================Timing constraint: Default period analysis for Clock 'clk'Clock period: 6.910ns (frequency: 144.716MHz)Total number of paths / destination ports: 2997 / 306-------------------------------------------------------------------------Delay: 6.910ns (Levels of Logic = 2)14Synthesize & Map ReportSource: u_fifo_ctrl/reg_count_3 (FF)Destination: u_fifo_regfile/int_reg_b_6_31 (FF)Source Clock: clk risingDestination Clock: clk risingData Path: u_fifo_ctrl/reg_count_3 to u_fifo_regfile/int_reg_b_6_31Gate NetCell:in->out fanout Delay Delay Logical Name (Net Name)---------------------------------------- ------------FDC:C->Q 10 0.720 1.473 u_fifo_ctrl/reg_count_3 (u_fifo_ctrl/reg_count_3) LUT4:I0->O 10 0.551 1.160 u_fifo_ctrl/full_n1 (fifo_full_n_OBUF)LUT4:I3->O 32 0.551 1.853 u_fifo_regfile/int_reg_b_7_not00011 (u_fifo_regfile/int_reg_b_7_not0001)FDCE:CE 0.602 u_fifo_regfile/int_reg_b_7_0----------------------------------------Total 6.910ns (2.424ns logic, 4.486ns route)(35.1% logic, 64.9% route)=======================================================================Timing constraint: Default OFFSET IN BEFORE for Clock 'clk'Total number of paths / destination ports: 574 / 555-------------------------------------------------------------------------Offset: 6.810ns (Levels of Logic = 3)Source: fifo_in_n (PAD)Destination: u_fifo_regfile/int_reg_b_6_31 (FF)Destination Clock: clk risingData Path: fifo_in_n to u_fifo_regfile/int_reg_b_6_31Gate NetCell:in->out fanout Delay Delay Logical Name (Net Name)---------------------------------------- ------------IBUF:I->O 12 0.821 1.457 fifo_in_n_IBUF (fifo_in_n_IBUF)LUT2_D:I0->O 3 0.551 0.975 u_fifo_regfile/int_reg_b_0_not000111_SW0 (N276) LUT4:I2->O 32 0.551 1.853 u_fifo_regfile/int_reg_b_7_not00011 (u_fifo_regfile/int_reg_b_7_not0001)FDCE:CE 0.602 u_fifo_regfile/int_reg_b_7_0----------------------------------------Total 6.810ns (2.525ns logic, 4.285ns route)(37.1% logic, 62.9% route)=======================================================================Timing constraint: Default OFFSET OUT AFTER for Clock 'clk'Total number of paths / destination ports: 52 / 37-------------------------------------------------------------------------Offset: 10.797ns (Levels of Logic = 2)Source: u_fifo_ctrl/reg_count_3 (FF)Destination: fifo_empty_n (PAD)Source Clock: clk rising15Synthesize & Map ReportData Path: u_fifo_ctrl/reg_count_3 to fifo_empty_nGate NetCell:in->out fanout Delay Delay Logical Name (Net Name)---------------------------------------- ------------FDC:C->Q 10 0.720 1.473 u_fifo_ctrl/reg_count_3 (u_fifo_ctrl/reg_count_3) LUT4:I0->O 129 0.551 2.409 u_fifo_ctrl/empty_n1 (fifo_empty_n_OBUF)OBUF:I->O 5.644 fifo_empty_n_OBUF (fifo_empty_n)----------------------------------------Total 10.797ns (6.915ns logic, 3.882ns route)(64.0% logic, 36.0% route)=======================================================================Total REAL time to Xst completion: 16.00 secsTotal CPU time to Xst completion: 15.84 secs-->Total memory usage is 170712 kilobytesNumber of errors : 0 ( 0 filtered)Number of warnings : 0 ( 0 filtered)Number of infos : 2 ( 0 filtered)16Synthesize & Map Report///////////////////////////////////////////////////////MAP REPORT///////////////////////////////////////////////////////////////////////////// Release 10.1 Map K.31 (nt)Xilinx Mapping Report File for Design 'top_fifo'Design Information------------------Command Line : map -iseD:/Post-Graduate/CourseWare_10/verilog/FIFO_xjy/FIFO_xjy.ise -intstyle ise -pxc3s1500-fg456-4 -cm area -pr off -k 4 -c 100 -o top_fifo_map.ncd top_fifo.ngdtop_fifo.pcfTarget Device : xc3s1500Target Package : fg456Target Speed : -4Mapper Version : spartan3 -- $Revision: 1.46 $Mapped Date : Thu Oct 21 14:03:23 2010Design Summary--------------Number of errors: 0Number of warnings: 0Logic Utilization:Number of Slice Flip Flops: 299 out of 26,624 1%Number of 4 input LUTs: 292 out of 26,624 1%Logic Distribution:Number of occupied Slices: 341 out of 13,312 2%Number of Slices containing only related logic: 341 out of 341 100%Number of Slices containing unrelated logic: 0 out of 341 0%*See NOTES below for an explanation of the effects of unrelated logic.Total Number of 4 input LUTs: 292 out of 26,624 1%Number of bonded IOBs: 73 out of 333 21%Number of BUFGMUXs: 1 out of 8 12%Peak Memory Usage: 158 MBTotal REAL time to MAP completion: 6 secsTotal CPU time to MAP completion: 3 secsNOTES:Related logic is defined as being logic that shares connectivity - e.g. twoLUTs are "related" if they share common inputs. When assembling slices,Map gives priority to combine logic that is related. Doing so results inthe best timing performance.Unrelated logic shares no connectivity. Map will only begin packingunrelated logic into a slice once 99% of the slices are occupied throughrelated logic packing.17Synthesize & Map Report Note that once logic distribution reaches the 99% level through relatedlogic packing, this does not mean the device is completely utilized.Unrelated logic packing will then begin, continuing until all usable LUTsand FFs are occupied. Depending on your timing budget, increased levels of unrelated logic packing may adversely affect the overall timing performance of your design.Table of Contents-----------------Section 1 - ErrorsSection 2 - WarningsSection 3 - InformationalSection 4 - Removed Logic SummarySection 5 - Removed LogicSection 6 - IOB PropertiesSection 7 - RPMsSection 8 - Guide ReportSection 9 - Area Group and Partition SummarySection 10 - Modular Design SummarySection 11 - Timing ReportSection 12 - Configuration String InformationSection 13 - Control Set InformationSection 14 - Utilization by HierarchySection 1 - Errors------------------Section 2 - Warnings--------------------Section 3 - Informational-------------------------INFO:MapLib:562 - No environment variables are currently set.INFO:LIT:244 - All of the single ended outputs in this design are using slew rate limited output drivers. The delay on speed critical single ended outputs can be dramatically reduced by designating them as fast outputs.Section 4 - Removed Logic Summary---------------------------------Section 5 - Removed Logic-------------------------To enable printing of redundant blocks removed and signals merged, set the detailed map report option and rerun map.18Synthesize & Map ReportSection 6 - IOB Properties+----------------------------------------------------------------------------------------------------------------------------+| IOB Name | Type | Direction | IO Standard | Drive | Slew | Reg (s) | Resistor | IOB || | | | | Strength | Rate | | | Delay |+----------------------------------------------------------------------------------------------------------------------------+| clk | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<0> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<1> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<2> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<3> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<4> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<5> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<6> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<7> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<8> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<9> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<10> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<11> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<12> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<13> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<14> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<15> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<16> | IOB | INPUT | LVCMOS25 | | | | | || fifo_data_in<17> | IOB | INPUT | LVCMOS25 | | | | | |19。
使用verilog_hdl实现8位宽,256位的深的同步fifo的实验原理

使用verilog hdl实现8位宽,256位的深的同步fifo的实验原理1. 引言1.1 概述本文旨在介绍如何使用Verilog HDL实现一个具有8位宽和256位深度的同步FIFO(First In, First Out)电路。
FIFO是一种常用的数据缓存结构,被广泛应用于数字系统中,具有先进先出的特性,能够实现数据的有序存储和检索。
文章将从FIFO的简介开始讲解,然后深入探讨同步FIFO设计时需要考虑的要点,并通过使用Verilog HDL进行设计和实现过程,最后对实验结果进行仿真验证、波形分析以及功能测试与性能评估。
1.2 文章结构本文总共包括五个部分。
首先是引言部分,概述了本文的目标和内容。
接下来是实验原理部分,从FIFO基本概念入手,详细介绍了同步FIFO设计时需要注意的要点以及Verilog HDL语言的简介。
然后是设计与实现部分,给出了8位宽、256位深度同步FIFO电路的设计思路,并逐步引导读者完成Verilog HDL代码的编写。
紧接着是实验结果与分析部分,通过仿真验证、波形分析以及功能测试与性能评估来验证所设计的同步FIFO电路是否符合预期。
最后是结论与展望部分,对实验结果进行总结,并探讨未来可能的改进方向和应用领域。
1.3 目的本文的主要目的是介绍使用Verilog HDL实现8位宽、256位深度同步FIFO电路的原理和方法。
读者可以通过本文了解到FIFO的基本原理和设计要点,以及如何使用Verilog HDL进行FIFO电路的实现。
通过本文,希望读者能够掌握基本的数字电路设计技巧和Verilog HDL编程能力,并在实践中提高对于同步FIFO电路设计的理解和应用能力。
同时,读者还可以通过仿真验证和功能测试等手段深入理解所实现的同步FIFO电路的性能特点,并为相关领域的研究与应用提供参考依据。
2. 实验原理:2.1 FIFO简介FIFO(First-In-First-Out)是一种常见的数据缓冲区结构,它的基本原则是按照先进先出的顺序处理输入和输出数据。
怎么用Verilog语言描述同步FIFO和异步FIFO

怎么⽤Verilog语⾔描述同步FIFO和异步FIFO感谢知乎龚⼤佬打杂⼤佬⽹上⼏个nice的博客(忘了是哪个了。
)前⾔虽然FIFO都有IP可以使⽤,但理解原理还是⾃⼰写⼀个来得透彻。
什么是FIFO?Fist in first out。
先⼊先出的数据缓存器,没有外部读写地址线,可同时读写。
规则:永远不要写⼀个已经写满了的fifo。
永远不要读⼀个读空了的fifo。
FIFO种类?同步FIFO和异步FIFO。
同步FIFO只有⼀个时钟,也就是说写端和读端的时钟是⼀⽑⼀样的。
异步FIFO读端和写端两个时钟则是不⼀样的。
包括同频异相,异频异相。
FIFO⽤途?1. 数据缓冲器。
⽐如你写端burst⼀个数据,没有fifo缓冲的话就炸了。
Fifo会把写端的突发数据吃到肚⼦⾥,读端可以慢慢的⼀个个读出来。
2. 跨时钟域。
异步fifo主要使⽤在不同时钟域的边缘,⽤来同步数据到另⼀个时钟域。
3.ALTERA FIFO IP 的缺点是什么?虽然altera贴⼼的提供了FIFO的IP块,但是对于可移植性与⾃定义位宽深度更好的话,还是⾃⼰写的更佳。
FIFO深度如何计算?(避免溢出)对于异步fifo,如果读时钟⼤于写时钟且每个周期读写,那么⼀定是会读空的,反之⼀定会被写满。
⼀般来说,不会设计这么⽆聊的东西。
假设写端有突发的数据,⽽读端是均匀的读出,怎么保证fifo不溢出呢?异步FIFO快转慢的问题:可能采样踩不到某些值。
同步FIFO:当缓冲器使⽤,可以⽤ram资源搭。
原理图:信号定义:clk:时钟信号rst_n:异步复位信号wr:写请求rd:读请求data:数据输⼊q:数据输出full:满信号,表⽰fifo吃饱了empty:空信号,表⽰fifo肚⼦已经空掉了usedw:表⽰fifo中已有的数据个数仿真:没有usedw款:有usedw款:资源使⽤量:如何设计⼀个异步FIFO?⼀般⽤作跨时钟域,可⽤ram搭。
判断读空与写满,读写指针要跨时钟域,所以采⽤格雷码减少亚稳态。
同步FIFO的Verilog代码

ÍFIFOµÄVerilog?úÂëmodule fifo_syn(datain,rd,wr,rst,clk,dataout,full,empty);input [7:0] datain;input rd, wr, rst, clk;output [7:0] dataout;output full, empty;reg [7:0] dataout;reg full_in, empty_in;reg [7:0] mem [15:0];reg [3:0] rp, wp;assign full = full_in;assign empty = empty_in;// memory read out ÉÔ×?ÐÞ?Äalways@(posedge clk) beginif(rd && ~empty_in) dataout = mem[rp];end// memory write inalways@(posedge clk) beginif(wr && ~full_in) mem[wp]<=datain;end// memory write pointer incrementalways@(posedge clk or negedge rst)if(!rst)wp<=0;else wp <= (wr && ~full_in) ? (wp + 1'b1) : wp;// memory read pointer incrementalways@(posedge clk or negedge rst)if(!rst)rp <= 0;else rp <= (rd && ~empty_in)? (rp + 1'b1): rp;// Full signal generatealways@(posedge clk or negedge rst) beginif(!rst) full_in <= 1'b0;else beginif( (~rd && wr)&&((wp==rp-1) | | (rp==4'h0&&wp==4'hf))) full_in <= 1'b1;else if(full_in && rd) full_in <= 1'b0;endend// Empty signal generatealways@(posedge clk or negedge rst) beginif(!rst) empty_in <= 1'b1;else beginif((rd&&~wr)&&(rp==wp-1 || (rp==4'hf&&wp==4'h0)))empty_in<=1'b1;else if(empty_in && wr) empty_in<=1'b0;endendendmodule******************************************************************** ***********ÍøÉϵÄ?úÂë?ÁÊý?ÝÊä?ö(dataout)Ö??ÊÜ?ÁÊ?ÄÜ(rd)?ØÖÆ??ÏÔÈ?Ô??ËùÒÔÉ Ô×?ÐÞ?ÄÓ,ÅúÆÀ******************************************************************** ******************ÁíÒ?ÖÖ?ç?ñµÄÍFIFOmodule FIFO_Buffer(Data_out,stack_full,stack_almost_full,stack_half_full,stack_almost_empty,stack_empty,Data_in,write_to_stack,read_from_stack,clk,rst);parameter stack_width=32;parameter stack_height=8;parameter stack_ptr_width=3;parameter AE_level=2;parameter AF_level=6;parameter HF_level=4;output [stack_width-1:0] Data_out;output stack_full,stack_almost_full,stack_half_full; output stack_almost_empty,stack_empty;input[stack_width-1:0] Data_in;input write_to_stack,read_from_stack;input clk,rst;reg[stack_ptr_width-1:0] read_ptr,write_ptr;reg[stack_ptr_width:0] ptr_gap;reg[stack_width-1:0] Data_out;reg[stack_width-1:0] stack[stack_height-1:0]; assign stack_full=(ptr_gap==stack_height);assign stack_almost_full=(ptr_gap==AF_level);assign stack_half_full=(ptr_gap==HF_level);assign stack_almost_empty=(ptr_gap==AE_level);assign stack_empty=(ptr_gap==0);always @(posedge clk or posedge rst)if(rst)beginData_out<=0;read_ptr<=0;write_ptr<=0;ptr_gap<=0;endelse if(write_to_stack &&(!stack_full)&&(!read_from_stack))begin stack[write_ptr]<=Data_in;write_ptr<=write_ptr+1;ptr_gap<=ptr_gap+1;endelse if((!write_to_stack)&&(!stack_empty)&&read_from_stack)begin Data_out<=stack[read_ptr];read_ptr<=read_ptr+1;ptr_gap<=ptr_gap-1;endelse if(write_to_stack &&read_from_stack&&stack_empty)begin stack[write_ptr]<=Data_in;write_ptr<=write_ptr+1;ptr_gap<=ptr_gap+1;endelse if(write_to_stack &&read_from_stack&&stack_full)beginData_out<=stack[read_ptr];read_ptr<=read_ptr+1;ptr_gap<=ptr_gap-1;endelseif(write_to_stack&&read_from_stack&&(!stack_full)&&(!stack_empty)) beginData_out<=stack[read_ptr];stack[write_ptr]<=Data_in;read_ptr<=read_ptr+1;write_ptr<=write_ptr+1;endendmoduleÏÔÈ?Õâ?ö?È?ÏÈÝÒ×Àí?â。
使用VerilogHDL实现异步FIFO分析报告与实现FIFO读写时序

使用实现异步设计与实现读写时序在现代设计中,特别是在模块与外围芯片的通信设计中,多时钟域的情况不可避免。
当数据从一个时钟域传递到另一个域,并且目标时钟域与源时钟域不相关时,这些域中的动作是不相关的,从而消除了同步操作的可能性,并使系统重复地进入亚稳定状态[]。
在有大量的数据需要进稳定的最小时间;而保持时间( )是在时钟上升沿到来之后,触发器数据还应该保持的最小时间[]。
如图所示,在时钟上升沿前后的这个窗口内数据应该保持不变,否则会使触发器工作在一个不确定的状态,即亚稳态。
当触发器处于亚稳态,且处于亚稳态的时间超过了一个时钟周期时,这种不确定的状态将会影响到下一级的触发器,最终导致连锁反应,从而使整个系统功能失常。
当一个信号跨越某个时钟域时,对新时钟域的电路来说它就是一个异步信号。
由于异步信号之间的时序是毫无关系的,因此必然存在冲突。
为了避免亚稳态问题,采用如图所示的双锁存器法[],即在一个信号进入另一个时钟域前,将该信号用两个锁存器消除亚稳态只是保证了信号电平的稳定,要在不同时钟域中准确传输数据还需要一个接口电路。
异步就是一种不同时钟域之间传递多位数据的常用方法。
异步设计异步是一种先进先出电路,用在需要实时数据接口的部分,用来存储、缓冲在两个异步时钟之间的数据传输。
主要由双口存储器、读地址产生逻辑、写地址产生逻辑、空满标志产生逻辑四部分构成。
图是一种都要变化,读指针的每一位在读时钟的作用下,跳变不一致,即产生毛刺。
如果写时钟恰好在读指针的变化时刻采样,得到的采样信号可能是~中的任何一个,从而导致空满信号判断错误。
由实践可知,同步多个异步输入信号出现亚稳态的概率远远大于同步一个异步信号的概率[]。
解决这一问题的有效方法是采用格雷码。
格雷码的主要特点是相邻的两个编码之间只有一位变化。
图是格雷码产生的逻辑框图。
在读使能或写使能信号有效、并且空满标志无效的情况下,读写指针开始累加,进行读或写操作。
二进制码与格雷码的转换是一个“异或”运算:(>>)^。
同步FIFO设计(verilog)

module syn_fifo(clk,reset,wr,rd,din,dout,full,empty);input clk,reset,wr,rd;input[7:0] din;output[7:0] dout;output full,empty;wire[7:0] din;wire[7:0] doubt;wire full,empty;reg[2:0] wp,rp;reg w_full,r_empty;reg[7:0] fifo[7:0];assign full=w_full;assign empty=r_empty;assign doubt=fifo[rp]; //output the data rp pointed//data wire in the FIFOalways @ (posedge clk)beginif ((wr==1'b0)&&(w_full==1'b0))fifo[wp]<=din;end//wp(indicate then adress of the coming new data)modified always @(posedge reset or posedge clk)beginif(reset)wp<=1'b0;elsebeginif((wr==1'b0)&&(w_full==1'b0))beginif(wp==3'b111)wp<=3'b000;elsewp<=wp+1'b1;endendend//rp(indicate the address of data which was readout) modefiedalways @(posedge reset or posedge clk)beginif(reset)rp<=3'b111;elsebeginif((rd==1'b0)&&(r_empty==1'b0))beginif(rp==3'b111)rp<=3'b000;elserp<=rp+1'b1;endendend//generate 'empty' indicationalways @(posedge reset or posedge clk)beginif(reset)r_empty=1'b1;elsebeginif(((rd==1'b0)&&(wr==1'b1))&&((rp==wp-3'b010)||((rp==3'b111)&&(wp==3'b001))||((rp==3'b11 0)&&(wp==3'b000))))r_empty<=1'b1;else if((r_empty==1'b1)&&(wr==1'b0))r_empty<=1'b0;endend//generate 'full' indicationalways @(posedge reset or posedge clk)beginif(reset)w_full<=1'b0;elsebeginif((rp==wp)&&(wr==1'b0)&&(rd==1'b1))w_full<=1'b1;else if((w_full==1'b1)&&(rd==1'b0))w_full<=1'b0;endend endmodule。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
FIFO存储器的设计
module fifo (clk, rstp, din, writep, readp, dout, emptyp, fullp);
input clk;
input rstp; //复位信号
input [15:0] din;
input readp; //读信号
input writep; //写信号
output [15:0] dout;
output emptyp; //空标志
output fullp; //满标志
parameterDEPTH = 2,
MAX_COUNT = 2’b11; //定义地址最大值
reg emptyp;
reg fullp;
reg [15:0]dout;
reg [(DEPTH-1):0] tail; //定义读指针
reg [(DEPTH-1):0] head; //定义写指针
// 定义计数器
reg [(DEPTH-1):0] count;
reg [15:0] fifomem[0:MAX_COUNT]; //定义fifomem存储器有4个16位的存储器
// dout被赋给tail指向的值
always @(posedge clk) begin
if (rstp == 1) begin
dout <= 16'h0000; //复位信号有效置0
end
else begin
dout <= fifomem[tail]; //将fifomem中第tail个单元赋给dout end
end
always @(posedge clk) begin
if (rstp == 1'b0 && writep == 1'b1 && fullp == 1'b0) begin
fifomem[head] <= din; //写入
end
end
always @(posedge clk) begin
if (rstp == 1'b1) begin
head <= 2'b00; //复位
end
else begin
if (writep == 1'b1 && fullp == 1'b0) begin
head <= head + 1;
end
end
end
always @(count) begin
if (count == 2'b00)
emptyp <= 1'b1; //count为0时emptyp赋为1
else
emptyp <= 1'b0;
end
always @(count) begin
if (count == MAX_COUNT)
fullp <= 1'b1; //计数到最大时fullp赋为1 else
fullp <= 1'b0;
end
endmodule
测试程序:
module test_fifo;
reg clk;
reg rstp;
reg [15:0]din;
reg readp;
reg writep;
wire [15:0] dout;
wire emptyp;
wire fullp;
reg [15:0]value;
fifo U1 (.clk(clk),.rstp(rstp),.din(din),.readp(readp),.writep(writep),.dout(dout), .emptyp(emptyp),.fullp(fullp));
task read_word;
begin
@(negedge clk);
readp = 1;
@(posedge clk) #5;
readp = 0;
end
endtask
task write_word;
input [15:0] value;
begin
@(negedge clk);
din = value;
writep = 1;
@(posedge clk);
#5;
din = 16'hzzzz;
writep = 0;
end
endtask
initial begin
clk = 0;
forever begin
#10 clk = 1;
#10 clk = 0;
end
end
initial begin
//test1;
test2; //调用测试模块2
end
task test1;
begin
din = 16'hzzzz;
writep = 0;
readp = 0;
rstp = 1;
#50 rstp = 0;
#50;
write_word (16'h1111);
write_word (16'h2222);
write_word (16‘h3333); //写入3个数据read_word;
read_word; //读两个
write_word (16‘h4444); //在写一个数据repeat (6) begin
read_word;
end
write_word (16'h0001);
write_word (16'h0002);
write_word (16'h0003);
write_word (16'h0004);
write_word (16'h0005);
write_word (16'h0006);
write_word (16'h0007);
write_word (16'h0008);
repeat (6) begin
read_word;
end
end
endtask
task test2;
reg [15:0] writer_counter;
begin
writer_counter = 16'h0001;
din = 16'hzzzz;
writep = 0;
readp = 0;
rstp = 1;
#50 rstp = 0;
#50;
fork
//写数据
begin
repeat (500) begin
@(negedge clk);
if (fullp == 1'b0) begin
write_word (writer_counter);
#5;
writer_counter = writer_counter + 1;
end
#50;
end
end。