Clean up warnings for round() function declaration.
[iverilog.git] / libveriuser / delay.c
blob2e8972722f1436814d5121f3004a135050afeacd
1 /*
2 * Copyright (c) 2003 Stephen Williams (steve@icarus.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)
8 * any later version.
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
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: delay.c,v 1.3 2003/06/17 16:55:07 steve Exp $"
21 #endif
23 #include <veriuser.h>
24 #include <vpi_user.h>
25 #include "priv.h"
26 #include <assert.h>
28 static PLI_INT32 delay_callback(struct t_cb_data*cb)
30 vpi_printf("XXXX delay_callback called.\n");
31 return 0;
34 int tf_isetdelay(PLI_INT32 delay, void*ss)
36 vpiHandle sys = (vpiHandle)ss;
37 int unit = vpi_get(vpiTimeUnit, sys);
38 int prec = vpi_get(vpiTimePrecision, 0);
40 struct t_cb_data cb;
41 struct t_vpi_time ct;
43 if (pli_trace) {
44 fprintf(pli_trace, "%s: tf_isetdelay(%d, ...)"
45 " <unit=%d, prec=%d>;\n",
46 vpi_get_str(vpiName, sys), delay, unit, prec);
50 /* Convert the delay from the UNITS of the specified
51 task/function to the precision of the simulation. */
52 assert(unit >= prec);
54 while (unit > prec) {
55 PLI_INT32 tmp = delay * 10;
56 assert(tmp > delay);
57 delay = tmp;
58 unit -= 1;
61 /* Create a VPI callback to schedule the delay. */
62 ct.type = vpiSimTime;
63 ct.high = 0;
64 ct.low = delay;
66 cb.reason = cbAfterDelay;
67 cb.cb_rtn = delay_callback;
68 cb.obj = 0;
69 cb.time = &ct;
70 cb.value = 0;
71 cb.user_data = 0;
72 vpi_register_cb(&cb);
74 return 0;
77 int tf_setdelay(PLI_INT32 delay)
79 return tf_isetdelay(delay, tf_getinstance());
83 * $Log: delay.c,v $
84 * Revision 1.3 2003/06/17 16:55:07 steve
85 * 1) setlinebuf() for vpi_trace
86 * 2) Addes error checks for trace file opens
87 * 3) removes now extraneous flushes
88 * 4) fixes acc_next() bug
90 * Revision 1.2 2003/05/28 02:42:43 steve
91 * compiler warnings.
93 * Revision 1.1 2003/05/18 00:16:35 steve
94 * Add PLI_TRACE tracing of PLI1 modules.
96 * Add tf_isetdelay and friends, and add
97 * callback return values for acc_vcl support.