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
21 /* netlist_dev.c, netlist functions for netlists of circuital devices (ie fets)
26 /* our goal here is to provide all the netlist convenience functions
27 which are dependent on the particular definitions for the devices (ie hard coded device types)
28 by device netlists we refer to netlists to be fed to spice-like simulators.
30 this was split off the core device-independent netlist routines
36 #include "netlist_dev.h"
39 /* make a new device netlist, using client sizes as given
40 ni is ptr returned by netlist_parse_input
44 netlist_t
*netlist_devnew_inplace(netlist_input_t ni
, int extrasize
, int extrasizes
[DEVT_MAX
])
47 int terms
[]=DEVT_TERMS
;
49 char *syms
[]=DEVT_SYMS
;
50 int others
[]=DEVT_OTHERS
;
53 nl
=malloc(sizeof(netlist_t
)+extrasize
);
57 for(i
=0;i
<DEVT_MAX
;i
++)
59 r
=netlist_register_entity(nl
,i
,terms
[i
],vals
[i
],others
[i
],syms
[i
],extrasizes
[i
]);
66 switch(ni
.generic
->magic
)
71 for(i
=0;i
<DEVT_MAX
;i
++)
73 list_hint(&(nl
->e
[i
].l
),nl
->e
[i
].qcount
);
80 for(i=0;i<DEVT_MAX;i++)
82 list_hint(&(nl->e[i].l),nl->e[i].qcount);
91 netlist_t
*netlist_devnew(netlist_input_t ni
)
94 memset(sz
,0,sizeof(sz
));
95 return netlist_devnew_inplace(ni
, 0, sz
);
99 /**** output spice_like file ****/
101 void netlist_o_spice(void *of_fp
, netlist_t
*nl
, int n_start
)
105 int m_i
=1, c_i
=1, l_i
=1, i_i
=1, v_i
=1;
114 eqnl_evaldep(&(nl
->eqnl
));
116 fprintf(of
,"*** netlist output \n");
117 for(i
=0;i
<DEVT_MAX
;i
++)
120 assert(e
->qterms
<(sizeof(nodes
)/sizeof(int)));
121 assert(e
->qvals
<(sizeof(vals
)/sizeof(float)));
123 list_iterate(&(e
->l
),j
,p
.p
)
125 for(k
=0;k
<e
->qterms
;k
++)
126 nodes
[k
]=n_start
+netlist_node_termptr(nl
,p
.genp
->n
[k
]);
128 v
=NETLIST_VALS(nl
,i
,j
);
129 for(k
=0;k
<e
->qvals
;k
++)
130 vals
[k
]=eqnl_eval(&(nl
->eqnl
),v
[k
]);
134 case DEVT_NODE
: /* output a mini node-name directory */
135 fprintf(of
,"* %i %s\n",j
+n_start
,names_lookup(nl
->names
,j
));
139 fprintf(of
,"m%i %i %i %i %i %s L=%g W=%g AS=%g AD=%g PS=%g PD=%g\n",m_i
++,
140 nodes
[DEVFET_S
],nodes
[DEVFET_G
],nodes
[DEVFET_D
], nodes
[DEVFET_B
],
141 (p
.fetp
->type
==DEVFET_nmos
)?"n":"p",
142 vals
[DEVFET_l
],vals
[DEVFET_w
], vals
[DEVFET_as
],
143 vals
[DEVFET_ad
], vals
[DEVFET_ps
], vals
[DEVFET_pd
]
147 fprintf(of
,"c%i %i %i %g\n",c_i
++,
148 nodes
[DEV2TERM_P
], nodes
[DEV2TERM_N
], vals
[DEVCAP_c
]
152 fprintf(of
,"c%i %i %i %g\n",c_i
++,
153 nodes
[DEV2TERM_P
], nodes
[DEV2TERM_N
], vals
[DEVRES_r
]
157 fprintf(of
,"l%i %i %i %g\n",l_i
++,
158 nodes
[DEV2TERM_P
], nodes
[DEV2TERM_N
], vals
[0]
162 fprintf(of
,"v%i %i %i %g\n",v_i
++,
163 nodes
[DEV2TERM_P
], nodes
[DEV2TERM_N
], vals
[0]
167 fprintf(of
,"i%i %i %i %g\n",i_i
++,
168 nodes
[DEV2TERM_P
], nodes
[DEV2TERM_N
], vals
[0]
177 fprintf(of
,"*** end netlist output \n");
182 netlist_t
*netlist_copyish(netlist_t
*in
, int size
, int sizes
[])
185 int extras
[TERMPTR_MAX_DEVT
];
186 int defsize
[DEVT_MAX
]=NETLIST_DEFSIZES
;
187 for(i
=0;i
<TERMPTR_MAX_DEVT
;i
++)
190 extras
[i
]=sizes
[i
]-defsize
[i
];
193 if(extras
[i
]<0)extras
[i
]=0;
194 assert(extras
[i
]<2048);
197 return netlist_copyisher(in
,size
-sizeof(netlist_t
),extras
);