28#include <wx/filename.h>
46 std::vector<std::string> currentNames;
49 currentNames.push_back( fmt::format(
"I({}:{})",
ItemName( aItem ),
pin.modelPinName ) );
56 const wxString& aCacheDir,
REPORTER& aReporter )
const
67 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
76 KIBIS kibis( std::string(
path.c_str() ) );
77 kibis.
m_cacheDir = std::string( aCacheDir.c_str() );
81 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS file '%s'" ), ibisLibFilename ) );
86 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS component '%s'" ), ibisCompName ) );
92 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS component '%s'" ), ibisCompName ) );
96 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS pin '%s' in component '%s'" ),
103 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS pin '%s' in component '%s'" ),
111 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS model '%s'" ), ibisModelName ) );
114 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS model '%s'" ), ibisModelName ) );
136 case SIM_MODEL::TYPE::KIBIS_DEVICE:
144 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
146 std::string paramValue =
"";
149 paramValue = dc->value;
151 if( paramValue ==
"hi-Z" )
153 else if( paramValue ==
"low" )
155 else if( paramValue ==
"high" )
166 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
192 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
216 wxFAIL_MSG(
"Unknown IBIS model type" );
229 static std::vector<PARAM::INFO> device =
makeParamInfos( TYPE::KIBIS_DEVICE );
230 static std::vector<PARAM::INFO> dcDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_DC );
231 static std::vector<PARAM::INFO> rectDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_RECT );
232 static std::vector<PARAM::INFO> prbsDriver =
makeParamInfos( TYPE::KIBIS_DRIVER_PRBS );
234 std::vector<PARAM::INFO>* paramInfos =
nullptr;
238 case SIM_MODEL::TYPE::KIBIS_DEVICE: paramInfos = &device;
break;
239 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC: paramInfos = &dcDriver;
break;
240 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT: paramInfos = &rectDriver;
break;
241 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS: paramInfos = &prbsDriver;
break;
242 default: wxFAIL;
return;
245 for(
const PARAM::INFO& paramInfo : *paramInfos )
267 AddPin( {
"IN/OUT",
"2" } );
279 AddPin( {
"PIN_A",
"1" } );
280 AddPin( {
"PIN_B",
"2" } );
292 static const PARAM::INFO
info = [&]
298 i.category = PARAM::CATEGORY::PRINCIPAL;
299 i.defaultValue =
"1";
300 i.description =
_(
"Switch state (1 = on, 0 = off)" ).ToStdString();
301 i.isSpiceInstanceParam =
true;
302 i.spiceInstanceName =
"SW_STATE";
320 const std::string& aModelName )
379 if( param1.info.name == param2.
info.
name )
439 std::vector<PARAM::INFO> paramInfos;
440 PARAM::INFO paramInfo;
442 paramInfo.name =
"vcc";
445 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
446 paramInfo.defaultValue =
"typ";
447 paramInfo.description =
_(
"Power supply" );
448 paramInfo.spiceModelName =
"";
449 paramInfo.enumValues = {
"typ",
"min",
"max" };
450 paramInfos.push_back( paramInfo );
452 paramInfo.name =
"rpin";
455 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
456 paramInfo.defaultValue =
"typ";
457 paramInfo.description =
_(
"Parasitic pin resistance" );
458 paramInfo.spiceModelName =
"";
459 paramInfo.enumValues = {
"typ",
"min",
"max" };
460 paramInfos.push_back( paramInfo );
462 paramInfo.name =
"lpin";
465 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
466 paramInfo.defaultValue =
"typ";
467 paramInfo.description =
_(
"Parasitic pin inductance" );
468 paramInfo.spiceModelName =
"";
469 paramInfo.enumValues = {
"typ",
"min",
"max" };
470 paramInfos.push_back( paramInfo );
472 paramInfo.name =
"cpin";
475 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
476 paramInfo.defaultValue =
"typ";
477 paramInfo.description =
_(
"Parasitic pin capacitance" );
478 paramInfo.spiceModelName =
"";
479 paramInfo.enumValues = {
"typ",
"min",
"max" };
480 paramInfos.push_back( paramInfo );
488 case TYPE::KIBIS_DRIVER_DC:
490 paramInfos.push_back( param );
494 case TYPE::KIBIS_DRIVER_RECT:
496 paramInfos.push_back( param );
500 case TYPE::KIBIS_DRIVER_PRBS:
502 paramInfos.push_back( param );
516 std::vector<PARAM::INFO> paramInfos;
517 PARAM::INFO paramInfo;
519 paramInfo.name =
"dc";
522 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
523 paramInfo.defaultValue =
"hi-Z";
524 paramInfo.description =
_(
"DC Value" );
525 paramInfo.enumValues = {
"hi-Z",
"low",
"high" };
526 paramInfos.push_back( paramInfo );
534 std::vector<PARAM::INFO> paramInfos;
535 PARAM::INFO paramInfo;
537 paramInfo.name =
"ton";
539 paramInfo.unit =
"s";
540 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
541 paramInfo.defaultValue =
"";
542 paramInfo.description =
_(
"ON time" );
543 paramInfos.push_back( paramInfo );
545 paramInfo.name =
"toff";
547 paramInfo.unit =
"s";
548 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
549 paramInfo.defaultValue =
"";
550 paramInfo.description =
_(
"OFF time" );
551 paramInfos.push_back( paramInfo );
553 paramInfo.name =
"td";
555 paramInfo.unit =
"s";
556 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
557 paramInfo.defaultValue =
"0";
558 paramInfo.description =
_(
"Delay" );
559 paramInfos.push_back( paramInfo );
561 paramInfo.name =
"n";
564 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
565 paramInfo.defaultValue =
"1";
566 paramInfo.description =
_(
"Number of cycles" );
567 paramInfos.push_back( paramInfo );
575 std::vector<PARAM::INFO> paramInfos;
576 PARAM::INFO paramInfo;
578 paramInfo.name =
"f0";
580 paramInfo.unit =
"Hz";
581 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
582 paramInfo.defaultValue =
"";
583 paramInfo.description =
_(
"Bitrate" );
584 paramInfos.push_back( paramInfo );
586 paramInfo.name =
"td";
588 paramInfo.unit =
"s";
589 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
590 paramInfo.defaultValue =
"";
591 paramInfo.description =
_(
"Delay" );
592 paramInfos.push_back( paramInfo );
594 paramInfo.name =
"n";
597 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
598 paramInfo.defaultValue =
"";
599 paramInfo.description =
_(
"Number of bits" );
600 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.