Initial commit at Tue Apr 25 08:36:02 EDT 2017 by tim on stravinsky
[xcircuit.git] / spiceparser / netlist_lib.h
blob320ef13e8e0738fd10b02916ae28f574918d4cea
1 /********************
2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ******************/
21 /* netlist_lib.h, definitions for netlist library routines
22 Conrad Ziesler
25 #ifndef __EQN_H__
26 #include "eqn.h"
27 #endif
29 #ifndef __NETLIST_H__
30 #include "netlist.h"
31 #endif
33 #ifndef __BITLIST_H__
34 #include "bitlist.h"
35 #endif
37 #define NLIBIO_MAXNODES 4
39 /* convenience structures */
40 typedef struct nlibiodef_st
42 char *encoding;
43 int wires;
44 int tokens;
45 int digitize;
46 }nlibiodef_t;
49 /* input definition */
50 typedef struct nlibio_st
52 int tokens;
53 int qnodes;
54 int digitize;
55 int nodes[NLIBIO_MAXNODES];
56 }nlibio_t;
58 typedef struct nlibiol_st
60 list_t iol;
61 int qtokens; /* product (iol[k].tokens) */
62 }nlibiol_t;
64 /* parameter range */
65 typedef struct nlibpm_st
67 int index; /* index into netlist parameter list */
68 float min, max;
69 int qty;
70 }nlibpm_t;
72 typedef struct nlibfunc_st
74 int p_delay; /* phases of delay before we begin computations */
75 int p_cycle; /* phases per cycle (compute each n phases) */
76 int p_offset; /* phases between inputs sampled and outputs valid */
77 int qin;
78 int qout;
79 int map[2]; /* alloc in place, size = qin*sizeof(int) */
80 }nlibfunc_t;
82 /* function reference */
83 typedef struct nlibfref_st
85 int index;
86 }nlibfref_t;
90 /* reference nodes and associated skew parameters */
91 typedef enum nlibreftype_en
93 RTrseries=0,
94 RTcshunt=1,
95 RTdelay=2,
96 RTqty
97 }nlibreftype_t;
99 #define MAXSKEW_PARAMS 3
100 typedef struct nlibrefnode_st
102 eqn_t skew[MAXSKEW_PARAMS]; /* RTxxx indices */
103 int vrefi; /* index into vref structure */
104 int devnodei; /* node index in netlist */
105 }nlibrefnode_t;
107 /* database object */
108 typedef struct nlibdb_st
110 netlist_t *nl;
111 nlibiol_t in,out;
112 nlibfref_t map; /* mapping between input and output tokens */
113 list_t params;
114 list_t refnodes;
115 float *pvals;
116 }nlibdb_t;
119 typedef struct nlibflatdb_st
121 int lib_index; /* index from process */
122 int db_index; /* index into db list */
123 int qvals; /* cache db->params.q */
124 float *pvals; /* copy db pvals to here */
125 list_t uservals; /* array of user gate physical parameters */
126 }nlibflatdb_t;
128 /* container of database objects */
129 typedef struct nlib_st
131 list_t iodefs;
132 list_t db; /* our database of nlibdb objects */
133 names_t *dbref; /* database gate reference names */
134 names_t *vref; /* voltage reference node names */
135 int qvref;
136 list_t funcs; /* ptrs */
137 names_t *funcnames;
138 eqnlist_t eqnl; /* top level parameters we can use anywhere in eqns */
139 bitlist_t *flags; /* user can select set of elements to use */
140 list_t flatdb; /* database of flat info */
141 void *eqn_mem;
142 }nlib_t;
144 #define NLIB_MAXPHASES 4
146 typedef struct nlib_icall_st
148 int dbi;
149 int flatdbi;
150 float *in[NLIBIO_MAXNODES];
151 float *out[NLIBIO_MAXNODES];
152 int itokens[NLIB_MAXPHASES], otokens[NLIB_MAXPHASES], ctoken;
153 int ver;
154 int err;
155 int idigitize, odigitize;
156 int inode,onode;
157 }nlib_icall_t;
159 #define NLIB_MAXFREF 64
160 typedef struct nlib_ifref_st
162 float *val;
163 float vals[NLIB_MAXPHASES];
164 char name[NLIB_MAXFREF];
165 }nlib_ifref_t;
167 typedef enum nlib_refid_en
169 NLIBref_vss, /* the vdd/vss values are used by cmos digitalize */
170 NLIBref_vdd,
171 NLIBref_clk, /* clk is generic refering to some clock signal */
172 NLIBref_firstunused, /* user can allocate any ref ids after this point */
173 NLIBref_max=512
174 }nlib_refid_e;
176 typedef struct nlib_iface_st
178 nlib_t *nlib;
179 list_t icalls;
180 list_t frefs;
181 int ref_map[NLIBref_max];
182 int phase;
183 float * (*lookup_node_f)(void *user, char *name);
184 void *user;
185 }nlib_iface_t;
187 typedef enum nlib_tokens_en
189 Knlib_start=1024, Knlib_nlib,Knlib_input, Knlib_output,
190 Knlib_param, Knlib_netlist, Knlib_spice,
191 Knlib_encoding, Knlib_wires,
192 Knlib_tokens, Knlib_digitize, Knlib_digital, Knlib_qtyin, Knlib_qtyout,
193 Knlib_end_digital, Knlib_min, Knlib_max, Knlib_qty,
194 Knlib_function, Knlib_end_netlist, Knlib_define,
195 Knlib_reference, Knlib_name, Knlib_rseries, Knlib_cshunt, Knlib_delay,
196 Knlib_p_delay, Knlib_p_offset, Knlib_p_cycle,
197 Knlib_end
198 }nlib_tokens_t;
200 #define NLIB_TOKENS { \
201 { Knlib_nlib, ".nlib" }, \
202 { Knlib_input, ".input" }, \
203 { Knlib_output, ".output" }, \
204 { Knlib_define, ".define" }, \
205 { Knlib_param, ".param" }, \
206 { Knlib_netlist, ".netlist" }, \
207 { Knlib_end_netlist, ".end_netlist" }, \
208 { Knlib_spice, ".spice" }, \
209 { Knlib_encoding, ".encoding" }, \
210 { Knlib_digital, ".digital" }, \
211 { Knlib_end_digital, ".end_digital" }, \
212 { Knlib_qtyout, ".qtyout" }, \
213 { Knlib_qtyin, ".qtyin" }, \
214 { Knlib_digitize, ".digitize" }, \
215 { Knlib_min, ".min" }, \
216 { Knlib_max, ".max" }, \
217 { Knlib_qty, ".qtysteps" }, \
218 { Knlib_function, ".function" }, \
219 { Knlib_tokens, ".tokens" }, \
220 { Knlib_wires, ".wires" }, \
221 { Knlib_name, ".name" }, \
222 { Knlib_rseries, ".rseries" }, \
223 { Knlib_cshunt, ".cshunt" }, \
224 { Knlib_delay, ".delay" }, \
225 { Knlib_reference, ".reference" }, \
226 { Knlib_p_delay, ".p_delay" }, \
227 { Knlib_p_offset, ".p_offset" }, \
228 { Knlib_p_cycle, ".p_cycle" }, \
229 { Knlib_end, NULL } }
232 typedef struct nlib_process_st
234 /* filled in by user */
235 void (*process)(struct nlib_process_st *proc);
236 void *user;
237 nlib_t *nlib;
239 /* filled in by nlib_process before user->process() is called */
240 int lib_index;
241 int db_index;
242 netlist_t *nl;
243 }nlib_process_t;
246 int nlib_parse(nlib_t *nlib, scanner_t *scan);
247 int nlib_add_io(nlib_t *nlib, int dbindex, nlibiol_t *io, int tokens, int nodes, int dig, char **names);
248 int nlib_init(nlib_t *nlib);
249 int nlib_add_pm(nlib_t *nlib, int dbi, char *str, float min, float max, int qty);
250 int nlib_new_db(nlib_t *nlib, char *str);
251 int nlib_db_netlist(nlib_t *nlib, int index, netlist_t *nl);
252 int nlib_db_func(nlib_t *nlib, int index, char *str);
253 void nlib_process(nlib_process_t *user, int screened);
254 void nlib_fixup(nlib_t *nlib);
255 void nlib_disable(nlib_t *nlib, int index);
256 int nlib_isdisabled(nlib_t *nlib, int index);
258 void nlib_release(nlib_t *nlib);
260 void *nlib_flat(nlib_process_t *user, int s_uservals, int q_uservals);
261 void nlib_o_spice_subckts(nlib_t *nlib, void * of_fp);
262 void nlib_o_spice_call(nlib_t *nlib, int index, int i_node, int o_node, int *skt, void * of);
263 void nlib_o_spice_refs(nlib_t *nlib, void * of_fp);
264 int nlib_flatdb_write(nlib_t *nlib, void * file_fp);
265 int nlib_flatdb_read(nlib_t *nlib, void * file_fp);
267 /* interface routines */
269 nlib_ifref_t *nlib_iface_getref(nlib_iface_t *iface, int id);
270 void nlib_iface_phase(nlib_iface_t *iface);
271 int nlib_i_spice_calls(nlib_iface_t *iface, void * cktf_fp);
272 void nlib_iface_init(nlib_iface_t *iface, nlib_t *nlib);
273 void nlib_iface_release(nlib_iface_t *iface);