blob: 47ef6cb7a584c8b5d12eb66f838ec077fa75e3d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "config.h"
#ifndef NO_GPSIM
#include "micropackage.h"
#include "piccomponent.h"
#include "piccomponentpin.h"
#include <kdebug.h>
PICComponentPin::PICComponentPin( PICComponent * picComponent, PicPin picPin )
: m_id( picPin.pinID )
{
m_gOutHigh = 0.0;
m_gOutLow = 0.0;
m_picPin = picPin;
m_pPICComponent = picComponent;
m_pLogicOut = 0l;
m_pLogicIn = 0l;
m_pIOPIN = 0l;
m_pStimulusNode = 0l;
Zth = 0.0;
Vth = 0.0;
switch ( picPin.type )
{
case PicPin::type_input:
{
m_pLogicIn = picComponent->createLogicIn( picComponent->ecNodeWithID(picPin.pinID) );
break;
}
case PicPin::type_bidir:
{
m_pLogicOut = picComponent->createLogicOut( picComponent->ecNodeWithID(picPin.pinID), false );
m_gOutHigh = 0.004;
m_gOutLow = 0.004;
break;
}
case PicPin::type_open:
{
m_pLogicOut = picComponent->createLogicOut( picComponent->ecNodeWithID(picPin.pinID), false );
m_pLogicOut->setOutputHighVoltage(0.0);
m_pLogicOut->setOutputHighConductance(0.0);
m_gOutHigh = 0.0;
m_gOutLow = 0.004;
break;
}
case PicPin::type_vss:
case PicPin::type_vdd:
case PicPin::type_mclr:
case PicPin::type_osc:
default:
break;
}
if (m_pLogicIn)
m_pLogicIn->setCallback( this, (CallbackPtr)(&PICComponentPin::logicCallback) );
if (m_pLogicOut)
m_pLogicOut->setCallback( this, (CallbackPtr)(&PICComponentPin::logicCallback) );
}
PICComponentPin::~PICComponentPin()
{
delete m_pStimulusNode;
}
void PICComponentPin::attach( IOPIN * iopin )
{
if (!iopin)
{
kdWarning() << k_funcinfo << " iopin is NULL" << endl;
return;
}
if (m_pStimulusNode)
{
kdWarning() << k_funcinfo << " Already have a node stimulus" << endl;
return;
}
if (m_pIOPIN)
{
kdWarning() << k_funcinfo << " Already have an iopin" << endl;
return;
}
m_pIOPIN = iopin;
m_pStimulusNode = new Stimulus_Node(m_id.ascii());
m_pStimulusNode->attach_stimulus(iopin);
m_pStimulusNode->attach_stimulus(this);
// We need to tell the iopin whether or not we are high
if (m_pLogicOut)
logicCallback( m_pLogicOut->isHigh() );
else if (m_pLogicIn)
logicCallback( m_pLogicIn->isHigh() );
}
double PICComponentPin::get_Vth( )
{
if (!m_pIOPIN)
return 0.0;
if ( m_pIOPIN->get_direction() == IOPIN::DIR_INPUT )
return Vth;
else
return m_pIOPIN->get_Vth();
}
void PICComponentPin::set_nodeVoltage( double v )
{
Q_UNUSED(v);
if ( !m_pLogicOut || !m_pIOPIN )
return;
if ( m_pIOPIN->get_direction() == IOPIN::DIR_INPUT )
{
m_pLogicOut->setOutputHighConductance(0.0);
m_pLogicOut->setOutputLowConductance(0.0);
return;
}
m_pLogicOut->setHigh( m_pIOPIN->getDrivingState() );
m_pLogicOut->setOutputHighConductance(m_gOutHigh);
m_pLogicOut->setOutputLowConductance(m_gOutLow);
}
void PICComponentPin::logicCallback( bool state )
{
if (!m_pIOPIN)
return;
Vth = state ? 5e10 : 0;
bDrivingState = state;
if ( m_pIOPIN->get_direction() == IOPIN::DIR_INPUT )
{
Zth = 1e5;
m_pIOPIN->setDrivenState(state);
if (m_pStimulusNode)
m_pStimulusNode->update();
}
else
Zth = 0;
}
void PICComponentPin::resetOutput()
{
if ( m_pLogicOut )
m_pLogicOut->setHigh( false );
}
#endif
|