diff --git a/CHANGELOG.md b/CHANGELOG.md index 050cdbd180e8d7ad78c8f5175d4054e3c8c2c0a7..30fb967ffb6b16294c4e57833fe7b8db6497a98b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog 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 - add -b or --binary option for read and write files in binary format @@ -8,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 @@ -21,14 +27,13 @@ All notable changes to this project will be documented in this file. - fixed several bug when using the last_info option - fix a bug in the calculation of the adaptive compression sizes - ## [0.09] - 30-09-2022 ### Added - decompression/compression for non-imagette data - 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/README.md b/README.md index 413b717531291ea167ad0f874821619bb5a52866..55e8ecffa12404a5c1fabd96594fd883d5565316 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,17 @@ Compiled executables can be found [here](https://gitlab.phaidra.org/loidoltd15/c ### General Options -| Options | Description | -|:------------------|:------------------------------------------------------------------------------| -| `-h, --help` | Print some help text and exit | -| `-o <prefix>` | Use the `<prefix>` for output files<sup>[1](#fnote1)</sup> | -| `-n, --model_cfg` | Print a default model configuration and exit<sup>[2](#fnote2)</sup> | -| `--diff_cfg` | Print a default 1d-differencing configuration and exit<sup>[2](#fnote2)</sup> | -| `-b, --binary` | Read and write files in binary format | -| `-a, --rdcu_par` | Add additional RDCU control parameters | -| `-V, --version` | Print program version and exit | -| `-v, --verbose` | Print various debugging information | +| Options | Description | +|:--------------------|:------------------------------------------------------------------------------| +| `-h, --help` | Print some help text and exit | +| `-o <prefix>` | Use the `<prefix>` for output files<sup>[1](#fnote1)</sup> | +| `-n, --model_cfg` | Print a default model configuration and exit<sup>[2](#fnote2)</sup> | +| `--diff_cfg` | Print a default 1d-differencing configuration and exit<sup>[2](#fnote2)</sup> | +| `-b, --binary` | Read and write files in binary format | +| `-a, --rdcu_par` | Add additional RDCU control parameters | +| `-V, --version` | Print program version and exit | +| `-v, -vv, --verbose`| Print various debugging information, -vv is extra verbose | + <a name="fnote1">1</a>) **NOTE:** If the -o option is not used the `<prefix>` will be set to "OUTPUT". diff --git a/cmp_tool.c b/cmp_tool.c index fc19592cbfcd724aa65c92e47d6f02c60a775ed7..6532bfc5667a5cec594ff9785251bcd60a00bde4 100644 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -201,6 +201,8 @@ int main(int argc, char **argv) output_prefix = optarg; break; case 'v': /* --verbose */ + if (io_flags & CMP_IO_VERBOSE) + io_flags |= CMP_IO_VERBOSE_EXTRA; io_flags |= CMP_IO_VERBOSE; break; case 'V': /* --version */ @@ -434,7 +436,7 @@ int main(int argc, char **argv) cmp_ent_set_size(decomp_entity, (uint32_t)buf_size); } - if (io_flags & CMP_IO_VERBOSE) { + if (io_flags & CMP_IO_VERBOSE_EXTRA) { cmp_ent_print(decomp_entity); printf("\n"); } diff --git a/include/cmp_io.h b/include/cmp_io.h index 15c93f95f9ff2200d84d1237f64c0bbcd301a173..bb30f04e8c223c58942cfd5ad6f93690e747b3dd 100644 --- a/include/cmp_io.h +++ b/include/cmp_io.h @@ -29,8 +29,9 @@ #define BUFFER_LENGTH_DEF_FAKTOR 2 /* flags argument options (can be combined) */ -#define CMP_IO_VERBOSE 1 -#define CMP_IO_BINARY 2 +#define CMP_IO_BINARY 0x1 +#define CMP_IO_VERBOSE 0x2 +#define CMP_IO_VERBOSE_EXTRA 0x4 void print_help(const char *program_name); diff --git a/lib/cmp_entity.c b/lib/cmp_entity.c index 3336e674f0445011e5866950ba39ac76c134d703..abf2a54de6647dcc017c9c96af8ae0cb60da4b63 100644 --- a/lib/cmp_entity.c +++ b/lib/cmp_entity.c @@ -2344,11 +2344,11 @@ void cmp_ent_print_header(struct cmp_entity *ent) size_t i; for (i = 0; i < hdr_size; ++i) { - debug_print("%02X ", p[i]); + printf("%02X ", p[i]); if (i && !((i+1) % 32)) - debug_print("\n"); + printf("\n"); } - debug_print("\n"); + printf("\n"); } @@ -2368,11 +2368,11 @@ void cmp_ent_print_data(struct cmp_entity *ent) return; for (i = 0; i < data_size; ++i) { - debug_print("%02X ", p[i]); + printf("%02X ", p[i]); if (i && !((i+1) % 32)) - debug_print("\n"); + printf("\n"); } - debug_print("\n"); + printf("\n"); } @@ -2384,9 +2384,9 @@ void cmp_ent_print_data(struct cmp_entity *ent) void cmp_ent_print(struct cmp_entity *ent) { - debug_print("compression entity header:\n"); + printf("compression entity header:\n"); cmp_ent_print_header(ent); - debug_print("compressed data in the compressed entity:\n"); + printf("compressed data in the compressed entity:\n"); cmp_ent_print_data(ent); } @@ -2411,62 +2411,62 @@ static void cmp_ent_parse_generic_header(struct cmp_entity *ent) uint16_t major = (version_id & 0x7FFF0000U) >> 16U; uint16_t minor = version_id & 0xFFFFU; - debug_print("Compressed with cmp_tool version: %u.%02u\n", major, minor); + printf("Compressed with cmp_tool version: %u.%02u\n", major, minor); } else - debug_print("ICU ASW Version ID: %08" PRIx32 "\n", version_id); + printf("ICU ASW Version ID: %08" PRIx32 "\n", version_id); cmp_ent_size = cmp_ent_get_size(ent); - debug_print("Compression Entity Size: %" PRIu32 " byte\n", cmp_ent_size); + printf("Compression Entity Size: %" PRIu32 " byte\n", cmp_ent_size); original_size = cmp_ent_get_original_size(ent); - debug_print("Original Data Size: %" PRIu32 " byte\n", original_size); + printf("Original Data Size: %" PRIu32 " byte\n", original_size); start_coarse_time = cmp_ent_get_coarse_start_time(ent); - debug_print("Compression Coarse Start Time: %" PRIu32 "\n", start_coarse_time); + printf("Compression Coarse Start Time: %" PRIu32 "\n", start_coarse_time); start_fine_time = cmp_ent_get_fine_start_time(ent); - debug_print("Compression Fine Start Time: %d\n", start_fine_time); + printf("Compression Fine Start Time: %d\n", start_fine_time); end_coarse_time = cmp_ent_get_coarse_end_time(ent); - debug_print("Compression Coarse End Time: %" PRIu32 "\n", end_coarse_time); + printf("Compression Coarse End Time: %" PRIu32 "\n", end_coarse_time); end_fine_time = cmp_ent_get_fine_end_time(ent); - debug_print("Compression Fine End Time: %d\n", end_fine_time); + printf("Compression Fine End Time: %d\n", end_fine_time); #ifdef HAS_TIME_H { struct tm epoch_date = PLATO_EPOCH_DATE; time_t time = my_timegm(&epoch_date) + start_coarse_time; - debug_print("Data were compressed on (local time): %s", ctime(&time)); + printf("Data were compressed on (local time): %s", ctime(&time)); } #endif - debug_print("The compression took %f second\n", end_coarse_time - start_coarse_time + printf("The compression took %f second\n", end_coarse_time - start_coarse_time + ((end_fine_time - start_fine_time)/256./256.)); data_type = cmp_ent_get_data_type(ent); - debug_print("Data Product Type: %d\n", data_type); + printf("Data Product Type: %d\n", data_type); raw_bit = cmp_ent_get_data_type_raw_bit(ent); - debug_print("RAW bit in the Data Product Type is%s set\n", raw_bit ? "" : " not"); + printf("RAW bit in the Data Product Type is%s set\n", raw_bit ? "" : " not"); cmp_mode_used = cmp_ent_get_cmp_mode(ent); - debug_print("Used Compression Mode: %" PRIu32 "\n", cmp_mode_used); + printf("Used Compression Mode: %" PRIu32 "\n", cmp_mode_used); model_value_used = cmp_ent_get_model_value(ent); - debug_print("Used Model Updating Weighing Value: %" PRIu32 "\n", model_value_used); + printf("Used Model Updating Weighing Value: %" PRIu32 "\n", model_value_used); model_id = cmp_ent_get_model_id(ent); - debug_print("Model ID: %" PRIu32 "\n", model_id); + printf("Model ID: %" PRIu32 "\n", model_id); model_counter = cmp_ent_get_model_counter(ent); - debug_print("Model Counter: %" PRIu32 "\n", model_counter); + printf("Model Counter: %" PRIu32 "\n", model_counter); max_used_bits_version = cmp_ent_get_max_used_bits_version(ent); - debug_print("Maximum Used Bits Registry Version: %" PRIu32 "\n", max_used_bits_version); + printf("Maximum Used Bits Registry Version: %" PRIu32 "\n", max_used_bits_version); lossy_cmp_par_used = cmp_ent_get_lossy_cmp_par(ent); - debug_print("Used Lossy Compression Parameters: %" PRIu32 "\n", lossy_cmp_par_used); + printf("Used Lossy Compression Parameters: %" PRIu32 "\n", lossy_cmp_par_used); } @@ -2481,10 +2481,10 @@ static void cmp_ent_parese_imagette_header(struct cmp_entity *ent) uint32_t spill_used, golomb_par_used; spill_used = cmp_ent_get_ima_spill(ent); - debug_print("Used Spillover Threshold Parameter: %" PRIu32 "\n", spill_used); + printf("Used Spillover Threshold Parameter: %" PRIu32 "\n", spill_used); golomb_par_used = cmp_ent_get_ima_golomb_par(ent); - debug_print("Used Golomb Parameter: %" PRIu32 "\n", golomb_par_used); + printf("Used Golomb Parameter: %" PRIu32 "\n", golomb_par_used); } @@ -2500,22 +2500,22 @@ static void cmp_ent_parese_adaptive_imagette_header(struct cmp_entity *ent) ap1_golomb_par_used, ap2_spill_used, ap2_golomb_par_used; spill_used = cmp_ent_get_ima_spill(ent); - debug_print("Used Spillover Threshold Parameter: %" PRIu32 "\n", spill_used); + printf("Used Spillover Threshold Parameter: %" PRIu32 "\n", spill_used); golomb_par_used = cmp_ent_get_ima_golomb_par(ent); - debug_print("Used Golomb Parameter: %" PRIu32 "\n", golomb_par_used); + printf("Used Golomb Parameter: %" PRIu32 "\n", golomb_par_used); ap1_spill_used = cmp_ent_get_ima_ap1_spill(ent); - debug_print("Used Adaptive 1 Spillover Threshold Parameter: %" PRIu32 "\n", ap1_spill_used); + printf("Used Adaptive 1 Spillover Threshold Parameter: %" PRIu32 "\n", ap1_spill_used); ap1_golomb_par_used = cmp_ent_get_ima_ap1_golomb_par(ent); - debug_print("Used Adaptive 1 Golomb Parameter: %" PRIu32 "\n", ap1_golomb_par_used); + printf("Used Adaptive 1 Golomb Parameter: %" PRIu32 "\n", ap1_golomb_par_used); ap2_spill_used = cmp_ent_get_ima_ap2_spill(ent); - debug_print("Used Adaptive 2 Spillover Threshold Parameter: %" PRIu32 "\n", ap2_spill_used); + printf("Used Adaptive 2 Spillover Threshold Parameter: %" PRIu32 "\n", ap2_spill_used); ap2_golomb_par_used = cmp_ent_get_ima_ap2_golomb_par(ent); - debug_print("Used Adaptive 2 Golomb Parameter: %" PRIu32 "\n", ap2_golomb_par_used); + printf("Used Adaptive 2 Golomb Parameter: %" PRIu32 "\n", ap2_golomb_par_used); } @@ -2530,7 +2530,7 @@ static void cmp_ent_parese_specific_header(struct cmp_entity *ent) enum cmp_data_type data_type = cmp_ent_get_data_type(ent); if (cmp_ent_get_data_type_raw_bit(ent)) { - debug_print("Uncompressed data bit is set. No specific header is used.\n"); + printf("Uncompressed data bit is set. No specific header is used.\n"); return; } @@ -2546,7 +2546,7 @@ static void cmp_ent_parese_specific_header(struct cmp_entity *ent) cmp_ent_parese_adaptive_imagette_header(ent); break; default: - debug_print("For this data product type no parse functions is implemented!\n"); + printf("For this data product type no parse functions is implemented!\n"); break; } } diff --git a/lib/cmp_io.c b/lib/cmp_io.c index 874f2246f86326c9b09794f8bdf1af5935e90d06..e3498c8ee7ae6e62ec6697686e4ed143406c87ee 100644 --- a/lib/cmp_io.c +++ b/lib/cmp_io.c @@ -84,7 +84,7 @@ void print_help(const char *program_name) printf(" -b, --binary Read and write files in binary format\n"); printf(" -a, --rdcu_par Add additional RDCU control parameters\n"); printf(" -V, --version Print program version and exit\n"); - printf(" -v, --verbose Print various debugging information\n"); + printf(" -v, -vv, --verbose Print various debugging information, -vv is extra verbose\n"); printf("Compression Options:\n"); printf(" -c <file> File containing the compressing configuration\n"); printf(" -d <file> File containing the data to be compressed\n"); @@ -157,7 +157,7 @@ static FILE *open_file(const char *dirname, const char *filename) * @param data_type compression data type of the data * @param output_prefix file name without file extension * @param name_extension extension (with leading point character) - * @param flags CMP_IO_VERBOSE print verbose output if set + * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set * CMP_IO_BINARY write file in binary format if set * * @returns 0 on success, error otherwise @@ -203,7 +203,7 @@ int write_input_data_to_file(void *data, uint32_t data_size, enum cmp_data_type * @param output_prefix file name without file extension * @param name_extension file extension (with leading point character) * - * @param flags CMP_IO_VERBOSE print verbose output if set + * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set * CMP_IO_BINARY write file in binary format if set * * @returns 0 on success, error otherwise @@ -268,9 +268,10 @@ int write_data_to_file(const void *buf, uint32_t buf_size, const char *output_pr } } - if (flags & CMP_IO_VERBOSE && !(flags & CMP_IO_BINARY)) { + if (flags & CMP_IO_VERBOSE_EXTRA && !(flags & CMP_IO_BINARY)) { + printf("\n"); fwrite(output_file_data, 1, output_file_size, stdout); - printf("\n\n"); + printf("\n"); } free(tmp_buf); @@ -1309,7 +1310,7 @@ static __inline ssize_t str2uint8_arr(const char *str, uint8_t *data, uint32_t b * @param file_name data/model file name * @param buf buffer to write the file content (can be NULL) * @param buf_size number of uint8_t data words to read in - * @param flags CMP_IO_VERBOSE print verbose output if set + * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set * CMP_IO_BINARY read in file in binary format if set * * @returns the size in bytes to store the file content; negative on error @@ -1382,7 +1383,7 @@ ssize_t read_file8(const char *file_name, uint8_t *buf, uint32_t buf_size, int f fclose(fp); fp = NULL; - size = str2uint8_arr(file_cpy, buf, buf_size, file_name, flags & CMP_IO_VERBOSE); + size = str2uint8_arr(file_cpy, buf, buf_size, file_name, flags & CMP_IO_VERBOSE_EXTRA); free(file_cpy); file_cpy = NULL; @@ -1406,7 +1407,7 @@ fail: * @param data_type compression data type used for the data * @param buf buffer to write the file content (can be NULL) * @param buf_size size in bytes of the buffer - * @param flags CMP_IO_VERBOSE print verbose output if set + * @param flags CMP_IO_VERBOSE_EXTRA print verbose output if set * CMP_IO_BINARY read in file in binary format if set * * @returns the size in bytes to store the file content; negative on error @@ -1471,6 +1472,11 @@ ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, if (ent) { enum cmp_data_type data_type = cmp_ent_get_data_type(ent); + if (flags & CMP_IO_VERBOSE) { + printf("\n"); + cmp_ent_parse(ent); + } + if (data_type == DATA_TYPE_UNKNOWN) { fprintf(stderr, "%s: %s: Error: Compression data type is not supported. The header of the compression entity may be corrupted.\n", PROGRAM_NAME, file_name); @@ -1481,9 +1487,6 @@ ssize_t read_file_cmp_entity(const char *file_name, struct cmp_entity *ent, PROGRAM_NAME, file_name, cmp_ent_get_size(ent), (size_t)size); return -1; } - - if (flags & CMP_IO_VERBOSE) - cmp_ent_parse(ent); } return size; diff --git a/lib/cmp_rdcu.c b/lib/cmp_rdcu.c index 362cdfc47ad61b9cec898b28391ca0cd8b8f8431..5c6b01591f281d2e247ceec271cc08c6f4ae1b25 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 f870c534f0be38d3ab50ec442b4c73768bad8361..774a7950930d0091750073674f117891d0db934d 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 9563b5f253db73c6ad488c82d0458af700a0c358..44c8e425613255ccac7f0226228bd7475095c363 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'] diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index 1f0c948b352195c6a3a8efba6b38c5807b076637..9d40abefc597e4cbecde941c951210db17bcb9d7 100755 --- a/test/cmp_tool/cmp_tool_integration_test.py +++ b/test/cmp_tool/cmp_tool_integration_test.py @@ -209,7 +209,7 @@ General Options: -b, --binary Read and write files in binary format -a, --rdcu_par Add additional RDCU control parameters -V, --version Print program version and exit - -v, --verbose Print various debugging information + -v, -vv, --verbose Print various debugging information, -vv is extra verbose Compression Options: -c <file> File containing the compressing configuration -d <file> File containing the data to be compressed