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./
--- /dev/null
+#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
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#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;
+}
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;
}
printf("z0: %p, z1: %p\n", z0, z1);
uint8_t* buf = NULL;
- int len = 0;
+ long len = 0;
B_pack(&b, &buf, &len);
#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;
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;
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))
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;
*(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:
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");
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:
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;
};
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;
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);
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;
}
}
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;
}
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++) {
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;
}
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;
}
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;
}
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) {
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;
}
}
}
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;
}
}
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;
+}
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
#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
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++) {
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++) {
ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
{
ScfEcomponent* c;
- scf_edata_t* ed;
+ ScfEdata* ed;
if (type >= SCF_EDA_Components_NB)
return NULL;
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;
SCF_EDA_NPN,
SCF_EDA_PNP,
+ SCF_EDA_NAND,
+ SCF_EDA_NOR,
+ SCF_EDA_NOT,
+
SCF_EDA_Components_NB,
};
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;
double uf;
double uh;
double hfe;
-} scf_edata_t;
+
+ void* ops;
+ char* cpk;
+} ScfEdata;
typedef struct {
SCF_PACK_DEF_VAR(int, x0);
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);
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);
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);
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);
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),
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);
int index;
uint8_t bflag:1;
+
+ uint8_t amplify_flag:1;
};
struct ses_node_s
ScfEline* el;
ScfLine* l;
- size_t i;
+ long i;
int ret = __ses_layout_lines2(f);
if (ret < 0)
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];
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];
}
}
-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;
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];
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];
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;
+ };
}
}
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];
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;
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;
+ }
}
}
}
{
int i;
int j;
-
+#if 0
printf("A:\n");
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++)
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]);
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;
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) {
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++;
+ }
}
}
}
int n_offs = 0;
+#define MAX_TRYS 100
int try = 0;
do {
n_offs = 0;
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];
{
ScfEcomponent* c;
ScfEpin* p;
+ ScfEpin* p0;
+ ScfEpin* p1;
ScfEpin* pb;
ScfEpin* pc;
ScfEpin* pe;
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);
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;
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;
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,
};
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) {
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];
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);
}
}
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;
}
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;
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;
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) {
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);
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);
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;
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) {
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;
*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;
*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;
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) {
}
}
-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;
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;
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;
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);
}
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;
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[] =
&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)
-#CFILES += main.c
+CFILES += main.c
#CFILES += test.c
-CFILES += fft.c
+#CFILES += fft.c
#CFILES += dct.c
#CFILES += pnp.c
#CFILES += colpitts.c