Document API IEC60730 Library
|
Verifies contents of flash memory. More...
Classes | |
struct | sl_iec60730_imc_params_t |
This structure is used as configuration for IMC testing, that holds GPCRC Register. More... | |
struct | sl_iec60730_update_crc_params_t |
struct | sl_iec60730_imc_test_region_t |
This structure is used as configuration for IMC testing. The variable contains information about the starting and ending address of the region you want to check. More... | |
struct | sl_iec60730_imc_test_multiple_regions_t |
Macros | |
#define | sl_iec60730_crc_t |
#define | SL_IEC60730_INVAR_BLOCKS_PER_BIST |
#define | SL_IEC60730_ROM_SIZE ((uint32_t) SL_IEC60730_ROM_END - (uint32_t) SL_IEC60730_ROM_START) |
#define | STEPS_NUMBER ((uint32_t) SL_IEC60730_ROM_SIZE / SL_IEC60730_FLASH_BLOCK) |
#define | SL_IEC60730_ROM_SIZE_INWORDS ((uint32_t) SL_IEC60730_ROM_SIZE / 4U) |
#define | SL_IEC60730_FLASH_BLOCK_WORDS ((uint32_t) (SL_IEC60730_ROM_SIZE_INWORDS / STEPS_NUMBER)) |
#define | SL_IEC60730_ROM_SIZE_TEST(start, end) ((uint32_t) end - (uint32_t) start) |
#define | STEPS_NUMBER_TEST(start, end) ((uint32_t) SL_IEC60730_ROM_SIZE_TEST(start, end) / SL_IEC60730_FLASH_BLOCK) |
#define | SL_IEC60730_ROM_SIZE_INWORDS_TEST(start, end) ((uint32_t) SL_IEC60730_ROM_SIZE_TEST(start, end) / 4U) |
#define | SL_IEC60730_FLASH_BLOCK_WORDS_TEST(start, end) ((uint32_t) (SL_IEC60730_ROM_SIZE_INWORDS_TEST(start, end) / STEPS_NUMBER_TEST(start, end))) |
#define | SL_IEC60730_REF_CRC (check_sum) |
#define | SL_IEC60370_ENTER_ATOMIC() CORE_ENTER_ATOMIC() |
Enter ATOMIC section. | |
#define | SL_IEC60370_EXIT_ATOMIC() CORE_EXIT_ATOMIC() |
Exit ATOMIC section. | |
#define | SL_IEC60370_DECLARE_IRQ_STATE CORE_DECLARE_IRQ_STATE; |
Declare irq state. | |
#define | SL_IEC60730_IMC_POST_ENTER_ATOMIC() |
Enter ATOMIC section of IMC Post. More... | |
#define | SL_IEC60730_IMC_POST_EXIT_ATOMIC() CORE_EXIT_ATOMIC() |
Exit ATOMIC section of IMC Post. | |
#define | SL_IEC60730_IMC_BIST_ENTER_ATOMIC() |
Enter ATOMIC section of IMC Bist. More... | |
#define | SL_IEC60730_IMC_BIST_EXIT_ATOMIC() CORE_EXIT_ATOMIC() |
Exit ATOMIC section of IMC Bist. | |
#define | SL_IEC60730_CRC_INIT(crc, init) GPCRC_Init(crc, init) |
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module. | |
#define | SL_IEC60730_CRC_RESET(crc) GPCRC_Reset(crc) |
Reset GPCRC registers to the hardware reset state. | |
#define | SL_IEC60730_CRC_START(crc) GPCRC_Start(crc) |
Issues a command to initialize CRC calculation. | |
#define | SL_IEC60730_CRC_INPUTU32(crc, d) GPCRC_InputU32(crc, d) |
Writes a 32-bit value to the input data register of the CRC. | |
#define | SL_IEC60730_CRC_INPUTU16(crc, d) GPCRC_InputU16(crc, d) |
Writes a 32-bit value to the input data register of the CRC. | |
#define | SL_IEC60730_CRC_INPUTU8(crc, d) GPCRC_InputU8(crc, d) |
Writes a 8-bit value to the input data register of the CRC. | |
#define | SL_IEC60730_CRC_DATA_READ(crc) GPCRC_DataRead(crc) |
Reads the data register of the CRC. | |
#define | SL_IEC60730_CRC_DATA_READ_BIT_REVERSED(crc) GPCRC_DataReadBitReversed(crc) |
Reads the data register of the CRC. | |
#define | SL_IEC60730_CRC_DATA_READ_BYTE_REVERSED(crc) GPCRC_DataReadByteReversed(crc) |
Reads the data register of the CRC. | |
#define | SL_IEC60730_DEFAULT_GPRC |
#define | SL_IEC60730_IMC_CRC_BUFFER_SAMPLE_TEST "123456789" |
#define | SL_IEC60730_IMC_CRC_BUFFER_INIT_VALUE |
#define | SL_IEC60730_IMC_CRC_BUFFER_XOR_OUTPUT |
#define | SL_IEC60730_IMC_CRC_BUFFER_SAMPLE_RESULT |
#define | SL_IEC60730_IMC_CRC_BUFFER_UPDATE_DEFAULT |
#define | SL_IEC60730_ROM_START ((uint32_t *) (&flash_start)) |
#define | SL_IEC60730_ROM_END ((uint32_t *) (&check_sum)) |
#define | SL_IEC60730_IMC_INIT_VALUE |
#define | SL_IEC60730_IMC_XOROUTPUT |
#define | SL_IEC60730_IMC_INIT_DEFAULT |
#define | SL_IEC60730_CRC_DEBUG_ENABLE 1 |
Use this definition for debugging purposes. | |
#define | SL_IEC60730_INVAR_BLOCKS_PER_BIST 512 |
Number of blocks per test bist. | |
#define | SL_IEC60730_FLASH_BLOCK 64 |
#define | SL_IEC60730_CRC_USE_SW_ENABLE 0 |
#define | SL_IEC60730_SW_CRC_TABLE_ENABLE 0 |
#define | SL_IEC60730_USE_CRC_32_ENABLE 0 |
Typedefs | |
typedef GPCRC_TypeDef | sl_iec60730_crc_typedef |
the General Purpose Cyclic Redundancy Check (GPCRC) module | |
typedef GPCRC_Init_TypeDef | sl_iec60730_crc_init_typedef |
CRC initialization structure. | |
typedef uint8_t | sl_iec60730_read_type_t |
The way to read CRC value when using function sl_iec60730_update_crc_with_data_buffer. | |
Enumerations | |
enum | { SL_IEC60730_IMC_DATA_READ = 0, SL_IEC60730_IMC_DATA_READ_BIT_REVERSED, SL_IEC60730_IMC_DATA_READ_BYTE_REVERSED } |
The way to read CRC value when using function sl_iec60730_update_crc_with_data_buffer. More... | |
Functions | |
void | sl_iec60730_imc_init (sl_iec60730_imc_params_t *params, sl_iec60730_imc_test_multiple_regions_t *test_config) |
sl_iec60730_test_result_t | sl_iec60730_update_crc_with_data_buffer (sl_iec60730_update_crc_params_t *params, sl_iec60730_crc_t *crc, uint8_t *buffer, uint32_t size) |
sl_iec60730_test_result_t | sl_iec60730_imc_post (void) |
sl_iec60730_test_result_t | sl_iec60730_imc_bist (void) |
Variables | |
sl_iec60730_crc_t | check_sum |
uint32_t | flash_start |
Flash start address. | |
Verifies contents of flash memory.
In the current version, the calculation of CRC for Flash is calculated starting from the starting address of the Flash (that value can be changed) to the end address whose value is specified by the address of the check_sum variable. Currently, the check_sum variable is set to the end address of user code that uses IEC60730 Library.
To test the Flash memory, a Cyclic Redundancy Check (CRC) is computed and compared with a value stored in Flash. Any change in the Flash will cause the CRC not to match the stored value.
We support multiple calculation modes. These modes are selected by the user. User adds definitions to use these modes. Please reference definitions SL_IEC60730_CRC_DEBUG_ENABLE, SL_IEC60730_CRC_USE_SW_ENABLE, and SL_IEC60730_USE_CRC_32_ENABLE for more detail.
As electrically eraseable memories, the primary risk with Flash is losing charge. Normal memory concerns such as stuck-at, coupling, and address faults may also occur. All these faults will be detected by a CRC across the region. Another risk is the hardware CRC module operating incorrectly. In this case, the CRC comparison will fail and sl_iec60730_safe_state() will begin.
The Invariable Memory Check (IMC) validates that the Flash memory storing the firmware and any persistent configuration information has not been corrupted. The IMC calculates a CRC across designated areas to verify their contents.
We support calculation CRC by using hardware and software. The default CRC is hardware calculation. User CAN use the SL_IEC60730_CRC_USE_SW_ENABLE definition in case using CRC software.
With case CRC software is chosen, the default is calculate CRC-table in initialization process. User CAN use the SL_IEC60730_SW_CRC_TABLE_ENABLE definition in case using pre-defined table.
We support both CRC-16 and CRC-32 mode. With CRC-16, the CRC engine is configured to use the CRC-16/XMODEM polynominal 0x1021. With CRC-32, the CRC engine is configured to use the CRC-32 polynominal 0x04C11DB7. The default is CRC-16 mode. In case using CRC-32, user SHOULD enable define the SL_IEC60730_USE_CRC_32_ENABLE definition.
We also provide scripts named sl_iec60730_call_crc16.sh (for CRC-16 mode) and sl_iec60730_call_crc32.sh (for CRC-32 mode) which is used in Post Build process to calculate CRC value of the Flash and place this CRC value at the end of user code determined by address of check_sum variable. We WILL call these scripts with the common name sl_iec60730_call_crcXY. These scripts work for both GCC and IAR compiler. To use these scripts, user SHOULD install srecord that can be downloaded (.exe) file for Window OS or run command as below for Linux OS.
Script sl_iec60730_call_crcXY requires the following parameters
$1 | Name of your project. | |
$2 | Directory of building. This directory MUST contain *.hex file and *.map file. The *.map file MUST contains check_sum variable. | |
$3 | Path of srecord. With Linux OS, it SHOULD be blank. With Win OS, it SHOULD be the path to install folder of srecord. For example: 'C:\srecord-1.64-win32' in Win OS. | |
$4 | Compiler: GCC or IAR. | |
$5 | Start address of Flash. Or multiple regions address of Flash |
The struct sl_iec60730_imc_params_t is used to manage hardware configuration of CRC. In case using CRC software (define SL_IEC60730_CRC_USE_SW_ENABLE), you can pass NULL pointer to function use this struct.
We use a pair of variables to check intergrity. Using the following macros in case you want to work with pair of variables need to be checked intergrity. These macros are defined in sl_iec60730.h file.
Some detail about implementing of IMC and using variables for testing purpose. These variables are also used in the test cases (TC) of the IMC module.
To provide complete definitions of IMC modules, in SL_IEC60730_BOARD_HEADER file, user SHOULD pay attention to the SL_IEC60730_ROM_START definition. The STEPS_NUMBER, SL_IEC60730_ROM_SIZE_INWORDS, and SL_IEC60730_FLASH_BLOCK_WORDS definitions SHOULD use our default definitions. The SL_IEC60730_FLASH_BLOCK, SL_IEC60730_ROM_END, and SL_IEC60730_REF_CRC definitions can be redefined by the user but SHOULD not be recommended unless the user has knowledge of linker and Flash configuration.
Figure 1 describes a Flash with multiple applications on that. These applications are named Application 1, Application 2, ..., Application N, and Application (N+1). Where Application N is a main application that uses the IEC60730 library.
The SL_IEC60730_ROM_START definition can be placed anywhere that guarantees the description of SL_IEC60730_ROM_START. As you can see in Figure 1, it is possible that SL_IEC60730_ROM_START is either SL_IEC60730_ROM_START (1) or SL_IEC60730_ROM_START (N).
The SL_IEC60730_ROM_END definition as described at the address of the variable check_sum. As the linker files is used in our example will be at address the end of Application (N). The CRC calculation will go from address SL_IEC60730_ROM_START to SL_IEC60730_ROM_END.
With SL_IEC60730_ROM_START (1) we calculate CRC (1) and with SL_IEC60730_ROM_START (N) we calculate CRC (N). The CRC value is calculated and placed at the location of the variable check_sum. Calculating and placing are implemented by script sl_iec60730_call_crcXY.
In this example you see that Application (N + 1) is an application that does not use the IEC60730 library. Our reference solutions DO NOT support customizing check_sum anywhere in Flash. Therefore, the CRC calculation WILL not cover the Flash area of Application (N + 1).
In case the user edits their linker to let the check_sum variable go to any location (of course larger than SL_IEC60730_ROM_START), the IMC modules WILL still work normally. For example, the user adjust the address of check_sum to the end address of Flash of Application (N + 1), then the CRC calculation WILL completely cover Application (N + 1).
Function sl_iec60730_imc_post() checks for all the invariable memory areas have been configured.
On BIST, partial memory sections are tested to keep overall BIST test time reasonable. Global variables store the current location being tested and other information. Each call to sl_iec60730_imc_bist() it checks SL_IEC60730_INVAR_BLOCKS_PER_BIST. After the calculation is finished, the CRC does not match the expected value, SL_IEC60730_TEST_FAILED is returned. If it does match, the global variables are configured for the next CRC entry. If all areas are complete, SL_IEC60730_TEST_PASSED is returned. If all areas are not complete, SL_IEC60730_TEST_IN_PROGRESS is returned.
#define sl_iec60730_crc_t |
Support for cleaner code.
#define SL_IEC60730_CRC_USE_SW_ENABLE 0 |
The library support both hardware and software CRC. Use this definition in case the user use software CRC. The default hardware is used.
#define SL_IEC60730_DEFAULT_GPRC |
This macro is the default of GPCRC Register.
#define SL_IEC60730_FLASH_BLOCK 64 |
The value of this definition SHOULD be a power of two. The minimal value SHOULD be 4 and maximum value SHOULD be the alignment value that is defined in linker (GCC compiler) or in configuration of IAR. Our example use alignment 64 for check_sum variable. So that in our example the SL_IEC60730_FLASH_BLOCK definition is 64. User can refer to our example linker on how to provide check_sum variable with alignment 64.
#define SL_IEC60730_FLASH_BLOCK_WORDS ((uint32_t) (SL_IEC60730_ROM_SIZE_INWORDS / STEPS_NUMBER)) |
The SL_IEC60730_FLASH_BLOCK_WORDS definitionn WILL be defined base on SL_IEC60730_ROM_SIZE_INWORDS and STEPS_NUMBER definitions. User SHOULD not change it.
#define SL_IEC60730_FLASH_BLOCK_WORDS_TEST | ( | start, | |
end | |||
) | ((uint32_t) (SL_IEC60730_ROM_SIZE_INWORDS_TEST(start, end) / STEPS_NUMBER_TEST(start, end))) |
The SL_IEC60730_FLASH_BLOCK_WORDS_TEST definitionn WILL be defined base on SL_IEC60730_ROM_SIZE_INWORDS_TEST and STEPS_NUMBER_TEST definitions. User SHOULD not change it.
#define SL_IEC60730_IMC_BIST_ENTER_ATOMIC | ( | ) |
Enter ATOMIC section of IMC Bist.
#define SL_IEC60730_IMC_CRC_BUFFER_INIT_VALUE |
This macro is the initial value used for CRC calculations. User DOES NOT change this value
#define SL_IEC60730_IMC_CRC_BUFFER_SAMPLE_RESULT |
This macro is the expected CRC value with input buffer that equal to "123456789" and init value CRC is 0x0000 (CRC16) or 0xFFFFFFFF (CRC32) . These value are only used in development phase. User DOES NOT take care this definition.
#define SL_IEC60730_IMC_CRC_BUFFER_SAMPLE_TEST "123456789" |
This macro is the sample test buffer used for testing CRC algorithm. This value is used in development phase. User DOES NOT take care this definition.
#define SL_IEC60730_IMC_CRC_BUFFER_UPDATE_DEFAULT |
This macro is the default value of struct sl_iec60730_update_crc_params_t. User DOES NOT change this value
#define SL_IEC60730_IMC_CRC_BUFFER_XOR_OUTPUT |
This macro is the value that will XOR with calculated CRC value to get CRC output value. User DOES NOT change this value
#define SL_IEC60730_IMC_INIT_DEFAULT |
This macro is the default value of struct #CRC_INIT_TypeDef. In our library, The #CRC_INIT_TypeDef struct WILL be #GPCRC_Init_TypeDef struct, a struct is defined for CRC by Silicon Labs.
#define SL_IEC60730_IMC_INIT_VALUE |
This macro is the initial value used for CRC calculations.
#define SL_IEC60730_IMC_POST_ENTER_ATOMIC | ( | ) |
Enter ATOMIC section of IMC Post.
#define SL_IEC60730_IMC_XOROUTPUT |
This macro is the value that will XOR with calculated CRC value to get CRC output value.
#define SL_IEC60730_INVAR_BLOCKS_PER_BIST |
The SL_IEC60730_INVAR_BLOCKS_PER_BIST desribles maximum number of loops that perform the CRC calculation each time the sl_iec60730_imc_bist is invoked. We provide default value for this definition in sl_iec60730.h file.
#define SL_IEC60730_REF_CRC (check_sum) |
The SL_IEC60730_REF_CRC definition describes variable that address of this variable store CRC value that is calculated by sl_iec60730_call_crcXY in Post Build. We use check_sum so in our example SL_IEC60730_REF_CRC definition is check_sum.
#define SL_IEC60730_ROM_END ((uint32_t *) (&check_sum)) |
The SL_IEC60730_ROM_END definition describes the end address of Flash. It is the address of check_sum variables. In this version, users SHOULD not change this definition. Refer to the example in invariable_memory_check_example_flowchart, to better understand the SL_IEC60730_ROM_START, and SL_IEC60730_ROM_END definitions.
#define SL_IEC60730_ROM_SIZE ((uint32_t) SL_IEC60730_ROM_END - (uint32_t) SL_IEC60730_ROM_START) |
The SL_IEC60730_ROM_SIZE definition describes the size of Flash calculated CRC value. This calculation based on SL_IEC60730_ROM_END, and SL_IEC60730_ROM_START definitions.
#define SL_IEC60730_ROM_SIZE_INWORDS ((uint32_t) SL_IEC60730_ROM_SIZE / 4U) |
The SL_IEC60730_ROM_SIZE_INWORDS definitionn WILL be defined base on SL_IEC60730_ROM_SIZE definition. User SHOULD not change it.
#define SL_IEC60730_ROM_SIZE_INWORDS_TEST | ( | start, | |
end | |||
) | ((uint32_t) SL_IEC60730_ROM_SIZE_TEST(start, end) / 4U) |
The SL_IEC60730_ROM_SIZE_INWORDS_TEST definitionn WILL be defined base on SL_IEC60730_ROM_SIZE_TEST definition. User SHOULD not change it.
#define SL_IEC60730_ROM_SIZE_TEST | ( | start, | |
end | |||
) | ((uint32_t) end - (uint32_t) start) |
The SL_IEC60730_ROM_SIZE_TEST definition describes the size of region Flash calculated CRC value. This calculation based on #end address, and #start address region is transmitted. definitions.
#define SL_IEC60730_ROM_START ((uint32_t *) (&flash_start)) |
The SL_IEC60730_ROM_START definition describes the start address of Flash for CRC calculation. This definition MUST be alignment of SL_IEC60730_FLASH_BLOCK and can be changed by user so that the value DOES NOT exceed the end address of Flash (the SL_IEC60730_ROM_END definition). Otherwise, sl_iec60730_imc_post and sl_iec60730_imc_bist return SL_IEC60730_TEST_FAILED. The default value of the SL_IEC60730_ROM_START can be found in sl_iec60730_board.h file.
In case you change value of this definition then you SHOULD change the 5th parameter of the script sl_iec60730_call_crcXY when running the Post Build.
In our example, we use the variable flash_start provided by the linker file to simply define the start address of Flash. User can redefine SL_IEC60730_ROM_START as follows.
#define SL_IEC60730_SW_CRC_TABLE_ENABLE 0 |
If using SL_IEC60730_CRC_USE_SW_ENABLE definition then the SL_IEC60730_SW_CRC_TABLE_ENABLE definition is used for using pre-defined table for calculating.
#define SL_IEC60730_USE_CRC_32_ENABLE 0 |
Use this definition in case the user use CRC-32 for calculating the CRC value. The default CRC-16 is used.
#define STEPS_NUMBER ((uint32_t) SL_IEC60730_ROM_SIZE / SL_IEC60730_FLASH_BLOCK) |
The STEPS_NUMBER definitionn WILL be defined base on SL_IEC60730_ROM_SIZE and SL_IEC60730_FLASH_BLOCK definition. User SHOULD not change it.
#define STEPS_NUMBER_TEST | ( | start, | |
end | |||
) | ((uint32_t) SL_IEC60730_ROM_SIZE_TEST(start, end) / SL_IEC60730_FLASH_BLOCK) |
The STEPS_NUMBER_TEST definitionn WILL be defined base on SL_IEC60730_ROM_SIZE_TEST and SL_IEC60730_FLASH_BLOCK definition. User SHOULD not change it.
anonymous enum |
The way to read CRC value when using function sl_iec60730_update_crc_with_data_buffer.
sl_iec60730_test_result_t sl_iec60730_imc_bist | ( | void | ) |
public IEC60730 Invariable Memory Check BIST
Performs a CRC check across all defined memory areas. For details how sl_iec60730_imc_bist work, please refer to Software Architecture
Requires sl_iec60730_imc_init to be called first to setup global variables.
void sl_iec60730_imc_init | ( | sl_iec60730_imc_params_t * | params, |
sl_iec60730_imc_test_multiple_regions_t * | test_config | ||
) |
public IEC60730 Invariable Memory Check (IMC) Init
params | input parameter hardware configuration of CRC |
test_config | input parameter of region and number of regions user want to test |
Performs a initialization of global variables and hardware configuration in case hardware support.
sl_iec60730_test_result_t sl_iec60730_imc_post | ( | void | ) |
public IEC60730 Invariable Memory Check POST
Performs a CRC check across all defined memory areas.
sl_iec60730_test_result_t sl_iec60730_update_crc_with_data_buffer | ( | sl_iec60730_update_crc_params_t * | params, |
sl_iec60730_crc_t * | crc, | ||
uint8_t * | buffer, | ||
uint32_t | size | ||
) |
public IEC60730 Update CRC git pull with Data Buffer
params | input parameter hardware configuration of CRC |
crc | The CRC to be updated. The initial value of crc is also initial value of CRC calculation. |
buffer | A contiguous array of 1-byte values to be used to update the CRC. |
size | The number of bytes stored in the buffer. |
This routine takes a CRC and updates it on a pointer crc using a buffer of one or more bytes of data. For details on the CRC polynomial used, see Hardware Architecture
sl_iec60730_crc_t check_sum |
The end address of Flash is specified by the address of the check_sum variable. This variable is provided by linker in GCC or generated by configurations in IAR.