Esempio n. 1
0
File: vhpi3.c Progetto: gr8linux/nvc
static void start_of_sim(const vhpiCbDataT *cb_data)
{
   vhpi_printf("start_of_sim");

   fail_unless(phys_to_i64(vhpiFS) == 1ll);
   fail_unless(phys_to_i64(vhpiPS) == 1000ll);
   fail_unless(phys_to_i64(vhpiNS) == 1000000ll);
   fail_unless(phys_to_i64(vhpiUS) == 1000000000ll);
   fail_unless(phys_to_i64(vhpiMS) == 1000000000000ll);
   fail_unless(phys_to_i64(vhpiS) == 1000000000000000ll);
   fail_unless(phys_to_i64(vhpiMN) == 1000000000000000ll * 60);
   fail_unless(phys_to_i64(vhpiHR) == 1000000000000000ll * 60 * 60);

   vhpiPhysT res_limit = vhpi_get_phys(vhpiResolutionLimitP, NULL);
   check_error();
   fail_unless(phys_to_i64(res_limit) == phys_to_i64(vhpiFS));

   vhpiHandleT root = vhpi_handle(vhpiRootInst, NULL);
   check_error();
   fail_if(root == NULL);

   vhpiHandleT handle_x = vhpi_handle_by_name("x", root);
   check_error();
   fail_if(handle_x == NULL);
   vhpi_printf("x handle %p", handle_x);

   vhpiPhysT x_val = vhpi_get_phys(vhpiPhysValP, handle_x);
   check_error();
   fail_unless(phys_to_i64(x_val) == 2);

   vhpiHandleT handle_weight_type = vhpi_handle(vhpiType, handle_x);
   check_error();
   fail_if(handle_weight_type == NULL);

   vhpiHandleT handle_weight_cons =
      vhpi_handle_by_index(vhpiConstraints, handle_weight_type, 0);
   check_error();
   fail_if(handle_weight_cons == NULL);

   vhpiPhysT weight_left = vhpi_get_phys(vhpiPhysLeftBoundP,
                                         handle_weight_cons);
   check_error();
   fail_unless(phys_to_i64(weight_left) == -100);

   vhpiPhysT weight_right = vhpi_get_phys(vhpiPhysRightBoundP,
                                          handle_weight_cons);
   check_error();
   fail_unless(phys_to_i64(weight_right) == 4000);

   vhpi_release_handle(handle_weight_cons);
   vhpi_release_handle(handle_weight_type);
   vhpi_release_handle(handle_x);
   vhpi_release_handle(root);
}
Esempio n. 2
0
// this function adjusts clock delays and checks if they are valid
void adjustClock( signed int _nUnit, unsigned int _nPeriod, double _rDuty, vhpiTimeT* _tHighDelay, vhpiTimeT* _tLowDelay )
{
	vhpiPhysT tTimeUnit;								  
	// get simulation time unit
	tTimeUnit = vhpi_get_phys( vhpiSimTimeUnitP, NULL );
	// check if integer value corresponding to unit is correct
	if ( ( _nUnit != -15 ) && ( _nUnit != -12 ) && ( _nUnit != -9 ) && ( _nUnit != -6 ) && ( _nUnit != -3 ) && ( _nUnit != 0 ) )
	{										   
		// if not, set to ns and report problem
		vhpi_printf( "adjustClock(): Selected clock unit is illegal. Setting unit to ns.\n" );
		_nUnit = -9;
	}
									 
	// check if real value corresponding to duty cycle is correct
	if ( ( _rDuty < 0.01 ) || ( _rDuty > 0.99 ) )
	{															 
		// if not, set to 0.50 and report problem
		vhpi_printf( "Selected clock duty cycle is out of legal range. Setting duty cycle to 50%.\n" );
		_rDuty = 0.50;
	}
	
	// express clock period in simulation units
	double rPeriod = _nPeriod * pow( 10, abs( tTimeUnit.low ) + _nUnit ); // clock period in simulation units
	unsigned int nLowTime = (unsigned int)( rPeriod * ( 1 - _rDuty ) ); // clock low state duration in simulation units
	unsigned int nHighTime = (unsigned int)( rPeriod * _rDuty ); // clock high state duration in simulation units
										 
	// check if period to simulation unit ratio is greater or equal than 100
	if ( rPeriod < 100 )
	{
		vhpi_assert( (vhpiSeverityT)vhpiFailure, "Selected clock period requires greater simulation resolution.");
		vhpi_sim_control( vhpiFinish );
	}																  
	
	_tHighDelay->low = nHighTime;
	_tLowDelay->low = nLowTime;
}