⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genxlib_arch.vhd

📁 用VHDL语言编程实现2维图像的滤波算法
💻 VHD
📖 第 1 页 / 共 2 页
字号:
  general: if IWIDTH>OWIDTH+1 generate
    biased : if (MODE=0) generate r_cy <= '1'; end generate; 
    tw_zero: if (MODE=1) generate r_cy <= msb; end generate;
    tw_inf : if (MODE=2) generate r_cy <= NOT msb; end generate;
    
    no_offset : if (has_offset = 0) generate r_add <= zeros & ones; end generate;
    hs_offset : if (has_offset = 1) generate r_add <= offset & '0' & ones; end generate;
  end generate;
  
  one_bit: if IWIDTH=OWIDTH+1 generate
    biased : if (MODE=0) generate r_cy <= '0'; end generate; 
    tw_zero: if (MODE=1) generate r_cy <= msb; end generate;
    tw_inf : if (MODE=2) generate r_cy <= NOT msb; end generate;
    
    no_offset : if (has_offset = 0) generate r_add <= zeros; end generate;
    hs_offset : if (has_offset = 1) generate r_add <= offset & '0'; end generate;
  end generate;

  no_rnd: if IWIDTH<OWIDTH+1 generate
    biased : if (MODE=0) generate r_cy <= '0'; end generate; 
    tw_zero: if (MODE=1) generate r_cy <= msb; end generate;
    tw_inf : if (MODE=2) generate r_cy <= NOT msb; end generate;
    
    no_offset : if (has_offset = 0) generate r_add <= zeros(IWIDTH-1 downto 0) ; end generate;
    hs_offset : if (has_offset = 1) generate r_add <= offset(IWIDTH-1 downto 0); end generate;
  end generate;

end rtl;

-- *********************************************
--  *0004*  round Macro
--  round
--
-- *********************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

entity round is 
  generic ( 
    iwidth    : integer := 16;
    owidth    : integer := 15;
    has_offset: integer := 0;
    mode      : integer := 0; -- 0: biased, 1: towards zero, 2: towards inf
    delay     : integer :=  1);
  port (
    a       : in std_logic_vector(iwidth-1 downto 0);
    offset  : in  std_logic_vector(OWIDTH-1 downto 0) := (others => '0');
    ra      : out std_logic_vector(OWIDTH-1 downto 0);
    clk     : in std_logic;
    ce      : in std_logic;
    sclr    : in std_logic);
end round;

architecture rtl of round is
  signal rounding_const : std_logic_vector(iwidth-1 downto 0); 
  signal rounding_carry : std_logic;
  signal q              : std_logic_vector(iwidth downto 0); 

begin

  rnd_add : entity work.get_round_addend(rtl)  
    generic map( 
      IWIDTH      => IWIDTH,
      OWIDTH      => OWIDTH,
      has_offset  => has_offset,
      mode        => mode)
    port map(
      msb         => a(IWIDTH-1),
      offset      => offset,
      r_add       => rounding_const,
      r_cy        => rounding_carry);

  adder : entity work.radd_sub_sclr(rtl) 
    generic map ( width => iwidth, delay => delay)   
    port map ( clk => clk, ce => ce, sclr => sclr, 
               c_in => rounding_carry, a => a, b => rounding_const, s => q);

  ra <= q(iwidth-1 downto iwidth-OWIDTH);
end rtl;

-- *********************************************
--  *0005*  mult Macro
--  mult
--
-- *********************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

entity mult is 
  generic ( 
    IWIDTHA : integer:=18;
    IWIDTHB : integer:=18;
    delay   : integer:=2);
  port (
    a       : in std_logic_vector(IWIDTHA-1 downto 0);
    b       : in std_logic_vector(IWIDTHB-1 downto 0);
    p       : out std_logic_vector(IWIDTHA+IWIDTHB-1 downto 0);
    clk     : in std_logic;
    ce      : in std_logic;
    sclr    : in std_logic);

  attribute register_balancing: string; 
  attribute register_balancing of mult: entity is "yes";
  attribute mult_style: string;
  attribute mult_style of mult: entity is "pipe_block"; 
end mult;

architecture rtl of mult is  

  signal c : std_logic_vector(IWIDTHA+IWIDTHB-1 downto 0);

begin

  c <= a * b;

  reg : entity work.delay_sclr(rtl) 
    generic map ( width => IWIDTHA+IWIDTHB, delay => delay)   
    port map ( clk => clk, ce => ce, sclr => sclr, d => c, q => p);

end rtl;

-- *********************************************
--  *0006*  mac Macro
--  mac
--
-- *********************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

entity mac is            -- this module calculates p = round(a*b)+c
  generic (                 -- delay = 3
    IWIDTHA     : integer:=16;
    IWIDTHB     : integer:=16;
    OWIDTH      : integer:=16;
    ROUND_MODE  : integer:= 0; -- 0: biased, 1: towards zero, 2: towards inf
    HAS_C       : integer:= 0);
  port (
    a           : in std_logic_vector(IWIDTHA-1 downto 0);
    b           : in std_logic_vector(IWIDTHB-1 downto 0);
    c           : in std_logic_vector(OWIDTH-1 downto 0);
    p           : out std_logic_vector(OWIDTH-1 downto 0);
    clk         : in std_logic;
    ce          : in std_logic;
    sclr        : in std_logic);

  attribute register_balancing: string; 
  attribute register_balancing of mac: entity is "yes";
  attribute mult_style: string;
  attribute mult_style of mac: entity is "pipe_block"; 
  attribute use_dsp48: string; 
  attribute use_dsp48 of mac: entity is "yes"; 
  
end mac;

architecture rtl of mac is  

  signal rounding_const : std_logic_vector(IWIDTHA+IWIDTHB-1 downto 0); 
  signal rounding_carry : std_logic;
  signal r_cy_in 		: std_logic;

  signal ar    : std_logic_vector(IWIDTHA-1 downto 0) := (others => '0');
  signal br    : std_logic_vector(IWIDTHB-1 downto 0) := (others => '0');
  signal pr    : std_logic_vector(IWIDTHA+IWIDTHB-1 downto 0) := (others => '0');
  signal mac   : std_logic_vector(IWIDTHA+IWIDTHB-1 downto 0) := (others => '0');

begin

  r_cy_in <= ar(IWIDTHA-1) xor br(IWIDTHB-1);

  rnd_add : entity work.get_round_addend(rtl)  
    generic map( 
      IWIDTH      => IWIDTHA+IWIDTHB,
      OWIDTH      => OWIDTH,
      has_offset  => HAS_C,
      mode        => ROUND_MODE)
    port map(
      msb         => r_cy_in,
      offset      => c,
      r_add       => rounding_const,
      r_cy        => rounding_carry);

  clk_process: process(clk)
  begin
    if (clk'event and clk = '1') then
      if (sclr = '1') then  
        ar    <= (others => '0');
        br    <= (others => '0');
        pr    <= (others => '0');
        mac   <= (others => '0');
       elsif (ce = '1') then 
        mac <= pr + rounding_const + rounding_carry;
        pr <= ar*br;
        ar <= a;
        br <= b;
      end if;
    end if;
  end process;

  p <= mac(IWIDTHA+IWIDTHB-1 downto IWIDTHA+IWIDTHB-OWIDTH);

end;

-- *********************************************
--  *0007*  max_sat Macro
--  max_sat
--
-- *********************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

entity max_sat is 
  generic ( 
    width  : integer:= 16;
    delay   : integer:= 1 );
  port (
    a       : in std_logic_vector(width-1 downto 0);
    max     : in std_logic_vector(width-1 downto 0);
    ma      : out std_logic_vector(width-1 downto 0);
    clk     : in std_logic;
    ce      : in std_logic;
    sclr    : in std_logic);

  attribute register_balancing: string; 
  attribute register_balancing of max_sat: entity is "yes";
end max_sat;

architecture rtl of max_sat is
  signal c : std_logic_vector(width-1 downto 0);
begin
  c <=  max when (a > max) else a;
  reg : entity work.delay_sclr(rtl) 
    generic map ( width => width, delay => delay)   
    port map ( clk => clk, ce => ce, sclr => sclr, d => c, q => ma);
end rtl;

-- *********************************************
--  *0008*  min_sat Macro
--  min_sat
--
-- *********************************************
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;

entity min_sat is 
  generic ( 
    width   : integer:=16;
    delay   : integer:=1);
  port (
    a       : in std_logic_vector(width-1 downto 0);
    min     : in std_logic_vector(width-1 downto 0);
    ma      : out std_logic_vector(width-1 downto 0);
    clk     : in std_logic;
    ce      : in std_logic;
    sclr    : in std_logic );
  attribute register_balancing: string; 
  attribute register_balancing of min_sat: entity is "yes";
end min_sat;

architecture rtl of min_sat is
  signal c : std_logic_vector(width-1 downto 0);
begin
  c <=  min when (a < min) else a;
  reg : entity work.delay_sclr(rtl) 
    generic map ( width => width, delay => delay)   
    port map ( clk => clk, ce => ce, sclr => sclr, d => c, q => ma);

end rtl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -