KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kibis.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Fabien Corona f.corona<at>laposte.net
5 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
18 * to endorse or promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32
33#ifndef KIBIS_H
34#define KIBIS_H
35
36#include "ibis_parser.h"
37
38class KIBIS_PIN;
39class KIBIS_FILE;
40class KIBIS_MODEL;
41class KIBIS_COMPONENT;
42class KIBIS;
43
44class KIBIS_ANY : public IBIS_ANY
45{
46protected:
47 KIBIS_ANY( KIBIS* aTopLevel );
48
53 KIBIS_ANY( KIBIS* aTopLevel, REPORTER* aReporter );
54
55public:
57 bool m_valid;
58};
59
61{
62 NONE = 0, // Used for three state
63 PRBS,
67 HIGH_Z
68};
69
70
72{
73public:
74 KIBIS_WAVEFORM( KIBIS& aTopLevel ) : KIBIS_ANY{ &aTopLevel } { m_valid = true; };
75 KIBIS_WAVEFORM_TYPE GetType() const { return m_type; };
76 virtual double GetDuration() const { return 1; };
77 bool inverted = false; // Used for differential drivers
78 virtual ~KIBIS_WAVEFORM() {};
79
80 virtual std::vector<std::pair<int, double>> GenerateBitSequence() const
81 {
82 std::vector<std::pair<int, double>> bits;
83 return bits;
84 };
85
86 // Check function if using waveform data
87 virtual bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const
88 {
89 return true;
90 };
91 // Check function if using ramp data
92 virtual bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const
93 {
94 return true;
95 };
96
97protected:
98 KIBIS_WAVEFORM_TYPE m_type = KIBIS_WAVEFORM_TYPE::NONE;
99};
100
102{
103public:
105 {
106 m_type = KIBIS_WAVEFORM_TYPE::RECTANGULAR;
107 };
108 double m_ton = 100e-9;
109 double m_toff = 100e-9;
110 double m_delay = 0;
111 int m_cycles = 1;
112
113
114 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
115 bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const override;
116 bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const override;
117
118 double GetDuration() const override { return ( m_ton + m_toff ) * m_cycles; };
119};
120
121// For now, we only support PRBS7
123{
124public:
125 KIBIS_WAVEFORM_PRBS( KIBIS& aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
126 {
127 m_type = KIBIS_WAVEFORM_TYPE::PRBS;
128 };
129 double m_bitrate = 10e6;
130 double m_delay = 0;
131 int m_bits = 10;
132
133 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
134 bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const override;
135 bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const override;
136
137 void SetBits( int aBits ) { m_bits = std::abs( aBits ); };
138
139 double GetDuration() const override { return m_bits / m_bitrate; };
140};
141
143{
144public:
145 KIBIS_WAVEFORM_STUCK_HIGH( KIBIS& aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
146 {
147 m_type = KIBIS_WAVEFORM_TYPE::STUCK_HIGH;
148 };
149 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
150};
151
153{
154public:
155 KIBIS_WAVEFORM_STUCK_LOW( KIBIS& aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
156 {
157 m_type = KIBIS_WAVEFORM_TYPE::STUCK_LOW;
158 };
159 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
160};
161
163{
164public:
165 KIBIS_WAVEFORM_HIGH_Z( KIBIS& aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
166 {
167 m_type = KIBIS_WAVEFORM_TYPE::HIGH_Z;
168 };
169 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
170};
171
191{
192 LEVEL_0,
193 LEVEL_1,
194 LEVEL_2,
195 LEVEL_3,
196};
197
199{
200public:
201 IBIS_CORNER m_Rpin = IBIS_CORNER::TYP;
202 IBIS_CORNER m_Lpin = IBIS_CORNER::TYP;
203 IBIS_CORNER m_Cpin = IBIS_CORNER::TYP;
204 IBIS_CORNER m_Ccomp = IBIS_CORNER::TYP;
205 IBIS_CORNER m_supply = IBIS_CORNER::TYP;
207 KIBIS_ACCURACY m_accuracy = KIBIS_ACCURACY::LEVEL_2;
208
209 void SetCornerFromString( IBIS_CORNER& aCorner, const std::string& aString );
210};
211
212
214{
215public:
216 KIBIS_FILE( KIBIS& aTopLevel );
217
218 std::string m_fileName;
219 double m_fileRev;
221 std::string m_date;
222 std::string m_source;
223 std::string m_notes;
224 std::string m_disclaimer;
225 std::string m_copyright;
226
227 bool Init( const IbisParser& aParser );
228};
229
230class KIBIS_MODEL : public KIBIS_ANY
231{
232public:
233 KIBIS_MODEL( KIBIS& aTopLevel, const IbisModel& aSource, IbisParser& aParser );
234
235 std::string m_name;
236 std::string m_description;
237 IBIS_MODEL_TYPE m_type = IBIS_MODEL_TYPE::UNDEFINED;
238 /* The Polarity, Enable, Vinl, Vinh, Vmeas, Cref, Rref, and Vref subparameters are optional. */
239 /* the default values of Vinl = 0.8 V and Vinh = 2.0 V are assumed. */
240 double m_vinl = 0.8;
241 double m_vinh = 2;
242 double m_vref = 0;
243 double m_rref = 0;
244 double m_cref = 0;
245 double m_vmeas = 0;
246 IBIS_MODEL_ENABLE m_enable = IBIS_MODEL_ENABLE::UNDEFINED;
247 IBIS_MODEL_POLARITY m_polarity = IBIS_MODEL_POLARITY::UNDEFINED;
248 // End of optional subparameters
249
265 std::vector<IbisWaveform*> m_risingWaveforms;
266 std::vector<IbisWaveform*> m_fallingWaveforms;
268
270 bool HasPulldown() const;
272 bool HasPullup() const;
274 bool HasGNDClamp() const;
276 bool HasPOWERClamp() const;
277
284 std::string SpiceDie( const KIBIS_PARAMETER& aParam, int aIndex ) const;
285
294 std::vector<std::pair<IbisWaveform*, IbisWaveform*>> waveformPairs();
295
296
310 std::string generateSquareWave( const std::string& aNode1, const std::string& aNode2,
311 const std::vector<std::pair<int, double>>& aBits,
312 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
313 const KIBIS_PARAMETER& aParam );
314
315
322 IbisWaveform TrimWaveform( const IbisWaveform& aIn ) const;
323};
324
325class KIBIS_PIN : public KIBIS_ANY
326{
327public:
328 KIBIS_PIN( KIBIS& aTopLevel, const IbisComponentPin& aPin, const IbisComponentPackage& aPackage,
329 IbisParser& aParser, KIBIS_COMPONENT* aParent, std::vector<KIBIS_MODEL>& aModels );
333 std::string m_signalName;
337 std::string m_pinNumber;
338
345
347
348 std::vector<double> m_t, m_Ku, m_Kd;
349
350 std::vector<KIBIS_MODEL*> m_models;
351
352 bool writeSpiceDriver( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
353 const KIBIS_PARAMETER& aParam );
354 bool writeSpiceDiffDriver( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
355 const KIBIS_PARAMETER& aParam );
356 bool writeSpiceDevice( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
357 const KIBIS_PARAMETER& aParam );
358 bool writeSpiceDiffDevice( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
359 const KIBIS_PARAMETER& aParam );
360
365 void getKuKdNoWaveform( KIBIS_MODEL& aModel, const KIBIS_PARAMETER& aParam );
366
372 void getKuKdOneWaveform( KIBIS_MODEL& aModel,
373 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
374 const KIBIS_PARAMETER& aParam );
375
385 void getKuKdTwoWaveforms( KIBIS_MODEL& aModel,
386 const std::pair<IbisWaveform*, IbisWaveform*>& aPair1,
387 const std::pair<IbisWaveform*, IbisWaveform*>& aPair2,
388 const KIBIS_PARAMETER& aParam );
389
400 std::string KuKdDriver( KIBIS_MODEL& aModel,
401 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
402 const KIBIS_PARAMETER& aParam, int aIndex );
403
414 std::string addDie( KIBIS_MODEL& aModel, const KIBIS_PARAMETER& aParam, int aIndex );
415
416
425 void getKuKdFromFile( const std::string& aSimul );
426
428
429 bool isDiffPin() const { return m_complementaryPin != nullptr; };
430};
431
433{
434public:
435 KIBIS_COMPONENT( KIBIS& aToplevel, const IbisComponent& aSource, IbisParser& aParser );
437 std::string m_name;
439 std::string m_manufacturer;
440
441 std::vector<KIBIS_PIN> m_pins;
442
448 KIBIS_PIN* GetPin( const std::string& aPinNumber );
449};
450
451class KIBIS : public KIBIS_ANY
452{
453public:
455 KIBIS() : KIBIS_ANY( this, nullptr ), m_file( *this ) {};
456
457 KIBIS( const std::string& aFileName, REPORTER* aReporter = nullptr );
458
459 std::vector<KIBIS_COMPONENT> m_components;
460 std::vector<KIBIS_MODEL> m_models;
462
464 std::string m_cacheDir = "";
465
467 KIBIS_MODEL* GetModel( const std::string& aName );
469 KIBIS_COMPONENT* GetComponent( const std::string& aName );
470};
471
472#endif
bool m_valid
Definition: kibis.h:57
KIBIS * m_topLevel
Definition: kibis.h:56
std::vector< KIBIS_PIN > m_pins
Definition: kibis.h:441
std::string m_manufacturer
Name of the manufacturer.
Definition: kibis.h:439
std::string m_name
Name of the component.
Definition: kibis.h:437
KIBIS_PIN * GetPin(const std::string &aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
Definition: kibis.cpp:327
std::string m_source
Definition: kibis.h:222
std::string m_notes
Definition: kibis.h:223
double m_ibisVersion
Definition: kibis.h:220
std::string m_date
Definition: kibis.h:221
bool Init(const IbisParser &aParser)
Definition: kibis.cpp:144
std::string m_fileName
Definition: kibis.h:218
std::string m_copyright
Definition: kibis.h:225
std::string m_disclaimer
Definition: kibis.h:224
double m_fileRev
Definition: kibis.h:219
std::vector< IbisWaveform * > m_fallingWaveforms
Definition: kibis.h:266
IbisWaveform TrimWaveform(const IbisWaveform &aIn) const
Copy a waveform, and substract the first value to all samples.
Definition: kibis.cpp:440
IBIS_MODEL_ENABLE m_enable
Definition: kibis.h:246
double m_vref
Definition: kibis.h:242
std::string m_name
Definition: kibis.h:235
bool HasPOWERClamp() const
Return true if the model has a clamp diode to the power net.
Definition: kibis.cpp:496
double m_vmeas
Definition: kibis.h:245
std::vector< IbisWaveform * > m_risingWaveforms
Definition: kibis.h:265
TypMinMaxValue m_Cac
Definition: kibis.h:260
double m_vinh
Definition: kibis.h:241
double m_rref
Definition: kibis.h:243
bool HasPullup() const
Return true if the model has a pullup transistor.
Definition: kibis.cpp:484
bool HasGNDClamp() const
Return true if the model has a clamp diode to the gnd net.
Definition: kibis.cpp:490
TypMinMaxValue m_pulldownReference
Definition: kibis.h:254
TypMinMaxValue m_GNDClampReference
Definition: kibis.h:255
TypMinMaxValue m_Rpower
Definition: kibis.h:258
bool HasPulldown() const
Return true if the model has a pulldown transistor.
Definition: kibis.cpp:478
IBIS_MODEL_TYPE m_type
Definition: kibis.h:237
IbisRamp m_ramp
Definition: kibis.h:267
IVtable m_pullup
Definition: kibis.h:263
IBIS_MODEL_POLARITY m_polarity
Definition: kibis.h:247
double m_cref
Definition: kibis.h:244
std::string generateSquareWave(const std::string &aNode1, const std::string &aNode2, const std::vector< std::pair< int, double > > &aBits, const std::pair< IbisWaveform *, IbisWaveform * > &aPair, const KIBIS_PARAMETER &aParam)
Generate a square waveform.
Definition: kibis.cpp:502
TypMinMaxValue m_Rac
Definition: kibis.h:259
TypMinMaxValue m_temperatureRange
Definition: kibis.h:252
TypMinMaxValue m_voltageRange
Definition: kibis.h:251
IVtable m_GNDClamp
Definition: kibis.h:261
TypMinMaxValue m_Rgnd
Definition: kibis.h:257
std::string m_description
Definition: kibis.h:236
IVtable m_POWERClamp
Definition: kibis.h:262
TypMinMaxValue m_pullupReference
Definition: kibis.h:253
std::vector< std::pair< IbisWaveform *, IbisWaveform * > > waveformPairs()
Create waveform pairs.
Definition: kibis.cpp:340
TypMinMaxValue m_POWERClampReference
Definition: kibis.h:256
TypMinMaxValue m_C_comp
Definition: kibis.h:250
std::string SpiceDie(const KIBIS_PARAMETER &aParam, int aIndex) const
Generate the spice directive to simulate the die.
Definition: kibis.cpp:367
IVtable m_pulldown
Definition: kibis.h:264
double m_vinl
Definition: kibis.h:240
IBIS_CORNER m_supply
Definition: kibis.h:205
IBIS_CORNER m_Cpin
Definition: kibis.h:203
KIBIS_ACCURACY m_accuracy
Definition: kibis.h:207
IBIS_CORNER m_Ccomp
Definition: kibis.h:204
IBIS_CORNER m_Lpin
Definition: kibis.h:202
IBIS_CORNER m_Rpin
Definition: kibis.h:201
void SetCornerFromString(IBIS_CORNER &aCorner, const std::string &aString)
Definition: kibis.cpp:1415
KIBIS_WAVEFORM * m_waveform
Definition: kibis.h:206
bool isDiffPin() const
Definition: kibis.h:429
TypMinMaxValue m_Rpin
Resistance from die to pin.
Definition: kibis.h:340
bool writeSpiceDiffDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1298
TypMinMaxValue m_Lpin
Inductance from die to pin.
Definition: kibis.h:342
void getKuKdFromFile(const std::string &aSimul)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:658
KIBIS_COMPONENT * m_parent
Definition: kibis.h:346
std::vector< double > m_Ku
Definition: kibis.h:348
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition: kibis.h:337
std::string addDie(KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam, int aIndex)
Generate the spice directive to simulate the die for Ku/Kd estimation.
Definition: kibis.cpp:606
bool writeSpiceDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1247
std::vector< KIBIS_MODEL * > m_models
Definition: kibis.h:350
std::vector< double > m_t
Definition: kibis.h:348
TypMinMaxValue m_Cpin
Capacitance from pin to GND.
Definition: kibis.h:344
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition: kibis.h:333
void getKuKdTwoWaveforms(KIBIS_MODEL &aModel, const std::pair< IbisWaveform *, IbisWaveform * > &aPair1, const std::pair< IbisWaveform *, IbisWaveform * > &aPair2, const KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:983
void getKuKdOneWaveform(KIBIS_MODEL &aModel, const std::pair< IbisWaveform *, IbisWaveform * > &aPair, const KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using with a single waveform input.
Definition: kibis.cpp:812
bool writeSpiceDiffDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1349
std::string KuKdDriver(KIBIS_MODEL &aModel, const std::pair< IbisWaveform *, IbisWaveform * > &aPair, const KIBIS_PARAMETER &aParam, int aIndex)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:738
std::vector< double > m_Kd
Definition: kibis.h:348
bool writeSpiceDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1125
KIBIS_PIN * m_complementaryPin
Definition: kibis.h:427
void getKuKdNoWaveform(KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using no falling / rising waveform inputs ( low accuracy )
Definition: kibis.cpp:921
KIBIS_WAVEFORM_HIGH_Z(KIBIS &aTopLevel)
Definition: kibis.h:165
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1445
double m_delay
Definition: kibis.h:130
bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const override
Definition: kibis.cpp:1627
void SetBits(int aBits)
Definition: kibis.h:137
double GetDuration() const override
Definition: kibis.h:139
KIBIS_WAVEFORM_PRBS(KIBIS &aTopLevel)
Definition: kibis.h:125
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1470
double m_bitrate
Definition: kibis.h:129
bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const override
Definition: kibis.cpp:1505
double GetDuration() const override
Definition: kibis.h:118
KIBIS_WAVEFORM_RECTANGULAR(KIBIS &aTopLevel)
Definition: kibis.h:104
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1451
KIBIS_WAVEFORM_STUCK_HIGH(KIBIS &aTopLevel)
Definition: kibis.h:145
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1426
KIBIS_WAVEFORM_STUCK_LOW(KIBIS &aTopLevel)
Definition: kibis.h:155
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1436
KIBIS_WAVEFORM_TYPE m_type
Definition: kibis.h:98
virtual ~KIBIS_WAVEFORM()
Definition: kibis.h:78
virtual bool Check(const dvdtTypMinMax &aRisingRp, const dvdtTypMinMax &aFallingRp) const
Definition: kibis.h:92
virtual bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const
Definition: kibis.h:87
KIBIS_WAVEFORM_TYPE GetType() const
Definition: kibis.h:75
KIBIS_WAVEFORM(KIBIS &aTopLevel)
Definition: kibis.h:74
bool inverted
Definition: kibis.h:77
virtual double GetDuration() const
Definition: kibis.h:76
virtual std::vector< std::pair< int, double > > GenerateBitSequence() const
Definition: kibis.h:80
Definition: kibis.h:452
std::vector< KIBIS_MODEL > m_models
Definition: kibis.h:460
KIBIS()
Constructor for unitialized KIBIS members.
Definition: kibis.h:455
std::vector< KIBIS_COMPONENT > m_components
Definition: kibis.h:459
KIBIS_MODEL * GetModel(const std::string &aName)
Return the model with name aName .
Definition: kibis.cpp:1393
KIBIS_COMPONENT * GetComponent(const std::string &aName)
Return the component with name aName .
Definition: kibis.cpp:1404
KIBIS_FILE m_file
Definition: kibis.h:461
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
Definition: kibis.h:464
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
IBIS_MODEL_TYPE
Definition: ibis_parser.h:424
IBIS_MODEL_POLARITY
Definition: ibis_parser.h:510
IBIS_CORNER
Definition: ibis_parser.h:94
IBIS_MODEL_ENABLE
Definition: ibis_parser.h:446
KIBIS_ACCURACY
Accuracy level.
Definition: kibis.h:191
KIBIS_WAVEFORM_TYPE
Definition: kibis.h:61
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390