本帖最后由 RZJM 于 2016-1-29 23:39 编辑
本编文章将对VGA的RTL代码,封装成AXI Stream,并且在vivado 里用TPG进行测试
本篇文章的VGA RTL代码在【ZYNQ-7000开发之一】基础上修改,封装好的VGA Stream可以方便我们实现视频图像处理
TGP 等的规范说明可以到官网下载最新版本
本文所使用的开发板是Miz702(兼容zedboard)
PC 开发环境版本:Vivado 2015.2 Xilinx SDK 2015.2
其它:VGA显示器
AXI Stream原理 首先这里列出axi stream的信号,红框里的是要用到的
核心的信号是,TVALID,TREADY,TLAST,TUSER
TVALID和TREADY握手信号
在TVALID和TREADY同时有效的时候,数据才有效。对于TPG来说,大部分时间TVALID是有效的,TREADY由我们自己控制。
TUSER(SOF,Start Of Frame),代表每一帧的开始。TLAST(EOL,End Of Line),代表每一行的结束。
这里给出TPG的时序图,比较简洁,要理解之后才好把RTL封装成AXI Stream
封装AXI Stream 打开vivado,建立一个工程(选择zed) 选择Tools->Create and Package IP
点击NEXT,选择Create AXI4,如图所示
输入好name和路径后,点击NEXT
按照如下配置(Name为S00_AXI_VGA)
点击NEXT,选择Edit IP,然后点击Finish 这时会弹出一个新的IP 编辑界面,这个可以看到VIVADO已经自动生成了一些必要的AXI Stream相关的代码,我们在这个基础上修改很方便 把VGA_AXI_Stream_v1_0.v文件里的代码,修改如下
`timescale 1 ns / 1 ps
module myip_v1_0 #
(
// Users to add parameters here
// User parameters ends
// Do not modify the parameters beyond this line
// Parameters of Axi Slave Bus Interface S00_AXIS_VGA
parameter integer C_S00_AXIS_VGA_TDATA_WIDTH = 32
)
(
// Users to add ports here
input wire clk_25mhz,
output wire hsync,
output wire vsync,
output wire [11:0] rgb,
output reg led,
// User ports ends
// Do not modify the ports beyond this line
// Ports of Axi Slave Bus Interface S00_AXIS_VGA
input wire s00_axis_vga_aclk,
input wire s00_axis_vga_aresetn,
output wire s00_axis_vga_tready,
input wire [C_S00_AXIS_VGA_TDATA_WIDTH-1 : 0] s00_axis_vga_tdata,
input wire [(C_S00_AXIS_VGA_TDATA_WIDTH/8)-1 : 0] s00_axis_vga_tstrb,
input wire s00_axis_vga_tlast,
input wire s00_axis_vga_tvalid,
input wire s00_axis_vga_tuser
);
// Instantiation of Axi Bus Interface S00_AXIS_VGA
myip_v1_0_S00_AXIS_VGA # (
.C_S_AXIS_TDATA_WIDTH(C_S00_AXIS_VGA_TDATA_WIDTH)
) myip_v1_0_S00_AXIS_VGA_inst (
.S_AXIS_ACLK(s00_axis_vga_aclk),
.S_AXIS_ARESETN(s00_axis_vga_aresetn),
.S_AXIS_TREADY(s00_axis_vga_tready),
.S_AXIS_TDATA(s00_axis_vga_tdata),
.S_AXIS_TSTRB(s00_axis_vga_tstrb),
.S_AXIS_TLAST(s00_axis_vga_tlast),
.S_AXIS_TVALID(s00_axis_vga_tvalid),
.S_AXIS_TUSER(s00_axis_vga_tuser),
.clk (clk_25mhz),
.rst_n (s00_axis_vga_aresetn),
.video_en (video_en),
.hsync (hsync),
.vsync (vsync),
.pixel_x (pixel_x),
.pixel_y (pixel_y)
);
// Add user logic here
wire [9:0] pixel_x;
wire [9:0] pixel_y;
wire clk_25mhz;
reg [11:0] rgb_reg;
//显示静态图像640*480
reg [23:0] cnt;
always @(posedge clk_25mhz or negedge s00_axis_vga_aresetn)
if(!s00_axis_vga_aresetn)
begin
cnt <= 0;
led <= 0;
end
else
begin
cnt <= cnt + 1'b1;
if(cnt == 24'd12500000)
begin
cnt <= 24'b0;
led <= ~led;
end
end
always @ (posedge clk_25mhz or negedge s00_axis_vga_aresetn)
if(!s00_axis_vga_aresetn)
begin
rgb_reg <= 12'b0;
end
else if(s00_axis_vga_tvalid == 1'b1 && s00_axis_vga_tready == 1'b1)
begin //显示图像
rgb_reg[3:0] <= s00_axis_vga_tdata[7:4];
rgb_reg[7:4] <= s00_axis_vga_tdata[15:12];
rgb_reg[11:8] <= s00_axis_vga_tdata[23:20];
end
/*
always @ (posedge clk_25mhz or negedge s00_axis_vga_aresetn)
if(!s00_axis_vga_aresetn)
begin
address_sig <= 19'b0;
end
else
begin
if(pixel_x>=0 && pixel_x<= 639 && pixel_y>=0 && pixel_y<=479)
address_sig = (pixel_x + 640*pixel_y);
end
*/
//////////////////////////////////////////////////////////////
assign rgb = (video_en == 1'b1) ? rgb_reg:12'b0;
// User logic ends
endmodule 复制代码
把VGA_AXI_Stream_v1_0_S00_AXI_VgA.v文件里的代码,修改如下
保存后,按照如图所示操作
其它的类似,最后在Review and Package,里选择repackage
建立硬件工程 首先要把IP的路径添加进来 在vivado里新建一个Block Design,按照如图所示建立硬件工程,FCLK_CLK0设置成25MHz
TPG这样配置
约束文件如下 set_property PACKAGE_PIN T22 [get_ports led]
set_property IOSTANDARD LVCMOS33 [get_ports led]
set_property PACKAGE_PIN AA19 [get_ports hsync]
set_property IOSTANDARD LVCMOS33 [get_ports hsync]
set_property PACKAGE_PIN Y19 [get_ports vsync]
set_property IOSTANDARD LVCMOS33 [get_ports vsync]
set_property PACKAGE_PIN Y21 [get_ports {rgb[0]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[0]}]
set_property PACKAGE_PIN Y20 [get_ports {rgb[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[1]}]
set_property PACKAGE_PIN AB20 [get_ports {rgb[2]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[2]}]
set_property PACKAGE_PIN AB19 [get_ports {rgb[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[3]}]
set_property PACKAGE_PIN AB22 [get_ports {rgb[4]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[4]}]
set_property PACKAGE_PIN AA22 [get_ports {rgb[5]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[5]}]
set_property PACKAGE_PIN AB21 [get_ports {rgb[6]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[6]}]
set_property PACKAGE_PIN AA21 [get_ports {rgb[7]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[7]}]
set_property PACKAGE_PIN V20 [get_ports {rgb[8]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[8]}]
set_property PACKAGE_PIN U20 [get_ports {rgb[9]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[9]}]
set_property PACKAGE_PIN V19 [get_ports {rgb[10]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[10]}]
set_property PACKAGE_PIN V18 [get_ports {rgb[11]}]
set_property IOSTANDARD LVCMOS33 [get_ports {rgb[11]}] 复制代码
编译后,导出硬件,新建一个Hello工程(主要是为PL提供25M时钟) 开发板上电测试,效果如下(color bar效果)