From: yu.dongliang <18588496441@163.com> Date: Wed, 4 Oct 2023 15:54:00 +0000 (+0800) Subject: native/eda X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=6b5134d44929640e201a58d2a902c6e7bbc89909;p=scf.git native/eda --- diff --git a/native/eda/scf_eda.c b/native/eda/scf_eda.c index 76dfe9e..af1f810 100644 --- a/native/eda/scf_eda.c +++ b/native/eda/scf_eda.c @@ -127,7 +127,7 @@ int scf_eda_select_inst(scf_native_t* ctx, scf_function_t* f) if (!f->ef) return -ENOMEM; - EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery); + EDA_INST_ADD_COMPONENT(f->ef, 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; diff --git a/native/eda/scf_eda.h b/native/eda/scf_eda.h index 276b4a5..a48b68d 100644 --- a/native/eda/scf_eda.h +++ b/native/eda/scf_eda.h @@ -4,43 +4,6 @@ #include"scf_native.h" #include"scf_eda_pb.h" -#define EDA_INST_ADD_COMPONENT(_f, _c, _type) \ - do { \ - _c = scf_ecomponent__alloc(_type); \ - if (!_c) \ - return -ENOMEM; \ - \ - (_c)->id = (_f)->ef->n_components; \ - \ - int ret = scf_efunction__add_component((_f)->ef, _c); \ - if (ret < 0) { \ - scf_ecomponent__free(_c); \ - _c = NULL; \ - return ret; \ - } \ - \ - for (size_t i = 0; i < (_c)->n_pins; i++) \ - (_c)->pins[i]->cid = (_c)->id; \ - } while (0) - -#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \ - do { \ - int ret = scf_epin__add_component((_pin), _cid, _pid); \ - if (ret < 0) \ - return ret; \ - } while (0) - -#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \ - do { \ - int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \ - if (ret < 0) \ - return ret; \ - \ - ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \ - if (ret < 0) \ - return ret; \ - } while (0) - typedef struct { scf_function_t* f; diff --git a/native/eda/scf_eda.pb-c.c b/native/eda/scf_eda.pb-c.c index ff59055..dc2927b 100644 --- a/native/eda/scf_eda.pb-c.c +++ b/native/eda/scf_eda.pb-c.c @@ -385,7 +385,7 @@ const ProtobufCMessageDescriptor scf_line__descriptor = (ProtobufCMessageInit) scf_line__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = +static const ProtobufCFieldDescriptor scf_epin__field_descriptors[28] = { { "id", @@ -664,9 +664,21 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = 0,NULL,NULL /* reserved1,reserved2, etc */ }, { - "vflag", + "n_diodes", 24, PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_INT32, + 0, /* quantifier_offset */ + offsetof(ScfEpin, n_diodes), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "vflag", + 25, + PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_BOOL, 0, /* quantifier_offset */ offsetof(ScfEpin, vflag), @@ -677,7 +689,7 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = }, { "pflag", - 25, + 26, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_BOOL, 0, /* quantifier_offset */ @@ -689,7 +701,7 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = }, { "vconst", - 26, + 27, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_BOOL, 0, /* quantifier_offset */ @@ -701,7 +713,7 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = }, { "aconst", - 27, + 28, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_BOOL, 0, /* quantifier_offset */ @@ -714,7 +726,7 @@ static const ProtobufCFieldDescriptor scf_epin__field_descriptors[27] = }; static const unsigned scf_epin__field_indices_by_name[] = { 8, /* field[8] = a */ - 26, /* field[26] = aconst */ + 27, /* field[27] = aconst */ 5, /* field[5] = c_lid */ 1, /* field[1] = cid */ 15, /* field[15] = dr */ @@ -728,7 +740,8 @@ static const unsigned scf_epin__field_indices_by_name[] = { 18, /* field[18] = jsr */ 7, /* field[7] = jv */ 2, /* field[2] = lid */ - 24, /* field[24] = pflag */ + 23, /* field[23] = n_diodes */ + 25, /* field[25] = pflag */ 19, /* field[19] = pr */ 10, /* field[10] = r */ 17, /* field[17] = sr */ @@ -736,15 +749,15 @@ static const unsigned scf_epin__field_indices_by_name[] = { 12, /* field[12] = uF */ 13, /* field[13] = uH */ 6, /* field[6] = v */ - 25, /* field[25] = vconst */ - 23, /* field[23] = vflag */ + 26, /* field[26] = vconst */ + 24, /* field[24] = vflag */ 21, /* field[21] = x */ 22, /* field[22] = y */ }; static const ProtobufCIntRange scf_epin__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 27 } + { 0, 28 } }; const ProtobufCMessageDescriptor scf_epin__descriptor = { @@ -754,7 +767,7 @@ const ProtobufCMessageDescriptor scf_epin__descriptor = "ScfEpin", "", sizeof(ScfEpin), - 27, + 28, scf_epin__field_descriptors, scf_epin__field_indices_by_name, 1, scf_epin__number_ranges, diff --git a/native/eda/scf_eda.pb-c.h b/native/eda/scf_eda.pb-c.h index db9998a..24e3c9d 100644 --- a/native/eda/scf_eda.pb-c.h +++ b/native/eda/scf_eda.pb-c.h @@ -69,6 +69,7 @@ struct _ScfEpin double jpr; int32_t x; int32_t y; + int32_t n_diodes; protobuf_c_boolean vflag; protobuf_c_boolean pflag; protobuf_c_boolean vconst; @@ -76,7 +77,7 @@ struct _ScfEpin }; #define SCF_EPIN__INIT \ { PROTOBUF_C_MESSAGE_INIT (&scf_epin__descriptor) \ - , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } struct _ScfEconn diff --git a/native/eda/scf_eda.proto b/native/eda/scf_eda.proto index e4d6fd3..9338efe 100644 --- a/native/eda/scf_eda.proto +++ b/native/eda/scf_eda.proto @@ -39,11 +39,14 @@ message scf_epin required int32 x = 22; required int32 y = 23; - required bool vflag = 24; - required bool pflag = 25; - required bool vconst = 26; - required bool aconst = 27; + required int32 n_diodes = 24; + + required bool vflag = 25; + required bool pflag = 26; + + required bool vconst = 27; + required bool aconst = 28; } message scf_econn diff --git a/native/eda/scf_eda_inst.c b/native/eda/scf_eda_inst.c index 630a3da..2179c08 100644 --- a/native/eda/scf_eda_inst.c +++ b/native/eda/scf_eda_inst.c @@ -98,8 +98,8 @@ static int _eda_inst_bit_not_handler(scf_native_t* ctx, scf_3ac_code_t* c) for (i = 0; i < N; i++) { - EDA_INST_ADD_COMPONENT(f, T, SCF_EDA_Transistor); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f->ef, T, SCF_EDA_Transistor); + EDA_INST_ADD_COMPONENT(f->ef, R, SCF_EDA_Resistor); EDA_PIN_ADD_INPUT(in, i, T, SCF_EDA_Transistor_B); @@ -139,9 +139,9 @@ static int _eda_inst_bit_and_handler(scf_native_t* ctx, scf_3ac_code_t* c) for (i = 0; i < N; i++) { - EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f->ef, D0, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f->ef, D1, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f->ef, R, SCF_EDA_Resistor); EDA_PIN_ADD_INPUT(in0, i, D0, SCF_EDA_Diode_NEG); EDA_PIN_ADD_INPUT(in1, i, D1, SCF_EDA_Diode_NEG); @@ -183,9 +183,9 @@ static int _eda_inst_bit_or_handler(scf_native_t* ctx, scf_3ac_code_t* c) for (i = 0; i < N; i++) { - EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); - EDA_INST_ADD_COMPONENT(f, R, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f->ef, D0, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f->ef, D1, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f->ef, R, SCF_EDA_Resistor); EDA_PIN_ADD_INPUT(in0, i, D0, SCF_EDA_Diode_POS); EDA_PIN_ADD_INPUT(in1, i, D1, SCF_EDA_Diode_POS); diff --git a/native/eda/scf_eda_pb.h b/native/eda/scf_eda_pb.h index 8f2aecf..059f2b6 100644 --- a/native/eda/scf_eda_pb.h +++ b/native/eda/scf_eda_pb.h @@ -27,6 +27,9 @@ enum { #define SCF_EDA_V_MIN -10000000.0 #define SCF_EDA_V_MAX 10000000.0 +#define SCF_EDA_V_Diode_ON 0.69 +#define SCF_EDA_V_Diode_OFF 0.70 + enum { SCF_EDA_Battery_NEG, SCF_EDA_Battery_POS, @@ -107,4 +110,41 @@ int scf_eboard__add_function(ScfEboard* b, ScfEfunction* f); int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f); void scf_eboard__free (ScfEboard* b); +#define EDA_INST_ADD_COMPONENT(_ef, _c, _type) \ + do { \ + _c = scf_ecomponent__alloc(_type); \ + if (!_c) \ + return -ENOMEM; \ + \ + (_c)->id = (_ef)->n_components; \ + \ + int ret = scf_efunction__add_component(_ef, _c); \ + if (ret < 0) { \ + scf_ecomponent__free(_c); \ + _c = NULL; \ + return ret; \ + } \ + \ + for (size_t i = 0; i < (_c)->n_pins; i++) \ + (_c)->pins[i]->cid = (_c)->id; \ + } while (0) + +#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \ + do { \ + int ret = scf_epin__add_component((_pin), _cid, _pid); \ + if (ret < 0) \ + return ret; \ + } while (0) + +#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \ + do { \ + int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \ + if (ret < 0) \ + return ret; \ + \ + ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \ + if (ret < 0) \ + return ret; \ + } while (0) + #endif