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{
46public:
47 KIBIS_ANY( KIBIS* aTopLevel );
49 bool m_valid;
50};
51
53{
54 NONE = 0, // Used for three state
59 HIGH_Z
60};
61
62
64{
65public:
66 KIBIS_WAVEFORM( KIBIS* aTopLevel ) : KIBIS_ANY{ aTopLevel } { m_valid = true; };
68 virtual double GetDuration() { return 1; };
69 bool inverted = false; // Used for differential drivers
70 virtual ~KIBIS_WAVEFORM(){};
71
72 virtual std::vector<std::pair<int, double>> GenerateBitSequence()
73 {
74 std::vector<std::pair<int, double>> bits;
75 return bits;
76 };
77
78 // Check fuction if using waveform data
79 virtual bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) { return true; };
80 // Check fuction if using ramp data
81 virtual bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) { return true; };
82
83protected:
84 KIBIS_WAVEFORM_TYPE m_type = KIBIS_WAVEFORM_TYPE::NONE;
85};
86
88{
89public:
90 KIBIS_WAVEFORM_RECTANGULAR( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
91 {
92 m_type = KIBIS_WAVEFORM_TYPE::RECTANGULAR;
93 };
94 double m_ton = 100e-9;
95 double m_toff = 100e-9;
96 double m_delay = 0;
97 int m_cycles = 1;
98
99
100 std::vector<std::pair<int, double>> GenerateBitSequence() override;
101 bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) override;
102 bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) override;
103
104 double GetDuration() override { return ( m_ton + m_toff ) * m_cycles; };
105};
106
107// For now, we only support PRBS7
109{
110public:
111 KIBIS_WAVEFORM_PRBS( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
112 {
113 m_type = KIBIS_WAVEFORM_TYPE::PRBS;
114 };
115 double m_bitrate = 10e6;
116 double m_delay = 0;
117 int m_bits = 10;
118
119 std::vector<std::pair<int, double>> GenerateBitSequence() override;
120 bool Check( IbisWaveform* aRisingWf, IbisWaveform* aFallingWf ) override;
121 bool Check( dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp ) override;
122
123 double GetDuration() override { return m_bits / m_bitrate ; };
124};
125
127{
128public:
129 KIBIS_WAVEFORM_STUCK_HIGH( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
130 {
131 m_type = KIBIS_WAVEFORM_TYPE::STUCK_HIGH;
132 };
133 std::vector<std::pair<int, double>> GenerateBitSequence() override;
134};
135
137{
138public:
139 KIBIS_WAVEFORM_STUCK_LOW( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
140 {
141 m_type = KIBIS_WAVEFORM_TYPE::STUCK_LOW;
142 };
143 std::vector<std::pair<int, double>> GenerateBitSequence() override;
144};
145
147{
148public:
149 KIBIS_WAVEFORM_HIGH_Z( KIBIS* aTopLevel ) : KIBIS_WAVEFORM( aTopLevel )
150 {
151 m_type = KIBIS_WAVEFORM_TYPE::HIGH_Z;
152 };
153 std::vector<std::pair<int, double>> GenerateBitSequence() override;
154};
155
175{
176 LEVEL_0,
177 LEVEL_1,
178 LEVEL_2,
179 LEVEL_3,
180};
181
183{
184public:
185 IBIS_CORNER m_Rpin = IBIS_CORNER::TYP;
186 IBIS_CORNER m_Lpin = IBIS_CORNER::TYP;
187 IBIS_CORNER m_Cpin = IBIS_CORNER::TYP;
188 IBIS_CORNER m_Ccomp = IBIS_CORNER::TYP;
189 IBIS_CORNER m_supply = IBIS_CORNER::TYP;
191 KIBIS_ACCURACY m_accuracy = KIBIS_ACCURACY::LEVEL_2;
192
193 void SetCornerFromString( IBIS_CORNER& aCorner, std::string aString );
194};
195
196
198{
199public:
200 KIBIS_FILE( KIBIS* aTopLevel );
201
202 std::string m_fileName;
203 double m_fileRev;
205 std::string m_date;
206 std::string m_source;
207 std::string m_notes;
208 std::string m_disclaimer;
209 std::string m_copyright;
210
211 bool Init( IbisParser& aParser );
212};
213
214class KIBIS_MODEL : public KIBIS_ANY
215{
216public:
217 KIBIS_MODEL( KIBIS* aTopLevel, IbisModel& aSource, IbisParser& aParser );
218
219 std::string m_name;
220 std::string m_description;
221 IBIS_MODEL_TYPE m_type = IBIS_MODEL_TYPE::UNDEFINED;
222 /* The Polarity, Enable, Vinl, Vinh, Vmeas, Cref, Rref, and Vref subparameters are optional. */
223 /* the default values of Vinl = 0.8 V and Vinh = 2.0 V are assumed. */
224 double m_vinl = 0.8;
225 double m_vinh = 2;
226 double m_vref = 0;
227 double m_rref = 0;
228 double m_cref = 0;
229 double m_vmeas = 0;
230 IBIS_MODEL_ENABLE m_enable = IBIS_MODEL_ENABLE::UNDEFINED;
231 IBIS_MODEL_POLARITY m_polarity = IBIS_MODEL_POLARITY::UNDEFINED;
232 // End of optional subparameters
233
249 std::vector<IbisWaveform*> m_risingWaveforms;
250 std::vector<IbisWaveform*> m_fallingWaveforms;
252
254 bool HasPulldown();
256 bool HasPullup();
258 bool HasGNDClamp();
260 bool HasPOWERClamp();
261
268 std::string SpiceDie( KIBIS_PARAMETER& aParam, int aIndex );
269
278 std::vector<std::pair<IbisWaveform*, IbisWaveform*>> waveformPairs();
279
280
294 std::string generateSquareWave( std::string aNode1, std::string aNode2,
295 std::vector<std::pair<int, double>> aBits,
296 std::pair<IbisWaveform*, IbisWaveform*> aPair,
297 KIBIS_PARAMETER& aParam );
298
299
307};
308
309class KIBIS_PIN : public KIBIS_ANY
310{
311public:
312 KIBIS_PIN( KIBIS* aTopLevel, IbisComponentPin& aPin, IbisComponentPackage& aPackage,
313 IbisParser& aParser, KIBIS_COMPONENT* aParent, std::vector<KIBIS_MODEL>& aModels );
317 std::string m_signalName;
321 std::string m_pinNumber;
322
329
331
332 std::vector<double> m_t, m_Ku, m_Kd;
333
334 std::vector<KIBIS_MODEL*> m_models;
335
336 bool writeSpiceDriver( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
337 KIBIS_PARAMETER& aParam );
338 bool writeSpiceDiffDriver( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
339 KIBIS_PARAMETER& aParam );
340 bool writeSpiceDevice( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
341 KIBIS_PARAMETER& aParam );
342 bool writeSpiceDiffDevice( std::string* aDest, std::string aName, KIBIS_MODEL& aModel,
343 KIBIS_PARAMETER& aParam );
344
349 void getKuKdNoWaveform( KIBIS_MODEL& aModel, KIBIS_PARAMETER& aParam );
350
356 void getKuKdOneWaveform( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair,
357 KIBIS_PARAMETER& aParam );
358
368 void getKuKdTwoWaveforms( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair1,
369 std::pair<IbisWaveform*, IbisWaveform*> aPair2,
370 KIBIS_PARAMETER& aParam );
371
382 std::string KuKdDriver( KIBIS_MODEL& aModel, std::pair<IbisWaveform*, IbisWaveform*> aPair,
383 KIBIS_PARAMETER& aParam, int aIndex );
384
395 std::string addDie( KIBIS_MODEL& aModel, KIBIS_PARAMETER& aParam, int aIndex );
396
397
406 void getKuKdFromFile( std::string* aSimul );
407
409
410 bool isDiffPin() { return m_complementaryPin != nullptr; };
411};
412
414{
415public:
416 KIBIS_COMPONENT( KIBIS* aToplevel, IbisComponent& aSource, IbisParser& aParser );
418 std::string m_name;
420 std::string m_manufacturer;
421
422 std::vector<KIBIS_PIN> m_pins;
423
429 KIBIS_PIN* GetPin( std::string aPinNumber );
430};
431
432class KIBIS : public KIBIS_ANY
433{
434public:
435 KIBIS() : KIBIS_ANY( this ), m_file( this )
436 {
437 m_valid = false;
438 }; // Constructor for unitialized KIBIS members
439
440 KIBIS( std::string aFileName, REPORTER* aReporter = nullptr );
441
443 std::vector<KIBIS_COMPONENT> m_components;
444 std::vector<KIBIS_MODEL> m_models;
446
448 std::string m_cacheDir = "";
449
451 KIBIS_MODEL* GetModel( std::string aName );
453 KIBIS_COMPONENT* GetComponent( std::string aName );
454};
455
456#endif
bool m_valid
Definition: kibis.h:49
KIBIS * m_topLevel
Definition: kibis.h:48
std::vector< KIBIS_PIN > m_pins
Definition: kibis.h:422
KIBIS_PIN * GetPin(std::string aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
Definition: kibis.cpp:331
std::string m_manufacturer
Name of the manufacturer.
Definition: kibis.h:420
std::string m_name
Name of the component.
Definition: kibis.h:418
bool Init(IbisParser &aParser)
Definition: kibis.cpp:146
std::string m_source
Definition: kibis.h:206
std::string m_notes
Definition: kibis.h:207
double m_ibisVersion
Definition: kibis.h:204
std::string m_date
Definition: kibis.h:205
std::string m_fileName
Definition: kibis.h:202
std::string m_copyright
Definition: kibis.h:209
std::string m_disclaimer
Definition: kibis.h:208
double m_fileRev
Definition: kibis.h:203
std::vector< IbisWaveform * > m_fallingWaveforms
Definition: kibis.h:250
IBIS_MODEL_ENABLE m_enable
Definition: kibis.h:230
double m_vref
Definition: kibis.h:226
std::string m_name
Definition: kibis.h:219
bool HasPulldown()
Return true if the model has a pulldown transistor.
Definition: kibis.cpp:488
double m_vmeas
Definition: kibis.h:229
std::vector< IbisWaveform * > m_risingWaveforms
Definition: kibis.h:249
TypMinMaxValue m_Cac
Definition: kibis.h:244
double m_vinh
Definition: kibis.h:225
bool HasPOWERClamp()
Return true if the model has a clamp diode to the power net.
Definition: kibis.cpp:506
double m_rref
Definition: kibis.h:227
TypMinMaxValue m_pulldownReference
Definition: kibis.h:238
TypMinMaxValue m_GNDClampReference
Definition: kibis.h:239
TypMinMaxValue m_Rpower
Definition: kibis.h:242
bool HasPullup()
Return true if the model has a pullup transistor.
Definition: kibis.cpp:494
IBIS_MODEL_TYPE m_type
Definition: kibis.h:221
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:512
IbisRamp m_ramp
Definition: kibis.h:251
IVtable m_pullup
Definition: kibis.h:247
IBIS_MODEL_POLARITY m_polarity
Definition: kibis.h:231
double m_cref
Definition: kibis.h:228
TypMinMaxValue m_Rac
Definition: kibis.h:243
TypMinMaxValue m_temperatureRange
Definition: kibis.h:236
TypMinMaxValue m_voltageRange
Definition: kibis.h:235
IVtable m_GNDClamp
Definition: kibis.h:245
std::string SpiceDie(KIBIS_PARAMETER &aParam, int aIndex)
Generate the spice directive to simulate the die.
Definition: kibis.cpp:374
IbisWaveform TrimWaveform(IbisWaveform &aIn)
Copy a waveform, and substract the first value to all samples.
Definition: kibis.cpp:447
TypMinMaxValue m_Rgnd
Definition: kibis.h:241
bool HasGNDClamp()
Return true if the model has a clamp diode to the gnd net.
Definition: kibis.cpp:500
std::string m_description
Definition: kibis.h:220
IVtable m_POWERClamp
Definition: kibis.h:246
TypMinMaxValue m_pullupReference
Definition: kibis.h:237
std::vector< std::pair< IbisWaveform *, IbisWaveform * > > waveformPairs()
Create waveform pairs.
Definition: kibis.cpp:344
TypMinMaxValue m_POWERClampReference
Definition: kibis.h:240
TypMinMaxValue m_C_comp
Definition: kibis.h:234
IVtable m_pulldown
Definition: kibis.h:248
double m_vinl
Definition: kibis.h:224
IBIS_CORNER m_supply
Definition: kibis.h:189
IBIS_CORNER m_Cpin
Definition: kibis.h:187
KIBIS_ACCURACY m_accuracy
Definition: kibis.h:191
IBIS_CORNER m_Ccomp
Definition: kibis.h:188
IBIS_CORNER m_Lpin
Definition: kibis.h:186
IBIS_CORNER m_Rpin
Definition: kibis.h:185
void SetCornerFromString(IBIS_CORNER &aCorner, std::string aString)
Definition: kibis.cpp:1426
KIBIS_WAVEFORM * m_waveform
Definition: kibis.h:190
bool writeSpiceDiffDriver(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1309
TypMinMaxValue m_Rpin
Resistance from die to pin.
Definition: kibis.h:324
TypMinMaxValue m_Lpin
Inductance from die to pin.
Definition: kibis.h:326
bool writeSpiceDiffDevice(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1360
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:616
KIBIS_COMPONENT * m_parent
Definition: kibis.h:330
std::vector< double > m_Ku
Definition: kibis.h:332
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition: kibis.h:321
std::vector< KIBIS_MODEL * > m_models
Definition: kibis.h:334
std::vector< double > m_t
Definition: kibis.h:332
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:748
void getKuKdFromFile(std::string *aSimul)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:668
TypMinMaxValue m_Cpin
Capacitance from pin to GND.
Definition: kibis.h:328
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition: kibis.h:317
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:993
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:822
void getKuKdNoWaveform(KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Update m_Ku, m_Kd using no falling / rising waveform inputs ( low accuracy )
Definition: kibis.cpp:931
bool writeSpiceDriver(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1135
std::vector< double > m_Kd
Definition: kibis.h:332
bool isDiffPin()
Definition: kibis.h:410
bool writeSpiceDevice(std::string *aDest, std::string aName, KIBIS_MODEL &aModel, KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1257
KIBIS_PIN * m_complementaryPin
Definition: kibis.h:408
KIBIS_WAVEFORM_HIGH_Z(KIBIS *aTopLevel)
Definition: kibis.h:149
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1456
double m_delay
Definition: kibis.h:116
bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf) override
Definition: kibis.cpp:1634
double GetDuration() override
Definition: kibis.h:123
double m_bitrate
Definition: kibis.h:115
KIBIS_WAVEFORM_PRBS(KIBIS *aTopLevel)
Definition: kibis.h:111
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1481
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1462
bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf) override
Definition: kibis.cpp:1515
KIBIS_WAVEFORM_RECTANGULAR(KIBIS *aTopLevel)
Definition: kibis.h:90
double GetDuration() override
Definition: kibis.h:104
KIBIS_WAVEFORM_STUCK_HIGH(KIBIS *aTopLevel)
Definition: kibis.h:129
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1437
KIBIS_WAVEFORM_STUCK_LOW(KIBIS *aTopLevel)
Definition: kibis.h:139
std::vector< std::pair< int, double > > GenerateBitSequence() override
Definition: kibis.cpp:1447
KIBIS_WAVEFORM_TYPE m_type
Definition: kibis.h:84
virtual ~KIBIS_WAVEFORM()
Definition: kibis.h:70
virtual std::vector< std::pair< int, double > > GenerateBitSequence()
Definition: kibis.h:72
KIBIS_WAVEFORM(KIBIS *aTopLevel)
Definition: kibis.h:66
virtual double GetDuration()
Definition: kibis.h:68
virtual bool Check(IbisWaveform *aRisingWf, IbisWaveform *aFallingWf)
Definition: kibis.h:79
KIBIS_WAVEFORM_TYPE GetType()
Definition: kibis.h:67
virtual bool Check(dvdtTypMinMax aRisingRp, dvdtTypMinMax aFallingRp)
Definition: kibis.h:81
bool inverted
Definition: kibis.h:69
Definition: kibis.h:433
std::vector< KIBIS_MODEL > m_models
Definition: kibis.h:444
KIBIS()
Definition: kibis.h:435
KIBIS_COMPONENT * GetComponent(std::string aName)
Return the component with name aName .
Definition: kibis.cpp:1415
std::vector< KIBIS_COMPONENT > m_components
Definition: kibis.h:443
KIBIS_MODEL * GetModel(std::string aName)
Return the model with name aName .
Definition: kibis.cpp:1404
KIBIS_FILE m_file
Definition: kibis.h:445
REPORTER * m_reporter
Definition: kibis.h:442
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
Definition: kibis.h:448
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
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:175
KIBIS_WAVEFORM_TYPE
Definition: kibis.h:53
@ STUCK_LOW
Definition: kibis.h:58
@ HIGH_Z
Definition: kibis.h:59
@ NONE
Definition: kibis.h:54
@ PRBS
Definition: kibis.h:55
@ RECTANGULAR
Definition: kibis.h:56
@ STUCK_HIGH
Definition: kibis.h:57