product/juno/module/juno_pvt/src/mod_juno_pvt.c
static int process_pvt_calibration(struct pvt_sub_dev_ctx *sensor_ctx,
                                   uint16_t cal_45C,
                                   uint16_t cal_85C)
{
    unsigned int freq_45;
    unsigned int freq_85;
    unsigned int freq_fs;
    unsigned int sample_window;
    int freq_b;
    int slope_m;

    if ((cal_45C == 0) || (cal_85C == 0)) {
        return FWK_E_PARAM;
    }

    /* Convert into kHz */
    freq_45 = (unsigned int)(cal_45C * 10);
    freq_85 = (unsigned int)(cal_85C * 10);

    /* Find the slope */
    slope_m = (int)((freq_85 - freq_45) / (85 - 45));
    if (!fwk_expect(slope_m != 0)) {
        return FWK_E_PARAM;
    }

    /* Find the intercept of the line */
    freq_b = (int)(freq_85 - (slope_m * 85));

    /* Use line equation to find full-scale frequency */
    freq_fs = (unsigned int)((slope_m * FULL_SCALE_TEMP) + freq_b);

    /*
     * freq_fs must always be bigger than or equal to REFCLK_KHZ or
     * sample_window calculation won't work.
     */
    if (freq_fs < REFCLK_KHZ) {
        return FWK_E_RANGE;
    }

    /* Calculate sample window to fit the full scale reading */
    sample_window = (SAMPLE_WINDOW_MASK * REFCLK_KHZ) / freq_fs;
    if (sample_window > SAMPLE_WINDOW_MASK) {
        return FWK_E_PARAM;
    }

    /* Store constants for run-time calculations */
    sensor_ctx->slope_m = slope_m;
    sensor_ctx->freq_b = freq_b;
    sensor_ctx->sample_window = sample_window;

    return FWK_SUCCESS;
}
/*
 * For the temperature-based sensors, there are two calibration points:
 * 45 degrees C and 85 degrees C
 *
 * The maths in this function considers temperature on the X-axis and
 * sensor readings on the Y-axis.
 */
For the temperature-based sensors, there are two calibration points:
45 degrees C and 85 degrees C

The maths in this function considers temperature on the X-axis and
sensor readings on the Y-axis.
For the temperature - based sensors there are two calibration points : 45 degrees C and 85 degrees C The maths in this function considers temperature on the X - axis and sensor readings on the Y - axis .
static int process_pvt_calibration(struct pvt_sub_dev_ctx *sensor_ctx,
                                   uint16_t cal_45C,
                                   uint16_t cal_85C)
{
    unsigned int freq_45;
    unsigned int freq_85;
    unsigned int freq_fs;
    unsigned int sample_window;
    int freq_b;
    int slope_m;
    if ((cal_45C == 0) || (cal_85C == 0)) {
        return FWK_E_PARAM;
    }
    freq_45 = (unsigned int)(cal_45C * 10);
    freq_85 = (unsigned int)(cal_85C * 10);
    slope_m = (int)((freq_85 - freq_45) / (85 - 45));
    if (!fwk_expect(slope_m != 0)) {
        return FWK_E_PARAM;
    }
    freq_b = (int)(freq_85 - (slope_m * 85));
    freq_fs = (unsigned int)((slope_m * FULL_SCALE_TEMP) + freq_b);
    if (freq_fs < REFCLK_KHZ) {
        return FWK_E_RANGE;
    }
    sample_window = (SAMPLE_WINDOW_MASK * REFCLK_KHZ) / freq_fs;
    if (sample_window > SAMPLE_WINDOW_MASK) {
        return FWK_E_PARAM;
    }
    sensor_ctx->slope_m = slope_m;
    sensor_ctx->freq_b = freq_b;
    sensor_ctx->sample_window = sample_window;
    return FWK_SUCCESS;
}
static int process_pvt_calibration ( struct pvt_sub_dev_ctx * sensor_ctx , uint16_t cal_45C , uint16_t cal_85C ) { unsigned int freq_45 ; unsigned int freq_85 ; unsigned int freq_fs ; unsigned int sample_window ; int freq_b ; int slope_m ; if ( ( cal_45C == 0 ) || ( cal_85C == 0 ) ) { return FWK_E_PARAM ; } freq_45 = ( unsigned int ) ( cal_45C * 10 ) ; freq_85 = ( unsigned int ) ( cal_85C * 10 ) ; slope_m = ( int ) ( ( freq_85 - freq_45 ) / ( 85 - 45 ) ) ; if ( ! fwk_expect ( slope_m != 0 ) ) { return FWK_E_PARAM ; } freq_b = ( int ) ( freq_85 - ( slope_m * 85 ) ) ; freq_fs = ( unsigned int ) ( ( slope_m * FULL_SCALE_TEMP ) + freq_b ) ; if ( freq_fs < REFCLK_KHZ ) { return FWK_E_RANGE ; } sample_window = ( SAMPLE_WINDOW_MASK * REFCLK_KHZ ) / freq_fs ; if ( sample_window > SAMPLE_WINDOW_MASK ) { return FWK_E_PARAM ; } sensor_ctx -> slope_m = slope_m ; sensor_ctx -> freq_b = freq_b ; sensor_ctx -> sample_window = sample_window ; return FWK_SUCCESS ; }
For the temperature-based sensors, there are two calibration points:
 45 degrees C and 85 degrees C
For the temperature - based sensors there are two calibration points : 45 degrees C and 85 degrees C
/* Convert into kHz */ /* Find the slope */ /* Find the intercept of the line */ /* Use line equation to find full-scale frequency */ /*
     * freq_fs must always be bigger than or equal to REFCLK_KHZ or
     * sample_window calculation won't work.
     */ /* Calculate sample window to fit the full scale reading */ /* Store constants for run-time calculations */