cancel
Showing results for 
Search instead for 
Did you mean: 

MotionMC_SaveCalInNVM write byte ?

lyiku.1
Associate II

mc.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Martin B
ST Employee

Hello,

The MotionMC_SaveCalInNVM() function is intended to store internal calibration data structure and is called from inside of algorithm.

This function is exposed due to HW dependent load/store mechanism and must be implemented (customized) specificaly for each HW.

The simplfied example code of its implementation and usage is:

/* ... */

uint8_t *calibration = NULL;

/* ... */

char MotionMC_SaveCalInNVM(unsigned short int datasize, unsigned int *data)
{
    if (calibration == NULL) {
         calibration = (uint8_t *)malloc(datasize);
    }

    memcpy(calibration, (uint8_t *)data, datasize);
    return 0;
}

/* ... */

 

where datasize is size of internal calibration data structure. For this specific library it is 184 bytes, e.g.:

sizeof(calibration_data) == 184

However this size might change in future in case of library update. Therefore it is recommended to use dynamic memory allocation using datasize as required memory size or in case of static allocation it is necessary to check
the datasize value in advance.

All bytes (size == datasize) are written, but some of bytes might be uninitialized and thus might apear as not written at all. Some of bytes might be uninitialized permanently (e.g.: padding bytes used for memory alignment inside of structure) or might be initialized later by algorithm internal decision.

View solution in original post

1 REPLY 1
Martin B
ST Employee

Hello,

The MotionMC_SaveCalInNVM() function is intended to store internal calibration data structure and is called from inside of algorithm.

This function is exposed due to HW dependent load/store mechanism and must be implemented (customized) specificaly for each HW.

The simplfied example code of its implementation and usage is:

/* ... */

uint8_t *calibration = NULL;

/* ... */

char MotionMC_SaveCalInNVM(unsigned short int datasize, unsigned int *data)
{
    if (calibration == NULL) {
         calibration = (uint8_t *)malloc(datasize);
    }

    memcpy(calibration, (uint8_t *)data, datasize);
    return 0;
}

/* ... */

 

where datasize is size of internal calibration data structure. For this specific library it is 184 bytes, e.g.:

sizeof(calibration_data) == 184

However this size might change in future in case of library update. Therefore it is recommended to use dynamic memory allocation using datasize as required memory size or in case of static allocation it is necessary to check
the datasize value in advance.

All bytes (size == datasize) are written, but some of bytes might be uninitialized and thus might apear as not written at all. Some of bytes might be uninitialized permanently (e.g.: padding bytes used for memory alignment inside of structure) or might be initialized later by algorithm internal decision.