STEP 2 - S2P1 / S2P2  Serial-to-Parallel registers  (guide architecture, page 3)
================================================================================

What it is
----------
     x --> R1 --> R2 --> R3 ... --> R16          (16 registers, one shift per clock)
           |      |      |           |
           y1     y2     y3   ...    y16         (all 16 outputs in parallel)

  S2P1 takes I_out of the Input ROM, S2P2 takes Q_out (same clock).
  After 16 clocks: 16 I + 16 Q = one patch of 32 values -> sent out in parallel.
  128 samples -> 8 patches  =  function extract_patches : (2,128) -> (8,32)

  R1 = newest sample, R16 = oldest. For a full register:
     patch I0 = y16 ... I15 = y1   (same for Q)
  Patch layout = model layout [ I0..I15 | Q0..Q15 ].

Folder (extract so that S2_s2p stays its own folder, next to S1_input_rom_raw_src)
------
  S2_s2p\
     hls_config.cfg               top = s2p, part xc7s50csga324-1, 10 ns
     src\s2p.h, src\s2p.cpp        the 2 x 16 registers + shift + parallel output
     tb\s2p_tb.cpp                 feeds 128 + 128 raw samples, checks 8 patches
     data\i_rom.dat, q_rom.dat     raw input (same as Step 1 ROM)
     data\patches_raw_ref.dat      expected raw patches (8 x 32)
     data\patch_output_norm_ref.dat  model reference Patch_output.csv (normalized)
     data\norm_stats.dat           mean_I, mean_Q, std_I, std_Q (only used by the TEST)

Checks in the testbench
-----------------------
  A) hardware patches vs raw reference patches            expect ~3e-08
  B) (hardware patch - mean)/std vs Patch_output.csv      expect ~5e-06 (tol 1e-04)
     -> proves the S2P output = the function extract_patches of the function sheet
     (mean/std are used only here in the TEST, never in the hardware)

How to run
----------
  1. Extract: C:\Users\<you>\Documents\MRT_Blocks\MRT_Blocks\S2_s2p\
     (check: S2_s2p contains src, tb, data, hls_config.cfg directly)
  2. Vitis: File -> New Component -> HLS
        Name: s2_s2p   Config: Existing -> S2_s2p\hls_config.cfg
        Top: s2p       Part: xc7s50csga324-1   -> Finish
  3. C SIMULATION       expect "*** STEP 2 S2P TEST PASSED ***", 8 patches
  4. C SYNTHESIS        expect loop SHIFT_IN II = 1, ~130 clocks, 0 DSP, 0 BRAM,
                        FF about 800-900 (the 2 x 16 x 25-bit registers + output)
  5. C/RTL COSIMULATION expect PASS

Waveform (xsim --gui in ...\s2_s2p\s2p\hls\sim\verilog, then Tcl console):
  set g [add_wave_group "S2_per_clock"]; set p /apatb_s2p_top/AESL_inst_s2p; add_wave -into $g $p/ap_clk; add_wave -into $g $p/ap_start; add_wave -into $g $p/i_in_read; add_wave -into $g -radix hex $p/i_in_dout; add_wave -into $g -radix hex $p/q_in_dout; add_wave -into $g $p/patch_out_write; add_wave -into $g -radix hex $p/patch_out_din; add_wave -into $g $p/ap_done
  You should see i_in_read = 1 every clock and patch_out_write = 1 once every 16 clocks
  (8 pulses), each carrying the 800-bit patch (32 x 25 bit).
