00001 /*************************************************************************** 00002 * Copyright (C) 2003-2005 by David Saxton * 00003 * david@bluehaze.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #ifndef LOGIC_H 00012 #define LOGIC_H 00013 00014 #include "element.h" 00015 00016 #include <qguardedptr.h> 00017 #include <qvaluelist.h> 00018 00019 class Component; 00020 class Pin; 00021 class Simulator; 00022 00023 typedef QValueList<QGuardedPtr<Pin> > PinList; 00024 00025 typedef struct 00026 { 00027 float risingTrigger; // Trigger on rising edge 00028 float fallingTrigger; // Trigger on falling edge 00029 float output; // Output voltage 00030 float highImpedance; // Output impedance when high 00031 float lowImpedance; // Output impedance when low 00032 } LogicConfig; 00033 00034 /* What is this for? */ 00035 class CallbackClass {}; 00036 typedef void(CallbackClass::*CallbackPtr)( bool isHigh ); 00037 00046 class LogicIn : public Element 00047 { 00048 public: 00049 LogicIn( LogicConfig config ); 00050 virtual ~LogicIn(); 00051 00052 virtual Type type() const { return Element_LogicIn; } 00053 virtual void setElementSet( ElementSet *c ); 00054 00058 virtual void setLogic( LogicConfig config ); 00062 void check(); 00068 bool isHigh() const { return m_bLastState; } 00073 void setCallback( CallbackClass * object, CallbackPtr func ); 00078 static LogicConfig getConfig(); 00082 void setLastState( bool state ) { m_bLastState = state; } 00086 LogicIn * nextLogic() const { return m_pNextLogic; } 00090 void setNextLogic( LogicIn * next ) { m_pNextLogic = next; } 00094 void callCallback() 00095 { 00096 if (m_pCallbackFunction) 00097 (m_pCallbackObject->*m_pCallbackFunction)(m_bLastState); 00098 } 00099 00100 protected: 00101 virtual void updateCurrents(); 00102 virtual void add_initial_dc(); 00103 00104 CallbackPtr m_pCallbackFunction; 00105 CallbackClass * m_pCallbackObject; 00106 bool m_bLastState; 00107 LogicIn * m_pNextLogic; 00108 LogicConfig m_config; 00109 }; 00110 00111 00115 class LogicOut : public LogicIn 00116 { 00117 public: 00118 LogicOut( LogicConfig config, bool _high ); 00119 virtual ~LogicOut(); 00120 00121 virtual void setLogic( LogicConfig config ); 00122 virtual void setElementSet( ElementSet *c ); 00123 virtual void add_map(); 00124 virtual Type type() const { return Element_LogicOut; } 00125 00131 void setOutputHighConductance( double g ); 00137 void setOutputLowConductance( double g ); 00143 void setOutputHighVoltage( double v ); 00147 double outputHighVoltage() const { return m_vHigh; } 00151 void setHigh( bool high ); 00155 bool outputState() const { return b_state; } 00160 void setUseLogicChain( bool use ); 00167 void setNextChanged( LogicOut * logicOut, unsigned char chain ) { m_pNextChanged[chain] = logicOut; } 00174 void setCanAddChanged( bool canAdd ) { m_bCanAddChanged = canAdd; } 00180 LogicOut * nextChanged( unsigned char chain ) const { return m_pNextChanged[chain]; } 00181 PinList pinList; 00182 PinList::iterator pinListBegin; 00183 PinList::iterator pinListEnd; 00184 00185 protected: 00186 void configChanged(); 00187 virtual void updateCurrents(); 00188 virtual void add_initial_dc(); 00189 00190 // Pre-initalized levels from config 00191 double m_gHigh; 00192 double m_gLow; 00193 double m_vHigh; 00194 00195 // Whether to use the user-defined logic values 00196 bool m_bOutputHighConductanceConst; 00197 bool m_bOutputLowConductanceConst; 00198 bool m_bOutputHighVoltageConst; 00199 00200 double m_g_out; 00201 double m_v_out; 00202 double m_old_g_out; 00203 double m_old_v_out; 00204 bool b_state; 00205 bool m_bCanAddChanged; 00206 LogicOut * m_pNextChanged[2]; 00207 Simulator * m_pSimulator; 00208 bool m_bUseLogicChain; 00209 }; 00210 00211 #endif 00212
1.5.1