2022-07-05 21:24:43 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022 Jevin Sweval (jevinsweval@gmail.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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "vpi_user.h"
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
2024-02-05 19:17:53 +01:00
|
|
|
#if defined(TEST_SIM_TIME)
|
|
|
|
|
#define TIME_TYPE vpiSimTime
|
|
|
|
|
#elif defined(TEST_SCALED_TIME)
|
|
|
|
|
#define TIME_TYPE vpiScaledRealTime
|
|
|
|
|
#else
|
|
|
|
|
#define TIME_TYPE vpiSuppressTime
|
|
|
|
|
#endif
|
2022-07-05 21:24:43 +02:00
|
|
|
|
2024-02-05 19:17:53 +01:00
|
|
|
#ifndef TEST_NULL_TIME
|
|
|
|
|
static s_vpi_time cb_timerec = {TIME_TYPE, 0, 0, 0};
|
|
|
|
|
#endif
|
2022-07-05 21:24:43 +02:00
|
|
|
|
|
|
|
|
static PLI_INT32 register_nextsimtime(struct t_cb_data* cb);
|
|
|
|
|
|
2024-02-05 19:17:53 +01:00
|
|
|
|
2022-07-05 21:24:43 +02:00
|
|
|
static PLI_INT32 nextsimtime_cb(struct t_cb_data* cb) {
|
|
|
|
|
s_vpi_time timerec;
|
2024-02-05 19:17:53 +01:00
|
|
|
#ifdef TEST_SCALED_TIME
|
|
|
|
|
timerec.type = vpiScaledRealTime;
|
|
|
|
|
#else
|
2022-07-05 21:24:43 +02:00
|
|
|
timerec.type = vpiSimTime;
|
2024-02-05 19:17:53 +01:00
|
|
|
#endif
|
2022-07-05 21:24:43 +02:00
|
|
|
vpi_get_time(NULL, &timerec);
|
2024-02-05 19:17:53 +01:00
|
|
|
#ifdef TEST_SCALED_TIME
|
|
|
|
|
vpi_printf("nextsimtime: %f vpi_get_time: %f\n",
|
|
|
|
|
cb->time->real, timerec.real);
|
|
|
|
|
#else
|
|
|
|
|
uint64_t nextsimtime = ((uint64_t)cb->time->high << 32) | cb->time->low;
|
2022-07-05 21:24:43 +02:00
|
|
|
uint64_t time = ((uint64_t)timerec.high << 32) | timerec.low;
|
|
|
|
|
vpi_printf("nextsimtime: %" PLI_UINT64_FMT " vpi_get_time: %" PLI_UINT64_FMT "\n",
|
|
|
|
|
nextsimtime, time);
|
2024-02-05 19:17:53 +01:00
|
|
|
#endif
|
2022-07-05 21:24:43 +02:00
|
|
|
register_nextsimtime(NULL);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PLI_INT32 register_nextsimtime(struct t_cb_data* cb) {
|
|
|
|
|
(void)cb; /* unused */
|
|
|
|
|
s_cb_data cb_data;
|
2024-02-05 19:17:53 +01:00
|
|
|
#ifdef TEST_NULL_TIME
|
|
|
|
|
cb_data.time = 0;
|
|
|
|
|
#else
|
2022-07-05 21:24:43 +02:00
|
|
|
cb_data.time = &cb_timerec;
|
2024-02-05 19:17:53 +01:00
|
|
|
#endif
|
|
|
|
|
#ifdef TEST_SCALED_TIME
|
|
|
|
|
cb_data.obj = vpi_handle_by_name("main", NULL);
|
|
|
|
|
#else
|
|
|
|
|
cb_data.obj = 0;
|
|
|
|
|
#endif
|
2022-07-05 21:24:43 +02:00
|
|
|
cb_data.reason = cbNextSimTime;
|
|
|
|
|
cb_data.cb_rtn = nextsimtime_cb;
|
|
|
|
|
vpiHandle hndl = NULL;
|
|
|
|
|
assert((hndl = vpi_register_cb(&cb_data)) && vpi_free_object(hndl));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void register_functions(void)
|
|
|
|
|
{
|
|
|
|
|
s_cb_data cb_data;
|
|
|
|
|
cb_data.reason = cbEndOfCompile;
|
|
|
|
|
cb_data.cb_rtn = register_nextsimtime;
|
|
|
|
|
vpi_register_cb(&cb_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void (*vlog_startup_routines[])(void) = {
|
|
|
|
|
register_functions,
|
|
|
|
|
NULL
|
|
|
|
|
};
|