Sensor calibration data in normal mode, restore factory settings, no loss

Source: Internet
Author: User
Currently, the calibration data of ACC, gyro, and PS sensor is stored in NVRAM and added to NVRAM binregion. After the factory settings are restored, sensor calibration data recovery.
However, the sensor data in NVRAM binregion must be calibrated and saved on the production line, and is always a fixed value.
However, in normal mode, the customer needs to perform Calibration at any time and keep the latest calibration value intact.
Because the source code of NVRAM binregion and sensor daemon is not open, the sensor NVRAM cannot be saved in pro_info.
Now the sensor NVRAM backup function is provided to save sensor data.

1. Check whether mtk_product_info_support is enabled.
Modify Alps/mediatek/config/$ Project/projectconfig. mk: mtk_product_info_support = Yes
Mtk_product_info_support must also exist in auto_add_global_define_by_name.
 
2. Define the struct to be saved
Here, the ACC, gyro, and PS struct are defined in a backup data, which can be added or deleted as needed. The file name can be customized or added to an existing file.
\ Mediatek \ custom \ $ project \ cgen \ paifileinc \ pai_xxxx_file.h
// The new record for the hwmon sensor backup data
# Define pai_hwmon_backup_reserved_size (bytes)
Typedef struct {
Nvram_hwmon_acc_struct hwmon_acc;
Nvram_hwmon_gyro_struct hwmon_gyro;
Nvram_hwmon_ps_struct hwmon_ps;
Unsigned char reserved [performance_hwmon_backup_reserved_size];
} Hwmon_backup_struct;
# Define inclu_file_hwmon_backup_size sizeof (hwmon_backup_struct)
# Define pai_file_hwmon_backup_total 1
 
// Default value of the struct data
\ Mediatek \ custom \ $ project \ cgen \ export Default \ pai_xxxx_default.h
Hwmon_backup_struct st_hwmon_backup_default =
{
// ACC
{0 },
// Gyro
{0 },
// PS
{0 },
// Reserved
{0}
};


 
3. Add a new NVRAM Data Definition
\ Mediatek \ custom \ $ project \ cgen \ Inc \ custom_nvram_assist.h
// Add lid Definition
Ap_pai_rdcl_hwmon_backup_lid, // new add
Ap_cfg_custom_file_max_lid,
} Custom_cfg_file_lid;


 
// Add lid version information
# Define ap_assist_rdcl_hwmon_backup_assist_verno "000"


 
// Note that the location added to this table must match the location in custom_1__file_lid.
\ Mediatek \ custom \ $ project \ cgen \ Inc \ pai_file_info_custom.h
Const t1__file g_ak1__file_custom [] =
{
....
{"/Data/NVRAM/apcfg/aprdcl/hwmon_backup", Ver (ap_pai_rdcl_hwmon_backup_lid), pai_file_hwmon_backup_size,
Performance_file_hwmon_backup_total, signle_defualt_rec, (char *) & st_hwmon_backup_default, datareset, null
},
};


 
// Information to be read by meta Tool
\ Mediatek \ custom \ $ project \ cgen \ Inc \ custom_nvram_data_item.h
Pai_bit ver_lid (ap_pai_rdcl_hwmon_backup_lid)
Hwmon_backup_struct * resource_file_hwmon_backup_total
{
};


 
4. Add NVRAM to product_info
JB: \ mediatek \ custom \ common \ cgen \ pai_file_info.c
KK: \ mediatek \ external \ NVRAM \ libcustom_nvram \ pai_file_info.c
Const table_for_special_lid g_new_nvram_lid [] =
{
{Ap_pai_reeb_product_info_lid, 0, 1024*1024 },
{Ap_pai_rdcl_hwmon_backup_lid, 1024*1024,102 4*1024 },
};
 
5. Code for Backup Recovery




\ Mediatek \ external \ NVRAM \ libnvram_daemon_callback \ libnvram_daemon_callback.c
Int my_callback (void)
{
Alogd ("NVRAM daemon callback will run !!! ");
My_nvram_daemon (); // Add
Return 0;
}


 


Int my_nvram_daemon (void)
{
Int err = 0, ret = 0;
F_id FD;
Int rec_size, rec_num;
Hwmon_backup_struct hwmon_backup;


Nvram_log ("ready to read hwmon backup \ n ");
 
/* Read the hwmon backup data */
FD = nvm_getfiledesc (ap_pai_rdcl_hwmon_backup_lid, & rec_size, & rec_num, isread );
If (FD. ifiledesc <0)
{
Nvram_log ("null hwmon backup file handle pointer: % d! \ N ", FD. ifiledesc );
Err =-efault;
Return err;
}


Ret = read (FD. ifiledesc, & hwmon_backup, (rec_size * rec_num ));
If (Ret <0)
{
Nvram_log ("read hwmon backup file error: % d! \ N ", RET );
Err =-efault;
}
 
Nvm_closefiledesc (FD );


Nvram_log ("hwmon backup data, hwmon_acc: % d-% d \ n", region [0], hwmon_backup.hwmon_acc.offset [1], hwmon_backup.hwmon_acc.offset [2]);


/* Set the hwmon ACC data */
FD = nvm_getfiledesc (ap_assist_rdcl_hwmon_acc_lid, & rec_size, & rec_num, iswrite );


Ret = write (FD. ifiledesc, & hwmon_backup.hwmon_acc, (rec_size * rec_num ));


Nvm_closefiledesc (FD );


Nvram_log ("hwmon backup data, hwmon_gyro: % d-% d \ n", region [0], hwmon_backup.hwmon_gyro.offset [1], hwmon_backup.hwmon_gyro.offset [2]);


/* Set the hwmon gyro data */
FD = nvm_getfiledesc (ap_assist_rdcl_hwmon_gyro_lid, & rec_size, & rec_num, iswrite );


Ret = write (FD. ifiledesc, & hwmon_backup.hwmon_gyro, (rec_size * rec_num ));


Nvm_closefiledesc (FD );


Nvram_log ("hwmon backup data, hwmon_ps: % d-% d \ n", records [0], hwmon_backup.hwmon_ps.ps_cali [1], records [2]);


/* Set the hwmon PS data */
FD = nvm_getfiledesc (ap_pai_rdcl_hwmon_ps_lid, & rec_size, & rec_num, iswrite );


Ret = write (FD. ifiledesc, & hwmon_backup.hwmon_ps, (rec_size * rec_num ));


Nvm_closefiledesc (FD );


Return err;
}


7. Sensor calibration Customization
Backup of the sensor calibration data is implemented here. However, to save the calibration data of a specific sensor, you need to save the data to ap_pai_rdcl_hwmon_backup_lid at the same time. Otherwise, the backup is invalid.

Sensor calibration data in normal mode, restore factory settings, no loss

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.