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)
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: a_vcl.c,v 1.7 2004/10/04 01:10:56 steve Exp $"
33 * This is the structure of a record that I use locally to hold the
34 * information about a VCL. This record includes a pointer to the vpi
35 * callback that is actually watching the value, and that callback has
36 * a pointer to this record in its user_data so that I can get to it
37 * when the value changes.
39 * Keep all these records in a vcl_list so that I can get access to
40 * them for the vcl_delete.
43 /* Object who's value I'm watching. */
45 /* User's callback routine. */
46 PLI_INT32(*consumer
)(p_vc_record
);
52 struct vcl_record
*next
;
55 static struct vcl_record
*vcl_list
= 0;
57 static int vpi_strength_to_vcl(int vs
)
82 * This is a VPI callback that notices the value change. This function
83 * further dispatches the information about the callback to the
86 static PLI_INT32
vcl_value_callback(struct t_cb_data
*cb
)
89 s_vpi_value obj_value
;
90 struct t_vc_record vcr
;
91 struct vcl_record
*cur
= (struct vcl_record
*)cb
->user_data
;
93 sim_time
.type
= vpiSimTime
;
94 vpi_get_time(cur
->obj
, &sim_time
);
96 switch (cur
->vcl_flag
) {
97 case VCL_VERILOG_LOGIC
:
98 vpi_printf("XXXX vcl_value_callback(%s=%d);\n",
99 vpi_get_str(vpiName
, cur
->obj
), -1);
101 vcr
.vc_reason
= logic_value_change
;
104 case VCL_VERILOG_STRENGTH
:
105 vcr
.vc_reason
= strength_value_change
;
106 obj_value
.format
= vpiStrengthVal
;
107 vpi_get_value(cur
->obj
, &obj_value
);
108 assert(obj_value
.format
== vpiStrengthVal
);
109 switch (obj_value
.value
.strength
[0].logic
) {
111 vcr
.out_value
.strengths_s
.logic_value
= acc0
;
112 vcr
.out_value
.strengths_s
.strength1
=
113 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s0
);
114 vcr
.out_value
.strengths_s
.strength2
=
115 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s0
);
118 vcr
.out_value
.strengths_s
.logic_value
= acc1
;
119 vcr
.out_value
.strengths_s
.strength1
=
120 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s1
);
121 vcr
.out_value
.strengths_s
.strength2
=
122 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s1
);
125 vcr
.out_value
.strengths_s
.logic_value
= accX
;
126 vcr
.out_value
.strengths_s
.strength1
=
127 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s1
);
128 vcr
.out_value
.strengths_s
.strength2
=
129 vpi_strength_to_vcl(obj_value
.value
.strength
[0].s0
);
132 vcr
.out_value
.strengths_s
.logic_value
= accZ
;
133 vcr
.out_value
.strengths_s
.strength1
= vclHighZ
;
134 vcr
.out_value
.strengths_s
.strength2
= vclHighZ
;
142 "Call vcl_value_callback(%s=%d <s1=%d,s2=%d>)\n",
143 vpi_get_str(vpiFullName
, cur
->obj
),
144 vcr
.out_value
.strengths_s
.logic_value
,
145 vcr
.out_value
.strengths_s
.strength1
,
146 vcr
.out_value
.strengths_s
.strength2
);
154 vcr
.vc_hightime
= sim_time
.high
;
155 vcr
.vc_lowtime
= sim_time
.low
;
156 vcr
.user_data
= cur
->user_data
;
158 (cur
->consumer
) (&vcr
);
162 void acc_vcl_add(handle obj
, PLI_INT32(*consumer
)(p_vc_record
),
163 void*data
, PLI_INT32 vcl_flag
)
165 struct vcl_record
*cur
;
168 switch (vpi_get(vpiType
, obj
)) {
170 cur
= malloc(sizeof (struct vcl_record
));
172 cur
->consumer
= consumer
;
173 cur
->user_data
= data
;
174 cur
->vcl_flag
= vcl_flag
;
175 cur
->next
= vcl_list
;
178 cb
.reason
= cbValueChange
;
179 cb
.cb_rtn
= vcl_value_callback
;
183 cb
.user_data
= (void*)cur
;
184 cur
->callback
= vpi_register_cb(&cb
);
187 fprintf(pli_trace
, "acc_vcl_add(<%s>, ..., %p, %d)\n",
188 vpi_get_str(vpiFullName
, obj
), data
, vcl_flag
);
193 vpi_printf("XXXX acc_vcl_add(<type=%d>, ..., %d);\n",
194 vpi_get(vpiType
, obj
), vcl_flag
);
200 void acc_vcl_delete(handle obj
, PLI_INT32(*consumer
)(p_vc_record
),
201 void*data
, PLI_INT32 vcl_flag
)
203 vpi_printf("XXXX acc_vcl_delete(...)\n");
209 * Revision 1.7 2004/10/04 01:10:56 steve
210 * Clean up spurious trailing white space.
212 * Revision 1.6 2003/06/17 16:55:07 steve
213 * 1) setlinebuf() for vpi_trace
214 * 2) Addes error checks for trace file opens
215 * 3) removes now extraneous flushes
216 * 4) fixes acc_next() bug
218 * Revision 1.5 2003/05/18 00:16:35 steve
219 * Add PLI_TRACE tracing of PLI1 modules.
221 * Add tf_isetdelay and friends, and add
222 * callback return values for acc_vcl support.
224 * Revision 1.4 2003/04/30 01:09:29 steve
225 * Conditionally include malloc.h
227 * Revision 1.3 2003/04/24 02:02:37 steve
228 * Clean up some simple warnings.
230 * Revision 1.2 2003/04/20 02:48:39 steve
231 * Support value change callbacks.
233 * Revision 1.1 2003/04/12 18:57:14 steve
234 * More acc_ function stubs.