Esempio n. 1
0
u32_t file_vir2sec(u32_t vsec)
/* Translate a virtual sector number to an absolute disk sector. */
{
	off_t blk;

	if(!block_size) { errno = 0;  return -1; }

	if ((blk= r_vir2abs(vsec / RATIO(block_size))) == -1) {
		errno= EIO;
		return -1;
	}
	return blk == 0 ? 0 : lowsec + blk * RATIO(block_size) + vsec % RATIO(block_size);
}
PRIVATE void print_ratio
(
    char *what,
    char *format,
    double estimate,
    double actual
)
{
    if (estimate < 0 && actual < 0)	/* double relop, but ignore Nan case */
    {
	return ;
    }
    PRINTF (("    %-27s", what)) ;
    if (estimate >= 0)			/* double relop, but ignore Nan case */
    {
	PRINTF ((format, estimate)) ;
    }
    else
    {
	PRINTF (("                    -")) ;
    }
    if (actual >= 0)			/* double relop, but ignore Nan case */
    {
	PRINTF ((format, actual)) ;
    }
    else
    {
	PRINTF (("                    -")) ;
    }
    if (estimate >= 0 && actual >= 0)	/* double relop, but ignore Nan case */
    {
	PRINTF ((" %5.0f%%\n", 100 * RATIO (actual, estimate, 1))) ;
    }
    else
    {
	PRINTF (("      -\n")) ;
    }
}
static int sci_adc_ratio(int channel, int scale, int mux)
{
	switch (channel) {
	case ADC_CHANNEL_0:
	case ADC_CHANNEL_1:
	case ADC_CHANNEL_2:
	case ADC_CHANNEL_3:
		return (scale ? RATIO(400, 1025) : RATIO(1, 1));
	case ADC_CHANNEL_VBAT:		//vbat
	case ADC_CHANNEL_ISENSE:
		return RATIO(7, 29);
	case ADC_CHANNEL_DCDCCORE:		//dcdccore
	case ADC_CHANNEL_DCDCARM:		//dcdcarm
		return (scale ? RATIO(4, 5) : RATIO(1, 1));
	case ADC_CHANNEL_DCDCMEM:		//dcdcmem
		return (scale ? RATIO(3, 5) : RATIO(4, 5));
	case ADC_CHANNEL_DCDCLDO:	//dcdcgen
		return RATIO(4, 9);
	case 0x14 /* ADC_CHANNEL_HEADMIC */:	//DCDCHEADMIC
		return (scale ? RATIO(1, 3) : RATIO(1, 1));
	case ADC_CHANNEL_LDO0:		//DCDC Supply LDO, VDD18/CAMIO/CAMD/EMMCIO
		return RATIO(1, 2);
	case ADC_CHANNEL_VBATBK:	//DCDCVBATBK
	case ADC_CHANNEL_LDO1:		//VBATD Domain LDO, VDD25/SD/USB/SIM0/SIM1/SIM2
	case ADC_CHANNEL_LDO2:		//VBATA Domain LDO,  VDD28/CAMA/CAMMOT/EMMCCORE/CON/DCXO/RF0
	case ADC_CHANNEL_USBDP:		//DP from terminal
	case ADC_CHANNEL_USBDM:		//DM from terminal
		return RATIO(1, 3);

	default:
		return RATIO(1, 1);
	}
	return RATIO(1, 1);
}