From 0775eedc13885bbd55f751052c24183aea7b8ebe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Romain=20Bron=C3=A8s?= <romain.brones@synchrotron-soleil.fr>
Date: Mon, 5 Jun 2023 15:38:12 +0200
Subject: [PATCH] fix: Reduce memory area by using real number of BPM

*  Instead of deriving ID field width
---
 hdl/orbit_error.vhd   | 12 ++++++------
 rdl/corr_matrixpi.rdl |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hdl/orbit_error.vhd b/hdl/orbit_error.vhd
index dccb51a..bd6f795 100644
--- a/hdl/orbit_error.vhd
+++ b/hdl/orbit_error.vhd
@@ -69,40 +69,40 @@ begin
     -- Port A is read write from AXI controller, Port B is read only from logic
     inst_refx_table: entity desy.ram_tdp
     generic map(
-        G_ADDR      => C_W_BPMID,
+        G_ADDR      => C_W_MM_IDCNT,
         G_DATA      => C_W_BPMPOS
     )
     port map(
         pi_clk_a    => clk,
         pi_en_a     => reforbitx_i.en,
         pi_we_a     => reforbitx_i.we,
-        pi_addr_a   => reforbitx_i.addr(C_W_BPMID-1 downto 0),
+        pi_addr_a   => reforbitx_i.addr(C_W_MM_IDCNT-1 downto 0),
         pi_data_a   => reforbitx_i.data,
         po_data_a   => reforbitx_o.data,
         pi_clk_b    => clk,
         pi_en_b     => '1',
         pi_we_b     => '0',
-        pi_addr_b   => bpm_id,
+        pi_addr_b   => bpm_id(C_W_MM_IDCNT-1 downto 0),
         pi_data_b   => (others => '0'),
         po_data_b   => table_refx
     );
 
     inst_refy_table: entity desy.ram_tdp
     generic map(
-        G_ADDR      => C_W_BPMID,
+        G_ADDR      => C_W_MM_IDCNT,
         G_DATA      => C_W_BPMPOS
     )
     port map(
         pi_clk_a    => clk,
         pi_en_a     => reforbity_i.en,
         pi_we_a     => reforbity_i.we,
-        pi_addr_a   => reforbity_i.addr(C_W_BPMID-1 downto 0),
+        pi_addr_a   => reforbity_i.addr(C_W_MM_IDCNT-1 downto 0),
         pi_data_a   => reforbity_i.data,
         po_data_a   => reforbity_o.data,
         pi_clk_b    => clk,
         pi_en_b     => '1',
         pi_we_b     => '0',
-        pi_addr_b   => bpm_id,
+        pi_addr_b   => bpm_id(C_W_MM_IDCNT-1 downto 0),
         pi_data_b   => (others => '0'),
         po_data_b   => table_refy
     );
diff --git a/rdl/corr_matrixpi.rdl b/rdl/corr_matrixpi.rdl
index 148e377..000e351 100644
--- a/rdl/corr_matrixpi.rdl
+++ b/rdl/corr_matrixpi.rdl
@@ -52,13 +52,13 @@ addrmap corr_matrixpi {
     mem {
         desc = "X Reference orbit.";
         memwidth = `C_W_BPMPOS;
-        mementries = 2**`C_W_BPMID;
+        mementries = 2**`C_W_MM_IDCNT;
     } external REFORBITX;
 
     mem {
         desc = "Y Reference orbit.";
         memwidth = `C_W_BPMPOS;
-        mementries = 2**`C_W_BPMID;
+        mementries = 2**`C_W_MM_IDCNT;
     } external REFORBITY;
 
     mem {
-- 
GitLab