Network Wizard for VHDL Test Benches
nw_util_pkg Package Body Reference
Package >> nw_util_pkg

Functions

t_slv_arr   f_bitflip ( data: in t_slv_arr )
 Reverse bit order in each data word.
std_logic_vector   f_bitflip ( data: in std_logic_vector )
 Reverse bit order in data word.
t_slv_arr   f_concat ( data1: in t_slv_arr , data2: in t_slv_arr )
 Concatenate two arrays (of same data width)
t_slv_arr   f_repack (
data: in t_slv_arr
new_width: in natural
msb_first: in boolean
pad_after: in boolean
pad_value: in std_logic_vector
get_length: in boolean false
)
t_slv_arr   f_repack (
data: in t_slv_arr
new_width: in natural
msb_first: in boolean
pad_after: in boolean
pad_value: in std_logic_vector
)
 Repack array to new word size.
t_slv_arr   f_repack (
data: in t_slv_arr
new_width: in natural
msb_first: in boolean C_MSB_FIRST
)
natural   f_repack_len (
data: in t_slv_arr
new_width: in natural
msb_first: in boolean C_MSB_FIRST
)
 Return length of repacked array.
t_slv_arr   f_reverse ( data: in t_slv_arr )
 Reverse data array.
integer   f_search ( data: in t_slv_arr , token: in t_slv_arr )
 Find sub-array in data array.
t_slv_arr   f_stack ( data_high: in t_slv_arr , data_low: in t_slv_arr )
 Stack data words from two arrays.
t_slv_arr   f_swap_endian ( data: in t_slv_arr )
 Swap endianness of array.
std_logic_vector   f_swap_endian ( data: in std_logic_vector )
 Swap endianness of vector.
std_logic_vector   f_str_2_slv ( value: in string )
 Convert hex string to slv.
t_unsigned_arr   f_to_unsigned_arr ( data: in t_slv_arr )
 Convert slv array to unsigned array.
t_slv_arr   f_to_slv_arr ( data: in t_unsigned_arr )
 Convert unsigned array to slv array.
t_slv_arr   f_str_2_slv_arr ( str: in string )
 Convert string to slv array.
string   f_slv_arr_2_str ( data: in t_slv_arr )
 Convert slv array to string.

Procedures

  msg( constant msg_txt: in string )
 Print message in simulation log.

Member Function Documentation

◆ f_bitflip() [1/2]

t_slv_arr f_bitflip (   data in t_slv_arr  
)
Function

Reverse bit order in each data word.

Parameters
dataInput data array
Returns
Bit-flipped data array

Example use

array_8bit := (x"c1", x"67");
array_flipped := f_bitflip(array_8bit); -- array_flipped is now (x"83", x"e6")

◆ f_bitflip() [2/2]

std_logic_vector f_bitflip (   data in std_logic_vector  
)
Function

Reverse bit order in data word.

Parameters
dataInput data
Returns
Bit-flipped data

Example use

v_a := "1100001111";
v_a_flipped := f_bitflip(v_a); -- v_a_flipped is now "1111000011"

◆ f_concat()

t_slv_arr f_concat (   data1 in t_slv_arr ,
  data2 in t_slv_arr  
)
Function

Concatenate two arrays (of same data width)

Parameters
data1First data array
data2Second data array
Returns
Concatenated data array

Example use

array_8bit := (x"c1", x"67");
array2_8bit := (x"55", x"8f", x"42);
array_concat := f_concat(array_8bit, array2_8bit); -- array_concat is now (x"c1", x"67", x"55", x"8f", x"42)

◆ f_repack() [1/2]

t_slv_arr f_repack (   data in t_slv_arr ,
  new_width in natural ,
  msb_first in boolean ,
  pad_after in boolean ,
  pad_value in std_logic_vector  
)
Function

Repack array to new word size.

Parameters
dataInput data array
new_widthTarget data width
msb_firstInsert/extract most significant bits first if True, least significant bits if False
pad_afterPut padding after if True, before if False
pad_valueValue to pad with (same word size as data)
Returns
Repacked data array

Array will be repacked to wider or narrower data words. The only limit is that there must be an integer relationship between the input data word size and the new data width. This limit is circumvented by first repacking to 1bit, then to target width. When increasing the data width, padding will be added before or after as required with a user-defined pad word.

Example use

array_8bit := (x"11", x"22", x"33", x"44", x"55", x"66", x"77");
array_32bit := f_repack(array_8bit, 32, C_MSB_FIRST, C_PAD_BEFORE, x"ff"); -- array_32bit is now (x"ff112233", x"44556677")
array_32bit := f_repack(array_8bit, 32, C_LSB_FIRST, C_PAD_BEFORE, x"ff"); -- array_32bit is now (x"332211ff", x"77665544")
array_1bit := f_repack(array_8bit(0 to 0), 1, C_MSB_FIRST); -- array_1bit is now ("0", "0", "0", "1", "0", "0", "0", "1")
array_3bit := f_repack(array_1bit, 3, C_LSB_FIRST); -- array_3bit is now ("000", "001", "010")
array_7bit := f_repack(f_repack(array_8bit, 1), 7); -- array_7bit is now ("0001000", "1001000", "1000110", "0110100", "0100010", ...)

◆ f_repack() [2/2]

t_slv_arr f_repack (   data in t_slv_arr ,
  new_width in natural ,
  msb_first in boolean C_MSB_FIRST  
)
Function
Parameters
dataInput data array
new_widthTarget data width
msb_firstInsert/extract most significant bits first if True (default), least significant bits if False
Returns
Repacked data array

This is an overload of f_repack with the following parameters set:

   pad_after: True
   pad_value: (others => '0')
  

Example use

array_8bit := (x"11", x"22", x"33", x"44", x"55", x"66", x"77");
array_24bit := f_repack(array_8bit, 24, C_MSB_FIRST); -- array_24bit is now (x"112233", x"445566", x"770000")
array_24bit := f_repack(array_8bit, 24, C_LSB_FIRST); -- array_24bit is now (x"332211", x"665544", x"000077")
array_128bit := f_repack(array_8bit, 128, C_MSB_FIRST); -- array_128bit is now (x"11223344556677000000000000000000")
array_128bit := f_repack(array_8bit, 128, C_LSB_FIRST); -- array_128bit is now (x"00000000000000000077665544332211")

◆ f_repack_len()

natural f_repack_len (   data in t_slv_arr ,
  new_width in natural ,
  msb_first in boolean C_MSB_FIRST  
)
Function

Return length of repacked array.

Parameters
dataInput data array
new_widthTarget data width
Returns
Length of repacked data array

Return the length of the array when repacked to new_width.

Example use

array_8bit := (x"11", x"22", x"33", x"44", x"55", x"66", x"77");
v_len := f_repack_len(array_8bit, 2); -- v_len is now 28

◆ f_reverse()

t_slv_arr f_reverse (   data in t_slv_arr  
)
Function

Reverse data array.

Parameters
dataInput data array
Returns
Reversed data array

Example use

array_8bit := (x"c1", x"67", x"42");
array_rev := f_reverse(array_8bit); -- array_rev is now (x"42", x"67", x"c1")

◆ f_search()

integer f_search (   data in t_slv_arr ,
  token in t_slv_arr  
)
Function

Find sub-array in data array.

Parameters
dataInput data array
tokenSub-array to search for
Returns
Index of first occurence, -1 if not found

Search for a token in a data array. The token and data array must have the same data width. If the token is not found, -1 is returned.

Example use

array_8bit := (x"11", x"22", x"33", x"44", x"55", x"66", x"77");
token := (x"55", x"66");
v_res := f_search(array_8bit, token); -- v_res is now 4
token := (x"55", x"77");
v_res := f_search(array_8bit, token); -- v_res is now -1

◆ f_stack()

t_slv_arr f_stack (   data_high in t_slv_arr ,
  data_low in t_slv_arr  
)
Function

Stack data words from two arrays.

Parameters
data_highInput MSB data array
data_lowInput LSB data array
Returns
Stacked arrays

Stack two data arrays, word by word. If one array is longer than the other, it will be cropped to match the length of the shorter one.

Example use

array_8bit := (x"11", x"22", x"33", x"44", x"55", x"66", x"77");
array_4bit := (x"0", x"1", x"2", x"3");
array_12bit := f_stack(array_4bit, array_8bit); -- array_12bit is now (x"011", x"122", x"233", x"344)

◆ f_swap_endian() [1/2]

t_slv_arr f_swap_endian (   data in t_slv_arr  
)
Function

Swap endianness of array.

Parameters
dataInput data array
Returns
Byteswapped data array

This function will swap endianness of each dataword in the array. The width of the input data must be an integer factor of 8.

Example use

array_32bit := (x"11223344", x"abcdef00);
array_swapped := f_swap_endian(array_32bit); -- array_swapped is now (x"44332211", x"00efcdab")

◆ f_swap_endian() [2/2]

std_logic_vector f_swap_endian (   data in std_logic_vector  
)
Function

Swap endianness of vector.

Parameters
dataInput data vector
Returns
Byteswapped data vector

This function will swap endianness of the dataword. The width of the input data word must be an integer factor of 8.

Example use

v_32bit := x"11223344";
v_swapped := f_swap_endian(v_32bit); -- v_swapped is now x"44332211"

◆ f_str_2_slv()

std_logic_vector f_str_2_slv (   value in string  
)
Function

Convert hex string to slv.

Parameters
valueHex number in string format
Returns
Value as std_logic_vector

This function converts a hex number in string format to slv.

Example use

v_number := f_str_2_slv("a50"); -- v_number is now "101001010000"

◆ f_to_unsigned_arr()

t_unsigned_arr f_to_unsigned_arr (   data in t_slv_arr  
)
Function

Convert slv array to unsigned array.

Parameters
dataslv array
Returns
unsigned array

This function converts each word in the data array from std_logic_vector to unsigned type.

Example use

v_udata := f_to_unsigned_arr(v_data);

◆ f_to_slv_arr()

t_slv_arr f_to_slv_arr (   data in t_unsigned_arr  
)
Function

Convert unsigned array to slv array.

Parameters
dataunsigned array
Returns
slv array

This function converts each word in the data array from unsigned to std_logic_vector type.

Example use

v_data := f_to_slv_arr(v_udata);

◆ f_str_2_slv_arr()

t_slv_arr f_str_2_slv_arr (   str in string  
)
Function

Convert string to slv array.

Parameters
strString
Returns
String as slv array

This function converts a string to array of std_logic_vector(7 downto 0).

Example use

v_array(0 to 5) := f_str_2_slv_arr("NetWiz"); -- v_array is now (x"4e", x"65", x"74", x"57", x"76", x"7a")

◆ f_slv_arr_2_str()

string f_slv_arr_2_str (   data in t_slv_arr  
)
Function

Convert slv array to string.

Parameters
data8bit data array
Returns
Data as string

This function converts an 8bit slv array to string.

Example use

v_array := (x"4e", x"65", x"74", x"57", x"76", x"7a");
v_str := f_slv_arr_2_str(v_array); -- v_str is now "NetWiz"

◆ msg()

msg ( constant   msg_txt in string  
)
Procedure

Print message in simulation log.

Parameters
msgMessage to print

The input string is printed with a timestamp.

Example use

msg("Hello world");

The documentation for this class was generated from the following file: