KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_library_kibis.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 (C) 2022-2023 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, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <sim/sim_model_kibis.h>
26#include <ki_exception.h>
27#include <locale_io.h>
28#include <pegtl/contrib/parse_tree.hpp>
29#include <sch_pin.h>
30
31
32void SIM_LIBRARY_KIBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
33{
34 SIM_LIBRARY::ReadFile( aFilePath, aReporter );
35 m_kibis = KIBIS( aFilePath.ToStdString(), &aReporter );
36
37 if( !m_kibis.m_valid )
38 {
39 aReporter.Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ),
41 return;
42 }
43
44 SCH_PIN pinA( nullptr );
45 SCH_PIN pinB( nullptr );
46 pinA.SetNumber( wxT( "1" ) );
47 pinB.SetNumber( wxT( "2" ) );
48 std::vector<SCH_PIN*> pins = { &pinA, &pinB };
49
51 {
52 m_models.push_back( SIM_MODEL::Create( SIM_MODEL::TYPE::KIBIS_DEVICE, pins, aReporter ) );
53 m_modelNames.emplace_back( kcomp.m_name );
54
55 SIM_MODEL_KIBIS* libcomp = dynamic_cast<SIM_MODEL_KIBIS*>( m_models.back().get() );
56
57 if ( libcomp )
58 InitModel( *libcomp, kcomp.m_name );
59 }
60}
61
62
63bool SIM_LIBRARY_KIBIS::InitModel( SIM_MODEL_KIBIS& aModel, wxString aCompName )
64{
66 {
67 if( kcomp.m_name != aCompName )
68 continue;
69
70 aModel.m_componentName = kcomp.m_name;
71 aModel.m_ibisPins.clear();
72
73 for( KIBIS_PIN& kpin : kcomp.m_pins )
74 {
75 aModel.m_ibisPins.emplace_back( kpin.m_pinNumber, kpin.m_signalName );
76
77 if( kpin.isDiffPin() )
78 m_diffPins.emplace_back( kcomp.m_name, kpin.m_pinNumber );
79 }
80 return true;
81 }
82 return false;
83}
84
85
86bool SIM_LIBRARY_KIBIS::isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const
87{
88 for( std::pair<std::string, std::string> aInfo : m_diffPins )
89 {
90 if( aInfo.first == aComp && aInfo.second == aPinNumber )
91 return true;
92 }
93 return false;
94}
bool m_valid
Definition: kibis.h:49
std::vector< KIBIS_PIN > m_pins
Definition: kibis.h:422
std::string m_name
Name of the component.
Definition: kibis.h:418
std::string m_pinNumber
Pin Number Examples : 1, 2, 3 ( or for BGA ), A1, A2, A3, etc...
Definition: kibis.h:321
std::string m_signalName
Name of the pin Examples : "VCC", "GPIOA", "CLK", etc...
Definition: kibis.h:317
bool isDiffPin()
Definition: kibis.h:410
Definition: kibis.h:433
std::vector< KIBIS_COMPONENT > m_components
Definition: kibis.h:443
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)=0
Report a string with a given severity.
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:463
bool isPinDiff(const std::string &aComp, const std::string &aPinNumber) const
bool InitModel(SIM_MODEL_KIBIS &aModel, wxString aCompName)
std::vector< std::pair< std::string, std::string > > m_diffPins
void ReadFile(const wxString &aFilePath, REPORTER &aReporter) override
Read library from a source file.
virtual void ReadFile(const wxString &aFilePath, REPORTER &aReporter)=0
Read library from a source file.
Definition: sim_library.cpp:50
std::vector< std::string > m_modelNames
Definition: sim_library.h:77
std::vector< std::unique_ptr< SIM_MODEL > > m_models
Definition: sim_library.h:78
std::string m_componentName
std::vector< std::pair< std::string, std::string > > m_ibisPins
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
Definition: sim_model.cpp:492
#define _(s)
@ RPT_SEVERITY_ERROR