KiCad PCB EDA Suite
Loading...
Searching...
No Matches
time_domain_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
24#include <board.h>
27
28
30{
32}
33
34
35std::vector<int64_t>
36TIME_DOMAIN_PARAMETERS_USER_DEFINED::GetPropagationDelays( const std::vector<LENGTH_DELAY_CALCULATION_ITEM>& aItems,
37 const TIME_DOMAIN_GEOMETRY_CONTEXT& aContext )
38{
39 if( aItems.empty() )
40 return {};
41
42 const wxString delayProfileName = aItems.front().GetEffectiveNetClass()->GetDelayProfile();
43 const DELAY_PROFILE* delayProfile = GetDelayProfile( delayProfileName );
44
45 if( !delayProfile )
46 return std::vector<int64_t>( aItems.size(), 0 );
47
48 std::vector<int64_t> propagationDelays;
49 propagationDelays.reserve( aItems.size() );
50
51 for( const LENGTH_DELAY_CALCULATION_ITEM& item : aItems )
52 propagationDelays.emplace_back( getPropagationDelay( item, aContext, delayProfile ) );
53
54 return propagationDelays;
55}
56
57
59 const TIME_DOMAIN_GEOMETRY_CONTEXT& aContext )
60{
62 return 0;
63
64 const wxString delayProfileName = aItem.GetEffectiveNetClass()->GetDelayProfile();
65 const DELAY_PROFILE* delayProfile = GetDelayProfile( delayProfileName );
66
67 if( !delayProfile )
68 return 0;
69
70 return getPropagationDelay( aItem, aContext, delayProfile );
71}
72
73
75 const TIME_DOMAIN_GEOMETRY_CONTEXT& aContext,
76 const DELAY_PROFILE* aDelayProfile ) const
77{
79 return 0;
80
81 const LENGTH_DELAY_CALCULATION_ITEM::TYPE itemType = aItem.Type();
82
83 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::LINE )
84 {
85 const double delayUnit = aDelayProfile->m_LayerPropagationDelays.at( aItem.GetStartLayer() );
86 return static_cast<int64_t>( delayUnit * ( static_cast<double>( aItem.GetLine().Length() ) / PCB_IU_PER_MM ) );
87 }
88
89 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::VIA )
90 {
91 const PCB_LAYER_ID signalStartLayer = aItem.GetStartLayer();
92 const PCB_LAYER_ID signalEndLayer = aItem.GetEndLayer();
93 const PCB_LAYER_ID viaStartLayer = aItem.GetVia()->Padstack().StartLayer();
94 const PCB_LAYER_ID viaEndLayer = aItem.GetVia()->Padstack().EndLayer();
95
96 // First check for a layer-to-layer override - this assumes that the layers are already in CuStack() order
97 auto& viaOverrides = m_viaOverridesCache.at( aDelayProfile->m_ProfileName );
98
99 const auto viaItr = viaOverrides.find(
100 VIA_OVERRIDE_CACHE_KEY{ signalStartLayer, signalEndLayer, viaStartLayer, viaEndLayer } );
101
102 if( viaItr != viaOverrides.end() )
103 return viaItr->second;
104
105 // Otherwise, return the tuning profile default
106 const double distance = m_lengthCalculation->StackupHeight( signalStartLayer, signalEndLayer );
107 return static_cast<int64_t>( aDelayProfile->m_ViaPropagationDelay * ( distance / PCB_IU_PER_MM ) );
108 }
109
110 if( itemType == LENGTH_DELAY_CALCULATION_ITEM::TYPE::PAD )
111 {
112 return aItem.GetPad()->GetPadToDieDelay();
113 }
114
115 return 0;
116}
117
118
120{
121 auto itr = m_delayProfilesCache.find( aDelayProfileName );
122
123 if( itr != m_delayProfilesCache.end() )
124 return itr->second;
125
126 return nullptr;
127}
128
129
130int64_t
132 const TIME_DOMAIN_GEOMETRY_CONTEXT& aContext )
133{
134 const wxString delayProfileName = aContext.NetClass->GetDelayProfile();
135 const DELAY_PROFILE* profile = GetDelayProfile( delayProfileName );
136
137 if( !profile )
138 return 0;
139
140 const double delayUnit = profile->m_LayerPropagationDelays.at( aContext.Layer ); // Time IU / MM
141 const double lengthInMM = static_cast<double>( aDelay ) / delayUnit; // MM
142 return static_cast<int64_t>( lengthInMM * PCB_IU_PER_MM ); // Length IU
143}
144
145
147 const SHAPE_LINE_CHAIN& aShape, const TIME_DOMAIN_GEOMETRY_CONTEXT& aContext )
148{
149 const wxString delayProfileName = aContext.NetClass->GetDelayProfile();
150 const DELAY_PROFILE* profile = GetDelayProfile( delayProfileName );
151
152 if( !profile )
153 return 0;
154
155 const double delayUnit = profile->m_LayerPropagationDelays.at( aContext.Layer );
156 return static_cast<int64_t>( delayUnit * ( static_cast<double>( aShape.Length() ) / PCB_IU_PER_MM ) );
157}
158
159
161{
162 m_delayProfilesCache.clear();
163 m_viaOverridesCache.clear();
164
165 if( const PROJECT* project = m_board->GetProject() )
166 {
167 TIME_DOMAIN_PARAMETERS* params = project->GetProjectFile().TimeDomainParameters().get();
168
169 for( const DELAY_PROFILE& profile : params->GetDelayProfiles() )
170 {
171 m_delayProfilesCache[profile.m_ProfileName] = &profile;
172
173 std::map<VIA_OVERRIDE_CACHE_KEY, int64_t>& viaOverrides = m_viaOverridesCache[profile.m_ProfileName];
174
175 for( const DELAY_PROFILE_VIA_OVERRIDE_ENTRY& viaOverride : profile.m_ViaOverrides )
176 {
177 viaOverrides[VIA_OVERRIDE_CACHE_KEY{ viaOverride.m_SignalLayerFrom, viaOverride.m_SignalLayerTo,
178 viaOverride.m_ViaLayerFrom, viaOverride.m_ViaLayerTo }] =
179 viaOverride.m_Delay;
180 }
181 }
182 }
183}
constexpr double PCB_IU_PER_MM
Pcbnew IU is 1 nanometer.
Definition: base_units.h:70
PROJECT * GetProject() const
Definition: board.h:511
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.
int StackupHeight(PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
Returns the stackup distance between the two given layers.
wxString GetDelayProfile() const
Definition: netclass.h:243
PCB_LAYER_ID EndLayer() const
Definition: padstack.cpp:713
PCB_LAYER_ID StartLayer() const
Definition: padstack.cpp:707
int GetPadToDieDelay() const
Definition: pad.h:456
const PADSTACK & Padstack() const
Definition: pcb_track.h:453
Container for project specific data.
Definition: project.h:64
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.
BOARD * m_board
The board all calculations are for.
LENGTH_DELAY_CALCULATION * m_lengthCalculation
The parent length / delay calculation object.
int64_t GetPropagationDelay(const LENGTH_DELAY_CALCULATION_ITEM &aItem, const TIME_DOMAIN_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delay (in internal units) for the given item in the given geometry context.
const DELAY_PROFILE * GetDelayProfile(const wxString &aDelayProfileName)
Gets the tuning profile pointer for the given tuning profile name.
void OnSettingsChanged() override
Event called by the length and time calculation architecture if netclass definitions have changed.
std::map< wxString, const DELAY_PROFILE * > m_delayProfilesCache
Cached map of tuning profile names to per-layer time domain parameters.
int64_t GetTrackLengthForPropagationDelay(int64_t aDelay, const TIME_DOMAIN_GEOMETRY_CONTEXT &aContext) override
Gets the track length (in internal distance units) required for the given propagation delay (in inter...
std::map< wxString, std::map< VIA_OVERRIDE_CACHE_KEY, int64_t > > m_viaOverridesCache
Cached per-tuning profile via overrides.
int64_t CalculatePropagationDelayForShapeLineChain(const SHAPE_LINE_CHAIN &aShape, const TIME_DOMAIN_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delay for the given shape line chain.
int64_t getPropagationDelay(const LENGTH_DELAY_CALCULATION_ITEM &aItem, const TIME_DOMAIN_GEOMETRY_CONTEXT &aContext, const DELAY_PROFILE *aDelayProfile) const
Gets the propagation delay (in internal units) for the given item in the given geometry context,...
std::vector< int64_t > GetPropagationDelays(const std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, const TIME_DOMAIN_GEOMETRY_CONTEXT &aContext) override
Gets the propagation delays (in internal units) for the given items in the given geometry context.
TIME_DOMAIN_PARAMETERS stores the configuration for time-domain tuning.
const std::vector< DELAY_PROFILE > & GetDelayProfiles() const
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
Represents a single line in the time domain configuration net class configuration grid.
std::map< PCB_LAYER_ID, int > m_LayerPropagationDelays
A data structure to contain basic geometry data which can affect signal propagation calculations.
PCB_LAYER_ID Layer
The layer this track is on.
const NETCLASS * NetClass
The net class this track belongs to.