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 The 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_BASE : public IBIS_BASE
45{
46protected:
47 KIBIS_BASE( KIBIS* aTopLevel );
48
53 KIBIS_BASE( 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 ) :
75 KIBIS_BASE{ &aTopLevel }
76 {
77 m_valid = true;
78 };
79
80 KIBIS_WAVEFORM_TYPE GetType() const { return m_type; };
81 virtual double GetDuration() const { return 1; };
82 bool inverted = false; // Used for differential drivers
83 virtual ~KIBIS_WAVEFORM() {};
84
85 virtual std::vector<std::pair<int, double>> GenerateBitSequence() const
86 {
87 std::vector<std::pair<int, double>> bits;
88 return bits;
89 };
90
91 // Check function if using waveform data
92 virtual bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const
93 {
94 return true;
95 };
96 // Check function if using ramp data
97 virtual bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const
98 {
99 return true;
100 };
101
102protected:
103 KIBIS_WAVEFORM_TYPE m_type = KIBIS_WAVEFORM_TYPE::NONE;
104};
105
107{
108public:
110 KIBIS_WAVEFORM( aTopLevel )
111 {
112 m_type = KIBIS_WAVEFORM_TYPE::RECTANGULAR;
113 };
114
115 double m_ton = 100e-9;
116 double m_toff = 100e-9;
117 double m_delay = 0;
118 int m_cycles = 1;
119
120
121 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
122 bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const override;
123 bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const override;
124
125 double GetDuration() const override { return ( m_ton + m_toff ) * m_cycles; };
126};
127
128// For now, we only support PRBS7
130{
131public:
133 KIBIS_WAVEFORM( aTopLevel )
134 {
135 m_type = KIBIS_WAVEFORM_TYPE::PRBS;
136 };
137
138 double m_bitrate = 10e6;
139 double m_delay = 0;
140 int m_bits = 10;
141
142 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
143 bool Check( const IbisWaveform* aRisingWf, const IbisWaveform* aFallingWf ) const override;
144 bool Check( const dvdtTypMinMax& aRisingRp, const dvdtTypMinMax& aFallingRp ) const override;
145
146 void SetBits( int aBits ) { m_bits = std::abs( aBits ); };
147
148 double GetDuration() const override { return m_bits / m_bitrate; };
149};
150
152{
153public:
155 KIBIS_WAVEFORM( aTopLevel )
156 {
157 m_type = KIBIS_WAVEFORM_TYPE::STUCK_HIGH;
158 };
159
160 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
161};
162
164{
165public:
167 KIBIS_WAVEFORM( aTopLevel )
168 {
169 m_type = KIBIS_WAVEFORM_TYPE::STUCK_LOW;
170 };
171
172 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
173};
174
176{
177public:
179 KIBIS_WAVEFORM( aTopLevel )
180 {
181 m_type = KIBIS_WAVEFORM_TYPE::HIGH_Z;
182 };
183
184 std::vector<std::pair<int, double>> GenerateBitSequence() const override;
185};
186
206{
207 LEVEL_0,
208 LEVEL_1,
209 LEVEL_2,
210 LEVEL_3,
211};
212
214{
215public:
216 IBIS_CORNER m_Rpin = IBIS_CORNER::TYP;
217 IBIS_CORNER m_Lpin = IBIS_CORNER::TYP;
218 IBIS_CORNER m_Cpin = IBIS_CORNER::TYP;
219 IBIS_CORNER m_Ccomp = IBIS_CORNER::TYP;
220 IBIS_CORNER m_supply = IBIS_CORNER::TYP;
222 KIBIS_ACCURACY m_accuracy = KIBIS_ACCURACY::LEVEL_2;
223
224 void SetCornerFromString( IBIS_CORNER& aCorner, const std::string& aString );
225};
226
227
229{
230public:
231 KIBIS_FILE( KIBIS& aTopLevel );
232
233 std::string m_fileName;
234 double m_fileRev;
236 std::string m_date;
237 std::string m_source;
238 std::string m_notes;
239 std::string m_disclaimer;
240 std::string m_copyright;
241
242 bool Init( const IbisParser& aParser );
243};
244
246{
247public:
248 KIBIS_MODEL( KIBIS& aTopLevel, const IbisModel& aSource, IbisParser& aParser );
249
250 std::string m_name;
251 std::string m_description;
252 IBIS_MODEL_TYPE m_type = IBIS_MODEL_TYPE::UNDEFINED;
253 /* The Polarity, Enable, Vinl, Vinh, Vmeas, Cref, Rref, and Vref subparameters are optional. */
254 /* the default values of Vinl = 0.8 V and Vinh = 2.0 V are assumed. */
255 double m_vinl = 0.8;
256 double m_vinh = 2;
257 double m_vref = 0;
258 double m_rref = 0;
259 double m_cref = 0;
260 double m_vmeas = 0;
261 IBIS_MODEL_ENABLE m_enable = IBIS_MODEL_ENABLE::UNDEFINED;
262 IBIS_MODEL_POLARITY m_polarity = IBIS_MODEL_POLARITY::UNDEFINED;
263 // End of optional subparameters
264
280 std::vector<IbisWaveform*> m_risingWaveforms;
281 std::vector<IbisWaveform*> m_fallingWaveforms;
283
285 bool HasPulldown() const;
287 bool HasPullup() const;
289 bool HasGNDClamp() const;
291 bool HasPOWERClamp() const;
292
299 std::string SpiceDie( const KIBIS_PARAMETER& aParam, int aIndex ) const;
300
309 std::vector<std::pair<IbisWaveform*, IbisWaveform*>> waveformPairs();
310
311
325 std::string generateSquareWave( const std::string& aNode1, const std::string& aNode2,
326 const std::vector<std::pair<int, double>>& aBits,
327 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
328 const KIBIS_PARAMETER& aParam );
329
330
337 IbisWaveform TrimWaveform( const IbisWaveform& aIn ) const;
338};
339
340class KIBIS_PIN : public KIBIS_BASE
341{
342public:
343 KIBIS_PIN( KIBIS& aTopLevel, const IbisComponentPin& aPin, const IbisComponentPackage& aPackage,
344 IbisParser& aParser, KIBIS_COMPONENT* aParent, std::vector<KIBIS_MODEL>& aModels );
348 std::string m_signalName;
352 std::string m_pinNumber;
353
360
362
363 std::vector<double> m_t, m_Ku, m_Kd;
364
365 std::vector<KIBIS_MODEL*> m_models;
366
367 bool writeSpiceDriver( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
368 const KIBIS_PARAMETER& aParam );
369 bool writeSpiceDiffDriver( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
370 const KIBIS_PARAMETER& aParam );
371 bool writeSpiceDevice( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
372 const KIBIS_PARAMETER& aParam );
373 bool writeSpiceDiffDevice( std::string& aDest, const std::string& aName, KIBIS_MODEL& aModel,
374 const KIBIS_PARAMETER& aParam );
375
380 void getKuKdNoWaveform( KIBIS_MODEL& aModel, const KIBIS_PARAMETER& aParam );
381
387 void getKuKdOneWaveform( KIBIS_MODEL& aModel,
388 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
389 const KIBIS_PARAMETER& aParam );
390
400 void getKuKdTwoWaveforms( KIBIS_MODEL& aModel,
401 const std::pair<IbisWaveform*, IbisWaveform*>& aPair1,
402 const std::pair<IbisWaveform*, IbisWaveform*>& aPair2,
403 const KIBIS_PARAMETER& aParam );
404
415 std::string KuKdDriver( KIBIS_MODEL& aModel,
416 const std::pair<IbisWaveform*, IbisWaveform*>& aPair,
417 const KIBIS_PARAMETER& aParam, int aIndex );
418
429 std::string addDie( KIBIS_MODEL& aModel, const KIBIS_PARAMETER& aParam, int aIndex );
430
431
440 void getKuKdFromFile( const std::string& aSimul );
441
443
444 bool isDiffPin() const { return m_complementaryPin != nullptr; };
445};
446
448{
449public:
450 KIBIS_COMPONENT( KIBIS& aToplevel, const IbisComponent& aSource, IbisParser& aParser );
452 std::string m_name;
454 std::string m_manufacturer;
455
456 std::vector<KIBIS_PIN> m_pins;
457
463 KIBIS_PIN* GetPin( const std::string& aPinNumber );
464};
465
466class KIBIS : public KIBIS_BASE
467{
468public:
471 KIBIS_BASE( this, nullptr ),
472 m_file( *this )
473 {};
474
475 KIBIS( const std::string& aFileName, REPORTER* aReporter = nullptr );
476
477 std::vector<KIBIS_COMPONENT> m_components;
478 std::vector<KIBIS_MODEL> m_models;
480
482 std::string m_cacheDir = "";
483
485 KIBIS_MODEL* GetModel( const std::string& aName );
487 KIBIS_COMPONENT* GetComponent( const std::string& aName );
488};
489
490#endif
bool m_valid
Definition: kibis.h:57
KIBIS * m_topLevel
Definition: kibis.h:56
std::vector< KIBIS_PIN > m_pins
Definition: kibis.h:456
std::string m_manufacturer
Name of the manufacturer.
Definition: kibis.h:454
std::string m_name
Name of the component.
Definition: kibis.h:452
KIBIS_PIN * GetPin(const std::string &aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
Definition: kibis.cpp:330
std::string m_source
Definition: kibis.h:237
std::string m_notes
Definition: kibis.h:238
double m_ibisVersion
Definition: kibis.h:235
std::string m_date
Definition: kibis.h:236
bool Init(const IbisParser &aParser)
Definition: kibis.cpp:145
std::string m_fileName
Definition: kibis.h:233
std::string m_copyright
Definition: kibis.h:240
std::string m_disclaimer
Definition: kibis.h:239
double m_fileRev
Definition: kibis.h:234
std::vector< IbisWaveform * > m_fallingWaveforms
Definition: kibis.h:281
IbisWaveform TrimWaveform(const IbisWaveform &aIn) const
Copy a waveform, and substract the first value to all samples.
Definition: kibis.cpp:441
IBIS_MODEL_ENABLE m_enable
Definition: kibis.h:261
double m_vref
Definition: kibis.h:257
std::string m_name
Definition: kibis.h:250
bool HasPOWERClamp() const
Return true if the model has a clamp diode to the power net.
Definition: kibis.cpp:495
double m_vmeas
Definition: kibis.h:260
std::vector< IbisWaveform * > m_risingWaveforms
Definition: kibis.h:280
TypMinMaxValue m_Cac
Definition: kibis.h:275
double m_vinh
Definition: kibis.h:256
double m_rref
Definition: kibis.h:258
bool HasPullup() const
Return true if the model has a pullup transistor.
Definition: kibis.cpp:483
bool HasGNDClamp() const
Return true if the model has a clamp diode to the gnd net.
Definition: kibis.cpp:489
TypMinMaxValue m_pulldownReference
Definition: kibis.h:269
TypMinMaxValue m_GNDClampReference
Definition: kibis.h:270
TypMinMaxValue m_Rpower
Definition: kibis.h:273
bool HasPulldown() const
Return true if the model has a pulldown transistor.
Definition: kibis.cpp:477
IBIS_MODEL_TYPE m_type
Definition: kibis.h:252
IbisRamp m_ramp
Definition: kibis.h:282
IVtable m_pullup
Definition: kibis.h:278
IBIS_MODEL_POLARITY m_polarity
Definition: kibis.h:262
double m_cref
Definition: kibis.h:259
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:501
TypMinMaxValue m_Rac
Definition: kibis.h:274
TypMinMaxValue m_temperatureRange
Definition: kibis.h:267
TypMinMaxValue m_voltageRange
Definition: kibis.h:266
IVtable m_GNDClamp
Definition: kibis.h:276
TypMinMaxValue m_Rgnd
Definition: kibis.h:272
std::string m_description
Definition: kibis.h:251
IVtable m_POWERClamp
Definition: kibis.h:277
TypMinMaxValue m_pullupReference
Definition: kibis.h:268
std::vector< std::pair< IbisWaveform *, IbisWaveform * > > waveformPairs()
Create waveform pairs.
Definition: kibis.cpp:341
TypMinMaxValue m_POWERClampReference
Definition: kibis.h:271
TypMinMaxValue m_C_comp
Definition: kibis.h:265
std::string SpiceDie(const KIBIS_PARAMETER &aParam, int aIndex) const
Generate the spice directive to simulate the die.
Definition: kibis.cpp:368
IVtable m_pulldown
Definition: kibis.h:279
double m_vinl
Definition: kibis.h:255
IBIS_CORNER m_supply
Definition: kibis.h:220
IBIS_CORNER m_Cpin
Definition: kibis.h:218
KIBIS_ACCURACY m_accuracy
Definition: kibis.h:222
IBIS_CORNER m_Ccomp
Definition: kibis.h:219
IBIS_CORNER m_Lpin
Definition: kibis.h:217
IBIS_CORNER m_Rpin
Definition: kibis.h:216
void SetCornerFromString(IBIS_CORNER &aCorner, const std::string &aString)
Definition: kibis.cpp:1372
KIBIS_WAVEFORM * m_waveform
Definition: kibis.h:221
bool isDiffPin() const
Definition: kibis.h:444
TypMinMaxValue m_Rpin
Resistance from die to pin.
Definition: kibis.h:355
bool writeSpiceDiffDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1281
TypMinMaxValue m_Lpin
Inductance from die to pin.
Definition: kibis.h:357
void getKuKdFromFile(const std::string &aSimul)
Update m_Ku, m_Kd using with two waveform inputs.
Definition: kibis.cpp:646
KIBIS_COMPONENT * m_parent
Definition: kibis.h:361
std::vector< double > m_Ku
Definition: kibis.h:363
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition: kibis.h:352
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:602
bool writeSpiceDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1228
std::vector< KIBIS_MODEL * > m_models
Definition: kibis.h:365
std::vector< double > m_t
Definition: kibis.h:363
TypMinMaxValue m_Cpin
Capacitance from pin to GND.
Definition: kibis.h:359
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition: kibis.h:348
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:969
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:797
bool writeSpiceDiffDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1318
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:721
std::vector< double > m_Kd
Definition: kibis.h:363
bool writeSpiceDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition: kibis.cpp:1113
KIBIS_PIN * m_complementaryPin
Definition: kibis.h:442
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:908
KIBIS_WAVEFORM_HIGH_Z(KIBIS &aTopLevel)
Definition: kibis.h:178
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1402
double m_delay
Definition: kibis.h:139
bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const override
Definition: kibis.cpp:1586
void SetBits(int aBits)
Definition: kibis.h:146
double GetDuration() const override
Definition: kibis.h:148
KIBIS_WAVEFORM_PRBS(KIBIS &aTopLevel)
Definition: kibis.h:132
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1428
double m_bitrate
Definition: kibis.h:138
bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const override
Definition: kibis.cpp:1464
double GetDuration() const override
Definition: kibis.h:125
KIBIS_WAVEFORM_RECTANGULAR(KIBIS &aTopLevel)
Definition: kibis.h:109
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1408
KIBIS_WAVEFORM_STUCK_HIGH(KIBIS &aTopLevel)
Definition: kibis.h:154
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1383
KIBIS_WAVEFORM_STUCK_LOW(KIBIS &aTopLevel)
Definition: kibis.h:166
std::vector< std::pair< int, double > > GenerateBitSequence() const override
Definition: kibis.cpp:1393
KIBIS_WAVEFORM_TYPE m_type
Definition: kibis.h:103
virtual ~KIBIS_WAVEFORM()
Definition: kibis.h:83
virtual bool Check(const dvdtTypMinMax &aRisingRp, const dvdtTypMinMax &aFallingRp) const
Definition: kibis.h:97
virtual bool Check(const IbisWaveform *aRisingWf, const IbisWaveform *aFallingWf) const
Definition: kibis.h:92
KIBIS_WAVEFORM_TYPE GetType() const
Definition: kibis.h:80
KIBIS_WAVEFORM(KIBIS &aTopLevel)
Definition: kibis.h:74
bool inverted
Definition: kibis.h:82
virtual double GetDuration() const
Definition: kibis.h:81
virtual std::vector< std::pair< int, double > > GenerateBitSequence() const
Definition: kibis.h:85
Definition: kibis.h:467
std::vector< KIBIS_MODEL > m_models
Definition: kibis.h:478
KIBIS()
Constructor for unitialized KIBIS members.
Definition: kibis.h:470
std::vector< KIBIS_COMPONENT > m_components
Definition: kibis.h:477
KIBIS_MODEL * GetModel(const std::string &aName)
Return the model with name aName .
Definition: kibis.cpp:1348
KIBIS_COMPONENT * GetComponent(const std::string &aName)
Return the component with name aName .
Definition: kibis.cpp:1360
KIBIS_FILE m_file
Definition: kibis.h:479
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
Definition: kibis.h:482
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
IBIS_MODEL_TYPE
Definition: ibis_parser.h:454
IBIS_MODEL_POLARITY
Definition: ibis_parser.h:548
IBIS_CORNER
Definition: ibis_parser.h:102
IBIS_MODEL_ENABLE
Definition: ibis_parser.h:476
KIBIS_ACCURACY
Accuracy level.
Definition: kibis.h:206
KIBIS_WAVEFORM_TYPE
Definition: kibis.h:61
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390