type conversion of a custom enumeration type

OP #2401671
Rate this post
• ▲ useful
▼ not useful
Hi,

I defined an enumeration type ("reg") in a package header:
1
LIBRARY ieee;
2
USE ieee.std_logic_1164.all;
3
USE ieee.std_logic_arith.all;
4
...
...
1
type reg is (R0, R1, R2, R3);
...and a conversion function which converts type "std_logic_vector" to 
my type "reg":
1
function CONVTOREG (DATA :std_logic_vector) return reg;

In the body of the package I have the corresponding implementation of 
this conversion function:
1
  function CONVTOREG (DATA :std_logic_vector) return reg IS
2
    variable result :integer; 
3
      begin 
4
       result := CONV_INTEGER(unsigned(DATA));
5
      return reg'VAL(result);
6
  end function;

This works fine. Now I need another conversion function which converts 
the type "reg" back to std_logic_vector" which is declared like this:
1
function CONV_REG_TO_STDLV (DATA :reg) return std_logic_vector;

But I don't know how to implement that since there is no type conversion 
which accepts my enumeration type. Has anybody an idea how to do that?

Thanks a lot!

Best regards.

M.R.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.