library IEEE;
use IEEE.Std_Logic_1164.all;
use IEEE.Numeric_Std.all;
use WORK.MokuSupport.all;

entity Test{{top_entity}} is
    generic (
        NUM_AIN : integer;
        NUM_AOUT : integer;
        NUM_CBUFS : integer
        -- add custom generics here
    );
end entity;

architecture Behavioural of Test{{top_entity}} is
    signal Clk, Reset, Sync : std_logic;

    -- These are to make AIn/AOuts accessible from cocotb
{% for idx in range(num_ain) %}
    signal AIn{{idx}} : signed(63 downto 0);
    signal AIn{{idx}}Valid : std_logic;
{% endfor %}

{% for idx in range(num_aout) %}
    signal AOut{{idx}} : signed(63 downto 0);
    signal AOut{{idx}}Valid : std_logic;
{% endfor %}

    signal AIn : AInChannelArray(0 to NUM_AIN - 1);
    signal AOut : AInChannelArray(0 to NUM_AOUT - 1);

    signal SPI_MISO, SPI_MOSI, SPI_SClk, SPI_CS : std_logic;
begin
{% for idx in range(num_ain) %}
    AIn({{idx}}) <= (Data => AIn{{idx}}, Valid => AIn{{idx}}Valid);
{% endfor %}

{% for idx in range(num_aout) %}
    AOut{{idx}} <= AOut({{idx}}).Data;
    AOut{{idx}}Valid <= AOut({{idx}}).Valid;
{% endfor %}

    DUT: entity WORK.{{top_entity}}
        generic map (
            NUM_AIN => NUM_AIN,
            NUM_AOUT => NUM_AOUT,
            NUM_CBUFS => NUM_CBUFS
            -- add custom generics here
        )
        port map (
            Clk => Clk,
            Reset => Reset,
            Sync => Sync,

            AIn => AIn,
            AOut => AOut,
            BufData => open,

            SPI_MISO => SPI_MISO,
            SPI_MOSI => SPI_MOSI,
            SPI_SClk => SPI_SClk,
            SPI_CS => SPI_CS
        );
end architecture;
