Search code examples
verilogcompiler-warningsxilinxhdlxilinx-ise

What is the reason behind the warnings (Xst:3015) and how to rectify the same?


This is my warning message

WARNING:Xst:3015 - Contents of array <buf_mem> may be accessed with an index that does not cover the full array size or with a negative index. The RAM size is reduced to the index upper access or for only positive index values.

This is my code

module FIFO_Single_clock(
input clk,
input rst,
input [7:0] buf_in,
output [7:0] Buf_out,
input wr_en,
input rd_en,
output Buf_empty,
output Buf_full,
output [7:0] Fifo_counter
);
reg [7:0] buf_out;
reg buf_empty,buf_full;
reg [7:0] fifo_counter;
reg [3:0] rd_ptr,wr_ptr;
reg [7:0] buf_mem[63:0];

assign Buf_out = buf_out;
assign Buf_empty = buf_empty;
assign Buf_full = buf_full;
assign Fifo_counter = fifo_counter;

always@(fifo_counter)
  begin
  buf_empty=(fifo_counter==0);
  buf_full=(fifo_counter==64);
  end

always@(posedge clk or posedge rst)
  begin
  if(rst)
    begin
    fifo_counter <=8'h0;
    end
else if((!buf_full && wr_en)&&(!buf_empty && rd_en))
    begin
    fifo_counter <=fifo_counter;
    end
else if(!buf_full && wr_en)
    begin
    fifo_counter <= fifo_counter+8'h1;
    end
else if(!buf_empty && rd_en)
    begin
    fifo_counter <= fifo_counter-8'h1;
    end
else
    begin
    fifo_counter <= fifo_counter;
    end
end

always@(posedge clk or posedge rst)
begin
if(rst)
    begin
    buf_out <=8'h0;
    end
else
    begin
    if(rd_en && !buf_empty)
        begin
        buf_out <= buf_mem[rd_ptr];
        end
    else
        begin
        buf_out <= buf_out;
        end
    end
end

always@(posedge clk)
 begin
 if(wr_en && !buf_full)
    begin
    buf_mem[wr_ptr] <= buf_in;
    end
else
    begin
    buf_mem[wr_ptr] <= buf_mem[wr_ptr];
    end
end

always@(posedge clk or posedge rst)
begin
if(rst)
    begin
    wr_ptr <=4'h0;
    rd_ptr <=4'h0;
    end
else
    begin
    if(!buf_full&& wr_en)
        begin
        wr_ptr <= wr_ptr+4'h1;
        end
    else
        begin
        wr_ptr <= wr_ptr;
        end
    if(!buf_empty && rd_en )
        begin
        rd_ptr <= rd_ptr+4'h1;
        end
    else
        begin
        rd_ptr <= rd_ptr;
        end
    end
 end
endmodule

I am getting warning for this code. Please help me to solve and understand about the warning message.


Solution

  • You declared a memory with 64 locations with this line:

    reg [7:0] buf_mem[63:0];
    

    To access all locations you need an index (or pointer) which is 6 bits (values 0 to 63).

    However, you declared your indexes with only 4 bits in this line:

    reg [3:0] rd_ptr,wr_ptr;
    

    Those can only index locations 0 to 15. The warning tells you that you will only have a memory with 16 locations, not 64.

    If you want 64 locations in your memory, you need to change your pointers to:

    reg [5:0] rd_ptr,wr_ptr;
    

    and make any other needed adjustments.