2 * Copyright (c) 2002,2003 Michael Ruff (mruff at chiaro.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: getsimtime.c,v 1.11 2003/06/21 23:40:15 steve Exp $"
32 * some TF time routines implemented using VPI interface
36 scale(int high
, int low
, void*obj
) {
37 vpiHandle hand
= vpi_handle(vpiScope
, vpi_handle(vpiSysTfCall
,0));
41 scaled
= (scaled
<< 32) | low
;
42 scaled
*= pow(10, vpi_get(vpiTimePrecision
,0) -
43 vpi_get(vpiTimeUnit
,obj
? (vpiHandle
)obj
: hand
));
49 PLI_INT32
tf_gettime(void)
52 time
.type
= vpiSimTime
;
53 vpi_get_time (0, &time
);
54 return scale(time
.high
, time
.low
, 0) & 0xffffffff;
57 char *tf_strgettime(void)
62 time
.type
= vpiSimTime
;
63 vpi_get_time (0, &time
);
65 snprintf(buf
, sizeof(buf
)-1, "%u%08u", time
.high
, time
.low
);
67 snprintf(buf
, sizeof(buf
)-1, "%u", time
.low
);
71 PLI_INT32
tf_igetlongtime(PLI_INT32
*high
, void*obj
)
75 time
.type
= vpiSimTime
;
76 vpi_get_time ((vpiHandle
)obj
, &time
);
77 scaled
= scale(time
.high
, time
.low
, obj
);
79 *high
= (scaled
>> 32) & 0xffffffff;
80 return scaled
& 0xffffffff;
83 PLI_INT32
tf_getlongtime(PLI_INT32
*high
)
85 return tf_igetlongtime(high
, 0);
88 /* Alias for commercial simulators */
89 PLI_INT32
tf_getlongsimtime(PLI_INT32
*high
) \
90 __attribute__ ((weak
, alias ("tf_getlongtime")));
92 void tf_scale_longdelay(void*obj
, PLI_INT32 low
, PLI_INT32 high
,
93 PLI_INT32
*alow
, PLI_INT32
*ahigh
)
95 ivl_u64_t scaled
= scale(high
, low
, obj
);
96 *ahigh
= (scaled
>> 32) & 0xffffffff;
97 *alow
= scaled
& 0xffffffff;
100 void tf_unscale_longdelay(void*obj
, PLI_INT32 low
, PLI_INT32 high
,
101 PLI_INT32
*alow
, PLI_INT32
*ahigh
)
104 vpiHandle hand
= vpi_handle(vpiScope
, vpi_handle(vpiSysTfCall
,0));
107 unscaled
= (unscaled
<< 32) | low
;
108 unscaled
*= pow(10, vpi_get(vpiTimeUnit
, hand
) -
109 vpi_get(vpiTimePrecision
, 0));
111 *ahigh
= (unscaled
>> 32) & 0xffffffff;
112 *alow
= unscaled
& 0xffffffff;
115 void tf_scale_realdelay(void*obj
, double real
, double *areal
)
117 vpiHandle hand
= vpi_handle(vpiScope
, vpi_handle(vpiSysTfCall
,0));
119 *areal
= real
* pow(10, vpi_get(vpiTimePrecision
, 0) -
120 vpi_get(vpiTimeUnit
, hand
));
123 void tf_unscale_realdelay(void*obj
, double real
, double *areal
)
125 vpiHandle hand
= vpi_handle(vpiScope
, vpi_handle(vpiSysTfCall
,0));
127 *areal
= real
* pow(10, vpi_get(vpiTimeUnit
, hand
) -
128 vpi_get(vpiTimePrecision
, 0));
131 PLI_INT32
tf_gettimeprecision(void)
135 vpiHandle sys
= vpi_handle(vpiSysTfCall
,0);
138 hand
= vpi_handle(vpiScope
, sys
);
139 rc
= vpi_get(vpiTimePrecision
, hand
);
142 fprintf(pli_trace
, "tf_gettimeprecision(<%s>) --> %d\n",
143 vpi_get_str(vpiName
, sys
), rc
);
148 PLI_INT32
tf_igettimeprecision(void*obj
)
153 /* If the obj pointer is null, then get the simulation
155 rc
= vpi_get(vpiTimePrecision
, 0);
159 vpiHandle scope
= vpi_handle(vpiScope
, (vpiHandle
)obj
);
161 rc
= vpi_get(vpiTimePrecision
, scope
);
165 fprintf(pli_trace
, "tf_igettimeprecision(<%s>) --> %d\n",
166 obj
? vpi_get_str(vpiName
, obj
) : ".", rc
);
172 PLI_INT32
tf_gettimeunit()
174 vpiHandle hand
= vpi_handle(vpiScope
, vpi_handle(vpiSysTfCall
,0));
175 return vpi_get(vpiTimeUnit
, hand
);
178 PLI_INT32
tf_igettimeunit(void*obj
)
180 return vpi_get(!obj
? vpiTimePrecision
: vpiTimeUnit
, (vpiHandle
)obj
);
185 * $Log: getsimtime.c,v $
186 * Revision 1.11 2003/06/21 23:40:15 steve
187 * gettimeprecision will null argument has specific meaning.
189 * Revision 1.10 2003/06/13 19:23:42 steve
190 * Add a bunch more PLI1 routines.
192 * Revision 1.9 2003/06/04 01:56:20 steve
193 * 1) Adds configure logic to clean up compiler warnings
194 * 2) adds acc_compare_handle, acc_fetch_range, acc_next_scope and
195 * tf_isetrealdelay, acc_handle_scope
196 * 3) makes acc_next reentrant
197 * 4) adds basic vpiWire type support
198 * 5) fills in some acc_object_of_type() and acc_fetch_{full}type()
199 * 6) add vpiLeftRange/RigthRange to signals
201 * Revision 1.8 2003/05/30 04:01:55 steve
202 * Add tf_scale_longdelay.
204 * Revision 1.7 2003/05/28 03:14:20 steve
205 * Missing time related declarations.
207 * Revision 1.6 2003/05/27 16:22:10 steve
208 * PLI get time units/precision.
210 * Revision 1.5 2003/04/12 18:57:14 steve
211 * More acc_ function stubs.
213 * Revision 1.4 2003/03/13 04:35:09 steve
214 * Add a bunch of new acc_ and tf_ functions.
216 * Revision 1.3 2003/03/06 00:27:54 steve
217 * Fill in required fields when getting time.
219 * Revision 1.2 2002/08/12 01:35:02 steve
220 * conditional ident string using autoconfig.
222 * Revision 1.1 2002/05/31 18:25:51 steve
223 * Add tf_getlongtime (mruff)