TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
bundle.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Bundle (river) escapes (design doc 05 §50). The connections that leave one side of a dense package (QFN, QFP, SO) for one side of another part are
4// routed as one block, the way a designer draws them: parallel straight tracks at the pin pitch, in the order of the pins, for as long as the board has
5// room, and each track peels off toward its own pad at the last moment. Not a search per connection: ONE search for the spine of the block (a track as
6// wide as the whole block, on an octilinear grid, turns spaced so that the inner tracks of a turn keep their length), then every lane is the spine offset
7// by the lane's distance from the middle (rigid offsets: the order of the pins is the order of the lanes, so lanes cannot cross), and a last leg from the
8// lane to its pad. A lane is placed only when every piece of it passes the router's own exact check; a connection that does not get a lane is left to
9// the ordinary router. Related work: river routing (Hsu, "A new approach to channel routing"; Tsukiyama and Kuh, "Single-layer routing"); the
10// generalisation of the router's coupled-pair legs (doc 05 §15) from two tracks to n.
11#include <functional>
12#include <vector>
13
14#include "geom/point.hpp"
15#include "model/board.hpp"
16
17namespace tmk::route {
18
19struct BundleConn {
20 int ci = -1; // the router's connection index
22 int pad_a = -1, pad_b = -1; // board pads; the one on a dense package's perimeter is the source
23};
24
26 // May a track of `net` and `width` run a-b on `layer`? The router's exact check against everything placed (fixed copper, routed copper, rules).
27 std::function<bool(geom::Point, geom::Point, int layer, Coord width, model::NetId)> free;
28 std::function<Coord(model::NetId)> width; // track width of a net
29 std::function<Coord(model::NetId)> clearance; // clearance of a net
30 std::function<bool(int layer, model::NetId)> layer_ok;
31 // A via of `net` at p (the class via, not necked): may it go there? (exact check, strict)
32 std::function<bool(geom::Point, model::NetId)> via_ok;
34 // Places the tunnel of a connection: tracks (layer, polyline) and the vias that join them. False: refused (nothing placed).
35 std::function<bool(const BundleConn&, const std::vector<std::pair<int, std::vector<geom::Point>>>&, const std::vector<geom::Point>&)> place_tunnel;
36 // Places the lane of a connection: the polyline from the centre of one pad to the centre of the other, on `layer`. False: refused (not placed).
37 std::function<bool(const BundleConn&, int layer, const std::vector<geom::Point>&)> place;
38};
39
41 int min_lanes = 3; // a group of fewer connections is left to the router
42 Coord grid = 500'000; // spine grid step
43 Coord peel_step = 250'000; // places along a lane where it may leave the block
44 Coord extend = 30'000'000; // how far a lane may run on straight past the end of the spine
45 Coord max_pitch = 1'300'000; // pin pitch up to which a footprint counts as a dense package (as the escape plan)
46 int min_pads = 8;
47};
48
50 int groups = 0; // (package side, destination side) groups with enough connections
51 int spines = 0; // groups for which the search found a spine
52 int lanes = 0; // connections in those groups
53 int placed = 0; // lanes placed
54};
55
56// Pins on the perimeter of a dense package and the direction they leave in (index into the 8 octilinear directions: 0 +x, 2 +y, 4 -x, 6 -y).
57// Corner pins (within the ring of two sides) and thermal pads are not perimeter pins.
58std::vector<int> perimeter_directions(const model::Board& b, const BundleOptions& o); // by pad index; -1 = not a perimeter pin
59
60// Package tunnels (doc 05 §52): a connection between two perimeter pins of one dense package on the same net (the core rail's three pins, the supply pins
61// of a package) goes where the designer puts it: a short stub and a via straight out of each pin, and the run between the two vias on the other layer,
62// under the package. The run is one search (A*, octilinear, exact checks) between the two via sites; nothing is placed unless the whole tunnel passes.
64 int tried = 0, placed = 0;
65};
66TunnelStats route_tunnels(const model::Board& b, const std::vector<BundleConn>& conns, const BundleHooks& h, const BundleOptions& o = {});
67
68// Plans and places the bundles of `conns` (unrouted two-pad connections). Deterministic: groups, lanes and searches are in a fixed order.
69BundleStats route_bundles(const model::Board& b, const std::vector<BundleConn>& conns, const BundleHooks& h, const BundleOptions& o = {});
70
71} // 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
BundleStats route_bundles(const model::Board &b, const std::vector< BundleConn > &conns, const BundleHooks &h, const BundleOptions &o={})
Plans and places the bundles of conns (unrouted two-pad connections). Deterministic: groups,...
TunnelStats route_tunnels(const model::Board &b, const std::vector< BundleConn > &conns, const BundleHooks &h, const BundleOptions &o={})
std::vector< int > perimeter_directions(const model::Board &b, const BundleOptions &o)
Pins on the perimeter of a dense package and the direction they leave in (index into the 8 octilinear...
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
Integer-nanometre points and KiCad-compatible rotation.
int pad_b
board pads; the one on a dense package's perimeter is the source
Definition bundle.hpp:22
model::NetId net
Definition bundle.hpp:21
int ci
the router's connection index
Definition bundle.hpp:20
std::function< bool(const BundleConn &, int layer, const std::vector< geom::Point > &)> place
Places the lane of a connection: the polyline from the centre of one pad to the centre of the other,...
Definition bundle.hpp:37
std::function< Coord(model::NetId)> width
track width of a net
Definition bundle.hpp:28
std::function< bool(const BundleConn &, const std::vector< std::pair< int, std::vector< geom::Point > > > &, const std::vector< geom::Point > &)> place_tunnel
Places the tunnel of a connection: tracks (layer, polyline) and the vias that join them....
Definition bundle.hpp:35
std::function< bool(geom::Point, geom::Point, int layer, Coord width, model::NetId)> free
May a track of net and width run a-b on layer? The router's exact check against everything placed (fi...
Definition bundle.hpp:27
std::function< Coord(model::NetId)> via_diameter
Definition bundle.hpp:33
std::function< bool(geom::Point, model::NetId)> via_ok
A via of net at p (the class via, not necked): may it go there? (exact check, strict).
Definition bundle.hpp:32
std::function< Coord(model::NetId)> clearance
clearance of a net
Definition bundle.hpp:29
std::function< bool(int layer, model::NetId)> layer_ok
Definition bundle.hpp:30
Coord grid
spine grid step
Definition bundle.hpp:42
int min_lanes
a group of fewer connections is left to the router
Definition bundle.hpp:41
Coord peel_step
places along a lane where it may leave the block
Definition bundle.hpp:43
Coord extend
how far a lane may run on straight past the end of the spine
Definition bundle.hpp:44
Coord max_pitch
pin pitch up to which a footprint counts as a dense package (as the escape plan)
Definition bundle.hpp:45
int placed
lanes placed
Definition bundle.hpp:53
int groups
(package side, destination side) groups with enough connections
Definition bundle.hpp:50
int spines
groups for which the search found a spine
Definition bundle.hpp:51
int lanes
connections in those groups
Definition bundle.hpp:52
Package tunnels (doc 05 §52): a connection between two perimeter pins of one dense package on the sam...
Definition bundle.hpp:63