simulavr  1.1.0
net.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 "net.h"
27 #include "pin.h"
28 
29 void Net::Add(Pin *p) {
30  push_back(p);
31  p->RegisterNet(this);
32  CalcNet();
33 }
34 
35 void Net::Delete(Pin *p) {
36  iterator ii;
37  for(ii = begin(); ii != end(); ii++) {
38  if((Pin*)(*ii) == p) {
39  erase(ii);
40  break;
41  }
42  }
43 }
44 
46  while(begin() != end())
47  (*begin())->UnRegisterNet(this);
48 }
49 
50 bool Net::CalcNet() {
51  Pin result(Pin::TRISTATE);
52  iterator ii;
53  for(ii = begin(); ii != end(); ii++)
54  result += ((*ii)->GetPin()); //get state of pin (TRISTATE, HIGH, LOW ....)
55 
56  //new result is now found, so set all pins in the Net to new state
57  for(ii = begin(); ii != end(); ii++)
58  (*ii)->SetInState( result); //In-State that means the state of register PIN not the complete pin here
59 
60  return (bool)result;
61 }
62 
virtual bool CalcNet()
Calculate a "electrical potential" on the net and set all pin inputs with this value.
Definition: net.cpp:50
Pin class, handles input and output to external parts.
Definition: pin.h:98
void Add(Pin *p)
Add a pin to net, e.g. connect a pin to others.
Definition: net.cpp:29
virtual void Delete(Pin *p)
Definition: net.cpp:35
virtual ~Net()
Destructor, disconnects save all pins, which are connected.
Definition: net.cpp:45
virtual void RegisterNet(Net *n)
registers Net instance on pin
Definition: pin.cpp:168
virtual void SetInState(const Pin &p)
handles the input value from net
Definition: pin.cpp:64