VHDL 2008: protected type

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

  1. magne

    magne Guest


    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

    Is this correct or are there some other logical explanation?

    magne, Feb 5, 2010
    1. Advertisements

  2. magne

    KJ Guest

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

    function xyz(...) return ...

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

    Kevin Jennings
    KJ, Feb 5, 2010
    1. Advertisements

  3. magne

    Tricky Guest

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

    magne Guest

    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,
    magne, Feb 7, 2010

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

    See also:

    -- Mike Treseler
    Mike Treseler, Feb 7, 2010
  6. magne

    magne Guest

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

    magne Guest

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

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 (here). After that, you can post your question and our members will help you out.