Table of Contents Previous page Next page Index

ModelSim

Model Technology Inc.


mti_GetCurrentRegion()

Gets the current elaboration region during elaboration or the current environment during simulation.

Syntax

region_id = mti_GetCurrentRegion() 

Returns

Name
Type
Description
region_id
mtiRegionIdT
A handle to the current region

Arguments

None

Description

During elaboration, mti_GetCurrentRegion() returns the region ID of the current elaboration region. During simulation, mti_GetCurrentRegion() returns the region ID of the current environment set by the environment command.

The region ID returned by mti_GetCurrentRegion() can be either a VHDL region or a Verilog region.

Related functions

mti_GetCallingRegion()

Example

FLI code

#include <mti.h>

void doProc( void )
{
  char *          region_name;
  mtiRegionIdT    regid;

  regid = mti_GetCurrentRegion();
  region_name = mti_GetRegionFullName( regid );
  mti_PrintFormatted( "Time [%d,%d]: doProc Procedure: "
                     "Current region is %s\n",
                     mti_NowUpper(), mti_Now(), region_name );
  mti_VsimFree( region_name );
}

static void checkEnv( void )
{
  char *          region_name;
  mtiRegionIdT    regid;

  regid = mti_GetCurrentRegion();
  region_name = mti_GetRegionFullName( regid );
  mti_PrintFormatted( "Time [%d,%d]: checkEnv Function: "
                     "Current region is %s\n",
                     mti_NowUpper(), mti_Now(), region_name );
  mti_VsimFree( region_name );
}

static void checkRegion( void )
{
  char *          region_name;
  mtiRegionIdT    regid;

  regid = mti_GetCurrentRegion();
  region_name = mti_GetRegionFullName( regid );
  mti_PrintFormatted( "Time [%d,%d]: checkRegion Function: "
                     "Current region is %s\n",
                     mti_NowUpper(), mti_Now(), region_name );
  mti_VsimFree( region_name );
}

static void initInstance( void )
{
  char *          region_name;
  mtiProcessIdT   procid;
  mtiRegionIdT    regid;

  regid = mti_GetCurrentRegion();
  region_name = mti_GetRegionFullName( regid );
  mti_PrintFormatted( "Load Done Callback Function: Current region is %s\n",
                     region_name );
  mti_VsimFree( region_name );

  procid = mti_CreateProcess( "Test Process", checkRegion, 0 );
  mti_ScheduleWakeup( procid, 10 );
}

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.   */
)
{
  char *       region_name;
  mtiRegionIdT regid;

  mti_PrintFormatted( "Foreign Init Function:\n" );

  region_name = mti_GetRegionFullName( region );
  mti_PrintFormatted( "  Region parameter is %s\n", region_name );
  mti_VsimFree( region_name );

  regid = mti_GetCurrentRegion();
  region_name = mti_GetRegionFullName( regid );
  mti_PrintFormatted( "  Current region is %s\n", region_name );
  mti_VsimFree( region_name );

  mti_AddLoadDoneCB( initInstance, 0 );
  mti_AddEnvCB( checkEnv, 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;

package for_pkg is

  procedure test_proc;
  attribute foreign of test_proc : procedure is "doProc for_model.sl;";

end for_pkg;

package body for_pkg is

  procedure test_proc is
    begin
    end;

end for_pkg;

use work.for_pkg.all;

entity lower is
end lower;

architecture level of lower is
begin

  p1 : process
    begin
      test_proc;
      wait for 15 ns;
    end process;

end level;

library ieee;
use ieee.std_logic_1164.all;

entity top is
end top;

architecture a of top is

  component for_model
  end component;

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

  component lower
  end component;

  for all : lower use entity work.lower(level);

begin

  linst1 : lower;

  linst2 : lower;

  finst  : for_model;

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.for_pkg(body)
# Loading ./for_model.sl
# Loading work.top(a)
# Loading work.lower(level)
# Loading work.for_model(a)
# Foreign Init Function:
#   Region parameter is /top/finst
#   Current region is /top/finst
# Time [0,0]: checkEnv Function: Current region is /top
# Load Done Callback Function: Current region is /top
VSIM 1> run 0
# Time [0,0]: doProc Procedure: Current region is /top
# Time [0,0]: doProc Procedure: Current region is /top
VSIM 2> env
# sim:/top
VSIM 3> env finst
# Time [0,0]: checkEnv Function: Current region is /top/finst
# sim:/top/finst
VSIM 4> run 10
# Time [0,10]: checkRegion Function: Current region is /top/finst
VSIM 5> env
# sim:/top/finst
VSIM 6> env /top
# Time [0,10]: checkEnv Function: Current region is /top
# sim:/top
VSIM 7> run 10
# Time [0,15]: doProc Procedure: Current region is /top
# Time [0,15]: doProc Procedure: Current region is /top
VSIM 8> env
# sim:/top
VSIM 9> env linst1
# Time [0,20]: checkEnv Function: Current region is /top/linst1
# sim:/top/linst1
VSIM 10> run 15
# Time [0,30]: doProc Procedure: Current region is /top/linst1
# Time [0,30]: doProc Procedure: Current region is /top/linst1
VSIM 11> env
# sim:/top/linst1
VSIM 12> quit 


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

ModelSim