Claude
Skills
Sign in
Back

vhdl-language

Included with Lifetime
$97 forever

Deep expertise in VHDL language constructs, IEEE 1076 standard compliance, and synthesis coding guidelines. Expert skill for generating synthesizable VHDL code.

General

What this skill does


# VHDL Language Skill

Expert skill for VHDL (VHSIC Hardware Description Language) development following IEEE 1076 standards. Provides deep expertise in synthesizable VHDL code generation, coding guidelines, and best practices for FPGA design.

## Overview

The VHDL Language skill enables comprehensive VHDL development for FPGA and ASIC designs, supporting:
- IEEE 1076-2019 standard compliance
- Synthesizable code generation
- Entity, architecture, package, and component declarations
- Synchronous process design with proper reset handling
- Vendor-specific synthesis attributes
- Testbench generation with assert statements
- Detection and fix of common coding anti-patterns

## Capabilities

### 1. Entity and Architecture Definition

Generate proper entity and architecture structures:

```vhdl
-- Example: Parameterized FIFO Entity
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity sync_fifo is
  generic (
    DATA_WIDTH : positive := 8;
    DEPTH      : positive := 16;
    ALMOST_FULL_THRESHOLD  : natural := 14;
    ALMOST_EMPTY_THRESHOLD : natural := 2
  );
  port (
    clk           : in  std_logic;
    rst_n         : in  std_logic;
    -- Write interface
    wr_en         : in  std_logic;
    wr_data       : in  std_logic_vector(DATA_WIDTH-1 downto 0);
    full          : out std_logic;
    almost_full   : out std_logic;
    -- Read interface
    rd_en         : in  std_logic;
    rd_data       : out std_logic_vector(DATA_WIDTH-1 downto 0);
    empty         : out std_logic;
    almost_empty  : out std_logic;
    -- Status
    fill_level    : out unsigned(clog2(DEPTH) downto 0)
  );
end entity sync_fifo;

architecture rtl of sync_fifo is
  -- Type declarations
  type ram_type is array (0 to DEPTH-1) of std_logic_vector(DATA_WIDTH-1 downto 0);

  -- Signal declarations
  signal ram       : ram_type := (others => (others => '0'));
  signal wr_ptr    : unsigned(clog2(DEPTH)-1 downto 0) := (others => '0');
  signal rd_ptr    : unsigned(clog2(DEPTH)-1 downto 0) := (others => '0');
  signal count     : unsigned(clog2(DEPTH) downto 0) := (others => '0');

  -- Function for ceiling log2
  function clog2(n : positive) return natural is
    variable result : natural := 0;
    variable value  : natural := n - 1;
  begin
    while value > 0 loop
      result := result + 1;
      value := value / 2;
    end loop;
    return result;
  end function clog2;

begin
  -- Architecture implementation
end architecture rtl;
```

### 2. Synchronous Process Design

Implement synchronous processes with proper reset handling:

```vhdl
-- Synchronous process with asynchronous reset
process(clk, rst_n)
begin
  if rst_n = '0' then
    -- Asynchronous reset - initialize all registers
    wr_ptr <= (others => '0');
    rd_ptr <= (others => '0');
    count  <= (others => '0');
  elsif rising_edge(clk) then
    -- Synchronous logic
    if wr_en = '1' and full_i = '0' then
      ram(to_integer(wr_ptr)) <= wr_data;
      wr_ptr <= wr_ptr + 1;
    end if;

    if rd_en = '1' and empty_i = '0' then
      rd_ptr <= rd_ptr + 1;
    end if;

    -- Update count
    if (wr_en = '1' and full_i = '0') and not (rd_en = '1' and empty_i = '0') then
      count <= count + 1;
    elsif not (wr_en = '1' and full_i = '0') and (rd_en = '1' and empty_i = '0') then
      count <= count - 1;
    end if;
  end if;
end process;

-- Synchronous process with synchronous reset
process(clk)
begin
  if rising_edge(clk) then
    if sync_rst = '1' then
      -- Synchronous reset
      state <= IDLE;
      counter <= (others => '0');
    else
      -- Normal operation
      state <= next_state;
      counter <= counter + 1;
    end if;
  end if;
end process;
```

### 3. Package and Component Declarations

Create reusable packages and components:

```vhdl
-- Package declaration
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

package fpga_utils_pkg is
  -- Constants
  constant CLK_FREQ_HZ : natural := 100_000_000;

  -- Type definitions
  type axi_lite_master_t is record
    awaddr  : std_logic_vector(31 downto 0);
    awvalid : std_logic;
    wdata   : std_logic_vector(31 downto 0);
    wstrb   : std_logic_vector(3 downto 0);
    wvalid  : std_logic;
    bready  : std_logic;
    araddr  : std_logic_vector(31 downto 0);
    arvalid : std_logic;
    rready  : std_logic;
  end record axi_lite_master_t;

  constant AXI_LITE_MASTER_INIT : axi_lite_master_t := (
    awaddr  => (others => '0'),
    awvalid => '0',
    wdata   => (others => '0'),
    wstrb   => (others => '0'),
    wvalid  => '0',
    bready  => '0',
    araddr  => (others => '0'),
    arvalid => '0',
    rready  => '0'
  );

  -- Function declarations
  function clog2(n : positive) return natural;
  function max(a, b : integer) return integer;
  function min(a, b : integer) return integer;

  -- Component declarations
  component sync_fifo is
    generic (
      DATA_WIDTH : positive := 8;
      DEPTH      : positive := 16
    );
    port (
      clk     : in  std_logic;
      rst_n   : in  std_logic;
      wr_en   : in  std_logic;
      wr_data : in  std_logic_vector(DATA_WIDTH-1 downto 0);
      full    : out std_logic;
      rd_en   : in  std_logic;
      rd_data : out std_logic_vector(DATA_WIDTH-1 downto 0);
      empty   : out std_logic
    );
  end component sync_fifo;

end package fpga_utils_pkg;

-- Package body
package body fpga_utils_pkg is

  function clog2(n : positive) return natural is
    variable result : natural := 0;
    variable value  : natural := n - 1;
  begin
    while value > 0 loop
      result := result + 1;
      value := value / 2;
    end loop;
    return result;
  end function clog2;

  function max(a, b : integer) return integer is
  begin
    if a > b then return a; else return b; end if;
  end function max;

  function min(a, b : integer) return integer is
  begin
    if a < b then return a; else return b; end if;
  end function min;

end package body fpga_utils_pkg;
```

### 4. Vendor-Specific Synthesis Attributes

Apply synthesis directives for Xilinx and Intel:

```vhdl
-- Xilinx synthesis attributes
architecture rtl of my_design is
  -- ASYNC_REG for synchronizers
  signal sync_reg : std_logic_vector(1 downto 0);
  attribute ASYNC_REG : string;
  attribute ASYNC_REG of sync_reg : signal is "TRUE";

  -- Keep hierarchy for debugging
  attribute KEEP_HIERARCHY : string;
  attribute KEEP_HIERARCHY of rtl : architecture is "YES";

  -- RAM style control
  signal block_ram : ram_type;
  attribute RAM_STYLE : string;
  attribute RAM_STYLE of block_ram : signal is "block";

  signal dist_ram : small_ram_type;
  attribute RAM_STYLE of dist_ram : signal is "distributed";

  -- Register duplication for fanout
  signal high_fanout_reg : std_logic;
  attribute MAX_FANOUT : integer;
  attribute MAX_FANOUT of high_fanout_reg : signal is 50;

  -- FSM encoding
  type state_type is (IDLE, RUNNING, DONE);
  signal state : state_type;
  attribute FSM_ENCODING : string;
  attribute FSM_ENCODING of state : signal is "one_hot";

begin
  -- Implementation
end architecture rtl;

-- Intel/Altera synthesis attributes
architecture rtl of my_design is
  -- RAM inference control
  signal ram : ram_type;
  attribute ramstyle : string;
  attribute ramstyle of ram : signal is "M20K";

  -- Preserve signal
  signal debug_sig : std_logic;
  attribute preserve : boolean;
  attribute preserve of debug_sig : signal is true;

begin
  -- Implementation
end architecture rtl;
```

### 5. Numeric_std Best Practices

Use numeric_std library correctly (avoid std_logic_arith):

```vhdl
-- CORRECT: Using numeric_std
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;  -- Preferred library

architecture rtl of example is
  signal counter : unsigned(7 downto 0);
  signal signed_val : signed(15 downto 0);
begin
  -- Arithmetic with unsigned
  counter <= counter + 1;
  counter <= counter + to_unsigned(10, counter'length);

  -- Conversion from std_logic_vector
  counter <= unsigned(input_slv);

  -

Related in General