1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California.  All rights reserved.
4 Authors: 1988 Min-Chie Jeng, Hong J. Park, Thomas L. Quarles
5          1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include <stdio.h>
10 #include <math.h>
11 #include "bsim2def.h"
12 #include "const.h"
13 #include "sperror.h"
14 #include "util.h"
15 #include "cktext.h"
16 
17 
18 int
B2setup(matrix,inModel,ckt,states)19 B2setup(matrix,inModel,ckt,states)
20     register SMPmatrix *matrix;
21     register GENmodel *inModel;
22     register CKTcircuit *ckt;
23     int *states;
24         /* load the B2 device structure with those pointers needed later
25          * for fast matrix loading
26          */
27 
28 {
29     register B2model *model = (B2model*)inModel;
30     register B2instance *here;
31     int error;
32     CKTnode *tmp;
33 
34     /*  loop through all the B2 device models */
35     for( ; model != NULL; model = model->B2nextModel ) {
36 
37 /* Default value Processing for B2 MOSFET Models */
38         if( ! model->B2typeGiven) {
39             model->B2type = NMOS;  /* NMOS */
40         }
41         if( ! model->B2vfb0Given) {
42             model->B2vfb0 = -1.0;
43         }
44         if( ! model->B2vfbLGiven) {
45             model->B2vfbL = 0.0;
46         }
47         if( ! model->B2vfbWGiven) {
48             model->B2vfbW = 0.0;
49         }
50         if( ! model->B2phi0Given) {
51             model->B2phi0 = 0.75;
52         }
53         if( ! model->B2phiLGiven) {
54             model->B2phiL = 0.0;
55         }
56         if( ! model->B2phiWGiven) {
57             model->B2phiW = 0.0;
58         }
59         if( ! model->B2k10Given) {
60             model->B2k10 = 0.8;
61         }
62         if( ! model->B2k1LGiven) {
63             model->B2k1L = 0.0;
64         }
65         if( ! model->B2k1WGiven) {
66             model->B2k1W = 0.0;
67         }
68         if( ! model->B2k20Given) {
69             model->B2k20 = 0.0;
70         }
71         if( ! model->B2k2LGiven) {
72             model->B2k2L = 0.0;
73         }
74         if( ! model->B2k2WGiven) {
75             model->B2k2W = 0.0;
76         }
77         if( ! model->B2eta00Given) {
78             model->B2eta00 = 0.0;
79         }
80         if( ! model->B2eta0LGiven) {
81             model->B2eta0L = 0.0;
82         }
83         if( ! model->B2eta0WGiven) {
84             model->B2eta0W = 0.0;
85         }
86         if( ! model->B2etaB0Given) {
87             model->B2etaB0 = 0.0;
88         }
89         if( ! model->B2etaBLGiven) {
90             model->B2etaBL = 0.0;
91         }
92         if( ! model->B2etaBWGiven) {
93             model->B2etaBW = 0.0;
94         }
95         if( ! model->B2deltaLGiven) {
96             model->B2deltaL = 0.0;
97         }
98         if( ! model->B2deltaWGiven) {
99             model->B2deltaW = 0.0;
100         }
101         if( ! model->B2ua00Given) {
102             model->B2ua00 = 0.2;
103         }
104         if( ! model->B2ua0LGiven) {
105             model->B2ua0L = 0.0;
106         }
107         if( ! model->B2ua0WGiven) {
108             model->B2ua0W = 0.0;
109         }
110         if( ! model->B2uaB0Given) {
111             model->B2uaB0 = 0.0;
112         }
113         if( ! model->B2uaBLGiven) {
114             model->B2uaBL = 0.0;
115         }
116         if( ! model->B2uaBWGiven) {
117             model->B2uaBW = 0.0;
118         }
119         if( ! model->B2ub00Given) {
120             model->B2ub00 = 0.0;
121         }
122         if( ! model->B2ub0LGiven) {
123             model->B2ub0L = 0.0;
124         }
125         if( ! model->B2ub0WGiven) {
126             model->B2ub0W = 0.0;
127         }
128         if( ! model->B2ubB0Given) {
129             model->B2ubB0 = 0.0;
130         }
131         if( ! model->B2ubBLGiven) {
132             model->B2ubBL = 0.0;
133         }
134         if( ! model->B2ubBWGiven) {
135             model->B2ubBW = 0.0;
136         }
137         if( ! model->B2u100Given) {
138             model->B2u100 = 0.1;
139         }
140         if( ! model->B2u10LGiven) {
141             model->B2u10L = 0.0;
142         }
143         if( ! model->B2u10WGiven) {
144             model->B2u10W = 0.0;
145         }
146         if( ! model->B2u1B0Given) {
147             model->B2u1B0 = 0.0;
148         }
149         if( ! model->B2u1BLGiven) {
150             model->B2u1BL = 0.0;
151         }
152         if( ! model->B2u1BWGiven) {
153             model->B2u1BW = 0.0;
154         }
155         if( ! model->B2u1D0Given) {
156             model->B2u1D0 = 0.0;
157         }
158         if( ! model->B2u1DLGiven) {
159             model->B2u1DL = 0.0;
160         }
161         if( ! model->B2u1DWGiven) {
162             model->B2u1DW = 0.0;
163         }
164         if( ! model->B2mob00Given) {
165             model->B2mob00 = 400.0;
166         }
167         if( ! model->B2mob0B0Given) {
168             model->B2mob0B0 = 0.0;
169         }
170         if( ! model->B2mob0BLGiven) {
171             model->B2mob0BL = 0.0;
172         }
173         if( ! model->B2mob0BWGiven) {
174             model->B2mob0BW = 0.0;
175         }
176         if( ! model->B2mobs00Given) {
177             model->B2mobs00 = 500.0;
178         }
179         if( ! model->B2mobs0LGiven) {
180             model->B2mobs0L = 0.0;
181         }
182         if( ! model->B2mobs0WGiven) {
183             model->B2mobs0W = 0.0;
184         }
185         if( ! model->B2mobsB0Given) {
186             model->B2mobsB0 = 0.0;
187         }
188         if( ! model->B2mobsBLGiven) {
189             model->B2mobsBL = 0.0;
190         }
191         if( ! model->B2mobsBWGiven) {
192             model->B2mobsBW = 0.0;
193         }
194         if( ! model->B2mob200Given) {
195             model->B2mob200 = 1.5;
196         }
197         if( ! model->B2mob20LGiven) {
198             model->B2mob20L = 0.0;
199         }
200         if( ! model->B2mob20WGiven) {
201             model->B2mob20W = 0.0;
202         }
203         if( ! model->B2mob2B0Given) {
204             model->B2mob2B0 = 0.0;
205         }
206         if( ! model->B2mob2BLGiven) {
207             model->B2mob2BL = 0.0;
208         }
209         if( ! model->B2mob2BWGiven) {
210             model->B2mob2BW = 0.0;
211         }
212         if( ! model->B2mob2G0Given) {
213             model->B2mob2G0 = 0.0;
214         }
215         if( ! model->B2mob2GLGiven) {
216             model->B2mob2GL = 0.0;
217         }
218         if( ! model->B2mob2GWGiven) {
219             model->B2mob2GW = 0.0;
220         }
221         if( ! model->B2mob300Given) {
222             model->B2mob300 = 10;
223         }
224         if( ! model->B2mob30LGiven) {
225             model->B2mob30L = 0.0;
226         }
227         if( ! model->B2mob30WGiven) {
228             model->B2mob30W = 0.0;
229         }
230         if( ! model->B2mob3B0Given) {
231             model->B2mob3B0 = 0.0;
232         }
233         if( ! model->B2mob3BLGiven) {
234             model->B2mob3BL = 0.0;
235         }
236         if( ! model->B2mob3BWGiven) {
237             model->B2mob3BW = 0.0;
238         }
239         if( ! model->B2mob3G0Given) {
240             model->B2mob3G0 = 0.0;
241         }
242         if( ! model->B2mob3GLGiven) {
243             model->B2mob3GL = 0.0;
244         }
245         if( ! model->B2mob3GWGiven) {
246             model->B2mob3GW = 0.0;
247         }
248         if( ! model->B2mob400Given) {
249             model->B2mob400 = 0.0;
250         }
251         if( ! model->B2mob40LGiven) {
252             model->B2mob40L = 0.0;
253         }
254         if( ! model->B2mob40WGiven) {
255             model->B2mob40W = 0.0;
256         }
257         if( ! model->B2mob4B0Given) {
258             model->B2mob4B0 = 0.0;
259         }
260         if( ! model->B2mob4BLGiven) {
261             model->B2mob4BL = 0.0;
262         }
263         if( ! model->B2mob4BWGiven) {
264             model->B2mob4BW = 0.0;
265         }
266         if( ! model->B2mob4G0Given) {
267             model->B2mob4G0 = 0.0;
268         }
269         if( ! model->B2mob4GLGiven) {
270             model->B2mob4GL = 0.0;
271         }
272         if( ! model->B2mob4GWGiven) {
273             model->B2mob4GW = 0.0;
274         }
275         if( ! model->B2n00Given) {
276             model->B2n00 = 1.4;
277         }
278         if( ! model->B2n0LGiven) {
279             model->B2n0L = 0.0;
280         }
281         if( ! model->B2n0WGiven) {
282             model->B2n0W = 0.0;
283         }
284         if( ! model->B2nB0Given) {
285             model->B2nB0 = 0.5;
286         }
287         if( ! model->B2nBLGiven) {
288             model->B2nBL = 0.0;
289         }
290         if( ! model->B2nBWGiven) {
291             model->B2nBW = 0.0;
292         }
293         if( ! model->B2nD0Given) {
294             model->B2nD0 = 0.0;
295         }
296         if( ! model->B2nDLGiven) {
297             model->B2nDL = 0.0;
298         }
299         if( ! model->B2nDWGiven) {
300             model->B2nDW = 0.0;
301         }
302         if( ! model->B2vof00Given) {
303             model->B2vof00 = 1.8;
304         }
305         if( ! model->B2vof0LGiven) {
306             model->B2vof0L = 0.0;
307         }
308         if( ! model->B2vof0WGiven) {
309             model->B2vof0W = 0.0;
310         }
311         if( ! model->B2vofB0Given) {
312             model->B2vofB0 = 0.0;
313         }
314         if( ! model->B2vofBLGiven) {
315             model->B2vofBL = 0.0;
316         }
317         if( ! model->B2vofBWGiven) {
318             model->B2vofBW = 0.0;
319         }
320         if( ! model->B2vofD0Given) {
321             model->B2vofD0 = 0.0;
322         }
323         if( ! model->B2vofDLGiven) {
324             model->B2vofDL = 0.0;
325         }
326         if( ! model->B2vofDWGiven) {
327             model->B2vofDW = 0.0;
328         }
329         if( ! model->B2ai00Given) {
330             model->B2ai00 = 0.0;
331         }
332         if( ! model->B2ai0LGiven) {
333             model->B2ai0L = 0.0;
334         }
335         if( ! model->B2ai0WGiven) {
336             model->B2ai0W = 0.0;
337         }
338         if( ! model->B2aiB0Given) {
339             model->B2aiB0 = 0.0;
340         }
341         if( ! model->B2aiBLGiven) {
342             model->B2aiBL = 0.0;
343         }
344         if( ! model->B2aiBWGiven) {
345             model->B2aiBW = 0.0;
346         }
347         if( ! model->B2bi00Given) {
348             model->B2bi00 = 0.0;
349         }
350         if( ! model->B2bi0LGiven) {
351             model->B2bi0L = 0.0;
352         }
353         if( ! model->B2bi0WGiven) {
354             model->B2bi0W = 0.0;
355         }
356         if( ! model->B2biB0Given) {
357             model->B2biB0 = 0.0;
358         }
359         if( ! model->B2biBLGiven) {
360             model->B2biBL = 0.0;
361         }
362         if( ! model->B2biBWGiven) {
363             model->B2biBW = 0.0;
364         }
365         if( ! model->B2vghigh0Given) {
366             model->B2vghigh0 = 0.2;
367         }
368         if( ! model->B2vghighLGiven) {
369             model->B2vghighL = 0.0;
370         }
371         if( ! model->B2vghighWGiven) {
372             model->B2vghighW = 0.0;
373         }
374         if( ! model->B2vglow0Given) {
375             model->B2vglow0 = -0.15;
376         }
377         if( ! model->B2vglowLGiven) {
378             model->B2vglowL = 0.0;
379         }
380         if( ! model->B2vglowWGiven) {
381             model->B2vglowW = 0.0;
382         }
383         if( ! model->B2toxGiven) {
384             model->B2tox = 0.03;  /* um */
385         }
386         if( ! model->B2tempGiven) {
387             model->B2temp = 27.0;
388         }
389         if( ! model->B2vddGiven) {
390             model->B2vdd = 5.0;
391         }
392         if( ! model->B2vggGiven) {
393             model->B2vgg = 5.0;
394         }
395         if( ! model->B2vbbGiven) {
396             model->B2vbb = 5.0;
397         }
398         if( ! model->B2gateDrainOverlapCapGiven) {
399             model->B2gateDrainOverlapCap = 0.0;
400         }
401         if( ! model->B2gateSourceOverlapCapGiven) {
402             model->B2gateSourceOverlapCap = 0.0;
403         }
404         if( ! model->B2gateBulkOverlapCapGiven) {
405             model->B2gateBulkOverlapCap = 0.0;
406         }
407         if( ! model->B2channelChargePartitionFlagGiven) {
408             model->B2channelChargePartitionFlag = 0.0;
409         }
410         if( ! model->B2sheetResistanceGiven) {
411             model->B2sheetResistance = 0.0;
412         }
413         if( ! model->B2unitAreaJctCapGiven) {
414             model->B2unitAreaJctCap = 0.0;
415         }
416         if( ! model->B2unitLengthSidewallJctCapGiven) {
417             model->B2unitLengthSidewallJctCap = 0.0;
418         }
419         if( ! model->B2jctSatCurDensityGiven) {
420             model->B2jctSatCurDensity = 0.0;
421         }
422         if( ! model->B2bulkJctPotentialGiven) {
423             model->B2bulkJctPotential = 0.0;
424         }
425         if( ! model->B2sidewallJctPotentialGiven) {
426             model->B2sidewallJctPotential = 0.0;
427         }
428         if( ! model->B2bulkJctBotGradingCoeffGiven) {
429             model->B2bulkJctBotGradingCoeff = 0.0;
430         }
431         if( ! model->B2bulkJctSideGradingCoeffGiven) {
432             model->B2bulkJctSideGradingCoeff = 0.0;
433         }
434         if( ! model->B2defaultWidthGiven) {
435             model->B2defaultWidth = 10.0;
436         }
437         if( ! model->B2deltaLengthGiven) {
438             model->B2deltaLength = 0.0;
439         }
440 
441         /* loop through all the instances of the model */
442         for (here = model->B2instances; here != NULL ;
443                 here=here->B2nextInstance) {
444 
445             /* allocate a chunk of the state vector */
446             here->B2states = *states;
447             *states += B2numStates;
448 
449             /* perform the parameter defaulting */
450 
451             if(!here->B2drainAreaGiven) {
452                 here->B2drainArea = 0;
453             }
454             if(!here->B2drainPerimeterGiven) {
455                 here->B2drainPerimeter = 0;
456             }
457             if(!here->B2drainSquaresGiven) {
458                 here->B2drainSquares = 1;
459             }
460             if(!here->B2icVBSGiven) {
461                 here->B2icVBS = 0;
462             }
463             if(!here->B2icVDSGiven) {
464                 here->B2icVDS = 0;
465             }
466             if(!here->B2icVGSGiven) {
467                 here->B2icVGS = 0;
468             }
469             if(!here->B2lGiven) {
470                 here->B2l = 5e-6;
471             }
472             if(!here->B2sourceAreaGiven) {
473                 here->B2sourceArea = 0;
474             }
475             if(!here->B2sourcePerimeterGiven) {
476                 here->B2sourcePerimeter = 0;
477             }
478             if(!here->B2sourceSquaresGiven) {
479                 here->B2sourceSquares = 1;
480             }
481             if(!here->B2vdsatGiven) {
482                 here->B2vdsat = 0;
483             }
484             if(!here->B2vonGiven) {
485                 here->B2von = 0;
486             }
487             if(!here->B2wGiven) {
488                 here->B2w = 5e-6;
489             }
490 
491             /* process drain series resistance */
492             if( (model->B2sheetResistance != 0) &&
493                     (here->B2drainSquares != 0.0 ) &&
494                     (here->B2dNodePrime == 0) ) {
495                 error = CKTmkVolt(ckt,&tmp,here->B2name,"drain");
496                 if(error) return(error);
497                 here->B2dNodePrime = tmp->number;
498             } else {
499                     here->B2dNodePrime = here->B2dNode;
500             }
501 
502             /* process source series resistance */
503             if( (model->B2sheetResistance != 0) &&
504                     (here->B2sourceSquares != 0.0 ) &&
505                     (here->B2sNodePrime == 0) ) {
506                 if(here->B2sNodePrime == 0) {
507                     error = CKTmkVolt(ckt,&tmp,here->B2name,"source");
508                     if(error) return(error);
509                     here->B2sNodePrime = tmp->number;
510                 }
511             } else  {
512                 here->B2sNodePrime = here->B2sNode;
513             }
514 
515 
516         /* set Sparse Matrix Pointers */
517 
518             TSTALLOC(B2DdPtr, B2dNode, B2dNode)
519             TSTALLOC(B2GgPtr, B2gNode, B2gNode)
520             TSTALLOC(B2SsPtr, B2sNode, B2sNode)
521             TSTALLOC(B2BbPtr, B2bNode, B2bNode)
522             TSTALLOC(B2DPdpPtr, B2dNodePrime, B2dNodePrime)
523             TSTALLOC(B2SPspPtr, B2sNodePrime, B2sNodePrime)
524             TSTALLOC(B2DdpPtr, B2dNode, B2dNodePrime)
525             TSTALLOC(B2GbPtr, B2gNode, B2bNode)
526             TSTALLOC(B2GdpPtr, B2gNode, B2dNodePrime)
527             TSTALLOC(B2GspPtr, B2gNode, B2sNodePrime)
528             TSTALLOC(B2SspPtr, B2sNode, B2sNodePrime)
529             TSTALLOC(B2BdpPtr, B2bNode, B2dNodePrime)
530             TSTALLOC(B2BspPtr, B2bNode, B2sNodePrime)
531             TSTALLOC(B2DPspPtr, B2dNodePrime, B2sNodePrime)
532             TSTALLOC(B2DPdPtr, B2dNodePrime, B2dNode)
533             TSTALLOC(B2BgPtr, B2bNode, B2gNode)
534             TSTALLOC(B2DPgPtr, B2dNodePrime, B2gNode)
535             TSTALLOC(B2SPgPtr, B2sNodePrime, B2gNode)
536             TSTALLOC(B2SPsPtr, B2sNodePrime, B2sNode)
537             TSTALLOC(B2DPbPtr, B2dNodePrime, B2bNode)
538             TSTALLOC(B2SPbPtr, B2sNodePrime, B2bNode)
539             TSTALLOC(B2SPdpPtr, B2sNodePrime, B2dNodePrime)
540 
541         }
542     }
543     return(OK);
544 }
545