I am working on a task that reads in a some video data and injects it into and axis interface. Maybe I am going about this wrong, but so far I have a for loop that loops through each pixel in the input file. If the downstream module de-asserts tready, I need to pause the loop. Is there someway to pause a for loop? is there a better way to do this, maybe using a while loop? I dont want to break out of the loop because I will loose what index I was at in the loop.
for(int i = 0; i < frame_width*frame_height*num_frames; i++) begin // loop through the number of pixels in the input file
if(s_axis_tready == 1'b1) begin
status = $fscanf(file_handler, "%c%c", frame[i][7:0], frame[i][15:8]);
@(posedge vhdcs_lvds_if.clock) this.vhdcs_lvds_byte_if.data[15:0] = frame[i][15:0];
if (status == 2) begin
s_axis_tvalid = 1'b1;
end
else begin
s_axis_tvalid = 1'b0; // otherwise tvalid should be low
end
//COUNTERS FOR SOF and TLAST GENERATION:
// tuser = SOF = data[16]. This should be high at the start of every frame, i.e. when the row counter and pixel counter are both 0
if(row_count == 0 && pixel_count == 0) begin
s_axis_tuser = 1'b1;
end else begin
s_axis_tuser = 1'b0;
end
// tlast = data[17]. This should be high at the end of every row, i.e. when the pixel counter reaches the width of the frame
if(pixel_count == frame_width-1) begin
s_axis_tlast = 1'b1;
pixel_count = 0; //reset counter after each row
if(row_count == frame_height-1) begin
row_count = 0;
end else begin
row_count = row_count + 1;
end
end else begin
s_axis_tlast = 1'b0;
pixel_count = pixel_count + 1;
end
end
end
You can use a while() loop to wait for t_ready to be asserted:
for(int i = 0; i < frame_width*frame_height*num_frames; i++) begin // loop through the number of pixels in the input file
while (s_axis_tready == 1'b0) @(posedge vhdcs_lvds_if.clock); // wait for t_ready to be asserted
status = $fscanf(file_handler, "%c%c", frame[i][7:0], frame[i][15:8]);
@(posedge vhdcs_lvds_if.clock) this.vhdcs_lvds_byte_if.data[15:0] = frame[i][15:0];
if (status == 2) begin
s_axis_tvalid = 1'b1;
end
else begin
s_axis_tvalid = 1'b0; // otherwise tvalid should be low
end
//COUNTERS FOR SOF and TLAST GENERATION:
// tuser = SOF = data[16]. This should be high at the start of every frame, i.e. when the row counter and pixel counter are both 0
if(row_count == 0 && pixel_count == 0) begin
s_axis_tuser = 1'b1;
end
else begin
s_axis_tuser = 1'b0;
end
// tlast = data[17]. This should be high at the end of every row, i.e. when the pixel counter reaches the width of the frame
if(pixel_count == frame_width-1) begin
s_axis_tlast = 1'b1;
pixel_count = 0; //reset counter after each row
if(row_count == frame_height-1) begin
row_count = 0;
end
else begin
row_count = row_count + 1;
end
end
else begin
s_axis_tlast = 1'b0;
pixel_count = pixel_count + 1;
end
end
In reply to ianmurph:
You can use a while() loop to wait for t_ready to be asserted:
for(int i = 0; i < frame_width*frame_height*num_frames; i++) begin // loop through the number of pixels in the input file
while (s_axis_tready == 1'b0) @(posedge vhdcs_lvds_if.clock); // wait for t_ready to be asserted
status = $fscanf(file_handler, "%c%c", frame[i][7:0], frame[i][15:8]);
@(posedge vhdcs_lvds_if.clock) this.vhdcs_lvds_byte_if.data[15:0] = frame[i][15:0];
if (status == 2) begin
s_axis_tvalid = 1'b1;
end
else begin
s_axis_tvalid = 1'b0; // otherwise tvalid should be low
end
//COUNTERS FOR SOF and TLAST GENERATION:
// tuser = SOF = data[16]. This should be high at the start of every frame, i.e. when the row counter and pixel counter are both 0
if(row_count == 0 && pixel_count == 0) begin
s_axis_tuser = 1'b1;
end
else begin
s_axis_tuser = 1'b0;
end
// tlast = data[17]. This should be high at the end of every row, i.e. when the pixel counter reaches the width of the frame
if(pixel_count == frame_width-1) begin
s_axis_tlast = 1'b1;
pixel_count = 0; //reset counter after each row
if(row_count == frame_height-1) begin
row_count = 0;
end
else begin
row_count = row_count + 1;
end
end
else begin
s_axis_tlast = 1'b0;
pixel_count = pixel_count + 1;
end
end
Thank you very much for the reply. This is quite close to working, but it seems to be delayed by one clock cycle, so one pixel gets dropped and one gets written twice on every tready cycle.
for(int i = 0; i < frame_width*frame_height*num_frames; i++) begin // loop through the number of pixels in the input file
@(posedge vhdcs_lvds_if.clock);
while (s_axis_tready == 1'b0) @(posedge vhdcs_lvds_if.clock); // wait for t_ready to be asserted
status = $fscanf(file_handler, "%c%c", frame[i][7:0], frame[i][15:8]);
this.vhdcs_lvds_byte_if.data[15:0] = frame[i][15:0];
if (status == 2) begin
s_axis_tvalid = 1'b1;
end
else begin
s_axis_tvalid = 1'b0; // otherwise tvalid should be low
end