Technical data
Using checkpoint/restore with the FLI
464
-
VHDL Foreign Language Interface and Verilog PLI ModelSim EE/PLUS Reference Manual
from mti routines. Pointers that you save and restore must be global, not variables
on the stack. If you choose not to use the MTI provided memory allocation
functions, you will have to explicitly save and restore your allocated memory
structures as well.
You must code your model assuming that the code could reside in a different
memory location when restored.
The following is a C model of a two-input AND gate (the same model as provided
in /modeltech/examples/foreign/gates.c) adapted for checkpoint/restore. The lines
added for checkpoint/restore are marked with comments.
/* ------------------------------------------- */
#include <stdio.h>
#include "mti.h"
typedef struct {
signalID in1;
signalID in2;
driverID out1;
} inst_rec;
do_and(ip)
inst_rec *ip;
{
int val1, val2;
int result;
char buf[128];
val1 = mti_GetSignalValue(ip->in1);
val2 = mti_GetSignalValue(ip->in2);
result = val1 & val2;
mti_ScheduleDriver(ip->out1, result, 0, MTI_INERTIAL);
}
and_gate_init(region, param, generics, ports)
regionID region;
char *param;
interface_list *generics;
interface_list *ports;
{
inst_rec *ip;
signalID outp;
processID proc;
if (mti_IsRestore()){ /* new */
ip = (inst_rec *)mti_RestoreLong(); /* new */
proc = (processID)mti_RestoreLong(); /* new */
mti_RestoreProcess(proc, "p1", do_and, ip); /* new */