Example #1
0
/*!
 * \brief Adds data to local gatherer structure.
 *
 * \param stat Current stat variable.
 *
 * \retval 0 on success.
 * \retval -1 on memory error.
 */
static int stat_gatherer_add_data(stat_t *stat)
{
	/* TODO IPv6*/
	uint index = return_index(stat->s_addr, stat->protocol);
	if (!local_gath->freq_array[index]) {
		char addr[24];
		inet_ntop(AF_INET, &stat->s_addr->sin_addr, addr, 24);
		flow_data_t *tmp;
		tmp = malloc(sizeof(flow_data_t));
		if (tmp == NULL) {
			ERR_ALLOC_FAILED;
			return -1;
		}
		tmp->addr = malloc(sizeof(char) * 24);
		if (tmp->addr == NULL) {
			ERR_ALLOC_FAILED;
			return -1;
		}
		strcpy(tmp->addr, addr);
		tmp->port = stat->s_addr->sin_port;
		tmp->protocol = stat->protocol;
		local_gath->flow_array[index] = tmp;
	}

	//TODO add a check here, whether hashing fction performs well enough

	local_gath->freq_array[index] += 1;

	return 0;
}
static int adc_map_pmu_temp(struct bcmpmu_adc *padc, int adc,
						enum bcmpmu_adc_sig sig) {

	const struct bcmpmu_temp_map *pmu_temp_map;
						/*PMU Temperature Sensor map*/
	int delta = 0;
	int pmu_temp = 0; /* PMU Temperature */
	int index = 0;

	pmu_temp_map = padc->pmu_temp_map;
	if (pmu_temp_map == NULL) {
		pr_hwmon(ERROR, "%s pmu_temp_map is NULL\n", __func__);
		return -EINVAL;
	}
	index = return_index(pmu_temp_map, padc->ptmap_len, adc);
	delta = adc - pmu_temp_map[index].adc;
	pmu_temp = pmu_temp_map[index].temp + (delta/2);
	pr_hwmon(DATA, "%s adc-r = %d adc = %d, temp = %d pmu_temp = %d\n",
						__func__, adc,
						pmu_temp_map[index].adc,
						pmu_temp_map[index].temp,
						pmu_temp);

	return pmu_temp;

}
Example #3
0
static int bcmpmu_adc_raw_to_actual(struct bcmpmu_adc *adc,
				enum bcmpmu_adc_channel channel,
					struct bcmpmu_adc_result *result)

{
	struct bcmpmu_adc_lut *lut;
	int index = 0;
	int len = 0;

	if (adc->pdata[channel].lut) {
		len = adc->pdata[channel].lut_len;
		lut = adc->pdata[channel].lut;
		index = return_index(lut, len, result->raw);
		if (result->raw < lut[0].raw ||
					result->raw > lut[len - 1].raw) {
			pr_hwmon(ERROR, "ADC out of range, raw = %d\n",
								result->raw);
			result->conv = 0;
			return -EINVAL;
		}
		result->conv = INTERPOLATE_LINEAR(result->raw,
					lut[index].raw, lut[index].map,
					lut[index + 1].raw, lut[index + 1].map);

		pr_hwmon(FLOW, "index = %d, raw = %d, map = %d\n",
				index, lut[index].raw, lut[index].map);
		pr_hwmon(FLOW, "%s channel:%d raw = %x conv_lut = %d\n",
				__func__, channel, result->raw, result->conv);
		return 0;
	}
	if (channel != PMU_ADC_CHANN_DIE_TEMP) {
		result->conv = (result->raw * adc->pdata[channel].volt_range) /
					BCMPMU_ADC_RESOLUTION +
					(adc->pdata[channel].adc_offset);
	} else {
		/* temp = raw * 0.497 - 275.7 C
		 * But for better precision below formulae
		 * gives the result in 10th multiple of Centigrade*/
		result->conv = ((result->raw * PMU_TEMP_MULTI_CONST) -
					(KELVIN_CONST * 1000)) / 100;
	}

	pr_hwmon(FLOW, "%s channel:%d raw = %x conv_formula = %d\n",
			__func__, channel, result->raw, result->conv);
	return 0;
}