From f934932225d45ca266c34db4c5b5965bcad616f2 Mon Sep 17 00:00:00 2001
From: Dominik Loidolt <dominik.loidolt@univie.ac.at>
Date: Tue, 12 Jul 2022 11:03:54 +0200
Subject: [PATCH] Unification of buffer names between RDCU and ICU compression
 Fix some typos Use default values if .rdcu_pkt_mode_cfg file is not available

---
 cmp_tool.c                 |  2 +-
 include/cmp_io.h           |  3 +++
 include/cmp_rdcu.h         |  4 +--
 include/rdcu_pkt_to_file.h |  5 ++++
 lib/cmp_io.c               |  2 +-
 lib/cmp_rdcu.c             | 50 ++++++++++++++++++++------------------
 lib/rdcu_pkt_to_file.c     | 13 ++++++----
 lib/rdcu_rmap.c            |  2 +-
 8 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/cmp_tool.c b/cmp_tool.c
index c30ae6e..54e20ab 100644
--- a/cmp_tool.c
+++ b/cmp_tool.c
@@ -569,7 +569,7 @@ static int guess_cmp_pars(struct cmp_cfg *cfg, const char *guess_cmp_mode,
 }
 
 
-/* generate packets to setup a RDCU compression */
+/* generate packets to setup an RDCU compression */
 static int gen_rdcu_write_pkts(struct cmp_cfg *cfg)
 {
 	int error;
diff --git a/include/cmp_io.h b/include/cmp_io.h
index 6de2222..873bf91 100644
--- a/include/cmp_io.h
+++ b/include/cmp_io.h
@@ -54,3 +54,6 @@ void print_cfg(const struct cmp_cfg *cfg, int rdcu_cfg);
 
 int atoui32(const char *dep_str, const char *val_str, uint32_t *red_val);
 int cmp_mode_parse(const char *cmp_mode_str, uint32_t *cmp_mode);
+
+enum cmp_data_type string2data_type(const char *data_type_str);
+const char *data_type2string(enum cmp_data_type data_type);
diff --git a/include/cmp_rdcu.h b/include/cmp_rdcu.h
index 6273549..780c869 100644
--- a/include/cmp_rdcu.h
+++ b/include/cmp_rdcu.h
@@ -55,9 +55,9 @@ int rdcu_read_cmp_status(struct cmp_status *status);
 
 int rdcu_read_cmp_info(struct cmp_info *info);
 
-int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *output_buf);
+int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *compressed_data);
 
-int rdcu_read_model(const struct cmp_info *info, void *model_buf);
+int rdcu_read_model(const struct cmp_info *info, void *updated_model);
 
 int rdcu_interrupt_compression(void);
 
diff --git a/include/rdcu_pkt_to_file.h b/include/rdcu_pkt_to_file.h
index 1c350c8..b0f0558 100644
--- a/include/rdcu_pkt_to_file.h
+++ b/include/rdcu_pkt_to_file.h
@@ -27,6 +27,11 @@
 
 #define MAX_TC_FOLDER_DIR_LEN 256
 
+/* default values when no .rdcu_pkt_mode_cfg file is available */
+#define DEF_ICU_ADDR 0xA7
+#define DEF_RDCU_ADDR 0xFE
+#define DEF_MTU 4224
+
 int init_rmap_pkt_to_file(void);
 
 void set_tc_folder_dir(const char *dir_name);
diff --git a/lib/cmp_io.c b/lib/cmp_io.c
index 0e74c0d..9e4eb3a 100644
--- a/lib/cmp_io.c
+++ b/lib/cmp_io.c
@@ -200,7 +200,7 @@ int write_input_data_to_file(void *data, uint32_t data_size, enum cmp_data_type
 	if (verbose) {
 		printf("\n\n");
 			for (i = 0; i < data_size; i++) {
-				printf("%02X ", tmp_buf[i]);
+				printf("%02X", tmp_buf[i]);
 			if ((i + 1) % 16 == 0)
 				printf("\n");
 			else
diff --git a/lib/cmp_rdcu.c b/lib/cmp_rdcu.c
index 336fc87..ff4eb6c 100644
--- a/lib/cmp_rdcu.c
+++ b/lib/cmp_rdcu.c
@@ -82,13 +82,13 @@ static void sync(void)
 
 /**
  * @brief check if the compression data product type, compression mode, model
- *	value and the lossy rounding parameters are valid for a RDCU compression
+ *	value and the lossy rounding parameters are valid for an RDCU compression
  *
  * @param cfg	pointer to a compression configuration containing the compression
  *	data product type, compression mode, model value and the rounding parameters
  *
  * @returns 0 if the compression data type, compression mode, model value and
- *	the lossy rounding parameters are valid for a RDCU compression, non-zero
+ *	the lossy rounding parameters are valid for an RDCU compression, non-zero
  *	if parameters are invalid
  */
 
@@ -131,7 +131,7 @@ static int rdcu_cfg_gen_par_is_invalid(const struct cmp_cfg *cfg)
 
 
 /**
- * @brief create a RDCU compression configuration
+ * @brief create an RDCU compression configuration
  *
  * @param data_type	compression data product types
  * @param cmp_mode	compression mode
@@ -401,7 +401,7 @@ int rdcu_cfg_buffers(struct cmp_cfg *cfg, uint16_t *data_to_compress,
 
 /**
  * @brief check if the Golomb and spillover threshold parameter combination is
- *	invalid for a RDCU compression
+ *	invalid for an RDCU compression
  * @note also checked the adaptive Golomb and spillover threshold parameter combinations
  *
  * @param cfg	a pointer to a compression configuration
@@ -519,7 +519,7 @@ int rdcu_cfg_imagette(struct cmp_cfg *cfg,
 
 
 /**
- * @brief check if the compressor configuration is invalid for a RDCU compression,
+ * @brief check if the compressor configuration is invalid for an RDCU compression,
  *	see the user manual for more information (PLATO-UVIE-PL-UM-0001).
  *
  * @param cfg	pointer to a compression configuration contains all parameters
@@ -677,10 +677,13 @@ int rdcu_start_compression(void)
  *
  * @param cfg  configuration contains all parameters required for compression
  *
- * @note when using the 1d-differencing mode or the raw mode (cmp_mode = 0,2,4),
- *      the model parameters (model_value, model_buf, rdcu_model_adr) are ignored
- * @note the validity of the cfg structure is checked before the compression is
- *	 started
+ * @note Before the rdcu_compress function can be used, an initialization of
+ *	the RMAP library is required. This is achieved with the functions
+ *	rdcu_ctrl_init() and rdcu_rmap_init().
+ * @note When using the 1d-differencing mode or the raw mode (cmp_mode = 0,2,4),
+ *       the model parameters (model_value, model_of_data, rdcu_model_adr) are ignored.
+ * @note The validity of the cfg structure is checked before the compression is
+ *	 started.
  *
  * @returns 0 on success, error otherwise
  */
@@ -761,7 +764,7 @@ int rdcu_read_cmp_status(struct cmp_status *status)
 
 
 /**
- * @brief read out the metadata of a RDCU compression
+ * @brief read out the metadata of an RDCU compression
  *
  * @param info  compression information contains the metadata of a compression
  *
@@ -817,15 +820,14 @@ int rdcu_read_cmp_info(struct cmp_info *info)
 /**
  * @brief read the compressed bitstream from the RDCU SRAM
  *
- * @param info  compression information contains the metadata of a compression
- *
- * @param output_buf  the buffer to store the bitstream (if NULL, the required
- *		      size is returned)
+ * @param info			compression information contains the metadata of a compression
+ * @param compressed_data	the buffer to store the bitstream (if NULL, the
+ *				required size is returned)
  *
  * @returns the number of bytes read, < 0 on error
  */
 
-int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *output_buf)
+int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *compressed_data)
 {
 	uint32_t s;
 
@@ -835,7 +837,7 @@ int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *output_buf)
 	/* calculate the need bytes for the bitstream */
 	s = cmp_bit_to_4byte(info->cmp_size);
 
-	if (output_buf == NULL)
+	if (compressed_data == NULL)
 		return (int)s;
 
 	if (rdcu_sync_sram_to_mirror(info->rdcu_cmp_adr_used, s,
@@ -845,22 +847,22 @@ int rdcu_read_cmp_bitstream(const struct cmp_info *info, void *output_buf)
 	/* wait for it */
 	sync();
 
-	return rdcu_read_sram(output_buf, info->rdcu_cmp_adr_used, s);
+	return rdcu_read_sram(compressed_data, info->rdcu_cmp_adr_used, s);
 }
 
 
 /**
- * @brief read the model from the RDCU SRAM
+ * @brief read the updated model from the RDCU SRAM
  *
- * @param info  compression information contains the metadata of a compression
+ * @param info		compression information contains the metadata of a compression
  *
- * @param model_buf  the buffer to store the model (if NULL, the required size
- *		     is returned)
+ * @param updated_model	the buffer to store the updated model (if NULL, the required size
+ *			is returned)
  *
  * @returns the number of bytes read, < 0 on error
  */
 
-int rdcu_read_model(const struct cmp_info *info, void *model_buf)
+int rdcu_read_model(const struct cmp_info *info, void *updated_model)
 {
 	uint32_t s;
 
@@ -870,7 +872,7 @@ int rdcu_read_model(const struct cmp_info *info, void *model_buf)
 	/* calculate the need bytes for the model */
 	s = info->samples_used * IMA_SAM2BYT;
 
-	if (model_buf == NULL)
+	if (updated_model == NULL)
 		return (int)s;
 
 	if (rdcu_sync_sram_to_mirror(info->rdcu_new_model_adr_used, (s+3) & ~3U,
@@ -880,7 +882,7 @@ int rdcu_read_model(const struct cmp_info *info, void *model_buf)
 	/* wait for it */
 	sync();
 
-	return rdcu_read_sram(model_buf, info->rdcu_new_model_adr_used, s);
+	return rdcu_read_sram(updated_model, info->rdcu_new_model_adr_used, s);
 }
 
 
diff --git a/lib/rdcu_pkt_to_file.c b/lib/rdcu_pkt_to_file.c
index ed10778..9e80125 100644
--- a/lib/rdcu_pkt_to_file.c
+++ b/lib/rdcu_pkt_to_file.c
@@ -311,8 +311,11 @@ int init_rmap_pkt_to_file(void)
 	uint8_t icu_addr, rdcu_addr;
 	int mtu;
 
-	if (read_rdcu_pkt_mode_cfg(&icu_addr, &rdcu_addr, &mtu))
-		return -1;
+	if (read_rdcu_pkt_mode_cfg(&icu_addr, &rdcu_addr, &mtu)) {
+		icu_addr = DEF_ICU_ADDR;
+		rdcu_addr = DEF_RDCU_ADDR;
+		mtu = DEF_MTU;
+	}
 	rdcu_ctrl_init();
 	rdcu_set_source_logical_address(icu_addr);
 	rdcu_set_destination_logical_address(rdcu_addr);
@@ -323,7 +326,7 @@ int init_rmap_pkt_to_file(void)
 
 
 /**
- * @brief generate the rmap packets to set up a RDCU compression
+ * @brief generate the rmap packets to set up an RDCU compression
  * @note note that the initialization function init_rmap_pkt_to_file() must be
  *	executed before
  * @note the configuration of the ICU_ADDR, RDCU_ADDR, MTU settings are in the
@@ -363,7 +366,7 @@ int gen_write_rdcu_pkts(const struct cmp_cfg *cfg)
 
 
 /**
- * @brief generate the rmap packets to read the result of a RDCU compression
+ * @brief generate the rmap packets to read the result of an RDCU compression
  * @note note that the initialization function init_rmap_pkt_to_file() must be
  *	executed before
  * @note the configuration of the ICU_ADDR, RDCU_ADDR, MTU settings are in the
@@ -434,7 +437,7 @@ int gen_read_rdcu_pkts(const struct cmp_info *info)
 
 
 /**
- * @brief generate the rmap packets to set up a RDCU compression, read the
+ * @brief generate the rmap packets to set up an RDCU compression, read the
  *	bitstream and the updated model in parallel to write the data to compressed
  *	and the model and start the compression
  * @note the compressed data are read from cfg->rdcu_buffer_adr with the length
diff --git a/lib/rdcu_rmap.c b/lib/rdcu_rmap.c
index b314b47..e4ec4b6 100644
--- a/lib/rdcu_rmap.c
+++ b/lib/rdcu_rmap.c
@@ -490,7 +490,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd),
 /**
  * @brief submit a data sync command
  *
- * @param fn a RDCU data transfer generation function
+ * @param fn an RDCU data transfer generation function
  * @param addr the remote address
  * @param data the local data address
  * @param data_len the length of the data payload
-- 
GitLab