typedef struct scf_register_s scf_register_t;
typedef struct scf_OpCode_s scf_OpCode_t;
-typedef struct _ScfEpin ScfEpin;
-typedef struct _ScfEcomponent ScfEcomponent;
-typedef struct _ScfEfunction ScfEfunction;
-typedef struct _ScfEboard ScfEboard;
+typedef struct scf_epin_s ScfEpin;
+typedef struct scf_ecomponent_s ScfEcomponent;
+typedef struct scf_efunction_s ScfEfunction;
+typedef struct scf_eboard_s ScfEboard;
enum scf_core_types {
SCF_OP_ADD = 0, // +
#define SCF_EDA_H
#include"scf_native.h"
-#include"scf_eda_pb.h"
+#include"scf_eda_pack.h"
typedef struct {
--- /dev/null
+#include "scf_eda_pack.h"
+//#include "scf_def.h"
+
+static int component_pins[SCF_EDA_Components_NB] =
+{
+ 0, // None
+ SCF_EDA_Battery_NB, // SCF_EDA_Battery
+
+ 2, // SCF_EDA_Resistor
+ 2, // SCF_EDA_Capacitor
+ 2, // SCF_EDA_Inductor
+
+ SCF_EDA_Diode_NB,
+ SCF_EDA_NPN_NB,
+ SCF_EDA_PNP_NB,
+};
+
+static scf_edata_t component_datas[] =
+{
+ {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 0, 0, 0, 0, 0},
+
+ {SCF_EDA_Resistor, 0, 0, 0, 0, 10 * 1000, 0, 0, 0, 0},
+ {SCF_EDA_Capacitor, 0, 0, 0, 0, 1e12, 0, 0.1, 0, 0},
+ {SCF_EDA_Inductor, 0, 0, 0, 0, 0, 0, 0, 1000, 0},
+};
+
+static scf_edata_t pin_datas[] =
+{
+ {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+
+ {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0, 0},
+
+ {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0, 0},
+ {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 10, 0, 0, 0, 150},
+
+ {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0, 0},
+ {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 10, 0, 0, 0, 150},
+};
+
+static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid)
+{
+ scf_edata_t* ed;
+
+ int i;
+ for (i = 0; i < sizeof(pin_datas) / sizeof(pin_datas[0]); i++) {
+ ed = &pin_datas[i];
+
+ if (ed->type == type && ed->model == model && ed->pid == pid)
+ return ed;
+ }
+
+ return NULL;
+}
+
+static scf_edata_t* _component_find_data(const uint64_t type, const uint64_t model)
+{
+ scf_edata_t* ed;
+
+ int i;
+ for (i = 0; i < sizeof(component_datas) / sizeof(component_datas[0]); i++) {
+ ed = &component_datas[i];
+
+ if (ed->type == type && ed->model == model)
+ return ed;
+ }
+
+ return NULL;
+}
+
+ScfEconn* scf_econn__alloc()
+{
+ ScfEconn* ec = calloc(1, sizeof(ScfEconn));
+
+ return ec;
+}
+
+int scf_econn__add_cid(ScfEconn* ec, uint64_t cid)
+{
+ if (!ec)
+ return -EINVAL;
+
+ for (size_t i = 0; i < ec->n_cids; i++) {
+
+ if (ec->cids[i] == cid)
+ return 0;
+ }
+
+ uint64_t* p = realloc(ec->cids, sizeof(uint64_t) * (ec->n_cids + 1));
+ if (!p)
+ return -ENOMEM;
+
+ ec->cids = p;
+ ec->cids[ec->n_cids++] = cid;
+ return 0;
+}
+
+int scf_econn__del_cid(ScfEconn* ec, uint64_t cid)
+{
+ if (!ec)
+ return -EINVAL;
+
+ uint64_t* p;
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < ec->n_cids; i++) {
+
+ if (ec->cids[i] == cid) {
+
+ for (j = i + 1; j < ec->n_cids; j++)
+ ec->cids[j - 1] = ec->cids[j];
+
+ ec->n_cids--;
+
+ p = realloc(ec->cids, sizeof(uint64_t) * ec->n_cids);
+ if (p)
+ ec->cids = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+ScfEline* scf_eline__alloc()
+{
+ ScfEline* l = calloc(1, sizeof(ScfEline));
+
+ return l;
+}
+
+int scf_eline__add_line(ScfEline* el, ScfLine* l)
+{
+ if (!el || !l)
+ return -EINVAL;
+
+ for (size_t i = 0; i < el->n_lines; i++) {
+
+ if (el->lines[i] == l)
+ return 0;
+
+ if (el->lines[i]->x0 == l->x0
+ && el->lines[i]->y0 == l->y0
+ && el->lines[i]->x1 == l->x1
+ && el->lines[i]->y1 == l->y1)
+ return 0;
+ }
+
+ void* p = realloc(el->lines, sizeof(ScfLine*) * (el->n_lines + 1));
+ if (!p)
+ return -ENOMEM;
+
+ el->lines = p;
+ el->lines[el->n_lines++] = l;
+ return 0;
+}
+
+int scf_eline__del_line(ScfEline* el, ScfLine* l)
+{
+ if (!el || !l)
+ return -EINVAL;
+
+ void* p;
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < el->n_lines; i++) {
+
+ if (el->lines[i]->x0 == l->x0
+ && el->lines[i]->y0 == l->y0
+ && el->lines[i]->x1 == l->x1
+ && el->lines[i]->y1 == l->y1) {
+
+ for (j = i + 1; j < el->n_lines; j++)
+ el->lines[j - 1] = el->lines[j];
+
+ el->n_lines--;
+
+ p = realloc(el->lines, sizeof(ScfLine*) * el->n_lines);
+ if (p)
+ el->lines = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+int scf_eline__add_pin(ScfEline* el, uint64_t cid, uint64_t pid)
+{
+ if (!el)
+ return -EINVAL;
+
+ for (size_t i = 0; i + 1 < el->n_pins; i += 2) {
+
+ if (el->pins[i] == cid && el->pins[i + 1] == pid)
+ return 0;
+ }
+
+ uint64_t* p = realloc(el->pins, sizeof(uint64_t) * (el->n_pins + 2));
+ if (!p)
+ return -ENOMEM;
+
+ el->pins = p;
+ el->pins[el->n_pins++] = cid;
+ el->pins[el->n_pins++] = pid;
+ return 0;
+}
+
+int scf_eline__del_pin(ScfEline* el, uint64_t cid, uint64_t pid)
+{
+ if (!el)
+ return -EINVAL;
+
+ uint64_t* p;
+ size_t i;
+ size_t j;
+
+ for (i = 0; i + 1 < el->n_pins; i += 2) {
+
+ if (el->pins[i] == cid && el->pins[i + 1] == pid) {
+
+ for (j = i + 2; j < el->n_pins; j++)
+ el->pins[j - 2] = el->pins[j];
+
+ el->n_pins -= 2;
+
+ p = realloc(el->pins, sizeof(uint64_t) * el->n_pins);
+ if (p)
+ el->pins = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+int scf_eline__add_conn(ScfEline* el, ScfEconn* ec)
+{
+ if (!el || !ec)
+ return -EINVAL;
+
+ for (size_t i = 0; i < el->n_conns; i++) {
+
+ if (el->conns[i] == ec)
+ return 0;
+ }
+
+ void* p = realloc(el->conns, sizeof(ScfEconn*) * (el->n_conns + 1));
+ if (!p)
+ return -ENOMEM;
+
+ el->conns = p;
+ el->conns[el->n_conns++] = ec;
+ return 0;
+}
+
+int scf_eline__del_conn(ScfEline* el, ScfEconn* ec)
+{
+ if (!el || !ec)
+ return -EINVAL;
+
+ void* p;
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < el->n_conns; i++) {
+
+ if (el->conns[i] == ec) {
+
+ for (j = i + 1; j < el->n_conns; j++)
+ el->conns[j - 1] = el->conns[j];
+
+ el->n_conns--;
+
+ p = realloc(el->conns, sizeof(ScfEconn*) * el->n_conns);
+ if (p)
+ el->conns = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+ScfEpin* scf_epin__alloc()
+{
+ ScfEpin* pin = calloc(1, sizeof(ScfEpin));
+
+ return pin;
+}
+
+int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+{
+ if (!pin)
+ return -EINVAL;
+
+ for (size_t i = 0; i + 1 < pin->n_tos; i += 2) {
+
+ if (pin->tos[i] == cid && pin->tos[i + 1] == pid)
+ return 0;
+ }
+
+ uint64_t* p = realloc(pin->tos, sizeof(uint64_t) * (pin->n_tos + 2));
+ if (!p)
+ return -ENOMEM;
+
+ pin->tos = p;
+ pin->tos[pin->n_tos++] = cid;
+ pin->tos[pin->n_tos++] = pid;
+ return 0;
+}
+
+int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
+{
+ if (!pin)
+ return -EINVAL;
+
+ uint64_t* p;
+ size_t i;
+ size_t j;
+
+ for (i = 0; i + 1 < pin->n_tos; i += 2) {
+
+ if (pin->tos[i] == cid && pin->tos[i + 1] == pid) {
+
+ for (j = i + 2; j < pin->n_tos; j++)
+ pin->tos[j - 2] = pin->tos[j];
+
+ pin->n_tos -= 2;
+
+ p = realloc(pin->tos, sizeof(uint64_t) * pin->n_tos);
+ if (p)
+ pin->tos = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
+{
+ ScfEcomponent* c;
+ scf_edata_t* ed;
+
+ if (type >= SCF_EDA_Components_NB)
+ return NULL;
+
+ c = calloc(1, sizeof(ScfEcomponent));
+ if (!c)
+ return NULL;
+
+ c->type = type;
+
+ ed = _component_find_data(c->type, c->model);
+ if (ed) {
+ c->v = ed->v;
+ c->a = ed->a;
+ c->r = ed->r;
+ c->jr = ed->jr;
+ c->uf = ed->uf;
+ c->uh = ed->uh;
+ }
+
+ int i;
+ for (i = 0; i < component_pins[type]; i++) {
+
+ ScfEpin* pin = scf_epin__alloc();
+ if (!pin) {
+ ScfEcomponent_free(c);
+ return NULL;
+ }
+
+ pin->id = i;
+
+ if (scf_ecomponent__add_pin(c, pin) < 0) {
+ ScfEcomponent_free(c);
+ ScfEpin_free(pin);
+ return NULL;
+ }
+
+ ed = _pin_find_data(c->type, c->model, pin->id);
+ if (ed) {
+ pin->v = ed->v;
+ pin->a = ed->a;
+ pin->r = ed->r;
+ pin->jr = ed->jr;
+ pin->uf = ed->uf;
+ pin->uh = ed->uh;
+ pin->hfe = ed->hfe;
+ }
+ }
+
+ return c;
+}
+
+int scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin)
+{
+ if (!c || !pin)
+ return -EINVAL;
+
+ void* p = realloc(c->pins, sizeof(ScfEpin*) * (c->n_pins + 1));
+ if (!p)
+ return -ENOMEM;
+
+ c->pins = p;
+ c->pins[c->n_pins++] = pin;
+ return 0;
+}
+
+int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin)
+{
+ if (!c)
+ return -EINVAL;
+
+ size_t i;
+ size_t j;
+ void* p;
+
+ for (i = 0; i < c->n_pins; i++) {
+
+ if (c->pins[i] == pin) {
+
+ for (j = i + 1; j < c->n_pins; j++)
+ c->pins[j - 1] = c->pins[j];
+
+ c->n_pins--;
+
+ p = realloc(c->pins, sizeof(ScfEpin*) * c->n_pins);
+ if (p)
+ c->pins = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+ScfEfunction* scf_efunction__alloc(const char* name)
+{
+ ScfEfunction* f = calloc(1, sizeof(ScfEfunction));
+ if (!f)
+ return NULL;
+
+ f->n_name = strlen(name) + 1;
+
+ f->name = strdup(name);
+ if (!f->name) {
+ free(f);
+ return NULL;
+ }
+
+ return f;
+}
+
+int scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c)
+{
+ if (!f || !c)
+ return -EINVAL;
+
+ void* p = realloc(f->components, sizeof(ScfEcomponent*) * (f->n_components + 1));
+ if (!p)
+ return -ENOMEM;
+
+ f->components = p;
+ f->components[f->n_components++] = c;
+ return 0;
+}
+
+int scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c)
+{
+ if (!f || !c)
+ return -EINVAL;
+
+ size_t i;
+ size_t j;
+ void* p;
+
+ for (i = 0; i < f->n_components; i++) {
+
+ if (f->components[i] == c) {
+
+ for (j = i + 1; j < f->n_components; j++)
+ f->components[j - 1] = f->components[j];
+
+ f->n_components--;
+
+ p = realloc(f->components, sizeof(ScfEcomponent*) * f->n_components);
+ if (p)
+ f->components = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+int scf_efunction__add_eline(ScfEfunction* f, ScfEline* el)
+{
+ if (!f || !el)
+ return -EINVAL;
+
+ void* p = realloc(f->elines, sizeof(ScfEline*) * (f->n_elines + 1));
+ if (!p)
+ return -ENOMEM;
+
+ f->elines = p;
+ f->elines[f->n_elines++] = el;
+ return 0;
+}
+
+int scf_efunction__del_eline(ScfEfunction* f, ScfEline* el)
+{
+ if (!f || !el)
+ return -EINVAL;
+
+ size_t i;
+ size_t j;
+ void* p;
+
+ for (i = 0; i < f->n_elines; i++) {
+
+ if (f->elines[i] == el) {
+
+ for (j = i + 1; j < f->n_elines; j++)
+ f->elines[j - 1] = f->elines[j];
+
+ f->n_elines--;
+
+ p = realloc(f->elines, sizeof(ScfEline*) * f->n_elines);
+ if (p)
+ f->elines = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+ScfEboard* scf_eboard__alloc()
+{
+ ScfEboard* b = calloc(1, sizeof(ScfEboard));
+
+ return b;
+}
+
+int scf_eboard__add_function(ScfEboard* b, ScfEfunction* f)
+{
+ if (!b || !f)
+ return -EINVAL;
+
+ void* p = realloc(b->functions, sizeof(ScfEfunction*) * (b->n_functions + 1));
+ if (!p)
+ return -ENOMEM;
+
+ b->functions = p;
+ b->functions[b->n_functions++] = f;
+ return 0;
+}
+
+int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f)
+{
+ if (!b)
+ return -EINVAL;
+
+ size_t i;
+ size_t j;
+ void* p;
+
+ for (i = 0; i < b->n_functions; i++) {
+
+ if (b->functions[i] == f) {
+
+ for (j = i + 1; j < b->n_functions; j++)
+ b->functions[j - 1] = b->functions[j];
+
+ b->n_functions--;
+
+ p = realloc(b->functions, sizeof(ScfEfunction*) * b->n_functions);
+ if (p)
+ b->functions = p;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
--- /dev/null
+#ifndef SCF_EDA_PACK_H
+#define SCF_EDA_PACK_H
+
+#include "scf_pack.h"
+
+enum {
+ SCF_EDA_None,
+ SCF_EDA_Battery,
+
+ SCF_EDA_Resistor,
+ SCF_EDA_Capacitor,
+ SCF_EDA_Inductor,
+
+ SCF_EDA_Diode,
+ SCF_EDA_NPN,
+ SCF_EDA_PNP,
+
+ SCF_EDA_Components_NB,
+};
+
+#define SCF_EDA_PIN_NONE 0
+#define SCF_EDA_PIN_IN 1
+#define SCF_EDA_PIN_OUT 2
+#define SCF_EDA_PIN_POS 4
+#define SCF_EDA_PIN_NEG 8
+#define SCF_EDA_PIN_CF 16
+#define SCF_EDA_PIN_BORDER 32
+
+#define SCF_EDA_V_INIT -10001001.0
+#define SCF_EDA_V_MIN -10000000.0
+#define SCF_EDA_V_MAX 10000000.0
+
+#define SCF_EDA_V_Diode_ON 0.58
+#define SCF_EDA_V_Diode_OFF 0.55
+
+#define SCF_EDA_V_NPN_ON 0.70
+#define SCF_EDA_V_NPN_OFF 0.61
+
+enum {
+ SCF_EDA_Battery_NEG,
+ SCF_EDA_Battery_POS,
+ SCF_EDA_Battery_NB,
+};
+
+enum {
+ SCF_EDA_Diode_NEG,
+ SCF_EDA_Diode_POS,
+ SCF_EDA_Diode_NB,
+};
+
+enum {
+ SCF_EDA_Status_ON,
+ SCF_EDA_Status_OFF,
+ SCF_EDA_Path_OFF,
+ SCF_EDA_Path_TO,
+};
+
+enum {
+ SCF_EDA_NPN_B,
+ SCF_EDA_NPN_E,
+ SCF_EDA_NPN_C,
+ SCF_EDA_NPN_NB,
+};
+
+enum {
+ SCF_EDA_PNP_B,
+ SCF_EDA_PNP_E,
+ SCF_EDA_PNP_C,
+ SCF_EDA_PNP_NB,
+};
+
+typedef struct {
+ uint64_t type;
+ uint64_t model;
+ uint64_t pid;
+
+ double v;
+ double a;
+ double r;
+ double jr;
+ double uf;
+ double uh;
+ double hfe;
+} scf_edata_t;
+
+typedef struct {
+ SCF_PACK_DEF_VAR(int, x0);
+ SCF_PACK_DEF_VAR(int, y0);
+ SCF_PACK_DEF_VAR(int, x1);
+ SCF_PACK_DEF_VAR(int, y1);
+} ScfLine;
+
+SCF_PACK_TYPE(ScfLine)
+SCF_PACK_INFO_VAR(ScfLine, x0),
+SCF_PACK_INFO_VAR(ScfLine, y0),
+SCF_PACK_INFO_VAR(ScfLine, x1),
+SCF_PACK_INFO_VAR(ScfLine, y1),
+SCF_PACK_END(ScfLine)
+
+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_epin_s
+{
+ SCF_PACK_DEF_VAR(uint64_t, id);
+ SCF_PACK_DEF_VAR(uint64_t, cid);
+ SCF_PACK_DEF_VAR(uint64_t, lid);
+ SCF_PACK_DEF_VAR(uint64_t, flags);
+ SCF_PACK_DEF_VARS(uint64_t, tos);
+ SCF_PACK_DEF_VAR(uint64_t, c_lid);
+
+ SCF_PACK_DEF_VAR(double, v);
+ SCF_PACK_DEF_VAR(double, jv);
+ SCF_PACK_DEF_VAR(double, a);
+ SCF_PACK_DEF_VAR(double, ja);
+
+ SCF_PACK_DEF_VAR(double, r);
+ SCF_PACK_DEF_VAR(double, jr);
+ SCF_PACK_DEF_VAR(double, uf);
+ SCF_PACK_DEF_VAR(double, uh);
+ SCF_PACK_DEF_VAR(double, hfe);
+
+ SCF_PACK_DEF_VAR(double, dr);
+ SCF_PACK_DEF_VAR(double, jdr);
+
+ SCF_PACK_DEF_VAR(double, sr);
+ SCF_PACK_DEF_VAR(double, jsr);
+
+ SCF_PACK_DEF_VAR(double, pr);
+ SCF_PACK_DEF_VAR(double, jpr);
+
+ SCF_PACK_DEF_VAR(uint64_t, path);
+
+ SCF_PACK_DEF_VAR(int, x);
+ SCF_PACK_DEF_VAR(int, y);
+
+ SCF_PACK_DEF_VAR(int, n_diodes);
+ SCF_PACK_DEF_VAR(int, l_pos);
+
+ SCF_PACK_DEF_VAR(uint8_t, vflag);
+ SCF_PACK_DEF_VAR(uint8_t, pflag);
+ SCF_PACK_DEF_VAR(uint8_t, vconst);
+ SCF_PACK_DEF_VAR(uint8_t, aconst);
+};
+
+SCF_PACK_TYPE(ScfEpin)
+SCF_PACK_INFO_VAR(ScfEpin, id),
+SCF_PACK_INFO_VAR(ScfEpin, cid),
+SCF_PACK_INFO_VAR(ScfEpin, lid),
+SCF_PACK_INFO_VAR(ScfEpin, flags),
+SCF_PACK_INFO_VARS(ScfEpin, tos, uint64_t),
+SCF_PACK_INFO_VAR(ScfEpin, c_lid),
+
+SCF_PACK_INFO_VAR(ScfEpin, v),
+SCF_PACK_INFO_VAR(ScfEpin, jv),
+SCF_PACK_INFO_VAR(ScfEpin, a),
+SCF_PACK_INFO_VAR(ScfEpin, ja),
+
+SCF_PACK_INFO_VAR(ScfEpin, r),
+SCF_PACK_INFO_VAR(ScfEpin, jr),
+SCF_PACK_INFO_VAR(ScfEpin, uf),
+SCF_PACK_INFO_VAR(ScfEpin, uh),
+SCF_PACK_INFO_VAR(ScfEpin, hfe),
+
+SCF_PACK_INFO_VAR(ScfEpin, dr),
+SCF_PACK_INFO_VAR(ScfEpin, jdr),
+
+SCF_PACK_INFO_VAR(ScfEpin, sr),
+SCF_PACK_INFO_VAR(ScfEpin, jsr),
+
+SCF_PACK_INFO_VAR(ScfEpin, pr),
+SCF_PACK_INFO_VAR(ScfEpin, jpr),
+
+SCF_PACK_INFO_VAR(ScfEpin, path),
+SCF_PACK_INFO_VAR(ScfEpin, x),
+SCF_PACK_INFO_VAR(ScfEpin, y),
+SCF_PACK_INFO_VAR(ScfEpin, n_diodes),
+SCF_PACK_INFO_VAR(ScfEpin, l_pos),
+
+SCF_PACK_INFO_VAR(ScfEpin, vflag),
+SCF_PACK_INFO_VAR(ScfEpin, pflag),
+SCF_PACK_INFO_VAR(ScfEpin, vconst),
+SCF_PACK_INFO_VAR(ScfEpin, aconst),
+SCF_PACK_END(ScfEpin)
+
+typedef struct {
+ SCF_PACK_DEF_VAR(uint64_t, lid);
+ SCF_PACK_DEF_VARS(uint64_t, cids);
+} ScfEconn;
+
+SCF_PACK_TYPE(ScfEconn)
+SCF_PACK_INFO_VAR(ScfEconn, lid),
+SCF_PACK_INFO_VARS(ScfEconn, cids, uint64_t),
+SCF_PACK_END(ScfEconn)
+
+typedef struct {
+ SCF_PACK_DEF_VAR(uint64_t, id);
+ SCF_PACK_DEF_VARS(uint64_t, pins);
+ SCF_PACK_DEF_VAR(uint64_t, c_pins);
+ SCF_PACK_DEF_VAR(uint64_t, flags);
+ SCF_PACK_DEF_VAR(int64_t, color);
+
+ SCF_PACK_DEF_OBJS(ScfEconn, conns);
+ SCF_PACK_DEF_OBJS(ScfLine, lines);
+
+ SCF_PACK_DEF_VAR(double, v);
+ SCF_PACK_DEF_VAR(double, jv);
+ SCF_PACK_DEF_VAR(double, a);
+ SCF_PACK_DEF_VAR(double, ja);
+ SCF_PACK_DEF_VAR(uint8_t, vconst);
+ SCF_PACK_DEF_VAR(uint8_t, aconst);
+ SCF_PACK_DEF_VAR(uint8_t, vflag);
+} ScfEline;
+
+SCF_PACK_TYPE(ScfEline)
+SCF_PACK_INFO_VAR(ScfEline, id),
+SCF_PACK_INFO_VARS(ScfEline, pins, uint64_t),
+SCF_PACK_INFO_VAR(ScfEline, c_pins),
+SCF_PACK_INFO_VAR(ScfEline, flags),
+SCF_PACK_INFO_VAR(ScfEline, color),
+
+SCF_PACK_INFO_OBJS(ScfEline, conns, ScfEconn),
+SCF_PACK_INFO_OBJS(ScfEline, lines, ScfLine),
+
+SCF_PACK_INFO_VAR(ScfEline, v),
+SCF_PACK_INFO_VAR(ScfEline, jv),
+SCF_PACK_INFO_VAR(ScfEline, a),
+SCF_PACK_INFO_VAR(ScfEline, ja),
+SCF_PACK_INFO_VAR(ScfEline, vconst),
+SCF_PACK_INFO_VAR(ScfEline, aconst),
+SCF_PACK_INFO_VAR(ScfEline, vflag),
+SCF_PACK_END(ScfEline)
+
+struct scf_ecomponent_s
+{
+ SCF_PACK_DEF_VAR(uint64_t, id);
+ SCF_PACK_DEF_VAR(uint64_t, type);
+ SCF_PACK_DEF_VAR(uint64_t, model);
+ SCF_PACK_DEF_OBJS(ScfEpin, pins);
+
+ SCF_PACK_DEF_VAR(double, v);
+ SCF_PACK_DEF_VAR(double, jv);
+ SCF_PACK_DEF_VAR(double, a);
+ SCF_PACK_DEF_VAR(double, ja);
+
+ SCF_PACK_DEF_VAR(double, r);
+ SCF_PACK_DEF_VAR(double, jr);
+ SCF_PACK_DEF_VAR(double, uf);
+ SCF_PACK_DEF_VAR(double, uh);
+
+ SCF_PACK_DEF_VAR(int64_t, color);
+ SCF_PACK_DEF_VAR(int, status);
+ SCF_PACK_DEF_VAR(int, x);
+ SCF_PACK_DEF_VAR(int, y);
+ SCF_PACK_DEF_VAR(int, w);
+ SCF_PACK_DEF_VAR(int, h);
+ SCF_PACK_DEF_VAR(uint8_t, vflag);
+ SCF_PACK_DEF_VAR(uint8_t, lock);
+};
+
+SCF_PACK_TYPE(ScfEcomponent)
+SCF_PACK_INFO_VAR(ScfEcomponent, id),
+SCF_PACK_INFO_VAR(ScfEcomponent, type),
+SCF_PACK_INFO_VAR(ScfEcomponent, model),
+SCF_PACK_INFO_OBJS(ScfEcomponent, pins, ScfEpin),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, v),
+SCF_PACK_INFO_VAR(ScfEcomponent, jv),
+SCF_PACK_INFO_VAR(ScfEcomponent, a),
+SCF_PACK_INFO_VAR(ScfEcomponent, ja),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, r),
+SCF_PACK_INFO_VAR(ScfEcomponent, jr),
+SCF_PACK_INFO_VAR(ScfEcomponent, uf),
+SCF_PACK_INFO_VAR(ScfEcomponent, uh),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, color),
+SCF_PACK_INFO_VAR(ScfEcomponent, status),
+SCF_PACK_INFO_VAR(ScfEcomponent, x),
+SCF_PACK_INFO_VAR(ScfEcomponent, y),
+SCF_PACK_INFO_VAR(ScfEcomponent, w),
+SCF_PACK_INFO_VAR(ScfEcomponent, h),
+SCF_PACK_INFO_VAR(ScfEcomponent, vflag),
+SCF_PACK_INFO_VAR(ScfEcomponent, lock),
+SCF_PACK_END(ScfEcomponent)
+
+struct scf_efunction_s
+{
+ SCF_PACK_DEF_VARS(uint8_t, name);
+ SCF_PACK_DEF_OBJS(ScfEcomponent, components);
+ SCF_PACK_DEF_OBJS(ScfEline, elines);
+ SCF_PACK_DEF_VAR(int, x);
+ SCF_PACK_DEF_VAR(int, y);
+ SCF_PACK_DEF_VAR(int, w);
+ SCF_PACK_DEF_VAR(int, h);
+};
+
+SCF_PACK_TYPE(ScfEfunction)
+SCF_PACK_INFO_VARS(ScfEfunction, name, uint8_t),
+SCF_PACK_INFO_OBJS(ScfEfunction, components, ScfEcomponent),
+SCF_PACK_INFO_OBJS(ScfEfunction, elines, ScfEline),
+SCF_PACK_INFO_VAR(ScfEfunction, x),
+SCF_PACK_INFO_VAR(ScfEfunction, y),
+SCF_PACK_INFO_VAR(ScfEfunction, w),
+SCF_PACK_INFO_VAR(ScfEfunction, h),
+SCF_PACK_END(ScfEfunction)
+
+struct scf_eboard_s
+{
+ SCF_PACK_DEF_OBJS(ScfEfunction, functions);
+};
+
+SCF_PACK_TYPE(ScfEboard)
+SCF_PACK_INFO_OBJS(ScfEboard, functions, ScfEfunction),
+SCF_PACK_END(ScfEboard)
+
+
+ScfEconn* scf_econn__alloc();
+int scf_econn__add_cid(ScfEconn* ec, uint64_t cid);
+int scf_econn__del_cid(ScfEconn* ec, uint64_t cid);
+
+ScfEline* scf_eline__alloc();
+int scf_eline__add_line(ScfEline* el, ScfLine* l);
+int scf_eline__del_line(ScfEline* el, ScfLine* l);
+
+int scf_eline__add_pin (ScfEline* el, uint64_t cid, uint64_t pid);
+int scf_eline__del_pin (ScfEline* el, uint64_t cid, uint64_t pid);
+
+int scf_eline__add_conn(ScfEline* el, ScfEconn* ec);
+int scf_eline__del_conn(ScfEline* el, ScfEconn* ec);
+
+ScfEpin* scf_epin__alloc();
+int scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
+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);
+
+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);
+
+ScfEboard* scf_eboard__alloc();
+int scf_eboard__add_function(ScfEboard* b, ScfEfunction* f);
+int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f);
+
+#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) { \
+ ScfEcomponent_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)
+
+#define EDA_PIN_ADD_PIN_EF(_ef, _p0, _p1) \
+ EDA_PIN_ADD_PIN((_ef)->components[(_p0)->cid], (_p0)->id, (_ef)->components[(_p1)->cid], (_p1)->id)
+
+#endif
uint8_t* buf = NULL;
int len = 0;
- scf_B_pack(&b, &buf, &len);
+ B_pack(&b, &buf, &len);
int i;
int j;
for (i = 0; i < len; i++)
printf("i: %d, %#x\n", i, buf[i]);
#if 1
- scf_B_unpack(&p, buf, len);
+ B_unpack(&p, buf, len);
printf("p: %p, p->as: %p\n", p, p->as);
printf("p->d: %lg, p->n_as: %ld, p->as: %p\n", p->d, p->n_as, p->as);
printf("\n");
}
- scf_B_free(p);
+ B_free(p);
free(buf);
#endif
return 0;
max = i;
else
max -= i;
- scf_loge("max: %d, i: %d, j: %d, k: %d, shift: %d\n", max, i, j, k, shift);
+ scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n", max, i, j, k, shift);
pack[j] |= max << k;
return -EINVAL;
}
- scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+ scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
max = i;
}
if (8 - k < shift && 0 != max) {
pack[++j] = 0;
- scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+ scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
}
return j + 1;
for (i = 0; i < bytes; i++) {
if (p[i]) {
pack[++j] = p[i];
- scf_logi("bytes: %d, map: %#x, i: %d, j: %d, p[i]: %#x\n", bytes, map, i, j, p[i]);
+ scf_logd("bytes: %d, map: %#x, i: %d, j: %d, p[i]: %#x\n", bytes, map, i, j, p[i]);
}
}
u = ~u;
}
- scf_logw("bits: %d, not: %d, u: %#lx, sum: %d\n", bits, not, u, sum);
+ scf_logd("bits: %d, not: %d, u: %#lx, sum: %d\n", bits, not, u, sum);
pack[0] = not;
else
max -= i;
- u |= 1u << max;
+ u |= 1ull << max;
- if (i < 2)
+ if (max < 2)
shift = 1;
- else if (i < 4)
+ else if (max < 4)
shift = 2;
- else if (i < 8)
+ else if (max < 8)
shift = 3;
- else if (i < 16)
+ else if (max < 16)
shift = 4;
- else if (i < 32)
+ else if (max < 32)
shift = 5;
- else if (i < 64)
+ else if (max < 64)
shift = 6;
else {
scf_loge("unpack error\n");
return -EINVAL;
}
- scf_logi("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
-
- max = i;
+ scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
}
j++;
- scf_logi("u: %ld, %#lx\n", u, u);
+ scf_logd("u: %ld, %#lx\n", u, u);
} else if (!(buf[0] & 0x8)) {
j = 1;
u |= u8 << (k << 3);
- scf_loge("buf[%d]: %#x, u: %#lx\n", j, buf[j], u);
+ scf_logd("buf[%d]: %#x, u: %#lx, k: %d, bits: %d\n", j, buf[j], u, k, bits);
j++;
}
if (1 >= len)
return -EINVAL;
- map |= buf[1] & 0xf;
+ map |= buf[1] << 4;
j = 2;
} else
j = 1;
uint64_t u8 = buf[j++];
u |= u8 << (k << 3);
+
+ scf_logd("buf[%d]: %#x, u: %#lx, k: %d, map: %#x, bits: %d\n", j, buf[j], u, k, map, bits);
}
}
break;
};
+ scf_logd("u: %#lx, j: %d, bits: %d\n", u, j, bits);
return j;
}
*(uint32_t*)pack = *(uint32_t*)p;
len = 4;
#endif
- scf_logi("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len);
+ scf_logd("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len);
break;
case 8:
#if 1
*(uint64_t*)pack = *(uint64_t*)p;
len = 8;
#endif
- scf_logi("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: %d\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len);
break;
default:
scf_loge("data size '%d' NOT support!\n", size);
if (!*pbuf)
*plen = 0;
- printf("\n");
- scf_logw("p: %p\n", p);
+// printf("\n");
+ scf_logd("p: %p\n", p);
int i;
for (i = 0; i < n_infos; i++) {
- printf("name: %s, size: %ld, offset: %ld, noffset: %ld, msize: %ld, members: %p, n_members: %ld\n",
+ 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);
if (infos[i].noffset >= 0) {
long n = *(long* )(p + infos[i].noffset);
int j;
- scf_loge("a: %p, n: %ld, infos[i].msize: %ld, infos[i].noffset: %ld\n", a, n, infos[i].msize, infos[i].noffset);
+ 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++) {
return ret;
}
- scf_loge("size: %ld\n\n", infos[i].size);
+ scf_logd("size: %ld\n\n", infos[i].size);
}
return 0;
return -ENOMEM;
*(void**)(p + infos[i].offset) = a;
- scf_loge("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+ scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
for (j = 0; j < n; j++) {
long n = *(long* )(p + infos[i].noffset);
void* a = *(void**)(p + infos[i].offset);
- scf_loge("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+ scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
if (infos[i].members) {
}
}
- scf_logi("a: %p\n", a);
+ scf_logd("a: %p\n", a);
free(a);
continue;
}
}
}
- scf_logi("p: %p\n", p);
+ scf_logd("p: %p\n", p);
free(p);
return 0;
}
#define SCF_PACK_END(type) \
}; \
-static int scf_##type##_pack(type* p, uint8_t** pbuf, int* plen) \
+static int type##_pack(type* p, uint8_t** pbuf, int* plen) \
{ \
return scf_pack(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type), pbuf, plen); \
} \
-static int scf_##type##_unpack(type** pp, uint8_t* buf, int len) \
+static int type##_unpack(type** pp, uint8_t* buf, int len) \
{ \
return scf_unpack((void**)pp, scf_pack_info_##type, SCF_PACK_N_INFOS(type), buf, len); \
} \
-static int scf_##type##_free(type* p) \
+static int type##_free(type* p) \
{ \
return scf_unpack_free(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type)); \
}
CFILES += ../native/eda/scf_eda.c
CFILES += ../native/eda/scf_eda_inst.c
-CFILES += ../native/eda/scf_eda_pb.c
-CFILES += ../native/eda/scf_eda.pb-c.c
+CFILES += ../native/eda/scf_eda_pack.c
+CFILES += ../pack/scf_pack.c
CFILES += ../elf/scf_elf.c
CFILES += ../elf/scf_elf_link.c
CFLAGS += -I../core
CFLAGS += -I../lex
CFLAGS += -I../parse
+CFLAGS += -I../pack
CFLAGS += -I../elf
CFLAGS += -I../vm
CFLAGS += -I../native
CFLAGS += -I../native/eda
LDFLAGS += -ldl
-LDFLAGS += -lprotobuf-c
+#LDFLAGS += -lprotobuf-c
all:
gcc $(CFLAGS) $(CFILES) $(LDFLAGS) -o scf
f->ef = NULL;
if (ret < 0) {
- scf_eboard__free(b);
+ ScfEboard_free(b);
return ret;
}
}
- size_t len = scf_eboard__get_packed_size(b);
+ uint8_t* buf = NULL;
+ int len = 0;
- scf_loge("len: %ld\n", len);
-
- uint8_t* buf = malloc(len);
- if (!buf) {
- scf_eboard__free(b);
- return -ENOMEM;
+ int ret = ScfEboard_pack(b, &buf, &len);
+ if (ret < 0) {
+ ScfEboard_free(b);
+ free(buf);
+ return ret;
}
- scf_eboard__pack(b, buf);
- scf_eboard__free(b);
+ scf_loge("len: %d\n", len);
+
+ ScfEboard_free(b);
b = NULL;
FILE* fp = fopen(out, "wb");
fwrite(buf, len, 1, fp);
fclose(fp);
+ free(buf);
return 0;
}
#include<errno.h>
#include<time.h>
#include<unistd.h>
+#include<limits.h>
+#include<math.h>
#if 1
#include<sys/time.h>