modules/batt_health/nvm.c
static bool nvm_file_write(int fd, bhd_state_t *state)
{
	bool is_success = false;
	ssize_t r;
	nvm_file_hdr_t hdr;
	nvm_file_data_ver_0_t data;

	/* Populate header, always use latest version */
	hdr.version = NVM_FILE_HEADER_VERSION_1;
	hdr.timestamp = time(NULL);
	hdr.file_write_count = state->file_write_count;
	strcpy(hdr.text, NVM_HDR_TEXT);

	/* Populate data section */
	data.real_fcc_batt_temp = state->bms.real_fcc_batt_temp;
	data.real_fcc_mah = state->bms.real_fcc_mah;
	data.soc = state->bms.soc;
	data.ocv_uv = state->bms.ocv_uv;
	data.rbatt = state->bms.rbatt;
	data.charge_increase = state->bms.charge_increase;
	data.chargecycles = state->bms.chargecycles;
	data.aged_capacity = state->aged_capacity;
	data.aged_timestamp = state->eoc.aged_timestamp;
	data.boc_percent = state->eoc.boc_percent;
	data.boc_ocv_uv = state->eoc.boc_ocv_uv;
	data.boc_cc_uah = state->eoc.boc_cc_uah;
	data.eoc_percent = state->eoc.eoc_percent;
	data.eoc_ocv_uv = state->eoc.eoc_ocv_uv;
	data.eoc_cc_uah = state->eoc.eoc_cc_uah;

	r = write(fd, &hdr, sizeof(hdr));
	if (r != sizeof(hdr))
		ALOGE("NVM Write - Failed to file header, r = %lu, errno = %d (%s)",
			r, errno, strerror(errno));
	else {
		r = write(fd, &data, sizeof(data));
		if (r != sizeof(data))
			ALOGE("NVM Write - Failed to write file data, r = %lu, errno = %d (%s)",
				r, errno, strerror(errno));
		else {
			is_success = true;
			ALOGV("NVM Write - File write count = %llu, timestamp = %s",
				hdr.file_write_count, ctime(&hdr.timestamp));
			ALOGV("NVM Write - OCV = %d, rbatt = %d", data.ocv_uv, data.rbatt);
			ALOGV("NVM Write - Charge %% increase = %d, charge cycles = %d",
				data.charge_increase, data.chargecycles);
			ALOGV("NVM Write - Aged capacity = %d, Calculated @ %s",
				data.aged_capacity, ctime(&data.aged_timestamp));
			ALOGV("NVM Write - BOC percent = %d, ocv = %d, cc = %d",
				data.boc_percent, data.boc_ocv_uv, data.boc_cc_uah);
			ALOGV("NVM Write - EOC percent = %d, ocv = %d, cc = %d",
				data.eoc_percent, data.eoc_ocv_uv, data.eoc_cc_uah);
		}
	}
	return is_success;
}
/* Writes battery health file to NVM */
Writes battery health file to NVM
Writes battery health file to NVM
static bool nvm_file_write(int fd, bhd_state_t *state)
{
	bool is_success = false;
	ssize_t r;
	nvm_file_hdr_t hdr;
	nvm_file_data_ver_0_t data;
	hdr.version = NVM_FILE_HEADER_VERSION_1;
	hdr.timestamp = time(NULL);
	hdr.file_write_count = state->file_write_count;
	strcpy(hdr.text, NVM_HDR_TEXT);
	data.real_fcc_batt_temp = state->bms.real_fcc_batt_temp;
	data.real_fcc_mah = state->bms.real_fcc_mah;
	data.soc = state->bms.soc;
	data.ocv_uv = state->bms.ocv_uv;
	data.rbatt = state->bms.rbatt;
	data.charge_increase = state->bms.charge_increase;
	data.chargecycles = state->bms.chargecycles;
	data.aged_capacity = state->aged_capacity;
	data.aged_timestamp = state->eoc.aged_timestamp;
	data.boc_percent = state->eoc.boc_percent;
	data.boc_ocv_uv = state->eoc.boc_ocv_uv;
	data.boc_cc_uah = state->eoc.boc_cc_uah;
	data.eoc_percent = state->eoc.eoc_percent;
	data.eoc_ocv_uv = state->eoc.eoc_ocv_uv;
	data.eoc_cc_uah = state->eoc.eoc_cc_uah;
	r = write(fd, &hdr, sizeof(hdr));
	if (r != sizeof(hdr))
		ALOGE("NVM Write - Failed to file header, r = %lu, errno = %d (%s)",
			r, errno, strerror(errno));
	else {
		r = write(fd, &data, sizeof(data));
		if (r != sizeof(data))
			ALOGE("NVM Write - Failed to write file data, r = %lu, errno = %d (%s)",
				r, errno, strerror(errno));
		else {
			is_success = true;
			ALOGV("NVM Write - File write count = %llu, timestamp = %s",
				hdr.file_write_count, ctime(&hdr.timestamp));
			ALOGV("NVM Write - OCV = %d, rbatt = %d", data.ocv_uv, data.rbatt);
			ALOGV("NVM Write - Charge %% increase = %d, charge cycles = %d",
				data.charge_increase, data.chargecycles);
			ALOGV("NVM Write - Aged capacity = %d, Calculated @ %s",
				data.aged_capacity, ctime(&data.aged_timestamp));
			ALOGV("NVM Write - BOC percent = %d, ocv = %d, cc = %d",
				data.boc_percent, data.boc_ocv_uv, data.boc_cc_uah);
			ALOGV("NVM Write - EOC percent = %d, ocv = %d, cc = %d",
				data.eoc_percent, data.eoc_ocv_uv, data.eoc_cc_uah);
		}
	}
	return is_success;
}
static bool nvm_file_write ( int fd , bhd_state_t * state ) { bool is_success = false ; ssize_t r ; nvm_file_hdr_t hdr ; nvm_file_data_ver_0_t data ; hdr . version = NVM_FILE_HEADER_VERSION_1 ; hdr . timestamp = time ( NULL ) ; hdr . file_write_count = state -> file_write_count ; strcpy ( hdr . text , NVM_HDR_TEXT ) ; data . real_fcc_batt_temp = state -> bms . real_fcc_batt_temp ; data . real_fcc_mah = state -> bms . real_fcc_mah ; data . soc = state -> bms . soc ; data . ocv_uv = state -> bms . ocv_uv ; data . rbatt = state -> bms . rbatt ; data . charge_increase = state -> bms . charge_increase ; data . chargecycles = state -> bms . chargecycles ; data . aged_capacity = state -> aged_capacity ; data . aged_timestamp = state -> eoc . aged_timestamp ; data . boc_percent = state -> eoc . boc_percent ; data . boc_ocv_uv = state -> eoc . boc_ocv_uv ; data . boc_cc_uah = state -> eoc . boc_cc_uah ; data . eoc_percent = state -> eoc . eoc_percent ; data . eoc_ocv_uv = state -> eoc . eoc_ocv_uv ; data . eoc_cc_uah = state -> eoc . eoc_cc_uah ; r = write ( fd , & hdr , sizeof ( hdr ) ) ; if ( r != sizeof ( hdr ) ) ALOGE ( " " , r , errno , strerror ( errno ) ) ; else { r = write ( fd , & data , sizeof ( data ) ) ; if ( r != sizeof ( data ) ) ALOGE ( " " , r , errno , strerror ( errno ) ) ; else { is_success = true ; ALOGV ( " " , hdr . file_write_count , ctime ( & hdr . timestamp ) ) ; ALOGV ( " " , data . ocv_uv , data . rbatt ) ; ALOGV ( " " , data . charge_increase , data . chargecycles ) ; ALOGV ( " " , data . aged_capacity , ctime ( & data . aged_timestamp ) ) ; ALOGV ( " " , data . boc_percent , data . boc_ocv_uv , data . boc_cc_uah ) ; ALOGV ( " " , data . eoc_percent , data . eoc_ocv_uv , data . eoc_cc_uah ) ; } } return is_success ; }
Writes battery health file to NVM
Writes battery health file to NVM
/* Populate header, always use latest version */ /* Populate data section */