A
alb
Hi everyone,
I'm trying to define my own set of types in order to have a more
readable code and try to represent my data structures at a higher level.
This code is used for testbench only and I'm using it to define my
packets to be transmitted on my serial link.
Eventually somewhere there is a procedure handling these data types and
'sending' a std_logic signal to a DUT.
<code>
constant WORD_LENGTH : natural := 16;
constant MAX_BUF_LEN : natural := 1024;
-- data word over the link interface are 16 bit wide.
subtype data_word_t is bit_vector (WORD_LENGTH - 1 downto 0);
type buff_t is array (0 to MAX_BUF_LEN - 1) of data_word_t;
type data_buffer_t is record
len : natural; -- length of the data
buf : buff_t; -- data buffer
end record;
</code>
the intent of this gymnastic is to deal with bits and non negative
integers for packet lengths, but I'm facing lots of troubles when I
start to manipulate these datatypes because of conversion.
Since the header of my packets include the length I thought that simply
doing:
<code>
variable data_buffer : data_buffer_t;
variable data_word : data_word_t;
data_word := some_conversion_function(data_buffer.len);
</code>
would have been enough, but it seems to me I'm too stupid to find the
right combination of conversions.
Moreover I start to think that maybe my original choice of types is not
optimal and some people around here can direct me to a better choice of
types.
Should I build a set of functions that allow me to manipulate these types?
Any suggestion is welcome.
Al
I'm trying to define my own set of types in order to have a more
readable code and try to represent my data structures at a higher level.
This code is used for testbench only and I'm using it to define my
packets to be transmitted on my serial link.
Eventually somewhere there is a procedure handling these data types and
'sending' a std_logic signal to a DUT.
<code>
constant WORD_LENGTH : natural := 16;
constant MAX_BUF_LEN : natural := 1024;
-- data word over the link interface are 16 bit wide.
subtype data_word_t is bit_vector (WORD_LENGTH - 1 downto 0);
type buff_t is array (0 to MAX_BUF_LEN - 1) of data_word_t;
type data_buffer_t is record
len : natural; -- length of the data
buf : buff_t; -- data buffer
end record;
</code>
the intent of this gymnastic is to deal with bits and non negative
integers for packet lengths, but I'm facing lots of troubles when I
start to manipulate these datatypes because of conversion.
Since the header of my packets include the length I thought that simply
doing:
<code>
variable data_buffer : data_buffer_t;
variable data_word : data_word_t;
data_word := some_conversion_function(data_buffer.len);
</code>
would have been enough, but it seems to me I'm too stupid to find the
right combination of conversions.
Moreover I start to think that maybe my original choice of types is not
optimal and some people around here can direct me to a better choice of
types.
Should I build a set of functions that allow me to manipulate these types?
Any suggestion is welcome.
Al