00001 /* 00002 **************************************************************************** 00003 * 00004 * simulavr - A simulator for the Atmel AVR family of microcontrollers. 00005 * Copyright (C) 2001, 2002, 2003 Klaus Rudolph 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 **************************************************************************** 00022 * 00023 * $Id$ 00024 */ 00025 00026 #ifndef PIN 00027 #define PIN 00028 #include <cstddef> 00029 #include <vector> 00030 00031 #include "pinnotify.h" 00032 00036 #define DISABLE_OPENDRAIN 1 00037 00038 class Net; 00039 #ifndef DISABLE_OPENDRAIN 00040 class OpenDrain; 00041 #endif 00042 00044 00047 class Pin { 00048 00049 protected: 00050 unsigned char *pinOfPort; 00051 unsigned char mask; 00052 int analogValue; 00053 00054 Net *connectedTo; 00055 00056 public: 00057 00059 00063 typedef enum { 00064 LOW, 00065 HIGH, 00066 SHORTED, 00067 PULLUP, 00068 TRISTATE, 00069 PULLDOWN, 00070 ANALOG, 00071 ANALOG_SHORTED 00072 } T_Pinstate; 00073 00074 T_Pinstate outState; 00075 std::vector<HasPinNotifyFunction*> notifyList; 00076 00077 Pin(void); 00078 Pin(const Pin& p); 00079 #ifndef DISABLE_OPENDRAIN 00080 Pin(const OpenDrain &od); 00081 #endif 00082 Pin(T_Pinstate ps); 00083 Pin(unsigned char *parentPin, unsigned char mask); 00084 virtual ~Pin(); 00085 00086 #ifndef SWIG 00087 operator char() const; 00088 virtual Pin &operator= (char); 00089 virtual operator bool() const; 00090 virtual Pin operator+ (const Pin& p); 00091 virtual Pin operator+= (const Pin& p); 00092 #endif 00093 00094 virtual void SetInState(const Pin &p); 00095 virtual void RegisterNet(Net *n); 00096 virtual void UnRegisterNet(Net *n); 00097 virtual Pin GetPin(void) { return *this;} 00098 int GetAnalog(void) const; 00099 Pin& SetAnalog(int value); 00100 void RegisterCallback(HasPinNotifyFunction *); 00101 00102 00104 bool CalcPin(void); 00105 00106 bool isPortPin(void) { return pinOfPort != NULL; } 00107 bool isConnected(void) { return connectedTo != NULL; } 00108 bool hasListener(void) { return notifyList.size() != 0; } 00109 00110 friend class HWPort; 00111 friend class Net; 00112 00113 }; 00114 00115 #ifndef DISABLE_OPENDRAIN 00116 00118 class OpenDrain: public Pin { 00119 protected: 00120 Pin *pin; 00121 00122 public: 00123 OpenDrain(Pin *p) { pin=p;} 00124 #ifndef SWIG 00125 virtual operator bool() const; 00126 virtual Pin operator+ (const Pin& p); 00127 virtual Pin operator+= (const Pin& p); 00128 #endif 00129 virtual Pin GetPin(); 00130 void RegisterNet(Net *n) { pin->RegisterNet(n);} 00131 virtual ~OpenDrain() {} 00132 }; 00133 00134 #endif 00135 00136 #endif