24#include <wx/filename.h>
42 std::vector<std::string> currentNames;
45 currentNames.push_back( fmt::format(
"I({}:{})",
ItemName( aItem ),
pin.modelPinName ) );
52 const wxString& aCacheDir,
REPORTER& aReporter )
const
63 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
72 KIBIS kibis( std::string(
path.c_str() ) );
73 kibis.
m_cacheDir = std::string( aCacheDir.c_str() );
77 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS file '%s'" ), ibisLibFilename ) );
82 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS component '%s'" ), ibisCompName ) );
88 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS component '%s'" ), ibisCompName ) );
92 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS pin '%s' in component '%s'" ),
99 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS pin '%s' in component '%s'" ),
107 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS model '%s'" ), ibisModelName ) );
110 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS model '%s'" ), ibisModelName ) );
132 case SIM_MODEL::TYPE::KIBIS_DEVICE:
140 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
142 std::string paramValue =
"";
145 paramValue = dc->value;
147 if( paramValue ==
"hi-Z" )
149 else if( paramValue ==
"low" )
151 else if( paramValue ==
"high" )
162 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
188 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
212 wxFAIL_MSG(
"Unknown IBIS model type" );
225 static std::vector<PARAM::INFO> device =
makeParamInfos( TYPE::KIBIS_DEVICE );
226 static std::vector<PARAM::INFO> dcDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_DC );
227 static std::vector<PARAM::INFO> rectDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_RECT );
228 static std::vector<PARAM::INFO> prbsDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_PRBS );
230 std::vector<PARAM::INFO>* paramInfos =
nullptr;
234 case SIM_MODEL::TYPE::KIBIS_DEVICE: paramInfos = &device;
break;
235 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC: paramInfos = &dcDriver;
break;
236 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT: paramInfos = &rectDriver;
break;
237 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS: paramInfos = &prbsDriver;
break;
238 default: wxFAIL;
return;
241 for(
const PARAM::INFO& paramInfo : *paramInfos )
263 AddPin( {
"IN/OUT",
"2" } );
275 AddPin( {
"PIN_A",
"1" } );
276 AddPin( {
"PIN_B",
"2" } );
288 static const PARAM::INFO
info = [&]
294 i.category = PARAM::CATEGORY::PRINCIPAL;
295 i.defaultValue =
"1";
296 i.description =
_(
"Switch state (1 = on, 0 = off)" ).ToStdString();
297 i.isSpiceInstanceParam =
true;
298 i.spiceInstanceName =
"SW_STATE";
316 const std::string& aModelName )
375 if( param1.info.name == param2.
info.
name )
435 std::vector<PARAM::INFO> paramInfos;
436 PARAM::INFO paramInfo;
438 paramInfo.name =
"vcc";
441 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
442 paramInfo.defaultValue =
"typ";
443 paramInfo.description =
_(
"Power supply" );
444 paramInfo.spiceModelName =
"";
445 paramInfo.enumValues = {
"typ",
"min",
"max" };
446 paramInfos.push_back( paramInfo );
448 paramInfo.name =
"rpin";
451 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
452 paramInfo.defaultValue =
"typ";
453 paramInfo.description =
_(
"Parasitic pin resistance" );
454 paramInfo.spiceModelName =
"";
455 paramInfo.enumValues = {
"typ",
"min",
"max" };
456 paramInfos.push_back( paramInfo );
458 paramInfo.name =
"lpin";
461 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
462 paramInfo.defaultValue =
"typ";
463 paramInfo.description =
_(
"Parasitic pin inductance" );
464 paramInfo.spiceModelName =
"";
465 paramInfo.enumValues = {
"typ",
"min",
"max" };
466 paramInfos.push_back( paramInfo );
468 paramInfo.name =
"cpin";
471 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
472 paramInfo.defaultValue =
"typ";
473 paramInfo.description =
_(
"Parasitic pin capacitance" );
474 paramInfo.spiceModelName =
"";
475 paramInfo.enumValues = {
"typ",
"min",
"max" };
476 paramInfos.push_back( paramInfo );
484 case TYPE::KIBIS_DRIVER_DC:
486 paramInfos.push_back( param );
490 case TYPE::KIBIS_DRIVER_RECT:
492 paramInfos.push_back( param );
496 case TYPE::KIBIS_DRIVER_PRBS:
498 paramInfos.push_back( param );
512 std::vector<PARAM::INFO> paramInfos;
513 PARAM::INFO paramInfo;
515 paramInfo.name =
"dc";
518 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
519 paramInfo.defaultValue =
"hi-Z";
520 paramInfo.description =
_(
"DC Value" );
521 paramInfo.enumValues = {
"hi-Z",
"low",
"high" };
522 paramInfos.push_back( paramInfo );
530 std::vector<PARAM::INFO> paramInfos;
531 PARAM::INFO paramInfo;
533 paramInfo.name =
"ton";
535 paramInfo.unit =
"s";
536 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
537 paramInfo.defaultValue =
"";
538 paramInfo.description =
_(
"ON time" );
539 paramInfos.push_back( paramInfo );
541 paramInfo.name =
"toff";
543 paramInfo.unit =
"s";
544 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
545 paramInfo.defaultValue =
"";
546 paramInfo.description =
_(
"OFF time" );
547 paramInfos.push_back( paramInfo );
549 paramInfo.name =
"td";
551 paramInfo.unit =
"s";
552 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
553 paramInfo.defaultValue =
"0";
554 paramInfo.description =
_(
"Delay" );
555 paramInfos.push_back( paramInfo );
557 paramInfo.name =
"n";
560 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
561 paramInfo.defaultValue =
"1";
562 paramInfo.description =
_(
"Number of cycles" );
563 paramInfos.push_back( paramInfo );
571 std::vector<PARAM::INFO> paramInfos;
572 PARAM::INFO paramInfo;
574 paramInfo.name =
"f0";
576 paramInfo.unit =
"Hz";
577 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
578 paramInfo.defaultValue =
"";
579 paramInfo.description =
_(
"Bitrate" );
580 paramInfos.push_back( paramInfo );
582 paramInfo.name =
"td";
584 paramInfo.unit =
"s";
585 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
586 paramInfo.defaultValue =
"";
587 paramInfo.description =
_(
"Delay" );
588 paramInfos.push_back( paramInfo );
590 paramInfo.name =
"n";
593 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
594 paramInfo.defaultValue =
"";
595 paramInfo.description =
_(
"Number of bits" );
596 paramInfos.push_back( paramInfo );
KIBIS_PIN * GetPin(const std::string &aPinNumber)
Get a pin by its number ( 1, 2, A1, A2, ... )
bool writeSpiceDiffDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
bool writeSpiceDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
std::vector< KIBIS_MODEL * > m_models
bool writeSpiceDiffDevice(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
KIBIS_PIN * SeriesPartner(std::string *aModelName=nullptr, std::string *aGroupName=nullptr) const
Partner pin from [Series Pin Mapping], or nullptr.
bool writeSpiceDriver(std::string &aDest, const std::string &aName, KIBIS_MODEL &aModel, const KIBIS_PARAMETER &aParam)
KIBIS_MODEL * GetModel(const std::string &aName)
Return the model with name aName .
KIBIS_COMPONENT * GetComponent(const std::string &aName)
Return the component with name aName .
std::string m_cacheDir
Absolute path of the directory that will be used for caching.
A pure virtual class used to derive REPORTER objects from.
Holds all the data relating to one schematic.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
EMBEDDED_FILES * GetEmbeddedFiles() override
static constexpr auto MODEL_FIELD
static constexpr auto PIN_FIELD
static constexpr auto DIFF_FIELD
static constexpr auto LIBRARY_FIELD
static constexpr auto NAME_FIELD
wxString ResolveLibraryPath(const wxString &aLibraryPath, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
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()
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()
void addSwitchStateParam()
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
void SwitchSingleEndedDiff(bool aDiff) override
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
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 AddPin(const SIM_MODEL_PIN &aPin)
int GetParamCount() const
const PARAM * FindParam(const std::string &aParamName) const
std::vector< PARAM > m_params
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
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.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
std::vector< SCH_FIELD > fields
std::string baseModelName
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.