How to handle protected types

Why OSVVM™?ForumsVHDLHow to handle protected types

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

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
April 3, 2012 at 14:19 #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?

April 3, 2012 at 14:53 #157
Avatar of Jerry Kaczynski
Jerry Kaczynski

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

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.

May 5, 2013 at 08:23 #590
Avatar of Ricardo Jasinski
Ricardo Jasinski

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.

October 23, 2013 at 05:20 #726
Avatar of Raghavan

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

October 23, 2013 at 19:34 #727
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.