KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_meander_skew_placer.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2015 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "pns_node.h"
23#include "pns_itemset.h"
24#include "pns_topology.h"
26#include "pns_solid.h"
27
28#include "pns_router.h"
29#include "pns_debug_decorator.h"
30
31namespace PNS {
32
34 MEANDER_PLACER ( aRouter )
35{
36 // Init temporary variables (do not leave uninitialized members)
43}
44
45
49
50
51bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
52{
53 if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T) )
54 {
55 Router()->SetFailureReason( _( "Please select a differential pair track you want to tune." ) );
56 return false;
57 }
58
59 m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
60 m_currentNode = nullptr;
62
63 m_world = Router()->GetWorld( )->Branch();
64 m_originLine = m_world->AssembleLine( m_initialSegment );
65
66 TOPOLOGY topo( m_world );
67 m_tunedPath = topo.AssembleTrivialPath( m_initialSegment, nullptr, true );
68
70 {
71 Router()->SetFailureReason( _( "Unable to find complementary differential pair "
72 "net for skew tuning. Make sure the names of the nets belonging "
73 "to a differential pair end with either _N/_P or +/-." ) );
74 return false;
75 }
76
77 if( m_originPair.Gap() < 0 )
78 m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
79
80 if( !m_originPair.PLine().SegmentCount() ||
81 !m_originPair.NLine().SegmentCount() )
82 return false;
83
84 m_tunedPathP = topo.AssembleTuningPath( Router()->GetInterface(), m_originPair.PLine().GetLink( 0 ), &m_startPad_p,
85 &m_endPad_p );
86
89
90 if( m_startPad_p )
91 {
92 m_padToDieLengthP += m_startPad_p->GetPadToDie();
93 m_padToDieDelayP += m_startPad_p->GetPadToDieDelay();
94 }
95
96 if( m_endPad_p )
97 {
98 m_padToDieLengthP += m_endPad_p->GetPadToDie();
99 m_padToDieDelayP += m_endPad_p->GetPadToDieDelay();
100 }
101
102 m_tunedPathN = topo.AssembleTuningPath( Router()->GetInterface(), m_originPair.NLine().GetLink( 0 ), &m_startPad_n,
103 &m_endPad_n );
104
107
108 if( m_startPad_n )
109 {
110 m_padToDieLengthN += m_startPad_n->GetPadToDie();
111 m_padToDieDelayN += m_startPad_n->GetPadToDieDelay();
112 }
113
114 if( m_endPad_n )
115 {
116 m_padToDieLengthN += m_endPad_n->GetPadToDie();
117 m_padToDieDelayN += m_endPad_n->GetPadToDieDelay();
118 }
119
120 m_world->Remove( m_originLine );
121
123 m_currentEnd = VECTOR2I( 0, 0 );
124
125 const BOARD_CONNECTED_ITEM* conItem = static_cast<BOARD_CONNECTED_ITEM*>( aStartItem->GetSourceItem() );
126 m_netClass = conItem->GetEffectiveNetClass();
127 m_settings.m_netClass = m_netClass;
128
129 if ( m_originPair.NetP() == m_originLine.Net() )
130 {
133
136
138 }
139 else
140 {
143
146
148 }
149
151
152 return true;
153}
154
155
163
164
172
173
175{
177}
178
179
180bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
181{
183
184 bool isPositive = m_originPair.NetP() == m_originLine.Net();
185
186 for( const ITEM* item : m_tunedPathP.CItems() )
187 {
188 if( const LINE* l = dyn_cast<const LINE*>( item ) )
189 {
190 PNS_DBG( Dbg(), AddItem, l, BLUE, 10000, wxT( "tuned-path-skew-p" ) );
191
192 m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 1 : 0 );
193 }
194 }
195
196 for( const ITEM* item : m_tunedPathN.CItems() )
197 {
198 if( const LINE* l = dyn_cast<const LINE*>( item ) )
199 {
200 PNS_DBG( Dbg(), AddItem, l, YELLOW, 10000, wxT( "tuned-path-skew-n" ) );
201
202 m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 0 : 1 );
203 }
204 }
205
206 return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew.Opt(),
207 m_coupledLength + m_settings.m_targetSkew.Min(),
208 m_coupledLength + m_settings.m_targetSkew.Max() );
209}
210
211
213{
215}
216
217
222
223
225{
226 if( m_settings.m_isTimeDomain )
227 {
228 const int64_t minSkew = m_router->GetInterface()->CalculateLengthForDelay(
229 m_settings.m_targetSkewDelay.Min(), m_originPair.Width(), true, m_originPair.Gap(),
230 m_router->GetCurrentLayer(), m_netClass );
231
232 const int64_t optSkew = m_router->GetInterface()->CalculateLengthForDelay(
233 m_settings.m_targetSkewDelay.Opt(), m_originPair.Width(), true, m_originPair.Gap(),
234 m_router->GetCurrentLayer(), m_netClass );
235
236 const int64_t maxSkew = m_router->GetInterface()->CalculateLengthForDelay(
237 m_settings.m_targetSkewDelay.Max(), m_originPair.Width(), true, m_originPair.Gap(),
238 m_router->GetCurrentLayer(), m_netClass );
239
240 m_settings.m_targetSkew.SetMin( static_cast<int>( minSkew ) );
241 m_settings.m_targetSkew.SetOpt( static_cast<int>( optSkew ) );
242 m_settings.m_targetSkew.SetMax( static_cast<int>( maxSkew ) );
243 }
244}
245}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
ROUTER * Router() const
Return current router settings.
ROUTER * m_router
DEBUG_DECORATOR * Dbg() const
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * GetSourceItem() const
Definition pns_item.h:202
bool OfKind(int aKindMask) const
Definition pns_item.h:181
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
int m_currentWidth
Meander settings.
MEANDER_SETTINGS m_settings
The current end point.
int64_t lineDelay(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad) const
Calculate the total delay of the line represented by an item set (tracks and vias)
NODE * m_world
Width of the meandered trace(s).
VECTOR2I getSnappedStartPoint(LINKED_ITEM *aStartItem, VECTOR2I aStartPoint)
long long int lineLength(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad) const
Calculate the total length of the line represented by an item set (tracks and vias)
bool doMove(const VECTOR2I &aP, ITEM *aEndItem, long long int aTargetLength, long long int aTargetMin, long long int aTargetMax)
LINKED_ITEM * m_initialSegment
Total length added by pad to die size.
MEANDER_PLACER(ROUTER *aRouter)
VECTOR2I m_currentStart
Current world state.
int64_t origPathDelay() const override
long long int origPathLength() const override
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
long long int TuningLengthResult() const override
Return the resultant length or skew of the tuned traces.
void calculateTimeDomainTargets() override
current routing start point (end of tail, beginning of head)
int64_t TuningDelayResult() const override
Return the resultant delay or skew of the tuned traces.
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition pns_node.cpp:143
void SetFailureReason(const wxString &aReason)
Definition pns_router.h:227
NODE * GetWorld() const
Definition pns_router.h:178
const DIFF_PAIR AssembleDiffPair(SEGMENT *aStart)
const ITEM_SET AssembleTuningPath(ROUTER_IFACE *aRouterIface, ITEM *aStart, SOLID **aStartPad=nullptr, SOLID **aEndPad=nullptr)
Like AssembleTrivialPath, but follows the track length algorithm, which discards segments that are fu...
const ITEM_SET AssembleTrivialPath(ITEM *aStart, std::pair< const JOINT *, const JOINT * > *aTerminalJoints=nullptr, bool aFollowLockedSegments=false)
Assemble a trivial path between two joints given a starting item.
@ BLUE
Definition color4d.h:56
@ YELLOW
Definition color4d.h:67
#define _(s)
Push and Shove diff pair dimensions (gap) settings dialog.
#define PNS_DBG(dbg, method,...)
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:61
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695