Adding Proprietary MOS Models

The CMI interface enables you to enter proprietary models into Star-Hspice. This section describes how to use CMI to add a new MOS model. Use CMI to simplify the integration process.


NOTE: In the following examples, the percent sign (%) represents the UNIX shell prompt, and $(installdir) points to the Star-Hspice release directory. $ARCH is the OS type for the computer. Star-Hspice 98.4 CMI release supports the platforms Sun4, Solaris, and HP.

Creating a CMI Shared Library

To add a new model:

1. Create a directory environment and modify the configuration file.

2. Prepare and modify model routines.

3. Compile the shared library.

4. Set up the runtime shared library path.

Creating the Directory Environment

To create the CMI directory environment:

1. Copy the CMI directory from the Star-Hspice release directory to a new location, as shown in the following example:

% cp -r $(installdir)/cmi /home/user1/userx/model

The new CMI directory /home/user1/userx/model/cmi is your working directory. Make sure that you have read and write access to your working directory.

2. Copy an existing model subdirectory to a new model directory and create a subdirectory for the new model under the working CMI directory. For example, if you have a MOSFET model whose LEVEL is 222, you can copy the subdirectory from the existing MOS model LEVEL 3, as follows:

%cp -r mos3 mos222

3. Add the following line in the configuration file config :

mos222 222 "my own MOSFET model"

where mos222 is the model name

222 is the model LEVEL;

"my own MOSFET model" is the descriptive comment for the model. The model name and level must be unique in the configuration file. For more information, see the in-line comment in the configuration file.

Preparing Model Routine Files

In the new model subdirectory mos222 , rename mos3 in all filenames to mos222 , for example:

% mv CMImos3defs.h CMImos222defs.h

After renaming all the files, the new model subdirectory should contain the following group of files:

CMImos222defs.h CMImos222.c

CMImos222GetIpar.c CMImos222SetIpar.c

CMImos222GetMpar.c CMImos222SetMpar.c

CMImos222eval.c CMImos222set.c

CMImos222temp.c

The purpose and detailed description of each routine can be found in Model Interface Routines. You must modify the functions as necessary. The majority of the work required to add a new model is for modification of these files.

Compiling the Shared Library

Follow the steps above to modify the model routine files and the configuration file, then compile the model routines and the shared library with a single make operation. Prior to the make operation, manually set the environment variable HSPICE_CMI to the working CMI directory (see Creating the Directory Environment):

% setenv HSPICE_CMI /home/user1/userx/model/cmi

With HSPICE_CMI set correctly, invoke the compilation process by entering the following:

% make -f makecmi

The new shared library called libCMImodel will be created in subdirectory lib/ with all the object files generated in subdirectory obj/ .

We recommend that you check the syntax of your C functions before launching the compilation process. Enter the following command:

% make -f makecmi lint

to list any syntax errors in your model routines.


NOTE: During compilation, CMI creates files ( makefile.SUN on SUN, makefile.HP on HP), and subdirectories ( obj/ , lib/ ) in the CMI working directory. Do not manually modify these generated files.

Choosing a Compiler

You can use any functional compiler by properly setting the environment variable CC to the location of the compiler ( CC is used in the autogenerated makefile, makefile.SUN and makefile.HP). Make sure that the appropriate compiler and link flags are properly set so the final CMI library build is in position independent code (PIC). PIC is needed for dynamic linking.

For SUNOS 5.4 platforms or later, the automatically generated compiler flag -KPIC and link flag -G -z are for the Sun workshop compiler, cc or acc . These compilers are typically installed in a directory such as /usr1/opt/SUNWspro/SC4.2/bin. For HP9000/700 platforms, cc is installed in /opt/ansic/bin. For more information, type man cc or man acc to display the on-line manual page for these commands.

There are no restrictions on the optimization flags you use for the CMI library. However, we recommend using the flag -fast for the Sun compiler cc or acc and the flag -O for HP compiler cc.

Using the gcc Compiler

If you use the gcc compiler, modify the makefile ( makefile.SUN or makefile.HP ) to set the compiler flags correctly.

For gcc, set the environment variable CC to gcc and modify the makefile to use the -fPIC flag for compiling and the -r flag for linking. For example:

gcc -c -I../include -fPIC CMImain.c

...

gcc -r -o ./lib/libCMImodel obj/*.o

Using the /usr/ucb/cc Compiler

If you use the /usr/ucb/cc compiler, modify the makefile ( makefile.SUN or makefile.HP ) to set the compiler flags correctly.

The /usr/ucb/cc compiler can not compile C source files until the "Language Optional Source Package" is installed. Verify that this source package is installed, then set the environment variable CC to /usr/ucb/cc.


NOTE: The "Language Optional Source Package" is not installed in Solaris by default, but it is installed in SUNOS 4.1.x by default. You must either install the optional language software or use a workable compiler such as the Sun workshop cc or acc. The gcc compiler can also be used with some minor modifications to the makefile.

Setting up the Runtime Shared Library Path

The shared library is now ready for use. You must update the shared model search path defined by the environment variable hspice_lib_models so that the system dynamic loader can find the new CMI shared library for Star-Hspice. Enter the following:

setenv hspice_lib_models $HSPICE_CMI/lib

Troubleshooting

Sometimes you can successfully build the CMI dynamic library, but at run time Star-Hspice returns the following error message:

**error**: Unable to load

/home/ant/lib/models/libCMImodel and /home/ant/lib/models/libCMImodel.so

This problem is usually caused by undefined symbols at run time. The following is an example output of undefined symbols, using Sun workshop cc as a compiler on a SUNOS 5.5 machine (note that different compilers usually generate nm output in different formats)

Example

nm libCMImodel |grep UNDEF

[35] | 0| 0|NOTY |LOCL |0 |UNDEF |

[34] | 0| 0|NOTY |LOCL |0 |UNDEF |

[1779] | 0| 0|NOTY |GLOB |0 |UNDEF |.mul

[1853] | 0| 0|NOTY |GLOB |0 |UNDEF |__dtou

[1810] | 0| 0|NOTY |GLOB |0 |UNDEF |__iob

[1822] | 0| 0|NOTY |WEAK |0 |UNDEF |_ex_deregister

[1749] | 0| 0|NOTY |WEAK |0 |UNDEF |_ex_register

[1857] | 0| 0|NOTY |GLOB |0 |UNDEF |atan

[1878] | 0| 0|NOTY |GLOB |0 |UNDEF |cos

[1820] | 0| 0|NOTY |GLOB |0 |UNDEF |exp

[1777] | 0| 0|NOTY |GLOB |0 |UNDEF |fabs

[1872] | 0| 0|NOTY |GLOB |0 |UNDEF |fprintf

[1764] | 0| 0|NOTY |GLOB |0 |UNDEF |log

[1767] | 0| 0|NOTY |GLOB |0 |UNDEF |malloc

[1842] | 0| 0|NOTY |GLOB |0 |UNDEF |memset

[1772] | 0| 0|NOTY |GLOB |0 |UNDEF |pow

[1869] | 0| 0|NOTY |GLOB |0 |UNDEF |sin

[1790] | 0| 0|NOTY |GLOB |0 |UNDEF |sqrt

[1758] | 0| 0|NOTY |GLOB |0 |UNDEF |strcasecmp

[1848] | 0| 0|NOTY |GLOB |0 |UNDEF |strcpy

[1858] | 0| 0|NOTY |GLOB |0 |UNDEF |strlen

[1800] | 0| 0|NOTY |GLOB |0 |UNDEF |strncpy

The above undefined symbols can be satisfied at run time by libraries such as libc or libm. However, any unsatisfied symbols other than those shown in the example may cause the "Unable to load" problem.

Star-Hspice Manual - Release 2001.2 - June 2001