simulavr  1.1.0
hwport.h
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 #ifndef HWPORT
27 #define HWPORT
28 
29 #include "hardware.h"
30 #include "pin.h"
31 #include "rwmem.h"
32 #include "traceval.h"
33 
34 #include <string>
35 
37 
43 class HWPort: public Hardware, public TraceValueRegister {
44 
45  protected:
46  std::string myName;
47 
48  unsigned char port;
49  unsigned char pin;
50  unsigned char ddr;
51 
52  PortPin p[8];
54  unsigned int portSize;
55  unsigned char portMask;
57 
58  public:
59  HWPort(AvrDevice *core, const std::string &name, bool portToggle = false, int size = 8);
60  ~HWPort();
61 
62  void CalcOutputs(void);
63  std::string GetPortString(void);
64  void Reset(void);
65  std::string GetName(void) { return myName; }
66  Pin& GetPin(unsigned char pinNo);
67  int GetPortSize(void) { return portSize; }
68 
69  void SetPort(unsigned char val);
70  void SetDdr(unsigned char val);
71  void SetPin(unsigned char val);
72  void SetPinBit( bool bit, unsigned int bitaddr);
73 
74  unsigned char GetPort() { return port; }
75  unsigned char GetDdr() { return ddr; }
76  unsigned char GetPin() { return pin; }
77 
78  // only as example if bit read did modify IO-hardware, here only as dummy
79  unsigned char GetPinBit(unsigned int bitaddr) { return pin&(1<<bitaddr);}
80 
81  friend class PinAtPort;
82 
85  pin_reg,
86  ddr_reg;
87 };
88 
89 #endif
std::string myName
the "name" of the port
Definition: hwport.h:46
unsigned char GetPin()
getter method for PIN register
Definition: hwport.h:76
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
TraceValue * pintrace[8]
trace channel to trace output driver state
Definition: hwport.h:53
Pin class, handles input and output to external parts.
Definition: pin.h:98
unsigned char pin
port input register
Definition: hwport.h:49
Defines a Port, e.g. a hardware device for GPIO.
Definition: hwport.h:43
void Reset(void)
Definition: hwport.cpp:77
void CalcOutputs(void)
Calculate the new output value to be transmitted to the environment.
Definition: hwport.cpp:92
IOReg< HWPort > port_reg
Definition: hwport.h:84
IOReg< HWPort > pin_reg
Definition: hwport.h:84
HWPort(AvrDevice *core, const std::string &name, bool portToggle=false, int size=8)
Definition: hwport.cpp:34
unsigned char portMask
mask out unused bits, if necessary
Definition: hwport.h:55
unsigned char ddr
data direction register
Definition: hwport.h:50
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
void SetPinBit(bool bit, unsigned int bitaddr)
Definition: hwport.cpp:139
std::string GetPortString(void)
returns a string representation of output states
Definition: hwport.cpp:108
unsigned char port
port output register
Definition: hwport.h:48
int GetPortSize(void)
returns, how much bits this port controls
Definition: hwport.h:67
bool portToggleFeature
controls functionality of SetPin method (write to PIN toggles port register)
Definition: hwport.h:56
unsigned char GetDdr()
getter method for data direction register
Definition: hwport.h:75
std::string GetName(void)
returns the port name as given in constructor
Definition: hwport.h:65
Pin class for HWPort, a special pin with override functionality for output stage. ...
Definition: pin.h:169
~HWPort()
Definition: hwport.cpp:71
void SetDdr(unsigned char val)
setter method for data direction register
Definition: hwport.cpp:123
void SetPort(unsigned char val)
setter method for port register
Definition: hwport.cpp:117
PortPin p[8]
the port pins, e.g. the final IO stages
Definition: hwport.h:52
void SetPin(unsigned char val)
setter method for PIN register (for new devices with toggle port)
Definition: hwport.cpp:129
unsigned char GetPinBit(unsigned int bitaddr)
Definition: hwport.h:79
unsigned char GetPort()
getter method for port register
Definition: hwport.h:74
IOReg< HWPort > ddr_reg
Definition: hwport.h:84
unsigned int portSize
how much bits does this port have [1..8]
Definition: hwport.h:54