KiCad PCB EDA Suite
Loading...
Searching...
No Matches
tuning_profile_parameters_user_defined.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 2
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 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 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
26#include <board.h>
28#include <pad.h>
29#include <pcb_track.h>
31
32
37
38
39std::vector<int64_t>
40TUNING_PROFILE_PARAMETERS_USER_DEFINED::GetPropagationDelays( const std::vector<LENGTH_DELAY_CALCULATION_ITEM>& aItems,
41 const TUNING_PROFILE_GEOMETRY_CONTEXT& aContext )
42{
43 if( aItems.empty() )
44 return {};
45
46 const wxString delayProfileName = aItems.front().GetEffectiveNetClass()->GetTuningProfile();
47 const TUNING_PROFILE* delayProfile = GetTuningProfile( delayProfileName );
48
49 if( !delayProfile )
50 return std::vector<int64_t>( aItems.size(), 0 );
51
52 std::vector<int64_t> propagationDelays;
53 propagationDelays.reserve( aItems.size() );
54
55 for( const LENGTH_DELAY_CALCULATION_ITEM& item : aItems )
56 propagationDelays.emplace_back( getPropagationDelay( item, aContext, delayProfile ) );
57
58 return propagationDelays;
59}
60
61
63 const TUNING_PROFILE_GEOMETRY_CONTEXT& aContext )
64{
66 return 0;
67
68 const wxString delayProfileName = aItem.GetEffectiveNetClass()->GetTuningProfile();
69 const TUNING_PROFILE* delayProfile = GetTuningProfile( delayProfileName );
70
71 if( !delayProfile )
72 return 0;
73
74 return getPropagationDelay( aItem, aContext, delayProfile );
75}
76
77
79 const TUNING_PROFILE_GEOMETRY_CONTEXT& aContext,
80 const TUNING_PROFILE* aDelayProfile ) const
81{
83 return 0;
84
85 const LENGTH_DELAY_CALCULATION_ITEM::TYPE itemType = aItem.Type();
86
87 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::LINE )
88 {
89 double delayUnit = 0.0;
90
91 if( aDelayProfile->m_TrackPropagationEntriesMap.contains( aItem.GetStartLayer() ) )
92 {
94 aDelayProfile->m_TrackPropagationEntriesMap.at( aItem.GetStartLayer() );
95 delayUnit = entry.GetDelay();
96 }
97
98 return static_cast<int64_t>( delayUnit * ( static_cast<double>( aItem.GetLine().Length() ) / PCB_IU_PER_MM ) );
99 }
100
101 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::VIA )
102 {
103 if( !aDelayProfile->m_EnableTimeDomainTuning )
104 return 0;
105
106 const PCB_LAYER_ID signalStartLayer = aItem.GetStartLayer();
107 const PCB_LAYER_ID signalEndLayer = aItem.GetEndLayer();
108 const PCB_LAYER_ID viaStartLayer = aItem.GetVia()->Padstack().StartLayer();
109 const PCB_LAYER_ID viaEndLayer = aItem.GetVia()->Padstack().EndLayer();
110
111 // First check for a layer-to-layer override - this assumes that the layers are already in CuStack() order
112 auto& viaOverrides = m_viaOverridesCache.at( aDelayProfile->m_ProfileName );
113
114 const auto viaItr = viaOverrides.find(
115 VIA_OVERRIDE_CACHE_KEY{ signalStartLayer, signalEndLayer, viaStartLayer, viaEndLayer } );
116
117 if( viaItr != viaOverrides.end() )
118 return viaItr->second;
119
120 // Otherwise, return the tuning profile default
121 const double distance = m_lengthCalculation->StackupHeight( signalStartLayer, signalEndLayer );
122 return static_cast<int64_t>( aDelayProfile->m_ViaPropagationDelay * ( distance / PCB_IU_PER_MM ) );
123 }
124
125 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::PAD )
126 {
127 return aItem.GetPad()->GetPadToDieDelay();
128 }
129
130 return 0;
131}
132
133
135{
136 auto itr = m_delayProfilesCache.find( aDelayProfileName );
137
138 if( itr != m_delayProfilesCache.end() )
139 return itr->second;
140
141 return nullptr;
142}
143
144
146 int64_t aDelay, const TUNING_PROFILE_GEOMETRY_CONTEXT& aContext )
147{
148 const wxString delayProfileName = aContext.NetClass->GetTuningProfile();
149 const TUNING_PROFILE* profile = GetTuningProfile( delayProfileName );
150
151 if( !profile )
152 return 0;
153
154 double delayUnit = 0.0;
155
156 if( profile->m_TrackPropagationEntriesMap.contains( aContext.Layer ) )
157 {
158 const DELAY_PROFILE_TRACK_PROPAGATION_ENTRY& entry = profile->m_TrackPropagationEntriesMap.at( aContext.Layer );
159 delayUnit = entry.GetDelay();
160 }
161
162 const double lengthInMM = static_cast<double>( aDelay ) / delayUnit; // MM
163 return static_cast<int64_t>( lengthInMM * PCB_IU_PER_MM ); // Length IU
164}
165
166
168 const SHAPE_LINE_CHAIN& aShape, const TUNING_PROFILE_GEOMETRY_CONTEXT& aContext )
169{
170 const wxString delayProfileName = aContext.NetClass->GetTuningProfile();
171 const TUNING_PROFILE* profile = GetTuningProfile( delayProfileName );
172
173 if( !profile )
174 return 0;
175
176 double delayUnit = 0.0;
177
178 if( profile->m_TrackPropagationEntriesMap.contains( aContext.Layer ) )
179 {
180 const DELAY_PROFILE_TRACK_PROPAGATION_ENTRY& entry = profile->m_TrackPropagationEntriesMap.at( aContext.Layer );
181 delayUnit = entry.GetDelay();
182 }
183
184 return static_cast<int64_t>( delayUnit * ( static_cast<double>( aShape.Length() ) / PCB_IU_PER_MM ) );
185}
186
187
189{
190 m_delayProfilesCache.clear();
191 m_viaOverridesCache.clear();
192
193 if( const PROJECT* project = m_board->GetProject() )
194 {
195 TUNING_PROFILES* params = project->GetProjectFile().TuningProfileParameters().get();
196
197 for( const TUNING_PROFILE& profile : params->GetTuningProfiles() )
198 {
199 m_delayProfilesCache[profile.m_ProfileName] = &profile;
200 std::map<VIA_OVERRIDE_CACHE_KEY, int64_t>& viaOverrides = m_viaOverridesCache[profile.m_ProfileName];
201
202 for( const DELAY_PROFILE_VIA_OVERRIDE_ENTRY& viaOverride : profile.m_ViaOverrides )
203 {
204 viaOverrides[VIA_OVERRIDE_CACHE_KEY{ viaOverride.m_SignalLayerFrom, viaOverride.m_SignalLayerTo,
205 viaOverride.m_ViaLayerFrom, viaOverride.m_ViaLayerTo }] =
206 viaOverride.m_Delay;
207 }
208 }
209 }
210}
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition base_units.h:70
Represents a single line in a time domain profile track propagation setup.
int GetDelay(const bool aForce=false) const
Lightweight class which holds a pad, via, or a routed trace outline.
MERGE_STATUS GetMergeStatus() const
Gets the MERGE_STATUS of this item.
TYPE
The type of routing object this item proxies.
TYPE Type() const
Gets the routing item type.
const PCB_VIA * GetVia() const
Gets the VIA associated with this item.
const NETCLASS * GetEffectiveNetClass() const
Returns the effective net class for the item.
SHAPE_LINE_CHAIN & GetLine() const
Gets the SHAPE_LINE_CHAIN associated with this item.
PCB_LAYER_ID GetEndLayer() const
Gets the end board layer for the proxied item.
const PAD * GetPad() const
Gets the parent PAD associated with this item.
PCB_LAYER_ID GetStartLayer() const
Gets the start board layer for the proxied item.
wxString GetTuningProfile() const
Definition netclass.h:246
PCB_LAYER_ID EndLayer() const
PCB_LAYER_ID StartLayer() const
int GetPadToDieDelay() const
Definition pad.h:581
const PADSTACK & Padstack() const
Definition pcb_track.h:406
Container for project specific data.
Definition project.h:65
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
long long int Length() const
Return length of the line chain in Euclidean metric.
TUNING_PROFILES stores the configuration for impedance / delay tuning profiles.
const std::vector< TUNING_PROFILE > & GetTuningProfiles() const
BOARD * m_board
The board all calculations are for.
LENGTH_DELAY_CALCULATION * m_lengthCalculation
The parent length / delay calculation object.
std::map< wxString, const TUNING_PROFILE * > m_delayProfilesCache
Cached map of tuning profile names to per-layer time domain parameters.
int64_t GetTrackLengthForPropagationDelay(int64_t aDelay, const TUNING_PROFILE_GEOMETRY_CONTEXT &aContext) override
Gets the track length (in internal distance units) required for the given propagation delay (in inter...
const TUNING_PROFILE * GetTuningProfile(const wxString &aDelayProfileName)
Gets the tuning profile pointer for the given tuning profile name.
int64_t CalculatePropagationDelayForShapeLineChain(const SHAPE_LINE_CHAIN &aShape, const TUNING_PROFILE_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delay for the given shape line chain.
std::map< wxString, std::map< VIA_OVERRIDE_CACHE_KEY, int64_t > > m_viaOverridesCache
Cached per-tuning profile via overrides.
int64_t GetPropagationDelay(const LENGTH_DELAY_CALCULATION_ITEM &aItem, const TUNING_PROFILE_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delay (in internal units) for the given item in the given geometry context.
void OnSettingsChanged() override
Event called by the length and time calculation architecture if netclass definitions have changed.
std::vector< int64_t > GetPropagationDelays(const std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, const TUNING_PROFILE_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delays (in internal units) for the given items in the given geometry context.
int64_t getPropagationDelay(const LENGTH_DELAY_CALCULATION_ITEM &aItem, const TUNING_PROFILE_GEOMETRY_CONTEXT &aContext, const TUNING_PROFILE *aDelayProfile) const
Gets the propagation delay (in internal units) for the given item in the given geometry context,...
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
Represents a single line in the time domain configuration via overrides configuration grid.
PCB_LAYER_ID m_SignalLayerFrom
PCB_LAYER_ID m_ViaLayerFrom
int m_Delay
PCB_LAYER_ID m_SignalLayerTo
PCB_LAYER_ID m_ViaLayerTo
A data structure to contain basic geometry data which can affect signal propagation calculations.
const NETCLASS * NetClass
The net class this track belongs to.
PCB_LAYER_ID Layer
The layer this track is on.
Represents a single line in the tuning profile configuration grid.
std::map< PCB_LAYER_ID, DELAY_PROFILE_TRACK_PROPAGATION_ENTRY > m_TrackPropagationEntriesMap