dsi-shield/hdl/rtl/dsi_core/dsi_test_image_gen.v

186 lines
4.9 KiB
Verilog

/*
* DSI Core
* Copyright (C) 2013 twl <twlostow@printf.cc>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
`include "dsi_defs.vh"
`timescale 1ns/1ns
/*
* dsi_test_image_gen.v
*
* A simple color bar image generator.
*/
module dsi_test_image_gen
(
input clk_i,
input rst_n_i,
input fifo_full_i,
output fifo_frame_o,
output [23:0] fifo_pixel_o,
output fifo_we_o,
input [5:0] host_a_i,
input [31:0] host_d_i,
output [31:0] host_d_o,
input host_wr_i,
output test_enable_o
);
parameter g_use_dpram = 1;
parameter g_fb_size = 640 * 960 / 2;
parameter g_fb_base = 32'h08000000;
parameter g_fb_mask = 32'h0f000000;
reg [11:0] r_xsize;
reg [11:0] r_ysize;
reg r_enable;
reg [11:0] x, y;
wire fifo_we;
reg [3:0] framebuffer [ 0:g_fb_size-1 ];
// synthesis translate_off
initial begin: init_ram
integer i;
for(i=0;i<g_fb_size;i=i+1)
framebuffer[i] = 0;
end
// synthesis translate_on
reg [20:0] fb_raddr, fb_waddr;
reg [20:0] fb_raddr_next;
reg [3:0] fb_rdata;
reg [23:0] pixel;
generate
always@(posedge clk_i)
if(!r_enable || !rst_n_i)
begin
x <= 0;
y <= 0;
end else begin
if(fifo_we)
begin
if(x == r_xsize) begin
x <= 0;
if(y == r_ysize)
y <= 0;
else
y <= y+1;
end else
x<= x + 1;
end
end // else: !if(!r_enable)
assign fifo_we = ~fifo_full_i && r_enable;
assign fifo_we_o = fifo_we;
assign fifo_frame_o = (x == 0 && y == 0);
if(!g_use_dpram)
begin
assign fifo_pixel_o[23:16] = (x==0||y==0||x==r_xsize||y==r_ysize) ? 'hff : ((x & 'h30) == 'h10 ? 8'hff : 0);
assign fifo_pixel_o[15:8] = (x & 'h30) == 'h20 ? 8'hff : 0;
assign fifo_pixel_o[7:0] = x;
end // if (!g_use_dpram)
// big framebuffer. good for testing in bigger FPGAs, but not really practical.
if(g_use_dpram) begin
// framebuffer DPRAM
always@(posedge clk_i)
begin
if(host_a_i == `REG_DBG_DATA && host_wr_i)
framebuffer[ host_d_i[20:0] ] <= host_d_i[27:24];
fb_rdata <= framebuffer[fb_raddr_next];
end
always @*
if(x == r_xsize && y ==r_ysize)
fb_raddr_next <= 0;
else if (x == r_xsize && !y[0])
fb_raddr_next <= fb_raddr - r_xsize;
else if (fifo_we)
fb_raddr_next <= fb_raddr + 1;
else
fb_raddr_next <= fb_raddr;
always@(posedge clk_i)
if(!r_enable || !rst_n_i)
fb_raddr <= 0;
else
fb_raddr <= fb_raddr_next;
always@(fb_rdata)
case(fb_rdata)
0 : pixel <= 24'h000000;
1 : pixel <= 24'h000080;
2 : pixel <= 24'h0000ff;
3 : pixel <= 24'h008000;
4 : pixel <= 24'h008080;
5 : pixel <= 24'h00ff00;
6 : pixel <= 24'h00ffff;
7 : pixel <= 24'h800000;
8 : pixel <= 24'h800080;
9 : pixel <= 24'h808000;
10 : pixel <= 24'h808080;
11 : pixel <= 24'hc0c0c0;
12 : pixel <= 24'hff0000;
13 : pixel <= 24'hff00ff;
14 : pixel <= 24'hffff00;
15 : pixel <= 24'hffffff;
default : pixel <= 24'h000000;
endcase // case (fb_rdata)
assign fifo_pixel_o = pixel;
end // if (g_use_dpram)
endgenerate
always@(posedge clk_i)
if(!rst_n_i)
begin
r_enable <= 0;
end else if (host_wr_i) begin
case(host_a_i)
`REG_TEST_CTL: r_enable <= host_d_i[0];
`REG_TEST_XSIZE: r_xsize <= host_d_i;
`REG_TEST_YSIZE: r_ysize <= host_d_i;
endcase // case (host_a_i)
end
assign test_enable_o = r_enable;
endmodule // test_image_gen