logari84
Newbie level 6
- Joined
- Jul 15, 2015
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,453
Hi all.
I've been looking for a FIFO implementation in SystemVerilog and unfortunately I couldn't find anything. So I decided to make one and post it here just in case someone needs it in the future.
P.S. I want to upload the source code for the FIFO and for the testbench but I get an error about incompatible file... Is not .sv supported??
I've been looking for a FIFO implementation in SystemVerilog and unfortunately I couldn't find anything. So I decided to make one and post it here just in case someone needs it in the future.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 /**************************************************************************************************************** STAMATIS POULIOS, 28/07/2015 File name: fifo.sv Description: Generalized fifo. Stores 'IN_BUS_WIDTH'-wide words. The depth of the fifo is defined by the value of the 'FIFO_DEPTH' variable. ****************************************************************************************************************/ `ifndef FIFO__SV `define FIFO__SV //*************************************************************************************************************** // Defines section //*************************************************************************************************************** `define FIFO_DEPTH 32 `define IN_BUS_WIDTH 5 `define FIFO_CNT_WIDTH 5 //*************************************************************************************************************** // Module declaration: fifo //*************************************************************************************************************** module fifo ( input logic clk, input logic rst, input logic [`IN_BUS_WIDTH-1:0] data_in, input logic rd_en, input logic wr_en, output logic empty, output logic full, output logic [`IN_BUS_WIDTH-1:0] data_out ); logic [`FIFO_DEPTH-1:0][`IN_BUS_WIDTH-1:0] buff_mem; logic [`FIFO_CNT_WIDTH-1:0] rd_ptr, wr_ptr; logic [`FIFO_DEPTH-1:0] status; // The 'status' signal indicates the status of the Nth memory position. Value '1' indicates new data is stored // in the Nth memory position, but not yet read. Value '0' indicates that the data from that memory position is // read and the memory position is available for writing new data. always@(data_out) begin assign empty = (status == 0); assign full = (status == {(`FIFO_DEPTH){1'b1}}); end always@(posedge clk or posedge rst) begin if(rst) begin data_out <= 0; buff_mem <= 0; status <= 0; rd_ptr <= 0; wr_ptr <= 0; end else begin data_out <= data_out; buff_mem[wr_ptr] <= buff_mem[wr_ptr]; rd_ptr <= rd_ptr; wr_ptr <= wr_ptr; if( rd_en && !empty ) begin data_out <= buff_mem[rd_ptr][`IN_BUS_WIDTH-1:0]; status[rd_ptr] <= 1'b0; rd_ptr <= rd_ptr + 1; end else if( wr_en && !full ) begin buff_mem[wr_ptr] <= {data_in}; status[wr_ptr] <= 1'b1; wr_ptr <= wr_ptr + 1; end end end endmodule `endif
P.S. I want to upload the source code for the FIFO and for the testbench but I get an error about incompatible file... Is not .sv supported??