Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


mti_GetDriverSubelements()

Gets the subelements of a composite driver.

Syntax

driver_list = mti_GetDriverSubelements( driver_id, buffer ) 

Returns

Name
Type
Description
driver_list
mtiDriverIdT *
A pointer to an array of driver IDs for each of the subelements of the specified array-type driver or NULL if the specified driver is not of an array type

Arguments

Name
Type
Description
driver_id
mtiDriverIdT
A handle to an array-type driver
buffer
mtiDriverIdT *
A buffer into which the subelement driver IDs are to be placed;
OPTIONAL - can be NULL

Description

mti_GetDriverSubelements() returns an array of driver IDs for each of the subelements of the specified array-type driver.

If the buffer parameter is NULL, then mti_GetDriverSubelements() allocates memory for the value and returns a pointer to it. The caller is responsible for freeing the returned pointer with mti_VsimFree().

If the buffer parameter is not NULL, then mti_GetDriverSubelements() copies the value into the buffer parameter and also returns the buffer parameter.

Related functions

mti_ScheduleDriver()

Example

FLI code

#include <stdlib.h>
#include <mti.h>

typedef enum {
  STD_LOGIC_U,
  STD_LOGIC_X,
  STD_LOGIC_0,
  STD_LOGIC_1,
  STD_LOGIC_Z,
  STD_LOGIC_W,
  STD_LOGIC_L,
  STD_LOGIC_H,
  STD_LOGIC_D
} standardLogicType;

typedef struct {
  mtiSignalIdT  sigid;
  mtiDriverIdT * drv_elems;
  int            index;
  int            num_elems;
} instanceInfoT;

char * convertStdLogicValue( char sigval )
{
  char * retval;

  switch ( sigval ) {
    case STD_LOGIC_U:  retval = "'U'";  break;
    case STD_LOGIC_X:  retval = "'X'";  break;
    case STD_LOGIC_0:  retval = "'0'";  break;
    case STD_LOGIC_1:  retval = "'1'";  break;
    case STD_LOGIC_Z:  retval = "'Z'";  break;
    case STD_LOGIC_W:  retval = "'W'";  break;
    case STD_LOGIC_L:  retval = "'L'";  break;
    case STD_LOGIC_H:  retval = "'H'";  break;
    case STD_LOGIC_D:  retval = "'-'";  break;
    default:  retval = "?";  break;
  }
  return retval;
}
void driveSignal( void * param )
{
  char          * region_name;
  char          * sigval;
  instanceInfoT * inst = (instanceInfoT*)param;
  int             i;

  region_name = mti_GetRegionFullName(mti_GetSignalRegion(inst->sigid));
  sigval      = (char *)mti_GetArraySignalValue( inst->sigid, 0 );
  mti_PrintFormatted( "Time [%d,%d] delta %d: Signal %s/%s is {",
                     mti_NowUpper(), mti_Now(), mti_Delta(),
                     region_name, mti_GetSignalName( inst->sigid ) );
  for ( i = 0; i < inst->num_elems; i++ ) {
    mti_PrintFormatted( " %s", convertStdLogicValue( sigval[i] ) );
  }
  mti_PrintFormatted( " }\n" );

  switch ( sigval[inst->index] ) {
    case STD_LOGIC_U:  sigval[inst->index] = STD_LOGIC_X;  break;
    case STD_LOGIC_X:  sigval[inst->index] = STD_LOGIC_0;  break;
    case STD_LOGIC_0:  sigval[inst->index] = STD_LOGIC_1;  break;
    case STD_LOGIC_1:  sigval[inst->index] = STD_LOGIC_Z;  break;
    case STD_LOGIC_Z:  sigval[inst->index] = STD_LOGIC_W;  break;
    case STD_LOGIC_W:  sigval[inst->index] = STD_LOGIC_L;  break;
    case STD_LOGIC_L:  sigval[inst->index] = STD_LOGIC_H;  break;
    case STD_LOGIC_H:  sigval[inst->index] = STD_LOGIC_D;  break;
    case STD_LOGIC_D:  sigval[inst->index] = STD_LOGIC_U;  break;
    default:  sigval[inst->index] = STD_LOGIC_U;  break;
  }
  mti_ScheduleDriver( inst->drv_elems[inst->index], sigval[inst->index],
                     5, MTI_INERTIAL );

  inst->index++;
    if ( inst->index >= inst->num_elems ) {
    inst->index = 0;
  }
  mti_VsimFree( region_name );
  mti_VsimFree( sigval );
}

void cleanupCallback( void * param )
{
  mti_PrintMessage( "Cleaning up...\n" );
  free( param );
}

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.   */
)
{
  instanceInfoT * inst;
  mtiDriverIdT    drvid;
  mtiProcessIdT   procid;

  inst            = (instanceInfoT *)malloc( sizeof(instanceInfoT) );
  inst->sigid     = mti_FindSignal( "/top/s1" );
  drvid           = mti_CreateDriver( inst->sigid );
  inst->drv_elems = mti_GetDriverSubelements( drvid, 0 );
  inst->num_elems = mti_TickLength( mti_GetSignalType( inst->sigid ));
  inst->index     = 0;
  procid          = mti_CreateProcess( "sigDriver", driveSignal, inst );
  mti_Sensitize( procid, inst->sigid, MTI_EVENT );
  mti_ScheduleWakeup( procid, 0 );
  mti_SetDriverOwner( drvid, procid );
  mti_AddQuitCB( cleanupCallback, inst );
  mti_AddRestartCB( cleanupCallback, inst );
} 

HDL code

library ieee;
use ieee.std_logic_1164.all;

entity top is
end top;

architecture a of top is
  signal s1 : std_logic_vector( 3 downto 0 ) := "0000";
begin
end a; 

Simulation output

% vsim -c top -foreign "initForeign for_model.sl"
Reading .../modeltech/sunos5/../tcl/vsim/pref.tcl 

# 5.4b

# vsim -foreign {initForeign for_model.sl} -c top 
# Loading .../modeltech/sunos5/../std.standard
# Loading .../modeltech/sunos5/../ieee.std_logic_1164(body)
# Loading work.top(a)
# Loading ./for_model.sl
VSIM 1> run 50
# Time [0,0] delta 1: Signal /top/s1 is { '0' '0' '0' '0' }
# Time [0,5] delta 0: Signal /top/s1 is { '1' '0' '0' '0' }
# Time [0,10] delta 0: Signal /top/s1 is { '1' '1' '0' '0' }
# Time [0,15] delta 0: Signal /top/s1 is { '1' '1' '1' '0' }
# Time [0,20] delta 0: Signal /top/s1 is { '1' '1' '1' '1' }
# Time [0,25] delta 0: Signal /top/s1 is { 'Z' '1' '1' '1' }
# Time [0,30] delta 0: Signal /top/s1 is { 'Z' 'Z' '1' '1' }
# Time [0,35] delta 0: Signal /top/s1 is { 'Z' 'Z' 'Z' '1' }
# Time [0,40] delta 0: Signal /top/s1 is { 'Z' 'Z' 'Z' 'Z' }
# Time [0,45] delta 0: Signal /top/s1 is { 'W' 'Z' 'Z' 'Z' }
# Time [0,50] delta 0: Signal /top/s1 is { 'W' 'W' 'Z' 'Z' }
VSIM 2> quit
# Cleaning up... 


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

ModelSim