TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
escape.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Escape (fanout) planning, version 1 (roadmap M9; design doc 05 §3).
4//
5// Dense packages (QFP/TSOP/SOIC rows, BGA/LGA arrays) fail in the router's strict first pass when other nets'
6// routes take the channels a pin needs to leave its package: the pin is then "boxed in" until negotiation,
7// which large boards often do not reach within the budget. The plan reserves, for every pin that has to be
8// routed, a short escape corridor: straight out of the package for pins on its perimeter, and a dog-bone stub to
9// the diagonal interstitial via site for the inner balls of an SMD array (the classic BGA fanout; Yan & Wong,
10// "Recent research development in PCB layout", ICCAD 2010, §3; Kong, Yan & Wong, "Optimal simultaneous pin
11// assignment and escape routing for dense PCBs", ASP-DAC 2010, for the escape model). The router treats
12// another net's corridor as blocked in strict passes and as costly in negotiated passes, and releases a corridor
13// once its pin is connected. Reservations only remove options: every commit is still checked exactly, so the
14// plan cannot introduce violations.
15#include <functional>
16#include <string>
17#include <vector>
18
19#include "model/board.hpp"
20#include "model/rules.hpp"
21
22namespace tmk::route {
23
24using geom::Point;
25
27 int pad = -1; // board pad index
29 int layer = -1; // copper index the stub runs on
30 Point a, b; // centreline: pad centre -> escape point (or via site)
31 bool has_mid = false; // second-ring pins: a -> mid (between two outer balls) -> b
33 Coord band = 0; // half-width of the reserved strip around the centreline
34 bool via = false; // b is a dog-bone via site (reserved on every layer)
35 // Version 2 (escape_flow.hpp): the corridor continues from b through these points on tail_layer (the pad's
36 // layer, or the layer a dog-bone via changes to).
37 std::vector<Point> tail;
38 int tail_layer = -1;
39};
40
41// Half extents of a pad's bounding box along x and y (rotation applied).
42std::pair<Coord, Coord> pad_half_extents(const model::Pad& p);
43
45 int min_pads = 8; // smaller footprints escape easily
46 Coord max_pitch = 1'300'000; // pin pitch up to which a footprint counts as dense (1.27 mm BGAs included)
47 // Corridor length past the pad edge for perimeter pins. One variant, fixed budget: 0.5 / 1 / 2 / 3 mm gave
48 // logicbone 961 / 964 / 968 / 977 and decelerator 449 / 479 / 491 / 490 routed; 2 mm reserves less board
49 // area than 3 mm for nearly the same gain (doc 05 §12).
50 Coord length = 2'000'000;
51};
52
54 int parts = 0, perimeter = 0, second_ring = 0, dogbones = 0;
55};
56
57// Plans corridors for the pads with needs[pad] != 0. keep(net) is the distance another net's centreline must
58// keep from this net's centreline (track width + clearance); the band is that, capped at a share of the pin
59// pitch so the corridors of neighbouring pins never overlap. Deterministic: footprints and pads in board order.
60// channel(net), when given, is the gap a track of that net needs between two pads (narrowest legal width plus
61// twice the clearance): second-ring balls whose outer neighbours leave that much room escape on their own layer
62// between them (the classic two-ring fanout) instead of taking a dog-bone via.
63std::vector<EscapeCorridor> plan_escapes(const model::Board& b, const std::vector<char>& needs, const std::function<Coord(model::NetId)>& keep,
64 const EscapeOptions& o = {}, EscapeStats* stats = nullptr,
65 const std::function<Coord(model::NetId)>& channel = {});
66
67class Obstacles;
68
69// Escape feasibility (M9 analysis): can each pin of a dense package leave it at all under the board's rules?
70// A breadth-first search from the pad over a lattice of the package area, against fixed copper only (nothing
71// routed; fills as the obstacles are set: hard, or ignored with set_soft_zones), at the narrowest legal width
72// (the router's neck-down width), changing layers wherever that net's via passes every fixed check. The router's
73// custom-rule limits apply: per-net track layers and via permission, and position-dependent disallow rules.
74// A pin escapes when it reaches `margin` outside the box of the package's pad centres. Pins whose net is already
75// complete in the existing copper are `satisfied`, not searched; complete as the router's planner sees it, so with
76// soft zones a plane of the net that no pad touches yet leaves the net outstanding. The search is complete over
77// its finite lattice and window, so "dead" means "no escape on this lattice": an off-lattice path can exist in
78// rare cases (the router keeps trying those pins), and a pin that escapes alone may still lose its channel to its
79// neighbours.
80struct DeadPin {
81 int pad = -1;
82 std::string reason;
83};
84struct PartEscape {
85 int footprint = -1;
86 std::string ref;
88 int pins = 0, escapable = 0; // pins still to be routed, and those of them that escape
89 int satisfied = 0; // pins whose net is already complete
90 std::vector<DeadPin> dead;
91 std::string hint; // what would make the dead pins escapable, when it can be told
92};
94 Coord lattice = 40'000; // search pitch
95 Coord margin = 500'000; // how far outside the package a pin must get
96 Coord window = 1'500'000; // search area around the package
97};
98std::vector<PartEscape> analyse_escapes(const model::Board& b, const model::DesignRules& r, Obstacles& obs,
99 const EscapeAnalysisOptions& o = {}, const EscapeOptions& eo = {});
100
101} // namespace tmk::route
The board model (design doc 02 §3): every object TraceMaker reads from a .kicad_pcb,...
std::int32_t NetId
0 = no net
Definition board.hpp:21
std::vector< EscapeCorridor > plan_escapes(const model::Board &b, const std::vector< char > &needs, const std::function< Coord(model::NetId)> &keep, const EscapeOptions &o={}, EscapeStats *stats=nullptr, const std::function< Coord(model::NetId)> &channel={})
Plans corridors for the pads with needs[pad] != 0.
std::vector< PartEscape > analyse_escapes(const model::Board &b, const model::DesignRules &r, Obstacles &obs, const EscapeAnalysisOptions &o={}, const EscapeOptions &eo={})
std::pair< Coord, Coord > pad_half_extents(const model::Pad &p)
Half extents of a pad's bounding box along x and y (rotation applied).
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Design rules as KiCad defines them (design doc 08 §3–4): board minimums and net classes from the ....
Escape feasibility (M9 analysis): can each pin of a dense package leave it at all under the board's r...
Definition escape.hpp:80
std::string reason
Definition escape.hpp:82
Coord margin
how far outside the package a pin must get
Definition escape.hpp:95
Coord window
search area around the package
Definition escape.hpp:96
std::vector< Point > tail
Version 2 (escape_flow.hpp): the corridor continues from b through these points on tail_layer (the pa...
Definition escape.hpp:37
Coord band
half-width of the reserved strip around the centreline
Definition escape.hpp:33
Point b
centreline: pad centre -> escape point (or via site)
Definition escape.hpp:30
int pad
board pad index
Definition escape.hpp:27
bool has_mid
second-ring pins: a -> mid (between two outer balls) -> b
Definition escape.hpp:31
bool via
b is a dog-bone via site (reserved on every layer)
Definition escape.hpp:34
int layer
copper index the stub runs on
Definition escape.hpp:29
Coord max_pitch
pin pitch up to which a footprint counts as dense (1.27 mm BGAs included)
Definition escape.hpp:46
Coord length
Corridor length past the pad edge for perimeter pins.
Definition escape.hpp:50
int min_pads
smaller footprints escape easily
Definition escape.hpp:45
int escapable
pins still to be routed, and those of them that escape
Definition escape.hpp:88
std::string hint
what would make the dead pins escapable, when it can be told
Definition escape.hpp:91
std::vector< DeadPin > dead
Definition escape.hpp:90
int satisfied
pins whose net is already complete
Definition escape.hpp:89