24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Macros (DO files)<br />

Creating DO files<br />

<strong>ModelSim</strong> macros (also called DO files) are simply scripts that contain <strong>ModelSim</strong> <strong>and</strong>,<br />

optionally, Tcl comm<strong>and</strong>s. You invoke these scripts with the Tools > Execute Macro<br />

menu selection or the do comm<strong>and</strong> (CR-151).<br />

Macros (DO files) UM-487<br />

You can create DO files, like any other Tcl script, by typing the required comm<strong>and</strong>s in any<br />

editor <strong>and</strong> saving the file. Alternatively, you can save the transcript as a DO file (see<br />

"Saving the transcript file" (GR-16)).<br />

All "event watching" comm<strong>and</strong>s (e.g. onbreak (CR-214), onerror (CR-216), etc.) must be<br />

placed before run (CR-252) comm<strong>and</strong>s within the macros in order to take effect.<br />

The following is a simple DO file that was saved from the transcript. It is used in the dataset<br />

exercise in the <strong>ModelSim</strong> Tutorial. This DO file adds several signals to the Wave window,<br />

provides stimulus to those signals, <strong>and</strong> then advances the simulation.<br />

Using Parameters with DO files<br />

add wave ld<br />

add wave rst<br />

add wave clk<br />

add wave d<br />

add wave q<br />

force -freeze clk 0 0, 1 {50 ns} -r 100<br />

force rst 1<br />

force rst 0 10<br />

force ld 0<br />

force d 1010<br />

onerror {cont}<br />

run 1700<br />

force ld 1<br />

run 100<br />

force ld 0<br />

run 400<br />

force rst 1<br />

run 200<br />

force rst 0 10<br />

run 1500<br />

You can increase the flexibility of DO files by using parameters. Parameters specify values<br />

that are passed to the corresponding parameters $1 through $9 in the macro file. For<br />

example say the macro "testfile" contains the line bp $1 $2. The comm<strong>and</strong> below would<br />

place a breakpoint in the source file named design.vhd at line 127:<br />

do testfile design.vhd 127<br />

Deleting a file from a .do script<br />

There is no limit on the number of parameters that can be passed to macros, but only nine<br />

values are visible at one time. You can use the shift comm<strong>and</strong> (CR-266) to see the other<br />

parameters.<br />

To delete a file from a .do script, use the Tcl file comm<strong>and</strong> as follows:<br />

file delete myfile.log<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!