2022-09-27 20:47:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-03 15:29:45 +00:00
|
|
|
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-09-27 20:47:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2024-06-10 19:16:30 +00:00
|
|
|
#include <sim/sim_library_ibis.h>
|
|
|
|
#include <sim/sim_model_ibis.h>
|
2022-09-27 20:47:00 +00:00
|
|
|
#include <ki_exception.h>
|
|
|
|
#include <locale_io.h>
|
2022-11-07 18:33:31 +00:00
|
|
|
#include <pegtl/contrib/parse_tree.hpp>
|
2024-04-20 09:44:34 +00:00
|
|
|
#include <sch_pin.h>
|
2022-09-27 20:47:00 +00:00
|
|
|
|
|
|
|
|
2024-06-10 19:16:30 +00:00
|
|
|
void SIM_LIBRARY_IBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
SIM_LIBRARY::ReadFile( aFilePath, aReporter );
|
2023-09-06 10:37:50 +00:00
|
|
|
m_kibis = KIBIS( aFilePath.ToStdString(), &aReporter );
|
2022-09-27 20:47:00 +00:00
|
|
|
|
|
|
|
if( !m_kibis.m_valid )
|
2023-01-03 15:29:45 +00:00
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter.Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2023-01-03 15:29:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-09-27 20:47:00 +00:00
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN pinA( nullptr );
|
|
|
|
SCH_PIN pinB( nullptr );
|
2022-12-17 15:21:35 +00:00
|
|
|
pinA.SetNumber( wxT( "1" ) );
|
|
|
|
pinB.SetNumber( wxT( "2" ) );
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> pins = { &pinA, &pinB };
|
2022-09-29 08:35:01 +00:00
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
|
|
|
|
{
|
2023-03-16 15:57:27 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( SIM_MODEL::TYPE::KIBIS_DEVICE, pins, aReporter ) );
|
2022-09-27 20:47:00 +00:00
|
|
|
m_modelNames.emplace_back( kcomp.m_name );
|
|
|
|
|
2024-06-10 19:16:30 +00:00
|
|
|
SIM_MODEL_IBIS* libcomp = dynamic_cast<SIM_MODEL_IBIS*>( m_models.back().get() );
|
2022-09-29 08:35:01 +00:00
|
|
|
|
|
|
|
if ( libcomp )
|
|
|
|
InitModel( *libcomp, kcomp.m_name );
|
2022-09-27 20:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 00:59:44 +00:00
|
|
|
|
2024-06-10 19:16:30 +00:00
|
|
|
bool SIM_LIBRARY_IBIS::InitModel( SIM_MODEL_IBIS& aModel, wxString aCompName )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
for( KIBIS_COMPONENT& kcomp : m_kibis.m_components )
|
|
|
|
{
|
|
|
|
if( kcomp.m_name != aCompName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aModel.m_componentName = kcomp.m_name;
|
|
|
|
aModel.m_ibisPins.clear();
|
|
|
|
|
|
|
|
for( KIBIS_PIN& kpin : kcomp.m_pins )
|
|
|
|
{
|
|
|
|
aModel.m_ibisPins.emplace_back( kpin.m_pinNumber, kpin.m_signalName );
|
2022-10-25 09:45:40 +00:00
|
|
|
|
|
|
|
if( kpin.isDiffPin() )
|
|
|
|
m_diffPins.emplace_back( kcomp.m_name, kpin.m_pinNumber );
|
2022-09-27 20:47:00 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-10-08 00:59:44 +00:00
|
|
|
}
|
2022-10-25 09:45:40 +00:00
|
|
|
|
|
|
|
|
2024-06-10 19:16:30 +00:00
|
|
|
bool SIM_LIBRARY_IBIS::isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const
|
2022-10-25 09:45:40 +00:00
|
|
|
{
|
|
|
|
for( std::pair<std::string, std::string> aInfo : m_diffPins )
|
|
|
|
{
|
|
|
|
if( aInfo.first == aComp && aInfo.second == aPinNumber )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-11-18 20:07:59 +00:00
|
|
|
}
|