From 19a78c9ac313958ccbf6f725d192695f76210724 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 23 Jun 2024 19:17:41 +0800 Subject: [PATCH] update node analysis, scf_pack.c, rename ses_step_simplify.c --> ses_step_draw.c, add nand.cpk for NAND, .. --- Makefile | 2 +- cpk/Makefile | 20 ++ cpk/add_gate.c | 73 ++++++ cpk/and_gate.c | 63 ++++++ cpk/nand.c | 46 ++++ cpk/nand.cpk | Bin 0 -> 301 bytes cpk/nor.c | 47 ++++ cpk/nor.cpk | Bin 0 -> 304 bytes cpk/not.c | 42 ++++ cpk/not.cpk | Bin 0 -> 194 bytes cpk/or_gate.c | 56 +++++ examples/add.cpk | Bin 1322 -> 1336 bytes examples/add2.cpk | Bin 3297 -> 3331 bytes examples/and.cpk | Bin 720 -> 728 bytes examples/colpitts_oscillator.cpk | Bin 943 -> 0 bytes examples/or.cpk | Bin 723 -> 731 bytes examples/pnp_oscillator.cpk | Bin 1010 -> 0 bytes examples/sin_oscillator.cpk | Bin 1010 -> 1021 bytes examples/sub.cpk | Bin 2331 -> 1397 bytes main.c | 57 +++-- pack/main.c | 2 +- pack/scf_pack.c | 187 +++++++++------- pack/scf_pack.h | 14 +- scf_eda_pack.c | 208 +++++++++++++++-- scf_eda_pack.h | 59 ++++- ses_core.h | 2 + ses_layout.c | 193 ++++++++++------ ses_node_analysis.c | 58 +++-- ses_step_simplify.c => ses_step_draw.c | 296 ++++++++++++++++++++++++- ses_step_jr.c | 10 +- ses_step_output.c | 16 +- ses_step_topo.c | 58 +++-- ses_steps.c | 4 +- test/Makefile | 4 +- 34 files changed, 1220 insertions(+), 297 deletions(-) create mode 100644 cpk/Makefile create mode 100644 cpk/add_gate.c create mode 100644 cpk/and_gate.c create mode 100644 cpk/nand.c create mode 100644 cpk/nand.cpk create mode 100644 cpk/nor.c create mode 100644 cpk/nor.cpk create mode 100644 cpk/not.c create mode 100644 cpk/not.cpk create mode 100644 cpk/or_gate.c delete mode 100644 examples/colpitts_oscillator.cpk delete mode 100644 examples/pnp_oscillator.cpk rename ses_step_simplify.c => ses_step_draw.c (67%) diff --git a/Makefile b/Makefile index 952b8f2..be7e530 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ CFILES += ses_step_open.c CFILES += ses_step_va_nodes.c CFILES += ses_step_output.c -CFILES += ses_step_simplify.c +CFILES += ses_step_draw.c CFLAGS += -g -D_GNU_SOURCE CFLAGS += -I./ diff --git a/cpk/Makefile b/cpk/Makefile new file mode 100644 index 0000000..bcf56ea --- /dev/null +++ b/cpk/Makefile @@ -0,0 +1,20 @@ +#CFILES += nand.c +#CFILES += nor.c +#CFILES += not.c +CFILES += and_gate.c +#CFILES += or_gate.c +#CFILES += add_gate.c +CFILES += ../scf_eda_pack.c +CFILES += ../pack/scf_pack.c + +CFLAGS += -g +CFLAGS += -I../ +CFLAGS += -I../pack + +LDFLAGS += -lcairo -lm -lgsl -lgslcblas + +all: + gcc $(CFLAGS) $(CFILES) $(LDFLAGS) + +clean: + rm *.o diff --git a/cpk/add_gate.c b/cpk/add_gate.c new file mode 100644 index 0000000..4868d60 --- /dev/null +++ b/cpk/add_gate.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* NAND0; + ScfEcomponent* NOR0; + ScfEcomponent* NOR1; + ScfEcomponent* NOT0; + + ScfEfunction* f; + ScfEboard* b; + + b = scf_eboard__alloc(); + f = scf_efunction__alloc("add_gate"); + + EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); + + B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG; + B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS; + + EDA_INST_ADD_COMPONENT(f, NAND0, SCF_EDA_NAND); + EDA_INST_ADD_COMPONENT(f, NOT0, SCF_EDA_NOT); + EDA_INST_ADD_COMPONENT(f, NOR0, SCF_EDA_NOR); + EDA_INST_ADD_COMPONENT(f, NOR1, SCF_EDA_NOR); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NAND0, SCF_EDA_NAND_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NAND0, SCF_EDA_NAND_NEG); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOR0, SCF_EDA_NOR_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOR0, SCF_EDA_NOR_NEG); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOR1, SCF_EDA_NOR_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOR1, SCF_EDA_NOR_NEG); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOT0, SCF_EDA_NOT_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOT0, SCF_EDA_NOT_NEG); + + EDA_PIN_ADD_PIN(NAND0, SCF_EDA_NAND_OUT, NOT0, SCF_EDA_NOT_IN); + + EDA_PIN_ADD_PIN(NOT0, SCF_EDA_NOT_OUT, NOR1, SCF_EDA_NOR_IN0); + EDA_PIN_ADD_PIN(NOR0, SCF_EDA_NOR_OUT, NOR1, SCF_EDA_NOR_IN1); + + EDA_PIN_ADD_PIN(NAND0, SCF_EDA_NAND_IN0, NOR0, SCF_EDA_NOR_IN0); + EDA_PIN_ADD_PIN(NAND0, SCF_EDA_NAND_IN1, NOR0, SCF_EDA_NOR_IN1); + + NAND0->pins[SCF_EDA_NAND_IN0]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + NAND0->pins[SCF_EDA_NAND_IN1]->flags = SCF_EDA_PIN_IN; + + NOR1->pins[SCF_EDA_NOR_OUT]->flags = SCF_EDA_PIN_OUT; + + scf_logi("\n"); + scf_eboard__add_function(b, f); + + int len = 0; + uint8_t* buf = NULL; + + ScfEboard_pack(b, &buf, &len); + ScfEboard_free(b); + b = NULL; + + FILE* fp = fopen("./add_gate.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/cpk/and_gate.c b/cpk/and_gate.c new file mode 100644 index 0000000..26ddfc9 --- /dev/null +++ b/cpk/and_gate.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* NAND0; + ScfEcomponent* NOT0; + ScfEcomponent* R0; + ScfEcomponent* R1; + + ScfEfunction* f; + ScfEboard* b; + + b = scf_eboard__alloc(); + f = scf_efunction__alloc("and_gate"); + + EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); + EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor); + + B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG; + B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS; + + EDA_INST_ADD_COMPONENT(f, NAND0, SCF_EDA_NAND); + EDA_INST_ADD_COMPONENT(f, NOT0, SCF_EDA_NOT); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NAND0, SCF_EDA_NAND_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NAND0, SCF_EDA_NAND_NEG); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOT0, SCF_EDA_NOT_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOT0, SCF_EDA_NOT_NEG); + + EDA_PIN_ADD_PIN(NAND0, SCF_EDA_NAND_OUT, NOT0, SCF_EDA_NOT_IN); + + EDA_PIN_ADD_PIN(R0, 0, NAND0, SCF_EDA_NAND_IN0); + EDA_PIN_ADD_PIN(R1, 0, NAND0, SCF_EDA_NAND_IN1); + + R0->pins[1]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + R1->pins[1]->flags = SCF_EDA_PIN_IN; + + NOT0->pins[SCF_EDA_NOT_OUT]->flags = SCF_EDA_PIN_OUT; + + scf_eboard__add_function(b, f); + + uint8_t* buf = NULL; + long len = 0; + + ScfEboard_pack(b, &buf, &len); + ScfEboard_free(b); + b = NULL; + + FILE* fp = fopen("./and_gate.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/cpk/nand.c b/cpk/nand.c new file mode 100644 index 0000000..f2b7a01 --- /dev/null +++ b/cpk/nand.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* R0; + ScfEcomponent* T0; + ScfEcomponent* T1; + + ScfEfunction* f; + + f = scf_efunction__alloc("nand.cpk"); + + EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN); + EDA_INST_ADD_COMPONENT(f, T1, SCF_EDA_NPN); + + EDA_PIN_ADD_PIN(R0, 0, T0, SCF_EDA_NPN_C); + EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E, T1, SCF_EDA_NPN_C); + + R0->pins[1]->flags = SCF_EDA_PIN_POS; + T1->pins[SCF_EDA_NPN_E]->flags = SCF_EDA_PIN_NEG; + + T0->pins[SCF_EDA_NPN_B]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + T1->pins[SCF_EDA_NPN_B]->flags = SCF_EDA_PIN_IN; + R0->pins[0]->flags = SCF_EDA_PIN_OUT; + + int len = 0; + uint8_t* buf = NULL; + + ScfEfunction_pack(f, &buf, &len); + ScfEfunction_free(f); + f = NULL; + + FILE* fp = fopen("./nand.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/cpk/nand.cpk b/cpk/nand.cpk new file mode 100644 index 0000000000000000000000000000000000000000..b80fcfaa098fef1c4330139eaaf7ff1f1981c9ad GIT binary patch literal 301 zcmY$%OUz5rOD@P};9=kZLIws74i*rF4p +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* R0; + ScfEcomponent* T0; + ScfEcomponent* T1; + + ScfEfunction* f; + + f = scf_efunction__alloc("nor.cpk"); + + EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN); + EDA_INST_ADD_COMPONENT(f, T1, SCF_EDA_NPN); + + EDA_PIN_ADD_PIN(R0, 0, T0, SCF_EDA_NPN_C); + EDA_PIN_ADD_PIN(R0, 0, T1, SCF_EDA_NPN_C); + EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E, T1, SCF_EDA_NPN_E); + + R0->pins[1]->flags = SCF_EDA_PIN_POS; + T0->pins[SCF_EDA_NPN_E]->flags = SCF_EDA_PIN_NEG; + + T0->pins[SCF_EDA_NPN_B]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + T1->pins[SCF_EDA_NPN_B]->flags = SCF_EDA_PIN_IN; + R0->pins[0]->flags = SCF_EDA_PIN_OUT; + + int len = 0; + uint8_t* buf = NULL; + + ScfEfunction_pack(f, &buf, &len); + ScfEfunction_free(f); + f = NULL; + + FILE* fp = fopen("./nor.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/cpk/nor.cpk b/cpk/nor.cpk new file mode 100644 index 0000000000000000000000000000000000000000..9fc5bc88ee2b512a4a79a785177f6164985ae354 GIT binary patch literal 304 zcmY$$%P-PPF34u!Vc-Bl1_llR77h*&10Aq1FbJTF!T5Z99fuuY93agi0W^<=!HN$g z#>ZFC?f_yS0Tvbp1r83Nkr)6Z2(kW?I8c(0&mrFdLlKey2goW8pk+XS)h3`}96;+Z M0mzr6*aS8K01eU% +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* R0; + ScfEcomponent* T0; + + ScfEfunction* f; + + f = scf_efunction__alloc("not.cpk"); + + EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN); + + EDA_PIN_ADD_PIN(R0, 0, T0, SCF_EDA_NPN_C); + + R0->pins[1]->flags = SCF_EDA_PIN_POS; + T0->pins[SCF_EDA_NPN_E]->flags = SCF_EDA_PIN_NEG; + + T0->pins[SCF_EDA_NPN_B]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + R0->pins[0]->flags = SCF_EDA_PIN_OUT; + + int len = 0; + uint8_t* buf = NULL; + + ScfEfunction_pack(f, &buf, &len); + ScfEfunction_free(f); + f = NULL; + + FILE* fp = fopen("./not.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/cpk/not.cpk b/cpk/not.cpk new file mode 100644 index 0000000000000000000000000000000000000000..f74503d7aef56bff56abe1a48c53a50146e4bede GIT binary patch literal 194 zcmY$$%P-MOF34u!07C`_4h|L$228-hz#xDr3K8Ms>p1LyB*`Mdz{9}8V8sU# +#include +#include +#include"ses_core.h" + +int main(int argc, char* argv[]) +{ + ScfEcomponent* B; + + ScfEcomponent* NOR0; + ScfEcomponent* NOT0; + + ScfEfunction* f; + ScfEboard* b; + + b = scf_eboard__alloc(); + f = scf_efunction__alloc("or_gate"); + + EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); + + B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG; + B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS; + + EDA_INST_ADD_COMPONENT(f, NOR0, SCF_EDA_NOR); + EDA_INST_ADD_COMPONENT(f, NOT0, SCF_EDA_NOT); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOR0, SCF_EDA_NAND_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOR0, SCF_EDA_NAND_NEG); + + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, NOT0, SCF_EDA_NOT_POS); + EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_NEG, NOT0, SCF_EDA_NOT_NEG); + + EDA_PIN_ADD_PIN(NOR0, SCF_EDA_NOR_OUT, NOT0, SCF_EDA_NOT_IN); + + NOR0->pins[SCF_EDA_NOR_IN0]->flags = SCF_EDA_PIN_IN | SCF_EDA_PIN_IN0; + NOR0->pins[SCF_EDA_NOR_IN1]->flags = SCF_EDA_PIN_IN; + + NOT0->pins[SCF_EDA_NOT_OUT]->flags = SCF_EDA_PIN_OUT; + + scf_eboard__add_function(b, f); + + int len = 0; + uint8_t* buf = NULL; + + ScfEboard_pack(b, &buf, &len); + ScfEboard_free(b); + b = NULL; + + FILE* fp = fopen("./or_gate.cpk", "wb"); + if (!fp) + return -EINVAL; + + fwrite(buf, len, 1, fp); + fclose(fp); + return 0; +} diff --git a/examples/add.cpk b/examples/add.cpk index f549b6accb3faa6f52e312a195ed74332f03dc08..ad32f5061b8ad2c55302396f605016a8791e98d8 100644 GIT binary patch delta 78 zcmZ3*wS#Ly(8R#@iP!TcyD-{KKF26Hc@m>7kgl2R$&@pB3lPgQJ4}vau9~m5Y5T}0s#NU8@~Vm diff --git a/examples/add2.cpk b/examples/add2.cpk index 30cbeebf6375b4c7a8c0f63e539d5a95c86ef01d..ae8ca9aa82ed41b209a0da9463b64acda7155b47 100644 GIT binary patch delta 186 zcmaDT*(^07Yhq^m#P@lVV;JowZ(tLgyo%8tO#fueo}A2-Gx;14TQWO<#X6a@Cx2$n znH0v)Y2`9@fIie^`qq=d!r~`3;lx+4CmPVb7V&&XF^@2#D`; z*nrh(a%NAS%xO3I0%y%+Z?2rl+qj&-;vC%BlZ&{4>VVjT#~Lg)nFnkKD+34s00zTD A0{{R3 delta 180 zcmZpcdMG&|YhrfW#80`C6BunL&tvqT{Eo4Dau!qe!Qz+M@+Uj9=T6?po;_KXBYScu5P#*c w2Fp2eW=~$r3DNf($WG_Vo_v|h5iF<5ojrLX5dQ_@Odg0`TX-xdzvB@F0Qx;bi2wiq diff --git a/examples/and.cpk b/examples/and.cpk index 4cfa6984d812c7c5ee6c0ebc5cb4129c5aa310b4..717e76d4bebb0889739ad2958d4820de3954c6d0 100644 GIT binary patch delta 50 wcmcb>dV_U>+eFvai6?U=n=sl<-oq$3xrxylNY_j@X9CecK9ePgW@P{Y0PR8$OaK4? delta 50 xcmcb?dVzI<+eG)4iD$AWTQJ&Au4EFJ+{S1PrY|vOPqt&S0&IOlsg%n!^*&-Y%#7EHe4fF{_4~v694lkXpqMe2KE|v$@*ZK^C zjrau4e-?YEv;HB;l0W}9yORx{PWo;(9ftXNKc7sy?qcY#>42CF5yi+9sHQ06KVl;9 zJy&wqG$37 w#8@PX<6CO9E(oK*Y`|z2*8xznZgH@`(S&j0`b diff --git a/examples/or.cpk b/examples/or.cpk index c52c94575adef2b87c06c78d0f8d63b5e790fa1c..a861ebd124931f1a2da9e0bc458cea2ba4923012 100644 GIT binary patch delta 50 wcmcc2dYg5E`$V_aiKlWVn=(2~-p?pFxs}lxNY_lZVgk`XK9ePgW@P{Y0PzeEZ2$lO delta 50 xcmcc3dYN^C`$UhHiD$DXTQb^Du3-|G+{tJSrmr$)Pj+Oo0birj^Aw`NHTLeiF#0LDleFy)!A`sttMo*j<$)4H_uTa~aUM7%YtP4Ga5AW$mo?$t z%U9xYNi4PI*AT8ByWU=n6u!L}Q;DrsT<(t>!s5JJMcEJ3z+tn@-;mO&41=FSczW*! zUO^NZl|j)-gXzQJ7*!HgW>Iir!z!5?!z%U%n}|uH)dz*=yq&cK|9!M^|8?@V^KiH5 zmrGImNj(% diff --git a/examples/sin_oscillator.cpk b/examples/sin_oscillator.cpk index 25cb122aff1f8b05b02288e083b2877f68692506..ddeef15c536b97182b845c924d9c062b5c9df318 100644 GIT binary patch delta 85 zcmeyw{+E41=){o7iEDf&evji6XJBC9<2#V#FgcM?a&kGN-Q@p_f|HLjS_5f6FgupX bcCtOQ#N>@onw8la$PWg~EdsLdFpB{IFcckY delta 83 zcmey%{)v4;=)|yyiR-;5{*Gmu%s4rcQF(GLqxIxD%mR~7LTOPZTQENvNP9AiPu>Bg Ud6}(&{2-v5_r&!AtPCIk0QnCZSpWb4 diff --git a/examples/sub.cpk b/examples/sub.cpk index b64b29046e55f2a78cd5ea24da856a6a2e302722..aea4f8909d3ac6a128af4debd569d811f37655b1 100644 GIT binary patch literal 1397 zcmb7^K}y9i5Qb+l$bcnADA+|8T@>k}NEdHWM5JCtaIGMoK`-EmT)(YnaP0~F|GXzP zA%z%tkjbB!|LY`q>Yrcka2akPfW*LABCGdmVE-ka6<`gL$FhcEjZ_4-nTyUnz5Z3X2D|V@oX5kc1p4m_ zD9$a9OS~hBDsorg_BKVrF;Hm5+@9PX#X8wBKT8hXYMw?qj0)^TipXo4q1V1;-#5&l z=d6f;pJ!r`S;ICpxIwLTHpmnl>H23V^x{^vq;C%#8|+Yhmoq{ZGhtUq-_fi?3Oc-D zMzzhE8I^LYo{j2du_4!Y?NRJ-TqKD{`U(b855Ml&yF@iEa*S|BVlXRg&`9c0%%)s9 z9sfZ+k$OTxxXD>+s-dGPI-j7ytdM#~YCN>Vv8KgzC)X}rJjQ9OXI7d~DfjuJ^VX5! Kg~$I~q5cnO-Z=pP literal 2331 zcmb7Gv5MP35S?NO11EF}7^1?33K3L@Lj)Hhn6LpCE>x&c;ljmnaP=J=`G({N@fYN0*1Mm-KK{PCdH*H7zJGc7ddi~)HIS@4#ZFI3gs`{L^v82J1B|I)JxeS< z3%@=>Dn40~OM;)+k^D4${2pEtO%FmGY7_xu|XNQy+c&nbw07lqW)O&xIsvBwH;l$@5Wh(rml*{-!n zRaj-UwGzCfiXG8SD_BDT0-P+g3usig z1Z%x?x}l7BD#mWV{Y15N-GVR{>W-bL@0tk2B3*CkdW)MJZ09A^?SJ?V^c_GLzYDH! zqGMHbc)s{iGl)g{-cf1?%AOQgiYUR0Wklko_G}Skiq3i)NWNSOJbJtxy>}oipMRp4 zDu@^nh()%kr&JHh^7$v~OA(2e8Yne@QZk!65u&~nk$9;CCvpH~tZJT75Ar#k2mig# Y{|p?N>4;2;N6_QajYWNLuk1+w3y?f&egFUf diff --git a/main.c b/main.c index 1a848f5..8d9aa7b 100644 --- a/main.c +++ b/main.c @@ -56,62 +56,55 @@ int main(int argc, char* argv[]) return -EINVAL; } - FILE* fp = fopen(argv[1], "rb"); - if (!fp) { - scf_loge("fopen '%s' error\n", argv[1]); - return -EINVAL; - } + ScfEcomponent* c; + ScfEfunction* f; + ScfEboard* b = NULL; + ScfEdata* ed = NULL; - fseek(fp, 0, SEEK_END); + uint8_t* buf = NULL; - int len = ftell(fp); + long len = scf_pack_read(&buf, argv[1]); if (len < 0) { - scf_loge("pb len: %d\n", len); - return -EINVAL; + scf_loge("scf_pack_read error: %ld\n", len); + return len; } - uint8_t* pb = calloc(1, len); - if (!pb) { - scf_loge("malloc error\n"); - return -ENOMEM; + long ret = ScfEboard_unpack(&b, buf, len); + if (ret < 0) { + scf_loge("ScfEboard__unpack error: %ld\n", ret); + return ret; } - fseek(fp, 0, SEEK_SET); + free(buf); + buf = NULL; - if (fread(pb, 1, len, fp) != len) { - scf_loge("fread error\n"); - return -ENOMEM; - } + long i; + long j; - fclose(fp); - fp = NULL; + for (i = 0; i < b->n_functions; i++) { + f = b->functions[i]; - ScfEcomponent* c; - ScfEfunction* f; - ScfEboard* b = NULL; + for (j = 0; j < f->n_components; j++) { + c = f->components[j]; - int ret = ScfEboard_unpack(&b, pb, len); - if (ret < 0) { - scf_loge("ScfEboard__unpack error: %d\n", ret); - return ret; + ed = scf_ecomponent__find_data(c->type, c->model); + if (ed) + c->ops = ed->ops; + } } - // print_board(b); #if 1 ses_layout_board(b, 100); - size_t i; - for (i = 0; i < b->n_functions; i++) { f = b->functions[i]; printf("f: %s\n", f->name); - ses_steps_analyse(f, 100, 3); +// ses_steps_analyse(f, 100, 1); } #endif ScfEboard_free(b); - free(pb); return 0; } diff --git a/pack/main.c b/pack/main.c index 7b6abb8..82e503b 100644 --- a/pack/main.c +++ b/pack/main.c @@ -38,7 +38,7 @@ int main() printf("z0: %p, z1: %p\n", z0, z1); uint8_t* buf = NULL; - int len = 0; + long len = 0; B_pack(&b, &buf, &len); diff --git a/pack/scf_pack.c b/pack/scf_pack.c index 1d440fe..e49ead7 100644 --- a/pack/scf_pack.c +++ b/pack/scf_pack.c @@ -1,12 +1,12 @@ #include"scf_pack.h" -int __scf_pack_one_index(uint8_t* pack, uint64_t u, int shift) +long __scf_pack_one_index(uint8_t* pack, uint64_t u, long shift) { - int max = -1; - int bits = 1u << shift; - int i; - int j; - int k; + long max = -1; + long bits = 1u << shift; + long i; + long j; + long k; j = 0; k = 3; @@ -61,15 +61,15 @@ int __scf_pack_one_index(uint8_t* pack, uint64_t u, int shift) return j + 1; } -int __scf_pack_byte_map(uint8_t* pack, uint64_t u, int shift) +long __scf_pack_byte_map(uint8_t* pack, uint64_t u, long shift) { uint8_t* p = (uint8_t*)&u; uint8_t map = 0; - int bytes = 1u << shift >> 3; - int i; - int j; - int k; + long bytes = 1u << shift >> 3; + long i; + long j; + long k; pack[0] |= 0x4; j = 0; @@ -101,12 +101,12 @@ int __scf_pack_byte_map(uint8_t* pack, uint64_t u, int shift) return j + 1; } -int __scf_pack2(uint8_t* pack, uint64_t u, int shift) +long __scf_pack2(uint8_t* pack, uint64_t u, long shift) { - int sum = 0; - int not = 0; - int bits = 1u << shift; - int i; + long sum = 0; + long not = 0; + long bits = 1u << shift; + long i; for (i = 0; i < bits; i++) { if (u & (1ull << i)) @@ -135,13 +135,13 @@ int __scf_pack2(uint8_t* pack, uint64_t u, int shift) return __scf_pack_byte_map(pack, u, shift); } -int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len) +long __scf_unpack2(void* p, long shift, const uint8_t* buf, long len) { - int bits = 1u << shift; - int max = -1; - int i; - int j; - int k; + long bits = 1u << shift; + long max = -1; + long i; + long j; + long k; if (len < 1) return -EINVAL; @@ -261,16 +261,16 @@ int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len) *(uint64_t*)p = u; break; default: - scf_loge("bits %d Not support!\n", bits); + scf_loge("bits %ld Not support!\n", bits); return -EINVAL; break; }; - scf_logd("u: %#lx, j: %d, bits: %d\n", u, j, bits); + scf_logd("u: %#lx, j: %d, bits: %ld\n", u, j, bits); return j; } -int __scf_unpack(void* p, int size, const uint8_t* buf, int len) +long __scf_unpack(void* p, long size, const uint8_t* buf, long len) { switch (size) { case 1: @@ -288,25 +288,11 @@ int __scf_unpack(void* p, int size, const uint8_t* buf, int len) break; case 4: -#if 0 - if (4 <= len) { - *(uint32_t*)p = *(uint32_t*)buf; - return 4; - } -#else return __scf_unpack2(p, 5, buf, len); -#endif break; case 8: -#if 0 - if (8 <= len) { - *(uint64_t*)p = *(uint64_t*)buf; - return 8; - } -#else return __scf_unpack2(p, 6, buf, len); -#endif break; default: scf_loge("data type NOT support!\n"); @@ -316,10 +302,10 @@ int __scf_unpack(void* p, int size, const uint8_t* buf, int len) return -EINVAL; } -int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen) +long __scf_pack(void* p, long size, uint8_t** pbuf, long* plen) { uint8_t pack[64]; - int len = 0; + long len = 0; switch (size) { case 1: @@ -331,29 +317,21 @@ int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen) len = 2; break; case 4: -#if 1 len = __scf_pack2(pack, *(uint32_t*)p, 5); if (len < 0) return len; -#else - *(uint32_t*)pack = *(uint32_t*)p; - len = 4; -#endif - scf_logd("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len); + + scf_logd("p: %p, %d, len: %ld\n\n", p, *(uint32_t*)p, len); break; case 8: -#if 1 len = __scf_pack2(pack, *(uint64_t*)p, 6); if (len < 0) return len; -#else - *(uint64_t*)pack = *(uint64_t*)p; - len = 8; -#endif - scf_logd("p: %p, %ld, %#lx, %lg, len: %d\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len); + + scf_logd("p: %p, %ld, %#lx, %lg, len: %ld\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len); break; default: - scf_loge("data size '%d' NOT support!\n", size); + scf_loge("data size '%ld' NOT support!\n", size); return -EINVAL; break; }; @@ -368,7 +346,7 @@ int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen) return 0; } -int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* plen) +long scf_pack(void* p, scf_pack_info_t* infos, long n_infos, uint8_t** pbuf, long* plen) { if (!p || !infos || n_infos < 1 || !pbuf || !plen) return -EINVAL; @@ -376,10 +354,10 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* if (!*pbuf) *plen = 0; -// printf("\n"); +// prlongf("\n"); scf_logd("p: %p\n", p); - int i; + long i; for (i = 0; i < n_infos; i++) { scf_logd("name: %s, size: %ld, offset: %ld, noffset: %ld, msize: %ld, members: %p, n_members: %ld\n", infos[i].name, infos[i].size, infos[i].offset, infos[i].noffset, infos[i].msize, infos[i].members, infos[i].n_members); @@ -388,22 +366,22 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* void* a = *(void**)(p + infos[i].offset); long n = *(long* )(p + infos[i].noffset); - int j; + long j; scf_logd("a: %p, n: %ld, infos[i].msize: %ld, infos[i].noffset: %ld\n", a, n, infos[i].msize, infos[i].noffset); for (j = 0; j < n; j++) { if (infos[i].members) { - int ret = scf_pack(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, pbuf, plen); + long ret = scf_pack(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, pbuf, plen); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } } else { - int ret = __scf_pack(a + j * infos[i].msize, infos[i].msize, pbuf, plen); + long ret = __scf_pack(a + j * infos[i].msize, infos[i].msize, pbuf, plen); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } } @@ -414,17 +392,17 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* if (infos[i].members) { - int ret = scf_pack(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, pbuf, plen); + long ret = scf_pack(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, pbuf, plen); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } continue; } - int ret = __scf_pack(p + infos[i].offset, infos[i].size, pbuf, plen); + long ret = __scf_pack(p + infos[i].offset, infos[i].size, pbuf, plen); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } @@ -434,20 +412,20 @@ int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* return 0; } -int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* buf, int len) +long scf_unpack(void** pp, scf_pack_info_t* infos, long n_infos, const uint8_t* buf, long len) { if (!pp || !infos || n_infos < 1 || !buf || len < 1) return -EINVAL; - int size = infos[n_infos - 1].offset + infos[n_infos - 1].size; + long size = infos[n_infos - 1].offset + infos[n_infos - 1].size; void* p = calloc(1, size); if (!p) return -ENOMEM; - int i; - int j; - int k = 0; + long i; + long j; + long k = 0; for (i = 0; i < n_infos; i++) { @@ -464,18 +442,18 @@ int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* bu for (j = 0; j < n; j++) { if (infos[i].members) { - int ret = scf_unpack((void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, buf + k, len - k); + long ret = scf_unpack((void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, buf + k, len - k); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } k += ret; } else { - int ret = __scf_unpack(a + j * infos[i].msize, infos[i].msize, buf + k, len - k); + long ret = __scf_unpack(a + j * infos[i].msize, infos[i].msize, buf + k, len - k); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } @@ -488,9 +466,9 @@ int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* bu if (infos[i].members) { - int ret = scf_unpack((void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, buf + k, len - k); + long ret = scf_unpack((void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, buf + k, len - k); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } @@ -498,9 +476,9 @@ int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* bu continue; } - int ret = __scf_unpack(p + infos[i].offset, infos[i].size, buf + k, len - k); + long ret = __scf_unpack(p + infos[i].offset, infos[i].size, buf + k, len - k); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } @@ -511,13 +489,13 @@ int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* bu return k; } -int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos) +long scf_unpack_free(void* p, scf_pack_info_t* infos, long n_infos) { if (!p || !infos || n_infos < 1) return -EINVAL; - int i; - int j; + long i; + long j; for (i = 0; i < n_infos; i++) { if (infos[i].noffset >= 0) { @@ -529,9 +507,9 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos) if (infos[i].members) { for (j = 0; j < n; j++) { - int ret = scf_unpack_free(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members); + long ret = scf_unpack_free(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } } @@ -543,9 +521,9 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos) } if (infos[i].members) { - int ret = scf_unpack_free(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members); + long ret = scf_unpack_free(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members); if (ret < 0) { - scf_loge("ret: %d\n", ret); + scf_loge("ret: %ld\n", ret); return ret; } } @@ -555,3 +533,40 @@ int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos) free(p); return 0; } + +long scf_pack_read(uint8_t** pbuf, const char* cpk) +{ + if (!pbuf || !cpk) + return -EINVAL; + + FILE* fp = fopen(cpk, "rb"); + if (!fp) + return -EINVAL; + + fseek(fp, 0, SEEK_END); + + long len = ftell(fp); + if (len < 0) { + fclose(fp); + return -EINVAL; + } + + uint8_t* buf = calloc(1, len); + if (!buf) { + fclose(fp); + return -ENOMEM; + } + + fseek(fp, 0, SEEK_SET); + + if (fread(buf, 1, len, fp) != len) { + free(buf); + fclose(fp); + return -EINVAL; + } + + fclose(fp); + + *pbuf = buf; + return len; +} diff --git a/pack/scf_pack.h b/pack/scf_pack.h index 133497b..97984d5 100644 --- a/pack/scf_pack.h +++ b/pack/scf_pack.h @@ -16,9 +16,9 @@ struct scf_pack_info_s long n_members; }; -int scf_pack (void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* plen); -int scf_unpack (void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* buf, int len); -int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos); +long scf_pack (void* p, scf_pack_info_t* infos, long n_infos, uint8_t** pbuf, long* plen); +long scf_unpack (void** pp, scf_pack_info_t* infos, long n_infos, const uint8_t* buf, long len); +long scf_unpack_free(void* p, scf_pack_info_t* infos, long n_infos); #define SCF_PACK_DEF_VAR(type, var) type var #define SCF_PACK_DEF_VARS(type, vars) long n_##vars; type* vars @@ -45,17 +45,19 @@ static scf_pack_info_t scf_pack_info_##type[] = { #define SCF_PACK_END(type) \ }; \ -static int type##_pack(type* p, uint8_t** pbuf, int* plen) \ +static long type##_pack(type* p, uint8_t** pbuf, long* plen) \ { \ return scf_pack(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type), pbuf, plen); \ } \ -static int type##_unpack(type** pp, uint8_t* buf, int len) \ +static long type##_unpack(type** pp, uint8_t* buf, long len) \ { \ return scf_unpack((void**)pp, scf_pack_info_##type, SCF_PACK_N_INFOS(type), buf, len); \ } \ -static int type##_free(type* p) \ +static long type##_free(type* p) \ { \ return scf_unpack_free(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type)); \ } +long scf_pack_read(uint8_t** pbuf, const char* cpk); + #endif diff --git a/scf_eda_pack.c b/scf_eda_pack.c index cd251bf..c56a19f 100644 --- a/scf_eda_pack.c +++ b/scf_eda_pack.c @@ -12,34 +12,183 @@ static int component_pins[SCF_EDA_Components_NB] = SCF_EDA_Diode_NB, SCF_EDA_NPN_NB, SCF_EDA_PNP_NB, + + SCF_EDA_NAND_NB, + SCF_EDA_NOR_NB, + SCF_EDA_NOT_NB, }; -static scf_edata_t component_datas[] = +static int __diode_path_off(ScfEpin* p0, ScfEpin* p1) +{ + if (SCF_EDA_Diode_NEG == p0->id) + return 1; + return 0; +} + +static int __npn_path_off(ScfEpin* p0, ScfEpin* p1) +{ + if (SCF_EDA_NPN_E == p0->id) + return 1; + + if (!p1 || SCF_EDA_NPN_E == p1->id) + return 0; + return 1; +} + +static int __npn_shared(ScfEpin* p) +{ + if (SCF_EDA_NPN_E == p->id) + return 1; + return 0; +} + +static int __pnp_path_off(ScfEpin* p0, ScfEpin* p1) +{ + if (SCF_EDA_PNP_E == p0->id) + return 0; + return 1; +} + +static int __pnp_shared(ScfEpin* p) +{ + if (SCF_EDA_PNP_E == p->id) + return 1; + return 0; +} + +static int __nand_path_off(ScfEpin* p0, ScfEpin* p1) +{ + if (SCF_EDA_NAND_NEG == p0->id) + return 1; + + if (SCF_EDA_NAND_POS == p0->id) { + if (p1 && (SCF_EDA_NAND_IN0 == p1->id || SCF_EDA_NAND_IN1 == p1->id)) + return 1; + + } else if (p1 && SCF_EDA_NAND_NEG != p1->id) + return 1; + return 0; +} + +static int __nand_shared(ScfEpin* p) +{ + if (SCF_EDA_NAND_NEG == p->id || SCF_EDA_NAND_POS == p->id) + return 1; + return 0; +} + +static int __nor_path_off(ScfEpin* p0, ScfEpin* p1) { - {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0}, - {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 1e-9, 1e9, 0, 0}, + if (SCF_EDA_NOR_NEG == p0->id) + return 1; - {SCF_EDA_Resistor, 0, 0, 0, 0, 1e4, 0, 0, 0}, - {SCF_EDA_Capacitor, 0, 0, 0, 0, 10, 0.1, 0, 0}, - {SCF_EDA_Inductor, 0, 0, 0, 0, 10, 0, 1e3, 0}, + if (SCF_EDA_NOR_POS == p0->id) { + if (p1 && (SCF_EDA_NOR_IN0 == p1->id || SCF_EDA_NOR_IN1 == p1->id)) + return 1; + + } else if (p1 && SCF_EDA_NOR_NEG != p1->id) + return 1; + return 0; +} + +static int __nor_shared(ScfEpin* p) +{ + if (SCF_EDA_NOR_NEG == p->id || SCF_EDA_NOR_POS == p->id) + return 1; + return 0; +} + +static int __not_path_off(ScfEpin* p0, ScfEpin* p1) +{ + if (SCF_EDA_NOT_NEG == p0->id) + return 1; + + if (SCF_EDA_NOT_POS == p0->id) { + if (p1 && SCF_EDA_NOT_IN == p1->id) + return 1; + + } else if (p1 && SCF_EDA_NOT_NEG != p1->id) + return 1; + return 0; +} + +static int __not_shared(ScfEpin* p) +{ + if (SCF_EDA_NOT_NEG == p->id || SCF_EDA_NOT_POS == p->id) + return 1; + return 0; +} + +static ScfEops __diode_ops = +{ + __diode_path_off, + NULL, }; -static scf_edata_t pin_datas[] = +static ScfEops __npn_ops = { - {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0}, + __npn_path_off, + __npn_shared, +}; - {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0}, +static ScfEops __pnp_ops = +{ + __pnp_path_off, + __pnp_shared, +}; - {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0}, - {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 3, 0, 0, 250}, +static ScfEops __nand_ops = +{ + __nand_path_off, + __nand_shared, +}; - {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0}, - {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 3, 0, 0, 250}, +static ScfEops __nor_ops = +{ + __nor_path_off, + __nor_shared, }; -static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid) +static ScfEops __not_ops = { - scf_edata_t* ed; + __not_path_off, + __not_shared, +}; + +static ScfEdata component_datas[] = +{ + {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL}, + {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 1e-9, 1e9, 0, 0, NULL, NULL}, + + {SCF_EDA_Resistor, 0, 0, 0, 0, 1e4, 0, 0, 0, NULL, NULL}, + {SCF_EDA_Capacitor, 0, 0, 0, 0, 10, 0.1, 0, 0, NULL, NULL}, + {SCF_EDA_Inductor, 0, 0, 0, 0, 10, 0, 1e3, 0, NULL, NULL}, + + {SCF_EDA_Diode, 0, 0, 0, 0, 0, 0, 0, 0, &__diode_ops, NULL}, + {SCF_EDA_NPN, 0, 0, 0, 0, 0, 0, 0, 0, &__npn_ops, NULL}, + {SCF_EDA_PNP, 0, 0, 0, 0, 0, 0, 0, 0, &__pnp_ops, NULL}, + + {SCF_EDA_NAND, 0, 0, 0, 0, 0, 0, 0, 0, &__nand_ops, "./cpk/nand.cpk"}, + {SCF_EDA_NOR, 0, 0, 0, 0, 0, 0, 0, 0, &__nor_ops, "./cpk/nor.cpk"}, + {SCF_EDA_NOT, 0, 0, 0, 0, 0, 0, 0, 0, &__not_ops, "./cpk/not.cpk"}, +}; + +static ScfEdata pin_datas[] = +{ + {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL}, + + {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0, NULL, NULL}, + + {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0, NULL, NULL}, + {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 3, 0, 0, 250, NULL, NULL}, + + {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0, NULL, NULL}, + {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 3, 0, 0, 250, NULL, NULL}, +}; + +static ScfEdata* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid) +{ + ScfEdata* ed; int i; for (i = 0; i < sizeof(pin_datas) / sizeof(pin_datas[0]); i++) { @@ -52,9 +201,9 @@ static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, co return NULL; } -static scf_edata_t* _component_find_data(const uint64_t type, const uint64_t model) +ScfEdata* scf_ecomponent__find_data(const uint64_t type, const uint64_t model) { - scf_edata_t* ed; + ScfEdata* ed; int i; for (i = 0; i < sizeof(component_datas) / sizeof(component_datas[0]); i++) { @@ -342,7 +491,7 @@ int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid) ScfEcomponent* scf_ecomponent__alloc(uint64_t type) { ScfEcomponent* c; - scf_edata_t* ed; + ScfEdata* ed; if (type >= SCF_EDA_Components_NB) return NULL; @@ -353,13 +502,24 @@ ScfEcomponent* scf_ecomponent__alloc(uint64_t type) c->type = type; - ed = _component_find_data(c->type, c->model); + ed = scf_ecomponent__find_data(c->type, c->model); if (ed) { - c->v = ed->v; - c->a = ed->a; - c->r = ed->r; - c->uf = ed->uf; - c->uh = ed->uh; + c->v = ed->v; + c->a = ed->a; + c->r = ed->r; + c->uf = ed->uf; + c->uh = ed->uh; + c->ops = ed->ops; + + if (ed->cpk) { + c->n_cpk = strlen(ed->cpk) + 1; + + c->cpk = strdup(ed->cpk); + if (!c->cpk) { + ScfEcomponent_free(c); + return NULL; + } + } } int i; diff --git a/scf_eda_pack.h b/scf_eda_pack.h index cf2a246..2f094ab 100644 --- a/scf_eda_pack.h +++ b/scf_eda_pack.h @@ -15,6 +15,10 @@ enum { SCF_EDA_NPN, SCF_EDA_PNP, + SCF_EDA_NAND, + SCF_EDA_NOR, + SCF_EDA_NOT, + SCF_EDA_Components_NB, }; @@ -74,6 +78,38 @@ enum { SCF_EDA_PNP_NB = SCF_EDA_NPN_NB, }; +enum { + SCF_EDA_NAND_NEG, + SCF_EDA_NAND_POS, + + SCF_EDA_NAND_IN0, + SCF_EDA_NAND_IN1, + SCF_EDA_NAND_OUT, + + SCF_EDA_NAND_NB, +}; + +enum { + SCF_EDA_NOR_NEG, + SCF_EDA_NOR_POS, + + SCF_EDA_NOR_IN0, + SCF_EDA_NOR_IN1, + SCF_EDA_NOR_OUT, + + SCF_EDA_NOR_NB, +}; + +enum { + SCF_EDA_NOT_NEG, + SCF_EDA_NOT_POS, + + SCF_EDA_NOT_IN, + SCF_EDA_NOT_OUT, + + SCF_EDA_NOT_NB, +}; + typedef struct { uint64_t type; uint64_t model; @@ -86,7 +122,10 @@ typedef struct { double uf; double uh; double hfe; -} scf_edata_t; + + void* ops; + char* cpk; +} ScfEdata; typedef struct { SCF_PACK_DEF_VAR(int, x0); @@ -102,11 +141,18 @@ SCF_PACK_INFO_VAR(ScfLine, x1), SCF_PACK_INFO_VAR(ScfLine, y1), SCF_PACK_END(ScfLine) +typedef struct scf_eops_s ScfEops; typedef struct scf_epin_s ScfEpin; typedef struct scf_ecomponent_s ScfEcomponent; typedef struct scf_efunction_s ScfEfunction; typedef struct scf_eboard_s ScfEboard; +struct scf_eops_s +{ + int (*off )(ScfEpin* p0, ScfEpin* p1); + int (*shared)(ScfEpin* p); +}; + struct scf_epin_s { SCF_PACK_DEF_VAR(uint64_t, id); @@ -116,6 +162,8 @@ struct scf_epin_s SCF_PACK_DEF_VARS(uint64_t, tos); SCF_PACK_DEF_VAR(uint64_t, c_lid); + SCF_PACK_DEF_OBJ(ScfEcomponent, IC); + SCF_PACK_DEF_VAR(double, v); SCF_PACK_DEF_VAR(double, a); @@ -229,6 +277,10 @@ struct scf_ecomponent_s SCF_PACK_DEF_VAR(uint64_t, model); SCF_PACK_DEF_OBJS(ScfEpin, pins); + SCF_PACK_DEF_VARS(uint8_t, cpk); + SCF_PACK_DEF_OBJ(ScfEfunction, f); + SCF_PACK_DEF_OBJ(ScfEops, ops); + SCF_PACK_DEF_VAR(double, v); SCF_PACK_DEF_VAR(double, a); @@ -238,6 +290,7 @@ struct scf_ecomponent_s SCF_PACK_DEF_VAR(double, uf); SCF_PACK_DEF_VAR(double, uh); + SCF_PACK_DEF_VAR(int64_t, count); SCF_PACK_DEF_VAR(int64_t, color); SCF_PACK_DEF_VAR(int, status); @@ -255,6 +308,8 @@ SCF_PACK_INFO_VAR(ScfEcomponent, type), SCF_PACK_INFO_VAR(ScfEcomponent, model), SCF_PACK_INFO_OBJS(ScfEcomponent, pins, ScfEpin), +SCF_PACK_INFO_VARS(ScfEcomponent, cpk, uint8_t), + SCF_PACK_INFO_VAR(ScfEcomponent, v), SCF_PACK_INFO_VAR(ScfEcomponent, a), @@ -327,11 +382,11 @@ int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid) ScfEcomponent* scf_ecomponent__alloc (uint64_t type); int scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin); int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin); +ScfEdata* scf_ecomponent__find_data(const uint64_t type, const uint64_t model); ScfEfunction* scf_efunction__alloc (const char* name); int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c); int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c); - int scf_efunction__add_eline (ScfEfunction* f, ScfEline* el); int scf_efunction__del_eline (ScfEfunction* f, ScfEline* el); diff --git a/ses_core.h b/ses_core.h index 94724c0..0a3cd52 100644 --- a/ses_core.h +++ b/ses_core.h @@ -118,6 +118,8 @@ struct ses_edge_s int index; uint8_t bflag:1; + + uint8_t amplify_flag:1; }; struct ses_node_s diff --git a/ses_layout.c b/ses_layout.c index b9d3542..d64d5bb 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -710,7 +710,7 @@ static int __ses_layout_lines(ScfEfunction* f, int d) ScfEline* el; ScfLine* l; - size_t i; + long i; int ret = __ses_layout_lines2(f); if (ret < 0) @@ -748,10 +748,10 @@ static void __ses_layout_components(ScfEfunction* f, int d) ScfEpin* p0; ScfEpin* p1; - size_t i; - size_t j; - size_t m; - size_t n; + long i; + long j; + long m; + long n; for (i = 0; i < f->n_elines - 1; i++) { el0 = f->elines[i]; @@ -829,12 +829,12 @@ static void __ses_xchg_components(ScfEfunction* f, int d) ScfEpin* p2; ScfEpin* p3; - size_t i; - size_t j; - size_t k; - size_t m; - size_t n; - size_t q; + long i; + long j; + long k; + long m; + long n; + long q; for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; @@ -906,32 +906,6 @@ static void __ses_xchg_components(ScfEfunction* f, int d) } } -static inline void __ses_flip_neg(ScfEcomponent* c) -{ - ScfEpin* p; - size_t i; - - for (i = 0; i < c->n_pins; i++) { - p = c->pins[i]; - - if (p->x > 0) - p->x = -p->x; - } -} - -static inline void __ses_flip_pos(ScfEcomponent* c) -{ - ScfEpin* p; - size_t i; - - for (i = 0; i < c->n_pins; i++) { - p = c->pins[i]; - - if (p->x < 0) - p->x = -p->x; - } -} - static int __ses_get_crosses(ScfEfunction* f, int d, scf_vector_t* crosses) { ses_vertex_t* edge0; @@ -944,12 +918,12 @@ static int __ses_get_crosses(ScfEfunction* f, int d, scf_vector_t* crosses) ScfEpin* p2; ScfEpin* p3; - size_t i; - size_t j; - size_t k; - size_t m; - size_t n; - size_t q; + long i; + long j; + long k; + long m; + long n; + long q; for (i = 0; i < f->n_components - 1; i++) { c0 = f->components[i]; @@ -1216,9 +1190,10 @@ static void __ses_set_xy(ScfEfunction* f, int d) ScfEcomponent* c; ScfEpin* p0; ScfEpin* p1; + ScfEpin* p2; - size_t i; - size_t j; + long i; + long j; for (i = 0; i < f->n_components; i++) { c = f->components[i]; @@ -1236,14 +1211,56 @@ static void __ses_set_xy(ScfEfunction* f, int d) continue; } - for (j = 1; j < c->n_pins; j++) { - p0 = c->pins[j]; + int n = 0; + if (c->color > 0) + n = (c->color - 1) % 2; + + switch (c->type) { + case SCF_EDA_NPN: + case SCF_EDA_PNP: + p0 = c->pins[SCF_EDA_NPN_C]; + p1 = c->pins[SCF_EDA_NPN_E]; - if (j & 0x1) - p0->x = c->x - d / 3; - else p0->x = c->x + d / 3; - } + p1->x = c->x - d / 3; + break; + + case SCF_EDA_NAND: + case SCF_EDA_NOR: + p1->x = c->x; + + p0 = c->pins[SCF_EDA_NAND_IN0]; + p1 = c->pins[SCF_EDA_NAND_IN1]; + p2 = c->pins[SCF_EDA_NAND_OUT]; + + if (0 == n) { + p0->x = c->x + 36; + p1->x = c->x + 36; + p2->x = c->x - 36; + } else { + p0->x = c->x - 36; + p1->x = c->x - 36; + p2->x = c->x + 36; + } + break; + + case SCF_EDA_NOT: + p1->x = c->x; + + p0 = c->pins[SCF_EDA_NOT_IN]; + p1 = c->pins[SCF_EDA_NOT_OUT]; + + if (c->x < p1->x) { + p0->x = c->x - 36; + p1->x = c->x + 36; + } else { + p0->x = c->x + 36; + p1->x = c->x - 36; + } + break; + default: + break; + }; } } @@ -1436,6 +1453,19 @@ static void __ses_min_cx(ScfEfunction* f, int d) if (c->color > 0) m0 = (c->color - 1) / 2; + int y0 = INT_MAX; + int y1 = 0; + + for (k = 0; k < c->n_pins; k++) { + p = c->pins[k]; + + if (y0 > p->y) + y0 = p->y; + + if (y1 < p->y) + y1 = p->y; + } + for (j = i - 1; j >= 0; j--) { c2 = f->components[j]; @@ -1454,32 +1484,42 @@ static void __ses_min_cx(ScfEfunction* f, int d) p2 = c2->pins[m]; if (p->y == p2->y) { - if ((c->y >= p->y && c2->y >= p->y) || (c->y <= p->y && c2->y <= p->y)) { + if ((c->y >= p->y && c2->y >= p->y) || (c->y <= p->y && c2->y <= p->y)) + goto _max; - if (max < c2->x) { - max = c2->x; - scf_logd("c%ld->x: %d, c%ld->x: %d\n", c->id, c->x, c2->id, c2->x); - } - } - } else if (p->y > p2->y) { - if ((c->y < p->y && c2->y > c->y) || (c->y >= p->y && c2->y > p->y)) { - if (max < c2->x) - max = c2->x; - } - } else { - if ((c->y < p->y && c2->y < p->y) || (c->y >= p->y && c2->y < c->y)) { - if (max < c2->x) - max = c2->x; - } + scf_logd("c%ld->x: %d, c%ld->x: %d\n", c->id, c->x, c2->id, c2->x); + goto _next; } } } + + int y2 = INT_MAX; + int y3 = 0; + + for (m = 0; m < c2->n_pins; m++) { + p2 = c2->pins[m]; + + if (y2 > p2->y) + y2 = p2->y; + + if (y3 < p2->y) + y3 = p2->y; + } + + if (!(y1 <= y2 || y0 >= y3)) + goto _max; +_next: + continue; +_max: + if (max < c2->x) + max = c2->x; } if (0 == max) continue; + c->x = max + d; -_set_px: + for (k = 0; k < c->n_pins; k++) { p = c->pins[k]; p->x += c->x - tmp; @@ -1493,13 +1533,20 @@ _set_px: c2 = f->components[i - 1]; int tmp = c->x; + if (tmp - c2->x > d) { - if (c->x - c2->x > d) { - c->x = c2->x + d; + for (j = i; j < f->n_components; j++) { + c = f->components[j]; - for (k = 0; k < c->n_pins; k++) { - p = c->pins[k]; - p->x += c->x - tmp; + if (c->x > tmp) + break; + + c->x = c2->x + d; + + for (k = 0; k < c->n_pins; k++) { + p = c->pins[k]; + p->x += c->x - tmp; + } } } } diff --git a/ses_node_analysis.c b/ses_node_analysis.c index 8516e65..3893ccf 100644 --- a/ses_node_analysis.c +++ b/ses_node_analysis.c @@ -332,7 +332,7 @@ static void ses_AbX_print(double* A, double* b, double* X, int N) { int i; int j; - +#if 0 printf("A:\n"); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) @@ -343,7 +343,7 @@ static void ses_AbX_print(double* A, double* b, double* X, int N) printf("\nb:\n"); for (j = 0; j < N; j++) printf("%lg\n", b[j]); - +#endif printf("\nX:\n"); for (j = 0; j < N; j++) printf("%lg\n", X[j]); @@ -511,9 +511,9 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A double Rb = SCF_EDA_V_NPN_ON / Ib; if (-1e8 < Rb && Rb < 1e8) { - if (dV < SCF_EDA_V_NPN_ON * 0.995 || dV > SCF_EDA_V_NPN_ON * 1.005) { + if (dV < SCF_EDA_V_NPN_ON * 0.99 || dV > SCF_EDA_V_NPN_ON * 1.01) { - scf_logd("edge: [%d] c%ldp%ld-c%ldp%ld, Vb: %lg, Ve: %lg, dV: %lg, Ib: %lg, Rb: %lg\n", + scf_logi("edge: [%d] c%ldp%ld-c%ldp%ld, Vb: %lg, Ve: %lg, dV: %lg, Ib: %lg, Rb: %lg\n", edge->index, p0->cid, p0->id, p1->cid, p1->id, Vb, Ve, dV, Ib, Rb); A[(n + edge->index) * N + n + edge->index] = -Rb; @@ -524,7 +524,7 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A c->lock = 1; (*n_offs)++; - scf_logd("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index); + scf_logi("\033[34mc%ld, status: %d, dV: %lg, Ib: %lg, Rb: %lg, edge->index: %d\033[0m\n", c->id, c->status, dV, Ib, Rb, edge->index); } } else if (edge->edge_b) { @@ -533,18 +533,40 @@ static int __ses_edges_update_Ab(ScfEfunction* f, scf_vector_t* edges, double* A double dI = Ib * edge->hfe - Ic; - if (dI < -1e-10) { - scf_logd("edge: [%d] c%ldp%ld-c%ldp%ld [b%d], Ic: %lg, Ib: %lg, dI: %lg\n", - edge->index, p0->cid, p0->id, p1->cid, p1->id, edge->edge_b->index, Ic, Ib, dI); + double Vb; + double Ve; - for (i = 0; i < N; i++) - A[(n + edge->index) * N + i] = 0; + if (edge->edge_b->node1 && edge->edge_b->node1->lid != Bp->lid) + Vb = X[edge->edge_b->node1->index]; + else + Vb = Bp->v; - A[(n + edge->index) * N + n + edge->index] = -1; - A[(n + edge->index) * N + n + edge->edge_b->index] = edge->hfe; - b[ n + edge->index] = 0; + if (edge->edge_b->node0 && edge->edge_b->node0->lid != Bn->lid) + Ve = X[edge->edge_b->node0->index]; + else + Ve = Bn->v; - k++; + double dV = Vb - Ve; + double Rb = SCF_EDA_V_NPN_ON / Ib; + + if (dI < -1e-10 + && -1e8 < Rb && Rb < 1e8) { + + if (!edge->amplify_flag) { + edge->amplify_flag = 1; + + scf_logi("edge: [%d] c%ldp%ld-c%ldp%ld [b%d], Ic: %lg, Ib: %lg, dI: %lg, dVbe: %lg, Rb: %lg\n", + edge->index, p0->cid, p0->id, p1->cid, p1->id, edge->edge_b->index, Ic, Ib, dI, dV, Rb); + + for (i = 0; i < N; i++) + A[(n + edge->index) * N + i] = 0; + + A[(n + edge->index) * N + n + edge->index] = -1; + A[(n + edge->index) * N + n + edge->edge_b->index] = edge->hfe; + b[ n + edge->index] = 0; + + k++; + } } } } @@ -610,6 +632,7 @@ static int __ses_nodes_path_solve2(ScfEfunction* f, ses_path_t* path, int vip_m, int n_offs = 0; +#define MAX_TRYS 100 int try = 0; do { n_offs = 0; @@ -624,9 +647,12 @@ static int __ses_nodes_path_solve2(ScfEfunction* f, ses_path_t* path, int vip_m, ret = __ses_edges_update_Ab(f, edges, A, b, X, N, &n_offs); try++; - } while (ret > 0 && try < 100); + scf_logi("ret: %d, try: %d\n\n", ret, try); + + } while (ret > 0 && try < MAX_TRYS); - scf_logi("ret: %d, try: %d\n\n", ret, try); + if (try >= MAX_TRYS) + return -1; for (i = 0; i < n; i++) { node = nodes->data[i]; diff --git a/ses_step_simplify.c b/ses_step_draw.c similarity index 67% rename from ses_step_simplify.c rename to ses_step_draw.c index e3a2cce..b265879 100644 --- a/ses_step_simplify.c +++ b/ses_step_draw.c @@ -65,6 +65,8 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr) { ScfEcomponent* c; ScfEpin* p; + ScfEpin* p0; + ScfEpin* p1; ScfEpin* pb; ScfEpin* pc; ScfEpin* pe; @@ -83,7 +85,7 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr) cairo_set_source_rgb (cr, 0, 0, 0); cairo_select_font_face(cr, "Calibri", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 20); - cairo_move_to (cr, c->x - 10 - n * 10, c->y - 5); + cairo_move_to (cr, c->x - 10 - n * 10, c->y - 12); cairo_show_text (cr, text); cairo_stroke(cr); @@ -471,13 +473,291 @@ void __ses_function_draw(ScfEfunction* f, cairo_t* cr) ses_text_a(cr, c->x, c->y - 20, pe->a); cairo_stroke(cr); break; + + case SCF_EDA_NAND: + p = c->pins[SCF_EDA_NAND_OUT]; + p0 = c->pins[SCF_EDA_NAND_IN0]; + p1 = c->pins[SCF_EDA_NAND_IN1]; + + if (c->x < p->x) { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x + 32, c->y); + cairo_line_to(cr, c->x + 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x + 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_arc(cr, c->x + 6, c->y, 10, -0.5 * M_PI, 0.5 * M_PI); + cairo_stroke(cr); + + cairo_move_to(cr, c->x + 6, c->y + 10); + cairo_line_to(cr, c->x - 6, c->y + 10); + cairo_line_to(cr, c->x - 6, c->y - 10); + cairo_line_to(cr, c->x + 6, c->y - 10); + + if (p0->y < p1->y) { + cairo_move_to(cr, c->x - 6, c->y - 5); + cairo_line_to(cr, c->x - 14, c->y - 5); + cairo_line_to(cr, p0->x, p0->y); + + cairo_move_to(cr, c->x - 6, c->y + 5); + cairo_line_to(cr, c->x - 14, c->y + 5); + cairo_line_to(cr, p1->x, p1->y); + } else { + cairo_move_to(cr, c->x - 6, c->y - 5); + cairo_line_to(cr, c->x - 14, c->y - 5); + cairo_line_to(cr, p1->x, p1->y); + + cairo_move_to(cr, c->x - 6, c->y + 5); + cairo_line_to(cr, c->x - 14, c->y + 5); + cairo_line_to(cr, p0->x, p0->y); + } + + } else { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x - 32, c->y); + cairo_line_to(cr, c->x - 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x - 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_arc(cr, c->x - 6, c->y, 10, 0.5 * M_PI, 1.5 * M_PI); + cairo_stroke(cr); + + cairo_move_to(cr, c->x - 6, c->y + 10); + cairo_line_to(cr, c->x + 6, c->y + 10); + cairo_line_to(cr, c->x + 6, c->y - 10); + cairo_line_to(cr, c->x - 6, c->y - 10); + + if (p0->y < p1->y) { + cairo_move_to(cr, c->x + 6, c->y - 5); + cairo_line_to(cr, c->x + 14, c->y - 5); + cairo_line_to(cr, p0->x, p0->y); + + cairo_move_to(cr, c->x + 6, c->y + 5); + cairo_line_to(cr, c->x + 14, c->y + 5); + cairo_line_to(cr, p1->x, p1->y); + } else { + cairo_move_to(cr, c->x + 6, c->y - 5); + cairo_line_to(cr, c->x + 14, c->y - 5); + cairo_line_to(cr, p1->x, p1->y); + + cairo_move_to(cr, c->x + 6, c->y + 5); + cairo_line_to(cr, c->x + 14, c->y + 5); + cairo_line_to(cr, p0->x, p0->y); + } + } + cairo_stroke(cr); + + p = c->pins[SCF_EDA_NAND_POS]; + if (p->y < c->y) { + cairo_move_to(cr, c->x, c->y - 10); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NAND_NEG]; + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, p->x, p->y); + } else { + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NAND_NEG]; + cairo_move_to(cr, c->x, c->y - 10); + cairo_line_to(cr, p->x, p->y); + } + + cairo_stroke(cr); + break; + + case SCF_EDA_NOR: + p = c->pins[SCF_EDA_NOR_OUT]; + p0 = c->pins[SCF_EDA_NOR_IN0]; + p1 = c->pins[SCF_EDA_NOR_IN1]; + + if (c->x < p->x) { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x + 32, c->y); + cairo_line_to(cr, c->x + 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x + 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_save(cr); + cairo_translate(cr, c->x, c->y); + cairo_scale(cr, 1.6, 1.0); + cairo_arc (cr, 0, 0, 10, -0.5 * M_PI, 0.5 * M_PI); + cairo_restore(cr); + cairo_stroke(cr); + + cairo_save(cr); + cairo_translate(cr, c->x - 6, c->y); + cairo_scale(cr, 0.6, 1.0); + cairo_arc (cr, 0, 0, 10, -0.5 * M_PI, 0.5 * M_PI); + cairo_restore(cr); + cairo_stroke(cr); + + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, c->x - 6, c->y + 10); + cairo_move_to(cr, c->x - 6, c->y - 10); + cairo_line_to(cr, c->x, c->y - 10); + + if (p0->y < p1->y) { + cairo_move_to(cr, c->x - 2, c->y - 5); + cairo_line_to(cr, c->x - 10, c->y - 5); + cairo_line_to(cr, p0->x, p0->y); + + cairo_move_to(cr, c->x - 2, c->y + 5); + cairo_line_to(cr, c->x - 10, c->y + 5); + cairo_line_to(cr, p1->x, p1->y); + } else { + cairo_move_to(cr, c->x - 2, c->y - 5); + cairo_line_to(cr, c->x - 10, c->y - 5); + cairo_line_to(cr, p1->x, p1->y); + + cairo_move_to(cr, c->x - 2, c->y + 5); + cairo_line_to(cr, c->x - 10, c->y + 5); + cairo_line_to(cr, p0->x, p0->y); + } + + } else { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x - 32, c->y); + cairo_line_to(cr, c->x - 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x - 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_save(cr); + cairo_translate(cr, c->x, c->y); + cairo_scale(cr, 1.6, 1.0); + cairo_arc (cr, 0, 0, 10, 0.5 * M_PI, 1.5 * M_PI); + cairo_restore(cr); + cairo_stroke(cr); + + cairo_save(cr); + cairo_translate(cr, c->x + 6, c->y); + cairo_scale(cr, 0.6, 1.0); + cairo_arc (cr, 0, 0, 10, 0.5 * M_PI, 1.5 * M_PI); + cairo_restore(cr); + cairo_stroke(cr); + + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, c->x + 6, c->y + 10); + cairo_move_to(cr, c->x + 6, c->y - 10); + cairo_line_to(cr, c->x, c->y - 10); + + if (p0->y < p1->y) { + cairo_move_to(cr, c->x + 2, c->y - 5); + cairo_line_to(cr, c->x + 10, c->y - 5); + cairo_line_to(cr, p0->x, p0->y); + + cairo_move_to(cr, c->x + 2, c->y + 5); + cairo_line_to(cr, c->x + 10, c->y + 5); + cairo_line_to(cr, p1->x, p1->y); + } else { + cairo_move_to(cr, c->x + 2, c->y - 5); + cairo_line_to(cr, c->x + 10, c->y - 5); + cairo_line_to(cr, p1->x, p1->y); + + cairo_move_to(cr, c->x + 2, c->y + 5); + cairo_line_to(cr, c->x + 10, c->y + 5); + cairo_line_to(cr, p0->x, p0->y); + } + } + cairo_stroke(cr); + + p = c->pins[SCF_EDA_NOR_POS]; + if (p->y < c->y) { + cairo_move_to(cr, c->x, c->y - 10); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NOR_NEG]; + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, p->x, p->y); + } else { + cairo_move_to(cr, c->x, c->y + 10); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NOR_NEG]; + cairo_move_to(cr, c->x, c->y - 10); + cairo_line_to(cr, p->x, p->y); + } + + cairo_stroke(cr); + break; + + case SCF_EDA_NOT: + p = c->pins[SCF_EDA_NOT_OUT]; + + if (c->x < p->x) { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x + 32, c->y); + cairo_line_to(cr, c->x + 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x + 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_move_to(cr, c->x + 16, c->y); + cairo_line_to(cr, c->x - 16, c->y + 10); + cairo_line_to(cr, c->x - 16, c->y - 10); + cairo_line_to(cr, c->x + 16, c->y); + + p = c->pins[SCF_EDA_NOT_IN]; + cairo_move_to(cr, c->x - 16, c->y); + cairo_line_to(cr, c->x - 24, c->y); + cairo_line_to(cr, p->x, p->y); + } else { + cairo_move_to(cr, p->x, p->y); + cairo_line_to(cr, c->x - 32, c->y); + cairo_line_to(cr, c->x - 24, c->y); + cairo_stroke(cr); + + cairo_arc(cr, c->x - 20, c->y, 4, 0, 2 * M_PI); + cairo_stroke(cr); + + cairo_move_to(cr, c->x - 16, c->y); + cairo_line_to(cr, c->x + 16, c->y + 10); + cairo_line_to(cr, c->x + 16, c->y - 10); + cairo_line_to(cr, c->x - 16, c->y); + + p = c->pins[SCF_EDA_NOT_IN]; + cairo_move_to(cr, c->x + 16, c->y); + cairo_line_to(cr, c->x + 24, c->y); + cairo_line_to(cr, p->x, p->y); + } + cairo_stroke(cr); + + p = c->pins[SCF_EDA_NOT_POS]; + if (p->y < c->y) { + cairo_move_to(cr, c->x, c->y - 5); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NOT_NEG]; + cairo_move_to(cr, c->x, c->y + 5); + cairo_line_to(cr, p->x, p->y); + } else { + cairo_move_to(cr, c->x, c->y + 5); + cairo_line_to(cr, p->x, p->y); + + p = c->pins[SCF_EDA_NOT_NEG]; + cairo_move_to(cr, c->x, c->y - 5); + cairo_line_to(cr, p->x, p->y); + } + + cairo_stroke(cr); + break; default: break; }; } } -int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh, int64_t ns, int64_t count) +int ses_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh, int64_t ns, int64_t count) { ScfEcomponent* B; ScfEcomponent* c; @@ -622,12 +902,12 @@ int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t b return 0; } -static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +static int _draw_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { static int64_t i = 0; char file[128]; - snprintf(file, sizeof(file) - 1, "./simplify_%ld.png", i); + snprintf(file, sizeof(file) - 1, "./draw_%ld.png", i); #if 0 if (count < 64000) return 0; @@ -642,16 +922,16 @@ static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx if (fp) fprintf(fp, "%ld, %lg\n", i, f->elines[4]->v); #endif - ses_simplify_draw(f, file, f->x, f->y, f->w, f->h, ns, count); + ses_draw(f, file, f->x, f->y, f->w, f->h, ns, count); i++; } return 0; } -ses_step_t ses_step_simplify = +ses_step_t ses_step_draw = { - .name = "simplify", + .name = "draw", - .handler = _simplify_handler, + .handler = _draw_handler, }; diff --git a/ses_step_jr.c b/ses_step_jr.c index c27668a..d297356 100644 --- a/ses_step_jr.c +++ b/ses_step_jr.c @@ -120,7 +120,7 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) p->pr = r; } - scf_loge("path: %d, i: %d, c%ldp%ld, sr: %lg\n", path->index, i, p->cid, p->id, p->sr); + scf_logd("path: %d, i: %d, c%ldp%ld, sr: %lg\n", path->index, i, p->cid, p->id, p->sr); } if (path->childs) { @@ -172,7 +172,7 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) child->parent_pr = p1->pr; - scf_logi("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg, pr: %lg, dr: %lg\n", j, p1->cid, p1->id, p1->pr, p1->sr, pr, dr); + scf_logd("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg, pr: %lg, dr: %lg\n", j, p1->cid, p1->id, p1->pr, p1->sr, pr, dr); for (++j; j < path->pins->size; j++) { p = path->pins->data[j]; @@ -180,10 +180,10 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) p->pr -= dr; p->sr -= dr; - scf_logi("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg\n", j, p->cid, p->id, p->pr, p->sr); + scf_logd("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg\n", j, p->cid, p->id, p->pr, p->sr); } - scf_logw("child: %d, pr: %lg, dr: %lg\n", child->index, child->pr, dr); + scf_logi("child: %d, pr: %lg, dr: %lg\n", child->index, child->pr, dr); } } @@ -208,7 +208,7 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) path->pr = p->pr; path->sr = p->sr; - scf_loge("path: %d, pr: %lg, sr: %lg\n\n", path->index, path->pr, path->sr); + scf_logi("path: %d, pr: %lg, sr: %lg\n\n", path->index, path->pr, path->sr); return 0; } diff --git a/ses_step_output.c b/ses_step_output.c index f5bb247..a47b1fd 100644 --- a/ses_step_output.c +++ b/ses_step_output.c @@ -7,20 +7,24 @@ static int _output_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG]; ScfEline* el; - int i; + long i; printf("\n"); for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; - scf_logd("e%ld->vconst: %d\n", el->id, el->vconst); - if (SCF_EDA_PIN_OUT & el->flags) - scf_logw("out el: %ld, V: %lg\n", el->id, el->v); + scf_logi("out el: %ld, V: %lg\n", el->id, el->v); + } + + printf("\n"); + + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; - else if (SCF_EDA_PIN_CF & el->flags) - scf_logw("cf el: %ld, V: %lg\n", el->id, el->v); + if (SCF_EDA_PIN_CF & el->flags) + scf_logi("cf el: %ld, V: %lg\n", el->id, el->v); } return 0; diff --git a/ses_step_topo.c b/ses_step_topo.c index 23a6380..fbc0f7e 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -24,7 +24,7 @@ static int __ses_dfs_add_ppath(scf_vector_t* paths, ses_path_t** ppath) return 0; } -static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, ses_path_t** ppath) +static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_vector_t* __paths, ses_path_t** ppath, int flags) { ScfEcomponent* c; ScfEline* el; @@ -34,13 +34,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v int64_t i; int64_t j; - if (SCF_EDA_Diode == rc->type && SCF_EDA_Diode_NEG == rp->id) - return SCF_EDA_Path_OFF; - - if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id) - return SCF_EDA_Path_OFF; - - if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E != rp->id) + if (rc->ops && rc->ops->off && rc->ops->off(rp, NULL)) return SCF_EDA_Path_OFF; if (SCF_EDA_Status_OFF != rc->status) { @@ -54,8 +48,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v return -ENOMEM; } - if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == rp->id) - || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == rp->id))) + if (!rc->ops || !rc->ops->shared || !rc->ops->shared(rp)) rp->vflag = 1; scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", rp->cid, rp->id, rp->lid, rp->vflag, rp->pflag); @@ -68,9 +61,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v if (np->vflag) continue; - if (SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E != np->id) - continue; - if (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id) + if (rc->ops && rc->ops->off && rc->ops->off(rp, np)) continue; scf_logd("c%ldp%ld, l%ld, vflag: %d, pflag: %d\n", np->cid, np->id, np->lid, np->vflag, np->pflag); @@ -91,7 +82,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v return -ENOMEM; } - if (SCF_EDA_PNP == rc->type && 0 == (*ppath)->pins->size) { + if (rc->ops && rc->ops->shared && rc->ops->shared(rp) && 0 == (*ppath)->pins->size) { if (scf_vector_add((*ppath)->pins, rp) < 0) return -ENOMEM; @@ -101,8 +92,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v return -ENOMEM; } - if (!((SCF_EDA_NPN == rc->type && SCF_EDA_NPN_E == np->id) - || (SCF_EDA_PNP == rc->type && SCF_EDA_PNP_E == np->id))) + if (!rc->ops || !rc->ops->shared || !rc->ops->shared(np)) np->vflag = 1; if (SCF_EDA_PIN_NEG & el->flags) { @@ -110,7 +100,12 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v if (SCF_EDA_Status_OFF == rc->status) return 0; - return __ses_dfs_add_ppath(__paths, ppath); + + ret = __ses_dfs_add_ppath(__paths, ppath); + if (ret < 0) + return ret; + + continue; } ses_path_t* off = NULL; @@ -153,8 +148,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v *ppath = NULL; } - if (!((SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) - || (SCF_EDA_PNP == c->type && SCF_EDA_PNP_E == p->id))) + if (!c->ops || !c->ops->shared || !c->ops->shared(p)) p->vflag = 1; ses_path_t* tmp = NULL; @@ -165,7 +159,7 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v *ppath = NULL; } - ret = __ses_dfs_path(f, c, p, __paths, ppath); + ret = __ses_dfs_path(f, c, p, __paths, ppath, flags); if (ret < 0) return ret; @@ -188,15 +182,13 @@ static int __ses_dfs_path(ScfEfunction* f, ScfEcomponent* rc, ScfEpin* rp, scf_v if (off) *ppath = off; - if (*ppath) { - scf_vector_del((*ppath)->pins, np); + if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) { + if (*ppath) + scf_vector_del((*ppath)->pins, np); - if (SCF_EDA_Status_OFF != ret) - ret = SCF_EDA_Path_OFF; + if (SCF_EDA_Path_OFF == ret) + np->vflag = 0; } - - if (SCF_EDA_Path_OFF == ret) - np->vflag = 0; } if (SCF_EDA_Status_OFF == ret || SCF_EDA_Path_OFF == ret) { @@ -1194,7 +1186,7 @@ static void _topo_clear(ScfEfunction* f) } } -static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths) +static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths, int flags) { if (!f || !el || !paths) return -EINVAL; @@ -1217,7 +1209,7 @@ static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths) if (c == B) continue; - int ret = __ses_dfs_path(f, c, p, paths, &path); + int ret = __ses_dfs_path(f, c, p, paths, &path, flags); if (ret < 0) return ret; @@ -1560,7 +1552,7 @@ int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths) B = f->components[0]; el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid]; - int ret = _topo_paths(f, el, paths); + int ret = _topo_paths(f, el, paths, 0); if (ret < 0) return ret; @@ -1570,13 +1562,13 @@ int ses_layout_paths(ScfEfunction* f, scf_vector_t* paths) if (el->flags & SCF_EDA_PIN_IN) { - ret = _topo_paths(f, el, paths); + ret = _topo_paths(f, el, paths, 0); if (ret < 0) return ret; } } - ses_paths_print(paths); +// ses_paths_print(paths); return __ses_topo_layers(f, paths); } @@ -1595,7 +1587,7 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* B = f->components[0]; el = f->elines[B->pins[SCF_EDA_Battery_POS]->lid]; - int ret = _topo_paths(f, el, ctx->paths); + int ret = _topo_paths(f, el, ctx->paths, 1); if (ret < 0) return ret; diff --git a/ses_steps.c b/ses_steps.c index 5b6f94c..9801475 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -19,7 +19,7 @@ extern ses_step_t ses_step_open; extern ses_step_t ses_step_va_nodes; extern ses_step_t ses_step_output; -extern ses_step_t ses_step_simplify; +extern ses_step_t ses_step_draw; static ses_step_t* ses_steps_0[] = @@ -49,7 +49,7 @@ static ses_step_t* ses_steps_2[] = &ses_step_va_nodes, &ses_step_output, - &ses_step_simplify, + &ses_step_draw, }; static int __ses_analyse_input(ScfEfunction* f, int64_t ns, int64_t i, ses_ctx_t* ctx) diff --git a/test/Makefile b/test/Makefile index 5c5ce8c..1ddd2a9 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,6 +1,6 @@ -#CFILES += main.c +CFILES += main.c #CFILES += test.c -CFILES += fft.c +#CFILES += fft.c #CFILES += dct.c #CFILES += pnp.c #CFILES += colpitts.c -- 2.25.1