KiCad PCB EDA Suite
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 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
17 * to endorse or promote products derived from this software without specific
18 * prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32#ifndef KIBIS_H
33#define KIBIS_H
34
35#include "ibis_parser.h"
36
37class KIBIS_PIN;
38class KIBIS_FILE;
39class KIBIS_MODEL;
40class KIBIS_COMPONENT;
41class KIBIS;
42
43class KIBIS_ANY : public IBIS_ANY
44{
45public:
46 KIBIS_ANY( KIBIS* aTopLevel );
48 bool m_valid;
49};
50
52{
53 NONE = 0, // Used for three state
58 HIGH_Z
59};
60
61
63{
64public:
65 KIBIS_WAVEFORM( KIBIS* aTopLevel ) : KIBIS_ANY{ aTopLevel } { m_valid = true; };
67 virtual double GetDuration() { return 1; };
68 bool inverted = false; // Used for differential drivers
69 virtual ~KIBIS_WAVEFORM(){};
70
71 virtual std::vector<std::pair<int, double>> GenerateBitSequence()
72 {
73 std::vector<std::pair<int, double>> bits;
74 return bits;
75 };
76
77 // Check fuction if using waveform data
78 virtual bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) { return true; };
79 // Check fuction if using ramp data
80 virtual bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) { return true; };
81
82protected:
84};
85
87{
88public:
89 KIBIS_WAVEFORM_RECTANGULAR( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
90 {
92 };
93 double m_ton = 100e-9;
94 double m_toff = 100e-9;
95 double m_delay = 0;
96 int m_cycles = 1;
97
98
99 std::vector<std::pair<int, double>> GenerateBitSequence() override;
100 bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) override;
101 bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) override;
102
103 double GetDuration() override { return ( m_ton + m_toff ) * m_cycles; };
104};
105
106// For now, we only support PRBS7
108{
109public:
110 KIBIS_WAVEFORM_PRBS( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
111 {
113 };
114 double m_bitrate = 10e6;
115 double m_delay = 0;
116 int m_bits = 10;
117
118 std::vector<std::pair<int, double>> GenerateBitSequence() override;
119 bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) override;
120 bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) override;
121
122 double GetDuration() override { return m_bits / m_bitrate ; };
123};
124
126{
127public:
128 KIBIS_WAVEFORM_STUCK_HIGH( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
129 {
131 };
132 std::vector<std::pair<int, double>> GenerateBitSequence() override;
133};
134
136{
137public:
138 KIBIS_WAVEFORM_STUCK_LOW( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
139 {
141 };
142 std::vector<std::pair<int, double>> GenerateBitSequence() override;
143};
144
146{
147public:
148 KIBIS_WAVEFORM_HIGH_Z( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
149 {
151 };
152 std::vector<std::pair<int, double>> GenerateBitSequence() override;
153};
154
174{
175 LEVEL_0,
176 LEVEL_1,
177 LEVEL_2,
178 LEVEL_3,
179};
180
182{
183public:
191
192 void SetCornerFromString( IBIS_CORNER& aCorner, std::string aString );
193};
194
195
197{
198public:
199 KIBIS_FILE( KIBIS* aTopLevel );
200
201 std::string m_fileName;
202 double m_fileRev;
204 std::string m_date;
205 std::string m_source;
206 std::string m_notes;
207 std::string m_disclaimer;
208 std::string m_copyright;
209
210 bool Init( IbisParser& aParser );
211};
212
213
214class KIBIS : public KIBIS_ANY
215{
216public:
217 KIBIS() : KIBIS_ANY( this ), m_file( this )
218 {
219 m_valid = false;
220 }; // Constructor for unitialized KIBIS members
221 KIBIS( std::string aFileName, IBIS_REPORTER* aReporter = nullptr );
222
224 std::vector<KIBIS_COMPONENT> m_components;
225 std::vector<KIBIS_MODEL> m_models;
227
229 std::string m_cacheDir = "";
230
232 KIBIS_MODEL* GetModel( std::string aName );
234 KIBIS_COMPONENT* GetComponent( std::string aName );
235};
236
237class KIBIS_MODEL : public KIBIS_ANY
238{
239public:
240 KIBIS_MODEL( KIBIS* aTopLevel, IbisModel& aSource, IbisParser& aParser );
241
242 std::string m_name;
243 std::string m_description;
245 /* The Polarity, Enable, Vinl, Vinh, Vmeas, Cref, Rref, and Vref subparameters are optional. */
246 /* the default values of Vinl = 0.8 V and Vinh = 2.0 V are assumed. */
247 double m_vinl = 0.8;
248 double m_vinh = 2;
249 double m_vref = 0;
250 double m_rref = 0;
251 double m_cref = 0;
252 double m_vmeas = 0;
255 // End of optional subparameters
256
272 std::vector<IbisWaveform*> m_risingWaveforms;
273 std::vector<IbisWaveform*> m_fallingWaveforms;
275
277 bool HasPulldown();
279 bool HasPullup();
281 bool HasGNDClamp();
283 bool HasPOWERClamp();
284
291 std::string SpiceDie( KIBIS_PARAMETER& aParam, int aIndex );
292
301 std::vector<std::pair<IbisWaveform*, IbisWaveform*>> waveformPairs();
302
303
317 std::string generateSquareWave( std::string aNode1, std::string aNode2,
318 std::vector<std::pair<int, double>> aBits,
319 std::pair<IbisWaveform*, IbisWaveform*> aPair,
320 KIBIS_PARAMETER& aParam );
321
322
330};
331
332class KIBIS_PIN : public KIBIS_ANY
333{
334public:
335 KIBIS_PIN( KIBIS* aTopLevel, IbisComponentPin& aPin, IbisComponentPackage& aPackage,
336 IbisParser& aParser, KIBIS_COMPONENT* aParent, std::vector<KIBIS_MODEL>& aModels );
340 std::string m_signalName;
344 std::string m_pinNumber;
345
352
354
355 std::vector<double> m_t, m_Ku, m_Kd;
356
357 std::vector<KIBIS_MODEL*> m_models;
358
359 bool writeSpiceDriver( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
360 KIBIS_PARAMETER& aParam );
361 bool writeSpiceDiffDriver( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
362 KIBIS_PARAMETER& aParam );
363 bool writeSpiceDevice( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
364 KIBIS_PARAMETER& aParam );
365 bool writeSpiceDiffDevice( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
366 KIBIS_PARAMETER& aParam );
367
372 void getKuKdNoWaveform( KIBIS_MODEL& aModel, KIBIS_PARAMETER& aParam );
373
379 void getKuKdOneWaveform( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair,
380 KIBIS_PARAMETER& aParam );
381
391 void getKuKdTwoWaveforms( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair1,
392 std::pair<IbisWaveform*, IbisWaveform*> aPair2,
393 KIBIS_PARAMETER& aParam );
394
405 std::string KuKdDriver( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair,
406 KIBIS_PARAMETER& aParam, int aIndex );
407
418 std::string addDie( KIBIS_MODEL& aModel, KIBIS_PARAMETER& aParam, int aIndex );
419
420
429 void getKuKdFromFile( std::string* aSimul );
430
432
433 bool isDiffPin() { return m_complementaryPin != nullptr; };
434};
435
437{
438public:
439 KIBIS_COMPONENT( KIBIS* aToplevel, IbisComponent& aSource, IbisParser& aParser );
441 std::string m_name;
443 std::string m_manufacturer;
444
445 std::vector<KIBIS_PIN> m_pins;
446
452 KIBIS_PIN* GetPin( std::string aPinNumber );
453};
454
455#endif
KIBIS_ANY(KIBIS *aTopLevel)
Definition: kibis.cpp:65
bool m_valid
Definition: kibis.h:48
KIBIS * m_topLevel
Definition: kibis.h:47
std::vector< KIBIS_PIN > m_pins
Definition: kibis.h:445
KIBIS_PIN * GetPin(std::string aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
Definition: kibis.cpp:330
std::string m_manufacturer
Name of the manufacturer.
Definition: kibis.h:443
KIBIS_COMPONENT(KIBIS *aToplevel, IbisComponent &aSource, IbisParser &aParser)
Definition: kibis.cpp:304
std::string m_name
Name of the component.
Definition: kibis.h:441
bool Init(IbisParser &aParser)
Definition: kibis.cpp:145
std::string m_source
Definition: kibis.h:205
std::string m_notes
Definition: kibis.h:206
double m_ibisVersion
Definition: kibis.h:203
KIBIS_FILE(KIBIS *aTopLevel)
Definition: kibis.cpp:138
std::string m_date
Definition: kibis.h:204
std::string m_fileName
Definition: kibis.h:201
std::string m_copyright
Definition: kibis.h:208
std::string m_disclaimer
Definition: kibis.h:207
double m_fileRev
Definition: kibis.h:202
std::vector< IbisWaveform * > m_fallingWaveforms
Definition: kibis.h:273
IBIS_MODEL_ENABLE m_enable
Definition: kibis.h:253
double m_vref
Definition: kibis.h:249
std::string m_name
Definition: kibis.h:242
bool HasPulldown()
Return true if the model has a pulldown transistor.
Definition: kibis.cpp:487
double m_vmeas
Definition: kibis.h:252
std::vector< IbisWaveform * > m_risingWaveforms
Definition: kibis.h:272
TypMinMaxValue m_Cac
Definition: kibis.h:267
double m_vinh
Definition: kibis.h:248
bool HasPOWERClamp()
Return true if the model has a clamp diode to the power net.
Definition: kibis.cpp:505
double m_rref
Definition: kibis.h:250
KIBIS_MODEL(KIBIS *aTopLevel, IbisModel &aSource, IbisParser &aParser)
Definition: kibis.cpp:240
TypMinMaxValue m_pulldownReference
Definition: kibis.h:261
TypMinMaxValue m_GNDClampReference
Definition: kibis.h:262
TypMinMaxValue m_Rpower
Definition: kibis.h:265
bool HasPullup()
Return true if the model has a pullup transistor.
Definition: kibis.cpp:493
IBIS_MODEL_TYPE m_type
Definition: kibis.h:244
std::string generateSquareWave(std::string aNode1, std::string aNode2, std::vector< std::pair< int, double > > aBits, std::pair< IbisWaveform *, IbisWaveform * > aPair, KIBIS_PARAMETER &aParam)
Generate a square waveform.
Definition: kibis.cpp:511
IbisRamp m_ramp
Definition: kibis.h:274
IVtable m_pullup
Definition: kibis.h:270
IBIS_MODEL_POLARITY m_polarity
Definition: kibis.h:254
double m_cref
Definition: kibis.h:251
TypMinMaxValue m_Rac
Definition: kibis.h:266
TypMinMaxValue m_temperatureRange
Definition: kibis.h:259
TypMinMaxValue m_voltageRange
Definition: kibis.h:258
IVtable m_GNDClamp
Definition: kibis.h:268
std::string SpiceDie(KIBIS_PARAMETER &aParam, int aIndex)
Generate the spice directive to simulate the die.
Definition: kibis.cpp:373
IbisWaveform TrimWaveform(IbisWaveform &aIn)
Copy a waveform, and substract the first value to all samples.
Definition: kibis.cpp:446
TypMinMaxValue m_Rgnd
Definition: kibis.h:264
bool HasGNDClamp()
Return true if the model has a clamp diode to the gnd net.
Definition: kibis.cpp:499
std::string m_description
Definition: kibis.h:243
IVtable m_POWERClamp
Definition: kibis.h:269
TypMinMaxValue m_pullupReference
Definition: kibis.h:260
std::vector< std::pair< IbisWaveform *, IbisWaveform * > > waveformPairs()
Create waveform pairs.
Definition: kibis.cpp:343
TypMinMaxValue m_POWERClampReference
Definition: kibis.h:263
TypMinMaxValue m_C_comp
Definition: kibis.h:257
IVtable m_pulldown
Definition: kibis.h:271
double m_vinl
Definition: kibis.h:247
IBIS_CORNER m_supply
Definition: kibis.h:188
IBIS_CORNER m_Cpin
Definition: kibis.h:186
KIBIS_ACCURACY m_accuracy
Definition: kibis.h:190
IBIS_CORNER m_Ccomp
Definition: kibis.h:187
IBIS_CORNER m_Lpin
Definition: kibis.h:185
IBIS_CORNER m_Rpin
Definition: kibis.h:184
void SetCornerFromString(IBIS_CORNER &aCorner, std::string aString)
Definition: kibis.cpp:1429
KIBIS_WAVEFORM * m_waveform
Definition: kibis.h:189
bool writeSpiceDiffDriver(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1312
TypMinMaxValue m_Rpin
Resistance from die to pin.
Definition: kibis.h:347
TypMinMaxValue m_Lpin
Inductance from die to pin.
Definition: kibis.h:349
bool writeSpiceDiffDevice(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1363
std::string addDie(KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam, int aIndex)
Generate the spice directive to simulate the die for Ku/Kd estimation.
Definition: kibis.cpp:615
KIBIS_PIN(KIBIS *aTopLevel, IbisComponentPin &aPin, IbisComponentPackage &aPackage, IbisParser &aParser, KIBIS_COMPONENT *aParent, std::vector< KIBIS_MODEL > &aModels)
Definition: kibis.cpp:162
KIBIS_COMPONENT * m_parent
Definition: kibis.h:353
std::vector< double > m_Ku
Definition: kibis.h:355
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition: kibis.h:344
std::vector< KIBIS_MODEL * > m_models
Definition: kibis.h:357
std::vector< double > m_t
Definition: kibis.h:355
std::string KuKdDriver(KIBIS_MODEL &aModel, std::pair< IbisWaveform *, IbisWaveform * > aPair, KIBIS_PARAMETER &aParam, int aIndex)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:751
void getKuKdFromFile(std::string *aSimul)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:667
TypMinMaxValue m_Cpin
Capacitance from pin to GND.
Definition: kibis.h:351
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition: kibis.h:340
void getKuKdTwoWaveforms(KIBIS_MODEL &aModel, std::pair< IbisWaveform *, IbisWaveform * > aPair1, std::pair< IbisWaveform *, IbisWaveform * > aPair2, KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:996
void getKuKdOneWaveform(KIBIS_MODEL &aModel, std::pair< IbisWaveform *, IbisWaveform * > aPair, KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using with a single waveform input.
Definition: kibis.cpp:825
void getKuKdNoWaveform(KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using no falling / rising waveform inputs ( low accuracy )
Definition: kibis.cpp:934
bool writeSpiceDriver(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1138
std::vector< double > m_Kd
Definition: kibis.h:355
bool isDiffPin()
Definition: kibis.h:433
bool writeSpiceDevice(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1260
KIBIS_PIN * m_complementaryPin
Definition: kibis.h:431
KIBIS_WAVEFORM_HIGH_Z(KIBIS *aTopLevel)
Definition: kibis.h:148
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1459
double m_delay
Definition: kibis.h:115
bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf) override
Definition: kibis.cpp:1637
double GetDuration() override
Definition: kibis.h:122
double m_bitrate
Definition: kibis.h:114
KIBIS_WAVEFORM_PRBS(KIBIS *aTopLevel)
Definition: kibis.h:110
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1484
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1465
bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf) override
Definition: kibis.cpp:1518
KIBIS_WAVEFORM_RECTANGULAR(KIBIS *aTopLevel)
Definition: kibis.h:89
double GetDuration() override
Definition: kibis.h:103
KIBIS_WAVEFORM_STUCK_HIGH(KIBIS *aTopLevel)
Definition: kibis.h:128
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1440
KIBIS_WAVEFORM_STUCK_LOW(KIBIS *aTopLevel)
Definition: kibis.h:138
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1450
KIBIS_WAVEFORM_TYPE m_type
Definition: kibis.h:83
virtual ~KIBIS_WAVEFORM()
Definition: kibis.h:69
virtual std::vector< std::pair< int, double > > GenerateBitSequence()
Definition: kibis.h:71
KIBIS_WAVEFORM(KIBIS *aTopLevel)
Definition: kibis.h:65
virtual double GetDuration()
Definition: kibis.h:67
virtual bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf)
Definition: kibis.h:78
KIBIS_WAVEFORM_TYPE GetType()
Definition: kibis.h:66
virtual bool Check(dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp)
Definition: kibis.h:80
bool inverted
Definition: kibis.h:68
Definition: kibis.h:215
std::vector< KIBIS_MODEL > m_models
Definition: kibis.h:225
IBIS_REPORTER * m_reporter
Definition: kibis.h:223
KIBIS()
Definition: kibis.h:217
KIBIS_COMPONENT * GetComponent(std::string aName)
Return the component with name aName .
Definition: kibis.cpp:1418
std::vector< KIBIS_COMPONENT > m_components
Definition: kibis.h:224
KIBIS_MODEL * GetModel(std::string aName)
Return the model with name aName .
Definition: kibis.cpp:1407
KIBIS_FILE m_file
Definition: kibis.h:226
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
Definition: kibis.h:229
IBIS_MODEL_TYPE
Definition: ibis_parser.h:425
#define IBIS_REPORTER
Definition: ibis_parser.h:52
IBIS_MODEL_POLARITY
Definition: ibis_parser.h:511
IBIS_CORNER
Definition: ibis_parser.h:95
@ TYP
Definition: ibis_parser.h:96
IBIS_MODEL_ENABLE
Definition: ibis_parser.h:447
KIBIS_ACCURACY
Accuracy level.
Definition: kibis.h:174
KIBIS_WAVEFORM_TYPE
Definition: kibis.h:52
@ STUCK_LOW
Definition: kibis.h:57
@ HIGH_Z
Definition: kibis.h:58
@ NONE
Definition: kibis.h:53
@ PRBS
Definition: kibis.h:54
@ RECTANGULAR
Definition: kibis.h:55
@ STUCK_HIGH
Definition: kibis.h:56