KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_model_ibis.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <sim/kibis/kibis.h>
21#include <sim/sim_model_ibis.h>
23#include <fmt/core.h>
24#include <paths.h>
25#include <wx/filename.h>
26#include <wx/file.h>
27#include <wx/log.h>
28#include <kiway.h>
29#include <schematic.h>
30#include "sim_lib_mgr.h"
31
32std::string SPICE_GENERATOR_IBIS::ModelName( const SPICE_ITEM& aItem ) const
33{
34 return fmt::format( "{}.{}", aItem.refName, aItem.baseModelName );
35}
36
37
38std::string SPICE_GENERATOR_IBIS::ModelLine( const SPICE_ITEM& aItem ) const
39{
40 return "";
41}
42
43std::vector<std::string> SPICE_GENERATOR_IBIS::CurrentNames( const SPICE_ITEM& aItem ) const
44{
45 std::vector<std::string> currentNames;
46
47 for( const SIM_MODEL_PIN& pin : GetPins() )
48 currentNames.push_back( fmt::format( "I({}:{})", ItemName( aItem ), pin.modelPinName ) );
49
50 return currentNames;
51}
52
53
54std::string SPICE_GENERATOR_IBIS::IbisDevice( const SPICE_ITEM& aItem, SCHEMATIC* aSchematic,
55 const wxString& aCacheDir, REPORTER& aReporter ) const
56{
57 std::string ibisLibFilename = GetFieldValue( &aItem.fields, SIM_LIBRARY::LIBRARY_FIELD, true, 0 );
58 std::string ibisCompName = GetFieldValue( &aItem.fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
59 std::string ibisPinName = GetFieldValue( &aItem.fields, SIM_LIBRARY_IBIS::PIN_FIELD, true, 0 );
60 std::string ibisModelName = GetFieldValue( &aItem.fields, SIM_LIBRARY_IBIS::MODEL_FIELD, true, 0 );
61 bool diffMode = GetFieldValue( &aItem.fields, SIM_LIBRARY_IBIS::DIFF_FIELD, true, 0 ) == "1";
62
64 SIM_LIB_MGR mgr( &aSchematic->Project() );
65
66 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
67 embeddedFilesStack.push_back( aSchematic->GetEmbeddedFiles() );
68 mgr.SetFilesStack( std::move( embeddedFilesStack ) );
69
70 wxString path = mgr.ResolveLibraryPath( ibisLibFilename, reporter );
71
72 if( reporter.HasMessage() )
73 THROW_IO_ERROR( reporter.GetMessages() );
74
75 KIBIS kibis( std::string( path.c_str() ) );
76 kibis.m_cacheDir = std::string( aCacheDir.c_str() );
77 kibis.m_Reporter = &aReporter;
78
79 if( !kibis.m_valid )
80 THROW_IO_ERRORF( _( "Invalid IBIS file '%s'" ), ibisLibFilename );
81
82 KIBIS_COMPONENT* kcomp = kibis.GetComponent( std::string( ibisCompName ) );
83
84 if( !kcomp )
85 THROW_IO_ERRORF( _( "Could not find IBIS component '%s'" ), ibisCompName );
86
87 KIBIS_PIN* kpin = kcomp->GetPin( ibisPinName );
88
89
90 if( !kcomp->m_valid )
91 THROW_IO_ERRORF( _( "Invalid IBIS component '%s'" ), ibisCompName );
92
93 if( !kpin )
94 THROW_IO_ERRORF( _( "Could not find IBIS pin '%s' in component '%s'" ), ibisPinName, ibisCompName );
95
96 if( !kpin->m_valid )
97 THROW_IO_ERRORF( _( "Invalid IBIS pin '%s' in component '%s'" ), ibisPinName, ibisCompName );
98
99 KIBIS_MODEL* kmodel = kibis.GetModel( ibisModelName );
100
101 if( !kmodel )
102 THROW_IO_ERRORF( _( "Could not find IBIS model '%s'" ), ibisModelName );
103
104 if( !kmodel->m_valid )
105 THROW_IO_ERRORF( _( "Invalid IBIS model '%s'" ), ibisModelName );
106
108
109 if( const SIM_MODEL::PARAM* vcc = m_model.FindParam( "vcc" ) )
110 kparams.SetCornerFromString( kparams.m_supply, vcc->value );
111
112 if( const SIM_MODEL::PARAM* rpin = m_model.FindParam( "rpin" ) )
113 kparams.SetCornerFromString( kparams.m_Rpin, rpin->value );
114
115 if( const SIM_MODEL::PARAM* lpin = m_model.FindParam( "lpin" ) )
116 kparams.SetCornerFromString( kparams.m_Lpin, lpin->value );
117
118 if( const SIM_MODEL::PARAM* cpin = m_model.FindParam( "cpin" ) )
119 kparams.SetCornerFromString( kparams.m_Cpin, cpin->value );
120
121 //kparams.SetCornerFromString( kparams.m_Ccomp, FindParam( "ccomp" )->value );
122
123 std::string result;
124
125 switch( m_model.GetType() )
126 {
127 case SIM_MODEL::TYPE::KIBIS_DEVICE:
128 if( diffMode )
129 kpin->writeSpiceDiffDevice( result, aItem.modelName, *kmodel, kparams );
130 else
131 kpin->writeSpiceDevice( result, aItem.modelName, *kmodel, kparams );
132
133 break;
134
135 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
136 {
137 std::string paramValue = "";
138
139 if( const SIM_MODEL::PARAM* dc = m_model.FindParam( "dc" ) )
140 paramValue = dc->value;
141
142 if( paramValue == "hi-Z" )
143 kparams.m_waveform = new KIBIS_WAVEFORM_HIGH_Z( kibis );
144 else if( paramValue == "low" )
145 kparams.m_waveform = new KIBIS_WAVEFORM_STUCK_LOW( kibis );
146 else if( paramValue == "high" )
147 kparams.m_waveform = new KIBIS_WAVEFORM_STUCK_HIGH( kibis );
148
149 if( diffMode )
150 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
151 else
152 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
153
154 break;
155 }
156
157 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
158 {
160
161 if( const SIM_MODEL::PARAM* ton = m_model.FindParam( "ton" ) )
162 waveform->m_ton = SIM_VALUE::ToDouble( ton->value, 0 );
163
164 if( const SIM_MODEL::PARAM* toff = m_model.FindParam( "toff" ) )
165 waveform->m_toff = SIM_VALUE::ToDouble( toff->value, 0 );
166
167 if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) )
168 waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 );
169
170 if( const SIM_MODEL::PARAM* n = m_model.FindParam( "n" ) )
171 waveform->m_cycles = SIM_VALUE::ToInt( n->value, 1 );
172
173 kparams.m_waveform = waveform;
174
175 if( diffMode )
176 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
177 else
178 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
179
180 break;
181 }
182
183 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
184 {
185 KIBIS_WAVEFORM_PRBS* waveform = new KIBIS_WAVEFORM_PRBS( kibis );
186
187 if( const SIM_MODEL::PARAM* f0 = m_model.FindParam( "f0" ) )
188 waveform->m_bitrate = SIM_VALUE::ToDouble( f0->value, 0 );
189
190 if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) )
191 waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 );
192
193 if( const SIM_MODEL::PARAM* n = m_model.FindParam( "n" ) )
194 waveform->SetBits( SIM_VALUE::ToInt( n->value, 0 ) );
195
196 kparams.m_waveform = waveform;
197
198 if( diffMode )
199 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
200 else
201 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
202
203 break;
204 }
205
206 default:
207 wxFAIL_MSG( "Unknown IBIS model type" );
208 return "";
209 }
210
211 return result;
212}
213
214
216 SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_IBIS>( *this ) ),
217 m_enableDiff( false ),
218 m_sourceModel( nullptr )
219{
220 static std::vector<PARAM::INFO> device = makeParamInfos( TYPE::KIBIS_DEVICE );
221 static std::vector<PARAM::INFO> dcDriver = makeParamInfos( TYPE::KIBIS_DRIVER_DC );
222 static std::vector<PARAM::INFO> rectDriver = makeParamInfos( TYPE::KIBIS_DRIVER_RECT );
223 static std::vector<PARAM::INFO> prbsDriver = makeParamInfos( TYPE::KIBIS_DRIVER_PRBS );
224
225 std::vector<PARAM::INFO>* paramInfos = nullptr;
226
227 switch( aType )
228 {
229 case SIM_MODEL::TYPE::KIBIS_DEVICE: paramInfos = &device; break;
230 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC: paramInfos = &dcDriver; break;
231 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT: paramInfos = &rectDriver; break;
232 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS: paramInfos = &prbsDriver; break;
233 default: wxFAIL; return;
234 }
235
236 for( const PARAM::INFO& paramInfo : *paramInfos )
237 AddParam( paramInfo );
238
239 SwitchSingleEndedDiff( false );
240}
241
242
247
248
249std::vector<wxString> SIM_MODEL_IBIS::GetSpiceIncludes( const SPICE_ITEM& aItem, SCHEMATIC* aSchematic,
250 REPORTER& aReporter ) const
251{
252 wxFileName cacheFn;
253 cacheFn.AssignDir( PATHS::GetUserCachePath() );
254 cacheFn.AppendDir( wxT( "ibis" ) );
255 cacheFn.SetFullName( aItem.refName + ".cache" );
256
257 wxFile cacheFile( cacheFn.GetFullPath(), wxFile::write );
258
259 if( !cacheFile.IsOpened() )
260 wxLogError( _( "Could not open file '%s' to write IBIS model" ), cacheFn.GetFullPath() );
261
262 const SPICE_GENERATOR_IBIS& spiceGenerator = static_cast<const SPICE_GENERATOR_IBIS&>( SpiceGenerator() );
263
264 wxString cacheFilepath = cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
265 std::string modelData = spiceGenerator.IbisDevice( aItem, aSchematic, cacheFilepath, aReporter );
266
267 cacheFile.Write( wxString( modelData ) );
268
269 return { cacheFn.GetFullPath() };
270}
271
272
274{
275 m_ioMode = aMode;
276 ClearPins();
277
278 switch( aMode )
279 {
281 AddPin( { "GND", "1" } );
282 AddPin( { "IN/OUT", "2" } );
284 break;
285
287 AddPin( { "GND", "1" } );
288 AddPin( { "+", "2" } );
289 AddPin( { "-", "3" } );
291 break;
292
294 AddPin( { "PIN_A", "1" } );
295 AddPin( { "PIN_B", "2" } );
296 break;
297 }
298}
299
300
302{
303 if( FindParam( "sw_state" ) )
304 return;
305
306 // INFO must outlive every PARAM that references it (PARAM stores const INFO&).
307 static const PARAM::INFO info = [&]
308 {
309 PARAM::INFO i;
310 i.name = "sw_state";
311 i.type = SIM_VALUE::TYPE_FLOAT;
312 i.unit = "";
313 i.category = PARAM::CATEGORY::PRINCIPAL;
314 i.defaultValue = "1";
315 i.description = _( "Switch state (1 = on, 0 = off)" ).ToStdString();
316 i.isSpiceInstanceParam = true;
317 i.spiceInstanceName = "SW_STATE";
318 return i;
319 }();
320
321 AddParam( info );
322}
323
324
326{
327 // PARAM is not assignable; erase-from-middle is illegal. sw_state is
328 // the only post-construction append, so back() is safe.
329 if( !m_params.empty() && m_params.back().info.name == "sw_state" )
330 m_params.pop_back();
331}
332
333
334bool SIM_MODEL_IBIS::SetIbisModel( const SIM_LIBRARY_IBIS& aLib, const std::string& aPinNumber,
335 const std::string& aModelName )
336{
338
339 if( !kcomp )
340 return false;
341
342 KIBIS_MODEL* kmodel = aLib.m_kibis.GetModel( aModelName );
343
344 if( !kmodel )
345 return false;
346
347 KIBIS_PIN* kpin = kcomp->GetPin( aPinNumber );
348
349 switch( kmodel->m_type )
350 {
353 {
355
356 m_partnerPin.clear();
357
358 if( kpin )
359 {
360 if( KIBIS_PIN* partner = kpin->SeriesPartner() )
361 m_partnerPin = partner->m_pinNumber;
362 }
363
366 else
368
369 break;
370 }
371
372 default:
373 m_partnerPin.clear();
375
378
379 break;
380 }
381
382 return true;
383}
384
386 SIM_MODEL_IBIS( aType )
387{
388 for( PARAM& param1 : m_params )
389 {
390 for( int ii = 0; ii < aSource.GetParamCount(); ++ii )
391 {
392 const PARAM& param2 = aSource.GetParam( ii );
393
394 if( param1.info.name == param2.info.name )
395 param1.value = param2.value;
396 }
397 }
398
400
401 m_ibisPins = aSource.GetIbisPins();
402 m_ibisModels = aSource.GetIbisModels();
403
404 m_enableDiff = aSource.CanDifferential();
405 m_partnerPin = aSource.m_partnerPin;
406
407 // SetIOMode does not touch sw_state; re-add it for SERIES_SWITCH sources.
408 SetIOMode( aSource.m_ioMode );
409
410 if( aSource.IsSeries() )
411 {
412 if( const PARAM* srcSwState = aSource.FindParam( "sw_state" ) )
413 {
415 SetParamValue( "sw_state", srcSwState->value );
416 }
417 }
418}
419
420
421bool SIM_MODEL_IBIS::ChangePin( const SIM_LIBRARY_IBIS& aLib, const std::string& aPinNumber )
422{
423 KIBIS_COMPONENT* kcomp = aLib.m_kibis.GetComponent( std::string( GetComponentName() ) );
424
425 if( !kcomp )
426 return false;
427
428 KIBIS_PIN* kpin = kcomp->GetPin( aPinNumber );
429
430 if( !kpin )
431 return false;
432
433 m_ibisModels.clear();
434
435 for( KIBIS_MODEL* kmodel : kpin->m_models )
436 m_ibisModels.push_back( kmodel->m_name );
437
438 return true;
439}
440
441
443{
444 // Actual base models can only be of the same type, which is not the case here, as in addition
445 // to IBIS device model type we have multiple types of drivers available for the same sourced
446 // model. And we don't want to inherit the default values anyway. So we just store these models
447 // and use the only for Spice code generation.
448 m_sourceModel = dynamic_cast<const SIM_MODEL_IBIS*>( &aBaseModel );
449}
450
451
452std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeParamInfos( TYPE aType )
453{
454 std::vector<PARAM::INFO> paramInfos;
455 PARAM::INFO paramInfo;
456
457 paramInfo.name = "vcc";
458 paramInfo.type = SIM_VALUE::TYPE_STRING;
459 paramInfo.unit = "";
460 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
461 paramInfo.defaultValue = "typ";
462 paramInfo.description = _( "Power supply" );
463 paramInfo.spiceModelName = "";
464 paramInfo.enumValues = { "typ", "min", "max" };
465 paramInfos.push_back( paramInfo );
466
467 paramInfo.name = "rpin";
468 paramInfo.type = SIM_VALUE::TYPE_STRING;
469 paramInfo.unit = "";
470 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
471 paramInfo.defaultValue = "typ";
472 paramInfo.description = _( "Parasitic pin resistance" );
473 paramInfo.spiceModelName = "";
474 paramInfo.enumValues = { "typ", "min", "max" };
475 paramInfos.push_back( paramInfo );
476
477 paramInfo.name = "lpin";
478 paramInfo.type = SIM_VALUE::TYPE_STRING;
479 paramInfo.unit = "";
480 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
481 paramInfo.defaultValue = "typ";
482 paramInfo.description = _( "Parasitic pin inductance" );
483 paramInfo.spiceModelName = "";
484 paramInfo.enumValues = { "typ", "min", "max" };
485 paramInfos.push_back( paramInfo );
486
487 paramInfo.name = "cpin";
488 paramInfo.type = SIM_VALUE::TYPE_STRING;
489 paramInfo.unit = "";
490 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
491 paramInfo.defaultValue = "typ";
492 paramInfo.description = _( "Parasitic pin capacitance" );
493 paramInfo.spiceModelName = "";
494 paramInfo.enumValues = { "typ", "min", "max" };
495 paramInfos.push_back( paramInfo );
496
497 std::vector<PARAM::INFO> dc = makeDcWaveformParamInfos();
498 std::vector<PARAM::INFO> rect = makeRectWaveformParamInfos();
499 std::vector<PARAM::INFO> prbs = makePrbsWaveformParamInfos();
500
501 switch( aType )
502 {
503 case TYPE::KIBIS_DRIVER_DC:
504 for( const PARAM::INFO& param : makeDcWaveformParamInfos() )
505 paramInfos.push_back( param );
506
507 break;
508
509 case TYPE::KIBIS_DRIVER_RECT:
510 for( const PARAM::INFO& param : makeRectWaveformParamInfos() )
511 paramInfos.push_back( param );
512
513 break;
514
515 case TYPE::KIBIS_DRIVER_PRBS:
516 for( const PARAM::INFO& param : makePrbsWaveformParamInfos() )
517 paramInfos.push_back( param );
518
519 break;
520
521 default:
522 break;
523 }
524
525 return paramInfos;
526}
527
528
529std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeDcWaveformParamInfos()
530{
531 std::vector<PARAM::INFO> paramInfos;
532 PARAM::INFO paramInfo;
533
534 paramInfo.name = "dc";
535 paramInfo.type = SIM_VALUE::TYPE_STRING;
536 paramInfo.unit = "";
537 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
538 paramInfo.defaultValue = "hi-Z";
539 paramInfo.description = _( "DC Value" );
540 paramInfo.enumValues = { "hi-Z", "low", "high" };
541 paramInfos.push_back( paramInfo );
542
543 return paramInfos;
544}
545
546
547std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeRectWaveformParamInfos()
548{
549 std::vector<PARAM::INFO> paramInfos;
550 PARAM::INFO paramInfo;
551
552 paramInfo.name = "ton";
553 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
554 paramInfo.unit = "s";
555 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
556 paramInfo.defaultValue = "";
557 paramInfo.description = _( "ON time" );
558 paramInfos.push_back( paramInfo );
559
560 paramInfo.name = "toff";
561 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
562 paramInfo.unit = "s";
563 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
564 paramInfo.defaultValue = "";
565 paramInfo.description = _( "OFF time" );
566 paramInfos.push_back( paramInfo );
567
568 paramInfo.name = "td";
569 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
570 paramInfo.unit = "s";
571 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
572 paramInfo.defaultValue = "0";
573 paramInfo.description = _( "Delay" );
574 paramInfos.push_back( paramInfo );
575
576 paramInfo.name = "n";
577 paramInfo.type = SIM_VALUE::TYPE_INT;
578 paramInfo.unit = "";
579 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
580 paramInfo.defaultValue = "1";
581 paramInfo.description = _( "Number of cycles" );
582 paramInfos.push_back( paramInfo );
583
584 return paramInfos;
585}
586
587
588std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makePrbsWaveformParamInfos()
589{
590 std::vector<PARAM::INFO> paramInfos;
591 PARAM::INFO paramInfo;
592
593 paramInfo.name = "f0";
594 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
595 paramInfo.unit = "Hz";
596 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
597 paramInfo.defaultValue = "";
598 paramInfo.description = _( "Bitrate" );
599 paramInfos.push_back( paramInfo );
600
601 paramInfo.name = "td";
602 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
603 paramInfo.unit = "s";
604 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
605 paramInfo.defaultValue = "";
606 paramInfo.description = _( "Delay" );
607 paramInfos.push_back( paramInfo );
608
609 paramInfo.name = "n";
610 paramInfo.type = SIM_VALUE::TYPE_INT;
611 paramInfo.unit = "";
612 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
613 paramInfo.defaultValue = "";
614 paramInfo.description = _( "Number of bits" );
615 paramInfos.push_back( paramInfo );
616
617 return paramInfos;
618}
619
REPORTER * m_Reporter
Definition ibis_parser.h:77
bool m_valid
Definition kibis.h:57
KIBIS_PIN * GetPin(const std::string &aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
Definition kibis.cpp:432
std::string m_name
Definition kibis.h:269
IBIS_MODEL_TYPE m_type
Definition kibis.h:271
bool writeSpiceDiffDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition kibis.cpp:1614
bool writeSpiceDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition kibis.cpp:1507
std::vector< KIBIS_MODEL * > m_models
Definition kibis.h:397
bool writeSpiceDiffDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition kibis.cpp:1651
KIBIS_PIN * SeriesPartner(std::string *aModelName=nullptr, std::string *aGroupName=nullptr) const
Partner pin from [Series Pin Mapping], or nullptr.
Definition kibis.cpp:403
bool writeSpiceDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
Definition kibis.cpp:1382
void SetBits(int aBits)
Definition kibis.h:146
Definition kibis.h:513
KIBIS_MODEL * GetModel(const std::string &aName)
Return the model with name aName .
Definition kibis.cpp:1681
KIBIS_COMPONENT * GetComponent(const std::string &aName)
Return the component with name aName .
Definition kibis.cpp:1693
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
Definition kibis.h:528
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
Definition paths.cpp:460
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:72
Holds all the data relating to one schematic.
Definition schematic.h:90
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:105
EMBEDDED_FILES * GetEmbeddedFiles() override
static constexpr auto MODEL_FIELD
static constexpr auto PIN_FIELD
static constexpr auto DIFF_FIELD
static constexpr auto LIBRARY_FIELD
Definition sim_library.h:31
static constexpr auto NAME_FIELD
Definition sim_library.h:32
wxString ResolveLibraryPath(const wxString &aLibraryPath, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:44
SIM_MODEL_IBIS(TYPE aType)
static std::vector< PARAM::INFO > makeDcWaveformParamInfos()
void removeSwitchStateParam()
std::vector< std::pair< std::string, std::string > > m_ibisPins
friend class SIM_LIBRARY_IBIS
std::vector< std::string > m_ibisModels
static std::vector< PARAM::INFO > makeRectWaveformParamInfos()
IBIS_IO_MODE m_ioMode
bool SetIbisModel(const SIM_LIBRARY_IBIS &aLib, const std::string &aPinNumber, const std::string &aModelName)
Bind to a KIBIS model, set IO mode from its type, manage sw_state.
const PARAM & GetParam(unsigned aParamIndex) const override
static std::vector< PARAM::INFO > makePrbsWaveformParamInfos()
std::string m_partnerPin
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
void SwitchSingleEndedDiff(bool aDiff) override
bool IsSeries() const
const SIM_MODEL_IBIS * m_sourceModel
bool CanDifferential() const
std::vector< std::string > GetIbisModels() const
void SetIOMode(IBIS_IO_MODE aMode)
std::string m_componentName
std::vector< wxString > GetSpiceIncludes(const SPICE_ITEM &aItem, SCHEMATIC *aSchematic, REPORTER &aReporter) const override
Return the external files this model must pull into the netlist as .include directives,...
void SetBaseModel(const SIM_MODEL &aBaseModel) override
bool ChangePin(const SIM_LIBRARY_IBIS &aLib, const std::string &aPinNumber)
update the list of available models based on the pin number.
static std::vector< PARAM::INFO > makeParamInfos(TYPE aType)
std::string GetComponentName() const
void AddParam(const PARAM::INFO &aInfo)
void ClearPins()
void AddPin(const SIM_MODEL_PIN &aPin)
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:429
SIM_MODEL()=delete
int GetParamCount() const
Definition sim_model.h:488
const PARAM * FindParam(const std::string &aParamName) const
std::vector< PARAM > m_params
Definition sim_model.h:545
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
@ TYPE_STRING
Definition sim_value.h:67
static double ToDouble(const std::string &aString, double aDefault=NAN)
static int ToInt(const std::string &aString, int aDefault=-1)
std::string IbisDevice(const SPICE_ITEM &aItem, SCHEMATIC *aSchematic, const wxString &aCacheDir, REPORTER &aReporter) const
std::vector< std::string > CurrentNames(const SPICE_ITEM &aItem) const override
std::string ModelLine(const SPICE_ITEM &aItem) const override
std::string ModelName(const SPICE_ITEM &aItem) const override
virtual std::string ItemName(const SPICE_ITEM &aItem) const
virtual std::vector< std::reference_wrapper< const SIM_MODEL_PIN > > GetPins() const
const SIM_MODEL & m_model
A wrapper for reporting to a wxString object.
Definition reporter.h:225
#define _(s)
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
STL namespace.
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
Definition sch_field.h:421
SIM_MODEL::TYPE TYPE
Definition sim_model.cpp:54
IBIS_IO_MODE
std::string value
Definition sim_model.h:398
const INFO & info
Definition sim_model.h:399
std::string refName
std::vector< SCH_FIELD > fields
std::string modelName
std::string baseModelName
std::string path
IbisParser parser & reporter
KIBIS_PIN * partner
KIBIS_PARAMETER kparams
KIBIS_PIN * pin
wxString result
Test unit parsing edge cases and error handling.