Forum Discussion
Altera_Forum
Honored Contributor
12 years agoHi kaz, thank you very much for your reply.
I forgot myself to include the backpressure control in that code. Now I'm using the sink_enable signal to stop the data stream when the Encoder is not able to receive more data. This way it should be reasonably good, in fact the RS compiler guide says: "By de-asserting sink_ena, the encoder signals that it cannot sink more incoming symbols after sink_eop is signalled at the input. During this time it is generating the check symbols for the current codeword." However it doesn't work, as before. I post the corrected code:
module avalon_st_interface(
input clk,res,
input valid,
input data_in,
input sink_en,
output reg sop,eop,source_val,
output reg source_en,
output reg data_out,
output reg count
);
reg valid_mem;
always@(posedge clk)begin source_en<=sink_en;end
always@(posedge clk)begin data_out<=data_in;end
always@(posedge clk)begin valid_mem<=valid;end
always@(posedge clk or posedge res)
begin
if(res)
begin
count<=9'd0;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd0;
end
else
begin
if(sink_en)
begin
if(!valid_mem & valid & count==9'd0)
begin
count<=9'd1;
sop<=1'd1;
eop<=1'd0;
source_val<=1'd1;
end
else if(valid & count==9'd222)
begin
count<=count + 9'd1;
sop<=1'd0;
eop<=1'd1;
source_val<=1'd1;
end
else if(valid & count==9'd223)
begin
count<=9'd1;
sop<=1'd1;
eop<=1'd0;
source_val<=1'd1;
end
else if(valid & count>=9'd0 & count<=9'd222)
begin
count<=count + 9'd1;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd1;
end
else if(!valid & count>=9'd0 & count<=9'd222)
begin
count<=count;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd0;
end
else if(!valid & (count==9'd0 | count==9'd223)) //idle
begin
count<=9'd0;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd0;
end
else
begin
count<=9'd0;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd0;
end
end
else //backpressure on
begin
count<=count;
sop<=1'd0;
eop<=1'd0;
source_val<=1'd0;
end
end
end
endmodule