VHDL 2008: protected type

Discussion in 'VHDL' started by magne, Feb 5, 2010.

  1. magne

    magne Guest

    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
    magne, Feb 5, 2010
    #1
    1. Advertising

  2. magne

    KJ Guest

    On Feb 5, 7:44 am, magne <> wrote:
    > 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
    KJ, Feb 5, 2010
    #2
    1. Advertising

  3. magne

    Tricky Guest

    On 5 Feb, 13:31, KJ <> wrote:
    > On Feb 5, 7:44 am, magne <> wrote:
    >
    > > 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


    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.
    Tricky, Feb 5, 2010
    #3
  4. magne

    magne Guest

    On 5 Feb, 14:31, KJ <> wrote:
    > On Feb 5, 7:44 am, magne <> wrote:
    >
    > > 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



    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.
    magne, Feb 7, 2010
    #4
  5. magne wrote:

    > 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
    Mike Treseler, Feb 7, 2010
    #5
  6. magne

    magne Guest

    On Feb 7, 9:51 pm, Mike Treseler <> wrote:
    > magne wrote:
    > > 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...
    >
    >   -- 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
    magne, Feb 8, 2010
    #6
  7. magne

    magne Guest

    On Feb 8, 10:39 am, Alan Fitch <> wrote:
    > magne wrote:
    > > On 5 Feb, 14:31, KJ <> wrote:
    > >> On Feb 5, 7:44 am, magne <> wrote:

    >
    > >>> 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

    >
    > > 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.

    >
    > 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:        
    > Fax:  +44 (0)1425 471573                http://www.doulos.com
    >
    > ------------------------------------------------------------------------
    >
    > This message may contain personal views which are not the views of
    > Doulos, unless specifically stated.


    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.
    magne, Feb 8, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    2
    Views:
    556
    Andreas Klemt
    Jul 5, 2003
  2. afd
    Replies:
    1
    Views:
    8,292
    Colin Paul Gloster
    Mar 23, 2007
  3. shapper

    Windows 2008 and SQL 2008

    shapper, Dec 8, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    340
    Mark Fitzpatrick
    Dec 8, 2007
  4. Replies:
    0
    Views:
    499
  5. Tricky
    Replies:
    1
    Views:
    832
    JimLewis
    Feb 10, 2012
Loading...

Share This Page