How to handle protected types

Why OSVVM™? Forums VHDL How to handle protected types

This topic contains 4 replies, has 5 voices, and was last updated by Avatar of Andy Jones Andy Jones 5 years, 7 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #155
    Avatar of Jerry Drake
    Jerry Drake

    I see that OS-VVM is using protected types internally at the quite advanced level. I have done my share of coding in VHDL but am not very familiar with this type of construct. Any suggestions how to improve my understanding?


    It is a very good question. Protected types are rudimentary implementation of object oriented programming. They combine data items (properties) with subprograms (methods) that operate on them into one easy to operate object. The key issue here is to protect end users from the cumbersome implementation details that may change as the design develops and give them easy, consistent method of manipulating data. Public part of protected type is called protected type declaration and shows what can be done using this type:

      type FLAG_TYPE is protected        -- protected type declaration
         procedure Set;

         procedure Reset;
         impure function Active   return Boolean;
      end protected FLAG_TYPE;

    Actual properties and implementation of methods are present in protected type body:

      type FLAG_TYPE is protected body   -- protected type body
        variable flag : Boolean;        -- local variable declaration

        procedure Set is                -- procedure definition
          begin  flag := True;  end procedure Set;

        procedure Reset is              -- procedure definition
          begin  flag := False;  end procedure Reset;

        impure function Active return Boolean is   -- function definition
          begin  return flag;  end function Active
      end protected
    body FLAG_TYPE;

    Once both parts of the protected type are declared (and stored in a convenient location such as package) you can declare regular or shared variable of this type:

      shared variable my_flag : flag_type;

    Once declared, (shared) variable can be used in your processes like this:

      if then . . .

    So, you are using variable name + dot + method name to perform operations on internal data items.

    You can read more in the “Using Protected Types in VHDL Designs” paper in our Downloads section.


    Maybe it’s a stupid question, but how far are we from being able to use protected types with signals instead of shared variables only? Do you know of any plans to add it to VHDL anytime soon? It feels like that would allow for much cleaner code in many situations.

    Avatar of Raghavan

    Is there any way of using wait statements inside protected body?

    Avatar of Andy Jones
    Andy Jones

    Unfortunately, protected type method calls cannot span time (e.g. wait) because they are mutually exclusive. Multiple calls to the same variable’s same method execute one at a time from start to finish. This would require some sort of implicit wait (across time) in one call while another call finished. While possible, the effects of this are not well understood, and therefore not (yet) allowed.


Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.