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 HWPORT 00027 #define HWPORT 00028 00029 #include "hardware.h" 00030 #include "pin.h" 00031 #include "rwmem.h" 00032 #include "traceval.h" 00033 00034 #include <string> 00035 00037 00043 class HWPort: public Hardware, public TraceValueRegister { 00044 00045 private: 00046 void CalcPin(void); 00047 00048 protected: 00049 std::string myName; 00050 00051 unsigned char port; 00052 unsigned char pin; 00053 unsigned char ddr; 00054 00055 unsigned char alternateDdr; 00056 unsigned char useAlternateDdr; 00057 00058 unsigned char alternatePort; 00059 unsigned char useAlternatePort; 00060 00063 unsigned char useAlternatePortIfDdrSet; 00064 00065 Pin p[8]; 00066 int portSize; 00067 unsigned char portMask; 00068 bool portToggleFeature; 00069 00070 public: 00071 HWPort(AvrDevice *core, const std::string &name, bool portToggle = false, int size = 8); 00072 ~HWPort() {} 00073 00074 void CalcOutputs(void); 00075 std::string GetPortString(void); 00076 void Reset(void); 00077 std::string GetName(void) { return myName; } 00078 Pin& GetPin(unsigned char pinNo); 00079 int GetPortSize(void) { return portSize; } 00080 00081 void SetPort(unsigned char val) { port = val & portMask; CalcOutputs(); } 00082 void SetDdr(unsigned char val) { ddr = val & portMask; CalcOutputs(); } 00083 void SetPin(unsigned char val); 00084 unsigned char GetPort(void) { return port; } 00085 unsigned char GetDdr(void) { return ddr; } 00086 unsigned char GetPin(void) { return pin; } 00087 00088 friend class PinAtPort; 00089 00090 IOReg<HWPort> 00091 port_reg, 00092 pin_reg, 00093 ddr_reg; 00094 }; 00095 00096 #endif