diff --git a/bignumber/src/bignumber.c b/bignumber/src/bignumber.c index f120bde5465fe8a56966048152cd6cd27b61dc32..1d5ac3a9a4c7ee075cadb61c970e7ca3a7b44081 100644 --- a/bignumber/src/bignumber.c +++ b/bignumber/src/bignumber.c @@ -158,7 +158,7 @@ static int bigint_bn_SetWidth(HOBJECT object, int width, int signexpand) sign = 0; if (signexpand) { bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH-1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH-1))); } blen = (width + CELL_WIDTH - 1) / CELL_WIDTH; @@ -375,6 +375,7 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst lastnum: if (nstr != NULL) *nstr = strt; + bigint_bn_SetWidth(object, pobj->width, 1); return 0; } @@ -691,7 +692,7 @@ static int bigint_bn_SAR(HOBJECT object, int bits) if (bits < 0) return bigint_bn_SHL(object, -bits); bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1))); ito = 0; ifrom = bits / CELL_WIDTH; if (ifrom >= pobj->buflen) { @@ -828,7 +829,7 @@ static int bigint_bn_IsNeg(HOBJECT object) int bc, sign; pobj = (sBigInteger*)objectThis(object); bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1))); return sign?1:0; } @@ -843,11 +844,10 @@ static int bigint_bn_IsEQ(HOBJECT object, HOBJECT src) return 0; } psrc = (sBigInteger*)objectThis(src); - psrc = (sBigInteger*)objectThis(src); bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1))); bc = psrc->width / CELL_WIDTH; - signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); + signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1))); if (sign != signsrc) { return 0; } @@ -883,9 +883,9 @@ static int bigint_bn_IsLE(HOBJECT object, HOBJECT src) } psrc = (sBigInteger*)objectThis(src); bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1))); bc = psrc->width / CELL_WIDTH; - signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); + signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1))); if (sign == 0 && signsrc != 0) { return 0; } @@ -946,9 +946,9 @@ static int bigint_bn_IsLT(HOBJECT object, HOBJECT src) } psrc = (sBigInteger*)objectThis(src); bc = pobj->width / CELL_WIDTH; - sign = pobj->buf[bc] & (1 << (pobj->width & (CELL_WIDTH - 1))); + sign = pobj->buf[bc] & (1 << ((pobj->width-1) & (CELL_WIDTH - 1))); bc = psrc->width / CELL_WIDTH; - signsrc = psrc->buf[bc] & (1 << (psrc->width & (CELL_WIDTH - 1))); + signsrc = psrc->buf[bc] & (1 << ((psrc->width-1) & (CELL_WIDTH - 1))); if (sign == 0 && signsrc != 0) { return 0; } diff --git a/examples/counter/src/counter.c b/examples/counter/src/counter.c index 2f0841c1bf83f5c529f36b0cb5bd55b46417eb62..d4c9e91eaf89b72ab5d3b8fa5f16dc4edab0cb35 100644 --- a/examples/counter/src/counter.c +++ b/examples/counter/src/counter.c @@ -87,7 +87,7 @@ static IHDL4SEUnit** hdl4seCreateDec2seg(IHDL4SEModule** parent, char* instancep objectCall3(unit_mux16, Connect, i+1, wire_const[i], 0); } for (; i < 16; i++) { - objectCall3(unit_mux16, Connect, i + 11, wire_const[10], 0); + objectCall3(unit_mux16, Connect, i+1, wire_const[10], 0); } /* 译码模块的输出seg连接到数据先择器的输出*/ objectCall3(unit_dec2seg, Connect, 1, unit_mux16, 17); @@ -116,110 +116,74 @@ static IHDL4SEUnit** hdl4seCreateCounter(IHDL4SEModule** parent, char* instancep /*WIDTH宽度的寄存器用来保存计数器的值*/ sprintf(temp, "%d", width); - IHDL4SEUnit** wire_wirein_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "wirein_bCurrentCounter"); - IHDL4SEUnit** wire_wireout_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "wireout_bCurrentCounter"); IHDL4SEUnit** reg_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_REG, temp, "bCurrentCounter"); - /*寄存器和线网连接在一起*/ - objectCall3(reg_bCurrentCounter, Connect, 0, wire_wirein_bCurrentCounter, 0); - objectCall3(wire_wireout_bCurrentCounter, Connect, 0, reg_bCurrentCounter, 1); - objectCall3(unit_counter, Connect, 2, wire_wireout_bCurrentCounter, 0); /*定义一个寄存器来表示计数器是否溢出*/ - IHDL4SEUnit** wire_wirein_wOverflow = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wirein_wOverflow"); - IHDL4SEUnit** wire_wireout_wOverflow = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wireout_wOverflow"); IHDL4SEUnit** reg_wOverflow = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_REG, "1", "wOverflow"); - /*寄存器和线网连接在一起*/ - objectCall3(reg_wOverflow, Connect, 0, wire_wirein_wOverflow, 0); - objectCall3(wire_wireout_wOverflow, Connect, 0, reg_wOverflow, 1); - objectCall3(unit_counter, Connect, 3, wire_wireout_wOverflow, 0); - sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bConst_MAXVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bConst_MAXVALUE"); + objectCall3(unit_counter, Connect, 2, reg_bCurrentCounter, 1); + objectCall3(unit_counter, Connect, 3, reg_wOverflow, 1); + + sprintf(temp, "%d, %d", width, maxvalue); IHDL4SEUnit** unit_const_MAXVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, temp, "const_MAXVALUE"); - objectCall3(wire_bConst_MAXVALUE, Connect, 0, unit_const_MAXVALUE, 0); - sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bConst_RESETVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bConst_RESETVALUE"); sprintf(temp, "%d, %d", width, resetvalue); IHDL4SEUnit** unit_const_RESETVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, temp, "const_RESETVALUE"); - objectCall3(wire_bConst_RESETVALUE, Connect, 0, unit_const_RESETVALUE, 0); - - IHDL4SEUnit** wire_wEQ_bCurrentCounter_MAXVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wEQ_bCurrentCounter_MAXVALUE"); sprintf(temp, "%d, %d, 1, %d", width, width, BINOP_EQ); IHDL4SEUnit** unit_binop_EQ_bCurrentCounter_MAXVALUE = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_BINOP, temp, "binop_EQ_bCurrentCounter_MAXVALUE"); - objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 0, wire_wireout_bCurrentCounter, 0); - objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 1, wire_bConst_MAXVALUE, 0); - objectCall3(wire_wEQ_bCurrentCounter_MAXVALUE, Connect, 0, unit_binop_EQ_bCurrentCounter_MAXVALUE, 2); + objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 0, reg_bCurrentCounter, 1); + objectCall3(unit_binop_EQ_bCurrentCounter_MAXVALUE, Connect, 1, unit_const_MAXVALUE, 0); /* bCurrentCounter+1 用加法器实现 */ /* 常数 1 */ - sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bConst_One = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bConst_One"); sprintf(temp, "%d, %d", width, 1); IHDL4SEUnit** unit_const_One = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, temp, "const_One"); - objectCall3(wire_bConst_One, Connect, 0, unit_const_One, 0); /* bCurrentCounter + 1 */ - sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bCurrentCounterPlusOne = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bCurrentCounterPlusOne"); - sprintf(temp, "%d, %d, 1, %d", width, width, BINOP_ADD); + sprintf(temp, "%d, %d, %d, %d", width, width, width, BINOP_ADD); IHDL4SEUnit** unit_binop_bCurrentCounterPlusOne = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_BINOP, temp, "binop_bCurrentCounterInc"); - objectCall3(unit_binop_bCurrentCounterPlusOne, Connect, 0, wire_wireout_bCurrentCounter, 0); - objectCall3(unit_binop_bCurrentCounterPlusOne, Connect, 1, wire_bConst_One, 0); - objectCall3(wire_bCurrentCounterPlusOne, Connect, 0, unit_binop_bCurrentCounterPlusOne, 2); + objectCall3(unit_binop_bCurrentCounterPlusOne, Connect, 0, reg_bCurrentCounter, 1); + objectCall3(unit_binop_bCurrentCounterPlusOne, Connect, 1, unit_const_One, 0); /* if语句用数据选择器实现 */ sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bCurrentCounter_if_wCounterIt = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bCurrentCounter_if_wCounterIt"); - IHDL4SEUnit** unit_muxCurrentCouter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter_if_wCounterIt"); - objectCall3(unit_muxCurrentCouter, Connect, 0, wire_wEQ_bCurrentCounter_MAXVALUE, 0); - objectCall3(unit_muxCurrentCouter, Connect, 1, wire_bCurrentCounterPlusOne, 0); - objectCall3(unit_muxCurrentCouter, Connect, 2, wire_bConst_RESETVALUE, 0); - objectCall3(wire_bCurrentCounter_if_wCounterIt, Connect, 0, unit_muxCurrentCouter, 3); - - IHDL4SEUnit** wire_wConst_0 = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wConst_0"); - IHDL4SEUnit** unit_const_0 = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, "1, 0", "const_0"); - objectCall3(wire_wConst_0, Connect, 0, unit_const_0, 0); + IHDL4SEUnit** unit_mux_bCounter_If_EQMAXvalue = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter_if_wCounterIt"); + objectCall3(unit_mux_bCounter_If_EQMAXvalue, Connect, 0, unit_binop_EQ_bCurrentCounter_MAXVALUE, 2); + objectCall3(unit_mux_bCounter_If_EQMAXvalue, Connect, 1, unit_binop_bCurrentCounterPlusOne, 2); + objectCall3(unit_mux_bCounter_If_EQMAXvalue, Connect, 2, unit_const_RESETVALUE, 0); - IHDL4SEUnit** wire_wConst_1 = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wConst_1"); + IHDL4SEUnit** unit_const_0 = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, "1, 0", "const_0"); IHDL4SEUnit** unit_const_1 = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_CONST, "1, 1", "const_1"); - objectCall3(wire_wConst_1, Connect, 0, unit_const_1, 0); - IHDL4SEUnit** wire_wOverflow_if_wCounterIt = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wOverflow_if_wCounterIt"); - IHDL4SEUnit** unit_mux_wOverflow_if_wCounterIt = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, "1", "mux_wOverflow_if_wCounterIt"); - objectCall3(unit_mux_wOverflow_if_wCounterIt, Connect, 0, wire_wEQ_bCurrentCounter_MAXVALUE, 0); - objectCall3(unit_mux_wOverflow_if_wCounterIt, Connect, 1, wire_wConst_0, 0); - objectCall3(unit_mux_wOverflow_if_wCounterIt, Connect, 2, wire_wConst_1, 0); - objectCall3(wire_wOverflow_if_wCounterIt, Connect, 0, unit_mux_wOverflow_if_wCounterIt, 3); + IHDL4SEUnit** unit_mux_wOverflow_If_EQMAXvalue = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, "1", "mux_wOverflow_if_wCounterIt"); + objectCall3(unit_mux_wOverflow_If_EQMAXvalue, Connect, 0, unit_binop_EQ_bCurrentCounter_MAXVALUE, 2); + objectCall3(unit_mux_wOverflow_If_EQMAXvalue, Connect, 1, unit_const_0, 0); + objectCall3(unit_mux_wOverflow_If_EQMAXvalue, Connect, 2, unit_const_1, 0); sprintf(temp, "%d", width); - IHDL4SEUnit** wire_bCurrentCounter_if_nwReset = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, temp, "bCurrentCounter_if_nwReset"); IHDL4SEUnit** unit_mux_bCurrentCounter_if_nwReset = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter_if_nwReset"); objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 0, module_counter, 1); - objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 1, wire_wireout_bCurrentCounter, 0); - objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 2, wire_bCurrentCounter_if_wCounterIt, 0); - objectCall3(wire_bCurrentCounter_if_nwReset, Connect, 0, unit_mux_bCurrentCounter_if_nwReset, 3); + objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 1, reg_bCurrentCounter, 0); + objectCall3(unit_mux_bCurrentCounter_if_nwReset, Connect, 2, unit_mux_bCounter_If_EQMAXvalue, 2); - IHDL4SEUnit** wire_wOverflow_if_nwReset = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_WIRE, "1", "wOverfloat_if_nwReset"); IHDL4SEUnit** unit_mux_wOverflow_if_nwReset = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, "1", "mux_wOverflow_if_nwReset"); objectCall3(unit_mux_wOverflow_if_nwReset, Connect, 0, module_counter, 1); - objectCall3(unit_mux_wOverflow_if_nwReset, Connect, 1, wire_wireout_wOverflow, 0); - objectCall3(unit_mux_wOverflow_if_nwReset, Connect, 2, wire_wOverflow_if_wCounterIt, 0); - objectCall3(wire_wOverflow_if_nwReset, Connect, 0, unit_mux_wOverflow_if_nwReset, 3); + objectCall3(unit_mux_wOverflow_if_nwReset, Connect, 1, unit_const_0, 0); + objectCall3(unit_mux_wOverflow_if_nwReset, Connect, 2, unit_mux_wOverflow_If_EQMAXvalue, 2); IHDL4SEUnit** unit_mux_bCurrentCounter = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, temp, "mux_bCurrentCounter"); - objectCall3(unit_mux_bCurrentCounter, Connect, 0, module_counter, 1); - objectCall3(unit_mux_bCurrentCounter, Connect, 1, wire_bConst_RESETVALUE, 0); - objectCall3(unit_mux_bCurrentCounter, Connect, 2, wire_bCurrentCounter_if_nwReset, 0); - objectCall3(wire_wirein_bCurrentCounter, Connect, 0, unit_mux_bCurrentCounter, 3); + objectCall3(unit_mux_bCurrentCounter, Connect, 0, module_counter, 0); + objectCall3(unit_mux_bCurrentCounter, Connect, 1, unit_const_RESETVALUE, 0); + objectCall3(unit_mux_bCurrentCounter, Connect, 2, unit_mux_bCurrentCounter_if_nwReset, 2); + objectCall3(reg_bCurrentCounter, Connect, 0, unit_mux_bCurrentCounter, 3); IHDL4SEUnit** unit_mux_wOverflow = hdl4seCreateUnit(module_counter, CLSID_HDL4SE_MUX2, "1", "mux_wOverflow"); - objectCall3(unit_mux_wOverflow, Connect, 0, module_counter, 1); - objectCall3(unit_mux_wOverflow, Connect, 1, wire_wireout_wOverflow, 0); - objectCall3(unit_mux_wOverflow, Connect, 2, wire_wOverflow_if_wCounterIt, 0); - objectCall3(wire_wirein_wOverflow, Connect, 0, unit_mux_wOverflow, 3); + objectCall3(unit_mux_wOverflow, Connect, 0, module_counter, 0); + objectCall3(unit_mux_wOverflow, Connect, 1, unit_const_0, 0); + objectCall3(unit_mux_wOverflow, Connect, 2, unit_mux_wOverflow_if_nwReset, 2); + objectCall3(reg_wOverflow, Connect, 0, unit_mux_wOverflow, 3); /*释放module接口*/ objectRelease(module_counter); @@ -248,334 +212,178 @@ IHDL4SEUnit** hdl4seCreateMain(IHDL4SEModule** parent, char* instanceparam, char objectCall3(module_main, AddPort, 32, PORTTYPE_OUTPUT, "6.bReadAddr"); objectCall3(module_main, AddPort, 32, PORTTYPE_INPUT, "7.bReadData"); - IHDL4SEUnit** wire_wButton0Pressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wButton0Pressed"); - IHDL4SEUnit** wire_wButton1Pressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wButton1Pressed"); - IHDL4SEUnit** wire_wButton2Pressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wButton2Pressed"); - + IHDL4SEUnit** const_1b1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "1,1", "const_bReadAddr"); + objectCall3(unit_main, Connect, 1, const_1b1, 1); /* 简化处理,一直写 */ + IHDL4SEUnit** reg_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "32", "reg_bWriteAddr"); + objectCall3(unit_main, Connect, 2, reg_bWriteAddr, 1); + IHDL4SEUnit** reg_bWriteData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "32", "reg_bWriteData"); + objectCall3(unit_main, Connect, 3, reg_bWriteData, 1); + IHDL4SEUnit** reg_bWriteMask = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "4", "reg_bWriteMask"); + objectCall3(unit_main, Connect, 4, reg_bWriteMask, 1); IHDL4SEUnit** const_0_wRead = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "1, 1", "const_0_wRead"); objectCall3(unit_main, Connect, 5, const_0_wRead, 0); - IHDL4SEUnit** const_bReadAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hF000_0000", "const_bReadAddr"); objectCall3(unit_main, Connect, 6, const_bReadAddr, 0); IHDL4SEUnit** split_bReadData_wButton012 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_SPLIT4, "32, 1, 0, 1, 1, 1, 2, 1, 3", "bReadData_wButton012"); objectCall3(split_bReadData_wButton012, Connect, 0, unit_main, 7); - objectCall3(wire_wButton0Pressed, Connect, 0, split_bReadData_wButton012, 1); - objectCall3(wire_wButton1Pressed, Connect, 0, split_bReadData_wButton012, 2); - objectCall3(wire_wButton2Pressed, Connect, 0, split_bReadData_wButton012, 3); - /* split_bReadData_wButton012的第四脚不连接 */ - - IHDL4SEUnit** wire_nwResetCount = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "nwResetCount"); - - IHDL4SEUnit** wire_wCounterin[10]; - for (i = 0; i < 10; i++) { - sprintf(temp, "wCounterin0%d", i); - wire_wCounterin[i] = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", temp); - } - - IHDL4SEUnit** wire_bCount[10]; - for (i = 0; i < 10; i++) { - sprintf(temp, "bCount0%d", i); - wire_bCount[i] = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", temp); - } - - IHDL4SEUnit** counter_counter[10]; - for (i = 0; i < 10; i++) { - sprintf(temp, "counter%d", i); - counter_counter[i] = hdl4seCreateCounter(module_main, "4, 9, 0", temp); - objectCall3(counter_counter[i], Connect, 0, wire_nwResetCount, 0); - objectCall3(counter_counter[i], Connect, 1, wire_wCounterin[i], 0); - objectCall3(wire_bCount[i], Connect, 0, counter_counter[i], 2); - if (i<9) - objectCall3(wire_wCounterin[i+1], Connect, 0, counter_counter[i], 3); - } - - IHDL4SEUnit** wire_wirein_wCounterIt = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wirein_wCounterIt"); - IHDL4SEUnit** wire_wireout_wCounterIt = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wireout_wCounterIt"); - IHDL4SEUnit** reg_wCounterIt = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "1", "wCounterIt"); - /*寄存器和线网连接在一起*/ - objectCall3(reg_wCounterIt, Connect, 0, wire_wirein_wCounterIt, 0); - objectCall3(wire_wireout_wCounterIt, Connect, 0, reg_wCounterIt, 1); - objectCall3(wire_wCounterin[0], Connect, 0, wire_wireout_wCounterIt, 0); - IHDL4SEUnit** wire_wButton0NotPressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wButton0NotPressed"); sprintf(temp, "1, 1, %d", UNOP_NOT); IHDL4SEUnit** unop_Button0NotPressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_UNOP, temp, "unop_Button0NotPressed"); - objectCall3(unop_Button0NotPressed, Connect, 0, wire_wButton0Pressed, 0); - objectCall3(wire_wButton0NotPressed, Connect, 0, unop_Button0NotPressed, 1); - - IHDL4SEUnit** wire_wButton1NotPressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wButton1NotPressed"); + objectCall3(unop_Button0NotPressed, Connect, 0, split_bReadData_wButton012, 1); sprintf(temp, "1, 1, %d", UNOP_NOT); IHDL4SEUnit** unop_Button1NotPressed = hdl4seCreateUnit(module_main, CLSID_HDL4SE_UNOP, temp, "unop_Button1NotPressed"); - objectCall3(unop_Button1NotPressed, Connect, 0, wire_wButton1Pressed, 0); - objectCall3(wire_wButton1NotPressed, Connect, 0, unop_Button1NotPressed, 1); + objectCall3(unop_Button1NotPressed, Connect, 0, split_bReadData_wButton012, 2); sprintf(temp, "1, 1, 1, %d", BINOP_AND); - IHDL4SEUnit** binop_binop_counterit = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "binop_counterit"); - objectCall3(binop_binop_counterit, Connect, 0, wire_wButton1NotPressed, 0); - objectCall3(binop_binop_counterit, Connect, 1, wire_wButton2Pressed, 0); - objectCall3(wire_wirein_wCounterIt, Connect, 0, binop_binop_counterit, 2); + IHDL4SEUnit** binop_counterit = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "binop_counterit"); + objectCall3(binop_counterit, Connect, 0, unop_Button1NotPressed, 1); + objectCall3(binop_counterit, Connect, 1, split_bReadData_wButton012, 3); sprintf(temp, "1, 1, 1, %d", BINOP_AND); - IHDL4SEUnit** binop_binop_resetcounter = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "binop_resetcounter"); - objectCall3(binop_binop_resetcounter, Connect, 0, wire_wButton0NotPressed, 0); - objectCall3(binop_binop_resetcounter, Connect, 1, unit_main, 0); - objectCall3(wire_nwResetCount, Connect, 0, binop_binop_resetcounter, 2); - - /* 以下是译码器连接,十个计数器的输出对应到十个译码器 */ - IHDL4SEUnit** code[10]; - IHDL4SEUnit** dec[10]; + IHDL4SEUnit** binop_resetcounter = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "binop_resetcounter"); + objectCall3(binop_resetcounter, Connect, 0, unop_Button0NotPressed, 1); + objectCall3(binop_resetcounter, Connect, 1, unit_main, 0); + + + IHDL4SEUnit** counter[10]; + IHDL4SEUnit** dec2seg[10]; for (i = 0; i < 10; i++) { - sprintf(temp, "code%d", i); - code[i] = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "8", temp); - sprintf(temp, "dec%d", i); - dec[i] = hdl4seCreateDec2seg(module_main, "", temp); - objectCall3(dec[i], Connect, 0, wire_bCount[i], 0); - objectCall3(code[i], Connect, 0, dec[i], 1); + sprintf(temp, "counter%d", i); + counter[i] = hdl4seCreateCounter(module_main, "4, 9, 0", temp); + dec2seg[i] = hdl4seCreateDec2seg(module_main, "", temp); + objectCall3(counter[i], Connect, 0, binop_resetcounter, 2); + if (i == 0) + objectCall3(counter[i], Connect, 1, binop_counterit, 2); + else + objectCall3(counter[i], Connect, 1, counter[i-1], 3); + objectCall3(dec2seg[i], Connect, 0, counter[i], 2); } - IHDL4SEUnit** wire_wCounterin98 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin98"); - IHDL4SEUnit** wire_wCounterin76 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin76"); - IHDL4SEUnit** wire_wCounterin54 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin54"); - IHDL4SEUnit** wire_wCounterin32 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin32"); - IHDL4SEUnit** wire_wCounterin10 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin10"); - IHDL4SEUnit** wire_wCounterin7654 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin7654"); - IHDL4SEUnit** wire_wCounterin3210 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterin3210"); - sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or98 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or98"); - objectCall3(binop_or98, Connect, 0, wire_wCounterin[9], 0); - objectCall3(binop_or98, Connect, 1, wire_wCounterin[8], 0); - objectCall3(wire_wCounterin98, Connect, 0, binop_or98, 2); + objectCall3(binop_or98, Connect, 0, counter[8], 3); + objectCall3(binop_or98, Connect, 1, counter[7], 3); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or76 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or76"); - objectCall3(binop_or76, Connect, 0, wire_wCounterin[7], 0); - objectCall3(binop_or76, Connect, 1, wire_wCounterin[6], 0); - objectCall3(wire_wCounterin76, Connect, 0, binop_or76, 2); + objectCall3(binop_or76, Connect, 0, counter[6], 3); + objectCall3(binop_or76, Connect, 1, counter[5], 3); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or54 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or54"); - objectCall3(binop_or54, Connect, 0, wire_wCounterin[5], 0); - objectCall3(binop_or54, Connect, 1, wire_wCounterin[4], 0); - objectCall3(wire_wCounterin54, Connect, 0, binop_or54, 2); + objectCall3(binop_or54, Connect, 0, counter[4], 3); + objectCall3(binop_or54, Connect, 1, counter[3], 3); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or32 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or32"); - objectCall3(binop_or32, Connect, 0, wire_wCounterin[3], 0); - objectCall3(binop_or32, Connect, 1, wire_wCounterin[2], 0); - objectCall3(wire_wCounterin32, Connect, 0, binop_or32, 2); + objectCall3(binop_or32, Connect, 0, counter[2], 3); + objectCall3(binop_or32, Connect, 1, counter[1], 3); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or10 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or10"); - objectCall3(binop_or10, Connect, 0, wire_wCounterin[1], 0); - objectCall3(binop_or10, Connect, 1, wire_wCounterin[0], 0); - objectCall3(wire_wCounterin10, Connect, 0, binop_or10, 2); + objectCall3(binop_or10, Connect, 0, counter[0], 3); + objectCall3(binop_or10, Connect, 1, binop_counterit, 2); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or7654 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or7654"); - objectCall3(binop_or7654, Connect, 0, binop_or76, 0); - objectCall3(binop_or7654, Connect, 1, binop_or54, 0); - objectCall3(wire_wCounterin7654, Connect, 0, binop_or7654, 2); + objectCall3(binop_or7654, Connect, 0, binop_or76, 2); + objectCall3(binop_or7654, Connect, 1, binop_or54, 2); sprintf(temp, "1, 1, 1, %d", BINOP_OR); IHDL4SEUnit** binop_or3210 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or3210"); - objectCall3(binop_or3210, Connect, 0, binop_or32, 0); - objectCall3(binop_or3210, Connect, 1, binop_or10, 0); - objectCall3(wire_wCounterin3210, Connect, 0, binop_or3210, 2); - - IHDL4SEUnit** wire_wirein_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "3", "wirein_bCounterChanged"); - IHDL4SEUnit** wire_wireout_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "3", "wireout_bCounterChanged"); - IHDL4SEUnit** reg_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "3", "reg_bCounterChanged"); - objectCall3(reg_bCounterChanged, Connect, 0, wire_wirein_bCounterChanged, 0); - objectCall3(wire_wireout_bCounterChanged, Connect, 0, reg_bCounterChanged, 1); - - IHDL4SEUnit** wire_bChanged_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "3", "bChanged_if_nwReset"); - IHDL4SEUnit** bind_wCounterin = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1, 1, 1", "bind_wCounterin"); - objectCall3(bind_wCounterin, Connect, 0, wire_wCounterin3210, 0); - objectCall3(bind_wCounterin, Connect, 1, wire_wCounterin7654, 0); - objectCall3(bind_wCounterin, Connect, 2, wire_wCounterin98, 0); - objectCall3(wire_bChanged_if_nwReset, Connect, 0, bind_wCounterin, 3); - - IHDL4SEUnit** wire_b3b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "3", "b3b0"); - IHDL4SEUnit** const_b3b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "3, 0", "const_b3b0"); - objectCall3(wire_b3b0, Connect, 0, const_b3b0, 0); - IHDL4SEUnit** mux_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "3", "mux_if_nwReset"); - objectCall3(mux_if_nwReset, Connect, 0, wire_b3b0, 0); - objectCall3(mux_if_nwReset, Connect, 1, wire_bChanged_if_nwReset, 0); - objectCall3(wire_wirein_bCounterChanged, Connect, 0, mux_if_nwReset, 2); - - IHDL4SEUnit** wire_wCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterChanged0"); - IHDL4SEUnit** wire_wCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterChanged1"); - IHDL4SEUnit** wire_wCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wCounterChanged2"); - IHDL4SEUnit** split4_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_SPLIT4, - "3, 1, 0, 1, 1, 1,2, 1,2", "split4_bCounterChanded"); - objectCall3(split4_bCounterChanged, Connect, 0, wire_wireout_bCounterChanged, 0); - objectCall3(wire_wCounterChanged0, Connect, 0, split4_bCounterChanged, 1); - objectCall3(wire_wCounterChanged1, Connect, 0, split4_bCounterChanged, 2); - objectCall3(wire_wCounterChanged2, Connect, 0, split4_bCounterChanged, 3); - - IHDL4SEUnit** wire_wirein_wWrite = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wirein_wWrite"); - IHDL4SEUnit** wire_wireout_wWrite = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wireout_wWrite"); - IHDL4SEUnit** reg_wWrite = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "1", "reg_wWrite"); - objectCall3(reg_wWrite, Connect, 0, wire_wirein_wWrite, 0); - objectCall3(wire_wireout_wWrite, Connect, 0, reg_wWrite, 1); - - IHDL4SEUnit** wire_wirein_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wirein_bWriteAddr"); - IHDL4SEUnit** wire_wireout_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wireout_bWriteAddr"); - IHDL4SEUnit** reg_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "32", "reg_bWriteAddr"); - objectCall3(reg_bWriteAddr, Connect, 0, wire_wirein_bWriteAddr, 0); - objectCall3(wire_wireout_bWriteAddr, Connect, 0, reg_bWriteAddr, 1); + objectCall3(binop_or3210, Connect, 0, binop_or32, 2); + objectCall3(binop_or3210, Connect, 1, binop_or10, 2); - IHDL4SEUnit** wire_wirein_bWriteData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wirein_bWriteData"); - IHDL4SEUnit** wire_wireout_bWriteData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wireout_bWriteData"); - IHDL4SEUnit** reg_bWriteData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "32", "reg_bWriteData"); - objectCall3(reg_bWriteData, Connect, 0, wire_wirein_bWriteData, 0); - objectCall3(wire_wireout_bWriteData, Connect, 0, reg_bWriteData, 1); - - IHDL4SEUnit** wire_wirein_bWriteMask = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wirein_bWriteMask"); - IHDL4SEUnit** wire_wireout_bWriteMask = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wireout_bWriteMask"); - IHDL4SEUnit** reg_bWriteMask = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "4", "reg_bWriteMask"); - objectCall3(reg_bWriteMask, Connect, 0, wire_wirein_bWriteMask, 0); - objectCall3(wire_wireout_bWriteMask, Connect, 0, reg_bWriteMask, 1); - - IHDL4SEUnit** wire_b8b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "8", "b8b0"); IHDL4SEUnit** const_b8b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "8, 0", "const_b8b0"); - objectCall3(wire_b8b0, Connect, 0, const_b8b0, 0); - - IHDL4SEUnit** wire_b4b0000 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "b4b0000"); IHDL4SEUnit** const_b4b0000 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "4, 0", "const_b4b0000"); - objectCall3(wire_b4b0000, Connect, 0, const_b4b0000, 0); - - IHDL4SEUnit** wire_b4b1100 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "b4b1100"); IHDL4SEUnit** const_b4b1100 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "4, 4'b1100", "const_b4b1100"); - objectCall3(wire_b4b1100, Connect, 0, const_b4b1100, 0); - - IHDL4SEUnit** wire_b32b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b32b0"); IHDL4SEUnit** const_b32b0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 0", "const_b32b0"); - objectCall3(wire_b32b0, Connect, 0, const_b32b0, 0); - - IHDL4SEUnit** wire_b32hf0000018 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b32hf0000018"); IHDL4SEUnit** const_b32hf0000018 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hf0000018", "const_b32hf0000018"); - objectCall3(wire_b32hf0000018, Connect, 0, const_b32hf0000018, 0); - - IHDL4SEUnit** wire_b32hf0000014 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b32hf0000014"); IHDL4SEUnit** const_b32hf0000014 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hf0000014", "const_b32hf0000014"); - objectCall3(wire_b32hf0000014, Connect, 0, const_b32hf0000014, 0); - - IHDL4SEUnit** wire_b32hf0000010 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b32hf0000010"); IHDL4SEUnit** const_b32hf0000010 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hf0000010", "const_b32hf0000010"); - objectCall3(wire_b32hf0000010, Connect, 0, const_b32hf0000010, 0); - - IHDL4SEUnit** wire_b0098 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b0098"); - IHDL4SEUnit** wire_b7654 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b7654"); - IHDL4SEUnit** wire_b3210 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "b3210"); IHDL4SEUnit** bind4_b0098 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BIND4, "8,8,8,8", "bind_0098"); - objectCall3(bind4_b0098, Connect, 0, code[8], 0); - objectCall3(bind4_b0098, Connect, 1, code[9], 0); - objectCall3(bind4_b0098, Connect, 2, wire_b8b0, 0); - objectCall3(bind4_b0098, Connect, 3, wire_b8b0, 0); - objectCall3(wire_b0098, Connect, 0, bind4_b0098, 4); + objectCall3(bind4_b0098, Connect, 0, dec2seg[8], 1); + objectCall3(bind4_b0098, Connect, 1, dec2seg[9], 1); + objectCall3(bind4_b0098, Connect, 2, const_b8b0, 1); + objectCall3(bind4_b0098, Connect, 3, const_b8b0, 1); IHDL4SEUnit** bind4_b7654 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BIND4, "8,8,8,8", "bind_7654"); - objectCall3(bind4_b7654, Connect, 0, code[4], 0); - objectCall3(bind4_b7654, Connect, 1, code[5], 0); - objectCall3(bind4_b7654, Connect, 2, code[6], 0); - objectCall3(bind4_b7654, Connect, 3, code[7], 0); - objectCall3(wire_b7654, Connect, 0, bind4_b7654, 4); + objectCall3(bind4_b7654, Connect, 0, dec2seg[4], 1); + objectCall3(bind4_b7654, Connect, 1, dec2seg[5], 1); + objectCall3(bind4_b7654, Connect, 2, dec2seg[6], 1); + objectCall3(bind4_b7654, Connect, 3, dec2seg[7], 1); IHDL4SEUnit** bind4_b3210 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BIND4, "8,8,8,8", "bind_3210"); - objectCall3(bind4_b3210, Connect, 0, code[0], 0); - objectCall3(bind4_b3210, Connect, 1, code[1], 0); - objectCall3(bind4_b3210, Connect, 2, code[2], 0); - objectCall3(bind4_b3210, Connect, 3, code[3], 0); - objectCall3(wire_b3210, Connect, 0, bind4_b3210, 4); + objectCall3(bind4_b3210, Connect, 0, dec2seg[0], 1); + objectCall3(bind4_b3210, Connect, 1, dec2seg[1], 1); + objectCall3(bind4_b3210, Connect, 2, dec2seg[2], 1); + objectCall3(bind4_b3210, Connect, 3, dec2seg[3], 1); - IHDL4SEUnit** wire_bWriteMask_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wire_bWriteMask_if_bCounterChanged0"); IHDL4SEUnit** mux_bWriteMask_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "4", "mux_bWriteMask_if_bCounterChanged0"); - objectCall3(mux_bWriteMask_if_bCounterChanged0, Connect, 0, wire_wireout_bWriteMask, 0); - objectCall3(mux_bWriteMask_if_bCounterChanged0, Connect, 1, wire_b4b0000, 0); - objectCall3(wire_bWriteMask_if_bCounterChanged0, Connect, 0, mux_bWriteMask_if_bCounterChanged0, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged0, Connect, 0, binop_or3210, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged0, Connect, 1, reg_bWriteMask, 1); + objectCall3(mux_bWriteMask_if_bCounterChanged0, Connect, 2, const_b4b0000, 0); - IHDL4SEUnit** wire_bWriteAddr_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteAddr_if_bCounterChanged0"); IHDL4SEUnit** mux_bWriteAddr_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteAddr_if_bCounterChanged0"); - objectCall3(mux_bWriteAddr_if_bCounterChanged0, Connect, 0, wire_wireout_bWriteAddr, 0); - objectCall3(mux_bWriteAddr_if_bCounterChanged0, Connect, 1, wire_b32hf0000010, 0); - objectCall3(wire_bWriteAddr_if_bCounterChanged0, Connect, 0, mux_bWriteAddr_if_bCounterChanged0, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged0, Connect, 0, binop_or3210, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged0, Connect, 1, reg_bWriteAddr, 1); + objectCall3(mux_bWriteAddr_if_bCounterChanged0, Connect, 2, const_b32hf0000010, 0); - IHDL4SEUnit** wire_bWriteData_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteData_if_bCounterChanged0"); IHDL4SEUnit** mux_bWriteData_if_bCounterChanged0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteData_if_bCounterChanged0"); - objectCall3(mux_bWriteData_if_bCounterChanged0, Connect, 0, wire_wireout_bWriteData, 0); - objectCall3(mux_bWriteData_if_bCounterChanged0, Connect, 1, wire_b3210, 0); - objectCall3(wire_bWriteData_if_bCounterChanged0, Connect, 0, mux_bWriteData_if_bCounterChanged0, 2); + objectCall3(mux_bWriteData_if_bCounterChanged0, Connect, 0, binop_or3210, 2); + objectCall3(mux_bWriteData_if_bCounterChanged0, Connect, 1, reg_bWriteData, 1); + objectCall3(mux_bWriteData_if_bCounterChanged0, Connect, 2, bind4_b3210, 0); - IHDL4SEUnit** wire_bWriteMask_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wire_bWriteMask_if_bCounterChanged1"); IHDL4SEUnit** mux_bWriteMask_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "4", "mux_bWriteMask_if_bCounterChanged1"); - objectCall3(mux_bWriteMask_if_bCounterChanged1, Connect, 0, mux_bWriteMask_if_bCounterChanged0, 0); - objectCall3(mux_bWriteMask_if_bCounterChanged1, Connect, 1, wire_b4b0000, 0); - objectCall3(wire_bWriteMask_if_bCounterChanged1, Connect, 0, mux_bWriteMask_if_bCounterChanged1, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged1, Connect, 0, binop_or7654, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged1, Connect, 1, mux_bWriteMask_if_bCounterChanged0, 3); + objectCall3(mux_bWriteMask_if_bCounterChanged1, Connect, 2, const_b4b0000, 0); - IHDL4SEUnit** wire_bWriteAddr_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteAddr_if_bCounterChanged1"); IHDL4SEUnit** mux_bWriteAddr_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteAddr_if_bCounterChanged1"); - objectCall3(mux_bWriteAddr_if_bCounterChanged1, Connect, 0, mux_bWriteAddr_if_bCounterChanged0, 0); - objectCall3(mux_bWriteAddr_if_bCounterChanged1, Connect, 1, wire_b32hf0000014, 0); - objectCall3(wire_bWriteAddr_if_bCounterChanged1, Connect, 0, mux_bWriteAddr_if_bCounterChanged1, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged1, Connect, 0, binop_or7654, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged1, Connect, 1, mux_bWriteAddr_if_bCounterChanged0, 3); + objectCall3(mux_bWriteAddr_if_bCounterChanged1, Connect, 2, const_b32hf0000014, 0); - IHDL4SEUnit** wire_bWriteData_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteData_if_bCounterChanged1"); IHDL4SEUnit** mux_bWriteData_if_bCounterChanged1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteData_if_bCounterChanged1"); - objectCall3(mux_bWriteData_if_bCounterChanged1, Connect, 0, mux_bWriteData_if_bCounterChanged0, 0); - objectCall3(mux_bWriteData_if_bCounterChanged1, Connect, 1, wire_b7654, 0); - objectCall3(wire_bWriteData_if_bCounterChanged1, Connect, 0, mux_bWriteData_if_bCounterChanged1, 2); + objectCall3(mux_bWriteData_if_bCounterChanged1, Connect, 0, binop_or7654, 2); + objectCall3(mux_bWriteData_if_bCounterChanged1, Connect, 1, mux_bWriteData_if_bCounterChanged0, 3); + objectCall3(mux_bWriteData_if_bCounterChanged1, Connect, 2, bind4_b7654, 0); - IHDL4SEUnit** wire_bWriteMask_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wire_bWriteMask_if_bCounterChanged2"); IHDL4SEUnit** mux_bWriteMask_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "4", "mux_bWriteMask_if_bCounterChanged2"); - objectCall3(mux_bWriteMask_if_bCounterChanged2, Connect, 0, mux_bWriteMask_if_bCounterChanged1, 0); - objectCall3(mux_bWriteMask_if_bCounterChanged2, Connect, 1, wire_b4b1100, 0); - objectCall3(wire_bWriteMask_if_bCounterChanged2, Connect, 0, mux_bWriteMask_if_bCounterChanged2, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged2, Connect, 0, binop_or98, 2); + objectCall3(mux_bWriteMask_if_bCounterChanged2, Connect, 1, mux_bWriteMask_if_bCounterChanged1, 3); + objectCall3(mux_bWriteMask_if_bCounterChanged2, Connect, 2, const_b4b1100, 0); - IHDL4SEUnit** wire_bWriteAddr_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteAddr_if_bCounterChanged2"); IHDL4SEUnit** mux_bWriteAddr_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteAddr_if_bCounterChanged2"); - objectCall3(mux_bWriteAddr_if_bCounterChanged2, Connect, 0, mux_bWriteAddr_if_bCounterChanged1, 0); - objectCall3(mux_bWriteAddr_if_bCounterChanged2, Connect, 1, wire_b32hf0000018, 0); - objectCall3(wire_bWriteAddr_if_bCounterChanged2, Connect, 0, mux_bWriteAddr_if_bCounterChanged2, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged2, Connect, 0, binop_or98, 2); + objectCall3(mux_bWriteAddr_if_bCounterChanged2, Connect, 1, mux_bWriteAddr_if_bCounterChanged1, 3); + objectCall3(mux_bWriteAddr_if_bCounterChanged2, Connect, 2, const_b32hf0000018, 0); - IHDL4SEUnit** wire_bWriteData_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteData_if_bCounterChanged2"); IHDL4SEUnit** mux_bWriteData_if_bCounterChanged2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteData_if_bCounterChanged2"); - objectCall3(mux_bWriteData_if_bCounterChanged2, Connect, 0, mux_bWriteData_if_bCounterChanged1, 0); - objectCall3(mux_bWriteData_if_bCounterChanged2, Connect, 1, wire_b0098, 0); - objectCall3(wire_bWriteData_if_bCounterChanged2, Connect, 0, mux_bWriteData_if_bCounterChanged2, 2); + objectCall3(mux_bWriteData_if_bCounterChanged2, Connect, 0, binop_or98, 2); + objectCall3(mux_bWriteData_if_bCounterChanged2, Connect, 1, mux_bWriteData_if_bCounterChanged1, 3); + objectCall3(mux_bWriteData_if_bCounterChanged2, Connect, 2, bind4_b0098, 0); - IHDL4SEUnit** wire_bWriteMask_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "4", "wire_bWriteMask_if_nwReset"); IHDL4SEUnit** mux_bWriteMask_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "4", "mux_bWriteMask_if_nwReset"); - objectCall3(mux_bWriteMask_if_nwReset, Connect, 0, mux_bWriteMask_if_bCounterChanged2, 0); - objectCall3(mux_bWriteMask_if_nwReset, Connect, 1, wire_b4b0000, 0); - objectCall3(wire_wirein_bWriteMask, Connect, 0, mux_bWriteMask_if_nwReset, 2); + objectCall3(mux_bWriteMask_if_nwReset, Connect, 0, unit_main, 0); + objectCall3(mux_bWriteMask_if_nwReset, Connect, 2, mux_bWriteMask_if_bCounterChanged2, 3); + objectCall3(mux_bWriteMask_if_nwReset, Connect, 1, const_b4b0000, 0); - IHDL4SEUnit** wire_bWriteAddr_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteAddr_if_nwReset"); IHDL4SEUnit** mux_bWriteAddr_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteAddr_if_nwReset"); - objectCall3(mux_bWriteAddr_if_nwReset, Connect, 0, mux_bWriteAddr_if_bCounterChanged2, 0); - objectCall3(mux_bWriteAddr_if_nwReset, Connect, 1, wire_b32b0, 0); - objectCall3(wire_wirein_bWriteAddr, Connect, 0, mux_bWriteAddr_if_nwReset, 2); + objectCall3(mux_bWriteAddr_if_nwReset, Connect, 0, unit_main, 0); + objectCall3(mux_bWriteAddr_if_nwReset, Connect, 2, mux_bWriteAddr_if_bCounterChanged2, 3); + objectCall3(mux_bWriteAddr_if_nwReset, Connect, 1, const_b32b0, 0); - IHDL4SEUnit** wire_bWriteData_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "32", "wire_bWriteData_if_nwReset"); IHDL4SEUnit** mux_bWriteData_if_nwReset = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX2, "32", "mux_bWriteData_if_nwReset"); - objectCall3(mux_bWriteData_if_nwReset, Connect, 0, mux_bWriteData_if_bCounterChanged2, 0); - objectCall3(mux_bWriteData_if_nwReset, Connect, 1, wire_b32b0, 0); - objectCall3(wire_wirein_bWriteData, Connect, 0, mux_bWriteData_if_nwReset, 2); - - IHDL4SEUnit** wire_or_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_WIRE, "1", "wire_or_bCounterChanged"); - sprintf(temp, "3, 1, %d", UNOP_OR); - IHDL4SEUnit** or_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_UNOP, temp, "or_bCounterChanged"); - objectCall3(or_bCounterChanged, Connect, 0, wire_wireout_bCounterChanged, 0); - objectCall3(wire_or_bCounterChanged, Connect, 0, or_bCounterChanged, 2); - - sprintf(temp, "1, 1, 1, %d", BINOP_AND); - IHDL4SEUnit** and_nwReset_bCounterChanged = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, temp, "or_bCounterChanged"); - objectCall3(and_nwReset_bCounterChanged, Connect, 0, wire_or_bCounterChanged, 0); - objectCall3(and_nwReset_bCounterChanged, Connect, 1, unit_main, 0); /*nwReset*/ - objectCall3(wire_wirein_wWrite, Connect, 0, and_nwReset_bCounterChanged, 2); + objectCall3(mux_bWriteData_if_nwReset, Connect, 0, unit_main, 0); + objectCall3(mux_bWriteData_if_nwReset, Connect, 2, mux_bWriteData_if_bCounterChanged2, 3); + objectCall3(mux_bWriteData_if_nwReset, Connect, 1, const_b32b0, 0); + objectCall3(reg_bWriteMask, Connect, 0, mux_bWriteMask_if_nwReset, 3); + objectCall3(reg_bWriteAddr, Connect, 0, mux_bWriteAddr_if_nwReset, 3); + objectCall3(reg_bWriteData, Connect, 0, mux_bWriteData_if_nwReset, 3); /*释放module接口*/ objectRelease(module_main); @@ -637,24 +445,72 @@ IHDL4SEUnit** hdl4seCreateMain2(IHDL4SEModule** parent, char* instanceparam, cha IHDL4SEUnit** const_bReadAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hF000_0000", "const_bReadAddr"); objectCall3(unit_main, Connect, 6, const_bReadAddr, 0); - IHDL4SEUnit** const_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hF000_0014", "const_bWriteAddr"); + IHDL4SEUnit** const_bWriteAddr = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'hF000_0010", "const_bWriteAddr"); objectCall3(unit_main, Connect, 2, const_bWriteAddr, 0); IHDL4SEUnit** reg_bReadData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "32", "mux_bRegData"); objectCall3(reg_bReadData, Connect, 0, module_main, 7); + IHDL4SEUnit** split_bReadData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_SPLIT4, "32, 3, 0, 3, 3, 3, 6, 3, 9", "split_bReadData"); + objectCall3(split_bReadData, Connect, 0, reg_bReadData, 0); + + IHDL4SEUnit** ne_bReadData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, "4, 4, 1, 5", "ne_bReadData"); + objectCall3(ne_bReadData, Connect, 0, reg_bReadData, 0); + objectCall3(ne_bReadData, Connect, 1, module_main, 7); IHDL4SEUnit** const_bWriteData0 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'b01001111_01011011_00000110_00111111", "const_bWriteData"); IHDL4SEUnit** const_bWriteData1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'b00000111_01111101_01101101_01100110", "const_bWriteData"); IHDL4SEUnit** const_bWriteData2 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'b01111001_01111001_01101111_01111111", "const_bWriteData"); IHDL4SEUnit** const_bWriteData3 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "32, 32'b00000111_01111001_01101101_01111001", "const_bWriteData"); IHDL4SEUnit** mux_bWriteData = hdl4seCreateUnit(module_main, CLSID_HDL4SE_MUX4, "32", "mux_bWriteData"); - objectCall3(mux_bWriteData, Connect, 0, reg_bReadData, 1); + objectCall3(mux_bWriteData, Connect, 0, split_bReadData, 2); objectCall3(mux_bWriteData, Connect, 1, const_bWriteData0, 0); objectCall3(mux_bWriteData, Connect, 2, const_bWriteData1, 0); objectCall3(mux_bWriteData, Connect, 3, const_bWriteData2, 0); objectCall3(mux_bWriteData, Connect, 4, const_bWriteData3, 0); - objectCall3(unit_main, Connect, 3, mux_bWriteData, 5); + //objectCall3(unit_main, Connect, 3, mux_bWriteData, 5); + + IHDL4SEUnit** dec2seg_0 = hdl4seCreateDec2seg(module_main, "", "dec2seg_0"); + IHDL4SEUnit** dec2seg_1 = hdl4seCreateDec2seg(module_main, "", "dec2seg_1"); + IHDL4SEUnit** dec2seg_2 = hdl4seCreateDec2seg(module_main, "", "dec2seg_2"); + IHDL4SEUnit** dec2seg_3 = hdl4seCreateDec2seg(module_main, "", "dec2seg_3"); + /* + objectCall3(dec2seg_0, Connect, 0, split_bReadData, 1); + objectCall3(dec2seg_1, Connect, 0, split_bReadData, 2); + objectCall3(dec2seg_2, Connect, 0, split_bReadData, 3); + objectCall3(dec2seg_3, Connect, 0, split_bReadData, 4); + */ + IHDL4SEUnit** bind4_dec2seg = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BIND4, "8, 8, 8, 8", "bind4_dec2seg"); + objectCall3(bind4_dec2seg, Connect, 0, dec2seg_3, 1); + objectCall3(bind4_dec2seg, Connect, 1, dec2seg_2, 1); + objectCall3(bind4_dec2seg, Connect, 2, dec2seg_1, 1); + objectCall3(bind4_dec2seg, Connect, 3, dec2seg_0, 1); + + IHDL4SEUnit** reg_counter = hdl4seCreateUnit(module_main, CLSID_HDL4SE_REG, "4", "reg_counter"); + IHDL4SEUnit** add_counter = hdl4seCreateUnit(module_main, CLSID_HDL4SE_BINOP, "4, 4, 4, 0", "add_counter"); + IHDL4SEUnit** const_1 = hdl4seCreateUnit(module_main, CLSID_HDL4SE_CONST, "1, 1", "const_1"); + IHDL4SEUnit** counter_0 = hdl4seCreateCounter(module_main, "4, 9, 0", "counter_0"); + IHDL4SEUnit** counter_1 = hdl4seCreateCounter(module_main, "4, 9, 0", "counter_1"); + IHDL4SEUnit** counter_2 = hdl4seCreateCounter(module_main, "4, 9, 0", "counter_2"); + IHDL4SEUnit** counter_3 = hdl4seCreateCounter(module_main, "4, 9, 0", "counter_3"); + + objectCall3(counter_0, Connect, 0, const_1, 0); + objectCall3(counter_0, Connect, 1, const_1/*ne_bReadData*/, 2); + objectCall3(dec2seg_0, Connect, 0, counter_0, 2); + + objectCall3(counter_1, Connect, 0, const_1, 0); + objectCall3(counter_1, Connect, 1, counter_0, 3); + objectCall3(dec2seg_1, Connect, 0, counter_1, 2); + + objectCall3(counter_2, Connect, 0, const_1, 0); + objectCall3(counter_2, Connect, 1, counter_1, 3); + objectCall3(dec2seg_2, Connect, 0, counter_2, 2); + + objectCall3(counter_3, Connect, 0, const_1, 0); + objectCall3(counter_3, Connect, 1, counter_2, 3); + objectCall3(dec2seg_3, Connect, 0, counter_3, 2); + + objectCall3(unit_main, Connect, 3, bind4_dec2seg, 4); /*释放module接口*/ objectRelease(module_main); diff --git a/examples/counter/src/main.c b/examples/counter/src/main.c index 4a752ccd1556a9dc8f780f0996a9d688301872b6..6c1035d6af7e0bf10adebd6ac02f49b44c81f0a2 100644 --- a/examples/counter/src/main.c +++ b/examples/counter/src/main.c @@ -58,7 +58,7 @@ int StopRunning() int main(int argc, char* argv[]) { sim = hdl4sesimCreateSimulator(); - topmodule = hdl4seCreateMain2(NULL, "", "main"); + topmodule = hdl4seCreateMain(NULL, "", "main"); gui = guiCreate(0xf0000000, "digitled"); objectCall1(sim, SetTopModule, topmodule); objectCall2(sim, AddDevice, gui, 0xf0000000); diff --git a/examples/digitled/src/digitled.c b/examples/digitled/src/digitled.c index 63012dbe970122fb25e71bbeda009594496e50d7..2bca989152c1300e3d006a63e4731c213b9b20ed 100644 --- a/examples/digitled/src/digitled.c +++ b/examples/digitled/src/digitled.c @@ -67,6 +67,7 @@ typedef struct _sDigitLed { GLFWwindow* window; int width; int height; + int count; unsigned int baseaddr; @@ -172,6 +173,7 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb pobj->width = WIDTH; pobj->height = HEIGHT; pobj->wRead = 0; + pobj->count = 0; pobj->wRead_cur = 0; pobj->window = glfwCreateWindow(WIDTH, HEIGHT, "DIGIT LED", NULL, NULL); if (!pobj->window) @@ -184,12 +186,6 @@ static int digitledCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pOb glfwSetWindowAspectRatio(pobj->window, 3, 1); glfwSetKeyCallback(pobj->window, key_callback); - /* - glfwSetFramebufferSizeCallback(window, reshape); - - glfwSetMouseButtonCallback(window, mouse_button_callback); - glfwSetCursorPosCallback(window, cursor_position_callback); - */ glfwMakeContextCurrent(pobj->window); gladLoadGL(glfwGetProcAddress); glfwSwapInterval(1); @@ -374,42 +370,44 @@ static int digitled_hdl4se_unit_ClkTick(HOBJECT object) #define LEDTHINY 0.04f #define LEDANGLEY 0.06f +#define LEDOFFS 0.00f + static int digitled_DrawDigit(sDigitLed* pobj, int ind) { - float xoffs = -0.9f + ind * (LEDWIDTH + LEDTHINX * 5); + float xoffs = -0.9f + (9-ind) * (LEDWIDTH + LEDTHINX * 5); float yoffs = -LEDHEIGHT / 2.0f + 0.2f; /* seg a */ glColor3f(pobj->ledcolor[ind][0][0], pobj->ledcolor[ind][0][1], pobj->ledcolor[ind][0][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs + LEDGAPX, yoffs + LEDHEIGHT); - glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); - glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); - glVertex2f(xoffs + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT); - glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); - glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); + glVertex2f(xoffs + LEDOFFS + LEDGAPX, yoffs + LEDHEIGHT); + glVertex2f(xoffs + LEDOFFS + LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT + LEDTHINY); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); + glVertex2f(xoffs + LEDOFFS + LEDANGLEX, yoffs + LEDHEIGHT - LEDTHINY); glEnd(); /* seg b */ glColor3f(pobj->ledcolor[ind][1][0], pobj->ledcolor[ind][1][1], pobj->ledcolor[ind][1][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT - LEDGAPY); - glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); - glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); - glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); - glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); - glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH, yoffs + LEDHEIGHT - LEDGAPY); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); + glVertex2f(xoffs + LEDOFFS + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glEnd(); /* seg c */ glColor3f(pobj->ledcolor[ind][2][0], pobj->ledcolor[ind][2][1], pobj->ledcolor[ind][2][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); - glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDWIDTH + LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs + LEDWIDTH, yoffs + LEDGAPY); glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDANGLEY); - glVertex2f(xoffs + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glEnd(); /* seg d */ @@ -426,34 +424,34 @@ static int digitled_DrawDigit(sDigitLed* pobj, int ind) /* seg e */ glColor3f(pobj->ledcolor[ind][4][0], pobj->ledcolor[ind][4][1], pobj->ledcolor[ind][4][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); - glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f, yoffs + LEDHEIGHT / 2.0f - LEDGAPY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glVertex2f(xoffs + LEDTHINX, yoffs + LEDANGLEY); glVertex2f(xoffs, yoffs + LEDGAPY); glVertex2f(xoffs - LEDTHINX, yoffs + LEDANGLEY); - glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f - LEDTHINX, yoffs + LEDHEIGHT / 2.0f - LEDANGLEY); glEnd(); /* seg f */ glColor3f(pobj->ledcolor[ind][5][0], pobj->ledcolor[ind][5][1], pobj->ledcolor[ind][5][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs, yoffs + LEDHEIGHT - LEDGAPY); - glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); - glVertex2f(xoffs + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); - glVertex2f(xoffs, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); - glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); - glVertex2f(xoffs - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS, yoffs + LEDHEIGHT - LEDGAPY); + glVertex2f(xoffs + LEDOFFS + LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); + glVertex2f(xoffs + LEDOFFS / 2.0f, yoffs + LEDHEIGHT / 2.0f + LEDGAPY); + glVertex2f(xoffs + LEDOFFS / 2.0f - LEDTHINX, yoffs + LEDHEIGHT / 2.0f + LEDANGLEY); + glVertex2f(xoffs + LEDOFFS - LEDTHINX, yoffs + LEDHEIGHT - LEDANGLEY); glEnd(); /* seg g */ glColor3f(pobj->ledcolor[ind][6][0], pobj->ledcolor[ind][6][1], pobj->ledcolor[ind][6][2]); glBegin(GL_TRIANGLE_FAN); - glVertex2f(xoffs + LEDGAPX, yoffs + LEDHEIGHT / 2.0f); - glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); - glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); - glVertex2f(xoffs + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT / 2.0f); - glVertex2f(xoffs + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); - glVertex2f(xoffs + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDGAPX, yoffs + LEDHEIGHT / 2.0f); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f + LEDTHINY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDGAPX, yoffs + LEDHEIGHT / 2.0f); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDWIDTH - LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); + glVertex2f(xoffs + LEDOFFS / 2.0f + LEDANGLEX, yoffs + LEDHEIGHT / 2.0f - LEDTHINY); glEnd(); /* seg dp */ @@ -509,9 +507,13 @@ static int digitled_hdl4se_unit_Setup(HOBJECT object) /*读信号和读地址寄存一拍*/ pobj->wRead = pobj->wRead_cur; pobj->bReadAddr = pobj->bReadAddr_cur; - if (digitled_Render(pobj)) { - /* Swap buffers */ - glfwSwapBuffers(pobj->window); + pobj->count++; + /* 每256个周期新绘制一次 */ + if ((pobj->count & 0xff) == 0) { + if (digitled_Render(pobj)) { + /* Swap buffers */ + glfwSwapBuffers(pobj->window); + } } glfwPollEvents(); diff --git a/hdl4secell/CMakeLists.txt b/hdl4secell/CMakeLists.txt index c8a006f4d7b42de6ab13f40e683f92e4bdd7ca6a..0084b1a65f227a6c12185e76979f2aab01f5803b 100644 --- a/hdl4secell/CMakeLists.txt +++ b/hdl4secell/CMakeLists.txt @@ -16,7 +16,7 @@ add_library (hdl4secell STATIC "src/hdl4se_reg.c" "src/hdl4se_bind2.c" "src/hdl4se_bind3.c" - "src/hdl4se_bind4.c") + "src/hdl4se_bind4.c" "src/hdl4se_split2.c" "src/hdl4se_split4.c" "src/hdl4se_unop.c" "src/hdl4se_binop.c") include_directories("../../lcom/include") include_directories("../hdl4secell/include") diff --git a/hdl4secell/include/hdl4secell.h b/hdl4secell/include/hdl4secell.h index 7ebe57ba895febc0f5b9029faed110717f7f1eb0..f126e274d8013ace9fd513601306e93f28ca7c54 100644 --- a/hdl4secell/include/hdl4secell.h +++ b/hdl4secell/include/hdl4secell.h @@ -121,7 +121,7 @@ DEFINE_GUID(CLSID_HDL4SE_CONST, 0x8FBE5B87, 0xB484, 0x4f95, 0x82, 0x91, 0xDB, 0x #define BINOP_MUL 2 #define BINOP_DIV 3 #define BINOP_EQ 4 -#define BINOP_NEQ 5 +#define BINOP_NE 5 #define BINOP_LT 6 #define BINOP_LE 7 #define BINOP_GE 8 diff --git a/hdl4secell/src/hdl4se_bind4.c b/hdl4secell/src/hdl4se_bind4.c index ba475f7b4fa39835795c9e677465a2c5136e37bc..dd2c6e853b2bfb98f11cf124836410114c40e851 100644 --- a/hdl4secell/src/hdl4se_bind4.c +++ b/hdl4secell/src/hdl4se_bind4.c @@ -44,7 +44,7 @@ /* HDL4SE_BIND4 -instance parameter: "8, 9, 10", inputwidth0=8, inputwidth1=9, inputwidth2=10 +instance parameter: "8, 9, 10, 11", inputwidth0=8, inputwidth1=9, inputwidth2=10 outputwidth=8+9+10 */ diff --git a/hdl4secell/src/hdl4se_binop.c b/hdl4secell/src/hdl4se_binop.c new file mode 100644 index 0000000000000000000000000000000000000000..7de99725c897b60776fe8d65a57d5b0e75344645 --- /dev/null +++ b/hdl4secell/src/hdl4se_binop.c @@ -0,0 +1,317 @@ +/* +** HDL4SE: 软件Verilog综合仿真平台 +** Copyright (C) 2021-2021, raoxianhong +** LCOM: 轻量级组件对象模型 +** Copyright (C) 2021-2021, raoxianhong +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** +** * Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** * The name of the author may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +** THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +* hdl4se_binop.c + 修改记录: + 202105230844: rxh, initial version +*/ +#include "stdlib.h" +#include "stdio.h" +#include "object.h" +#include "dlist.h" +#include "bignumber.h" +#include "hdl4secell.h" + +/* +#define BINOP_ADD 0 +#define BINOP_SUB 1 +#define BINOP_MUL 2 +#define BINOP_DIV 3 +#define BINOP_EQ 4 +#define BINOP_NE 5 +#define BINOP_LT 6 +#define BINOP_LE 7 +#define BINOP_GE 8 +#define BINOP_GT 9 +#define BINOP_AND 10 +#define BINOP_OR 11 +#define BINOP_XOR 12 +*/ +#define BINOP_LAST BINOP_XOR +#define INCOUNT 2 +/* +hdl4se_binop +instance parameter: "8, 9, 1, 4", +inputwidth0=8, inputwidth1=9, outputwidth=1, unop=BINOP_EQ +*/ +typedef struct _sHDL4SEBinop { + OBJECT_HEADER + INTERFACE_DECLARE(IHDL4SEUnit) + HDL4SEUNIT_VARDECLARE + DLIST_VARDECLARE + + IHDL4SEModule** parent; + char* name; + + IHDL4SEUnit** wire_in[INCOUNT]; + int wire_in_index[INCOUNT]; + int in_width[INCOUNT]; + IBigNumber** in_data[INCOUNT]; + + IBigNumber** out_data; + int out_width; + int op; + int datavalid; +}sHDL4SEBinop; + +OBJECT_FUNCDECLARE(hdl4se_binop, CLSID_HDL4SE_BINOP); +HDL4SEUNIT_FUNCDECLARE(hdl4se_binop, CLSID_HDL4SE_BINOP, sHDL4SEBinop); +DLIST_FUNCIMPL(hdl4se_binop, CLSID_HDL4SE_BINOP, sHDL4SEBinop); + +OBJECT_FUNCIMPL(hdl4se_binop, sHDL4SEBinop, CLSID_HDL4SE_BINOP); + + +QUERYINTERFACE_BEGIN(hdl4se_binop, CLSID_HDL4SE_BINOP) +QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SEBinop) +QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SEBinop) +QUERYINTERFACE_END + +static const char* hdl4se_binopModuleInfo() +{ + return "1.0.0-20210523.0844 HDL4SE BINOP cell"; +} + +static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject) +{ + sHDL4SEBinop* pobj; + int i; + pobj = (sHDL4SEBinop*)malloc(sizeof(sHDL4SEBinop)); + if (pobj == NULL) + return -1; + *pObject = 0; + HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_BINOP); + INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_binop, hdl4se_unit); + DLIST_VARINIT(pobj, hdl4se_binop); + + for (i = 0; i < INCOUNT; i++) { + pobj->wire_in[i] = NULL; + pobj->wire_in_index[i] = 0; + pobj->in_data[i] = NULL; + pobj->in_width[i] = 0; + } + + pobj->out_data = NULL; + + pobj->name = NULL; + pobj->out_width = 0; + pobj->datavalid = 0; + pobj->op = -1; + pobj->parent = NULL; + + for (i = 0; i < paramcount; i++) { + if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) { + if (pobj->name != NULL) + free(pobj->name); + pobj->name = strdup(pParams[i].pvalue); + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) { + pobj->parent = (IHDL4SEModule **)pParams[i].pvalue; + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) { + IBigNumber** temp = bigintegerCreate(32); + if (temp != NULL) { + const char* nstr; + const char* lstr; + int j; + lstr = (const char*)pParams[i].pvalue; + for (j = 0; j < INCOUNT; j++) { + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->in_width[j]); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + } + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_width); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->op); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + objectRelease(temp); + } + } + } + for (i = 0; i < INCOUNT; i++) { + if (pobj->in_width[i] <= 0) + return EIID_INVALIDPARAM; + pobj->in_data[i] = bigintegerCreate(pobj->in_width[i]); + } + if (pobj->out_width <= 0) + return EIID_INVALIDPARAM; + if (pobj->op < UNOP_NEG || pobj->op > BINOP_LAST) + return EIID_INVALIDPARAM; + + pobj->out_data = bigintegerCreate(pobj->out_width); + + /* 返回生成的对象 */ + OBJECT_RETURN_GEN(hdl4se_binop, pobj, pObject, CLSID_HDL4SE_BINOP); + return EIID_OK; +} + +static void hdl4se_binopDestroy(HOBJECT object) +{ + sHDL4SEBinop* pobj; + int i; + pobj = (sHDL4SEBinop*)objectThis(object); + if (pobj->name != NULL) + free(pobj->name); + for (i = 0; i < INCOUNT; i++) { + objectRelease(pobj->wire_in[i]); + objectRelease(pobj->in_data[i]); + } + objectRelease(pobj->out_data); + memset(pobj, 0, sizeof(sHDL4SEBinop)); + free(pobj); +} + +static int hdl4se_binopValid(HOBJECT object) +{ + sHDL4SEBinop* pobj; + pobj = (sHDL4SEBinop*)objectThis(object); + return 1; +} + +static int hdl4se_binop_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex) +{ + sHDL4SEBinop* pobj; + IHDL4SEUnit** unit = NULL; + pobj = (sHDL4SEBinop*)objectThis(object); + if (index >= 0 && index < INCOUNT) { + if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { + objectRelease(pobj->wire_in[index]); + pobj->wire_in[index] = unit; + pobj->wire_in_index[index] = fromindex; + return 0; + } + } + return -1; +} + +static int hdl4se_binop_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber ** value) +{ + int i; + sHDL4SEBinop* pobj; + pobj = (sHDL4SEBinop*)objectThis(object); + if (pobj->datavalid == 0) { + for (i = 0; i < INCOUNT; i++) + objectCall3(pobj->wire_in[i], GetValue, pobj->wire_in_index[i], pobj->in_width[i], pobj->in_data[i]); + switch (pobj->op) { + case BINOP_ADD: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Add, pobj->in_data[1]); + break; + case BINOP_SUB: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Sub, pobj->in_data[1]); + break; + case BINOP_MUL: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Mul, pobj->in_data[1]); + break; + case BINOP_DIV: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Div, pobj->in_data[1]); + break; + case BINOP_EQ: + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 1); + break; + case BINOP_NE: + objectCall1(pobj->out_data, AssignInt, 1); + if (objectCall1(pobj->in_data[0], IsEQ, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 0); + break; + case BINOP_LT: + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 1); + break; + case BINOP_LE: + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 1); + break; + case BINOP_GE: + objectCall1(pobj->out_data, AssignInt, 1); + if (objectCall1(pobj->in_data[0], IsLT, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 0); + break; + case BINOP_GT: + objectCall1(pobj->out_data, AssignInt, 1); + if (objectCall1(pobj->in_data[0], IsLE, pobj->in_data[1])) + objectCall1(pobj->out_data, AssignInt, 0); + break; + case BINOP_AND: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, And, pobj->in_data[1]); + break; + case BINOP_OR: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Or, pobj->in_data[1]); + break; + case BINOP_XOR: + objectCall1(pobj->out_data, Assign, pobj->in_data[0]); + objectCall1(pobj->out_data, Xor, pobj->in_data[1]); + break; + } + pobj->datavalid = 1; + } + objectCall1(value, Assign, pobj->out_data); + return 0; +} + +static int hdl4se_binop_hdl4se_unit_ClkTick(HOBJECT object) +{ + sHDL4SEBinop* pobj; + pobj = (sHDL4SEBinop*)objectThis(object); + return 0; +} + +static int hdl4se_binop_hdl4se_unit_Setup(HOBJECT object) +{ + sHDL4SEBinop* pobj; + pobj = (sHDL4SEBinop*)objectThis(object); + pobj->datavalid = 0; + return 0; +} + diff --git a/hdl4secell/src/hdl4se_const.c b/hdl4secell/src/hdl4se_const.c index bfb7cd222e2f0084fb7c1ccf6b307ace5462f29f..4a9cc3d0ad1c804546e505faf139e19af1f97b26 100644 --- a/hdl4secell/src/hdl4se_const.c +++ b/hdl4secell/src/hdl4se_const.c @@ -88,7 +88,7 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pobj->out_data = NULL; pobj->name = NULL; - pobj->width = 8; + pobj->width = 0; pobj->parent = NULL; for (i = 0; i < paramcount; i++) { @@ -109,13 +109,15 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* } if (pobj->width <= 0 || pobj->width > (1 << 24)) return -1; - objectCall2(temp, AssignStr, nstr, NULL); - pobj->out_data = temp; + pobj->out_data = bigintegerCreate(pobj->width); + objectCall2(pobj->out_data, AssignStr, nstr, NULL); + objectRelease(temp); } } } + if (pobj->out_data == NULL) { - pobj->out_data = bigintegerCreate(pobj->width); + return NULL; } /* 返回生成的对象 */ diff --git a/hdl4secell/src/hdl4se_mux16.c b/hdl4secell/src/hdl4se_mux16.c index 645d0a154bb0fcb4259da31e5fed3464f6d13f90..94977e15521f52e9d11a2dce057a452029cfb89e 100644 --- a/hdl4secell/src/hdl4se_mux16.c +++ b/hdl4secell/src/hdl4se_mux16.c @@ -207,8 +207,10 @@ static int hdl4se_mux16_hdl4se_unit_GetValue(HOBJECT object, int index, int widt sHDL4SEMux16* pobj; pobj = (sHDL4SEMux16*)objectThis(object); if (pobj->datavalid == 0) { - objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); + objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel); + objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0); objectCall1(pobj->in_sel, GetInt, &sel); + sel &= MUXCOUNT - 1; if (sel >= 0 && sel < MUXCOUNT) { objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); } diff --git a/hdl4secell/src/hdl4se_mux2.c b/hdl4secell/src/hdl4se_mux2.c index efc9622b5c292ec8f7acbeccb7c1f6c17f6e96e1..1df33aafc01a001200da116717427010852f3e1b 100644 --- a/hdl4secell/src/hdl4se_mux2.c +++ b/hdl4secell/src/hdl4se_mux2.c @@ -210,8 +210,10 @@ static int hdl4se_mux2_hdl4se_unit_GetValue(HOBJECT object, int index, int width pobj = (sHDL4SEMux2*)objectThis(object); if (pobj->datavalid == 0) { - objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); + objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel); + objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0); objectCall1(pobj->in_sel, GetInt, &sel); + sel &= MUXCOUNT - 1; if (sel >= 0 && sel < MUXCOUNT) { objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); } diff --git a/hdl4secell/src/hdl4se_mux4.c b/hdl4secell/src/hdl4se_mux4.c index e15795a5ac32fdd9ba100bccd95ac76ffdfebd11..ed8239886613db236a7e49a20c1131cb3115a3be 100644 --- a/hdl4secell/src/hdl4se_mux4.c +++ b/hdl4secell/src/hdl4se_mux4.c @@ -207,8 +207,10 @@ static int hdl4se_mux4_hdl4se_unit_GetValue(HOBJECT object, int index, int width sHDL4SEMux4* pobj; pobj = (sHDL4SEMux4*)objectThis(object); if (pobj->datavalid == 0) { - objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); + objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel); + objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0); objectCall1(pobj->in_sel, GetInt, &sel); + sel &= MUXCOUNT - 1; if (sel >= 0 && sel < MUXCOUNT) { objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); } diff --git a/hdl4secell/src/hdl4se_mux8.c b/hdl4secell/src/hdl4se_mux8.c index a1b8461701bd2802519a906674be1a51df47f614..97dc46cf2d109027756752bf80575e4fd01d5eee 100644 --- a/hdl4secell/src/hdl4se_mux8.c +++ b/hdl4secell/src/hdl4se_mux8.c @@ -207,8 +207,10 @@ static int hdl4se_mux8_hdl4se_unit_GetValue(HOBJECT object, int index, int width sHDL4SEMux8* pobj; pobj = (sHDL4SEMux8*)objectThis(object); if (pobj->datavalid == 0) { - objectCall3(pobj->sel, GetValue, pobj->sel_index, 1, pobj->in_sel); + objectCall3(pobj->sel, GetValue, pobj->sel_index, MUXSELW, pobj->in_sel); objectCall1(pobj->in_sel, GetInt, &sel); + objectCall2(pobj->in_sel, SetWidth, MUXSELW, 0); + sel &= MUXCOUNT - 1; if (sel >= 0 && sel < MUXCOUNT) { objectCall3(pobj->in[sel], GetValue, pobj->in_index[sel], pobj->width, pobj->out_data); } diff --git a/hdl4secell/src/hdl4se_reg.c b/hdl4secell/src/hdl4se_reg.c index 8a09049d1e404649aafe19e4da3e018deb7a4455..78f25e154ecb7f9cf707d3a5030e820cee622cc5 100644 --- a/hdl4secell/src/hdl4se_reg.c +++ b/hdl4secell/src/hdl4se_reg.c @@ -158,6 +158,7 @@ static int hdl4se_reg_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT fro IHDL4SEUnit** unit = NULL; pobj = (sHDL4SEReg*)objectThis(object); if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { + objectRelease(pobj->wire_in); pobj->wire_in = unit; pobj->wire_in_index = fromindex; return 0; diff --git a/hdl4secell/src/hdl4se_split2.c b/hdl4secell/src/hdl4se_split2.c new file mode 100644 index 0000000000000000000000000000000000000000..f54edabf8078ee4f31f540de40aac9e09190f6fc --- /dev/null +++ b/hdl4secell/src/hdl4se_split2.c @@ -0,0 +1,257 @@ +/* +** HDL4SE: 软件Verilog综合仿真平台 +** Copyright (C) 2021-2021, raoxianhong +** LCOM: 轻量级组件对象模型 +** Copyright (C) 2021-2021, raoxianhong +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** +** * Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** * The name of the author may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +** THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +* hdl4se_split2.c + 修改记录: + 202105230810: rxh, initial version +*/ +#include "stdlib.h" +#include "stdio.h" +#include "object.h" +#include "dlist.h" +#include "bignumber.h" +#include "hdl4secell.h" + + +/* +HDL4SE_SPLIT2 +instance parameter: "32, 8, 4, 19, 9", + inputwidth=32 + outputwidth0=8 + outputfrom0=4 + outputwidth1=19 + outputfrom1=9 +*/ + +#define SPLITCOUNT 2 + +typedef struct _sHDL4SESplit2 { + OBJECT_HEADER + INTERFACE_DECLARE(IHDL4SEUnit) + HDL4SEUNIT_VARDECLARE + DLIST_VARDECLARE + + IHDL4SEModule** parent; + char* name; + + IHDL4SEUnit** in; + int in_index; + + IBigNumber** in_data; + IBigNumber** out_data[SPLITCOUNT]; + int out_info[SPLITCOUNT][2]; + + int datavalid; + int width; +}sHDL4SESplit2; + +OBJECT_FUNCDECLARE(hdl4se_split2, CLSID_HDL4SE_SPLIT2); +HDL4SEUNIT_FUNCDECLARE(hdl4se_split2, CLSID_HDL4SE_SPLIT2, sHDL4SESplit2); +DLIST_FUNCIMPL(hdl4se_split2, CLSID_HDL4SE_SPLIT2, sHDL4SESplit2); + +OBJECT_FUNCIMPL(hdl4se_split2, sHDL4SESplit2, CLSID_HDL4SE_SPLIT2); + + +QUERYINTERFACE_BEGIN(hdl4se_split2, CLSID_HDL4SE_SPLIT2) +QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SESplit2) +QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SESplit2) +QUERYINTERFACE_END + +static const char* hdl4se_split2ModuleInfo() +{ + return "1.0.0-20210523.0810 HDL4SE Split2 cell"; +} + +static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject) +{ + sHDL4SESplit2* pobj; + int i; + pobj = (sHDL4SESplit2*)malloc(sizeof(sHDL4SESplit2)); + if (pobj == NULL) + return -1; + *pObject = 0; + HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_SPLIT2); + INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_split2, hdl4se_unit); + DLIST_VARINIT(pobj, hdl4se_split2); + + pobj->datavalid = 0; + for (i = 0; i < SPLITCOUNT; i++) { + pobj->out_data[i] = NULL; + pobj->out_info[i][0] = 0; + pobj->out_info[i][1] = 0; + } + pobj->in = NULL; + pobj->in_data = NULL; + + + pobj->name = NULL; + pobj->width = 8; + pobj->parent = NULL; + + for (i = 0; i < paramcount; i++) { + if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) { + if (pobj->name != NULL) + free(pobj->name); + pobj->name = strdup(pParams[i].pvalue); + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) { + pobj->parent = (IHDL4SEModule **)pParams[i].pvalue; + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) { + IBigNumber** temp = bigintegerCreate(32); + if (temp != NULL) { + const char* nstr; + const char* lstr; + int j; + lstr = (const char*)pParams[i].pvalue; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->width); + } + else { + return -1; + } + lstr = nstr; + for (j = 0; j < SPLITCOUNT; j++) { + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_info[j][0]); + } + else { + return -1; + } + lstr = nstr; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_info[j][1]); + } + else { + return -1; + } + lstr = nstr; + } + objectRelease(temp); + } + } + } + + if (pobj->width <= 0) + return EIID_INVALIDPARAM; + for (i = 0; i < SPLITCOUNT; i++) { + if (pobj->out_info[i][0] <= 0) + return EIID_INVALIDPARAM; + if (pobj->out_info[i][0] + pobj->out_info[i][1] > pobj->width) + return EIID_INVALIDPARAM; + pobj->out_data[i] = bigintegerCreate(pobj->out_info[i][0]); + } + pobj->in_data = bigintegerCreate(pobj->width); + + /* 返回生成的对象 */ + OBJECT_RETURN_GEN(hdl4se_split2, pobj, pObject, CLSID_HDL4SE_SPLIT2); + return EIID_OK; +} + +static void hdl4se_split2Destroy(HOBJECT object) +{ + sHDL4SESplit2* pobj; + int i; + pobj = (sHDL4SESplit2*)objectThis(object); + if (pobj->name != NULL) + free(pobj->name); + for (i = 0; i < SPLITCOUNT; i++) { + objectRelease(pobj->out_data[i]); + } + objectRelease(pobj->in); + objectRelease(pobj->in_data); + memset(pobj, 0, sizeof(sHDL4SESplit2)); + free(pobj); +} + +static int hdl4se_split2Valid(HOBJECT object) +{ + sHDL4SESplit2* pobj; + pobj = (sHDL4SESplit2*)objectThis(object); + return 1; +} + +static int hdl4se_split2_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex) +{ + sHDL4SESplit2* pobj; + IHDL4SEUnit** unit = NULL; + pobj = (sHDL4SESplit2*)objectThis(object); + if (index == 0) { + if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { + objectRelease(pobj->in); + pobj->in = unit; + pobj->in_index = fromindex; + } + else { + return -2; + } + } + else { + return -1; + } + return 0; +} + +static int hdl4se_split2_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber** value) +{ + int i; + sHDL4SESplit2* pobj; + pobj = (sHDL4SESplit2*)objectThis(object); + if (index < 1 || index > SPLITCOUNT) + return -1; + if (pobj->datavalid == 0) { + objectCall3(pobj->in, GetValue, pobj->in_index, pobj->width, pobj->in_data); + pobj->datavalid = 1; + for (i = 0; i < SPLITCOUNT; i++) { + objectCall3(pobj->out_data[i], AssignSub, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]); + } + pobj->datavalid = 1; + } + objectCall1(value, Assign, pobj->out_data[index-1]); + return 0; +} + +static int hdl4se_split2_hdl4se_unit_ClkTick(HOBJECT object) +{ + sHDL4SESplit2* pobj; + pobj = (sHDL4SESplit2*)objectThis(object); + return 0; +} + +static int hdl4se_split2_hdl4se_unit_Setup(HOBJECT object) +{ + sHDL4SESplit2* pobj; + pobj = (sHDL4SESplit2*)objectThis(object); + pobj->datavalid = 0; + return 0; +} + diff --git a/hdl4secell/src/hdl4se_split4.c b/hdl4secell/src/hdl4se_split4.c new file mode 100644 index 0000000000000000000000000000000000000000..00fb92c63ec8675f5e014841489b6928ecd60883 --- /dev/null +++ b/hdl4secell/src/hdl4se_split4.c @@ -0,0 +1,261 @@ +/* +** HDL4SE: 软件Verilog综合仿真平台 +** Copyright (C) 2021-2021, raoxianhong +** LCOM: 轻量级组件对象模型 +** Copyright (C) 2021-2021, raoxianhong +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** +** * Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** * The name of the author may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +** THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +* hdl4se_split4.c + 修改记录: + 202105230810: rxh, initial version +*/ +#include "stdlib.h" +#include "stdio.h" +#include "object.h" +#include "dlist.h" +#include "bignumber.h" +#include "hdl4secell.h" + + +/* +HDL4SE_SPLIT4 +instance parameter: "32, 8, 4, 19, 9, 7, 3, 11, 1", + inputwidth=32 + outputwidth0=8 + outputfrom0=4 + outputwidth1=19 + outputfrom1=9 + outputwidth2=7 + outputfrom2=3 + outputwidth3=11 + outputfrom3=1 +*/ + +#define SPLITCOUNT 4 + +typedef struct _sHDL4SESplit4 { + OBJECT_HEADER + INTERFACE_DECLARE(IHDL4SEUnit) + HDL4SEUNIT_VARDECLARE + DLIST_VARDECLARE + + IHDL4SEModule** parent; + char* name; + + IHDL4SEUnit** in; + int in_index; + + IBigNumber** in_data; + IBigNumber** out_data[SPLITCOUNT]; + int out_info[SPLITCOUNT][2]; + + int datavalid; + int width; +}sHDL4SESplit4; + +OBJECT_FUNCDECLARE(hdl4se_split4, CLSID_HDL4SE_SPLIT4); +HDL4SEUNIT_FUNCDECLARE(hdl4se_split4, CLSID_HDL4SE_SPLIT4, sHDL4SESplit4); +DLIST_FUNCIMPL(hdl4se_split4, CLSID_HDL4SE_SPLIT4, sHDL4SESplit4); + +OBJECT_FUNCIMPL(hdl4se_split4, sHDL4SESplit4, CLSID_HDL4SE_SPLIT4); + + +QUERYINTERFACE_BEGIN(hdl4se_split4, CLSID_HDL4SE_SPLIT4) +QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SESplit4) +QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SESplit4) +QUERYINTERFACE_END + +static const char* hdl4se_split4ModuleInfo() +{ + return "1.0.0-20210523.0811 HDL4SE Split4 cell"; +} + +static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject) +{ + sHDL4SESplit4* pobj; + int i; + pobj = (sHDL4SESplit4*)malloc(sizeof(sHDL4SESplit4)); + if (pobj == NULL) + return -1; + *pObject = 0; + HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_SPLIT4); + INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_split4, hdl4se_unit); + DLIST_VARINIT(pobj, hdl4se_split4); + + pobj->datavalid = 0; + for (i = 0; i < SPLITCOUNT; i++) { + pobj->out_data[i] = NULL; + pobj->out_info[i][0] = 0; + pobj->out_info[i][1] = 0; + } + pobj->in = NULL; + pobj->in_data = NULL; + + + pobj->name = NULL; + pobj->width = 8; + pobj->parent = NULL; + + for (i = 0; i < paramcount; i++) { + if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) { + if (pobj->name != NULL) + free(pobj->name); + pobj->name = strdup(pParams[i].pvalue); + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) { + pobj->parent = (IHDL4SEModule **)pParams[i].pvalue; + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) { + IBigNumber** temp = bigintegerCreate(32); + if (temp != NULL) { + const char* nstr; + const char* lstr; + int j; + lstr = (const char*)pParams[i].pvalue; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->width); + } + else { + return -1; + } + lstr = nstr; + for (j = 0; j < SPLITCOUNT; j++) { + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_info[j][0]); + } + else { + return -1; + } + lstr = nstr; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_info[j][1]); + } + else { + return -1; + } + lstr = nstr; + } + objectRelease(temp); + } + } + } + + if (pobj->width <= 0) + return EIID_INVALIDPARAM; + for (i = 0; i < SPLITCOUNT; i++) { + if (pobj->out_info[i][0] <= 0) + return EIID_INVALIDPARAM; + if (pobj->out_info[i][0] + pobj->out_info[i][1] > pobj->width) + return EIID_INVALIDPARAM; + pobj->out_data[i] = bigintegerCreate(pobj->out_info[i][0]); + } + pobj->in_data = bigintegerCreate(pobj->width); + + /* 返回生成的对象 */ + OBJECT_RETURN_GEN(hdl4se_split4, pobj, pObject, CLSID_HDL4SE_SPLIT4); + return EIID_OK; +} + +static void hdl4se_split4Destroy(HOBJECT object) +{ + sHDL4SESplit4* pobj; + int i; + pobj = (sHDL4SESplit4*)objectThis(object); + if (pobj->name != NULL) + free(pobj->name); + for (i = 0; i < SPLITCOUNT; i++) { + objectRelease(pobj->out_data[i]); + } + objectRelease(pobj->in); + objectRelease(pobj->in_data); + memset(pobj, 0, sizeof(sHDL4SESplit4)); + free(pobj); +} + +static int hdl4se_split4Valid(HOBJECT object) +{ + sHDL4SESplit4* pobj; + pobj = (sHDL4SESplit4*)objectThis(object); + return 1; +} + +static int hdl4se_split4_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex) +{ + sHDL4SESplit4* pobj; + IHDL4SEUnit** unit = NULL; + pobj = (sHDL4SESplit4*)objectThis(object); + if (index == 0) { + if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { + objectRelease(pobj->in); + pobj->in = unit; + pobj->in_index = fromindex; + } + else { + return -2; + } + } + else { + return -1; + } + return 0; +} + +static int hdl4se_split4_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber** value) +{ + int i; + sHDL4SESplit4* pobj; + pobj = (sHDL4SESplit4*)objectThis(object); + if (index < 1 || index > SPLITCOUNT) + return -1; + if (pobj->datavalid == 0) { + objectCall3(pobj->in, GetValue, pobj->in_index, pobj->width, pobj->in_data); + pobj->datavalid = 1; + for (i = 0; i < SPLITCOUNT; i++) { + objectCall3(pobj->out_data[i], AssignSub, pobj->in_data, pobj->out_info[i][1], pobj->out_info[i][0]); + } + pobj->datavalid = 1; + } + objectCall1(value, Assign, pobj->out_data[index-1]); + return 0; +} + +static int hdl4se_split4_hdl4se_unit_ClkTick(HOBJECT object) +{ + sHDL4SESplit4* pobj; + pobj = (sHDL4SESplit4*)objectThis(object); + return 0; +} + +static int hdl4se_split4_hdl4se_unit_Setup(HOBJECT object) +{ + sHDL4SESplit4* pobj; + pobj = (sHDL4SESplit4*)objectThis(object); + pobj->datavalid = 0; + return 0; +} + diff --git a/hdl4secell/src/hdl4se_unop.c b/hdl4secell/src/hdl4se_unop.c new file mode 100644 index 0000000000000000000000000000000000000000..a38618f73b21372123ec09fc49c08dbf2f11a2dc --- /dev/null +++ b/hdl4secell/src/hdl4se_unop.c @@ -0,0 +1,266 @@ +/* +** HDL4SE: 软件Verilog综合仿真平台 +** Copyright (C) 2021-2021, raoxianhong +** LCOM: 轻量级组件对象模型 +** Copyright (C) 2021-2021, raoxianhong +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** +** * Redistributions of source code must retain the above copyright notice, +** this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright notice, +** this list of conditions and the following disclaimer in the documentation +** and/or other materials provided with the distribution. +** * The name of the author may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +** THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* +* hdl4se_unop.c + 修改记录: + 202105230816: rxh, initial version +*/ +#include "stdlib.h" +#include "stdio.h" +#include "object.h" +#include "dlist.h" +#include "bignumber.h" +#include "hdl4secell.h" + +/* +#define UNOP_NEG 0 +#define UNOP_NOT 1 +#define UNOP_AND 2 +#define UNOP_OR 3 +#define UNOP_XOR 4 +*/ +#define UNOP_LAST UNOP_XOR +/* +HDL4SE_UNOP +instance parameter: "8, 1, 2", +inputwidth=8, outputwidth=1, unop=UNOP_AND +*/ +typedef struct _sHDL4SEUnop { + OBJECT_HEADER + INTERFACE_DECLARE(IHDL4SEUnit) + HDL4SEUNIT_VARDECLARE + DLIST_VARDECLARE + + IHDL4SEModule** parent; + char* name; + + IHDL4SEUnit** wire_in; + int wire_in_index; + int in_width; + + IBigNumber** in_data; + IBigNumber** out_data; + int out_width; + int op; + int datavalid; +}sHDL4SEUnop; + +OBJECT_FUNCDECLARE(hdl4se_unop, CLSID_HDL4SE_UNOP); +HDL4SEUNIT_FUNCDECLARE(hdl4se_unop, CLSID_HDL4SE_UNOP, sHDL4SEUnop); +DLIST_FUNCIMPL(hdl4se_unop, CLSID_HDL4SE_UNOP, sHDL4SEUnop); + +OBJECT_FUNCIMPL(hdl4se_unop, sHDL4SEUnop, CLSID_HDL4SE_UNOP); + + +QUERYINTERFACE_BEGIN(hdl4se_unop, CLSID_HDL4SE_UNOP) +QUERYINTERFACE_ITEM(IID_HDL4SEUNIT, IHDL4SEUnit, sHDL4SEUnop) +QUERYINTERFACE_ITEM(IID_DLIST, IDList, sHDL4SEUnop) +QUERYINTERFACE_END + +static const char* hdl4se_unopModuleInfo() +{ + return "1.0.0-20210523.0816 HDL4SE UNOP cell"; +} + +static int hdl4se_unopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* pObject) +{ + sHDL4SEUnop* pobj; + int i; + pobj = (sHDL4SEUnop*)malloc(sizeof(sHDL4SEUnop)); + if (pobj == NULL) + return -1; + *pObject = 0; + HDL4SEUNIT_VARINIT(pobj, CLSID_HDL4SE_UNOP); + INTERFACE_INIT(IHDL4SEUnit, pobj, hdl4se_unop, hdl4se_unit); + DLIST_VARINIT(pobj, hdl4se_unop); + + pobj->wire_in = NULL; + pobj->wire_in_index = 0; + pobj->out_data = NULL; + pobj->in_data = NULL; + + pobj->name = NULL; + pobj->in_width = 0; + pobj->out_width = 0; + pobj->datavalid = 0; + pobj->op = -1; + pobj->parent = NULL; + + for (i = 0; i < paramcount; i++) { + if (pParams[i].name == PARAMID_HDL4SE_UNIT_NAME) { + if (pobj->name != NULL) + free(pobj->name); + pobj->name = strdup(pParams[i].pvalue); + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_PARENT) { + pobj->parent = (IHDL4SEModule **)pParams[i].pvalue; + } + else if (pParams[i].name == PARAMID_HDL4SE_UNIT_INSTANCE_PARAMETERS) { + IBigNumber** temp = bigintegerCreate(32); + if (temp != NULL) { + const char* nstr; + const char* lstr; + lstr = (const char*)pParams[i].pvalue; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->in_width); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->out_width); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) { + objectCall1(temp, GetInt, &pobj->op); + } + else { + return EIID_INVALIDPARAM; + } + lstr = nstr; + objectRelease(temp); + } + } + } + + if (pobj->in_width <= 0) + return EIID_INVALIDPARAM; + if (pobj->out_width <= 0) + return EIID_INVALIDPARAM; + if (pobj->op < UNOP_NEG || pobj->op > UNOP_LAST) + return EIID_INVALIDPARAM; + + pobj->out_data = bigintegerCreate(pobj->out_width); + pobj->in_data = bigintegerCreate(pobj->in_width); + + /* 返回生成的对象 */ + OBJECT_RETURN_GEN(hdl4se_unop, pobj, pObject, CLSID_HDL4SE_UNOP); + return EIID_OK; +} + +static void hdl4se_unopDestroy(HOBJECT object) +{ + sHDL4SEUnop* pobj; + int i; + pobj = (sHDL4SEUnop*)objectThis(object); + if (pobj->name != NULL) + free(pobj->name); + objectRelease(pobj->wire_in); + objectRelease(pobj->out_data); + objectRelease(pobj->in_data); + memset(pobj, 0, sizeof(sHDL4SEUnop)); + free(pobj); +} + +static int hdl4se_unopValid(HOBJECT object) +{ + sHDL4SEUnop* pobj; + pobj = (sHDL4SEUnop*)objectThis(object); + return 1; +} + +static int hdl4se_unop_hdl4se_unit_Connect(HOBJECT object, int index, HOBJECT from, int fromindex) +{ + sHDL4SEUnop* pobj; + IHDL4SEUnit** unit = NULL; + pobj = (sHDL4SEUnop*)objectThis(object); + if (0 == objectQueryInterface(from, IID_HDL4SEUNIT, (void**)&unit)) { + objectRelease(pobj->wire_in); + pobj->wire_in = unit; + pobj->wire_in_index = fromindex; + return 0; + } + return -1; +} + +static int hdl4se_unop_hdl4se_unit_GetValue(HOBJECT object, int index, int width, IBigNumber ** value) +{ + int i; + sHDL4SEUnop* pobj; + pobj = (sHDL4SEUnop*)objectThis(object); + if (pobj->datavalid == 0) { + switch (pobj->op) { + case UNOP_NEG: + objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->out_data); + objectCall0(pobj->out_data, Neg); + break; + case UNOP_NOT: + objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->out_data); + objectCall0(pobj->out_data, Not); + break; + case UNOP_AND: + objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data); + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall0(pobj->out_data, uAnd) != 0) { + objectCall1(pobj->out_data, AssignInt, 1); + } + break; + case UNOP_OR: + objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data); + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall0(pobj->out_data, uOr) != 0) { + objectCall1(pobj->out_data, AssignInt, 1); + } + break; + case UNOP_XOR: + objectCall3(pobj->wire_in, GetValue, pobj->wire_in_index, pobj->in_width, pobj->in_data); + objectCall1(pobj->out_data, AssignInt, 0); + if (objectCall0(pobj->out_data, uXor) != 0) { + objectCall1(pobj->out_data, AssignInt, 1); + } + break; + } + pobj->datavalid = 1; + } + objectCall1(value, Assign, pobj->out_data); + return 0; +} + +static int hdl4se_unop_hdl4se_unit_ClkTick(HOBJECT object) +{ + sHDL4SEUnop* pobj; + pobj = (sHDL4SEUnop*)objectThis(object); + return 0; +} + +static int hdl4se_unop_hdl4se_unit_Setup(HOBJECT object) +{ + sHDL4SEUnop* pobj; + pobj = (sHDL4SEUnop*)objectThis(object); + pobj->datavalid = 0; + return 0; +} + diff --git a/hdl4secell/src/hdl4se_wire.c b/hdl4secell/src/hdl4se_wire.c index e447a8e1318c339681894efba5ba9de74fcd3aa3..e89686df9be346e3565666307ac7a73b761e2560 100644 --- a/hdl4secell/src/hdl4se_wire.c +++ b/hdl4secell/src/hdl4se_wire.c @@ -178,7 +178,7 @@ static int hdl4se_wire_hdl4se_unit_GetValue(HOBJECT object, int index, int width int i; sHDL4SEWire* pobj; pobj = (sHDL4SEWire*)objectThis(object); - if (pobj->datavalid) { + if (pobj->datavalid == 0) { for (i = 0; i < pobj->wire_in_count; i++) { objectCall3(pobj->wire_in[i], GetValue, pobj->wire_in_index[i], pobj->width, pobj->out_data); } diff --git a/hdl4secell/src/hdl4secell.c b/hdl4secell/src/hdl4secell.c index 88f5adbc2be748395ba59a50cbe95558a017d098..b07208d5f75777d8edee789a38749926f0bb5aec 100644 --- a/hdl4secell/src/hdl4secell.c +++ b/hdl4secell/src/hdl4secell.c @@ -51,12 +51,16 @@ static int hdl4secell_registed = 0; extern OFUNCPTR A_u_t_o_registor_hdl4se_reg; +extern OFUNCPTR A_u_t_o_registor_hdl4se_unop; +extern OFUNCPTR A_u_t_o_registor_hdl4se_binop; extern OFUNCPTR A_u_t_o_registor_hdl4se_wire; extern OFUNCPTR A_u_t_o_registor_hdl4se_const; extern OFUNCPTR A_u_t_o_registor_hdl4se_module; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind2; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind3; extern OFUNCPTR A_u_t_o_registor_hdl4se_bind4; +extern OFUNCPTR A_u_t_o_registor_hdl4se_split2; +extern OFUNCPTR A_u_t_o_registor_hdl4se_split4; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux2; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux4; extern OFUNCPTR A_u_t_o_registor_hdl4se_mux8; @@ -74,19 +78,26 @@ IHDL4SEUnit** hdl4seCreateUnit(IHDL4SEModule** parent, IIDTYPE clsid, char* inst param[2].pvalue = parent; if (hdl4secell_registed == 0) { A_u_t_o_registor_hdl4se_reg(); + A_u_t_o_registor_hdl4se_unop(); + A_u_t_o_registor_hdl4se_binop(); A_u_t_o_registor_hdl4se_wire(); A_u_t_o_registor_hdl4se_const(); A_u_t_o_registor_hdl4se_module(); A_u_t_o_registor_hdl4se_bind2(); A_u_t_o_registor_hdl4se_bind3(); A_u_t_o_registor_hdl4se_bind4(); + A_u_t_o_registor_hdl4se_split2(); + A_u_t_o_registor_hdl4se_split4(); A_u_t_o_registor_hdl4se_mux2(); A_u_t_o_registor_hdl4se_mux4(); A_u_t_o_registor_hdl4se_mux8(); A_u_t_o_registor_hdl4se_mux16(); hdl4secell_registed = 1; } - objectCreateEx(clsid, param, 3, IID_HDL4SEUNIT, (const void**)&result); + if (EIID_OK != objectCreateEx(clsid, param, 3, IID_HDL4SEUNIT, (const void**)&result)) { + printf("%s[%s] create failed\n", name, instanceparam); + return NULL; + } objectCall1(parent, AddUnit, result); return result; } diff --git a/hdl4secell/verilog/hdl4secell.v b/hdl4secell/verilog/hdl4secell.v index d568be9dc8923cad8168ae7d048dec2172027c0b..14d4d2c1dae95760a78f6184db48d1464ecd130f 100644 --- a/hdl4secell/verilog/hdl4secell.v +++ b/hdl4secell/verilog/hdl4secell.v @@ -306,7 +306,7 @@ endmodule `define BINOP_MUL 2 `define BINOP_DIV 3 `define BINOP_EQ 4 -`define BINOP_NEQ 5 +`define BINOP_NE 5 `define BINOP_LT 6 `define BINOP_LE 7 `define BINOP_GE 8 @@ -332,9 +332,10 @@ module #(INPUTWIDTH0=8, INPUTWIDTH1=8, OUTPUTWIDTH=8, OP=`BINOP_ADD) endmodule `define UNOP_NEG 0 -`define UNOP_AND 1 -`define UNOP_OR 2 -`define UNOP_XOR 3 +`define UNOP_NOT 1 +`define UNOP_AND 2 +`define UNOP_OR 3 +`define UNOP_XOR 4 (* HDL4SE="LCOM", CLSID="E6772805-57BB-4b39-A10D-FDA6A4810E3B",