📄 svgactrl.vhd
字号:
------------------------------------------------------------------------------ This file is a part of the GRLIB VHDL IP LIBRARY-- Copyright (C) 2004 GAISLER RESEARCH---- This program is free software; you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation; either version 2 of the License, or-- (at your option) any later version.---- See the file COPYING for the full details of the license.--------------------------------------------------------------------------------- Entity: Vga Controller-- File: vga_controller.vhd-- Author: Hans Soderlund-- Description: Vga Controller main file-----------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;library grlib;use grlib.amba.all;use grlib.stdlib.all;use grlib.devices.all;library techmap;use techmap.gencomp.all;library gaisler;use gaisler.misc.all; entity svgactrl is generic( length : integer := 384; -- Fifo-length part : integer := 128; -- Fifo-part lenght memtech : integer := DEFMEMTECH; pindex : integer := 0; paddr : integer := 0; pmask : integer := 16#fff#; hindex : integer := 0; hirq : integer := 0; clk0 : integer := 40000; clk1 : integer := 20000; clk2 : integer := 15385; clk3 : integer := 0; burstlen : integer range 2 to 8 := 8 ); port ( rst : in std_logic; clk : in std_logic; vgaclk : in std_logic; apbi : in apb_slv_in_type; apbo : out apb_slv_out_type; vgao : out apbvga_out_type; ahbi : in ahb_mst_in_type; ahbo : out ahb_mst_out_type; clk_sel : out std_logic_vector(1 downto 0) );end ;architecture rtl of svgactrl is constant REVISION : amba_version_type := 0; constant pconfig : apb_config_type := ( 0 => ahb_device_reg ( VENDOR_GAISLER, GAISLER_SVGACTRL, 0, REVISION, 0), 1 => apb_iobar(paddr, pmask)); type RegisterType is array (1 to 5) of std_logic_vector(31 downto 0); type state_type is (running, not_running, reset); type read_type is record read_pointer : integer range 0 to length ; read_pointer_out : integer range 0 to length ; sync : std_logic_vector(2 downto 0); data_out : std_logic_vector(23 downto 0); lock : std_logic; index : std_logic_vector(1 downto 0); mem_index : integer; read_pointer_clut : std_logic_vector(7 downto 0); hcounter : std_logic_vector(15 downto 0); vcounter : std_logic_vector(15 downto 0); fifo_ren : std_logic; fifo_en : std_logic; hsync : std_logic ; vsync : std_logic ; csync : std_logic ; blank : std_logic ; hsync2 : std_logic ; vsync2 : std_logic ; csync2 : std_logic ; blank2 : std_logic ; end record; type control_type is record int_reg : RegisterType; state : state_type; enable : std_logic; reset : std_logic; sync_c : std_logic_vector(2 downto 0); sync_w : std_logic_vector(2 downto 0); write_pointer_clut : std_logic_vector(7 downto 0); datain_clut : std_logic_vector(23 downto 0); write_en_clut : std_logic; adress : std_logic_vector(31 downto 0); start : std_logic; write_pointer : integer range 0 to length; ram_address : integer range 0 to length; data : std_logic_vector(31 downto 0); level : integer range 0 to part + 1; status : integer range 0 to 3; hpolarity : std_ulogic; vpolarity : std_ulogic; func : std_logic_vector(1 downto 0); clk_sel : std_logic_vector(1 downto 0); end record; type sync_regs is record s1 : std_logic_vector(2 downto 0); s2 : std_logic_vector(2 downto 0); s3 : std_logic_vector(2 downto 0); end record; signal t,tin : read_type; signal r,rin : control_type; signal sync_w : sync_regs; signal sync_ra : sync_regs; signal sync_rb : sync_regs; signal sync_c : sync_regs; signal read_status : std_logic_vector(2 downto 0); signal write_status : std_logic_vector(2 downto 0); signal write_en : std_logic; signal res_mod :std_logic; signal en_mod : std_logic; signal fifo_en : std_logic; signal dmai : ahb_dma_in_type; signal dmao : ahb_dma_out_type; signal equal : std_logic; signal hmax : std_logic_vector(15 downto 0); signal hfporch : std_logic_vector(15 downto 0); signal hsyncpulse : std_logic_vector(15 downto 0); signal hvideo : std_logic_vector(15 downto 0); signal vmax : std_logic_vector(15 downto 0); signal vfporch : std_logic_vector(15 downto 0); signal vsyncpulse : std_logic_vector(15 downto 0); signal vvideo : std_logic_vector(15 downto 0); signal write_pointer_clut : std_logic_vector(7 downto 0); signal read_pointer_clut : std_logic_vector(7 downto 0); signal read_pointer_fifo : std_logic_vector(9 downto 0); signal write_pointer_fifo : std_logic_vector(9 downto 0); signal datain_clut : std_logic_vector(23 downto 0); signal dataout_clut : std_logic_vector(23 downto 0); signal dataout_fifo : std_logic_vector(31 downto 0); signal datain_fifo : std_logic_vector(31 downto 0); signal write_en_clut : std_logic; signal vcc : std_logic;begin vcc <= '1'; ram0 : syncram_2p generic map (tech => memtech, abits => 10, dbits => 32, sepclk => 1) port map (vgaclk, vcc, read_pointer_fifo, dataout_fifo,clk, vcc, write_pointer_fifo, datain_fifo); clutram : syncram_2p generic map (tech => memtech, abits => 8, dbits => 24, sepclk => 1) port map (vgaclk, vcc, read_pointer_clut, dataout_clut, clk, write_en_clut, write_pointer_clut,datain_clut); ahb_master : ahbmst generic map (hindex, hirq, VENDOR_GAISLER, GAISLER_SVGACTRL, 0, 3, 1) port map (rst, clk, dmai, dmao, ahbi, ahbo); apbo.pirq <= (others => '0'); apbo.pindex <= pindex; apbo.pconfig <= pconfig; control_proc : process(r,rst,sync_c,apbi,fifo_en,write_en,read_status,dmao,res_mod) variable v: control_type; variable rdata : std_logic_vector(31 downto 0); variable mem_sel : integer; variable apbwrite : std_logic; begin v := r; v.write_en_clut := '0'; rdata := (others =>'0'); mem_sel := conv_integer(apbi.paddr(5 downto 2));-- Control part. This part handles the apb-accesses and stores the internal registers-------------------------------------------------------------------------------------------------------------------------------------------------------------- apbwrite := apbi.psel(pindex) and apbi.pwrite and apbi.penable; case apbi.paddr(5 downto 2) is when "0000" => if apbwrite = '1' then v.enable := apbi.pwdata(0); v.reset := apbi.pwdata(1); v.hpolarity := apbi.pwdata(8); v.vpolarity := apbi.pwdata(9); v.func := apbi.pwdata(5 downto 4); v.clk_sel := apbi.pwdata(7 downto 6); end if; rdata(9 downto 0) := r.vpolarity & r.hpolarity & r.clk_sel & r.func & fifo_en & '0' & r.reset & r.enable; when "1010" => if apbwrite = '1' then v.datain_clut := apbi.pwdata(23 downto 0); v.write_pointer_clut := apbi.pwdata(31 downto 24); v.write_en_clut := '1'; end if; when "0001" => if apbwrite = '1' then v.int_reg(1) := apbi.pwdata; end if; rdata := r.int_reg(1); when "0010" => if apbwrite = '1' then v.int_reg(2) := apbi.pwdata; end if; rdata := r.int_reg(2); when "0011" => if apbwrite = '1' then v.int_reg(3) := apbi.pwdata; end if; rdata := r.int_reg(3); when "0100" => if apbwrite = '1' then v.int_reg(4) := apbi.pwdata; end if; rdata := r.int_reg(4); when "0101" => if apbwrite = '1' then v.int_reg(5) := apbi.pwdata; end if; rdata := r.int_reg(5); when "0110" => rdata := conv_std_logic_vector(clk0,32); when "0111" => rdata := conv_std_logic_vector(clk1,32); when "1000" => rdata := conv_std_logic_vector(clk2,32); when "1001" => rdata := conv_std_logic_vector(clk3,32); when others => end case; ------------------------------------------ ----------- Control state machine -------- case r.state is when running => if r.enable = '0' then v.sync_c := "011"; v.state := not_running; end if; when not_running => if r.enable = '1' then v.sync_c := "001"; v.state := reset; end if; when reset => if sync_c.s3 = "001" then v.sync_c := "010"; v.state := running; end if; end case; ---------------------------------------------------- Control reset part----------- if r.reset = '1' or rst = '0' then v.state := not_running; v.enable := '0'; v.int_reg := (others => (others => '0')); v.sync_c := "011"; v.reset := '0'; v.clk_sel := "00"; end if; -------------------------------------------------------------------------------- Write part. This part reads from the memory framebuffer and places the data-- in the designated fifo specified from the generic.------------------------------------------------------------------------------- v.start := '0'; if write_en = '0' then v.start := '1'; if dmao.ready = '1' then ------------ AHB access part ----------- ---------- and Fifo write part --------- v.data := dmao.rdata(31 downto 0); v.ram_address := v.write_pointer; v.write_pointer := v.write_pointer +1; if v.write_pointer = length then v.write_pointer := 0; end if; v.level := v.level +1; if dmao.haddr = (9 downto 0 => '0') then v.adress := (v.adress(31 downto 10) + 1) & dmao.haddr; else v.adress := v.adress(31 downto 10) & dmao.haddr; end if;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -