Martin G
Martin G

Reputation: 268

VHDL - array of std_logic_vectors convert into std_logic_vector

INTENTION:

I am reading data from RAM on ZedBoard, the RAM consists of 32 bits long words so I use the following buffer

type mem_word   is array (0 to 127) of std_logic_vector(31 downto 0);
signal buffer_word   : mem_word;

but then, I would like to address data in a linear fashion, in an intermediary linear buffer

signal buffer_linear : std_logic_vector(4095 downto 0);
buffer_linear <= buffer_word; -- !!! PROBLEM

so I can easily address any bit in the buffer without recalculating the position in specific word (of the buffer_word).

QUESTION:

How do I get from array of std_logic_vectors into 1 long std_logic_vector ? Is there a way to avoid concatenating 128 words in a loop ? (something like above buffer_linear <= buffer_word;)

Upvotes: 2

Views: 10380

Answers (1)

Paebbels
Paebbels

Reputation: 16211

You need a function to convert from vector-vector to a 1-dimensional vector.

My following example uses the type name T_SLVV_32 to denote that it is a vector of vectors, wherin the inner vector is 32 bit long. (See my linked source file, for a true 2-dimensional STD_LOGIC matrix type called T_SLM). So T_SLVV_32 is equivalen to your mem_word type.

subtype T_SLV_32  is STD_LOGIC_VECTOR(31 downto 0);
type    T_SLVV_32 is array(NATURAL range <>) of T_SLV_32;

function to_slv(slvv : T_SLVV_32) return STD_LOGIC_VECTOR is
  variable slv : STD_LOGIC_VECTOR((slvv'length * 32) - 1 downto 0);
begin
  for i in slvv'range loop
    slv((i * 32) + 31 downto (i * 32))      := slvv(i);
  end loop;
  return slv;
end function;

Usage:

buffer_linear <= to_slv(buffer_word);

This function creates no logic, just wiring.
Note: Accessing all bits of a memory at once, prevents synthesis tools of inferring RAM or ROM memory blocks!

Source: PoC.vectors

See my vector package at GitHub for more examples on transforming vectors and matrices forth and backwards.

Upvotes: 4

Related Questions