diff --git a/examples/counter/src/counter.c b/examples/counter/src/counter.c index d4c9e91eaf89b72ab5d3b8fa5f16dc4edab0cb35..726955d3809a2b72d436c2ce971c444a93cc9840 100644 --- a/examples/counter/src/counter.c +++ b/examples/counter/src/counter.c @@ -42,7 +42,6 @@ #include "hdl4secell.h" static IHDL4SEUnit** hdl4seCreateDec2seg(IHDL4SEModule** parent, char* instanceparam, char* name) { /* module dec2seg */ - IHDL4SEUnit** wire_const[11]; IHDL4SEUnit** unit_const[11]; IHDL4SEUnit** unit_mux16 = NULL; IHDL4SEModule** module_dec2seg = NULL; @@ -73,21 +72,18 @@ static IHDL4SEUnit** hdl4seCreateDec2seg(IHDL4SEModule** parent, char* instancep for (i = 0; i < 11; i++) { char tempname[32]; - sprintf(tempname, "wire_cst%d", i); - wire_const[i] = hdl4seCreateUnit(module_dec2seg, CLSID_HDL4SE_WIRE, "8", tempname); sprintf(tempname, "const_cst%d", i); unit_const[i] = hdl4seCreateUnit(module_dec2seg, CLSID_HDL4SE_CONST, constparam[i], tempname); - objectCall3(wire_const[i], Connect, 0, unit_const[i], 0); } /* 生成数据选择器unit_mux */ unit_mux16 = hdl4seCreateUnit(module_dec2seg, CLSID_HDL4SE_MUX16, "8", "mux_dec"); /*mux的输入连接到输入端口dec和线网constall上*/ objectCall3(unit_mux16, Connect, 0, unit_dec2seg, 0); for (i = 0; i < 10; i++) { - objectCall3(unit_mux16, Connect, i+1, wire_const[i], 0); + objectCall3(unit_mux16, Connect, i+1, unit_const[i], 0); } for (; i < 16; i++) { - objectCall3(unit_mux16, Connect, i+1, wire_const[10], 0); + objectCall3(unit_mux16, Connect, i+1, unit_const[10], 0); } /* 译码模块的输出seg连接到数据先择器的输出*/ objectCall3(unit_dec2seg, Connect, 1, unit_mux16, 17); diff --git a/examples/counter/src/main.c b/examples/counter/src/main.c index 13d46a7f05b2595ced54ea8a1d287be46897147e..f063eb5e913924937d685ecd8dd614918bb6875f 100644 --- a/examples/counter/src/main.c +++ b/examples/counter/src/main.c @@ -55,14 +55,34 @@ int StopRunning() return 0; } +static int hdl4se_print_all_signal(IHDL4SEDetector** detector, const char * pathname, int *pwidth) +{ + int i; + int count; + int width; + const char* name; + count = objectCall0(detector, GetSignalCount); + for (i = 0; i < count; i++) { + objectCall3(detector, GetSignalInfo, i, &name, &width); + printf("%s/%s, %d\n", pathname, name, width); + *pwidth += (width + 31) / 32; + } + return 0; +} + + int main(int argc, char* argv[]) { + int width; sim = hdl4sesimCreateSimulator(); topmodule = hdl4seCreateMain(NULL, "", "main"); gui = guiCreate(0xf0000000, "digitled"); objectCall1(sim, SetTopModule, topmodule); objectCall1(sim, AddDevice, gui); objectCall1(sim, SetReset, 0); + width = 0; + hdl4sedetectorTraversal(sim, hdl4se_print_all_signal, "", &width); + printf("Total width=%d bits, %d word\n", width * 32, width); do { objectCall0(sim, RunClockTick); clocks++; diff --git a/examples/digitled/src/digitled.c b/examples/digitled/src/digitled.c index e8cc951d5380b1a1e31956c419aa42cfd87b5637..13397467126f20564b0cff47095e52c3f0383f6e 100644 --- a/examples/digitled/src/digitled.c +++ b/examples/digitled/src/digitled.c @@ -544,13 +544,19 @@ static const char* digitled_dataname[9] = { "bReadData", "BASEADDR" }; -static int digitled_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) + +static const char* digitled_datawidth[9] ={ + 1, 1, 32, 32, 4, 1, 32, 32, 32 +}; + +static int digitled_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sDigitLed* pobj; pobj = (sDigitLed*)objectThis(object); if (index < 0 || index >= 9) return -1; *pname = digitled_dataname[index]; + *width = digitled_datawidth[index]; return 0; } @@ -565,10 +571,7 @@ static int digitled_hdl4se_detector_GetSignalValue(HOBJECT object, int index, IB objectCall1(value, AssignInt, pobj->portdata[index]); if (index == 8) objectCall1(value, AssignInt, pobj->baseaddr); - if (index == 0 || index == 1 || index == 5) - objectCall2(value, SetWidth, 1, 0); - if (index == 4) - objectCall2(value, SetWidth, 4, 0); + objectCall2(value, SetWidth, digitled_datawidth[index], 0); return 0; } diff --git a/hdl4secell/include/hdl4secell.h b/hdl4secell/include/hdl4secell.h index 49a06b9a4735cc72184669dc6d5fc7b9731c0532..f9ba039430aa9cdc85fc23eb2b1d263bfa33f5c3 100644 --- a/hdl4secell/include/hdl4secell.h +++ b/hdl4secell/include/hdl4secell.h @@ -79,7 +79,7 @@ typedef struct sIHDL4SEDetector { OBJECT_INTERFACE int (*GetName)(HOBJECT object, const char ** pname); int (*GetSignalCount)(HOBJECT object); - int (*GetSignalName)(HOBJECT object, int index, const char **pname); + int (*GetSignalInfo)(HOBJECT object, int index, const char **pname, int * width); int (*GetSignalValue)(HOBJECT object, int index, IBigNumber** value); int (*GetUnitCount)(HOBJECT object); int (*GetUnit)(HOBJECT object, int index, HOBJECT* unit); @@ -91,7 +91,7 @@ typedef struct sIHDL4SEDetector { #define HDL4SEDETECTOR_FUNCDECLARE(_obj, _clsid, _localstruct) \ static int _obj##_hdl4se_detector_GetName(HOBJECT object, const char ** pname); \ static int _obj##_hdl4se_detector_GetSignalCount(HOBJECT object); \ - static int _obj##_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname); \ + static int _obj##_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width); \ static int _obj##_hdl4se_detector_GetSignalValue(HOBJECT object, int index, IBigNumber** value); \ static int _obj##_hdl4se_detector_GetUnitCount(HOBJECT object); \ static int _obj##_hdl4se_detector_GetUnit(HOBJECT object, int index, HOBJECT* unit); \ @@ -99,12 +99,16 @@ typedef struct sIHDL4SEDetector { INTERFACE_HEADER(_obj, IHDL4SEDetector, _localstruct) \ _obj##_hdl4se_detector_GetName, \ _obj##_hdl4se_detector_GetSignalCount, \ - _obj##_hdl4se_detector_GetSignalName, \ + _obj##_hdl4se_detector_GetSignalInfo, \ _obj##_hdl4se_detector_GetSignalValue, \ _obj##_hdl4se_detector_GetUnitCount, \ _obj##_hdl4se_detector_GetUnit, \ }; +/* return 0 to continue traversal, or stop traversal */ +typedef int (*hdl4se_detector_TraversalFunc)(IHDL4SEDetector ** detector, const char * pathname, void * param); + +int hdl4sedetectorTraversal(HOBJECT object, hdl4se_detector_TraversalFunc func, const char * pathname, void* param); DEFINE_GUID(IID_HDL4SEMODULE, 0x88cf84f9, 0x17ac, 0x4edf, 0xbf, 0x0, 0xc7, 0x32, 0xd5, 0x26, 0x99, 0x2a); diff --git a/hdl4secell/src/hdl4se_bind2.c b/hdl4secell/src/hdl4se_bind2.c index 06ada3bfae9ecffc969aa3051d3fa7d00c9667ef..36d0b88b8b6a02233337b88fed0147553c19bec1 100644 --- a/hdl4secell/src/hdl4se_bind2.c +++ b/hdl4secell/src/hdl4se_bind2.c @@ -67,6 +67,7 @@ typedef struct _sHDL4SEBind2 { IBigNumber** in_data[BINDCOUNT]; IBigNumber** out_data; + int out_width; int datavalid; @@ -144,14 +145,14 @@ static int hdl4se_bind2Create(const PARAMITEM* pParams, int paramcount, HOBJECT* } } } - outputwidth = 0; + pobj->out_width = 0; for (i = 0; i < BINDCOUNT; i++) { if (pobj->inputwidth[i] <= 0) return EIID_INVALIDPARAM; pobj->in_data[i] = bigintegerCreate(pobj->inputwidth[i]); - outputwidth += pobj->inputwidth[i]; + pobj->out_width += pobj->inputwidth[i]; } - pobj->out_data = bigintegerCreate(outputwidth); + pobj->out_data = bigintegerCreate(pobj->out_width); /* 返回生成的对象 */ OBJECT_RETURN_GEN(hdl4se_bind2, pobj, pObject, CLSID_HDL4SE_BIND2); @@ -251,11 +252,12 @@ static int hdl4se_bind2_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_bind2_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_bind2_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEBind2* pobj; pobj = (sHDL4SEBind2*)objectThis(object); *pname = "out"; + *width = pobj->out_width; return 0; } diff --git a/hdl4secell/src/hdl4se_bind3.c b/hdl4secell/src/hdl4se_bind3.c index 7eee3513d10daf41b46c60dd25a7a3bf1a1cd59a..22f0c375ddd33d023a04b498feff4eb5dd3b958f 100644 --- a/hdl4secell/src/hdl4se_bind3.c +++ b/hdl4secell/src/hdl4se_bind3.c @@ -68,6 +68,7 @@ typedef struct _sHDL4SEBind3 { IBigNumber** in_data[BINDCOUNT]; IBigNumber** out_data; + int out_width; int datavalid; @@ -145,14 +146,14 @@ static int hdl4se_bind3Create(const PARAMITEM* pParams, int paramcount, HOBJECT* } } } - outputwidth = 0; + pobj->out_width = 0; for (i = 0; i < BINDCOUNT; i++) { if (pobj->inputwidth[i] <= 0) return EIID_INVALIDPARAM; pobj->in_data[i] = bigintegerCreate(pobj->inputwidth[i]); - outputwidth += pobj->inputwidth[i]; + pobj->out_width += pobj->inputwidth[i]; } - pobj->out_data = bigintegerCreate(outputwidth); + pobj->out_data = bigintegerCreate(pobj->out_width); /* 返回生成的对象 */ OBJECT_RETURN_GEN(hdl4se_bind3, pobj, pObject, CLSID_HDL4SE_BIND3); @@ -252,11 +253,12 @@ static int hdl4se_bind3_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_bind3_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_bind3_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SEBind3* pobj; pobj = (sHDL4SEBind3*)objectThis(object); *pname = "out"; + *width = pobj->out_width; return 0; } diff --git a/hdl4secell/src/hdl4se_bind4.c b/hdl4secell/src/hdl4se_bind4.c index 62573a3923167502112d8ded6067ac4c6138db8e..6ee691e509130320d04b312c1b1de2c35407fe81 100644 --- a/hdl4secell/src/hdl4se_bind4.c +++ b/hdl4secell/src/hdl4se_bind4.c @@ -68,6 +68,7 @@ typedef struct _sHDL4SEBind4 { IBigNumber** in_data[BINDCOUNT]; IBigNumber** out_data; + int out_width; int datavalid; @@ -145,14 +146,14 @@ static int hdl4se_bind4Create(const PARAMITEM* pParams, int paramcount, HOBJECT* } } } - outputwidth = 0; + pobj->out_width = 0; for (i = 0; i < BINDCOUNT; i++) { if (pobj->inputwidth[i] <= 0) return EIID_INVALIDPARAM; pobj->in_data[i] = bigintegerCreate(pobj->inputwidth[i]); - outputwidth += pobj->inputwidth[i]; + pobj->out_width += pobj->inputwidth[i]; } - pobj->out_data = bigintegerCreate(outputwidth); + pobj->out_data = bigintegerCreate(pobj->out_width); /* 返回生成的对象 */ OBJECT_RETURN_GEN(hdl4se_bind4, pobj, pObject, CLSID_HDL4SE_BIND4); @@ -252,11 +253,12 @@ static int hdl4se_bind4_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_bind4_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_bind4_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEBind4* pobj; pobj = (sHDL4SEBind4*)objectThis(object); *pname = "out"; + *width = pobj->out_width; return 0; } diff --git a/hdl4secell/src/hdl4se_binop.c b/hdl4secell/src/hdl4se_binop.c index 805da78189acca1d9641c67c4fb782457d03c2d3..e7e16313996d7020783c0f0d9404a9395ebe41c4 100644 --- a/hdl4secell/src/hdl4se_binop.c +++ b/hdl4secell/src/hdl4se_binop.c @@ -336,11 +336,12 @@ static int hdl4se_binop_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_binop_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_binop_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEBinop* pobj; pobj = (sHDL4SEBinop*)objectThis(object); *pname = "out"; + *width = pobj->out_width; return 0; } diff --git a/hdl4secell/src/hdl4se_const.c b/hdl4secell/src/hdl4se_const.c index 6853e24bf1275e82b56c0650642731ac986cefcb..25675cd4c64e75bb4af7ea76e4952a245ee373ca 100644 --- a/hdl4secell/src/hdl4se_const.c +++ b/hdl4secell/src/hdl4se_const.c @@ -188,11 +188,12 @@ static int hdl4se_const_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_const_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_const_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEConst* pobj; pobj = (sHDL4SEConst*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_module.c b/hdl4secell/src/hdl4se_module.c index 64a48c8c443d7b20bb05541d2ac08a35a61dc7b3..51e9caba5e27377768ee624a106276528d7a6e04 100644 --- a/hdl4secell/src/hdl4se_module.c +++ b/hdl4secell/src/hdl4se_module.c @@ -284,13 +284,14 @@ static int hdl4se_module_hdl4se_detector_GetSignalCount(HOBJECT object) return pobj->ports_count; } -static int hdl4se_module_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_module_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SEModule* pobj; pobj = (sHDL4SEModule*)objectThis(object); if (index < 0 || index >= pobj->ports_count) return -1; *pname = pobj->ports[index].name; + *width = pobj->ports[index].width; return 0; } diff --git a/hdl4secell/src/hdl4se_mux16.c b/hdl4secell/src/hdl4se_mux16.c index ac8ad073a4debdf3189237a9b8acf6d9c218d754..246d0e73d178d2ee7c8fff29824b1248d694cb6a 100644 --- a/hdl4secell/src/hdl4se_mux16.c +++ b/hdl4secell/src/hdl4se_mux16.c @@ -259,11 +259,12 @@ static int hdl4se_mux16_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_mux16_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_mux16_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SEMux16* pobj; pobj = (sHDL4SEMux16*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_mux2.c b/hdl4secell/src/hdl4se_mux2.c index 259ba6c05eda7920aac98050469f8055862778a6..b049acb83ca4d4cb10917940567016c6c7eef807 100644 --- a/hdl4secell/src/hdl4se_mux2.c +++ b/hdl4secell/src/hdl4se_mux2.c @@ -262,11 +262,12 @@ static int hdl4se_mux2_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_mux2_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_mux2_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEMux2* pobj; pobj = (sHDL4SEMux2*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_mux4.c b/hdl4secell/src/hdl4se_mux4.c index 5e174e2918ab2b8791e63686992c194a4dce3a12..24651c3bbe4dd69059518ac6e7347ad0209b3fea 100644 --- a/hdl4secell/src/hdl4se_mux4.c +++ b/hdl4secell/src/hdl4se_mux4.c @@ -260,11 +260,12 @@ static int hdl4se_mux4_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_mux4_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_mux4_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEMux4* pobj; pobj = (sHDL4SEMux4*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_mux8.c b/hdl4secell/src/hdl4se_mux8.c index cdfe2bdc438a12c6faec0564559abf97cf23354f..f96a3c98fc3e3206056c98fe800bd9f72e5e85fe 100644 --- a/hdl4secell/src/hdl4se_mux8.c +++ b/hdl4secell/src/hdl4se_mux8.c @@ -259,11 +259,12 @@ static int hdl4se_mux8_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_mux8_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_mux8_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEMux8* pobj; pobj = (sHDL4SEMux8*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_reg.c b/hdl4secell/src/hdl4se_reg.c index 1967b45a52b4833c88fcfa18f0dabf0cfabb8803..d114856682bd464a8fe5ed8401aa5fa9840838a7 100644 --- a/hdl4secell/src/hdl4se_reg.c +++ b/hdl4secell/src/hdl4se_reg.c @@ -212,11 +212,12 @@ static int hdl4se_reg_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_reg_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_reg_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SEReg* pobj; pobj = (sHDL4SEReg*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4se_split2.c b/hdl4secell/src/hdl4se_split2.c index bd00b2252fc9d025f9a65c94f7e5b47df8b5304e..e5cdf27b0b3bc5387af5d9d12d37b167d0b4656d 100644 --- a/hdl4secell/src/hdl4se_split2.c +++ b/hdl4secell/src/hdl4se_split2.c @@ -280,16 +280,20 @@ static const char* outname[SPLITCOUNT] = { "out0", "out1" }; -static int hdl4se_split2_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_split2_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SESplit2* pobj; pobj = (sHDL4SESplit2*)objectThis(object); if (index <0 || index > SPLITCOUNT) return -1; - if (index == 0) + if (index == 0) { *pname = "in"; - else + *width = pobj->width; + } + else { *pname = outname[index - 1]; + *width = pobj->out_info[index - 1][0]; + } return 0; } diff --git a/hdl4secell/src/hdl4se_split4.c b/hdl4secell/src/hdl4se_split4.c index cd4c6d11c422315b5c764a7e51ccae30e14133c6..4f23b17ea37a0f299e00d51358a721409d084636 100644 --- a/hdl4secell/src/hdl4se_split4.c +++ b/hdl4secell/src/hdl4se_split4.c @@ -283,16 +283,20 @@ static const char* outname[SPLITCOUNT] = { "out0", "out1", "out2", "out3" }; -static int hdl4se_split4_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_split4_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SESplit4* pobj; pobj = (sHDL4SESplit4*)objectThis(object); if (index <0 || index > SPLITCOUNT) return -1; - if (index == 0) + if (index == 0) { *pname = "in"; - else + *width = pobj->width; + } + else { *pname = outname[index - 1]; + *width = pobj->out_info[index - 1][0]; + } return 0; } diff --git a/hdl4secell/src/hdl4se_unop.c b/hdl4secell/src/hdl4se_unop.c index c5ba97f009a4624ed528b22c248ba19a6edfa736..c09c84ca244aa5b9d72ce6ac2e17a8eb9c31f34c 100644 --- a/hdl4secell/src/hdl4se_unop.c +++ b/hdl4secell/src/hdl4se_unop.c @@ -286,14 +286,18 @@ static int hdl4se_unop_hdl4se_detector_GetSignalCount(HOBJECT object) return 2; } -static int hdl4se_unop_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_unop_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int *width) { sHDL4SEUnop* pobj; pobj = (sHDL4SEUnop*)objectThis(object); - if (index == 0) + if (index == 0) { *pname = "in"; - else if (index == 1) + *width = pobj->in_width; + } + else if (index == 1) { *pname = "out"; + *width = pobj->out_width; + } return 0; } diff --git a/hdl4secell/src/hdl4se_wire.c b/hdl4secell/src/hdl4se_wire.c index 3a24def8460eb57e94b5dd9a940f4946f442d553..251e886f0c9b50ab78b82d69a25a6f4d2e3f95c2 100644 --- a/hdl4secell/src/hdl4se_wire.c +++ b/hdl4secell/src/hdl4se_wire.c @@ -225,11 +225,12 @@ static int hdl4se_wire_hdl4se_detector_GetSignalCount(HOBJECT object) return 1; } -static int hdl4se_wire_hdl4se_detector_GetSignalName(HOBJECT object, int index, const char** pname) +static int hdl4se_wire_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) { sHDL4SEWire* pobj; pobj = (sHDL4SEWire*)objectThis(object); *pname = "out"; + *width = pobj->width; return 0; } diff --git a/hdl4secell/src/hdl4secell.c b/hdl4secell/src/hdl4secell.c index b07208d5f75777d8edee789a38749926f0bb5aec..8fc5b7c36540e738e09d96f5049a676f6cbd35a8 100644 --- a/hdl4secell/src/hdl4secell.c +++ b/hdl4secell/src/hdl4secell.c @@ -102,4 +102,36 @@ IHDL4SEUnit** hdl4seCreateUnit(IHDL4SEModule** parent, IIDTYPE clsid, char* inst return result; } - +int hdl4sedetectorTraversal(HOBJECT object, hdl4se_detector_TraversalFunc func, const char* pathname, void* param) +{ + IHDL4SEDetector** detector; + if (0 == objectQueryInterface(object, IID_HDL4SEDETECTOR, (void**)&detector)) { + int count, i, pathlen; + char* pname; + const char* unitname = NULL; + pathlen = strlen(pathname) + 256; + pname = (char*)malloc(pathlen); + if (pname == NULL) + return -2; + strcpy(pname, pathname); + strcat(pname, "/"); + objectCall1(detector, GetName, &unitname); + if (unitname == NULL) { + free(pname); + return -3; + } + strcat(pname, unitname); + if (func(detector, pname, param) != 0) + return -1; + count = objectCall0(detector, GetUnitCount); + for (i = 0; i < count; i++) { + HOBJECT unit; + objectCall2(detector, GetUnit, i, &unit); + if (hdl4sedetectorTraversal(unit, func, pname, param) != 0) + return -1; + } + free(pname); + objectRelease(detector); + } + return 0; +} \ No newline at end of file diff --git a/hdl4sesim/src/hdl4sesim.c b/hdl4sesim/src/hdl4sesim.c index a7bcdeee99cb58596445ca0534f17050fa9feb5c..b5736125f8c8122e03b218e00b25ef9a34e57181 100644 --- a/hdl4sesim/src/hdl4sesim.c +++ b/hdl4sesim/src/hdl4sesim.c @@ -33,6 +33,7 @@ * hdl4sesim.c 淇敼璁板綍锛 202105180851: rxh, initial version + 202105241905锛歳xh, 澧炲姞Detector鎺ュ彛 */ #include "stdlib.h" #include "stdio.h" @@ -49,6 +50,8 @@ typedef struct _sHDL4SESim { OBJECT_HEADER INTERFACE_DECLARE(IHDL4SEUnit) HDL4SEUNIT_VARDECLARE + INTERFACE_DECLARE(IHDL4SEDetector) + HDL4SEDETECTOR_VARDECLARE INTERFACE_DECLARE(IHDL4SESimulator) HDL4SESIMULATOR_VARDECLARE @@ -61,12 +64,14 @@ typedef struct _sHDL4SESim { OBJECT_FUNCDECLARE(hdl4sesim, CLSID_HDL4SESIMULATOR); HDL4SEUNIT_FUNCDECLARE(hdl4sesim, CLSID_HDL4SESIMULATOR, sHDL4SESim); +HDL4SEDETECTOR_FUNCDECLARE(hdl4sesim, CLSID_HDL4SESIMULATOR, sHDL4SESim); HDL4SESIMULATOR_FUNCDECLARE(hdl4sesim, CLSID_HDL4SESIMULATOR, sHDL4SESim); OBJECT_FUNCIMPL(hdl4sesim, sHDL4SESim, CLSID_HDL4SESIMULATOR); QUERYINTERFACE_BEGIN(hdl4sesim, CLSID_HDL4SESIMULATOR) QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SESim) +QUERYINTERFACE_ITEM(IID_HDL4SEDETECTOR, IHDL4SEDetector, sHDL4SESim) QUERYINTERFACE_ITEM(IID_HDL4SESIMULATOR, IHDL4SESimulator, sHDL4SESim) QUERYINTERFACE_END @@ -85,6 +90,7 @@ static int hdl4sesimCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pO *pObject = 0; HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SESIMULATOR); INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4sesim, hdl4se_unit); + INTERFACE_INIT(IHDL4SEDetector, pobj, hdl4sesim, hdl4se_detector); INTERFACE_INIT(IHDL4SESimulator, pobj, hdl4sesim, hdl4se_simulator); for (i = 0; i < MAXDEVICES; i++) { @@ -226,6 +232,59 @@ static int hdl4sesim_hdl4se_simulator_RunClockTick(HOBJECT object) return 0; } +static int hdl4sesim_hdl4se_detector_GetName(HOBJECT object, const char** pname) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + *pname = "simulator"; + return 0; +} + +static int hdl4sesim_hdl4se_detector_GetSignalCount(HOBJECT object) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + return 1; +} + +static int hdl4sesim_hdl4se_detector_GetSignalInfo(HOBJECT object, int index, const char** pname, int * width) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + *pname = "nwReset"; + *width = 1; + return 0; +} + +static int hdl4sesim_hdl4se_detector_GetSignalValue(HOBJECT object, int index, IBigNumber** value) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + objectCall1(value, AssignInt, pobj->reset); + objectCall2(value, SetWidth, 1, 1); + return 0; +} + +static int hdl4sesim_hdl4se_detector_GetUnitCount(HOBJECT object) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + return pobj->devicecount + 1; +} + +static int hdl4sesim_hdl4se_detector_GetUnit(HOBJECT object, int index, HOBJECT* unit) +{ + sHDL4SESim* pobj; + pobj = (sHDL4SESim*)objectThis(object); + if (index < 0 || index > pobj->devicecount) + return -1; + if (index == 0) + *unit = pobj->topmodule; + else + *unit = pobj->devices[index-1]; + return 0; +} + IHDL4SESimulator** hdl4sesimCreateSimulator() { @@ -234,4 +293,4 @@ IHDL4SESimulator** hdl4sesimCreateSimulator() A_u_t_o_registor_hdl4sesim(); ret = objectCreateEx(CLSID_HDL4SESIMULATOR, NULL, 0, IID_HDL4SESIMULATOR, (const void**)&sim); return sim; -} \ No newline at end of file +}