Hi Klaus,

your problem with Pin class is a wrong implementation of OpenDrain class. And what you see as result is overwritten memory, sometimes you can get a segfault, sometimes it's only a endless loop! As I wrote, OpenDrain is unmaintained ... :-)

Appended a patch, with one of more possible and correct running implementations.

cu, Thomas
diff --git a/src/pin.cpp b/src/pin.cpp
index 5edb374..c4d9fff 100644
--- a/src/pin.cpp
+++ b/src/pin.cpp
@@ -255,7 +255,7 @@ Pin Pin::operator+= (const Pin& p) {
     return *this;
 }
 
-#ifndef DISABLE_OPENDRAIN
+#ifndef XXX_DISABLE_OPENDRAIN
 Pin::Pin(const OpenDrain &od) {
     bool res = (bool) od;
     if(res == 0) {
@@ -333,29 +333,17 @@ Pin Pin::operator+ (const Pin& p) {
 
 #ifndef DISABLE_OPENDRAIN
 
-Pin OpenDrain::operator+= (const Pin& p) {
-    *pin= *this+p;
-    return *this;
-}
-
 Pin OpenDrain::GetPin() {
-    bool res=(bool) *pin;
-    if (res==0) return Pin(TRISTATE);
-    else return Pin(LOW); 
-}
-
-Pin OpenDrain::operator +(const Pin &p) {
-    Pin dummy; 
-    bool parent=(bool)*pin;
-    if (parent==0) dummy=Pin(TRISTATE);    //if the result 
-    else dummy=Pin(LOW);
-
-    return dummy+p;
+    // get back state of output side
+    bool input = (bool)*pin;
+    if(input)
+        return Pin(LOW);
+    else
+        return Pin(TRISTATE);
 }
 
-OpenDrain::operator bool() const
-{ 
-    return 0;
+OpenDrain::OpenDrain(Pin *p) {
+    pin = p;
 }
 
 #endif
diff --git a/src/pin.h b/src/pin.h
index 2b31ea0..a872fa6 100644
--- a/src/pin.h
+++ b/src/pin.h
@@ -82,7 +82,7 @@ class Pin {
 
         Pin(void); //!< common constructor, initial output state is tristate
         Pin(const Pin& p); //!< copy constructor, copy values but no refs to Net or HWPort
-#ifndef DISABLE_OPENDRAIN
+#ifndef XXX_DISABLE_OPENDRAIN
         Pin(const OpenDrain &od); //!< copy constructor, if we take values from OpenDrain pin
 #endif
         Pin(T_Pinstate ps); //!< copy constructor from pin state
@@ -123,19 +123,11 @@ class Pin {
 //! Open drain Pin class, a special pin with open drain behavior
 class OpenDrain: public Pin {
     protected:
-        Pin *pin;
+        Pin *pin;        // the connected pin, which control input
 
     public:
-        OpenDrain(Pin *p) { pin=p;}
-#ifndef SWIG
-        virtual operator bool() const;
-        virtual Pin operator+ (const Pin& p);
-        virtual Pin operator+= (const Pin& p);
-#endif
+        OpenDrain(Pin *p);
         virtual Pin GetPin();
-        void RegisterNet(Net *n) { pin->RegisterNet(n);}
-        virtual ~OpenDrain() {}
-        void SetInState ( const Pin &p) { pin->SetInState(*pin); } // mirror out to in value
 };
 
 #endif
_______________________________________________
Simulavr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/simulavr-devel

Reply via email to