simulavr  1.1.0
pinatport.cpp
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #include "pinatport.h"
27 #include "hwport.h"
28 
30  port = NULL;
31  pinNo = 255;
32  regID = -1;
33 }
34 
35 PinAtPort::PinAtPort(HWPort *p, unsigned char pn) {
36  port = p;
37  pinNo = pn;
39 }
40 
42  return port != NULL;
43 }
44 
46  return port->GetPin(pinNo);
47 }
48 
49 void PinAtPort::SetPort(bool val) {
50  unsigned char *adr = &port->port;
51  SetVal(adr, val);
52  port->CalcOutputs();
53 }
54 
55 float PinAtPort::GetAnalogValue(float vcc) {
56  return port->p[pinNo].GetAnalogValue(vcc);
57 }
58 
59 void PinAtPort::SetDdr(bool val) {
60  unsigned char *adr = &port->ddr;
61  SetVal(adr, val);
62  port->CalcOutputs();
63 }
64 
66  port->p[pinNo].SetPUOV(val, regID);
67  port->CalcOutputs();
68 }
69 
71  port->p[pinNo].SetPUOE(val, regID);
72  port->CalcOutputs();
73 }
74 
76  port->p[pinNo].SetDDOV(val, regID);
77  port->CalcOutputs();
78 }
79 
81  port->p[pinNo].SetDDOE(val, regID);
82  port->CalcOutputs();
83 }
84 
86  port->p[pinNo].SetPVOV(val, regID);
87  port->CalcOutputs();
88 }
89 
91  port->p[pinNo].SetPVOE(val, regID);
92  port->CalcOutputs();
93 }
94 
97  port->CalcOutputs();
98 }
99 
101  return (port->port >> pinNo) & 1;
102 }
103 
105  return (port->ddr >> pinNo) & 1;
106 }
107 
108 PinAtPort::operator bool() {
109  return ((port->GetPin()) >> pinNo) & 0x01;
110 } //we must use GetPin to recalculate the Pin from p[] array
111 
112 void PinAtPort::SetVal( unsigned char *adr, bool val) {
113  if (val) {
114  *adr |= (1 << pinNo);
115  } else {
116  *adr &= ~(1 << pinNo);
117  }
118 }
119 
120 /* EOF*/
Pin & GetPin()
Definition: pinatport.cpp:45
void SetDdr(bool val)
Definition: pinatport.cpp:59
Pin class, handles input and output to external parts.
Definition: pin.h:98
void SetAlternateDdr(bool val)
Definition: pinatport.cpp:75
void SetUseAlternatePort(bool val)
Definition: pinatport.cpp:90
bool GetDdr()
Definition: pinatport.cpp:104
void SetPVOE(bool val, int index=0)
set port override enable
Definition: pin.cpp:399
Pin & GetPin(unsigned char pinNo)
returns a pin reference of pin with pin number
Definition: hwport.cpp:87
void SetPVOV(bool val, int index=0)
set port override value
Definition: pin.cpp:392
Defines a Port, e.g. a hardware device for GPIO.
Definition: hwport.h:43
void SetVal(unsigned char *adr, bool val)
Definition: pinatport.cpp:112
HWPort * port
Definition: pinatport.h:36
void SetUseAlternatePullup(bool val)
Definition: pinatport.cpp:70
void CalcOutputs(void)
Calculate the new output value to be transmitted to the environment.
Definition: hwport.cpp:92
void SetUseAlternatePortIfDdrSet(bool val)
Definition: pinatport.cpp:95
unsigned char ddr
data direction register
Definition: hwport.h:50
void SetAlternatePort(bool val)
Definition: pinatport.cpp:85
unsigned char pinNo
Definition: pinatport.h:37
void SetPort(bool val)
Definition: pinatport.cpp:49
unsigned char port
port output register
Definition: hwport.h:48
void SetAlternatePullup(bool val)
Definition: pinatport.cpp:65
bool GetPort()
Definition: pinatport.cpp:100
int RegisterAlternateUse(void)
register an alternate function to pin
Definition: pin.cpp:373
void SetUseAlternateDdr(bool val)
Definition: pinatport.cpp:80
void SetPUOE(bool val, int index=0)
set pullup override enable
Definition: pin.cpp:420
PortPin p[8]
the port pins, e.g. the final IO stages
Definition: hwport.h:52
void SetDDOV(bool val, int index=0)
set data direction override value
Definition: pin.cpp:378
void SetDDOE(bool val, int index=0)
set data direction override enable
Definition: pin.cpp:385
bool active()
Definition: pinatport.cpp:41
void SetPUOV(bool val, int index=0)
set pullup override value
Definition: pin.cpp:413
void SetPVOE_WithDDR(bool val, int index=0)
set port override enable, if DDR is set
Definition: pin.cpp:406
float GetAnalogValue(float vcc)
Get pin analog voltage level.
Definition: pinatport.cpp:55
float GetAnalogValue(float vcc)
Returns real analog input value of pin.
Definition: pin.h:150
int regID
Definition: pinatport.h:38