VHDL 2008: protected type

M

magne

Hi,

I was trying to write code for a protected type when I ran into a
issue. When testing in simulation it seems like functions of protected
types cannot update private variables of that type, but procedures
can.

Is this correct or are there some other logical explanation?


Magne
 
K

KJ

Hi,

I was trying to write code for a protected type when I ran into a
issue. When testing in simulation it seems like functions of protected
types cannot update private variables of that type, but procedures
can.

Is this correct or are there some other logical explanation?

Magne

That's correct, functions cannot update the private variables...but
impure functions can. Change your function declarations from

function xyz(...) return ...

to
impure function xyz(...) return ...

Kevin Jennings
 
T

Tricky

That's correct, functions cannot update the private variables...but
impure functions can.  Change your function declarations from

function xyz(...) return ...

to
impure function xyz(...) return ...

Kevin Jennings

This isnt just a VHDL 2008 issue or an issue with protected types. Its
functions in general updating anything not declared inside or passed
into the function. you'll get a warning if you try to write to OUTPUT
(the cmd prompt) inside a pure function.
 
M

magne

That's correct, functions cannot update the private variables...but
impure functions can.  Change your function declarations from

function xyz(...) return ...

to
impure function xyz(...) return ...

Kevin Jennings


Hi Kevin,

thanks for your answer but no, impure functions can't update the
private variables either, at least not in QuestaSim 6.5c.
I don't get any warnings or anything but the variables stays the same
when using pure or impure functions. Procedures can work the magic,
however.
 
M

Mike Treseler

magne said:
thanks for your answer but no, impure functions can't update the
private variables either, at least not in QuestaSim 6.5c.
I don't get any warnings or anything but the variables stays the same
when using pure or impure functions. Procedures can work the magic,
however.


An impure function ought to have the same scope
as a procedure declared in the same place.

See also:
http://www.synthworks.com/downloads/ConstrainedRandom_SynthWorks_2009.pdf


-- Mike Treseler
 
M

magne

An impure function ought to have the same scope
as a procedure declared in the same place.

See also:http://www.synthworks.com/downloads/ConstrainedRandom_SynthWorks_2009...

  -- Mike Treseler

Hi Mike,

Yes, that is the paper where I got the idea to put some stuff in a
protected type.
I've had a quick look at the code from synthworks, and I can't find an
impure function where the private variables are updated directly. Some
impure functions do call procedures that updates private variables,
though, so maybe that is the way to do it.

Magne
 
M

magne

I've tried an example in 6.5d and it works as expected (i.e. impure
functions can update a variable declared within the body of the
protected type).

Is it possible to post a simple example which doesn't work for you, and
I can try it in 6.5d in case there's a difference?

regards
Alan

--
Alan Fitch
Senior Consultant

Doulos – Developing Design Know-how
VHDL * Verilog * SystemVerilog * SystemC * PSL * Perl * Tcl/Tk * Project
Services

Doulos Ltd. Church Hatch, 22 Marketing Place, Ringwood, Hampshire, BH24
1AW, UK
Tel:  + 44 (0)1425 471223               Email: (e-mail address removed)        
Fax:  +44 (0)1425 471573                http://www.doulos.com

I tried to make a simple example to prove my claims, but it worked as
expected for me as well. I found out however, by experimenting with my
original code, that under some circumstances and simulation
optimizations the value in the wave window doesn't update even if the
value of the variable changes. I assumed that since I could add the
variable to the wave window it was visible, but now I know better.

So I was wrong, impure functions of protected types CAN update private
variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top