Altera_Forum
Honored Contributor
13 years agoCircular Buffer Implementation
Good morning. Am trying to implement a circular buffer to write to external SRAM. I am using two always constructs. The first determines that something should be written (there are multiple potential writes in this function) and the second actually performs the write. However, I do not see the writes occurring.
First Q: Have changed between blocking v. non-blocking with no change in performance (The writes never occur) Second Q: As an old SW guy, if I create a 256 elemnt buffer with 8 bit wr and rd indexes, the indexes automatically wrap from 255 to 0 when I increment. Is this the same behavior in Verliog? Example code (with unimportant stuff omitted): reg [19:0] sram_buffer [7:0] reg [7:0]sram_buffer_rd_index; reg [7:0]sram_buffer_wr_index; always @(posedge clk or negedge reset_n) begin if (sram_buffer_rd_index != sram_buffer_wr_index) begin decision[sram_buffer[sram_buffer_rd_index]] <= 1; sram_buffer_rd_index = sram_buffer_rd_index + 1; end end always @(posedge clk or negedge reset_n) begin /* Unimportant Stuff ommitted */ sram_buffer[sram_buffer_wr_index] = data[0]; // Increment the decision coverage write SM write counter sram_buffer_wr_index = sram_buffer_wr_index + 1; /* Unimportant Stuff ommitted */ sram_buffer[sram_buffer_wr_index] = data[1]; // Increment the decision coverage write SM write counter sram_buffer_wr_index = sram_buffer_wr_index + 1; /* Unimportant Stuff ommitted */ sram_buffer[sram_buffer_wr_index] = data[2]; // Increment the decision coverage write SM write counter sram_buffer_wr_index = sram_buffer_wr_index + 1; end