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#include <sch_pin.h>
26
27
28void SIM_LIBRARY_IBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
29{
30 SIM_LIBRARY::ReadFile( aFilePath, aReporter );
31 m_kibis = KIBIS( aFilePath.ToStdString(), &aReporter );
32
33 if( !m_kibis.m_valid )
34 {
35 aReporter.Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ),
37 return;
38 }
39
40 SCH_PIN pinA( nullptr );
41 SCH_PIN pinB( nullptr );
42 pinA.SetNumber( wxT( "1" ) );
43 pinB.SetNumber( wxT( "2" ) );
44 std::vector<SCH_PIN*> pins = { &pinA, &pinB };
45
46 for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
47 {
48 m_models.push_back( SIM_MODEL::Create( SIM_MODEL::TYPE::KIBIS_DEVICE, pins, aReporter ) );
49 m_modelNames.emplace_back( kcomp.m_name );
50
51 SIM_MODEL_IBIS* libcomp = dynamic_cast<SIM_MODEL_IBIS*>( m_models.back().get() );
52
53 if ( libcomp )
54 InitModel( *libcomp, kcomp.m_name );
55 }
56}
57
58
59bool SIM_LIBRARY_IBIS::InitModel( SIM_MODEL_IBIS& aModel, wxString aCompName )
60{
61 for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
62 {
63 if( kcomp.m_name != aCompName )
64 continue;
65
66 aModel.m_componentName = kcomp.m_name;
67 aModel.m_ibisPins.clear();
68
69 for( KIBIS_PIN& kpin : kcomp.m_pins )
70 {
71 aModel.m_ibisPins.emplace_back( kpin.m_pinNumber, kpin.m_signalName );
72
73 if( kpin.isDiffPin() )
74 m_diffPins.emplace_back( kcomp.m_name, kpin.m_pinNumber );
75 }
76 return true;
77 }
78 return false;
79}
80
81
82bool SIM_LIBRARY_IBIS::isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const
83{
84 for( std::pair<std::string, std::string> aInfo : m_diffPins )
85 {
86 if( aInfo.first == aComp && aInfo.second == aPinNumber )
87 return true;
88 }
89 return false;
90}
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:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:100
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:734
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, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
#define _(s)
@ RPT_SEVERITY_ERROR
KIBIS_PIN * pinA