25#include <wx/filename.h>
45 std::vector<std::string> currentNames;
48 currentNames.push_back( fmt::format(
"I({}:{})",
ItemName( aItem ),
pin.modelPinName ) );
55 const wxString& aCacheDir,
REPORTER& aReporter )
const
66 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
75 KIBIS kibis( std::string(
path.c_str() ) );
76 kibis.
m_cacheDir = std::string( aCacheDir.c_str() );
80 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS file '%s'" ), ibisLibFilename ) );
85 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS component '%s'" ), ibisCompName ) );
91 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS component '%s'" ), ibisCompName ) );
95 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS pin '%s' in component '%s'" ),
102 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS pin '%s' in component '%s'" ),
110 THROW_IO_ERROR( wxString::Format(
_(
"Could not find IBIS model '%s'" ), ibisModelName ) );
113 THROW_IO_ERROR( wxString::Format(
_(
"Invalid IBIS model '%s'" ), ibisModelName ) );
135 case SIM_MODEL::TYPE::KIBIS_DEVICE:
143 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
145 std::string paramValue =
"";
148 paramValue = dc->value;
150 if( paramValue ==
"hi-Z" )
152 else if( paramValue ==
"low" )
154 else if( paramValue ==
"high" )
165 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
191 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
215 wxFAIL_MSG(
"Unknown IBIS model type" );
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 );
233 std::vector<PARAM::INFO>* paramInfos =
nullptr;
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;
244 for(
const PARAM::INFO& paramInfo : *paramInfos )
262 cacheFn.AppendDir( wxT(
"ibis" ) );
263 cacheFn.SetFullName( aItem.
refName +
".cache" );
265 wxFile cacheFile( cacheFn.GetFullPath(), wxFile::write );
267 if( !cacheFile.IsOpened() )
268 wxLogError(
_(
"Could not open file '%s' to write IBIS model" ), cacheFn.GetFullPath() );
272 wxString cacheFilepath = cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
273 std::string modelData = spiceGenerator.
IbisDevice( aItem, aSchematic, cacheFilepath, aReporter );
275 cacheFile.Write( wxString( modelData ) );
277 return { cacheFn.GetFullPath() };
290 AddPin( {
"IN/OUT",
"2" } );
302 AddPin( {
"PIN_A",
"1" } );
303 AddPin( {
"PIN_B",
"2" } );
315 static const PARAM::INFO
info = [&]
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";
343 const std::string& aModelName )
402 if( param1.info.name == param2.
info.
name )
462 std::vector<PARAM::INFO> paramInfos;
463 PARAM::INFO paramInfo;
465 paramInfo.name =
"vcc";
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 );
475 paramInfo.name =
"rpin";
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 );
485 paramInfo.name =
"lpin";
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 );
495 paramInfo.name =
"cpin";
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 );
511 case TYPE::KIBIS_DRIVER_DC:
513 paramInfos.push_back( param );
517 case TYPE::KIBIS_DRIVER_RECT:
519 paramInfos.push_back( param );
523 case TYPE::KIBIS_DRIVER_PRBS:
525 paramInfos.push_back( param );
539 std::vector<PARAM::INFO> paramInfos;
540 PARAM::INFO paramInfo;
542 paramInfo.name =
"dc";
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 );
557 std::vector<PARAM::INFO> paramInfos;
558 PARAM::INFO paramInfo;
560 paramInfo.name =
"ton";
562 paramInfo.unit =
"s";
563 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
564 paramInfo.defaultValue =
"";
565 paramInfo.description =
_(
"ON time" );
566 paramInfos.push_back( paramInfo );
568 paramInfo.name =
"toff";
570 paramInfo.unit =
"s";
571 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
572 paramInfo.defaultValue =
"";
573 paramInfo.description =
_(
"OFF time" );
574 paramInfos.push_back( paramInfo );
576 paramInfo.name =
"td";
578 paramInfo.unit =
"s";
579 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
580 paramInfo.defaultValue =
"0";
581 paramInfo.description =
_(
"Delay" );
582 paramInfos.push_back( paramInfo );
584 paramInfo.name =
"n";
587 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
588 paramInfo.defaultValue =
"1";
589 paramInfo.description =
_(
"Number of cycles" );
590 paramInfos.push_back( paramInfo );
598 std::vector<PARAM::INFO> paramInfos;
599 PARAM::INFO paramInfo;
601 paramInfo.name =
"f0";
603 paramInfo.unit =
"Hz";
604 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
605 paramInfo.defaultValue =
"";
606 paramInfo.description =
_(
"Bitrate" );
607 paramInfos.push_back( paramInfo );
609 paramInfo.name =
"td";
611 paramInfo.unit =
"s";
612 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
613 paramInfo.defaultValue =
"";
614 paramInfo.description =
_(
"Delay" );
615 paramInfos.push_back( paramInfo );
617 paramInfo.name =
"n";
620 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
621 paramInfo.defaultValue =
"";
622 paramInfo.description =
_(
"Number of bits" );
623 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.
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
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
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 AddPin(const SIM_MODEL_PIN &aPin)
const SPICE_GENERATOR & SpiceGenerator() const
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.