Reply To: Usage of random functions (e.g RandSlv)

Why OSVVM™? Forums OSVVM Usage of random functions (e.g RandSlv) Reply To: Usage of random functions (e.g RandSlv)

#1073

Hi Jim,

thanks for that recommendation.

Meanwhile I found another working solution too.

For using the RandomPType QuestaSim insists that the function has to be impure. I remembered from your documentations that there’s some link between protected types, shared variables and impure functions.

So I came up with this solution:

 shared variable RandomData : RandomPType;

 impure function DataGenerator(DataWidth : natural) return std_logic_vector is
  begin
    -- check seed for initial value (from RandomBasePkg Random Seed declaration)
    if RandomData.GetSeed = RandomSeedType(integer_vector'(1,7)) then
      RandomData.InitSeed(RandomData'instance_name);
      report "Info: Seed generated for DataGenerator:RandomData";
    end if;
    return RandomData.RandSlv(0, 2**Datawidth-1, DataWidth);
  end function;

And calling the Function like this works just fine:

   for i in 0 to 99 loop
      wait until falling_edge(clock); -- just creating some delay
      DataIn <= DataGenerator(DataIn'length);
      wait until rising_edge(clock);
    end loop;

I think it would work with a procedure as well. (hopefully)

The good thing is that I do not have to double declare the RandomPType outside and inside the function and do not have to transfer the actual values. Instead I just have a constant in the function argument list.

Thanks for reminding me about the Random Package UG.

I saw it was there, but just read the OSVVM UG and the Protected types paper. Somehow I couldn’t resist to try it out immediately. 🙂

Kind regards

  Eilert