2001-03-31 21:00:43 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
|
|
|
|
#ident "$Id: vpi_time.cc,v 1.8 2002/08/12 01:35:09 steve Exp $"
|
2001-03-31 21:00:43 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "schedule.h"
|
2001-04-03 05:46:14 +02:00
|
|
|
# include <stdio.h>
|
2001-03-31 21:00:43 +02:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
2001-07-01 01:03:16 +02:00
|
|
|
|
|
|
|
|
static int vpi_time_precision = 0;
|
|
|
|
|
|
2002-04-20 06:33:23 +02:00
|
|
|
void vpip_time_to_timestruct(struct t_vpi_time*ts, vvp_time64_t ti)
|
|
|
|
|
{
|
|
|
|
|
ts->low = ti & 0xFFFFFFFF;
|
|
|
|
|
ts->high = (ti >> 32) & 0xFFFFFFFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_time64_t vpip_timestruct_to_time(const struct t_vpi_time*ts)
|
|
|
|
|
{
|
|
|
|
|
vvp_time64_t ti = ts->high;
|
|
|
|
|
ti <<= 32;
|
|
|
|
|
ti += ts->low & 0xffffffff;
|
|
|
|
|
return ti;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-31 21:00:43 +02:00
|
|
|
static struct __vpiSystemTime {
|
|
|
|
|
struct __vpiHandle base;
|
|
|
|
|
struct t_vpi_time value;
|
|
|
|
|
} time_handle;
|
|
|
|
|
|
2002-01-15 04:06:29 +01:00
|
|
|
static int timevar_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiSize:
|
|
|
|
|
return 64;
|
|
|
|
|
|
|
|
|
|
case vpiSigned:
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Code: %d\n", code);
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-31 21:00:43 +02:00
|
|
|
static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
|
|
|
|
|
{
|
2001-04-03 05:46:14 +02:00
|
|
|
static char buf_obj[128];
|
2001-03-31 21:00:43 +02:00
|
|
|
assert(ref == &time_handle.base);
|
2001-08-16 05:29:31 +02:00
|
|
|
unsigned long x, num_bits;
|
2001-03-31 21:00:43 +02:00
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
case vpiTimeVal:
|
|
|
|
|
vp->value.time = &time_handle.value;
|
|
|
|
|
vp->value.time->type = vpiSimTime;
|
2002-04-20 06:33:23 +02:00
|
|
|
vpip_time_to_timestruct(vp->value.time, schedule_simtime());
|
2001-03-31 21:00:43 +02:00
|
|
|
vp->format = vpiTimeVal;
|
|
|
|
|
break;
|
|
|
|
|
|
2001-08-16 05:29:31 +02:00
|
|
|
case vpiBinStrVal:
|
|
|
|
|
x = schedule_simtime();
|
|
|
|
|
num_bits = 8 * sizeof(unsigned long);
|
|
|
|
|
|
|
|
|
|
buf_obj[num_bits] = 0;
|
2001-10-15 04:55:03 +02:00
|
|
|
for (unsigned i = 1; i <= num_bits; i++) {
|
2001-08-16 05:29:31 +02:00
|
|
|
buf_obj[num_bits-i] = x & 1 ? '1' : '0';
|
|
|
|
|
x = x >> 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vp->value.str = buf_obj;
|
|
|
|
|
break;
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
case vpiDecStrVal:
|
|
|
|
|
sprintf(buf_obj, "%lu", schedule_simtime());
|
|
|
|
|
vp->value.str = buf_obj;
|
|
|
|
|
break;
|
|
|
|
|
|
2001-08-16 05:29:31 +02:00
|
|
|
case vpiOctStrVal:
|
|
|
|
|
sprintf(buf_obj, "%lo", schedule_simtime());
|
|
|
|
|
vp->value.str = buf_obj;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal:
|
|
|
|
|
sprintf(buf_obj, "%lx", schedule_simtime());
|
|
|
|
|
vp->value.str = buf_obj;
|
|
|
|
|
break;
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vpi_time: unknown format: %d\n", vp->format);
|
|
|
|
|
assert(0);
|
2001-03-31 21:00:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_system_time_rt = {
|
|
|
|
|
vpiTimeVar,
|
2002-01-15 04:06:29 +01:00
|
|
|
timevar_get,
|
2001-03-31 21:00:43 +02:00
|
|
|
0,
|
|
|
|
|
timevar_get_value,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vpiHandle vpip_sim_time(void)
|
|
|
|
|
{
|
|
|
|
|
time_handle.base.vpi_type = &vpip_system_time_rt;
|
|
|
|
|
return &time_handle.base;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-01 01:03:16 +02:00
|
|
|
int vpip_get_time_precision(void)
|
|
|
|
|
{
|
|
|
|
|
return vpi_time_precision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vpip_set_time_precision(int pre)
|
|
|
|
|
{
|
|
|
|
|
vpi_time_precision = pre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-31 21:00:43 +02:00
|
|
|
/*
|
|
|
|
|
* $Log: vpi_time.cc,v $
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.8 2002/08/12 01:35:09 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-04-20 06:33:23 +02:00
|
|
|
* Revision 1.7 2002/04/20 04:33:23 steve
|
|
|
|
|
* Support specified times in cbReadOnlySync, and
|
|
|
|
|
* add support for cbReadWriteSync.
|
|
|
|
|
* Keep simulation time in a 64bit number.
|
|
|
|
|
*
|
2002-01-15 04:06:29 +01:00
|
|
|
* Revision 1.6 2002/01/15 03:06:29 steve
|
|
|
|
|
* Support vpiSize and vpiSigned for time objects.
|
|
|
|
|
*
|
2001-10-15 04:55:03 +02:00
|
|
|
* Revision 1.5 2001/10/15 02:55:03 steve
|
|
|
|
|
* sign warning.
|
|
|
|
|
*
|
2001-08-16 05:29:31 +02:00
|
|
|
* Revision 1.4 2001/08/16 03:29:31 steve
|
|
|
|
|
* Support various other string formats for time.
|
|
|
|
|
*
|
2001-07-01 01:03:16 +02:00
|
|
|
* Revision 1.3 2001/06/30 23:03:17 steve
|
|
|
|
|
* support fast programming by only writing the bits
|
|
|
|
|
* that are listed in the input file.
|
|
|
|
|
*
|
2001-04-03 05:46:14 +02:00
|
|
|
* Revision 1.2 2001/04/03 03:46:14 steve
|
|
|
|
|
* VPI access time as a decimal string, and
|
|
|
|
|
* stub vpi access to the scopes.
|
|
|
|
|
*
|
2001-03-31 21:00:43 +02:00
|
|
|
* Revision 1.1 2001/03/31 19:00:44 steve
|
|
|
|
|
* Add VPI support for the simulation time.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|