Can you explain this:
slv4'(s_norm(i*4 to i*4+3))
I never saw this kind of value assignment using ' (for attributes) and
don't know what to ask google. Please if you could provide a useful
link or just explain
I would like to learn.
In this case, the ' does not indicate an attribute, instead it is used
to state that the thing to the right of the ' (in this case "(s_norm
(i*4 to i*4+3))") is of the type specified by what is to the left of
the ' (in this case "slv4"). The reason you need to tell it this is
because the data type of "(s_norm(i*4 to i*4+3))" is ambiguous. In
this situation the ' is called a 'type qualifier'.
A simpler example of the need for a type qualifier is something like
"0101". Should this be interpreted as a std_logic_vector, a
bit_vector, a string? Without any context, it is impossible to tell.
In many situations, the compiler can figure it out based on what
"0101" is being assigned to, in other cases it can't. In those
situations where the compiler complains about the type being
ambiguous, you have to explicitly tell it what the type is so if
"0101" is meant to be treated as a string then you would say
string'("0101")
As an aside, you'll probably find the conversion of data types to
strings will find many uses, in testbenches as well as design code. I
would suggest that you first create a function along the lines of what
Jonathon suggested but instead of working with std_logic_vector, have
it work with an input string. I'd also get rid of the limitation that
requires the input string to have only a multiple of 4 (don't assert
with a failure, just pad the left with the appropriate number of
zeros). So your basic function with all the gory code fits the
following form
function HexImage(L: string) return string;
Now you can build on this by creating heximage functions that work
with all the vector types quite easily, without having to rewrite
anything, instead you'll be building on this one basic function (see
code below).
Those functions presuppose that there is a function called 'image'
that can translate a particular data type (for example
'std_logic_vector') into a string of ones and zeros. You'll have to
write those functions too, but they are pretty simple (see example
below for 'bit' and 'bit_vector').
By building up a set of functions in this way you can pretty quickly
get yourself a full library of functions that convert from all of the
basic data types (including vectors) into strings. The most effective
way to do this is to have your base function (the one that has the
nitty, gritty code with the case, if, etc.) work with strings rather
than std_logic_vector.
In fact, you can see the value of using strings as function I/O right
in the use of the other conversion functions themselves that I've
shown because to build up the bigger functions, I rely on using other
lower level functions. By normalizing on strings for function I/O for
the lowest level conversion function, it simplifies things quite a
bit.
Kevin Jennings
-- Start of heximage functions
function HexImage(L: bit_vector) return String is
begin
return(HexImage(image(L)));
end function HexImage;
function HexImage(L: std_ulogic_vector) return String is
begin
return(HexImage(image(to_x01(L))));
end function HexImage;
function HexImage(L: std_logic_vector) return String is
begin
return(HexImage(image(to_x01(L))));
end function HexImage;
function HexImage(L: signed) return String is
begin
return(HexImage(image(L)));
end function HexImage;
function HexImage(L: unsigned) return String is
begin
return(HexImage(image(L)));
end function HexImage;
-- End of heximage functions
-- Start of an example image function
function image(L: bit) return String is
constant bit_image: String := bit'image(L);
begin
return(bit_image(2 to 2));
end function image;
function image(L: bit_vector) return String is
variable Lx: bit_vector(1 to L'length);
variable RetVal: String(1 to L'length);
begin
Lx := L;
for i in Lx'range loop
RetVal(i to i) := image(Lx(i));
end loop;
return(RetVal);
end function image;
-- End of an example image function
Kevin Jennings