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() );
94 THROW_IO_ERRORF(
_(
"Could not find IBIS pin '%s' in component '%s'" ), ibisPinName, ibisCompName );
97 THROW_IO_ERRORF(
_(
"Invalid IBIS pin '%s' in component '%s'" ), ibisPinName, ibisCompName );
127 case SIM_MODEL::TYPE::KIBIS_DEVICE:
135 case SIM_MODEL::TYPE::KIBIS_DRIVER_DC:
137 std::string paramValue =
"";
140 paramValue = dc->value;
142 if( paramValue ==
"hi-Z" )
144 else if( paramValue ==
"low" )
146 else if( paramValue ==
"high" )
157 case SIM_MODEL::TYPE::KIBIS_DRIVER_RECT:
183 case SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS:
207 wxFAIL_MSG(
"Unknown IBIS model type" );
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 );
225 std::vector<PARAM::INFO>* paramInfos =
nullptr;
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;
236 for(
const PARAM::INFO& paramInfo : *paramInfos )
254 cacheFn.AppendDir( wxT(
"ibis" ) );
255 cacheFn.SetFullName( aItem.
refName +
".cache" );
257 wxFile cacheFile( cacheFn.GetFullPath(), wxFile::write );
259 if( !cacheFile.IsOpened() )
260 wxLogError(
_(
"Could not open file '%s' to write IBIS model" ), cacheFn.GetFullPath() );
264 wxString cacheFilepath = cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
265 std::string modelData = spiceGenerator.
IbisDevice( aItem, aSchematic, cacheFilepath, aReporter );
267 cacheFile.Write( wxString( modelData ) );
269 return { cacheFn.GetFullPath() };
282 AddPin( {
"IN/OUT",
"2" } );
294 AddPin( {
"PIN_A",
"1" } );
295 AddPin( {
"PIN_B",
"2" } );
307 static const PARAM::INFO
info = [&]
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";
335 const std::string& aModelName )
394 if( param1.info.name == param2.
info.
name )
454 std::vector<PARAM::INFO> paramInfos;
455 PARAM::INFO paramInfo;
457 paramInfo.name =
"vcc";
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 );
467 paramInfo.name =
"rpin";
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 );
477 paramInfo.name =
"lpin";
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 );
487 paramInfo.name =
"cpin";
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 );
503 case TYPE::KIBIS_DRIVER_DC:
505 paramInfos.push_back( param );
509 case TYPE::KIBIS_DRIVER_RECT:
511 paramInfos.push_back( param );
515 case TYPE::KIBIS_DRIVER_PRBS:
517 paramInfos.push_back( param );
531 std::vector<PARAM::INFO> paramInfos;
532 PARAM::INFO paramInfo;
534 paramInfo.name =
"dc";
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 );
549 std::vector<PARAM::INFO> paramInfos;
550 PARAM::INFO paramInfo;
552 paramInfo.name =
"ton";
554 paramInfo.unit =
"s";
555 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
556 paramInfo.defaultValue =
"";
557 paramInfo.description =
_(
"ON time" );
558 paramInfos.push_back( paramInfo );
560 paramInfo.name =
"toff";
562 paramInfo.unit =
"s";
563 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
564 paramInfo.defaultValue =
"";
565 paramInfo.description =
_(
"OFF time" );
566 paramInfos.push_back( paramInfo );
568 paramInfo.name =
"td";
570 paramInfo.unit =
"s";
571 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
572 paramInfo.defaultValue =
"0";
573 paramInfo.description =
_(
"Delay" );
574 paramInfos.push_back( paramInfo );
576 paramInfo.name =
"n";
579 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
580 paramInfo.defaultValue =
"1";
581 paramInfo.description =
_(
"Number of cycles" );
582 paramInfos.push_back( paramInfo );
590 std::vector<PARAM::INFO> paramInfos;
591 PARAM::INFO paramInfo;
593 paramInfo.name =
"f0";
595 paramInfo.unit =
"Hz";
596 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
597 paramInfo.defaultValue =
"";
598 paramInfo.description =
_(
"Bitrate" );
599 paramInfos.push_back( paramInfo );
601 paramInfo.name =
"td";
603 paramInfo.unit =
"s";
604 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
605 paramInfo.defaultValue =
"";
606 paramInfo.description =
_(
"Delay" );
607 paramInfos.push_back( paramInfo );
609 paramInfo.name =
"n";
612 paramInfo.category = PARAM::CATEGORY::WAVEFORM;
613 paramInfo.defaultValue =
"";
614 paramInfo.description =
_(
"Number of bits" );
615 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
#define THROW_IO_ERRORF(msg,...)
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.