From 2170781fe1852ce3266d48ca578b674413646800 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Thu, 4 Aug 2022 11:34:49 +0200
Subject: [PATCH] Add stat_index, crosslet_index and wrdata_power to ease
 debugging of wrdata_re and wrdata_im. Use signed for XST.

---
 libraries/dsp/st/src/vhdl/st_xsq.vhd | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/libraries/dsp/st/src/vhdl/st_xsq.vhd b/libraries/dsp/st/src/vhdl/st_xsq.vhd
index 4378a4c750..073cbe526e 100644
--- a/libraries/dsp/st/src/vhdl/st_xsq.vhd
+++ b/libraries/dsp/st/src/vhdl/st_xsq.vhd
@@ -27,6 +27,10 @@
 --   of the previous sync interval. The length of the sync interval determines
 --   the nof accumlations per statistic, hence the integration time. See st_calc
 --   for more details.
+--
+--   View wrdata_power and a_sp, b_sp and crosslet_index in Wave window to see
+--   the stat power values series.
+--
 -- Remarks:
 -- . The in_sync is assumed to be a pulse an interpreted directly.
 -- . The MM register is single page RAM to save memory resources. Therefore
@@ -42,11 +46,13 @@
 
 LIBRARY IEEE, common_lib, mm_lib, technology_lib, dp_lib;
 USE IEEE.std_logic_1164.ALL;
+USE IEEE.math_real.ALL;
 USE common_lib.common_pkg.ALL;
 USE common_lib.common_mem_pkg.ALL;
 USE common_lib.common_field_pkg.ALL;
 USE dp_lib.dp_stream_pkg.ALL;
 USE technology_lib.technology_select_pkg.ALL;
+
 ENTITY st_xsq IS
   GENERIC (
     g_nof_signal_inputs : NATURAL := 2;
@@ -100,7 +106,13 @@ ARCHITECTURE str OF st_xsq IS
   
   SIGNAL wrdata_re    : STD_LOGIC_VECTOR(c_mem_data_w-1 DOWNTO 0);
   SIGNAL wrdata_im    : STD_LOGIC_VECTOR(c_mem_data_w-1 DOWNTO 0);
-  
+  SIGNAL wrdata_power : REAL;
+
+  SIGNAL stat_index     : NATURAL;
+  SIGNAL a_sp           : NATURAL;
+  SIGNAL b_sp           : NATURAL;
+  SIGNAL crosslet_index : NATURAL;
+
   SIGNAL stat_mosi    : t_mem_mosi := c_mem_mosi_rst;
 
   SIGNAL ram_st_xsq_mosi_arr      : t_mem_mosi_arr(c_nof_complex-1 DOWNTO 0) := (OTHERS => c_mem_mosi_rst);
@@ -165,9 +177,19 @@ BEGIN
     out_val_m      => OPEN
   );
   
-  wrdata_re <= RESIZE_MEM_UDATA(stat_data_re);
-  wrdata_im <= RESIZE_MEM_UDATA(stat_data_im);
+  -- Cross correlations are signed values
+  wrdata_re <= RESIZE_MEM_SDATA(stat_data_re);
+  wrdata_im <= RESIZE_MEM_SDATA(stat_data_im);
   
+  -- View XST power values in wave window
+  wrdata_power <= COMPLEX_RADIUS(TO_SREAL(stat_data_re), TO_SREAL(stat_data_im)) ** 2.0;
+
+  -- Translate statistcs [crosslets][in A][in B] order into indices
+  stat_index <= TO_UINT(stat_mosi.address(c_stat_ram.adr_w-1 DOWNTO 0));
+  a_sp <= (stat_index / g_nof_signal_inputs) MOD g_nof_signal_inputs;
+  b_sp <= stat_index MOD g_nof_signal_inputs;
+  crosslet_index <= stat_index / c_xsq;
+
   ---------------------------------------------------------------
   -- COMBINE MEMORY MAPPED INTERFACES
   ---------------------------------------------------------------
-- 
GitLab