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 00027 #include "pinatport.h" 00028 #include "hwport.h" 00029 00030 #include <iostream> 00031 using namespace std; 00032 PinAtPort::PinAtPort() { 00033 cerr << "Dummy Pin At Port" << endl; 00034 } 00035 00036 PinAtPort::PinAtPort( HWPort *p, unsigned char pn) 00037 { 00038 port=p; 00039 pinNo=pn; 00040 } 00041 00042 Pin& PinAtPort::GetPin() { 00043 return port->GetPin(pinNo); 00044 } 00045 00046 void PinAtPort::SetPort(bool val) { 00047 unsigned char *adr=&port->port; 00048 SetVal(adr, val); 00049 port->CalcOutputs(); 00050 } 00051 00052 int PinAtPort::GetAnalog() const { 00053 return port->p[pinNo].GetAnalog(); 00054 } 00055 00056 00057 void PinAtPort::SetDdr(bool val) { 00058 unsigned char *adr=&port->ddr; 00059 SetVal(adr, val); 00060 port->CalcOutputs(); 00061 } 00062 00063 void PinAtPort::SetAlternateDdr(bool val){ 00064 unsigned char *adr=&port->alternateDdr; 00065 SetVal(adr, val); 00066 port->CalcOutputs(); 00067 } 00068 00069 void PinAtPort::SetUseAlternateDdr(bool val) { 00070 unsigned char *adr=&port->useAlternateDdr; 00071 SetVal(adr, val); 00072 port->CalcOutputs(); 00073 } 00074 00075 void PinAtPort::SetAlternatePort(bool val) { 00076 unsigned char *adr=&port->alternatePort; 00077 SetVal(adr, val); 00078 port->CalcOutputs(); 00079 port->port_reg.hardwareChange(port->alternatePort); 00080 } 00081 00082 void PinAtPort::SetUseAlternatePort(bool val) { 00083 unsigned char *adr=&port->useAlternatePort; 00084 SetVal(adr, val); 00085 port->CalcOutputs(); 00086 } 00087 00088 void PinAtPort::SetUseAlternatePortIfDdrSet(bool val) { 00089 unsigned char *adr=&port->useAlternatePortIfDdrSet; 00090 SetVal(adr, val); 00091 port->CalcOutputs(); 00092 } 00093 00094 bool PinAtPort::GetPort() { 00095 return (port->port)>>pinNo; 00096 } 00097 00098 bool PinAtPort::GetDdr() { 00099 return (port->ddr)>>pinNo; 00100 } 00101 00102 bool PinAtPort::GetAlternateDdr(){ 00103 return (port->alternateDdr)>>pinNo; 00104 } 00105 00106 bool PinAtPort::GetUseAlterateDdr() { 00107 return (port->useAlternateDdr)>>pinNo; 00108 } 00109 00110 bool PinAtPort::GetAlternatePort() { 00111 return (port->alternatePort)>>pinNo; 00112 } 00113 00114 bool PinAtPort::GetUseAlternatePort() { 00115 return (port->useAlternatePort)>>pinNo; 00116 } 00117 00118 bool PinAtPort::GetUseAlternatePortIfDdrSet() { 00119 return (port->useAlternatePortIfDdrSet)>>pinNo; 00120 } 00121 00122 PinAtPort::operator bool() { 00123 return ((port->GetPin())>>pinNo)&0x01; 00124 } //we must use GetPin to recalculate the Pin from p[] array 00125 00126 00127 void PinAtPort::SetVal( unsigned char *adr, bool val) { 00128 if (val) { 00129 *adr|=(1<<pinNo); 00130 } else { 00131 *adr&=~(1<<pinNo); 00132 } 00133 } 00134