1999-10-28 02:47:24 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1999 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
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT)
|
1999-10-28 06:47:57 +02:00
|
|
|
#ident "$Id: vpi_callback.c,v 1.2 1999/10/28 04:47:57 steve Exp $"
|
1999-10-28 02:47:24 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
|
|
|
|
static struct __vpirt vpip_callback_rt = {
|
|
|
|
|
vpiCallback,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
1999-10-28 06:47:57 +02:00
|
|
|
/*
|
|
|
|
|
* This function is called by the scheduler to execute an event of
|
|
|
|
|
* some sort. The parameter is a vpiHandle of the callback that is to
|
|
|
|
|
* be executed.
|
|
|
|
|
*/
|
1999-10-28 02:47:24 +02:00
|
|
|
static void vpip_call_callback(void*cp)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiCallback*rfp = (struct __vpiCallback*)cp;
|
|
|
|
|
assert(rfp->base.vpi_type->type_code == vpiCallback);
|
|
|
|
|
rfp->cb_data.cb_rtn(&rfp->cb_data);
|
|
|
|
|
free(rfp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
1999-10-28 06:47:57 +02:00
|
|
|
* Register callbacks. This supports a variety of callback reasons.
|
1999-10-28 02:47:24 +02:00
|
|
|
*/
|
|
|
|
|
vpiHandle vpi_register_cb(p_cb_data data)
|
|
|
|
|
{
|
1999-10-28 06:47:57 +02:00
|
|
|
unsigned long tim;
|
1999-10-28 02:47:24 +02:00
|
|
|
struct __vpiCallback*rfp = calloc(1, sizeof(struct __vpiCallback));
|
|
|
|
|
rfp->base.vpi_type = &vpip_callback_rt;
|
|
|
|
|
rfp->cb_data = *data;
|
|
|
|
|
|
|
|
|
|
switch (data->reason) {
|
|
|
|
|
case cbReadOnlySynch:
|
|
|
|
|
assert(data->time);
|
|
|
|
|
assert(data->time->type == vpiSimTime);
|
|
|
|
|
assert(data->time->high == 0);
|
1999-10-28 06:47:57 +02:00
|
|
|
tim = data->time->low;
|
|
|
|
|
rfp->ev = vpip_sim_insert_event(tim, rfp, vpip_call_callback, 1);
|
1999-10-28 02:47:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &(rfp->base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int vpi_remove_cb(vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiCallback*rfp = (struct __vpiCallback*)ref;
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiCallback);
|
|
|
|
|
vpip_sim_cancel_event(rfp->ev);
|
|
|
|
|
free(rfp);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vpi_callback.c,v $
|
1999-10-28 06:47:57 +02:00
|
|
|
* Revision 1.2 1999/10/28 04:47:57 steve
|
|
|
|
|
* Support delay in constSync callback.
|
|
|
|
|
*
|
1999-10-28 02:47:24 +02:00
|
|
|
* Revision 1.1 1999/10/28 00:47:25 steve
|
|
|
|
|
* Rewrite vvm VPI support to make objects more
|
|
|
|
|
* persistent, rewrite the simulation scheduler
|
|
|
|
|
* in C (to interface with VPI) and add VPI support
|
|
|
|
|
* for callbacks.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|