I am concerned with having a 25 x delay(1) in the refresh.
Is possible to do the measurement startup -- then schedule a task
to pick up the results?
> +void
> +imxtemp_refresh_sensors(void *arg)
> +{
> + struct imxtemp_softc *sc = (struct imxtemp_softc *)arg;
> + uint32_t value;
> + uint32_t temp_cnt;
> + int i;
> +
> + /* Power on temperature sensor. */
> + HCLR4(sc, TEMPMON_TEMPSENSE0, TEMPMON_TEMPSENSE0_POWER_DOWN);
> + HSET4(sc, TEMPMON_TEMPSENSE0, TEMPMON_TEMPSENSE0_MEASURE_TEMP);
> +
> + /* It may require up to ~17us to complete a measurement. */
> + for (i = 0; i < 25; i++) {
> + delay(1);
> + value = HREAD4(sc, TEMPMON_TEMPSENSE0);
> + if (value & TEMPMON_TEMPSENSE0_FINISHED)
> + break;
> + }
> +
> + /* Power down temperature sensor. */
> + HCLR4(sc, TEMPMON_TEMPSENSE0, TEMPMON_TEMPSENSE0_MEASURE_TEMP);
> + HSET4(sc, TEMPMON_TEMPSENSE0, TEMPMON_TEMPSENSE0_POWER_DOWN);
> +
> + if ((value & TEMPMON_TEMPSENSE0_FINISHED) == 0) {
> + sc->sc_sensor.flags |= SENSOR_FINVALID;
> + return;
> + }
> +
> + temp_cnt = (value >> TEMPMON_TEMPSENSE0_TEMP_CNT_SHIFT) &
> + TEMPMON_TEMPSENSE0_TEMP_CNT_MASK;
> + sc->sc_sensor.value = imxtemp_calc_temp(sc, temp_cnt) + 273150000;
> + sc->sc_sensor.flags &= ~SENSOR_FINVALID;
> +}
>