01 Dec 09:08
2
`timescale 1ns / 1ps
module axi_stream_XY(
input CLK,
input RSTN,
input S_TVALID,
input S_TUSER,
input S_TLAST,
output S_TREADY,
input M_TREADY,
output reg M_TVALID,
output reg M_TUSER,
output reg M_TLAST,
output reg [31:0] M_TDATA,
output [10:0] X, Y,
input [23:0] RGB
);
reg [10:0] next_x;
reg [10:0] next_y;
assign X = S_TUSER ? 11'd0 : next_x;
assign Y = S_TUSER ? 11'd0 : next_y;
assign S_TREADY =
RSTN && (!M_TVALID || M_TREADY);
wire [9:0] r10 = {RGB[23:16], RGB[23:22]};
wire [9:0] g10 = {RGB[15:8], RGB[15:14]};
wire [9:0] b10 = {RGB[7:0], RGB[7:6]};
always @(posedge CLK) begin
if (!RSTN) begin
next_x <= 0;
next_y <= 0;
M_TVALID <= 0;
M_TUSER <= 0;
M_TLAST <= 0;
M_TDATA <= 0;
end
else if (S_TREADY) begin
M_TVALID <= S_TVALID;
if (S_TVALID) begin
M_TDATA <= {2'b00, r10, b10, g10};
M_TUSER <= S_TUSER;
M_TLAST <= S_TLAST;
if (S_TLAST) begin
next_x <= 0;
next_y <= Y + 11'd1;
end
else begin
next_x <= X + 11'd1;
next_y <= Y;
end
end
end
end
endmodule