diff --git a/include/stored_configuration_nvm/config_data.h b/include/stored_configuration_nvm/config_data.h index b928e4e..6654e5a 100644 --- a/include/stored_configuration_nvm/config_data.h +++ b/include/stored_configuration_nvm/config_data.h @@ -459,4 +459,45 @@ typedef struct __attribute__((aligned (4))) config_data_gsm_t { } config_data_gsm_t; +/** + * This structure holds compatibility numbers, which are used to check if + * configuration data stored in the NVM is compatible with running software. + * It is useful after firmware upgrade, which doesn't alter the configuration + * data. Each config block has a separate entry here (like basic, mode, RTU). + * During startup, if CRC verification is passed the software reads uint32_t + * word for each config block, and compare with internally hardcoded value + * If value in NVM is bigger than what application has, the app AND that + * with a bitmask (also hardcoded) to check if it can safely ignore that. + * + * If it cannot ignore, the configuration is too new and supposedly + * not compatible. The application should then either restore default values, + * or switch to different interpretation of that data - at least do something.  + * + * If the value from NVM is less than value from application (but not equal!!!) + * it is additionally ORed with another hardcoded bitmask. If a result of + * this OR is bigger than application + * + * + */ +typedef struct __attribute__((aligned (4))) config_data_compatibility_version_t { + + uint64_t mode_block_compatiblity_number; // 8 bytes + + uint64_t basic_block_compatiblity_number; // 8 bytes + + uint64_t sources_block_compatiblity_number; // 8 bytes + + uint64_t umb_block_compatiblity_number; // 8 bytes + + uint64_t rtu_block_compatiblity_number; // 8 bytes + + uint64_t gsm_block_compatiblity_number; // 8 bytes + + uint64_t seventh_block_compatibility_number; + + uint64_t eight_block_compatibility_number; + + +}config_data_compatibility_version_t; + #endif /* CONFIG_DATA_H_ */ diff --git a/ldscripts/stm32f100/sections.ld b/ldscripts/stm32f100/sections.ld index 41c8e1a..a24ba99 100644 --- a/ldscripts/stm32f100/sections.ld +++ b/ldscripts/stm32f100/sections.ld @@ -266,6 +266,9 @@ SECTIONS . = start + 0x160; KEEP(*(.config_section_first.rtu)); + . = start + 0x790; + KEEP(*(.config_section_first.compat)); + . = 0x7F8; KEEP(*(.config_section_first.crc)); @@ -296,6 +299,9 @@ SECTIONS . = start + 0x160; KEEP(*(.config_section_second.rtu)); + . = start + 0x790; + KEEP(*(.config_section_second.compat)); + . = 0x7F8; KEEP(*(.config_section_second.crc)); diff --git a/src/stored_configuration_nvm/config_data_default.c b/src/stored_configuration_nvm/config_data_default.c index 036e924..eae127e 100644 --- a/src/stored_configuration_nvm/config_data_default.c +++ b/src/stored_configuration_nvm/config_data_default.c @@ -546,3 +546,13 @@ const config_data_gsm_t __attribute__((section(".config_section_default.gsm"))) #endif +const config_data_compatibility_version_t __attribute__((section(".config_section_default.compat"))) config_data_compatibility_default = { + .mode_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .basic_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .sources_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .umb_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .rtu_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .gsm_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .seventh_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL, + .eight_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL +}; diff --git a/src/stored_configuration_nvm/config_data_first.c b/src/stored_configuration_nvm/config_data_first.c index 90dd4fb..ae35cc3 100644 --- a/src/stored_configuration_nvm/config_data_first.c +++ b/src/stored_configuration_nvm/config_data_first.c @@ -525,4 +525,16 @@ const config_data_rtu_t __attribute__((section(".config_section_first.rtu"))) co //}; //#endif +const config_data_compatibility_version_t __attribute__((section(".config_section_first.compat"))) config_data_compatibility_first = { + .mode_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .basic_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .sources_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .umb_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .rtu_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .gsm_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .seventh_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL, + .eight_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL + +}; + #endif diff --git a/src/stored_configuration_nvm/config_data_second.c b/src/stored_configuration_nvm/config_data_second.c index 060ed9e..a258ae4 100644 --- a/src/stored_configuration_nvm/config_data_second.c +++ b/src/stored_configuration_nvm/config_data_second.c @@ -519,5 +519,17 @@ const config_data_rtu_t __attribute__((section(".config_section_second.rtu"))) c #endif +const config_data_compatibility_version_t __attribute__((section(".config_section_second.compat"))) config_data_compatibility_second = { + .mode_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .basic_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .sources_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .umb_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .rtu_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .gsm_block_compatiblity_number = 0xFFFFFFFFFFFFFFFFULL, + .seventh_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL, + .eight_block_compatibility_number = 0xFFFFFFFFFFFFFFFFULL + +}; + #endif diff --git a/src/stored_configuration_nvm/configuration_handler.c b/src/stored_configuration_nvm/configuration_handler.c index 0d87d27..e7babdc 100644 --- a/src/stored_configuration_nvm/configuration_handler.c +++ b/src/stored_configuration_nvm/configuration_handler.c @@ -42,11 +42,12 @@ #define CONFIG_MODE_PGM_CNTR 0x0 #define CONFIG_MODE_OFSET 0x20 // Current size: 0x14, free: 0x0C -#define CONFIG_BASIC_OFFSET 0x40 // Current size: 0xA6, free: 0x3A +#define CONFIG_BASIC_OFFSET 0x40 // Current size: 0xA8, free: 0x38 #define CONFIG_SOURCES_OFFSET 0x120 // Current size: 0x8, free: 0x18 #define CONFIG_UMB_OFFSET 0x140 // Current size: 0x10, free: 0x10 -#define CONFIG_RTU_OFFSET 0x160 // Current size: 0x10, free: 0x90 -#define CONFIG_GSM_OFFSET 0x200 // Current size: 0x114, +#define CONFIG_RTU_OFFSET 0x160 // Current size: 0x54, free: 0x4C +#define CONFIG_GSM_OFFSET 0x200 // Current size: 0x114,free: +#define CONFIG_COMPAT_OFFSET 0x790 // Current size: 0x40, free: 0x28 #define CONFIG__END__OFFSET 0x7E0 #include