From 4e5ad7feac5b41876e3b09162cea8815fe0821bf Mon Sep 17 00:00:00 2001
From: David Shah <dave@ds0.me>
Date: Mon, 9 Nov 2020 11:43:54 +0000
Subject: nexus: Add timing structures to BBA

Signed-off-by: David Shah <dave@ds0.me>
---
 nexus/arch.h          | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 nexus/bba_version.inc |  2 +-
 2 files changed, 50 insertions(+), 2 deletions(-)

(limited to 'nexus')

diff --git a/nexus/arch.h b/nexus/arch.h
index c6064ea2..88660ca1 100644
--- a/nexus/arch.h
+++ b/nexus/arch.h
@@ -108,7 +108,7 @@ enum PipFlags
 NPNR_PACKED_STRUCT(struct PipInfoPOD {
     uint16_t from_wire, to_wire;
     uint16_t flags;
-    uint16_t padding;
+    uint16_t timing_class;
     int32_t tile_type;
 });
 
@@ -273,13 +273,61 @@ NPNR_PACKED_STRUCT(struct IdStringDBPOD {
     RelPtr<RelPtr<char>> bba_id_strs;
 });
 
+// Timing structures are generally sorted using IdString indices as keys for fast binary searches
+// All delays are integer picoseconds
+
+// Sort key: (from_port, to_port) for binary search by IdString
+NPNR_PACKED_STRUCT(struct CellPropDelayPOD {
+    int32_t from_port;
+    int32_t to_port;
+    int32_t min_delay;
+    int32_t max_delay;
+});
+
+// Sort key: (sig_port, clock_port) for binary search by IdString
+NPNR_PACKED_STRUCT(struct CellSetupHoldPOD {
+    int32_t sig_port;
+    int32_t clock_port;
+    int32_t min_setup;
+    int32_t max_setup;
+    int32_t min_hold;
+    int32_t max_hold;
+});
+
+// Sort key: (cell_type, cell_variant) for binary search by IdString
+NPNR_PACKED_STRUCT(struct CellTimingPOD {
+    int32_t cell_type;
+    int32_t cell_variant;
+    int32_t num_prop_delays;
+    int32_t num_setup_holds;
+    RelPtr<CellPropDelayPOD> prop_delays;
+    RelPtr<CellSetupHoldPOD> setup_holds;
+});
+
+NPNR_PACKED_STRUCT(struct PipTimingPOD {
+    int32_t min_delay;
+    int32_t max_delay;
+    int32_t min_fanout_adder;
+    int32_t max_fanout_adder;
+});
+
+NPNR_PACKED_STRUCT(struct SpeedGradePOD {
+    RelPtr<char> name;
+    int32_t num_cell_types;
+    int32_t num_pip_classes;
+    RelPtr<CellTimingPOD> cell_types;
+    RelPtr<PipTimingPOD> pip_classes;
+});
+
 NPNR_PACKED_STRUCT(struct DatabasePOD {
     uint32_t version;
     uint32_t num_chips;
     uint32_t num_loctypes;
+    uint32_t num_speed_grades;
     RelPtr<char> family;
     RelPtr<ChipInfoPOD> chips;
     RelPtr<LocTypePOD> loctypes;
+    RelPtr<SpeedGradePOD> speed_grades;
     RelPtr<IdStringDBPOD> ids;
 });
 
diff --git a/nexus/bba_version.inc b/nexus/bba_version.inc
index 7f8f011e..45a4fb75 100644
--- a/nexus/bba_version.inc
+++ b/nexus/bba_version.inc
@@ -1 +1 @@
-7
+8
-- 
cgit v1.2.3