Note: This is a general Getting Started. Please refer to the User Guides and Installation for each platform.
For 64 Bit MSYS click here.
Getting Started
Download CapsimTMK from here. You can run CapsimTMK from the BIN directory, $CAPSIM/BIN/capsim. Example topologies are included the APPLICATIONS directory. Each application has a README file. To start capsim in the interative mode type:
$CAPSIM/BIN/capsim -b
Set the environment variable CAPSIM to the directory where CapsimTMK resides.
For example,
%export CAPSIM=/usr/local/CapsimTMK
Creating Capsim and Adding Models
CAPSIM provides the utility to add blocks(stars) to the library through the use of the bash shell program precapsim.sh. This is a separate program from CAPSIM and is run from the UNIX/LINUX shell not from inside CAPSIM. Another program, blockmaint.pl, is also available for library maintenance.
Precapsim and Makefile
the bash shell script precapsim.sh provides all the functionality necessary to create your own personalized version of CAPSIM.
Create a new directory any where on your system. For example WORK. You will be creating blocks and subroutines to incorporate into Capsim in this directory.
Suppose that CapsimTMK is installed in the following directory:
/usr/local/CapsimTMK
Then setup the environment variable CAPSIM as follows:
export CAPSIM=/usr/local/CapsimTMK
Next make the directory you just created the current directory and execute the following:
bash $CAPSIM/TOOLS/precapsim.sh -l
(-l is l as in link).
The precapsim.sh shell command will create all the necessary directories and copy all files including Makefiles and scripts from the $CAPSIM directory. It will also create the capsim executable in the current directory.
Following the precapsim.sh execution type:
make
To execute capsim type:
./capsim -b
You will be in the Capsim TMK interactive environment. Go ahead and quit.
Directory Structure
The shell command creates the directories BLOCKS, SUBS, and include. A dummy subroutine and block(star) are also created.
A key point is that the precapsim.sh also copies a Makefile into the current directory. With this Makefile it is very easy to build capsim using your blocks(stars) and subroutines. All you need to do is place a block in the BLOCKS directory and, in the main directory (WORK), type make (twice if first time block is added).
View the Makefile to see how this happens. The BLOCKS directory has a file called blocks.mak . This Makefile has all the necessary dependencies to create the C code from the Block ".s" code. It adds the block to the block database blockdatabase.dat and creates the file krn_libblock.c and the library libblock.a with the object files for the blocks. This is all done automatically. The file blocks.mak itself is created by a perl script blockmake.pl in the $CAPSIM/TOOLS directory. This perl script, given the name of the blocks or *.s, creates a make file for the blocks: blocks.mak.
For more info on the block database and block maintenance see the CapsimTMK document on adding blocks.
The subroutine directory SUBS also has a Makefile and any C subroutine will be compiled and added to the libsubs.a library and linked to capsim.
The include directory is where common include files to the blocks in the BLOCKS and C code in the SUBS directory should be placed. The Makefiles use this directory to search for include files when compiling the blocks and subroutines.
So in a nutshell it is real easy to get started. For the first time just execute precapsim.sh followed by make. Afterwords just type make to update. Just place blocks in the BLOCKS directory and the subroutine C code in the SUBS directory.
When running make, check for errors and correct them. For block compile errors, refer to the C code. Make sure you fix the corresponding .s code.
You can use gdb and ddd to debug the block source code.
Adding Blocks to CapsimTMK
To setup CAPSIM in order to add your own blocks see the CAPSIM Tutorial.
Here is a quick guide:
- Create a working directory anywhere. For example call it WORK.
mkdir WORK - Change directory to WORK
cd WORK - Type ( Do this once!)
bash $CAPSIM/TOOLS/precapsim.sh -l
That is "l" as in link. (If using MSYS use "source" instead of "bash"). - The precapsim.sh bash shell will do all the work. It will create
the BLOCKS dierctory and copy a dummy block to this directroy.
It will create the SUBS directroy. It will copy a Makefile
to the WORK directory. The Makefile will be used to maintain and
add Blocks and Subroutines to your custom CAPSIM. - You must type "make"
make - A CAPSIM executable "capsim" will be created in the WORK directory (With MSYS "capsim.exe").
- To run CAPSIM type
./capsim - To run CAPSIM with TCL command interpretor active type:
./capsim -c - To run Capsim in text mode type:
./capsim -b
Creating Blocks Using the Block Generation Tool
To create a block and add it to Capsim do the following (detailed and step by step):
- Change directory to the BLOCKS directory in the WORK directory:
cd BLOCKS - Type the following to bring up the Block Generation Graphical Tool:
wish $CAPSIM/TOOLS/blockgen.tcl &
This will also send it to the background so we can edit
the generated block.
- Select Source Block and set a name (for example xsource).
- Click on Generate Block.
- The block is generated. View the file:
xsource.s
Or using the name you provided. - Change directory to WORK
cd .. - Type make TWICE!
make
make
This is only necessary when you add a block or multiple blocsk.
Once a block is added type make once when you change a blocks
source code or asubroutines source code. - Bring up CAPSIM
./capsim -b - Type
block xsource block prfile connect xsource0 prfile0 store test
- Run the simulation.
- You should see a print out of a constant DC source.
- Save your topology.
- Now lets change the source code for "xsource.s".
- Change directory to BLOCKS.
- Edit "xsource.s" or your block name. Change the following in the MAIN_CODE section:
/*
* output the sample
*/
x(0)=1.0*sampleCount*sampleCount/numberOfSamples;
- This will output a parabola.
- Save the block.
- Change directory to WORK and type make.
cd ..
make - Run capsim. Open the saved topology. Run the simulation.
You should see a print of a parabola.
Store in a file and plot.
- If you run into any errors make sure you check all the
messages for compilation errors.
One thing you can do is go to the BLOCKS directory and type
make -f blocks.mak
Check for errors. Correct. Then type make again. When all
errors have been corrected type:
cd ..
make
Run CAPSIM
./capsim -b
See the CAPSIM Tutorial on using the Block Generation tool.
Its easy to create new blocks and add them to CAPSIM.
Adding C code and calling libraries and subroutines is straight forward.
Finally, if you plan on linking to additional libraries you have to:
1- create a copy of precapsim.sh
2- Add the library to the link path (see the last line in precapsim.sh)
3- Edit your Makefile to use the modified precapsim.sh file.