//! \brief Moves port1 to \a newLocalPos and adjust's the wire's lines. void Wire::movePort1(const QPointF& newLocalPos) { port1()->setPos(newLocalPos); // This is true when wire is created if(m_wLines.isEmpty()) { return initWireline(); } QPointF referencePos = port1()->pos(); if(m_wLines.size() == 1) { m_wLines.append(WireLine(port2()->pos(), port2()->pos())); } WireLine &first = m_wLines[0]; WireLine &second = m_wLines[1]; Q_ASSERT(!first.isOblique()); Q_ASSERT(!second.isOblique()); { bool should_set_x = ((first.isNull() && (second.isNull() || second.isHorizontal())) || (!first.isNull() && first.isVertical())); if(should_set_x) { first.setX(referencePos.x()); } else { first.setY(referencePos.y()); } first.setP1(referencePos); } referencePos = first.p2(); { bool should_set_y = ((second.isNull() && (first.isNull() || first.isVertical())) || (!second.isNull() && second.isHorizontal())); if(should_set_y) { second.setY(referencePos.y()); } else { second.setX(referencePos.x()); } second.setP1(referencePos); } updateGeometry(); }
//! \brief Moves port2 to \a newLocalPos and adjust's the wire's lines. void Wire::movePort2(const QPointF& newLocalPos) { port2()->setPos(newLocalPos); if(m_wLines.isEmpty()) { return initWireline(); } QPointF referencePos = port2()->pos(); if(m_wLines.size() == 1) { m_wLines.prepend(WireLine(port1()->pos(), port1()->pos())); } WireLine &last = m_wLines.last(); WireLine &last_but_one = m_wLines[m_wLines.size() - 2]; Q_ASSERT(!last.isOblique()); Q_ASSERT(!last_but_one.isOblique()); { bool should_set_x = ((last.isNull() && (last_but_one.isNull() || last_but_one.isHorizontal())) || (!last.isNull() && last.isVertical())); if(should_set_x) { last.setX(referencePos.x()); } else { last.setY(referencePos.y()); } last.setP2(referencePos); } referencePos = last.p1(); { bool should_set_y = ((last_but_one.isNull() && (last.isNull() || last.isVertical())) || (!last_but_one.isNull() && last_but_one.isHorizontal())); if(should_set_y) { last_but_one.setY(referencePos.y()); } else { last_but_one.setX(referencePos.x()); } last_but_one.setP2(referencePos); } updateGeometry(); }
/*! * \brief Initialize wire line used on wire creation * \note assert m_wLines.isEmpty() * \todo BR->GPK document inter */ void Wire::initWireline() { Q_ASSERT(m_wLines.isEmpty()); QPointF inter = QPointF(port1()->pos().x(), port2()->pos().y()); /* create two wire line */ m_wLines << WireLine(port1()->pos(), inter); m_wLines << WireLine(inter, port2()->pos()); /* update wire */ updateGeometry(); }
/*! * \brief Constructs a wire between \a startPort and \a endPort. * * Also connects the wire's port's to coinciding ports. * \bug br->gpk: does the new port is a purpose?? */ Wire::Wire(Port *startPort, Port *endPort, SchematicScene *scene) : QucsItem(0, scene), m_grabbedIndex(-1) { QPointF startPos = startPort->scenePos(); QPointF endPos = endPort->scenePos(); /* set position */ setPos((startPos + endPos)/2); /* set flags */ setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable); #if QT_VERSION >= 0x040600 setFlag(ItemSendsGeometryChanges, true); setFlag(ItemSendsScenePositionChanges, true); #endif /* create port BR->GPK: Why not add startport and endport */ QPointF localStartPos = mapFromScene(startPos); QPointF localEndPos = mapFromScene(endPos); m_ports << new Port(this, localStartPos); m_ports << new Port(this, localEndPos); initWireline(); if(scene) { removeNullLines(); } port1()->connectTo(startPort); port2()->connectTo(endPort); }
//! \brief Moves port matching connection \a connections to scene pos \a scenePos. void Wire::movePort(QList<Port*> *connections, const QPointF& scenePos) { if(port1()->connections() == connections) { movePort1(mapFromScene(scenePos)); } else if(port2()->connections() == connections) { movePort2(mapFromScene(scenePos)); } else { qWarning() << "Wire::movePort() : Port not found"; } }
void portTest::testMoveConstructor() { //construct port1 with a given id and put it into InitializedState long id1 = newPortId++; PortMock port1(// true, // isOutput, id1); port1.failOnWrongState = true; port1.initialize(nullptr, nullptr, nullptr); CPPUNIT_ASSERT(port1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id1, port1.getId()); //construct port1_1 (like port1) long id2 = newPortId++; PortMock port2(// false, // isInput, id2); port2.failOnWrongState = true; port2.initialize(nullptr, nullptr, nullptr); CPPUNIT_ASSERT(port2.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id2, port2.getId()); // move port1 into port 1_1 PortMock port1_1 = std::move(port1); // move port2 into port 2_1 PortMock port2_1 = std::move(port2); // verify that port1_1 has got the characteristics of port1 CPPUNIT_ASSERT(port1_1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id1, port1_1.getId()); // verify that port2_1 has got the characteristics of port2 CPPUNIT_ASSERT(port2_1.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id2, port2_1.getId()); // very that the remains of port1 characterize a dead port CPPUNIT_ASSERT_EQUAL(PortInvalidId, port1.getId()); CPPUNIT_ASSERT(port1.isDeletableState()); // very that the remains of port2 characterize a dead port CPPUNIT_ASSERT_EQUAL(PortInvalidId, port2.getId()); CPPUNIT_ASSERT(port2.isDeletableState()); //end port1_1.shutdown(nullptr, nullptr, false); port2_1.shutdown(nullptr, nullptr, false); }
/*! * \brief Moves wire by (\a dx, \a dy). * \sa beginGrabMode */ void Wire::grabMoveBy(qreal dx, qreal dy) { // assure atleast two wirelines presence at both ends. Q_ASSERT(m_grabbedIndex >= 2 && (m_wLines.size()-1-m_grabbedIndex) >= 2); /* now calculate the constant positions in the beginning and end. This position wont change when wire is moved. */ QPointF refPos1 = m_grabbedIndex == 2 ? port1()->pos() : m_wLines[m_grabbedIndex-3].p2(); QPointF refPos2 = m_wLines.size()-1-m_grabbedIndex == 2 ? port2()->pos() : m_wLines[m_grabbedIndex+3].p1(); QPointF inter1, inter2; // Move the grabbed line first and asserts its nature. WireLine& grabbedLine = m_wLines[m_grabbedIndex]; grabbedLine.translate(QPointF(dx, dy)); Q_ASSERT(grabbedLine.isHorizontal() || grabbedLine.isVertical()); // Calculate the intermediate points of the wirelines. if(grabbedLine.isHorizontal()) { inter1 = QPointF(grabbedLine.p1().x(), refPos1.y()); inter2 = QPointF(grabbedLine.p2().x(), refPos2.y()); } else { inter1 = QPointF(refPos1.x(), grabbedLine.p1().y()); inter2 = QPointF(refPos2.x(), grabbedLine.p2().y()); } // Modify wirelines to accomodate the changes. m_wLines[m_grabbedIndex-1] = WireLine(inter1, grabbedLine.p1()); m_wLines[m_grabbedIndex-2] = WireLine(refPos1, inter1); m_wLines[m_grabbedIndex+1] = WireLine(grabbedLine.p2(), inter2); m_wLines[m_grabbedIndex+2] = WireLine(inter2, refPos2); // Now update the wires. updateGeometry(); }
void portTest::testMoveConstructorOnBusyPort() { //construct port1 with a given id and put it into InitializedState long id = newPortId++; PortMock port1(// true, // isOutput, id, // internalId, 500, // _initializeDuration, << initialization will take long time 0, // _registerDuration, 0, // _startDuration, 0, // _execJavaProcessDuration, 0, // _execNativeProcessDuration, 0, // _stopDuration, 0, // _uninitializeDuration, 0); // _unregisterDuration) // this will take a while to execute.... std::thread iniThread([&]{port1.initialize(nullptr, nullptr, nullptr);}); std::this_thread::sleep_for(std::chrono::milliseconds(20)); // just to make sure that iniThread runs... // the move should block until the iniThread has ended. PortMock port2 = std::move(port1); iniThread.join(); // verify that port2 has got the characteristics of port1 (after initialization has finished) CPPUNIT_ASSERT(port2.isInitializedState()); CPPUNIT_ASSERT_EQUAL(id, port2.getId()); CPPUNIT_ASSERT_EQUAL(1, port2.initialize_implCount); // very that the remains of port1 characterize a dead port CPPUNIT_ASSERT_EQUAL(PortInvalidId, port1.getId()); CPPUNIT_ASSERT(port1.isDeletableState()); //end port2.shutdown(nullptr, nullptr, false); }
void Wire::saveData(Qucs::XmlWriter *writer) const { writer->writeStartElement("wire"); QPointF p1 = port1()->scenePos(); QPointF p2 = port2()->scenePos(); QString start = QString("%1,%2").arg(p1.x()).arg(p1.y()); QString end = QString("%1,%2").arg(p2.x()).arg(p2.y()); QString pos_str = QString("%1,%2").arg(pos().x()).arg(pos().y()); writer->writeAttribute("start", start); writer->writeAttribute("end", end); writer->writeAttribute("pos", pos_str); //write the lines foreach(WireLine line, m_wLines) { writer->writeEmptyElement("line"); writer->writeAttribute("x1", QString::number(line.x1())); writer->writeAttribute("y1", QString::number(line.y1())); writer->writeAttribute("x2", QString::number(line.x2())); writer->writeAttribute("y2", QString::number(line.y2())); }
//! \brief Try to connect ports void Wire::tryConnectPorts() { tryConnectPort(port1()); tryConnectPort(port2()); }
int sc_main(int argc,char *argv[]) { sc_signal<bool> clk, rst; sc_signal <bool> opreq, opreq0, opreq1; sc_signal <uint32> addr; assembler *A; uint32 MAX; sc_signal <bool> irq_0; MAX=128; uint32 *code = (uint32 *) malloc(MAX * sizeof(uint32)); A = new assembler(code, MAX); A->assemble("test_program", test_program); nominalproc_tlm nominal_0("nominal_0"); tlm_busmux busmux_0("busmux_0"); addr_decode addr_decode_0("addr_decode_0"); tlmram32 code_memory_0("code_memory_0"); tlmram32 port1("port1"); clock100 u_clkgen("u_clkgen"); u_clkgen.clk(clk); addr_decode_0.threshold = 0x10000; addr_decode_0.y0(opreq0); addr_decode_0.y1(opreq1); addr_decode_0.g(opreq); addr_decode_0.addr(addr); code_memory_0.contents(code, MAX); port1.contents(0,MAX); busmux_0.threshold = 0x10000; busmux_0.port0(code_memory_0); busmux_0.port1(port1); nominal_0.port0(busmux_0); nominal_0.rst(rst); nominal_0.irq(irq_0); /* nominalunit *nominalunit_0 = new nominalunit("nominalunit_0"); nominalunit_0->clk(clk); nominalunit_0->rst(rst); nominalunit_0->irq(irq_0);*/ // nominalunit_0->port1(port1_0); /* sc_signal <bool> irq_1; sc_signal <memport_if> port1_1; nominalunit *nominalunit_1 = new nominalunit("nominalunit_1"); nominalunit_1->clk(clk); nominalunit_1->rst(rst); nominalunit_1->irq(irq_1); // nominalunit_1->port1(port1_1); sc_signal <bool> irq_2; sc_signal <memport_if> port1_2; nominalunit *nominalunit_2 = new nominalunit("nominalunit_2"); nominalunit_2->clk(clk); nominalunit_2->rst(rst); nominalunit_2->irq(irq_2); // nominalunit_2->port1(port1_2); sc_signal <bool> irq_3; sc_signal <memport_if> port1_3; nominalunit *nominalunit_3 = new nominalunit("nominalunit_3"); nominalunit_3->clk(clk); nominalunit_3->rst(rst); nominalunit_3->irq(irq_3); // nominalunit_3->port1(port1_3); sc_signal <bool> irq_4; sc_signal <memport_if> port1_4; nominalunit *nominalunit_4 = new nominalunit("nominalunit_4"); nominalunit_4->clk(clk); nominalunit_4->rst(rst); nominalunit_4->irq(irq_4); // nominalunit_4->port1(port1_4); sc_signal <bool> irq_5; sc_signal <memport_if> port1_5; nominalunit *nominalunit_5 = new nominalunit("nominalunit_5"); nominalunit_5->clk(clk); nominalunit_5->rst(rst); nominalunit_5->irq(irq_5); // nominalunit_5->port1(port1_5); sc_signal <bool> irq_6; sc_signal <memport_if> port1_6; nominalunit *nominalunit_6 = new nominalunit("nominalunit_6"); nominalunit_6->clk(clk); nominalunit_6->rst(rst); nominalunit_6->irq(irq_6); // nominalunit_6->port1(port1_6); #if 1 // Second processor unit (B): sc_signal <bool> irq_7; sc_signal <memport_if> port1_7; nominalunit *nominalunit_7 = new nominalunit("nominalunit_7"); nominalunit_7->clk(clk); nominalunit_7->rst(rst); nominalunit_7->irq(irq_7); nominalunit_7->port1(port1_7); #endif */ irq_0 = 0; /* irq_1 = 0; irq_2 = 0; irq_3 = 0; irq_4 = 0; irq_5 = 0; irq_6 = 0; irq_7 = 0; */ rst = 1; sc_start(100, SC_NS); rst = 0; printf("End of reset\n"); sc_start(5, SC_US); cout << ("Interrupt to B\n") << sc_time_stamp() << "\n"; sc_start(10, SC_US); cout << "Dual CPU SystemC nominal proc finished at " << sc_time_stamp() << "\n"; return 0; }
// // Fix a compile error - see http://stackoverflow.com/questions/920500/what-is-the-purpose-of-cxa-pure-virtual for details. // // extern "C" void __cxa_pure_virtual() { while (1); } // // The main entry point // int main(void) { // // Board and port initialisations // StellarisLaunchpad pad; StellarisPort port1(SYSCTL_PERIPH_GPIOD); StellarisPort port2(SYSCTL_PERIPH_GPIOE); // // Create a set of objects representing the output pins // StellarisPortPin clock(GPIO_PORTD_BASE, GPIO_PIN_1); StellarisPortPin shift(GPIO_PORTD_BASE, GPIO_PIN_2); StellarisPortPin chipSelect(GPIO_PORTD_BASE, GPIO_PIN_3); StellarisPortPin a(GPIO_PORTE_BASE, GPIO_PIN_1); StellarisPortPin b(GPIO_PORTE_BASE, GPIO_PIN_2); StellarisPortPin c(GPIO_PORTE_BASE, GPIO_PIN_3); // // Create and initialise the LedArrayDriver // LedArrayDriver led(&clock, &chipSelect, &shift, &a,&b,&c, NBR_OF_DISPLAY_ROWS, NBR_OF_DISPLAY_COLUMNS); led.init(); AsciiMessage welcome("**** Welcome to the Museum of Computing - open Fridays 10am to 4pm and Saturdays 9:30am to 5pm ****"); AsciiMessage exhib1("**** Visit our \"Gaming on the Go\" exhibition - 35 years of handheld games consoles ****"); AsciiMessage retroGaming("**** Join our computer games sessions on Saturdays for some retro gaming ****"); AsciiMessage website("**** See us on the web at http://www.museum-of-computing.org.uk/ ****"); AsciiMessage hackspace("**** Join the Swindon Hackspace at the Museum of Computing - Wednesdays 6:30pm to 10pm ****"); AsciiMessage compClub("**** Ask about our Kids Computer Club on Saturdays ****"); AsciiMessage schoolVisit("**** Arrange a school visit and take part in a tour of the museum, quizzes and mini projects ****"); AsciiMessage shop("**** Our shop has a range of gifts and souvenirs ****"); RepeatedGraphic multiInvader(invader, 10, 8); AnimatedGraphic pacman(animPacman, 17, 7);// columns * frames AnimatedGraphic invader(animInvader, 11, 4);// columns * frames LeftScroller scrollLeft1(led, invader, 2, displayBuffer); LeftScroller scrollLeft2(led, welcome, 1, displayBuffer); LeftScroller scrollLeft3(led, exhib1, 1, displayBuffer); LeftScroller scrollLeft4(led, multiInvader, 1, displayBuffer); LeftScroller scrollLeft5(led, retroGaming, 1, displayBuffer); LeftScroller scrollLeft6(led, pacman, 1, displayBuffer); LeftScroller scrollLeft7(led, compClub, 1, displayBuffer); LeftScroller scrollLeft8(led, schoolVisit, 1, displayBuffer); LeftScroller scrollLeft9(led, website, 1, displayBuffer); LeftScroller scrollLeft10(led, shop, 1, displayBuffer); LeftScroller scrollLeft11(led, hackspace, 1, displayBuffer); do { scrollLeft1.init(); while(scrollLeft1.animate()); scrollLeft2.init(); while(scrollLeft2.animate()); scrollLeft3.init(); while(scrollLeft3.animate()); scrollLeft4.init(); while(scrollLeft4.animate()); scrollLeft5.init(); while(scrollLeft5.animate()); scrollLeft6.init(); while(scrollLeft6.animate()); scrollLeft7.init(); while(scrollLeft7.animate()); scrollLeft8.init(); while(scrollLeft8.animate()); scrollLeft9.init(); while(scrollLeft9.animate()); scrollLeft10.init(); while(scrollLeft10.animate()); scrollLeft11.init(); while(scrollLeft11.animate()); } while(1); }
int sc_main(int argc, char *argv[]) { // First processor unit (A): assembler *A; uint32 MAX; sc_in <bool> rst, clk, irq; // sc_port <memport_if> port1; sc_signal <bool> opreq, opreq0, opreq1; sc_signal <uint32> addr; clock100 u_clkgen("u_clkgen"); u_clkgen.clk(clk); addr_decode addr_decode_0("addr_decode_0"); addr_decode_0.threshold = 0x10000; addr_decode_0.y0(opreq0); addr_decode_0.y1(opreq1); addr_decode_0.g(opreq); addr_decode_0.addr(addr); MAX = 128; uint32 *code = (uint32 *) malloc(MAX * sizeof(uint32)); A = new assembler(code, MAX); A->assemble("test_program", test_program); tlmram32 code_memory_0("code_memory_0"); code_memory_0.contents(code, MAX); tlmram32 port1("port1"); port1.contents(0,MAX); tlm_busmux busmux_0("busmux_0"); busmux_0.threshold = 0x10000; busmux_0.port0(code_memory_0); busmux_0.port1(port1); nominalproc_tlm nominal_0("nominal_0"); nominal_0.port0(busmux_0); nominal_0.rst(rst); nominal_0.irq(irq); irq = 0; rst = 1; sc_start(100, SC_NS); rst = 0; printf("End of reset\n"); sc_start(5, SC_US); cout << ("Interrupt to B\n") << sc_time_stamp() << "\n"; sc_start(10, SC_US); cout << "Dual CPU SystemC nominal proc finished at " << sc_time_stamp() << "\n"; return 0; }