2 * Copyright (c) 1999 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)
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: vpi_callback.c,v 1.2 2002/08/12 01:35:05 steve Exp $"
23 # include "vpi_priv.h"
27 static struct __vpirt vpip_callback_rt
= {
38 * This function is called by the scheduler to execute an event of
39 * some sort. The parameter is a vpiHandle of the callback that is to
42 static void vpip_call_callback(void*cp
)
45 struct __vpiCallback
*rfp
= (struct __vpiCallback
*)cp
;
46 assert(rfp
->base
.vpi_type
->type_code
== vpiCallback
);
48 switch (rfp
->cb_data
.time
->type
) {
50 case vpiScaledRealTime
: /* XXXX not supported */
54 now
= ((struct __vpiTimeVar
*)vpip_sim_time())->time
;
55 rfp
->cb_data
.time
->low
= now
;
56 rfp
->cb_data
.time
->high
= 0;
60 rfp
->cb_data
.cb_rtn(&rfp
->cb_data
);
65 * This function is called by the product when it changes the value of
66 * a signal. It arranges for all the value chance callbacks to be
69 void vpip_run_value_changes(struct __vpiSignal
*sig
)
71 struct __vpiCallback
*cur
;
75 sig
->mfirst
= cur
->next
;
79 cur
->ev
= vpip_sim_insert_event(0, cur
, vpip_call_callback
, 0);
84 * Handle read-only synch events. This causes the callback to be
85 * scheduled for a moment at the end of the time period. This method
86 * handles scheduling with itme delays.
88 static void go_readonly_synch(struct __vpiCallback
*rfp
)
91 assert(rfp
->cb_data
.time
);
92 assert(rfp
->cb_data
.time
->type
== vpiSimTime
);
93 assert(rfp
->cb_data
.time
->high
== 0);
94 tim
= rfp
->cb_data
.time
->low
;
95 rfp
->ev
= vpip_sim_insert_event(tim
, rfp
, vpip_call_callback
, 1);
99 * To schedule a value change, attach the callback to the signal to me
100 * monitored. I'll be inserted as an event later.
102 static void go_value_change(struct __vpiCallback
*rfp
)
104 struct __vpiSignal
*sig
= (struct __vpiSignal
*)rfp
->cb_data
.obj
;
105 assert((sig
->base
.vpi_type
->type_code
== vpiReg
)
106 || (sig
->base
.vpi_type
->type_code
== vpiNet
));
109 /* If there are no monitor events, start the list. */
110 if (sig
->mfirst
== 0) {
118 /* Put me at the end of the list. Remember that the monitor
119 points to the *last* item in the list. */
122 sig
->mlast
->next
= rfp
;
126 * Register callbacks. This supports a variety of callback reasons,
127 * mostly by dispatching them to a type specific handler.
129 vpiHandle
vpi_register_cb(p_cb_data data
)
131 struct __vpiCallback
*rfp
= calloc(1, sizeof(struct __vpiCallback
));
132 rfp
->base
.vpi_type
= &vpip_callback_rt
;
133 rfp
->cb_data
= *data
;
135 switch (data
->reason
) {
136 case cbReadOnlySynch
:
137 go_readonly_synch(rfp
);
141 go_value_change(rfp
);
152 int vpi_remove_cb(vpiHandle ref
)
154 struct __vpiCallback
*rfp
= (struct __vpiCallback
*)ref
;
155 assert(ref
->vpi_type
->type_code
== vpiCallback
);
159 /* callbacks attached to events are easy. */
160 vpip_sim_cancel_event(rfp
->ev
);
162 } else if (rfp
->sig
) {
164 /* callbacks to signals need to be removed from the
165 signal's list of monitor callbacks. */
166 struct __vpiSignal
*sig
= rfp
->sig
;
168 if (sig
->mfirst
== rfp
) {
169 sig
->mfirst
= rfp
->next
;
170 if (sig
->mfirst
== 0)
175 struct __vpiCallback
*cur
= sig
->mfirst
;
176 while (cur
->next
!= rfp
) {
180 cur
->next
= rfp
->next
;
193 * $Log: vpi_callback.c,v $
194 * Revision 1.2 2002/08/12 01:35:05 steve
195 * conditional ident string using autoconfig.
197 * Revision 1.1 2001/03/14 19:27:44 steve
198 * Rearrange VPI support libraries.
200 * Revision 1.8 2000/08/20 17:49:05 steve
201 * Clean up warnings and portability issues.
203 * Revision 1.7 2000/03/31 07:08:39 steve
204 * allow cancelling of cbValueChange events.
206 * Revision 1.6 2000/02/23 02:56:56 steve
207 * Macintosh compilers do not support ident.
209 * Revision 1.5 1999/12/15 04:01:14 steve
210 * Add the VPI implementation of $readmemh.
212 * Revision 1.4 1999/11/07 20:33:30 steve
213 * Add VCD output and related system tasks.
215 * Revision 1.3 1999/10/29 03:37:22 steve
216 * Support vpiValueChance callbacks.
218 * Revision 1.2 1999/10/28 04:47:57 steve
219 * Support delay in constSync callback.
221 * Revision 1.1 1999/10/28 00:47:25 steve
222 * Rewrite vvm VPI support to make objects more
223 * persistent, rewrite the simulation scheduler
224 * in C (to interface with VPI) and add VPI support