From 095b65afcb5de8167322e1a87a5a9e9ada61c32c Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Thu, 11 May 2023 10:05:28 +0200
Subject: [PATCH] =?UTF-8?q?-last=5Finfo=20option:=20skip=20model=20transfe?=
 =?UTF-8?q?r=20if=20last=20updated=20model=20buffer=20and=20the=20current?=
 =?UTF-8?q?=20model=20buffer=20overlap=20exactly=C2=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 CHANGELOG.md    |  6 ++++--
 lib/cmp_rdcu.c  | 39 ++++++++++++++++++++++-----------------
 lib/rdcu_ctrl.c |  5 ++++-
 meson.build     |  2 +-
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c925724..30fb967 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
 ## [Unreleased]
 ### Added
 - add -vv flag for extra verbose output
+###Changed
+- -last_info option: skip model transfer if last updated model buffer and the current model buffer overlap exactly
 
 ## [0.11] - 26-04-2023
 ### Added
@@ -12,7 +14,7 @@ All notable changes to this project will be documented in this file.
 - add tests for the compression entity
 - add test for cmp_rdcu_cfg.c
 - add sparc inttypes.h definitions
-###Changed
+### Changed
 - refactor function and constants names
 - refactor configure check functions
 - move the rdcu setup functions to cmp_rdcu_cfg.c
@@ -31,7 +33,7 @@ All notable changes to this project will be documented in this file.
 - functions to create and configure a compression configuration
 - add max_used_bits feature
 - add max used bit version field to the compression entity
-###Changed
+### Changed
 - Change the build system form make to meson
 - Change DEFAULT_CFG_MODEL and DEFAULT_CFG_DIFF to CMP_DIF_XXX constants
 ### Fixed
diff --git a/lib/cmp_rdcu.c b/lib/cmp_rdcu.c
index 362cdfc..5c6b015 100644
--- a/lib/cmp_rdcu.c
+++ b/lib/cmp_rdcu.c
@@ -509,26 +509,31 @@ int rdcu_compress_data_parallel(const struct cmp_cfg *cfg,
 
 	/* read model and write model in parallel */
 	if (cfg->model_buf && model_mode_is_used(cfg->cmp_mode) && model_mode_is_used(last_info->cmp_mode_used)) {
-		uint32_t new_model_size_4byte;
+		if (cfg->rdcu_model_adr == last_info->rdcu_new_model_adr_used &&
+		    cfg->samples == last_info->samples_used) {
+			printf("The last updated model buffer and the current model buffer overlap exactly in the SRAM of the RDCU. Skip model transfer.\n");
+		} else {
+			uint32_t new_model_size_4byte;
 
-		/* set the model in the local mirror... */
-		if (rdcu_write_sram_16(cfg->model_buf, cfg->rdcu_model_adr,
-				       cfg->samples * IMA_SAM2BYT) < 0)
-			return -1;
+			/* set the model in the local mirror... */
+			if (rdcu_write_sram_16(cfg->model_buf, cfg->rdcu_model_adr,
+					       cfg->samples * IMA_SAM2BYT) < 0)
+				return -1;
 
-		new_model_size_4byte = last_info->samples_used * IMA_SAM2BYT;
-		if (rdcu_sync_sram_mirror_parallel(last_info->rdcu_new_model_adr_used,
-						   (new_model_size_4byte+3) & ~0x3U,
-						   cfg->rdcu_model_adr,
-						   samples_4byte, rdcu_get_data_mtu()))
-			return -1;
-		/* wait for it */
-		sync();
-		if (cfg->icu_new_model_buf) {
-			if (rdcu_read_sram(cfg->icu_new_model_buf,
-					   last_info->rdcu_new_model_adr_used,
-					   new_model_size_4byte) < 0)
+			new_model_size_4byte = last_info->samples_used * IMA_SAM2BYT;
+			if (rdcu_sync_sram_mirror_parallel(last_info->rdcu_new_model_adr_used,
+							   (new_model_size_4byte+3) & ~0x3U,
+							   cfg->rdcu_model_adr,
+							   samples_4byte, rdcu_get_data_mtu()))
 				return -1;
+			/* wait for it */
+			sync();
+			if (cfg->icu_new_model_buf) {
+				if (rdcu_read_sram(cfg->icu_new_model_buf,
+						   last_info->rdcu_new_model_adr_used,
+						   new_model_size_4byte) < 0)
+					return -1;
+			}
 		}
 	/* write model */
 	} else if (cfg->model_buf && model_mode_is_used(cfg->cmp_mode)) {
diff --git a/lib/rdcu_ctrl.c b/lib/rdcu_ctrl.c
index f870c53..774a795 100644
--- a/lib/rdcu_ctrl.c
+++ b/lib/rdcu_ctrl.c
@@ -2439,8 +2439,11 @@ int rdcu_sync_sram_mirror_parallel(uint32_t rx_addr, uint32_t rx_size,
 		return -1;
 
 	/* check buffer overlap */
-	if (rx_addr < tx_addr+tx_size && rx_addr+rx_size > tx_addr)
+	if (rx_addr < tx_addr+tx_size && rx_addr+rx_size > tx_addr) {
+		printf("Error: The two parallel transferring buffers overlap. Read buffer: 0x%x size: %u. Write buffer: 0x%x size: %u.\n",
+			rx_addr, rx_size, tx_addr, tx_size);
 		return -1;
+	}
 
 
 	rx_bytes = rx_size;
diff --git a/meson.build b/meson.build
index 9563b5f..44c8e42 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
 project('cmp_tool', 'c',
-  version : '0.11',
+  version : '0.11-b1',
   meson_version : '>= 0.56',
   license : 'GPL-2.0',
   default_options : ['warning_level=3', 'c_std=gnu99']
-- 
GitLab