quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif randomize()

In last page we saw basic usage of randomize() method. randomize() method in Vera has following extension.

   

space.gif

  • constraint_mode()
  • rand_mode()
  • randomize() with
  • pre_randomize()
  • post_randomize()
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif constraint_mode()

Vera provides the predefined constraint_mode() method to control whether a constraint is active or inactive. All constraints are initially active.

   

space.gif

Syntax

   

space.gif

function integer object_name.constraint_mode
(ON | OFF | REPORT [, string constraint_name]);
   

space.gif

Where

   

space.gif

  • object_name Is the name of the object in which the constraint block is defined.
  • ON Sets the specified constraint block to active so that it is enforced on subsequent calls to the randomize() method.
  • OFF Sets the specified constraint block to inactive so that it is not enforced on subsequent calls to the randomize() method.
  • REPORT Returns the current ON/OFF value for the specified variable.
  • constraint_name Is the name of the constraint block to be made active or inactive. It can be the name of any constraint block in the class hierarchy. If it is not specified, the switch is applied to all constraints within the specified object. The constraint name must be specified for a REPORT.
   

space.gif

constraint_mode methode is really usefull when we want to randomize a class which is coded for different configs. Below example shows we can use constraint mode.

   

space.gif

  ../images/main/4blue_dots_bullets.gif Example : constraint_mode()
   

space.gif


  1 enum pkt_type {UNICAST=11,MULTICAST,BROADCAST};
  2 
  3 class frame_t {
  4   rand pkt_type type;
  5   rand integer len;
  6   rand reg  [7:0] payload [];
  7   constraint common {
  8     payload.size() == len;
  9   }
 10   // Constraint the members
 11   constraint unicast {
 12     len <= 2;
 13     type == UNICAST;
 14   }
 15   // Constraint the members
 16   constraint multicast {
 17     len >= 3;
 18     len <= 4;
 19     type == MULTICAST;
 20   }
 21   // Print the members of the class
 22   task print() {
 23     integer i =0;
 24     printf("Packet type %s\n",type);
 25     printf("Size of frame is %0d\n",len);
 26     printf("Payload is ");
 27     for (i=0; i < len; i++) {
 28       printf(" %2x",payload[i]);
 29     }
 30     printf("\n");
 31   }  
 32 }
 33 
 34 program rand_ex {
 35    frame_t frame = new();
 36    integer j = 0;
 37    printf("-------------------------------\n");
 38    // Do contraint for Unicast frame
 39    if ( frame.constraint_mode(OFF,"multicast") == OFF) {
 40      if (frame.randomize() == OK) {
 41        frame.print(); 
 42      } else {
 43        printf("Failed to randomize frame\n");
 44      }
 45    } else {
 46       printf("Failed to disable constraint multicast\n");
 47    }
 48    printf("-------------------------------\n");
 49    // Check the status of constraint multicast
 50    printf ("Constraint state of multicast is %0d\n",
 51        frame.constraint_mode(REPORT,"multicast"));
 52    printf("-------------------------------\n");
 53    // Now disable the unitcast and enable multicast
 54    j = frame.constraint_mode(OFF,"unicast");
 55    j = frame.constraint_mode(ON,"multicast");
 56    if (frame.randomize() == OK) {
 57      frame.print(); 
 58    } else {
 59      printf("Failed to randomize frame\n");
 60    }
 61    printf("-------------------------------\n");
 62 }
You could download file constraint_mode_ex.vr here
   

space.gif

  ../images/main/4blue_dots_bullets.gif Simulation Output : constraint_mode()
   

space.gif

 -------------------------------
 Packet type UNICAST
 Size of frame is 1
 Payload is  7d
 -------------------------------
 Constraint state of multicast is 0
 -------------------------------
 Packet type MULTICAST
 Size of frame is 3
 Payload is  df 40 f7
 -------------------------------
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com