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_ERROR( wxString::Format( _( "Invalid IBIS file '%s'" ), ibisLibFilename ) );
81
82 KIBIS_COMPONENT* kcomp = kibis.GetComponent( std::string( ibisCompName ) );
83
84 if( !kcomp )
85 THROW_IO_ERROR( wxString::Format( _( "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_ERROR( wxString::Format( _( "Invalid IBIS component '%s'" ), ibisCompName ) );
92
93 if( !kpin )
94 {
95 THROW_IO_ERROR( wxString::Format( _( "Could not find IBIS pin '%s' in component '%s'" ),
96 ibisPinName,
97 ibisCompName ) );
98 }
99
100 if( !kpin->m_valid )
101 {
102 THROW_IO_ERROR( wxString::Format( _( "Invalid IBIS pin '%s' in component '%s'" ),
103 ibisPinName,
104 ibisCompName ) );
105 }
106
107 KIBIS_MODEL* kmodel = kibis.GetModel( ibisModelName );
108
109 if( !kmodel )
110 THROW_IO_ERROR( wxString::Format( _( "Could not find IBIS model '%s'" ), ibisModelName ) );
111
112 if( !kmodel->m_valid )
113 THROW_IO_ERROR( wxString::Format( _( "Invalid IBIS model '%s'" ), ibisModelName ) );
114
116
117 if( const SIM_MODEL::PARAM* vcc = m_model.FindParam( "vcc" ) )
118 kparams.SetCornerFromString( kparams.m_supply, vcc->value );
119
120 if( const SIM_MODEL::PARAM* rpin = m_model.FindParam( "rpin" ) )
121 kparams.SetCornerFromString( kparams.m_Rpin, rpin->value );
122
123 if( const SIM_MODEL::PARAM* lpin = m_model.FindParam( "lpin" ) )
124 kparams.SetCornerFromString( kparams.m_Lpin, lpin->value );
125
126 if( const SIM_MODEL::PARAM* cpin = m_model.FindParam( "cpin" ) )
127 kparams.SetCornerFromString( kparams.m_Cpin, cpin->value );
128
129 //kparams.SetCornerFromString( kparams.m_Ccomp, FindParam( "ccomp" )->value );
130
131 std::string result;
132
133 switch( m_model.GetType() )
134 {
135 case SIM_MODEL::TYPE::KIBIS_DEVICE:
136 if( diffMode )
137 kpin->writeSpiceDiffDevice( result, aItem.modelName, *kmodel, kparams );
138 else
139 kpin->writeSpiceDevice( result, aItem.modelName, *kmodel, kparams );
140
141 break;
142
143 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
144 {
145 std::string paramValue = "";
146
147 if( const SIM_MODEL::PARAM* dc = m_model.FindParam( "dc" ) )
148 paramValue = dc->value;
149
150 if( paramValue == "hi-Z" )
151 kparams.m_waveform = new KIBIS_WAVEFORM_HIGH_Z( kibis );
152 else if( paramValue == "low" )
153 kparams.m_waveform = new KIBIS_WAVEFORM_STUCK_LOW( kibis );
154 else if( paramValue == "high" )
155 kparams.m_waveform = new KIBIS_WAVEFORM_STUCK_HIGH( kibis );
156
157 if( diffMode )
158 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
159 else
160 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
161
162 break;
163 }
164
165 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
166 {
168
169 if( const SIM_MODEL::PARAM* ton = m_model.FindParam( "ton" ) )
170 waveform->m_ton = SIM_VALUE::ToDouble( ton->value, 0 );
171
172 if( const SIM_MODEL::PARAM* toff = m_model.FindParam( "toff" ) )
173 waveform->m_toff = SIM_VALUE::ToDouble( toff->value, 0 );
174
175 if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) )
176 waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 );
177
178 if( const SIM_MODEL::PARAM* n = m_model.FindParam( "n" ) )
179 waveform->m_cycles = SIM_VALUE::ToInt( n->value, 1 );
180
181 kparams.m_waveform = waveform;
182
183 if( diffMode )
184 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
185 else
186 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
187
188 break;
189 }
190
191 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
192 {
193 KIBIS_WAVEFORM_PRBS* waveform = new KIBIS_WAVEFORM_PRBS( kibis );
194
195 if( const SIM_MODEL::PARAM* f0 = m_model.FindParam( "f0" ) )
196 waveform->m_bitrate = SIM_VALUE::ToDouble( f0->value, 0 );
197
198 if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) )
199 waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 );
200
201 if( const SIM_MODEL::PARAM* n = m_model.FindParam( "n" ) )
202 waveform->SetBits( SIM_VALUE::ToInt( n->value, 0 ) );
203
204 kparams.m_waveform = waveform;
205
206 if( diffMode )
207 kpin->writeSpiceDiffDriver( result, aItem.modelName, *kmodel, kparams );
208 else
209 kpin->writeSpiceDriver( result, aItem.modelName, *kmodel, kparams );
210
211 break;
212 }
213
214 default:
215 wxFAIL_MSG( "Unknown IBIS model type" );
216 return "";
217 }
218
219 return result;
220}
221
222
224 SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_IBIS>( *this ) ),
225 m_enableDiff( false ),
226 m_sourceModel( nullptr )
227{
228 static std::vector<PARAM::INFO> device = makeParamInfos( TYPE::KIBIS_DEVICE );
229 static std::vector<PARAM::INFO> dcDriver = makeParamInfos( TYPE::KIBIS_DRIVER_DC );
230 static std::vector<PARAM::INFO> rectDriver = makeParamInfos( TYPE::KIBIS_DRIVER_RECT );
231 static std::vector<PARAM::INFO> prbsDriver = makeParamInfos( TYPE::KIBIS_DRIVER_PRBS );
232
233 std::vector<PARAM::INFO>* paramInfos = nullptr;
234
235 switch( aType )
236 {
237 case SIM_MODEL::TYPE::KIBIS_DEVICE: paramInfos = &device; break;
238 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC: paramInfos = &dcDriver; break;
239 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT: paramInfos = &rectDriver; break;
240 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS: paramInfos = &prbsDriver; break;
241 default: wxFAIL; return;
242 }
243
244 for( const PARAM::INFO& paramInfo : *paramInfos )
245 AddParam( paramInfo );
246
247 SwitchSingleEndedDiff( false );
248}
249
250
255
256
257std::vector<wxString> SIM_MODEL_IBIS::GetSpiceIncludes( const SPICE_ITEM& aItem, SCHEMATIC* aSchematic,
258 REPORTER& aReporter ) const
259{
260 wxFileName cacheFn;
261 cacheFn.AssignDir( PATHS::GetUserCachePath() );
262 cacheFn.AppendDir( wxT( "ibis" ) );
263 cacheFn.SetFullName( aItem.refName + ".cache" );
264
265 wxFile cacheFile( cacheFn.GetFullPath(), wxFile::write );
266
267 if( !cacheFile.IsOpened() )
268 wxLogError( _( "Could not open file '%s' to write IBIS model" ), cacheFn.GetFullPath() );
269
270 const SPICE_GENERATOR_IBIS& spiceGenerator = static_cast<const SPICE_GENERATOR_IBIS&>( SpiceGenerator() );
271
272 wxString cacheFilepath = cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
273 std::string modelData = spiceGenerator.IbisDevice( aItem, aSchematic, cacheFilepath, aReporter );
274
275 cacheFile.Write( wxString( modelData ) );
276
277 return { cacheFn.GetFullPath() };
278}
279
280
282{
283 m_ioMode = aMode;
284 ClearPins();
285
286 switch( aMode )
287 {
289 AddPin( { "GND", "1" } );
290 AddPin( { "IN/OUT", "2" } );
292 break;
293
295 AddPin( { "GND", "1" } );
296 AddPin( { "+", "2" } );
297 AddPin( { "-", "3" } );
299 break;
300
302 AddPin( { "PIN_A", "1" } );
303 AddPin( { "PIN_B", "2" } );
304 break;
305 }
306}
307
308
310{
311 if( FindParam( "sw_state" ) )
312 return;
313
314 // INFO must outlive every PARAM that references it (PARAM stores const INFO&).
315 static const PARAM::INFO info = [&]
316 {
317 PARAM::INFO i;
318 i.name = "sw_state";
319 i.type = SIM_VALUE::TYPE_FLOAT;
320 i.unit = "";
321 i.category = PARAM::CATEGORY::PRINCIPAL;
322 i.defaultValue = "1";
323 i.description = _( "Switch state (1 = on, 0 = off)" ).ToStdString();
324 i.isSpiceInstanceParam = true;
325 i.spiceInstanceName = "SW_STATE";
326 return i;
327 }();
328
329 AddParam( info );
330}
331
332
334{
335 // PARAM is not assignable; erase-from-middle is illegal. sw_state is
336 // the only post-construction append, so back() is safe.
337 if( !m_params.empty() && m_params.back().info.name == "sw_state" )
338 m_params.pop_back();
339}
340
341
342bool SIM_MODEL_IBIS::SetIbisModel( const SIM_LIBRARY_IBIS& aLib, const std::string& aPinNumber,
343 const std::string& aModelName )
344{
346
347 if( !kcomp )
348 return false;
349
350 KIBIS_MODEL* kmodel = aLib.m_kibis.GetModel( aModelName );
351
352 if( !kmodel )
353 return false;
354
355 KIBIS_PIN* kpin = kcomp->GetPin( aPinNumber );
356
357 switch( kmodel->m_type )
358 {
361 {
363
364 m_partnerPin.clear();
365
366 if( kpin )
367 {
368 if( KIBIS_PIN* partner = kpin->SeriesPartner() )
369 m_partnerPin = partner->m_pinNumber;
370 }
371
374 else
376
377 break;
378 }
379
380 default:
381 m_partnerPin.clear();
383
386
387 break;
388 }
389
390 return true;
391}
392
394 SIM_MODEL_IBIS( aType )
395{
396 for( PARAM& param1 : m_params )
397 {
398 for( int ii = 0; ii < aSource.GetParamCount(); ++ii )
399 {
400 const PARAM& param2 = aSource.GetParam( ii );
401
402 if( param1.info.name == param2.info.name )
403 param1.value = param2.value;
404 }
405 }
406
408
409 m_ibisPins = aSource.GetIbisPins();
410 m_ibisModels = aSource.GetIbisModels();
411
412 m_enableDiff = aSource.CanDifferential();
413 m_partnerPin = aSource.m_partnerPin;
414
415 // SetIOMode does not touch sw_state; re-add it for SERIES_SWITCH sources.
416 SetIOMode( aSource.m_ioMode );
417
418 if( aSource.IsSeries() )
419 {
420 if( const PARAM* srcSwState = aSource.FindParam( "sw_state" ) )
421 {
423 SetParamValue( "sw_state", srcSwState->value );
424 }
425 }
426}
427
428
429bool SIM_MODEL_IBIS::ChangePin( const SIM_LIBRARY_IBIS& aLib, const std::string& aPinNumber )
430{
431 KIBIS_COMPONENT* kcomp = aLib.m_kibis.GetComponent( std::string( GetComponentName() ) );
432
433 if( !kcomp )
434 return false;
435
436 KIBIS_PIN* kpin = kcomp->GetPin( aPinNumber );
437
438 if( !kpin )
439 return false;
440
441 m_ibisModels.clear();
442
443 for( KIBIS_MODEL* kmodel : kpin->m_models )
444 m_ibisModels.push_back( kmodel->m_name );
445
446 return true;
447}
448
449
451{
452 // Actual base models can only be of the same type, which is not the case here, as in addition
453 // to IBIS device model type we have multiple types of drivers available for the same sourced
454 // model. And we don't want to inherit the default values anyway. So we just store these models
455 // and use the only for Spice code generation.
456 m_sourceModel = dynamic_cast<const SIM_MODEL_IBIS*>( &aBaseModel );
457}
458
459
460std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeParamInfos( TYPE aType )
461{
462 std::vector<PARAM::INFO> paramInfos;
463 PARAM::INFO paramInfo;
464
465 paramInfo.name = "vcc";
466 paramInfo.type = SIM_VALUE::TYPE_STRING;
467 paramInfo.unit = "";
468 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
469 paramInfo.defaultValue = "typ";
470 paramInfo.description = _( "Power supply" );
471 paramInfo.spiceModelName = "";
472 paramInfo.enumValues = { "typ", "min", "max" };
473 paramInfos.push_back( paramInfo );
474
475 paramInfo.name = "rpin";
476 paramInfo.type = SIM_VALUE::TYPE_STRING;
477 paramInfo.unit = "";
478 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
479 paramInfo.defaultValue = "typ";
480 paramInfo.description = _( "Parasitic pin resistance" );
481 paramInfo.spiceModelName = "";
482 paramInfo.enumValues = { "typ", "min", "max" };
483 paramInfos.push_back( paramInfo );
484
485 paramInfo.name = "lpin";
486 paramInfo.type = SIM_VALUE::TYPE_STRING;
487 paramInfo.unit = "";
488 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
489 paramInfo.defaultValue = "typ";
490 paramInfo.description = _( "Parasitic pin inductance" );
491 paramInfo.spiceModelName = "";
492 paramInfo.enumValues = { "typ", "min", "max" };
493 paramInfos.push_back( paramInfo );
494
495 paramInfo.name = "cpin";
496 paramInfo.type = SIM_VALUE::TYPE_STRING;
497 paramInfo.unit = "";
498 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
499 paramInfo.defaultValue = "typ";
500 paramInfo.description = _( "Parasitic pin capacitance" );
501 paramInfo.spiceModelName = "";
502 paramInfo.enumValues = { "typ", "min", "max" };
503 paramInfos.push_back( paramInfo );
504
505 std::vector<PARAM::INFO> dc = makeDcWaveformParamInfos();
506 std::vector<PARAM::INFO> rect = makeRectWaveformParamInfos();
507 std::vector<PARAM::INFO> prbs = makePrbsWaveformParamInfos();
508
509 switch( aType )
510 {
511 case TYPE::KIBIS_DRIVER_DC:
512 for( const PARAM::INFO& param : makeDcWaveformParamInfos() )
513 paramInfos.push_back( param );
514
515 break;
516
517 case TYPE::KIBIS_DRIVER_RECT:
518 for( const PARAM::INFO& param : makeRectWaveformParamInfos() )
519 paramInfos.push_back( param );
520
521 break;
522
523 case TYPE::KIBIS_DRIVER_PRBS:
524 for( const PARAM::INFO& param : makePrbsWaveformParamInfos() )
525 paramInfos.push_back( param );
526
527 break;
528
529 default:
530 break;
531 }
532
533 return paramInfos;
534}
535
536
537std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeDcWaveformParamInfos()
538{
539 std::vector<PARAM::INFO> paramInfos;
540 PARAM::INFO paramInfo;
541
542 paramInfo.name = "dc";
543 paramInfo.type = SIM_VALUE::TYPE_STRING;
544 paramInfo.unit = "";
545 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
546 paramInfo.defaultValue = "hi-Z";
547 paramInfo.description = _( "DC Value" );
548 paramInfo.enumValues = { "hi-Z", "low", "high" };
549 paramInfos.push_back( paramInfo );
550
551 return paramInfos;
552}
553
554
555std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makeRectWaveformParamInfos()
556{
557 std::vector<PARAM::INFO> paramInfos;
558 PARAM::INFO paramInfo;
559
560 paramInfo.name = "ton";
561 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
562 paramInfo.unit = "s";
563 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
564 paramInfo.defaultValue = "";
565 paramInfo.description = _( "ON time" );
566 paramInfos.push_back( paramInfo );
567
568 paramInfo.name = "toff";
569 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
570 paramInfo.unit = "s";
571 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
572 paramInfo.defaultValue = "";
573 paramInfo.description = _( "OFF time" );
574 paramInfos.push_back( paramInfo );
575
576 paramInfo.name = "td";
577 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
578 paramInfo.unit = "s";
579 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
580 paramInfo.defaultValue = "0";
581 paramInfo.description = _( "Delay" );
582 paramInfos.push_back( paramInfo );
583
584 paramInfo.name = "n";
585 paramInfo.type = SIM_VALUE::TYPE_INT;
586 paramInfo.unit = "";
587 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
588 paramInfo.defaultValue = "1";
589 paramInfo.description = _( "Number of cycles" );
590 paramInfos.push_back( paramInfo );
591
592 return paramInfos;
593}
594
595
596std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_IBIS::makePrbsWaveformParamInfos()
597{
598 std::vector<PARAM::INFO> paramInfos;
599 PARAM::INFO paramInfo;
600
601 paramInfo.name = "f0";
602 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
603 paramInfo.unit = "Hz";
604 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
605 paramInfo.defaultValue = "";
606 paramInfo.description = _( "Bitrate" );
607 paramInfos.push_back( paramInfo );
608
609 paramInfo.name = "td";
610 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
611 paramInfo.unit = "s";
612 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
613 paramInfo.defaultValue = "";
614 paramInfo.description = _( "Delay" );
615 paramInfos.push_back( paramInfo );
616
617 paramInfo.name = "n";
618 paramInfo.type = SIM_VALUE::TYPE_INT;
619 paramInfo.unit = "";
620 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
621 paramInfo.defaultValue = "";
622 paramInfo.description = _( "Number of bits" );
623 paramInfos.push_back( paramInfo );
624
625 return paramInfos;
626}
627
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:71
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:189
#define _(s)
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
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.