Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


mti_AddTclCommand()

Adds a user-defined, Tcl-style simulator command.

Syntax

mti_AddTclCommand( cmd_name, cmd_func, cmd_param, func_delete_cb ) 

Returns

Nothing

Arguments

Name
Type
Description
cmd_name
char *
The name of the command being added
cmd_func
Tcl_CmdProc *
A pointer to a function that will be called whenever the command is recognized by the command interpreter; OPTIONAL - can be NULL
cmd_param
void *
A parameter to be passed to the command function; OPTIONAL - can be NULL
func_delete_cb
mtiVoidFuncPtrT
A pointer to a function that will be called if the command is redefined or deleted; OPTIONAL - can be NULL

Description

mti_AddTclCommand() adds the specified Tcl command to the simulator. The case of the command name is significant. The simulator command interpreter subsequently recognizes the command and calls the command function along with its parameter and user-supplied arguments whenever the command is recognized. The command function must return a valid Tcl status (for example TCL_OK or TCL_ERROR). The command function prototype is:

int commandFuncName( ClientData cmd_param, Tcl_Interp * interp, int argc, char ** argv) 

A command can be added with the same name as a previously added command (or even a standard simulator command), but only the command added last has any effect.

If a command is readded or deleted, the delete callback function is called along with the command parameter so that the old command information can be cleaned up. The delete callback function prototype is:

void deleteCBname( ClientData cmd_param ) 

A command can be essentially deactivated by calling mti_AddTclCommand() with the same command name but with a NULL command function pointer.

To make the prototype of mti_AddTclCommand() visible, the header file tcl.h must be included in the FLI application code before mti.h.

Related functions

mti_AddCommand()

mti_Cmd()

mti_Command()

Example

FLI code

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

typedef struct {
  char         model_name[100];
  mtiSignalIdT sig1;
  mtiSignalIdT sig2;
} instanceInfoT;

int noAction( ClientData param, Tcl_Interp * interp, int argc, char ** argv )
{
  mti_PrintFormatted( "Time [%ld,%ld] delta %d:\n",
                     mti_NowUpper(), mti_Now(), mti_Delta() );
  mti_PrintMessage( "  The printSigs command has been deactivated.\n" );
  return TCL_OK;
}

void printSigInfo( mtiSignalIdT sigid, char printFullName )
{
  char * region_name;

  mti_PrintFormatted( "    Signal " );
  if ( printFullName ) {
    region_name = mti_GetRegionFullName( mti_GetSignalRegion( sigid ));
    mti_PrintFormatted( "%s/", region_name );
    mti_VsimFree( region_name );
  }
  mti_PrintFormatted( "%s = ", mti_GetSignalName( sigid ) );
  switch ( mti_GetTypeKind( mti_GetSignalType( sigid )) ) {
    case MTI_TYPE_SCALAR:
    case MTI_TYPE_ENUM:
    case MTI_TYPE_PHYSICAL:
      mti_PrintFormatted( "%d\n", mti_GetSignalValue( sigid ) );
      break;
    default:
      mti_PrintFormatted( "(Type not supported)\n" );
      break;
  }
}

int printRegionInfo( ClientData param, Tcl_Interp * interp,
                    int argc, char ** argv )
{
  instanceInfoT * inst_info = (instanceInfoT*)param;
  char            printFullName = 0;

  if ( argc > 1 ) {
    if ( strcmp( argv[1], "full" ) == 0 ) {
         printFullName = 1;
    } else {
         Tcl_SetResult( interp, "printRegionInfo(): Unknown argument",
                       TCL_STATIC );
         return TCL_ERROR;
    }
  }
  mti_PrintFormatted( "Time [%ld,%ld] delta %d:\n",
                     mti_NowUpper(), mti_Now(), mti_Delta() );
  mti_PrintFormatted( "  Signal info for %s:\n", inst_info->model_name );
  printSigInfo( inst_info->sig1, printFullName );
  printSigInfo( inst_info->sig2, printFullName );

  if ( mti_Now() > 15 ) {
      mti_AddTclCommand( "printSigs", noAction, 0, 0 );
  }

  return TCL_OK;
}

void deleteCB( ClientData param )
{
  instanceInfoT * inst_info = (instanceInfoT*)param;

  mti_PrintFormatted( "Time [%ld,%ld] delta %d:\n",
                     mti_NowUpper(), mti_Now(), mti_Delta() );
  mti_PrintFormatted( "  Deleting old command data for %s.\n",
                     inst_info->model_name );
  free( inst_info );
}

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_info;
  mtiInterfaceListT * portp;

  inst_info = (instanceInfoT *)malloc( sizeof(instanceInfoT) );

  /* ASSUME param is less than 100 chars and
   * there are at least two signal ports.
   */
  strcpy( inst_info->model_name, param );
  portp = ports;
  inst_info->sig1 = portp->u.port;
  portp = portp->nxt;
  inst_info->sig2 = portp->u.port;

mti_AddTclCommand( "printSigs", printRegionInfo, inst_info, deleteCB );
mti_AddQuitCB( cleanupCallback, inst_info );
mti_AddRestartCB( cleanupCallback, inst_info );
} 

HDL code

library ieee;
use ieee.std_logic_1164.all;

entity for_model is
  port ( inb : in bit;
         ins : in std_logic
        );
end for_model;

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

library ieee;
use ieee.std_logic_1164.all;

entity top is
end top;

architecture a of top is

  signal s1 : bit := '0';
  signal s2 : std_logic := '1';

  component for_model is
    port ( inb : in bit;
            ins : in std_logic
          );
  end component;

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

begin

  i1 : for_model
       port map ( s1, s2 );

  s1 <= not s1 after 5 ns;
  s2 <= not s2 after 5 ns;

end a; 

Simulation output

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

# 5.5 Dev

# 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
VSIM 1> printSigs
# Time [0,0] delta 0:
#   Signal info for for_model:
#     Signal s1 = 0
#     Signal s2 = 3
VSIM 2> printSigs full
# Time [0,0] delta 0:
#   Signal info for for_model:
#     Signal /top/s1 = 0
#     Signal /top/s2 = 3
VSIM 3> run 5
VSIM 4> printSigs
# Time [0,5] delta 1:
#   Signal info for for_model:
#     Signal s1 = 1
#     Signal s2 = 2
VSIM 5> printSigs all
# printRegionInfo(): Unknown argument
VSIM 6> run 5
VSIM 7> printSigs
# Time [0,10] delta 1:
#   Signal info for for_model:
#     Signal s1 = 0
#     Signal s2 = 3
VSIM 8> run 10
VSIM 9> printSigs
# Time [0,20] delta 1:
#   Signal info for for_model:
#     Signal s1 = 0
#     Signal s2 = 3
# Time [0,20] delta 1:
#   Deleting old command data for for_model.
VSIM 10> run 5
VSIM 11> printSigs
# Time [0,25] delta 1:
#   The printSigs command has been deactivated.
VSIM 12> 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