From 3761c3dfcb313092efeaafc7636a9fcc074f69f0 Mon Sep 17 00:00:00 2001
From: Eric Kooistra <kooistra@astron.nl>
Date: Wed, 17 Mar 2021 18:12:14 +0100
Subject: [PATCH] Corrected peripheral for reversed word order in
 dp_offload_tx_v3.vhd.

---
 .../lofar2/libraries/sdp/sdp.peripheral.yaml  | 96 +++++++++++--------
 1 file changed, 57 insertions(+), 39 deletions(-)

diff --git a/applications/lofar2/libraries/sdp/sdp.peripheral.yaml b/applications/lofar2/libraries/sdp/sdp.peripheral.yaml
index 5f26ca047a..2c25ab9b39 100644
--- a/applications/lofar2/libraries/sdp/sdp.peripheral.yaml
+++ b/applications/lofar2/libraries/sdp/sdp.peripheral.yaml
@@ -154,50 +154,68 @@ peripherals:
       # MM port for sdp_beamformer_output.vhd / dp_offload_tx_v3.vhd
       - slave_name: REG_DP_OFFLOAD_TX_HDR_DAT
         slave_description: |
-          "The ETH/IP/UDP/application header fields for the beamlet data output offload UDP packets."
+          "The ETH/IP/UDP/application header fields for the beamlet data output offload UDP packets.
+
+           From tb_dp_offload_tx_v3.vhd simulation it follows that:
+           . the header fields are stored in reversed address order due to that the array in VHDL has
+             range (h downto 0) where the first header field (eth_destination_mac) is at index h.
+           . the RO fields are filled in by the logic, when the packet header is transmitted, however
+             the read value does not still represents the MM write value, not the transmitted value.
+           . dp_bsn with radix_width = 64 is stored as:
+              word  byte
+              addr  addr  bits
+                0   0x0 [31:0] = dp_bsn[31:0]
+                1   0x4 [31:0] = dp_bsn[63:32]
+           . eth_dst_mac with radix_width = 48 is stored as:
+              word  byte
+              addr  addr  bits
+               21   0x84 [31:0] = eth_dst_mac[31:0]
+               22   0x88 [15:0] = eth_dst_mac[47:32]
+          "
         slave_type: REG
         fields:
           # eth field group
-          - - { field_name: eth_destination_mac,    width: 32,                 access_mode: RW, address_offset: 0x0,  radix_width: 48 }
-          - - { field_name: eth_source_mac,         width: 32,                 access_mode: RO, address_offset: 0x8,  radix_width: 48 }
-          - - { field_name: eth_type,               width: 16,                 access_mode: RO, address_offset: 0x10 }
+          - - { field_name: eth_destination_mac,    width: 32,                 access_mode: RW, address_offset: 0x84, radix_width: 48 }
+          - - { field_name: eth_source_mac,         width: 32,                 access_mode: RO, address_offset: 0x7C, radix_width: 48 }
+          - - { field_name: eth_type,               width: 16,                 access_mode: RO, address_offset: 0x78 }
           # ip field group
-          - - { field_name: ip_version,             width:  4,                 access_mode: RW, address_offset: 0x14 }
-          - - { field_name: ip_header_length,       width:  4,                 access_mode: RW, address_offset: 0x18 }
-          - - { field_name: ip_services,            width:  8,                 access_mode: RW, address_offset: 0x1C }
-          - - { field_name: ip_total_length,        width: 16,                 access_mode: RW, address_offset: 0x20 }
-          - - { field_name: ip_identification,      width: 16,                 access_mode: RW, address_offset: 0x24 }
-          - - { field_name: ip_flags,               width:  3,                 access_mode: RW, address_offset: 0x28 }
-          - - { field_name: ip_fragment_offset,     width: 13,                 access_mode: RW, address_offset: 0x2C }
-          - - { field_name: ip_time_to_live,        width:  8,                 access_mode: RW, address_offset: 0x30 }
-          - - { field_name: ip_protocol,            width:  8,                 access_mode: RW, address_offset: 0x34 }
-          - - { field_name: ip_header_checksum,     width: 16,                 access_mode: RW, address_offset: 0x38 }
-          - - { field_name: ip_source_address,      width: 32,                 access_mode: RW, address_offset: 0x3C }
-          - - { field_name: ip_destination_address, width: 32,                 access_mode: RW, address_offset: 0x40 }
+          - - { field_name: ip_version,             width:  4,                 access_mode: RW, address_offset: 0x74 }
+          - - { field_name: ip_header_length,       width:  4,                 access_mode: RW, address_offset: 0x70 }
+          - - { field_name: ip_services,            width:  8,                 access_mode: RW, address_offset: 0x6C }
+          - - { field_name: ip_total_length,        width: 16,                 access_mode: RW, address_offset: 0x68 }
+          - - { field_name: ip_identification,      width: 16,                 access_mode: RW, address_offset: 0x64 }
+          - - { field_name: ip_flags,               width:  3,                 access_mode: RW, address_offset: 0x60 }
+          - - { field_name: ip_fragment_offset,     width: 13,                 access_mode: RW, address_offset: 0x5C }
+          - - { field_name: ip_time_to_live,        width:  8,                 access_mode: RW, address_offset: 0x58 }
+          - - { field_name: ip_protocol,            width:  8,                 access_mode: RW, address_offset: 0x54 }
+          - - { field_name: ip_header_checksum,     width: 16,                 access_mode: RW, address_offset: 0x50 }
+          - - { field_name: ip_source_address,      width: 32,                 access_mode: RW, address_offset: 0x4C }
+          - - { field_name: ip_destination_address, width: 32,                 access_mode: RW, address_offset: 0x48 }
           # udp field group
           - - { field_name: udp_source_port,        width: 16,                 access_mode: RW, address_offset: 0x44 }
-          - - { field_name: udp_destination_port,   width: 16,                 access_mode: RW, address_offset: 0x48 }
-          - - { field_name: udp_length,             width: 16,                 access_mode: RW, address_offset: 0x4C }
-          - - { field_name: udp_checksum,           width: 16,                 access_mode: RW, address_offset: 0x50 }
+          - - { field_name: udp_destination_port,   width: 16,                 access_mode: RW, address_offset: 0x40 }
+          - - { field_name: udp_length,             width: 16,                 access_mode: RW, address_offset: 0x3C }
+          - - { field_name: udp_checksum,           width: 16,                 access_mode: RW, address_offset: 0x38 }
           # application field group
-          - - { field_name: marker,                 width:  8,                 access_mode: RO, address_offset: 0x54 }
-          - - { field_name: version_id,             width:  8,                 access_mode: RO, address_offset: 0x58 }
-          - - { field_name: observation_id,         width: 32,                 access_mode: RW, address_offset: 0x5C }
-          - - { field_name: station_id,             width: 16,                 access_mode: RW, address_offset: 0x60 }
-          - - { field_name: source_info,            width: 16,                 access_mode: RW, address_offset: 0x64 }
+          - - { field_name: marker,                 width:  8,                 access_mode: RO, address_offset: 0x34 }
+          - - { field_name: version_id,             width:  8,                 access_mode: RO, address_offset: 0x30 }
+          - - { field_name: observation_id,         width: 32,                 access_mode: RW, address_offset: 0x2C }
+          - - { field_name: station_id,             width: 16,                 access_mode: RW, address_offset: 0x28 }
+          - - { field_name: source_info,            width: 16,                 access_mode: RW, address_offset: 0x24 }
           - "source_info":
-            - { field_name: antenna_band_index,     width:  1, bit_offset: 15, access_mode: RW, address_offset: 0x64 }
-            - { field_name: nyquist_zone_index,     width:  2, bit_offset: 13, access_mode: RW, address_offset: 0x64 }
-            - { field_name: f_adc,                  width:  1, bit_offset: 12, access_mode: RW, address_offset: 0x64 }
-            - { field_name: fsub_type,              width:  1, bit_offset: 11, access_mode: RW, address_offset: 0x64 }
-            - { field_name: payload_error,          width:  1, bit_offset: 10, access_mode: RW, address_offset: 0x64 }
-            - { field_name: repositioning_flag,     width:  1, bit_offset:  9, access_mode: RW, address_offset: 0x64 }
-            - { field_name: beamlet_width,          width:  3, bit_offset:  5, access_mode: RW, address_offset: 0x64 }
-            - { field_name: gn_index,               width:  5, bit_offset:  0, access_mode: RW, address_offset: 0x64 }
-          - - { field_name: reserved,               width: 32,                 access_mode: RW, address_offset: 0x68, radix_width: 40 }
-          - - { field_name: beamlet_scale,          width: 16,                 access_mode: RW, address_offset: 0x70 }
-          - - { field_name: beamlet_index,          width: 16,                 access_mode: RW, address_offset: 0x74 }
-          - - { field_name: nof_blocks_per_packet,  width:  8,                 access_mode: RW, address_offset: 0x78 }
-          - - { field_name: nof_beamlets_per_block, width: 16,                 access_mode: RW, address_offset: 0x7C }
-          - - { field_name: block_period,           width: 16,                 access_mode: RW, address_offset: 0x80 }
-          - - { field_name: BSN,                    width: 32,                 access_mode: RW, address_offset: 0x84, radix_width: 64 }
+            - { field_name: antenna_band_index,     width:  1, bit_offset: 15, access_mode: RW, address_offset: 0x24 }
+            - { field_name: nyquist_zone_index,     width:  2, bit_offset: 13, access_mode: RW, address_offset: 0x24 }
+            - { field_name: f_adc,                  width:  1, bit_offset: 12, access_mode: RW, address_offset: 0x24 }
+            - { field_name: fsub_type,              width:  1, bit_offset: 11, access_mode: RW, address_offset: 0x24 }
+            - { field_name: payload_error,          width:  1, bit_offset: 10, access_mode: RW, address_offset: 0x24 }
+            - { field_name: repositioning_flag,     width:  1, bit_offset:  9, access_mode: RW, address_offset: 0x24 }
+            - { field_name: beamlet_width,          width:  3, bit_offset:  5, access_mode: RW, address_offset: 0x24 }
+            - { field_name: gn_index,               width:  5, bit_offset:  0, access_mode: RW, address_offset: 0x24 }
+
+          - - { field_name: reserved,               width: 32,                 access_mode: RW, address_offset: 0x1C, radix_width: 40 }
+          - - { field_name: beamlet_scale,          width: 16,                 access_mode: RW, address_offset: 0x18 }
+          - - { field_name: beamlet_index,          width: 16,                 access_mode: RW, address_offset: 0x14 }
+          - - { field_name: nof_blocks_per_packet,  width:  8,                 access_mode: RW, address_offset: 0x10 }
+          - - { field_name: nof_beamlets_per_block, width: 16,                 access_mode: RW, address_offset: 0xC }
+          - - { field_name: block_period,           width: 16,                 access_mode: RW, address_offset: 0x8 }
+          - - { field_name: BSN,                    width: 32,                 access_mode: RW, address_offset: 0x0, radix_width: 64 }
-- 
GitLab