Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


mti_GetPhysicalData()

Gets the unit information of a physical type.

Syntax

phys_data = mti_GetPhysicalData( type_id ) 

Returns

Name
Type
Description
phys_data
mtiPhysicalDataT *
A pointer to a linked list of structures each describing the name and position of a unit in the specified physical type

Arguments

Name
Type
Description
type_id
mtiTypeIdT
A handle to a VHDL physical type

Description

mti_GetPhysicalData() returns a pointer to a linked list of structures each describing the name and position of a unit in the specified physical type. The linked list is traversed by using the next pointer in each structure. Traversal is terminated by a NULL pointer. The caller is responsible for freeing each structure in the list with mti_Free().

mti_GetPhysicalData() returns NULL if the specified type is not a physical type.

Related functions

None

Example

FLI code

#include <mti.h>

typedef struct signalInfoT_tag {
  struct signalInfoT_tag * next;
  char                   * name;
  mtiPhysicalDataT       * phys_data;
  mtiSignalIdT             sigid;
  mtiTypeIdT               typeid;
} signalInfoT;

typedef struct {
  signalInfoT   * sig_info;     /* List of signals. */
  mtiProcessIdT   proc;         /* Test process id. */
} instanceInfoT;

static void printExtraUnits( signalInfoT * siginfo, mtiInt32T value )
{
  char             * unit_name;
  mtiInt32T          num_units;
  mtiInt32T          position;
  mtiInt32T          remainder;
  mtiPhysicalDataT * pdp;

  for ( pdp = siginfo->phys_data; pdp; pdp = pdp->next ) {
   if ( value < pdp->position ) {
    break;
   }
   unit_name = pdp->unit_name;
   position  = pdp->position;
  }
  num_units = value / position;
  remainder = value % position;
  mti_PrintFormatted( " and %d %s", num_units, unit_name );
  if ( remainder ) {
   printExtraUnits( siginfo, remainder );
  }
}

static void checkValues( void *inst_info )
{
  char             * unit_name;
  instanceInfoT    * inst_data = (instanceInfoT *)inst_info;
  mtiInt32T          num_units;
  mtiInt32T          position;
  mtiInt32T          remainder;
  mtiInt32T          sigval;
  mtiPhysicalDataT * pdp;
  signalInfoT      * siginfo;

  mti_PrintFormatted( "Time [%d,%d]:\n", mti_NowUpper(), mti_Now() );

  for ( siginfo = inst_data->sig_info; siginfo; siginfo = siginfo->next ) {
   mti_PrintFormatted( "  Signal %s:", siginfo->name );
   sigval = mti_GetSignalValue( siginfo->sigid );
   for ( pdp = siginfo->phys_data; pdp; pdp = pdp->next ) {
    if ( sigval < pdp->position ) {
     break;
    }
    unit_name = pdp->unit_name;
    position  = pdp->position;
   }
   num_units = sigval / position;
   remainder = sigval % position;
   mti_PrintFormatted( "  %d = %d %s", sigval, num_units, unit_name );
   if ( remainder ) {
    printExtraUnits( siginfo, remainder );
   }
   mti_PrintFormatted( "\n" );
  }

  mti_ScheduleWakeup( inst_data->proc, 5 );
}

static signalInfoT * setupSignal( mtiSignalIdT sigid )
{
  char             * prev_unit_name;
  mtiInt32T          num_units;
  mtiInt32T          prev_position;
  mtiPhysicalDataT * pdp;
  signalInfoT      * siginfo = 0;

  if ( mti_GetTypeKind( mti_GetSignalType( sigid )) == MTI_TYPE_PHYSICAL ) {
   siginfo            = (signalInfoT *)mti_Malloc(sizeof(signalInfoT));
   siginfo->sigid     = sigid;
   siginfo->name      = mti_GetSignalNameIndirect( sigid, 0, 0 );
   siginfo->typeid    = mti_GetSignalType( sigid );
   siginfo->phys_data = mti_GetPhysicalData( siginfo->typeid );
   siginfo->next      = 0;
   mti_PrintFormatted( "Setting a watch on %s\n", siginfo->name );
   mti_PrintFormatted( "  Physical Units are:\n" );
   for ( pdp = siginfo->phys_data; pdp; pdp = pdp->next ) {
    mti_PrintFormatted( "    %10s = %d %s",
                       pdp->unit_name, pdp->position,
                       siginfo->phys_data->unit_name );
    if ( pdp != siginfo->phys_data ) {
     num_units = pdp->position / prev_position;
     mti_PrintFormatted( " = %d %s", num_units, prev_unit_name );
    }
    mti_PrintFormatted( "\n" );
    prev_unit_name = pdp->unit_name;
    prev_position  = pdp->position;
   }
  }
  return( siginfo );
}

static void initInstance( void )
{
  instanceInfoT * inst_data;
  mtiSignalIdT    sigid;
  signalInfoT   * curr_info;
  signalInfoT   * siginfo;

  inst_data           = mti_Malloc( sizeof(instanceInfoT) );
  inst_data->sig_info = 0;

  for ( sigid = mti_FirstSignal( mti_GetTopRegion() );
        sigid; sigid = mti_NextSignal() ) {
   siginfo = setupSignal( sigid );
   if ( siginfo ) {
    if ( inst_data->sig_info == 0 ) {
     inst_data->sig_info = siginfo; 
    }
    else {
     curr_info->next = siginfo;
    }
    curr_info = siginfo;
   }
  }
  inst_data->proc = mti_CreateProcess( "Test Process", checkValues,
                                      (void *)inst_data );
  mti_ScheduleWakeup( inst_data->proc, 4 );
}

void initForeign(
  mtiRegionIdT       region,   /* The ID of the region in which this     */
                               /* foreign architecture is instantiated.  */
  char              *param,    /* The last part of the string in the     */
                               /* foreign attribute.                     */
  mtiInterfaceListT *generics, /* A list of generics for the foreign model.*/
  mtiInterfaceListT *ports     /* A list of ports for the foreign model.   */
)
{
  mti_AddLoadDoneCB( initInstance, 0 );
} 

HDL code

entity for_model is
end for_model;

architecture a of for_model is
  attribute foreign of a : architecture is "initForeign for_model.sl;";
begin
end a;

library ieee;
use ieee.std_logic_1164.all;

entity top is

  type bigtime is range 0 to integer'high
   units
    hour;
    day   = 24 hour;
    week  = 7 day;
    month = 4 week;
    year  = 12 month;
   end units;

end top;

architecture a of top is

  signal phys_sig1 : bigtime := 3 day;
  signal phys_sig2 : bigtime := 1 week;
  signal phys_sig3 : bigtime := 1 year;

  component for_model
  end component;

  for all : for_model use entity work.for_model(a);

begin

  inst1 : for_model;

  phys_sig1 <= phys_sig1 + 1 day after 5 ns;
  phys_sig2 <= phys_sig2 + 40 hour after 5 ns;
  phys_sig3 <= phys_sig3 + 80 hour after 5 ns;

end a; 

Simulation output

% vsim -c top
Reading .../modeltech/sunos5/../tcl/vsim/pref.tcl 

# 5.4b

# vsim -c top 
# Loading .../modeltech/sunos5/../std.standard
# Loading .../modeltech/sunos5/../ieee.std_logic_1164(body)
# Loading work.top(a)
# Loading work.for_model(a)
# Loading ./for_model.sl
# Setting a watch on phys_sig1
#   Physical Units are:
#           hour = 1 hour
#            day = 24 hour = 24 hour
#           week = 168 hour = 7 day
#          month = 672 hour = 4 week
#           year = 8064 hour = 12 month
# Setting a watch on phys_sig2
#   Physical Units are:
#           hour = 1 hour
#            day = 24 hour = 24 hour
#           week = 168 hour = 7 day
#          month = 672 hour = 4 week
#           year = 8064 hour = 12 month
# Setting a watch on phys_sig3
#   Physical Units are:
#           hour = 1 hour
#            day = 24 hour = 24 hour
#           week = 168 hour = 7 day
#          month = 672 hour = 4 week
#           year = 8064 hour = 12 month
VSIM 1> run 20
# Time [0,4]:
#   Signal phys_sig1:  72 = 3 day
#   Signal phys_sig2:  168 = 1 week
#   Signal phys_sig3:  8064 = 1 year
# Time [0,9]:
#   Signal phys_sig1:  96 = 4 day
#   Signal phys_sig2:  208 = 1 week and 1 day and 16 hour
#   Signal phys_sig3:  8144 = 1 year and 3 day and 8 hour
# Time [0,14]:
#   Signal phys_sig1:  120 = 5 day
#   Signal phys_sig2:  248 = 1 week and 3 day and 8 hour
#   Signal phys_sig3:  8224 = 1 year and 6 day and 16 hour
# Time [0,19]:
#   Signal phys_sig1:  144 = 6 day
#   Signal phys_sig2:  288 = 1 week and 5 day
#   Signal phys_sig3:  8304 = 1 year and 1 week and 3 day
VSIM 2> quit 


Model Technology Inc.
Voice: (503) 641-1340
Fax: (503)526-5410
http://www.model.com
sales@model.com
TOC PREV NEXT INDEX

ModelSim