Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > function declaration help

Reply
Thread Tools

function declaration help

 
 
Greg Dunn
Guest
Posts: n/a
 
      07-23-2003
I'm trying to create a function that will convert state_value types (see
below) to std_logic_vectors so i can monitor state transitions, but I keep
getting the following error:

ERROR ... LINE 35 The type of the operand of type conversion must be
determinable independent of the context

Here's a stripped version of my broken code:
----------------------------------------------------------------------------
-------------
architecture state_machine of logic_unit is
type state_value is (S0_WAIT_FOR_ACQ, S1_INIT, S2_WAIT_VE,
S3_RD_RAM, S4_WAIT, S5_WR_RAM, S6_CLR_VE);

function stateToVec (st : state_value)
return std_logic_vector(3 downto 0) is -- LINE 35
begin
return "0000";
end stateToVec;
begin
....
----------------------------------------------------------------------------
-------------

If I change the return type to std_logic, it works just fine, but isn't of
much use to me. Can anyone tell me what I'm doing wrong or a better way to
do this?

Thanks,
Greg


 
Reply With Quote
 
 
 
 
MK
Guest
Posts: n/a
 
      07-24-2003
You need declare subtype first:

subtype std_logic_vector4 is std_logic_vector(3 downto 0);
function stateToVec (st : state_value) return std_logic_vector4 is
begin
return "0000";
end stateToVec;

or return simply std_logic_vector without constraint:

function stateToVec (st : state_value) return std_logic_vector is
begin
return "0000";
end stateToVec;


regards,
MK.

"Greg Dunn" <(E-Mail Removed)> wrote in message
news:MWETa.644$(E-Mail Removed) y.com...
> I'm trying to create a function that will convert state_value types (see
> below) to std_logic_vectors so i can monitor state transitions, but I keep
> getting the following error:
>
> ERROR ... LINE 35 The type of the operand of type conversion must be
> determinable independent of the context
>
> Here's a stripped version of my broken code:
> --------------------------------------------------------------------------

--
> -------------
> architecture state_machine of logic_unit is
> type state_value is (S0_WAIT_FOR_ACQ, S1_INIT, S2_WAIT_VE,
> S3_RD_RAM, S4_WAIT, S5_WR_RAM,

S6_CLR_VE);
>
> function stateToVec (st : state_value)
> return std_logic_vector(3 downto 0) is -- LINE 35
> begin
> return "0000";
> end stateToVec;
> begin
> ...
> --------------------------------------------------------------------------

--
> -------------
>
> If I change the return type to std_logic, it works just fine, but isn't of
> much use to me. Can anyone tell me what I'm doing wrong or a better way

to
> do this?
>
> Thanks,
> Greg
>
>



 
Reply With Quote
 
 
 
 
William Wallace
Guest
Posts: n/a
 
      08-17-2003
If the sub-type suggestion doesn't help, try a variable.

....
function stateToVec (st : state_value) return std_logic_vector(3 downto 0) is
variable result : std_logic_vector(3 downto 0);
begin
case st is
when others =>
result := X"0"; -- requires 1993, or use result := "0000";
end case;
return result;
....

"Greg Dunn" <(E-Mail Removed)> wrote in message news:<MWETa.644$(E-Mail Removed) gy.com>...
> I'm trying to create a function that will convert state_value types (see
> below) to std_logic_vectors so i can monitor state transitions, but I keep
> getting the following error:
>
> ERROR ... LINE 35 The type of the operand of type conversion must be
> determinable independent of the context
>
> Here's a stripped version of my broken code:
> ----------------------------------------------------------------------------
> -------------
> architecture state_machine of logic_unit is
> type state_value is (S0_WAIT_FOR_ACQ, S1_INIT, S2_WAIT_VE,
> S3_RD_RAM, S4_WAIT, S5_WR_RAM, S6_CLR_VE);
>
> function stateToVec (st : state_value)
> return std_logic_vector(3 downto 0) is -- LINE 35
> begin
> return "0000";
> end stateToVec;
> begin
> ...
> ----------------------------------------------------------------------------
> -------------
>
> If I change the return type to std_logic, it works just fine, but isn't of
> much use to me. Can anyone tell me what I'm doing wrong or a better way to
> do this?
>
> Thanks,
> Greg

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
type declaration in declaration of a parameter or return type of a function Luca Forlizzi C Programming 4 11-14-2010 09:30 PM
Can a static function declaration conflict with a non-static declaration? nospam_timur@tabi.org C Programming 4 12-12-2006 10:26 PM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 02:34 PM
Variable declaration taken as a function pointer declaration Bolin C++ 4 12-02-2005 05:28 PM
Function declaration in class declaration Ovidesvideo C++ 4 12-10-2004 06:36 PM



Advertisments