KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_library_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
21#include <sim/sim_model_ibis.h>
22#include <ki_exception.h>
23#include <locale_io.h>
24#include <pegtl/contrib/parse_tree.hpp>
25
26
27void SIM_LIBRARY_IBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
28{
29 SIM_LIBRARY::ReadFile( aFilePath, aReporter );
30 m_kibis = KIBIS( aFilePath.ToStdString(), &aReporter );
31
32 if( !m_kibis.m_valid )
33 {
34 aReporter.Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ),
36 return;
37 }
38
39 const std::vector<wxString> pins = { wxS( "1" ), wxS( "2" ) };
40
41 for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
42 {
43 m_models.push_back( SIM_MODEL::Create( SIM_MODEL::TYPE::KIBIS_DEVICE, pins, aReporter ) );
44 m_modelNames.emplace_back( kcomp.m_name );
45
46 SIM_MODEL_IBIS* libcomp = dynamic_cast<SIM_MODEL_IBIS*>( m_models.back().get() );
47
48 if ( libcomp )
49 InitModel( *libcomp, kcomp.m_name );
50 }
51}
52
53
54bool SIM_LIBRARY_IBIS::InitModel( SIM_MODEL_IBIS& aModel, wxString aCompName )
55{
56 for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
57 {
58 if( kcomp.m_name != aCompName )
59 continue;
60
61 aModel.m_componentName = kcomp.m_name;
62 aModel.m_ibisPins.clear();
63
64 for( KIBIS_PIN& kpin : kcomp.m_pins )
65 {
66 aModel.m_ibisPins.emplace_back( kpin.m_pinNumber, kpin.m_signalName );
67
68 if( kpin.isDiffPin() )
69 m_diffPins.emplace_back( kcomp.m_name, kpin.m_pinNumber );
70 }
71 return true;
72 }
73 return false;
74}
75
76
77bool SIM_LIBRARY_IBIS::isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const
78{
79 for( std::pair<std::string, std::string> aInfo : m_diffPins )
80 {
81 if( aInfo.first == aComp && aInfo.second == aPinNumber )
82 return true;
83 }
84 return false;
85}
std::vector< KIBIS_PIN > m_pins
Definition kibis.h:501
std::string m_name
Name of the component.
Definition kibis.h:497
bool isDiffPin() const
Definition kibis.h:476
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition kibis.h:384
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition kibis.h:380
Definition kibis.h:513
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
void ReadFile(const wxString &aFilePath, REPORTER &aReporter) override
Read library from a source file.
friend class SIM_MODEL_IBIS
bool InitModel(SIM_MODEL_IBIS &aModel, wxString aCompName)
std::vector< std::pair< std::string, std::string > > m_diffPins
bool isPinDiff(const std::string &aComp, const std::string &aPinNumber) const
virtual void ReadFile(const wxString &aFilePath, REPORTER &aReporter)=0
Read library from a source file.
std::vector< std::string > m_modelNames
Definition sim_library.h:73
std::vector< std::unique_ptr< SIM_MODEL > > m_models
Definition sim_library.h:74
std::vector< std::pair< std::string, std::string > > m_ibisPins
std::string m_componentName
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
#define _(s)
@ RPT_SEVERITY_ERROR