drivers/sensor/dht/dht.c
/**
 * @brief Measure duration of signal send by sensor
 *
 * @param drv_data Pointer to the driver data structure
 * @param signal_val Value of signal being measured
 *
 * @return duration in usec of signal being measured,
 *         -1 if duration exceeds DHT_SIGNAL_MAX_WAIT_DURATION
 */
@brief Measure duration of signal send by sensor
@param drv_data Pointer to the driver data structure
@param signal_val Value of signal being measured

@return duration in usec of signal being measured,
-1 if duration exceeds DHT_SIGNAL_MAX_WAIT_DURATION
@brief Measure duration of signal send by sensor @param drv_data Pointer to the driver data structure @param signal_val Value of signal being measured @return duration in usec of signal being measured - 1 if duration exceeds DHT_SIGNAL_MAX_WAIT_DURATION
static s8_t dht_measure_signal_duration(struct dht_data *drv_data,
					  u32_t signal_val)
{
	u32_t val;
	u32_t elapsed_cycles;
	u32_t max_wait_cycles = (u32_t)(
		(u64_t)DHT_SIGNAL_MAX_WAIT_DURATION *
		(u64_t)sys_clock_hw_cycles_per_sec /
		(u64_t)USEC_PER_SEC
	);
	u32_t start_cycles = k_cycle_get_32();
	do {
		gpio_pin_read(drv_data->gpio, CONFIG_DHT_GPIO_PIN_NUM, &val);
		elapsed_cycles = k_cycle_get_32() - start_cycles;
		if (elapsed_cycles >= max_wait_cycles) {
			return -1;
		}
	} while (val == signal_val);
	return (u64_t)elapsed_cycles *
	       (u64_t)USEC_PER_SEC /
	       (u64_t)sys_clock_hw_cycles_per_sec;
}
static s8_t dht_measure_signal_duration ( struct dht_data * drv_data , u32_t signal_val ) { u32_t val ; u32_t elapsed_cycles ; u32_t max_wait_cycles = ( u32_t ) ( ( u64_t ) DHT_SIGNAL_MAX_WAIT_DURATION * ( u64_t ) sys_clock_hw_cycles_per_sec / ( u64_t ) USEC_PER_SEC ) ; u32_t start_cycles = k_cycle_get_32 ( ) ; do { gpio_pin_read ( drv_data -> gpio , CONFIG_DHT_GPIO_PIN_NUM , & val ) ; elapsed_cycles = k_cycle_get_32 ( ) - start_cycles ; if ( elapsed_cycles >= max_wait_cycles ) { return -1 ; } } while ( val == signal_val ) ; return ( u64_t ) elapsed_cycles * ( u64_t ) USEC_PER_SEC / ( u64_t ) sys_clock_hw_cycles_per_sec ; }
@brief Measure duration of signal send by sensor
 @param drv_data Pointer to the driver data structure
 @param signal_val Value of signal being measured
@brief Measure duration of signal send by sensor @param drv_data Pointer to the driver data structure @param signal_val Value of signal being measured