Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / tas / sim / simx.h
1 /*****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI AVERTEC */
4 /* */
5 /* Produit : SIM Version 2.00 */
6 /* Fichier : sim100.h */
7 /* */
8 /* (c) copyright 2000 AVERTEC */
9 /* Tous droits reserves */
10 /* */
11 /* Auteur(s) : Gilles Augustins */
12 /* Grégoire Avot */
13 /* */
14 /*****************************************************************************/
15
16 #ifndef SIM_HEADER
17 #define SIM_HEADER
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <math.h>
22 #include <limits.h>
23 #include <string.h>
24 #include <time.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <sys/stat.h>
28 #include <sys/time.h>
29 #include <sys/resource.h>
30 #include <signal.h>
31 #include <ctype.h>
32
33 #include MUT_H
34 #include MLO_H
35 #include RCN_H
36 #include BEH_H
37 #include LOG_H
38 #include CNS_H
39 #include GSP_H
40 #include EFG_H
41 #include MSL_H
42 #include MLU_H
43
44 #ifdef AVERTEC
45 #include AVT_H
46 #endif
47
48
49 extern int SIM_OUTLOAD;
50 extern char *SIM_SPICE_OPTIONS;
51 extern double SIM_OUT_CAPA_VAL;
52 extern double SIM_INPUT_START;
53 extern double SIM_TECSIZE;
54 extern double SIM_VTH;
55 extern double SIM_VTH_HIGH;
56 extern double SIM_VTH_LOW;
57 extern double SIM_SLOP;
58 extern double SIM_SIMU_STEP;
59 extern double SIM_DC_STEP;
60 extern char *SIM_SPICESTRING;
61 extern char *SIM_SPICEOUT;
62 extern char *SIM_SPICENAME;
63 extern char *SIM_SPICESTDOUT;
64 extern char *SIM_TECHFILE;
65 extern int SIM_SPI_TRANSISTOR_AS_INSTANCE;
66 extern void *SIM_EXTRACT_RULE;
67 extern char SIM_DEFAULT_DRIVE_NETLIST ;
68 extern char SIM_DEFAULT_OVR_FILES ;
69 extern char SIM_DEFAULT_REMOVE_FILES ;
70 extern float SIM_VT_SLOPEIN;
71
72 /* Labels for measure */
73 #define SIM_DELAY_LABEL_STRING ((char*)"SIM_DELAY")
74 #define SIM_SLOPE_LABEL_STRING ((char*)"SIM_SLOPE")
75 #define SIM_DELAY_LABEL ((long)0xFF000002)
76 #define SIM_SLOPE_LABEL ((long)0xFF000003)
77 #define SIM_RC_DELAY_LABEL ((long)0xFF000000)
78 #define SIM_RC_SLOPE_LABEL ((long)0xFF000001)
79 #define SIM_LOOP_FEEDBACK_DELAY_LABEL "sim_loop_feed_back_delay"
80 #define SIM_LOOP_FEEDBACK_DELAY_PTYPE 0xFF000004
81 #define SIM_DELAY_TO_VT_LABEL "sim_command_delay_to_vt"
82 #define SIM_DELAY_TO_VT_PTYPE 0xFF000005
83
84 /* Precision for calcul and storage of real number */
85 #define SIM_FLOAT double
86
87 typedef SIM_FLOAT (*PWL_FUNCTION) (SIM_FLOAT, void *);
88
89 /* Different outload type */
90
91 #define SIM_NO_OUTLOAD ((int)0)
92 #define SIM_DYNAMIC_OUTLOAD ((int)1)
93 #define SIM_TRANSISTOR_OUTLOAD ((int)2)
94
95 /* Model of simulator - for netlist & technology interpretation */
96 #define SIM_TOOLMODEL_SPICE ((int)0) /* Berkeley or old ngspice */
97 #define SIM_TOOLMODEL_HSPICE ((int)1) /* Hspice family */
98 #define SIM_TOOLMODEL_ELDO ((int)2) /* Eldo family */
99 #define SIM_TOOLMODEL_TITAN ((int)3) /* Titan family */
100
101 /* Simulator - for external simulator linking */
102 #define SIM_TOOL_SPICE ((int)0) /* Berkeley or old Ngspice */
103 #define SIM_TOOL_HSPICE ((int)1) /* Hspice */
104 #define SIM_TOOL_ELDO ((int)2) /* Eldo */
105 #define SIM_TOOL_TITAN ((int)3) /* Titan */
106 #define SIM_TOOL_TITAN7 ((int)4) /* Titanv7 */
107 #define SIM_TOOL_LTSPICE ((int)5) /* Ltspice */
108 #define SIM_TOOL_MSPICE ((int)6) /* Mspice */
109 #define SIM_TOOL_NGSPICE ((int)7) /* Ngspice */
110
111 /* Logical value */
112 #define SIM_ZERO ((char)'0')
113 #define SIM_ONE ((char)'1')
114
115 /* Configuration */
116 #define SIM_YES ((char)'y')
117 #define SIM_NO ((char)'n')
118
119 /* Input description */
120 #define SIM_STUCK ((char)'t') /* Constant input */
121 #define SIM_SLOPE ((char)'s') /* Slope */
122 #define SIM_FUNC ((char)'f') /* Function */
123 #define SIM_MIMIC ((char)'m') /* Mimic */
124 #define SIM_NC ((char)'z') /* Not connected */
125
126 #define SIM_INPUT_SIGNAL ((char)'s')
127 #define SIM_INPUT_LOCON ((char)'l')
128
129 /* Measure description */
130 #define SIM_MEASURE_SIGNAL ((char)'s')
131 //#define SIM_MEASURE_SIGNAL_NODE ((char)'n')
132 #define SIM_MEASURE_LOCON ((char)'l')
133
134 /* Measured value */
135 #define SIM_MEASURE_VOLTAGE ((char)'v')
136 #define SIM_MEASURE_CURRENT ((char)'i')
137 #define SIM_MEASURE_NO ((char)'n')
138 #define SIM_MEASURE_LAST ((long) 1000000)
139
140 /* Stuck description */
141 #define SIM_STUCK_LEVEL ((char)'l') /* Logical 0 or 1 input */
142 #define SIM_STUCK_VALUE ((char)'v') /* Constant voltage generator */
143
144 /* Slope description */
145 #define SIM_SLOPE_SINGLE ((char)'s') /* Single slope */
146 #define SIM_SLOPE_PATTERN ((char)'p') /* Multiple splopes */
147
148 /* Return code from execution */
149 #define SIM_SIMU_COMPLETED ((char)'y')
150 #define SIM_SIMU_CANTRUN ((char)'n')
151 #define SIM_SIMU_NONIMPLEMENTED ((char)'i')
152 #define SIM_SIMU_CANTDRIVEFILE ((char)'f')
153
154 /* Define for ICs */
155 #define SIM_IC_LEVEL ((char)'l')
156 #define SIM_IC_VOLTAGE ((char)'v')
157 #define SIM_IC_NOIC ((char)'n')
158
159 #define SIM_IC_LOCON ((char)'c')
160 #define SIM_IC_SIGNAL ((char)'s')
161 //#define SIM_IC_SIGNAL_NODE ((char)'n')
162
163 /* Unit management */
164 #define SIM_UNIT_TIME ((SIM_FLOAT)1.0)
165 #define SIM_UNIT_LABEL_SPICE_TIME "s"
166 #define SIM_UNIT_CAPACITANCE ((SIM_FLOAT)1.0)
167 #define SIM_UNIT_LABEL_SPICE_CAPACITANCE "F"
168 #define SIM_UNIT_RESISTANCE ((SIM_FLOAT)1.0)
169 #define SIM_UNIT_LABEL_SPICE_RESISTANCE ""
170 #define SIM_UNIT_VOLTAGE ((SIM_FLOAT)1.0)
171 #define SIM_UNIT_LABEL_SPICE_VOLTAGE "V"
172
173 #define SIM_UNIT_X_TO_Y(x,unitx,unity) ((x)*(unitx)/(unity))
174
175 #define SIM_FALL 'D'
176 #define SIM_RISE 'U'
177
178 #define SIM_RAMP 'r'
179 #define SIM_TANH 't'
180
181 #define SIM_MIN 'm'
182 #define SIM_MAX 'M'
183 #define SIM_ALL 'A'
184
185 #define SIM_RUN_DRIVE 1
186 #define SIM_RUN_EXEC 2
187 #define SIM_RUN_READ 4
188 #define SIM_RUN_MULTI 8
189 #define SIM_RUN_ALL (SIM_RUN_DRIVE|SIM_RUN_READ|SIM_RUN_EXEC)
190
191 #define SIM_EXT_CAPA 0xfab11105
192 /* Definition of stuck */
193 typedef struct {
194 char VALUE; // SIM_ZERO, SIM_ONE
195 } sim_stuck_level;
196
197 typedef struct {
198 SIM_FLOAT VALUE;
199 } sim_stuck_voltage;
200
201 typedef union {
202 sim_stuck_voltage STUCK_VOLTAGE;
203 sim_stuck_level STUCK_LEVEL;
204 } sim_ustuck;
205
206 typedef struct {
207 char TYPE; // SIM_STUCK_LEVEL, SIM_STUCK_VALUE
208 sim_ustuck MODEL;
209 } sim_stuck;
210
211 /* Definition of slope */
212 typedef struct {
213 char TRANSITION; // SIM_RISE, SIM_FALL
214 SIM_FLOAT TRISE;
215 SIM_FLOAT TSTART;
216 } sim_slope_single;
217
218 typedef struct {
219 SIM_FLOAT TRISE;
220 SIM_FLOAT TFALL;
221 SIM_FLOAT PERIOD;
222 char *PATTERN;
223 } sim_slope_pattern;
224
225 typedef union {
226 sim_slope_single SLOPE_SINGLE;
227 sim_slope_pattern SLOPE_PATTERN;
228 } sim_uslope;
229
230 typedef struct {
231 char TYPE; // SIM_SLOPE_SINGLE, SIM_SLOPE_PATTERN
232 sim_uslope MODEL;
233 } sim_slope;
234
235 typedef struct {
236 SIM_FLOAT (*FUNC)(SIM_FLOAT t, void *data);
237 void *USER_DATA;
238 } sim_func;
239
240 typedef struct {
241 char *REF_VSSNODE;
242 char *REF_VDDNODE;
243 char *REF_NODE;
244 int revert;
245 } sim_mimic_voltage;
246
247 /* Definition of input parameter */
248 typedef union {
249 sim_slope INPUT_SLOPE;
250 sim_stuck INPUT_STUCK;
251 sim_func INPUT_FUNC;
252 sim_mimic_voltage INPUT_MIMIC;
253 } sim_uinput;
254
255 /* Input connector definition */
256 typedef struct sim_input {
257 struct sim_input *NEXT;
258 char *LOCON_NAME;
259 char *LOSIG_NAME;
260 char TYPE; // SIM_STUCK, SIM_SLOPE, SIM_FUNC, SIM_LOAD
261 sim_uinput UINPUT;
262 char *DELTAVAR;
263 SIM_FLOAT VDD, VSS;
264 } sim_input ;
265
266 /* Measure */
267 /* Important : due to hierarchical representation of name, there is no
268 namealloc() allocation for name. */
269
270 typedef struct sim_measure_detail {
271 struct sim_measure_detail *NEXT;
272 char *NODE_NAME; // nom original du noeud
273 char *PRINT_NAME; // nom drive (alias du nom original)
274 SIM_FLOAT *DATA;
275 } sim_measure_detail;
276
277 typedef union sim_measure_where {
278 char *LOCON_NAME;
279 char *SIGNAL_NAME;
280 } sim_measure_uwhere;
281
282 typedef struct sim_measure {
283 struct sim_measure *NEXT;
284 char TYPE; // SIM_MEASURE_SIGNAL_NODE,SIM_MEASURE_SIGNAL, SIM_MEASURE_LOCON
285 char WHAT; // SIM_MEASURE_VOLTAGE, SIM_MEASURE_CURRENT
286 sim_measure_uwhere WHERE;
287 sim_measure_detail *DETAIL;
288 chain_list *NODENAME;
289 } sim_measure;
290
291 /* Initial condition */
292
293 typedef struct sim_ic_level {
294 char LEVEL; // SIM_ZERO, SIM_ONE
295 } sim_ic_level;
296
297 typedef struct sim_ic_voltage {
298 SIM_FLOAT VOLTAGE;
299 } sim_ic_voltage;
300
301 typedef union sim_uic {
302 sim_ic_level LEVEL;
303 sim_ic_voltage VOLTAGE;
304 } sim_uic;
305
306 typedef union sim_ic_where {
307 char *LOCON_NAME;
308 char *SIGNAL_NAME;
309 } sim_ic_uwhere;
310
311 typedef struct sim_ic {
312 struct sim_ic *NEXT;
313 sim_ic_uwhere WHERE;
314 char LOCATE; // SIM_IC_LOCON, SIM_IC_SIGNAL
315 char TYPE; // SIM_IC_LEVEL, SIM_IC_VOLTAGE.
316 sim_uic UIC;
317 chain_list *NODENAME;
318 SIM_FLOAT VDD, VSS;
319 } sim_ic;
320
321 /* Simulator configuration */
322 typedef struct {
323 SIM_FLOAT ALIM_VOLTAGE_IN;
324 SIM_FLOAT VSS_VOLTAGE_IN;
325 SIM_FLOAT ALIM_VOLTAGE_OUT;
326 SIM_FLOAT VSS_VOLTAGE_OUT;
327 SIM_FLOAT SLOPE;
328 SIM_FLOAT TEMP;
329 SIM_FLOAT VTHSTART, VTHEND;
330 SIM_FLOAT VTH_HIGH;
331 SIM_FLOAT VTH_LOW;
332 SIM_FLOAT TRANSIANT_TMAX;
333 SIM_FLOAT TRANSIANT_STEP;
334 SIM_FLOAT SIMULATOR_STEP;
335 char *TOOL_CMD;
336 char *TOOL_OUTFILE;
337 char *TOOL_STDOUTFILE;
338 int TOOL;
339 chain_list *TECHNOFILELIST;
340 char DRIVE_NETLIST; // SIM_YES, SIM_NO.
341 char OVR_FILES; // SIM_YES, SIM_NO.
342 char REMOVE_FILES; // SIM_YES, SIM_NO.
343 char NOISE_TYPE; // SIM_MIN, SIM_MAX.
344 char TRANSISTOR_AS_INSTANCE; // SIM_YES, SIM_NO.
345 PWL_FUNCTION PWL_FUNC;
346 } sim_parameter ;
347
348 typedef struct sim_translate
349 {
350 struct sim_translate *NEXT;
351 char *signal;
352 char *equiv;
353 } sim_translate;
354
355
356 /* Main structure */
357 typedef struct {
358 lofig_list *FIG;
359 char *FIGNAME;
360 sim_parameter PARAMETER;
361 sim_ic *LIC;
362 sim_input *LINPUT;
363 sim_measure *LMEASURE;
364 sim_translate *TRANSLATION;
365 ht *HTINPUT;
366 // ht *CONTEXT_HT;
367 char OUTPUT_READ;
368 char *OUTPUT_FILE;
369 long NUMBER;
370 ptype_list *USER;
371 void *LRULES;
372 void *LLABELS;
373 void *LARGS;
374 void *LPRN;
375 char SUBCKTFILENAME[256];
376 int NBMC;
377 } sim_model;
378
379 /* Results structure */
380
381 typedef struct sim_timing {
382 struct sim_timing *NEXT;
383 char *ROOT4USR; // noeud origine vu par l'utilisateur
384 char *NODE4USR; // noeud destination vu par l'utilisateur
385 char *ROOT; // noeud origine
386 char *NODE; // noeud destination
387 SIM_FLOAT DELAY; // delay entre root et node
388 SIM_FLOAT SLOPE; // slope du noeud destinataire
389 char ROOTEVENT; // SIM_FALL ou SIM_RISE
390 int IDXREVENT; // INDEX of ROOT EVENT
391 char NODEEVENT; // SIM_FALL ou SIM_RISE
392 int IDXNEVENT; // INDEX of NODE EVENT
393 } sim_timing;
394
395
396 typedef struct sim_noise {
397 struct sim_noise *NEXT;
398 char *NAME; // nom du noeud vu par l'utilisateur
399 char *NODENAME; // nom du noeud dans le circuit
400 SIM_FLOAT VTHNOISE; // valeur du seuil de detection du bruit
401 SIM_FLOAT *TAB; // tableau contenant toutes les tensions du noeud
402 chain_list *IDXPEAK; // indice du bruit : DATA = int (indice du TAB)
403 chain_list *IDXC; // indice de passage au seuil : DATA = int (indice du TAB)
404 } sim_noise;
405
406 typedef struct sim_slopes
407 {
408 float time;
409 char direction;
410 float time_low, time_high;
411 } sim_slopes;
412
413 #define SIM_UNDEF ((SIM_FLOAT)3.14159e27)
414