SCF_VAR_VOID,
SCF_VAR_BIT,
SCF_VAR_BIT2,
+ SCF_VAR_BIT3,
SCF_VAR_BIT4,
SCF_VAR_U16,
SCF_VAR_U32,
return 1;
if (SCF_VAR_BIT2 == v->type)
return 2;
+ if (SCF_VAR_BIT3 == v->type)
+ return 3;
if (SCF_VAR_BIT4 == v->type)
return 4;
k--;
}
- n_adds = k;
+ if (j == k)
+ n_adds = j + 1;
+ else
+ n_adds = j;
+ scf_logd("i: %d, n_adds: %d, j: %d, k: %d\n\n", i, n_adds, j, k);
}
out->pins[i] = adds[0];
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);
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_VAR_VOID, "void", 1},
{SCF_VAR_BIT, "bit", 1},
{SCF_VAR_BIT2, "bit2_t", 1},
+ {SCF_VAR_BIT3, "bit3_t", 1},
{SCF_VAR_BIT4, "bit4_t", 1},
{SCF_VAR_INT, "int", 4},
return 0;
}
-int scf_eda_write_pb(scf_parse_t* parse, const char* out, scf_vector_t* functions, scf_vector_t* global_vars)
+int scf_eda_write_cpk(scf_parse_t* parse, const char* out, scf_vector_t* functions, scf_vector_t* global_vars)
{
scf_function_t* f;
ScfEboard* b;
}
uint8_t* buf = NULL;
- int len = 0;
+ long len = 0;
- int ret = ScfEboard_pack(b, &buf, &len);
+ long ret = ScfEboard_pack(b, &buf, &len);
if (ret < 0) {
ScfEboard_free(b);
free(buf);
return ret;
}
- scf_loge("len: %d\n", len);
+ scf_loge("len: %ld\n", len);
ScfEboard_free(b);
b = NULL;
}
if (!strcmp(arch, "eda"))
- return scf_eda_write_pb(parse, out, functions, NULL);
+ return scf_eda_write_cpk(parse, out, functions, NULL);
global_vars = scf_vector_alloc();
if (!global_vars) {