T
Thomas Heller
I have written some code that uses a unconstrained integer
and wonder how (and why) it can be synthesized. Here is the code;
it is an SPI slave receiver which uses an unconstrained output port.
The word size is determined by the instantiation; I connect the
'data_out' signal to an std_logic_vector(11 downto 0).
The code works correctly in the target device; I have not yet
tried to simulate it.
As I said: how is the counter instantiated? Is this valid VHLD
or does it rely on some accidential features of xilinx implementation?
Would it be better to define the valid range of the integer 'bitcount'?
Thanks,
Thomas
<code>
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity spislave is
Port ( sysclock : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR;
data_strobe : out STD_LOGIC;
sclk : in STD_LOGIC;
mosi : in STD_LOGIC;
cs : in STD_LOGIC);
end spislave;
architecture Behavioral of spislave is
-- universal spi slave receiver, number of bits is determined by
instantiation.
signal sclk_pipe : std_logic_vector(1 downto 0);
signal data_sr : std_logic_vector(data_out'length-1 downto 0);
signal bitcount : integer; -- <===== ?????
begin
process(sysclock)
begin
if rising_edge(sysclock) then
sclk_pipe(0) <= sclk;
sclk_pipe(1) <= sclk_pipe(0);
if cs = '1' then
-- async reset
bitcount <= 0;
elsif sclk_pipe = "01" then
-- rising edge of SCLK detected: increment bitcount, shift data in
bitcount <= bitcount + 1;
data_sr <= data_sr(data_sr'length-2 downto 0) & mosi;
if bitcount = data_out'length-1 then
data_out <= data_sr(data_sr'length-2 downto 0) & mosi;
data_strobe <= '1';
else
data_strobe <= '0';
end if;
end if;
end if;
end process;
end Behavioral;
</code>
and wonder how (and why) it can be synthesized. Here is the code;
it is an SPI slave receiver which uses an unconstrained output port.
The word size is determined by the instantiation; I connect the
'data_out' signal to an std_logic_vector(11 downto 0).
The code works correctly in the target device; I have not yet
tried to simulate it.
As I said: how is the counter instantiated? Is this valid VHLD
or does it rely on some accidential features of xilinx implementation?
Would it be better to define the valid range of the integer 'bitcount'?
Thanks,
Thomas
<code>
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity spislave is
Port ( sysclock : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR;
data_strobe : out STD_LOGIC;
sclk : in STD_LOGIC;
mosi : in STD_LOGIC;
cs : in STD_LOGIC);
end spislave;
architecture Behavioral of spislave is
-- universal spi slave receiver, number of bits is determined by
instantiation.
signal sclk_pipe : std_logic_vector(1 downto 0);
signal data_sr : std_logic_vector(data_out'length-1 downto 0);
signal bitcount : integer; -- <===== ?????
begin
process(sysclock)
begin
if rising_edge(sysclock) then
sclk_pipe(0) <= sclk;
sclk_pipe(1) <= sclk_pipe(0);
if cs = '1' then
-- async reset
bitcount <= 0;
elsif sclk_pipe = "01" then
-- rising edge of SCLK detected: increment bitcount, shift data in
bitcount <= bitcount + 1;
data_sr <= data_sr(data_sr'length-2 downto 0) & mosi;
if bitcount = data_out'length-1 then
data_out <= data_sr(data_sr'length-2 downto 0) & mosi;
data_strobe <= '1';
else
data_strobe <= '0';
end if;
end if;
end if;
end process;
end Behavioral;
</code>