Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / api / ttv / ttv_API_cns_link.c
1 #include MUT_H
2 #include MLO_H
3 #include MLU_H
4 #include CNS_H
5 #include STM_H
6 #include TTV_H
7
8 #include "ttv_API_util.h"
9
10 static chain_list *findtr(branch_list *br, long typemask, char *namein, chain_list *cl)
11 {
12 chain_list *ch;
13 link_list *lk;
14 while (br!=NULL)
15 {
16 for (lk=br->LINK; lk!=NULL; lk=lk->NEXT)
17 {
18 if ((lk->TYPE & CNS_EXT) != CNS_EXT &&
19 (lk->ULINK.LOTRS->TYPE & typemask)==typemask &&
20 lk->ULINK.LOTRS->GRID->SIG->NAMECHAIN->DATA==namein &&
21 lk->ULINK.LOTRS->TRNAME!=NULL
22 )
23 {
24 for (ch=cl; ch!=NULL; ch=ch->NEXT)
25 if (ch->DATA==lk->ULINK.LOTRS) break;
26 if (ch==NULL) cl=addchain(cl, lk->ULINK.LOTRS);
27 }
28 }
29 br=br->NEXT;
30 }
31 return cl;
32 }
33
34 static chain_list *ttv_cnsgettransistor(cnsfig_list *cf, char *namein, char dirin, char *nameout, char dirout, int hz)
35 {
36 cone_list *cn;
37 long transistortypemask;
38 branch_list *brtosearch;
39 chain_list *cl;
40
41 if (tolower(dirin)!='u' && tolower(dirin)!='d')
42 {
43 avt_errmsg(TTV_API_ERRMSG, "001", AVT_ERROR, dirin);
44 /* avt_error("ttvapi", 4, AVT_ERR, "invalid direction for input signal '%c', function call ignored.\n", dirin);
45 avt_error("ttvapi", 4, AVT_INFO, "a direction should be 'u' or 'd'.\n");*/
46 return NULL;
47 }
48 if (tolower(dirout)!='u' && tolower(dirout)!='d')
49 {
50 avt_errmsg(TTV_API_ERRMSG, "001", AVT_ERROR, dirout);
51 /* avt_error("ttvapi", 4, AVT_ERR, "invalid direction for output signal '%c', function call ignored.\n", dirout);
52 avt_error("ttvapi", 4, AVT_INFO, "a direction should be 'u' or 'd'.\n");*/
53 return NULL;
54 }
55
56 if ((cn=getcone(cf, 0, nameout))==NULL) return NULL;
57
58 if (!hz)
59 {
60 // transistor passant
61 if (dirin=='u') transistortypemask=TRANSN; else transistortypemask=TRANSP;
62 }
63 else
64 {
65 // transistor bloquant
66 if (dirin=='u') transistortypemask=TRANSP; else transistortypemask=TRANSN;
67 }
68
69 if (dirout=='u') brtosearch=cn->BRVDD; else brtosearch=cn->BRVSS;
70
71 cl=findtr(cn->BREXT, transistortypemask, namein, NULL);
72 return findtr(brtosearch, transistortypemask, namein, cl);
73 }
74
75 chain_list *__ttv_GetCrossedTransistors(ttvfig_list *tvf, char *namein, char dirin, char *nameout, char dirout, int hzflag)
76 {
77 cnsfig_list *cf;
78 chain_list *cl;
79
80 cf=ttvutil_cnsload(tvf->INFO->FIGNAME, getloadedinffig(tvf->INFO->FIGNAME));
81
82 if (cf==NULL) return NULL;
83
84 cl=ttv_cnsgettransistor(cf, namealloc(namein), dirin, namealloc(nameout), dirout, hzflag);
85 if (cl==NULL)
86 {
87 namein=mbk_devect(namein, "[", "]");
88 nameout=mbk_devect(nameout, "[", "]");
89 cl=ttv_cnsgettransistor(cf, namein, dirin, nameout, dirout, hzflag);
90 }
91 return cl;
92 }
93
94 chain_list *ttv_GetCrossedTransistorNames(ttvfig_list *tvf, char *namein, char dirin, char *nameout, char dirout, int hzflag)
95 {
96 chain_list *cl, *ch;
97 cl=__ttv_GetCrossedTransistors(tvf, namein, dirin, nameout, dirout, hzflag);
98 for (ch=cl; ch!=NULL; ch=ch->NEXT)
99 {
100 ch->DATA=((lotrs_list *)ch->DATA)->TRNAME;
101 }
102 return cl;
103 }