// this function gets index of user variables structure pointer in objects table int getUserId( TValObjPtrs* _pValObjs ) { int i = -1; while ( _pValObjs[++i].hHdl != NULL ); if ( _pValObjs[i].pUserVars != NULL ) return i; else { return -1; vhpi_assert( (vhpiSeverityT)vhpiFailure, "getUserId(): Pointer to user variables structure not found"); } }
// this function gets index of object in objects table for given object handle int getId( vhpiHandleT _hHdl, TValObjPtrs* _pValObjs ) { int i = -1; while ( _pValObjs[++i].hHdl ) if ( vhpi_compare_handles( _pValObjs[i].hHdl, _hHdl ) == 1 ) { return i; break; } vhpi_printf( "getId(): i = %d, Object Handle: %d \n", i, _hHdl ); vhpi_assert( (vhpiSeverityT)vhpiFailure, "getId(): Object not found"); return -1; }
// this function gets index of object in objects table for given object name int getId( char* _szName, TValObjPtrs* _pValObjs ) { int i = -1; // search structures table for object name while ( _pValObjs[++i].szName ) { if ( stricmp( _szName, _pValObjs[i].szName ) == 0 ) { return i; break; } } vhpi_printf( "getId(): i = %d, Object Name: %s \n", i, _szName ); vhpi_assert( (vhpiSeverityT)vhpiFailure, "getId(): Object not found"); return -1; }
// 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; }
static void check_error(void) { vhpiErrorInfoT info; if (vhpi_check_error(&info)) vhpi_assert(vhpiFailure, "unexpected error '%s'", info.message); }