Chirp SonicLib  4.5.2
Classes | Macros | Typedefs | Enumerations | Functions
soniclib.h File Reference

SonicLib public API and support functions for TDK/InvenSense ultrasonic sensors (originally developed by Chirp Microsystems). More...

#include "chirp_board_config.h"
#include <invn/icu_interface/shasta_external_regs.h>
#include <invn/soniclib/details/icu.h>
#include <invn/icu_interface/icu_algo_info.h>
#include <invn/soniclib/details/ch_driver.h>
#include <invn/soniclib/details/ch_math_utils.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  ch_amp_thresh_t
 Sensor combined amplitude + detection threshold sample value. More...
 
struct  ch_api_funcs_t
 API function pointer structure (internal use). More...
 
struct  ch_cal_result_t
 Calibration result structure. More...
 
struct  ch_calib_funcs_t
 
struct  ch_clock_cal_t
 Clock calibration values. More...
 
struct  ch_config_t
 Combined configuration structure. More...
 
struct  ch_dev_t
 Chirp sensor device descriptor structure. More...
 
struct  ch_group_t
 Chirp sensor group descriptor structure. More...
 
struct  ch_i2c_info_t
 I2C info structure. More...
 
struct  ch_iq_sample_t
 Sensor I/Q data value. More...
 
struct  ch_log_cfg_t
 Log configuration structure. More...
 
struct  ch_log_data_t
 Log data structure. More...
 
struct  ch_meas_config_t
 Measurement configuration - used during ch_meas_init() More...
 
struct  ch_meas_info_t
 Measurement info. More...
 
struct  ch_meas_queue_info_t
 Measurement queue info. More...
 
struct  ch_meas_seg_info_t
 Measurement segment info. More...
 
struct  ch_meas_segment_t
 Measurement segment. More...
 
struct  ch_mfg_info_t
 Sensor manufacturing info. More...
 
struct  ch_output_t
 Data output structure. More...
 
struct  ch_thresh_t
 Detection threshold value. More...
 
struct  ch_version_t
 SonicLib version structure. More...
 
struct  fw_info_st
 

Macros

#define CH101_MAX_NUM_SAMPLES   (225)
 
#define CH101_PART_NUMBER   (101)
 
#define CH201_MAX_NUM_SAMPLES   (450)
 
#define CH201_PART_NUMBER   (201)
 
#define CH_DEFAULT_MEAS_NUM   (0)
 
#define CH_DEFAULT_TARGET_NUM   (0)
 
#define CH_I2C_ADDR_PROG   (0x45)
 
#define CH_MAX_NUM_TARGETS   (1)
 
#define CH_MEAS_MAX_MEAS   (MEAS_QUEUE_MAX_MEAS)
 
#define CH_MEAS_MAX_SEGMENTS   (INST_BUF_LENGTH)
 
#define CH_MIN_RANGE_VAL   (0x0001)
 
#define CH_NO_TARGET   (0xFFFFFFFF)
 
#define CH_OP_FREQ_USE_AVG   (0)
 
#define CH_PMUT_TICKS_PER_CYCLE   (16)
 
#define CH_RTC_FREQ_TYPICAL   (29000)
 
#define CH_RTC_USE_BUS_SPEED   (UINT16_MAX)
 
#define CH_SENSOR_ID_LENGTH   8
 
#define CH_SIG_BYTE_0   (0x0a)
 
#define CH_SIG_BYTE_1   (0x02)
 
#define CH_SPEEDOFSOUND_MPS   (343)
 
#define CH_TARGET_INT_HIST_DEFAULT   (5)
 
#define CH_TARGET_INT_HIST_MAX   (15)
 
#define CH_TARGET_INT_THRESH_DEFAULT   (3)
 
#define CH_WINDOW_MAX_SAMPLES   (64)
 
#define I2C_DRV_FLAG_RESET_AFTER_NB   (0x00000001)
 
#define I2C_DRV_FLAG_USE_PROG_NB   (0x00000002)
 
#define ICU10201_PART_NUMBER   (10201)
 
#define ICU20201_PART_NUMBER   (20201)
 
#define ICU30201_PART_NUMBER   (30201)
 
#define ICU_MAX_NUM_SAMPLES   (IQ_SAMPLES_MAX)
 
#define ICU_UNKNOWN_PART_NUMBER   (0)
 
#define MAX_NUM_SAMPLES   CH201_MAX_NUM_SAMPLES
 
#define MAX_NUM_SAMPLES   ICU_MAX_NUM_SAMPLES
 
#define SONICLIB_VER_MAJOR   (4)
 
#define SONICLIB_VER_MINOR   (5)
 
#define SONICLIB_VER_REV   (2)
 
#define SONICLIB_VER_SUFFIX   ""
 

Typedefs

typedef struct ch_dev_t ch_dev_t
 
typedef uint8_t(* ch_fw_init_func_t) (ch_dev_t *dev_ptr, fw_info_t **fw_info)
 ASIC firmware init function pointer typedef.
 
typedef uint16_t(* ch_get_amplitude_avg_func_t) (ch_dev_t *dev_ptr)
 
typedef uint8_t(* ch_get_amplitude_data_func_t) (ch_dev_t *dev_ptr, uint16_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t io_mode)
 
typedef uint16_t(* ch_get_amplitude_func_t) (ch_dev_t *dev_ptr)
 
typedef uint8_t(* ch_get_cal_result_func_t) (ch_dev_t *dev_ptr, ch_cal_result_t *cal_ptr)
 
typedef uint8_t(* ch_get_config_func_t) (ch_dev_t *dev_ptr, ch_config_t *config_ptr)
 API function pointer typedefs.
 
typedef uint8_t(* ch_get_data_ready_delay_func_t) (ch_dev_t *dev_ptr)
 
typedef uint8_t(* ch_get_iq_data_func_t) (ch_dev_t *dev_ptr, ch_iq_sample_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t io_mode)
 
typedef uint32_t(* ch_get_range_func_t) (ch_dev_t *dev_ptr, ch_range_t range_type)
 
typedef uint16_t(* ch_get_rx_low_gain_func_t) (ch_dev_t *dev_ptr)
 
typedef uint8_t(* ch_get_target_int_counter_func_t) (ch_dev_t *dev_ptr, uint8_t *meas_hist_ptr, uint8_t *thresh_count_ptr, uint8_t *reset_ptr)
 
typedef ch_tgt_int_filter_t(* ch_get_target_interrupt_func_t) (ch_dev_t *dev_ptr)
 
typedef uint16_t(* ch_get_tx_length_func_t) (ch_dev_t *dev_ptr)
 
typedef enum ch_group_status ch_group_status_t
 Sensor group status.
 
typedef struct ch_group_t ch_group_t
 
typedef void(* ch_io_complete_callback_t) (ch_group_t *grp_ptr)
 Non-blocking I/O complete callback routine pointer.
 
typedef void(* ch_io_int_callback_t) (ch_group_t *grp_ptr, uint8_t io_index, ch_interrupt_type_t int_type)
 Sensor interrupt callback routine pointer.
 
typedef ch_output_type_t(* ch_meas_get_iq_output_func_t) (ch_dev_t *dev_ptr, uint8_t meas_num)
 
typedef ch_meas_status_t(* ch_meas_get_status_func_t) (ch_dev_t *dev_ptr, uint8_t meas_num)
 
typedef uint8_t(* ch_meas_set_iq_output_func_t) (ch_dev_t *dev_ptr, uint8_t meas_num, ch_output_type_t output_format)
 
typedef uint16_t(* ch_mm_to_samples_func_t) (ch_dev_t *dev_ptr, uint16_t num_mm)
 
typedef uint8_t(* ch_set_cal_result_func_t) (ch_dev_t *dev_ptr, ch_cal_result_t *cal_ptr)
 
typedef uint8_t(* ch_set_config_func_t) (ch_dev_t *dev_ptr, ch_config_t *config_ptr)
 
typedef uint8_t(* ch_set_data_output_func_t) (ch_dev_t *dev_ptr, const ch_output_t *output)
 
typedef uint8_t(* ch_set_data_ready_delay_func_t) (ch_dev_t *dev_ptr, uint8_t num_cycles)
 
typedef uint8_t(* ch_set_frequency_func_t) (ch_dev_t *dev_ptr, uint32_t target_freq_Hz)
 
typedef uint8_t(* ch_set_num_samples_func_t) (ch_dev_t *dev_ptr, uint16_t num_samples)
 
typedef uint8_t(* ch_set_rx_low_gain_func_t) (ch_dev_t *dev_ptr, uint16_t num_samples)
 
typedef uint8_t(* ch_set_sample_window_func_t) (ch_dev_t *dev_ptr, uint16_t start_sample, uint16_t end_sample)
 
typedef uint8_t(* ch_set_target_int_counter_func_t) (ch_dev_t *dev_ptr, uint8_t meas_hist, uint8_t thresh_count, uint8_t reset)
 
typedef uint8_t(* ch_set_target_interrupt_func_t) (ch_dev_t *dev_ptr, ch_tgt_int_filter_t tgt_int_filter)
 
typedef uint8_t(* ch_set_tx_length_func_t) (ch_dev_t *dev_ptr, uint16_t tx_length)
 
typedef void(* ch_timer_callback_t) (void)
 Periodic timer callback routine pointer.
 
typedef void(* ch_trigger_soft_func_t) (ch_dev_t *dev_ptr)
 
typedef struct fw_info_st fw_info_t
 

Enumerations

enum  ch_asic_gen_t { CH_ASIC_GEN_1_WHITNEY = 1 , CH_ASIC_GEN_2_SHASTA = 2 }
 Sensor asic design generations. More...
 
enum  ch_decimation_t {
  CH_DECIMATION_0_25 = -2 , CH_DECIMATION_0_50 = -1 , CH_DECIMATION_NONE = 1 , CH_DECIMATION_2 = 2 ,
  CH_DECIMATION_3 = 3 , CH_DECIMATION_4 = 4
}
 Decimation factor.
 
enum  ch_group_status { CH_GROUP_STAT_NOT_INIT = 0 , CH_GROUP_STAT_INIT_PENDING = 1 , CH_GROUP_STAT_INIT_OK = 2 }
 Sensor group status. More...
 
enum  ch_interrupt_drive_t { CH_INTERRUPT_DRIVE_OPEN_DRAIN = 0 , CH_INTERRUPT_DRIVE_PUSH_PULL = 1 }
 Sensor interrupt drive type. More...
 
enum  ch_interrupt_mode_t { CH_INTERRUPT_MODE_PULSE = 0 , CH_INTERRUPT_MODE_LATCH = 1 }
 Sensor interrupt modes. More...
 
enum  ch_interrupt_type_t {
  CH_INTERRUPT_TYPE_UNKNOWN = INT_SRC_NONE , CH_INTERRUPT_TYPE_DATA_RDY = INT_SRC_DATA_RDY , CH_INTERRUPT_TYPE_MUT_FCOUNT = INT_SRC_MUT_FCOUNT_RDY , CH_INTERRUPT_TYPE_CPU_FCOUNT = INT_SRC_CPU_FCOUNT_RDY ,
  CH_INTERRUPT_TYPE_BIST_RDY = INT_SRC_BIST_RDY , CH_INTERRUPT_TYPE_TX_OPTIMIZE = INT_SRC_TX_OPTIMIZE , CH_INTERRUPT_TYPE_RTC_CAL_RDY = INT_SRC_RTC_CAL_RDY , CH_INTERRUPT_TYPE_OTP_COPY = INT_SRC_COPY_OTP_TO_RAM ,
  CH_INTERRUPT_TYPE_OTP_WR_STEP = INT_SRC_OTP_WR_STEP , CH_INTERRUPT_TYPE_WATCHDOG = INT_SRC_WDT_EXPIRY , CH_INTERRUPT_TYPE_PGM_LOADED = INT_SRC_PGM_LOADED , CH_INTERRUPT_TYPE_ALGO_ERROR = INT_SRC_ALGO_ERROR ,
  CH_INTERRUPT_TYPE_DEBUG = INT_SRC_DEBUG , CH_INTERRUPT_TYPE_ERROR = INT_SRC_ERROR
}
 Sensor interrupt types. More...
 
enum  ch_io_mode_t { CH_IO_MODE_BLOCK = 0 , CH_IO_MODE_NONBLOCK = 1 }
 I/O blocking mode flags. More...
 
enum  ch_log_fmt_t { CH_LOG_FMT_REDSWALLOW = 0 }
 Log format.
 
enum  ch_meas_mode_t { CH_MEAS_MODE_ACTIVE = 0 , CH_MEAS_MODE_STANDBY = 1 }
 Measurement mode (active / standby) More...
 
enum  ch_meas_seg_type_t { CH_MEAS_SEG_TYPE_COUNT = 0 , CH_MEAS_SEG_TYPE_TX = 1 , CH_MEAS_SEG_TYPE_RX = 2 , CH_MEAS_SEG_TYPE_EOF = 3 }
 Measurement segment type.
 
enum  ch_meas_status_t {
  CH_MEAS_STATUS_UNKNOWN = 0 , CH_MEAS_STATUS_INIT = 1 , CH_MEAS_STATUS_TX_OPT = 2 , CH_MEAS_STATUS_OK = 3 ,
  CH_MEAS_STATUS_PENDING = 4 , CH_MEAS_STATUS_DONE = 5
}
 Measurement status. More...
 
enum  ch_mode_t {
  CH_MODE_IDLE = 0x00 , CH_MODE_FREERUN = 0x02 , CH_MODE_TRIGGERED_TX_RX = 0x10 , CH_MODE_TRIGGERED_RX_ONLY = 0x20 ,
  CH_MODE_CONTINUOUS_RX = 0x40
}
 Sensor operating modes. More...
 
enum  ch_odr_t {
  CH_ODR_FREQ_DIV_32 = 2 , CH_ODR_FREQ_DIV_16 = 3 , CH_ODR_FREQ_DIV_8 = 4 , CH_ODR_FREQ_DIV_4 = 5 ,
  CH_ODR_FREQ_DIV_2 = 6 , CH_ODR_DEFAULT = CH_ODR_FREQ_DIV_8
}
 Sensor output data rate (ODR). More...
 
enum  ch_output_type_t { CH_OUTPUT_IQ = IQ_OUTPUT_NORMAL , CH_OUTPUT_AMP_THRESH = IQ_OUTPUT_MAG_THRESH , CH_OUTPUT_AMP = IQ_OUTPUT_MAG }
 Output type. More...
 
enum  ch_pmut_clk_cfg_t { CH_PMUT_CLK_DEFAULT = 0 , CH_PMUT_CLK_OUTPUT_ENABLE , CH_PMUT_CLK_SRC_EXTERNAL = 2 , CH_PMUT_CLK_OUTPUT_AUTO }
 PMUT clock configuration (ICU sensors) More...
 
enum  ch_prod_code_t { CH_PROD_CODE_ICU20201 = 1 , CH_PROD_CODE_ICU10201 = 2 , CH_PROD_CODE_ICU30201 = 3 , CH_PROD_CODE_UNKNOWN = 0xFF }
 Sensor product codes. More...
 
enum  ch_range_t { CH_RANGE_ECHO_ONE_WAY = 0 , CH_RANGE_ECHO_ROUND_TRIP = 1 , CH_RANGE_DIRECT = 2 }
 Range data types. More...
 
enum  ch_reset_t { CH_RESET_HARD = 0 , CH_RESET_SOFT = 1 }
 Sensor reset types. More...
 
enum  ch_retval { RET_OK = 0 , RET_ERR = 1 }
 Return value codes.
 
enum  ch_rtc_cal_t { CH_RTC_CAL_STD = 0 , CH_RTC_CAL_MANUAL = 1 , CH_RTC_CAL_BUS = 2 }
 Sensor real-time clock status. More...
 
enum  ch_rtc_src_t { CH_RTC_SRC_INTERNAL = 0 , CH_RTC_SRC_EXTERNAL = 1 }
 Sensor real-time clock sources. More...
 
enum  ch_rtc_status_t {
  CH_RTC_STATUS_INIT = 0 , CH_RTC_STATUS_CAL_DONE = 1 , CH_RTC_STATUS_CAL_FACTORY = 2 , CH_RTC_STATUS_CAL_ESTIMATED = 3 ,
  CH_RTC_STATUS_CAL_BUS = 4 , CH_RTC_STATUS_EXTERNAL = 5
}
 Sensor real-time clock status. More...
 
enum  ch_sensor_reset_state_t { CH_RESET_STATE_OK = 0 , CH_RESET_STATE_ACTIVE = 1 }
 Sensor reset state.
 
enum  ch_tgt_int_filter_t { CH_TGT_INT_FILTER_OFF = 0 , CH_TGT_INT_FILTER_ANY = 1 , CH_TGT_INT_FILTER_COUNTER = 4 }
 Target interrupt filter modes. More...
 
enum  ch_trigger_type_t { CH_TRIGGER_TYPE_HW = 0 , CH_TRIGGER_TYPE_SW = 1 }
 Sensor trigger types. More...
 

Functions

uint8_t ch_check_program (ch_dev_t *dev_ptr)
 Check sensor firmware program. More...
 
uint8_t ch_check_reset_state (ch_dev_t *dev_ptr, ch_sensor_reset_state_t *reset_state_ptr)
 Check if sensor reset has occurred. More...
 
uint16_t ch_cycles_to_samples (uint32_t num_cycles, ch_odr_t odr)
 Convert sensor cycles to samples. More...
 
uint32_t ch_cycles_to_usec (ch_dev_t *dev_ptr, uint32_t num_cycles)
 Convert sensor cycles to microseconds. More...
 
uint16_t ch_data_validation_check (ch_dev_t *dev_ptr, ch_iq_sample_t *data, uint16_t num_samples)
 Check data in validation mode, which should be enabled before calling this. Should be run over all IQ data received by the sensor after mode is enabled to keep the counters in sync. More...
 
uint8_t ch_enable_data_validation (ch_dev_t *dev_ptr, int16_t seed, uint8_t enable)
 Enable data validation mode. In this mode, ICU-x0201 sensors will overwrite the IQ data at the end of a measurement and after running the algorithm, with a known sequence to allow validating data transfer integrity while making minimal changes to the system otherwise. Currently, this is limited to a 16-bit counter that increments for each I and Q sample and is continuous across measurements. More...
 
uint8_t ch_enable_double_buffer (ch_dev_t *dev_ptr, uint8_t enable)
 Enable or disable the double buffering mode. More...
 
uint8_t ch_enable_metadata_in_iq0 (ch_dev_t *dev_ptr, uint8_t enable)
 Enable or disable placing metadata in the first IQ sample. More...
 
uint8_t ch_freerun_time_hop_disable (ch_dev_t *dev_ptr)
 Disable time-hopping on measure period freerunning mode. More...
 
uint8_t ch_freerun_time_hop_enable (ch_dev_t *dev_ptr)
 Enable time-hopping on measure period freerunning mode. More...
 
uint8_t ch_get_algo_config (ch_dev_t *dev_ptr, void *algo_cfg_ptr)
 Get the measurement algorithm configuration data from a sensor. More...
 
uint8_t ch_get_algo_info (ch_dev_t *dev_ptr, ICU_ALGO_SHASTA_INFO *algo_info_ptr)
 Get the measurement algorithm information data from a sensor. More...
 
uint8_t ch_get_algo_output (ch_dev_t *dev_ptr, void *algo_out_ptr)
 Get the measurement algorithm output data from a sensor. More...
 
uint8_t ch_get_algo_state (ch_dev_t *dev_ptr, void *algo_state_ptr)
 Get the measurement algorithm state data from a sensor. More...
 
uint8_t ch_get_amp_thresh_data (ch_dev_t *dev_ptr, ch_amp_thresh_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t mode)
 Get the amplitude measurement and threshold data from a sensor. More...
 
uint16_t ch_get_amplitude (ch_dev_t *dev_ptr)
 Get the measured amplitude from a sensor. More...
 
uint16_t ch_get_amplitude_avg (ch_dev_t *dev_ptr)
 Get the averaged measured amplitude over the sample window. More...
 
uint8_t ch_get_amplitude_data (ch_dev_t *dev_ptr, uint16_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t mode)
 Get the raw amplitude measurement data from a sensor. More...
 
uint16_t ch_get_bandwidth (ch_dev_t *dev_ptr)
 Get the bandwidth of a sensor. More...
 
uint8_t ch_get_bus (ch_dev_t *dev_ptr)
 Get the active SPI/I2C bus for a sensor. More...
 
uint8_t ch_get_cal_result (ch_dev_t *dev_ptr, ch_cal_result_t *cal_ptr)
 Get the calibration result. More...
 
uint8_t ch_get_config (ch_dev_t *dev_ptr, ch_config_t *config_ptr)
 Get current configuration settings for a sensor. More...
 
uint32_t ch_get_cpu_frequency (ch_dev_t *dev_ptr)
 Get the sensor CPU frequency, in Hz. More...
 
uint8_t ch_get_data_ready_delay (ch_dev_t *dev_ptr)
 Get data ready interrupt delay interval. More...
 
uint8_t ch_get_dev_num (ch_dev_t *dev_ptr)
 Get device number (I/O index values) for a sensor. More...
 
ch_dev_tch_get_dev_ptr (ch_group_t *grp_ptr, uint8_t dev_num)
 Get device descriptor pointer for a sensor. More...
 
uint16_t ch_get_freerun_interval (ch_dev_t *dev_ptr)
 Get the internal sensing timing interval for a sensor, in milliseconds. More...
 
uint16_t ch_get_freerun_interval_ticks (ch_dev_t *dev_ptr)
 Get the internal sensing timing interval for a sensor, in RTC clock ticks. More...
 
uint32_t ch_get_freerun_interval_us (ch_dev_t *dev_ptr)
 Get the internal sensing timing interval for a sensor, in microseconds. More...
 
uint32_t ch_get_frequency (ch_dev_t *dev_ptr)
 Get the operating frequency of a sensor. More...
 
const char * ch_get_fw_version_string (ch_dev_t *dev_ptr)
 Get the firmware version description string for a sensor. More...
 
uint8_t ch_get_i2c_address (ch_dev_t *dev_ptr)
 Get the active I2C address for a sensor. More...
 
ch_interrupt_drive_t ch_get_interrupt_drive (ch_dev_t *dev_ptr)
 Get the pulse interrupt drive setting. More...
 
ch_interrupt_mode_t ch_get_interrupt_mode (ch_dev_t *dev_ptr)
 Get the pulse interrupt mode setting. More...
 
uint8_t ch_get_iq_data (ch_dev_t *dev_ptr, ch_iq_sample_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t mode)
 Get the raw I/Q measurement data from a sensor. More...
 
uint16_t ch_get_max_range (ch_dev_t *dev_ptr)
 Get the maximum range setting in mm for a sensor. More...
 
uint16_t ch_get_max_samples (ch_dev_t *dev_ptr)
 Get the maximum possible sample count per measurement. More...
 
uint8_t ch_get_mfg_info (ch_dev_t *dev_ptr, ch_mfg_info_t *info_ptr)
 Get manufacturing information for a sensor. More...
 
ch_mode_t ch_get_mode (ch_dev_t *dev_ptr)
 Get the current operating mode for a sensor. More...
 
uint16_t ch_get_next_buf_addr (ch_dev_t *dev_ptr)
 Get the address of the IQ buffer that will be written by the next measurement. More...
 
uint16_t ch_get_num_output_samples (ch_dev_t *dev_ptr)
 Get the number of valid output samples in last measurement. More...
 
uint8_t ch_get_num_ports (ch_group_t *grp_ptr)
 Get the total number of sensor ports (possible sensors) in a sensor group. More...
 
uint16_t ch_get_num_samples (ch_dev_t *dev_ptr)
 Get the number of samples per measurement cycle. More...
 
uint16_t ch_get_part_number (ch_dev_t *dev_ptr)
 Get part number for a sensor. More...
 
ch_pmut_clk_cfg_t ch_get_pmut_clock (ch_dev_t *dev_ptr)
 Get ultrasound transducer clock configuration. More...
 
uint32_t ch_get_range (ch_dev_t *dev_ptr, ch_range_t range_type)
 Get the measured range from a sensor. More...
 
uint16_t ch_get_rtc_cal_pulselength (ch_dev_t *dev_ptr)
 Get the real-time clock calibration pulse length. More...
 
uint16_t ch_get_rtc_cal_result (ch_dev_t *dev_ptr)
 Get the real-time clock calibration value. More...
 
uint16_t ch_get_rtc_frequency (ch_dev_t *dev_ptr)
 Get the sensor real-time clock (RTC) frequency, in Hz. More...
 
uint16_t ch_get_rx_holdoff (ch_dev_t *dev_ptr)
 Get the receive holdoff sample count. More...
 
uint16_t ch_get_rx_low_gain (ch_dev_t *dev_ptr)
 Get the receive low-gain sample count. More...
 
uint8_t ch_get_rx_pretrigger (ch_group_t *grp_ptr)
 Get receive-only sensor pre-triggering setting. More...
 
uint16_t ch_get_sample_interval (ch_dev_t *dev_ptr)
 Get the internal sensing timing interval for a sensor (deprecated). More...
 
uint8_t ch_get_sample_window (ch_dev_t *dev_ptr, uint16_t *start_sample_ptr, uint16_t *num_samples_ptr)
 Get the sample window for amplitude averaging. More...
 
uint16_t ch_get_scale_factor (ch_dev_t *dev_ptr)
 Get the amplitude scale factor of a sensor. More...
 
const char * ch_get_sensor_id (ch_dev_t *dev_ptr)
 Get the unique Sensor ID String for a sensor. More...
 
uint8_t ch_get_target_int_counter (ch_dev_t *dev_ptr, uint8_t *meas_hist_ptr, uint8_t *thresh_count_ptr, uint8_t *reset_ptr)
 Get the target interrupt counter filter settings. More...
 
ch_tgt_int_filter_t ch_get_target_interrupt (ch_dev_t *dev_ptr)
 Get the target interrupt filtering mode setting. More...
 
ch_trigger_type_t ch_get_trigger_type (ch_dev_t *dev_ptr)
 Get the trigger type for a sensor. More...
 
uint16_t ch_get_tx_length (ch_dev_t *dev_ptr)
 Get the ultrasound transmit pulse length. More...
 
void ch_get_version (ch_version_t *version_ptr)
 Get the SonicLib version number. More...
 
uint32_t ch_group_get_frequency (ch_group_t *grp_ptr)
 Get the operating frequency for a group of sensors. More...
 
uint32_t ch_group_get_pmut_clock_freq (ch_group_t *grp_ptr)
 Get the transducer clock input frequency for a group of sensors. More...
 
uint8_t ch_group_init (ch_group_t *grp_ptr, uint8_t num_devices, uint8_t num_buses, uint16_t rtc_cal_pulse_ms)
 Initialize the group descriptor for a group of sensors. More...
 
void ch_group_reset (ch_group_t *grp_ptr, ch_reset_t reset_type)
 Reset a group of sensors. More...
 
uint8_t ch_group_restart (ch_group_t *grp_ptr)
 Restart a group of sensors. More...
 
uint8_t ch_group_set_frequency (ch_group_t *grp_ptr, uint32_t request_op_freq_hz)
 Set the operating frequency for a group of sensors. More...
 
void ch_group_set_pmut_clock_freq (ch_group_t *grp_ptr, uint32_t pmut_clock_freq)
 Specify the transducer clock input frequency for a group of sensors. More...
 
uint8_t ch_group_start (ch_group_t *grp_ptr)
 Program and start a group of sensors. More...
 
void ch_group_trigger (ch_group_t *grp_ptr)
 Trigger a measurement on a group of sensors. More...
 
uint8_t ch_init (ch_dev_t *dev_ptr, ch_group_t *grp_ptr, uint8_t dev_num, ch_fw_init_func_t fw_init_func)
 Initialize the device descriptor for a sensor. More...
 
uint8_t ch_init_algo (ch_dev_t *dev_ptr)
 Initialize the measurement algorithm on a sensor. More...
 
void ch_interrupt (ch_group_t *grp_ptr, uint8_t dev_num)
 Run SonicLib's full-featured interrupt handler. More...
 
void ch_io_complete_callback_set (ch_group_t *grp_ptr, ch_io_complete_callback_t callback_func_ptr)
 Register non-blocking I/O complete callback routine for a group of sensors. More...
 
void ch_io_int_callback_set (ch_group_t *grp_ptr, ch_io_int_callback_t callback_func_ptr)
 Register sensor interrupt callback routine for a group of sensors. More...
 
void ch_io_notify (ch_group_t *grp_ptr, uint8_t bus_index)
 Notify SonicLib that a non-blocking I/O operation has completed. More...
 
uint8_t ch_io_start_nb (ch_group_t *grp_ptr)
 Start non-blocking I/O operation(s) for a group of sensors. More...
 
uint16_t ch_iq_to_amplitude (ch_iq_sample_t *iq_sample_ptr)
 Calculate amplitude from sample I/Q values. More...
 
void ch_log_append (uint8_t log_id, ch_log_fmt_t format, uint64_t timestamp, ch_log_data_t *log_data_ptr)
 Append received sensor data to log. More...
 
uint8_t ch_log_init (ch_group_t *grp_ptr, ch_log_fmt_t format, ch_log_cfg_t *config_ptr)
 Initialize a log in the specified log format. More...
 
void ch_meas_activate (ch_dev_t *dev_ptr, uint8_t meas_num)
 Activate a defined measurement. More...
 
uint8_t ch_meas_add_segment (ch_dev_t *dev_ptr, uint8_t meas_num, ch_meas_segment_t *seg_ptr)
 Add a segment to a measurement. More...
 
uint8_t ch_meas_add_segment_count (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_cycles, uint8_t int_enable)
 Add a count (delay) segment to a measurement. More...
 
uint8_t ch_meas_add_segment_rx (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_samples, uint8_t gain_reduce, uint8_t atten, uint8_t int_enable)
 Add a receive segment to a measurement. More...
 
uint8_t ch_meas_add_segment_tx (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_cycles, uint8_t pulse_width, uint8_t phase, uint8_t int_enable)
 Add a transmit segment to a measurement. More...
 
void ch_meas_get_info (ch_dev_t *dev_ptr, uint8_t meas_num, ch_meas_info_t *info_ptr)
 Get configuration information for a measurement. More...
 
uint16_t ch_meas_get_interval (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the repeat interval for a measurement, in milliseconds. More...
 
uint32_t ch_meas_get_interval_ticks (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the repeat interval for a measurement, in sensor RTC clock ticks. More...
 
uint32_t ch_meas_get_interval_us (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the repeat interval for a measurement, in microseconds. More...
 
ch_output_type_t ch_meas_get_iq_output (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the I/Q data output format for a measurement. More...
 
uint8_t ch_meas_get_last_num (ch_dev_t *dev_ptr)
 Get number of last completed measurement. More...
 
uint16_t ch_meas_get_max_range (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the maximum range setting in mm for a specific measurement. More...
 
uint16_t ch_meas_get_num_samples (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the number of samples per measurement cycle for a specific measurement. More...
 
ch_odr_t ch_meas_get_odr (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get the output data rate for a measurement. More...
 
uint8_t ch_meas_get_queue (ch_dev_t *dev_ptr, measurement_queue_t *meas_queue_ptr)
 Get measurement queue values for a sensor. More...
 
void ch_meas_get_queue_info (ch_dev_t *dev_ptr, ch_meas_queue_info_t *info_ptr)
 Get configuration information for the sensor measurement queue. More...
 
void ch_meas_get_seg_info (ch_dev_t *dev_ptr, uint8_t meas_num, uint8_t seg_num, ch_meas_seg_info_t *info_ptr)
 Get configuration information for a measurement segment. More...
 
ch_meas_status_t ch_meas_get_status (ch_dev_t *dev_ptr, uint8_t meas_num)
 Get measurement status. More...
 
uint8_t ch_meas_import (ch_dev_t *dev_ptr, measurement_queue_t *meas_queue_ptr, void *algo_cfg_ptr)
 Import an externally defined measurement configuration. More...
 
uint8_t ch_meas_init (ch_dev_t *dev_ptr, uint8_t meas_num, const ch_meas_config_t *meas_config_ptr, const void *thresh_ptr)
 Initialize a measurement. More...
 
uint8_t ch_meas_init_queue (ch_dev_t *dev_ptr)
 Initialize the sensor measurement queue. More...
 
void ch_meas_init_segment_count (ch_meas_segment_t *seg_ptr, uint16_t num_cycles, uint8_t int_enable)
 Initialize a count (delay) measurement segment. More...
 
void ch_meas_init_segment_rx (ch_meas_segment_t *seg_ptr, uint16_t num_samples, ch_odr_t odr, uint8_t gain_reduce, uint8_t atten, uint8_t int_enable)
 Initialize a receive measurement segment. More...
 
void ch_meas_init_segment_tx (ch_meas_segment_t *seg_ptr, uint16_t num_cycles, uint8_t pulse_width, uint8_t phase, uint8_t int_enable)
 Initialize a transmit measurement segment. More...
 
uint8_t ch_meas_insert_instruction (ch_dev_t *dev_ptr, uint8_t meas_num, const ch_meas_segment_t *inst_ptr, uint8_t index_to_insert)
 Insert an instruction(segment) to a measurement. More...
 
uint8_t ch_meas_insert_segment (ch_dev_t *dev_ptr, uint8_t meas_num, const ch_meas_segment_t *inst_ptr, uint8_t index_to_insert)
 Insert an instruction(segment) to a measurement. More...
 
uint16_t ch_meas_mm_to_samples (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_mm)
 Convert millimeters to sample count for a specific measurement. More...
 
uint8_t ch_meas_optimize (ch_dev_t *dev_ptr, measurement_queue_t *meas_queue_ptr, void *algo_cfg_ptr)
 Optimize ultrasound measurement sequences for a sensor. More...
 
uint8_t ch_meas_remove_instruction (ch_dev_t *dev_ptr, uint8_t meas_num, uint8_t index_to_remove)
 Remove an instruction(segment) in a measurement. More...
 
uint8_t ch_meas_remove_segment (ch_dev_t *dev_ptr, uint8_t meas_num, uint8_t index_to_remove)
 Remove an instruction(segment) in a measurement. More...
 
uint8_t ch_meas_reset (ch_dev_t *dev_ptr, uint8_t meas_num)
 Reset a measurement. More...
 
uint16_t ch_meas_samples_to_mm (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_samples)
 Convert sample count to millimeters for a specific measurement. More...
 
uint8_t ch_meas_set_interval (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t interval_ms)
 Set the repeat interval for a measurement, in milliseconds. More...
 
uint8_t ch_meas_set_interval_ticks (ch_dev_t *dev_ptr, uint8_t meas_num, uint32_t rtc_ticks)
 Set the repeat interval for a measurement, in sensor RTC clock ticks. More...
 
uint8_t ch_meas_set_interval_us (ch_dev_t *dev_ptr, uint8_t meas_num, uint32_t interval_us)
 Set the repeat interval for a measurement, in microseconds. More...
 
uint8_t ch_meas_set_iq_output (ch_dev_t *dev_ptr, uint8_t meas_num, ch_output_type_t output_format)
 Set the I/Q data output format for a measurement. More...
 
uint8_t ch_meas_set_max_range (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t max_range_mm)
 Set the maximum range in mm for a specific measurement. More...
 
uint8_t ch_meas_set_num_samples (ch_dev_t *dev_ptr, uint8_t meas_num, uint16_t num_samples)
 Set the sensor sample count for a specific measurement. More...
 
uint8_t ch_meas_set_odr (ch_dev_t *dev_ptr, uint8_t meas_num, ch_odr_t odr)
 Set the output data rate for a measurement. More...
 
void ch_meas_standby (ch_dev_t *dev_ptr, uint8_t meas_num)
 Put a measurement in standby mode. More...
 
uint8_t ch_meas_switch (ch_dev_t *dev_ptr)
 Switch active and standby measurement definitions. More...
 
uint8_t ch_meas_time_hop_disable (ch_dev_t *dev_ptr, uint8_t meas_num)
 Disable time-hopping on measure period freerunning mode. More...
 
uint8_t ch_meas_time_hop_enable (ch_dev_t *dev_ptr, uint8_t meas_num)
 Enable time-hopping on measure period freerunning mode. More...
 
uint8_t ch_meas_write_config (ch_dev_t *dev_ptr)
 Write measurement configuration to sensor. More...
 
uint32_t ch_measure_pmut_frequency (ch_dev_t *dev_ptr)
 Measure PMUT frequency on an ICU device. More...
 
uint8_t ch_minimal_int_handler (ch_group_t *grp_ptr, uint8_t dev_num)
 Notify SonicLib that a sensor interrupt was received. More...
 
uint16_t ch_mm_to_samples (ch_dev_t *dev_ptr, uint16_t num_mm)
 Convert millimeters to sample count for a sensor. More...
 
void ch_reset (ch_dev_t *dev_ptr, ch_reset_t reset_type)
 Reset a sensor. More...
 
uint8_t ch_restart (ch_dev_t *dev_ptr)
 Restart a sensor. More...
 
uint32_t ch_samples_to_cycles (uint16_t num_samples, ch_odr_t odr)
 Convert samples to sensor cycles. More...
 
uint16_t ch_samples_to_mm (ch_dev_t *dev_ptr, uint16_t num_samples)
 Convert sample count to millimeters for a sensor. More...
 
uint8_t ch_sensor_is_connected (ch_dev_t *dev_ptr)
 Indicate if a sensor is connected. More...
 
uint8_t ch_set_algo_config (ch_dev_t *dev_ptr, const void *algo_cfg_ptr)
 Set the measurement algorithm configuration data to a sensor. More...
 
uint8_t ch_set_cal_result (ch_dev_t *dev_ptr, ch_cal_result_t *cal_ptr)
 Set the calibration result. More...
 
uint8_t ch_set_config (ch_dev_t *dev_ptr, ch_config_t *config_ptr)
 Set multiple configuration settings for a sensor. More...
 
uint8_t ch_set_data_output (ch_dev_t *dev_ptr, ch_output_t *output_ptr)
 Set data output format and rate. More...
 
uint8_t ch_set_data_ready_delay (ch_dev_t *dev_ptr, uint8_t delay_ms)
 Set data ready interrupt delay interval. More...
 
uint8_t ch_set_freerun_interval (ch_dev_t *dev_ptr, uint16_t interval_ms)
 Set the internal sensing interval for freerunning mode, in milliseconds. More...
 
uint8_t ch_set_freerun_interval_ticks (ch_dev_t *dev_ptr, uint32_t interval_ticks)
 Set the internal sensing interval for freerunning mode, in RTC clock ticks. More...
 
uint8_t ch_set_freerun_interval_us (ch_dev_t *dev_ptr, uint32_t interval_us)
 Set the internal sensing interval for freerunning mode, in microseconds. More...
 
uint8_t ch_set_frequency (ch_dev_t *dev_ptr, uint32_t request_op_freq_hz)
 Set the operating frequency of a sensor. More...
 
uint8_t ch_set_init_firmware (ch_dev_t *dev_ptr, ch_fw_init_func_t fw_init_func)
 Initialize the init firmware to use for a sensor. More...
 
uint8_t ch_set_interrupt_drive (ch_dev_t *dev_ptr, ch_interrupt_drive_t drive)
 Set interrupt drive (open drain or push pull) More...
 
uint8_t ch_set_interrupt_mode (ch_dev_t *dev_ptr, ch_interrupt_mode_t mode)
 Set interrupt mode (pulsed or latching) More...
 
uint8_t ch_set_max_range (ch_dev_t *dev_ptr, uint16_t max_range)
 Set the maximum range for a sensor. More...
 
uint8_t ch_set_mode (ch_dev_t *dev_ptr, ch_mode_t mode)
 Configure a sensor for the specified operating mode. More...
 
uint8_t ch_set_num_samples (ch_dev_t *dev_ptr, uint16_t num_samples)
 Set the sensor sample count directly. More...
 
uint8_t ch_set_pmut_clock (ch_dev_t *dev_ptr, ch_pmut_clk_cfg_t clock_cfg)
 Configure ultrasound transducer clock. More...
 
uint8_t ch_set_rtc (ch_dev_t *dev_ptr, ch_rtc_src_t rtc_source, uint16_t rtc_freq)
 Configure the sensor real-time clock (RTC). More...
 
uint8_t ch_set_rx_holdoff (ch_dev_t *dev_ptr, uint16_t num_samples)
 Set the receive holdoff sample count. More...
 
uint8_t ch_set_rx_low_gain (ch_dev_t *dev_ptr, uint16_t num_samples)
 Set the receive low-gain sample count. More...
 
void ch_set_rx_pretrigger (ch_group_t *grp_ptr, uint8_t enable)
 Enable/disable receive-only sensor pre-triggering. More...
 
uint8_t ch_set_sample_interval (ch_dev_t *dev_ptr, uint16_t interval_ms)
 Set the internal sensing interval (deprecated). More...
 
uint8_t ch_set_sample_window (ch_dev_t *dev_ptr, uint16_t start_sample, uint16_t num_samples)
 Set the sample window for amplitude averaging. More...
 
uint8_t ch_set_target_int_counter (ch_dev_t *dev_ptr, uint8_t meas_hist, uint8_t thresh_count, uint8_t reset)
 Configure the target interrupt counter filter. More...
 
uint8_t ch_set_target_interrupt (ch_dev_t *dev_ptr, ch_tgt_int_filter_t tgt_int_filter)
 Configure target interrupt filtering mode. More...
 
void ch_set_trigger_type (ch_dev_t *dev_ptr, ch_trigger_type_t trig_type)
 Set the trigger type for a sensor. More...
 
uint8_t ch_set_tx_length (ch_dev_t *dev_ptr, uint16_t num_cycles)
 Set the ultrasound transmit pulse length. More...
 
uint32_t ch_ticks_to_usec (ch_dev_t *dev_ptr, uint16_t num_ticks)
 Convert sensor RTC clock ticks to microseconds. More...
 
void ch_trigger (ch_dev_t *dev_ptr)
 Trigger a measurement on one sensor. More...
 
void ch_trigger_soft (ch_dev_t *dev_ptr)
 Trigger a measurement using software (SPI) interface. More...
 
uint8_t ch_update_metadata_from_iq0 (ch_dev_t *dev_ptr, ch_iq_sample_t *iq_data)
 Extract the metadata from the first IQ sample and update the device pointer. More...
 
uint32_t ch_usec_to_cycles (ch_dev_t *dev_ptr, uint32_t num_usec)
 Convert microseconds to sensor cycles. More...
 
uint16_t ch_usec_to_ticks (ch_dev_t *dev_ptr, uint32_t num_usec)
 Convert microseconds to sensor RTC clock ticks. More...
 
uint8_t ch_watchdog_disable (ch_dev_t *dev_ptr)
 Disable watchdog timer in sensor. More...
 
uint8_t ch_watchdog_enable (ch_dev_t *dev_ptr)
 Enable watchdog timer in sensor. More...
 

Detailed Description

SonicLib public API and support functions for TDK/InvenSense ultrasonic sensors (originally developed by Chirp Microsystems).

SonicLib is a set of API functions and sensor driver routines designed to easily control ultrasonic sensors from an embedded C application. It allows an application developer to obtain ultrasonic measurement data from one or more devices, without needing to develop special low-level code to interact with the sensors directly.

The SonicLib API functions provide a consistent interface for an application to use ultrasonic sensors in various situations. This is especially important, because all TDK/InvenSense ultrasonic sensors are completely programmable, including the memory map. The SonicLib interfaces allow an application to use different sensor firmware images, without requiring code changes. Only a single initialization parameter must be modified to use the new sensor firmware.

SonicLib is used with all TDK/InvenSense ultrasonic sensors and firmware types and contains all necessary functions to initialize and manage the devices. It includes a complete set of interfaces for typical rangefinding applications that measure distance using the sensor(s). Certain special sensor firmware may support unusual features, and additional API interfaces for those special functions may be distributed separately.

All function names in the SonicLib API begin with ch_.

Note
All operation of the sensor is controlled through the set of functions, data structures, and symbolic values defined in this header file. You should not need to modify this file or the SonicLib functions, or use lower-level internal functions such as described in the ch_driver.h file or other files in the details subdirectory. Using any of these internal definitions will reduce your ability to benefit from future enhancements and releases from TDK/InvenSense.

Board Support Package

SonicLib also defines a set of board support package (BSP) functions that must be provided by the developer, board vendor, or TDK/InvenSense. The BSP functions are NOT part of SonicLib - they are external interface routines that allow the SonicLib functions to access the peripherals on the target board. These functions, which all begin with a "chbsp_" prefix, are described in the chirp_bsp.h header file. See the descriptions in that file for more detailed information on the BSP interfaces.

Additionally, SonicLib requires the definition of a few static configuration symbols. These are generally board dependent and are used to set the size of static arrays, choose between hardware features that are unlikely to ever change at runtime, etc.

There are two ways to provide these symbols. The default behavior expects a header called chirp_board_config.h to be directly on the include path. A default implementation of this file is provided with the BSP, or can be copied from <invn/soniclib/details/chirp_board_config.h>. Once copied and placed in your project, you can edit it to meet your needs. Make sure that your build places the directory containing chirp_board_config.h on the include path (gcc -I option).

The second method for providing the symbols is to use the build system define flags. For example, you can use the -D option with gcc. To use this method, you must first define the symbol INVN_SONICLIB_INTERNAL_BOARD_CONFIG. This will cause soniclib to use the board config in <invn/soniclib/details>. You should not edit this file directly. Instead, to change the value of the symbols defined there, simply override them with -D flags during the build.

Basic Operating Sequence

At a high level, an application using SonicLib will do the following:

  1. Initialize the hardware on the board
  2. Initialize the Soniclib group structures, by calling ch_group_init()
  3. Initialize the SonicLib devices structures, by calling ch_init() for each sensor.
  4. Program and start the sensor(s), by calling ch_group_start().
  5. Set up a handler function to process interrupts from the sensor.
  6. Set up a triggering mechanism using a board timer, (unless the sensor will be used in free-running mode, in which no external trigger is needed). A timer handler routine will typically trigger the sensor(s) using ch_group_trigger().
  7. Configure the sensor's operating range, detection thresholds, and other parameters.
  8. Set the sensor mode to enable sensing.

There are dedicated ch_set_xxx() functions for all configuration values. Simple configurations may be able to use the ch_set_config() convenience function to configure the sensor and set the mode.

At this point, the sensor will begin to perform measurements. At the end of each measurement cycle, the sensor will interrupt the host controller using its INT line. The handler routine set up in step #4 above will be called, and it should cause the application to read the measurement results from the sensor(s), using ch_get_range() and optionally ch_get_amplitude() and/or ch_get_iq_data().

Do not trigger a new measurement until the previous measurement has completed and all needed data has been read from the device (including I/Q data, if ch_get_iq_data() is used). If any I/O operations are still active, the new measurement may be corrupted.

Verbose Debug Output

To assist with debugging, verbose debug output from various internal SonicLib functions may be enabled by defining CH_LOG_MODULE_LEVEL=X during the system build.

Macro Definition Documentation

◆ CH101_MAX_NUM_SAMPLES

#define CH101_MAX_NUM_SAMPLES   (225)

Max expected samples per measurement for CH101.

◆ CH101_PART_NUMBER

#define CH101_PART_NUMBER   (101)

Integer sensor identifier for CH101.

◆ CH201_MAX_NUM_SAMPLES

#define CH201_MAX_NUM_SAMPLES   (450)

Max expected samples per measurement for CH201.

◆ CH201_PART_NUMBER

#define CH201_PART_NUMBER   (201)

Integer sensor identifier for CH201.

◆ CH_DEFAULT_MEAS_NUM

#define CH_DEFAULT_MEAS_NUM   (0)

Measurement number to use for simple ch_mm_to_samples() etc.

◆ CH_DEFAULT_TARGET_NUM

#define CH_DEFAULT_TARGET_NUM   (0)

Target number to report for simple ch_get_range() etc.

◆ CH_I2C_ADDR_PROG

#define CH_I2C_ADDR_PROG   (0x45)

I2C address of sensor programming interface.

◆ CH_MAX_NUM_TARGETS

#define CH_MAX_NUM_TARGETS   (1)

Maximum number of targets supported in sensor f/w

◆ CH_MEAS_MAX_MEAS

#define CH_MEAS_MAX_MEAS   (MEAS_QUEUE_MAX_MEAS)

max number of measurements in meas queue

◆ CH_MEAS_MAX_SEGMENTS

#define CH_MEAS_MAX_SEGMENTS   (INST_BUF_LENGTH)

max number of segments in a measurement

◆ CH_MIN_RANGE_VAL

#define CH_MIN_RANGE_VAL   (0x0001)

Minimum range value returned for very short distances

◆ CH_NO_TARGET

#define CH_NO_TARGET   (0xFFFFFFFF)

Range value returned if no target was detected.

◆ CH_OP_FREQ_USE_AVG

#define CH_OP_FREQ_USE_AVG   (0)

Special freq value to use average op freq for sensor group

◆ CH_PMUT_TICKS_PER_CYCLE

#define CH_PMUT_TICKS_PER_CYCLE   (16)

Number of PMUT clock ticks per transducer cycle

◆ CH_RTC_FREQ_TYPICAL

#define CH_RTC_FREQ_TYPICAL   (29000)

Typical sensor RTC frequency, in Hz, to use if none available.

◆ CH_RTC_USE_BUS_SPEED

#define CH_RTC_USE_BUS_SPEED   (UINT16_MAX)

Special value for RTC freq estimate, use I/O bus

◆ CH_SENSOR_ID_LENGTH

#define CH_SENSOR_ID_LENGTH   8

length of sensor ID string in bytes: 3 byte lot + 4 byte serial num + null

◆ CH_SIG_BYTE_0

#define CH_SIG_BYTE_0   (0x0a)

Signature byte in sensor (1 of 2).

◆ CH_SIG_BYTE_1

#define CH_SIG_BYTE_1   (0x02)

Signature byte in sensor (2 of 2).

◆ CH_SPEEDOFSOUND_MPS

#define CH_SPEEDOFSOUND_MPS   (343)

Speed of sound, in meters per second.

◆ CH_TARGET_INT_HIST_DEFAULT

#define CH_TARGET_INT_HIST_DEFAULT   (5)

Default number of measurements included in target history

◆ CH_TARGET_INT_HIST_MAX

#define CH_TARGET_INT_HIST_MAX   (15)

Maximum number of measurements included in target history

◆ CH_TARGET_INT_THRESH_DEFAULT

#define CH_TARGET_INT_THRESH_DEFAULT   (3)

Default num targets in history required to interrupt

◆ CH_WINDOW_MAX_SAMPLES

#define CH_WINDOW_MAX_SAMPLES   (64)

Maximum number of samples in a sample window

◆ I2C_DRV_FLAG_RESET_AFTER_NB

#define I2C_DRV_FLAG_RESET_AFTER_NB   (0x00000001)

I2C interface needs reset after non-blocking transfer.

◆ I2C_DRV_FLAG_USE_PROG_NB

#define I2C_DRV_FLAG_USE_PROG_NB   (0x00000002)

Use programming interface for non-blocking transfer.

◆ ICU10201_PART_NUMBER

#define ICU10201_PART_NUMBER   (10201)

Integer sensor identifier for ICU-10201.

◆ ICU20201_PART_NUMBER

#define ICU20201_PART_NUMBER   (20201)

Integer sensor identifier for ICU-20201.

◆ ICU30201_PART_NUMBER

#define ICU30201_PART_NUMBER   (30201)

Integer sensor identifier for ICU-30201.

◆ ICU_MAX_NUM_SAMPLES

#define ICU_MAX_NUM_SAMPLES   (IQ_SAMPLES_MAX)

Max for ICU sensors, from shasta_external_regs.h

◆ ICU_UNKNOWN_PART_NUMBER

#define ICU_UNKNOWN_PART_NUMBER   (0)

Integer sensor identifier for unknown ICU sensors.

◆ SONICLIB_VER_MAJOR

#define SONICLIB_VER_MAJOR   (4)

SonicLib major version.

◆ SONICLIB_VER_MINOR

#define SONICLIB_VER_MINOR   (5)

SonicLib minor version.

◆ SONICLIB_VER_REV

#define SONICLIB_VER_REV   (2)

SonicLib revision.

◆ SONICLIB_VER_SUFFIX

#define SONICLIB_VER_SUFFIX   ""

SonicLib version suffix (contains pre-release info)

Enumeration Type Documentation

◆ ch_asic_gen_t

Sensor asic design generations.

Enumerator
CH_ASIC_GEN_1_WHITNEY 

Generation 1 sensors, including CH101 & CH201

CH_ASIC_GEN_2_SHASTA 

Generation 2 sensors, including ICU-x0201 models

◆ ch_group_status

Sensor group status.

Enumerator
CH_GROUP_STAT_NOT_INIT 

Group not initialized.

CH_GROUP_STAT_INIT_PENDING 

Group initialization pending.

CH_GROUP_STAT_INIT_OK 

Group initialized.

◆ ch_interrupt_drive_t

Sensor interrupt drive type.

Enumerator
CH_INTERRUPT_DRIVE_OPEN_DRAIN 

Open drain type.

CH_INTERRUPT_DRIVE_PUSH_PULL 

Push pull type.

◆ ch_interrupt_mode_t

Sensor interrupt modes.

Enumerator
CH_INTERRUPT_MODE_PULSE 

Pulse mode.

CH_INTERRUPT_MODE_LATCH 

Latching mode.

◆ ch_interrupt_type_t

Sensor interrupt types.

Enumerator
CH_INTERRUPT_TYPE_UNKNOWN 

0x0000 - Unknown.

CH_INTERRUPT_TYPE_DATA_RDY 

0x0001 - Data ready.

CH_INTERRUPT_TYPE_MUT_FCOUNT 

0x0002 - Transducer freq test done.

CH_INTERRUPT_TYPE_CPU_FCOUNT 

0x0004 - CPU freq test done.

CH_INTERRUPT_TYPE_BIST_RDY 

0x0008 - Self test done.

CH_INTERRUPT_TYPE_TX_OPTIMIZE 

0x0010 - Transmit optimization done.

CH_INTERRUPT_TYPE_RTC_CAL_RDY 

0x0020 - RTC calibration done.

CH_INTERRUPT_TYPE_OTP_COPY 

0x0080 - One-time-prog mem copied to ram.

CH_INTERRUPT_TYPE_OTP_WR_STEP 

0x0100 - One-time-prog mem write step done.

CH_INTERRUPT_TYPE_WATCHDOG 

0x0400 - Watchdog timer expired.

CH_INTERRUPT_TYPE_PGM_LOADED 

0x0800 - Sensor f/w program loaded.

CH_INTERRUPT_TYPE_ALGO_ERROR 

0x2000 - Measurement algorithm error.

CH_INTERRUPT_TYPE_DEBUG 

0x4000 - Debug interrupt.

CH_INTERRUPT_TYPE_ERROR 

0x8000 - Unspecified error.

◆ ch_io_mode_t

I/O blocking mode flags.

Enumerator
CH_IO_MODE_BLOCK 

Blocking mode.

CH_IO_MODE_NONBLOCK 

Non-blocking mode.

◆ ch_meas_mode_t

Measurement mode (active / standby)

Enumerator
CH_MEAS_MODE_ACTIVE 

Measurement is active (will be performed)

CH_MEAS_MODE_STANDBY 

Measurement is in standby mode

◆ ch_meas_status_t

Measurement status.

Enumerator
CH_MEAS_STATUS_UNKNOWN 

Measurement status unknown

CH_MEAS_STATUS_INIT 

Measurement queue initialization pending

CH_MEAS_STATUS_TX_OPT 

Transmit optimization pending.

CH_MEAS_STATUS_OK 

Measurement queue configured.

CH_MEAS_STATUS_PENDING 

Measurement is pending.

CH_MEAS_STATUS_DONE 

Measurement done.

◆ ch_mode_t

enum ch_mode_t

Sensor operating modes.

Enumerator
CH_MODE_IDLE 

Idle mode - low-power sleep, no sensing is enabled.

CH_MODE_FREERUN 

Free-running mode - sensor uses internal clock to wake and measure.

CH_MODE_TRIGGERED_TX_RX 

Triggered transmit/receive mode - transmits and receives when INT line triggered.

CH_MODE_TRIGGERED_RX_ONLY 

Triggered receive-only mode - for pitch-catch operation with another sensor.

CH_MODE_CONTINUOUS_RX 

Continuous receive mode.

In this mode, the receiver runs continuously. There is no measurement frame-trigger. Data is double-buffered on the ASIC. The host reads one buffer while the ASIC writes the other.

◆ ch_odr_t

enum ch_odr_t

Sensor output data rate (ODR).

Enumerator
CH_ODR_FREQ_DIV_32 

Sample output rate = sensor freq / 32 (lowest)

CH_ODR_FREQ_DIV_16 

Sample output rate = sensor freq / 16

CH_ODR_FREQ_DIV_8 

Sample output rate = sensor freq / 8 (default)

CH_ODR_FREQ_DIV_4 

Sample output rate = sensor freq / 4

CH_ODR_FREQ_DIV_2 

Sample output rate = sensor freq / 2 (highest)

CH_ODR_DEFAULT 

Default sensor output rate

◆ ch_output_type_t

Output type.

Enumerator
CH_OUTPUT_IQ 

(0) - Output I/Q int16_t pair values

CH_OUTPUT_AMP_THRESH 

(1) - Output amp + threshold uint16_t pair values

CH_OUTPUT_AMP 

(2) - Output amplitude uint16_t values only

◆ ch_pmut_clk_cfg_t

PMUT clock configuration (ICU sensors)

Enumerator
CH_PMUT_CLK_DEFAULT 

Standard PMUT clock config - MUTCLK pad disabled.

CH_PMUT_CLK_OUTPUT_ENABLE 

Output PMUT clock signal on MUTCLK. This option forces MUTCLK on regardless of sensor state.

CH_PMUT_CLK_SRC_EXTERNAL 

Use external input as PMUT clock source

CH_PMUT_CLK_OUTPUT_AUTO 

Output PMUT clock signal on MUTCLK but allow ICU device to control the power state

◆ ch_prod_code_t

Sensor product codes.

Enumerator
CH_PROD_CODE_ICU20201 

TDK ICU-20201

CH_PROD_CODE_ICU10201 

TDK ICU-10201

CH_PROD_CODE_ICU30201 

TDK ICU-30201

CH_PROD_CODE_UNKNOWN 

Unknown product

◆ ch_range_t

enum ch_range_t

Range data types.

Enumerator
CH_RANGE_ECHO_ONE_WAY 

One way - gets full pulse/echo distance & divides by 2.

CH_RANGE_ECHO_ROUND_TRIP 

Round trip - full pulse/echo distance.

CH_RANGE_DIRECT 

Direct - for receiving node in pitch-catch mode.

◆ ch_reset_t

enum ch_reset_t

Sensor reset types.

Enumerator
CH_RESET_HARD 

Hard reset.

CH_RESET_SOFT 

Soft reset.

◆ ch_rtc_cal_t

Sensor real-time clock status.

Enumerator
CH_RTC_CAL_STD 

Standard RTC calibration using INT pulse.

CH_RTC_CAL_MANUAL 

Manual calibration using factory value or estimate.

CH_RTC_CAL_BUS 

RTC calibration uses I/O bus clock.

◆ ch_rtc_src_t

Sensor real-time clock sources.

Enumerator
CH_RTC_SRC_INTERNAL 

Use sensor's internal RTC.

CH_RTC_SRC_EXTERNAL 

Use external RTC signal.

◆ ch_rtc_status_t

Sensor real-time clock status.

Enumerator
CH_RTC_STATUS_INIT 

Internal RTC not calibrated.

CH_RTC_STATUS_CAL_DONE 

Internal RTC calibrated locally.

CH_RTC_STATUS_CAL_FACTORY 

Internal RTC uses factory calibration value

CH_RTC_STATUS_CAL_ESTIMATED 

Internal RTC uses estimate for frequency.

CH_RTC_STATUS_CAL_BUS 

Internal RTC uses estimate based on bus clock rate

CH_RTC_STATUS_EXTERNAL 

Uses external RTC signal as input.

◆ ch_tgt_int_filter_t

Target interrupt filter modes.

Enumerator
CH_TGT_INT_FILTER_OFF 

Target interrupt filter disabled - get int after each meas

CH_TGT_INT_FILTER_ANY 

Interrupt if any target detected, no int if no target

CH_TGT_INT_FILTER_COUNTER 

Interrupt if num targets in meas history plus last meas is over threshold

◆ ch_trigger_type_t

Sensor trigger types.

Enumerator
CH_TRIGGER_TYPE_HW 

Hardware triggered.

CH_TRIGGER_TYPE_SW 

Software triggered.

Function Documentation

◆ ch_check_program()

uint8_t ch_check_program ( ch_dev_t dev_ptr)

Check sensor firmware program.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure

This function confirms that the contents of the sensor's program memory match the firmware that was loaded into it, as specified during the ch_init() call. The memory contents are read back from the sensor and are compared with the original byte values used to program the device.

Returns
0 if firmware matches the original program, or 1 if mismatch (error)

◆ ch_check_reset_state()

uint8_t ch_check_reset_state ( ch_dev_t dev_ptr,
ch_sensor_reset_state_t reset_state_ptr 
)

Check if sensor reset has occurred.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
reset_state_ptrpointer to variable that will be updated with the ch_sensor_reset_state_t value. 0 = No Reset, 1 = Reset has occurred.
Returns
0 if successful, non-zero otherwise

This function calls the driver function to check if the sensor has reset.

This API can be called periodically in a measurement loop to check if the sensor was arbitrarily reset. If this reset event is detected during normal sensor operation the sensor has to be completely re-initialized similar to a power-on condition.

◆ ch_cycles_to_samples()

uint16_t ch_cycles_to_samples ( uint32_t  num_cycles,
ch_odr_t  odr 
)

Convert sensor cycles to samples.

Parameters
num_cyclesnumber of cycles
odroutput data rate
Returns
Number of sample periods.

This function takes a count of internal sensor cycles and converts it to the corresponding number of sample periods. The cycles are the same units used to specify measurement segment lengths.

The odr parameter is the current output data rate setting for the sensor. The ODR affects the timing between samples, and therefore the number of internal cycles per sample.

See also ch_samples_to_cycles, ch_meas_get_odr.

◆ ch_cycles_to_usec()

uint32_t ch_cycles_to_usec ( ch_dev_t dev_ptr,
uint32_t  num_cycles 
)

Convert sensor cycles to microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_cyclesnumber of cycles
Returns
Number of microseconds.

This function takes a number of internal sensor cycles and converts it to the corresponding period of time specified in microseconds.

For ICU (Shasta architecture) sensors, num_cycles are in units of PMUT State Machine Clock (SMCLK) cycles. The SMCLK rate is 16 times the ultrasonic transducer acoustic operating frequency. These are the same units used to specify measurement transmit and count segment lengths.

For CH101 and CH201 (Whitney architecture) sensors, num_cycles are ultrasonic transducer cycles, so are 1/16 the corresponding ICU sensor value.

See also ch_usec_to_cycles().

◆ ch_data_validation_check()

uint16_t ch_data_validation_check ( ch_dev_t dev_ptr,
ch_iq_sample_t data,
uint16_t  num_samples 
)

Check data in validation mode, which should be enabled before calling this. Should be run over all IQ data received by the sensor after mode is enabled to keep the counters in sync.

Note that for some values of receive length, this will be unreliable - avoid using overall RX lengths 1 to 5 cycles longer than integer multiples of the ODR ratio.

Parameters
dev_ptrThe device pointer
dataPointer to IQ buffer containing data sequence read from the sensor
num_samplesNumber of IQ samples in buffer
Returns
Number of samples that don't match expected counter value

◆ ch_enable_data_validation()

uint8_t ch_enable_data_validation ( ch_dev_t dev_ptr,
int16_t  seed,
uint8_t  enable 
)

Enable data validation mode. In this mode, ICU-x0201 sensors will overwrite the IQ data at the end of a measurement and after running the algorithm, with a known sequence to allow validating data transfer integrity while making minimal changes to the system otherwise. Currently, this is limited to a 16-bit counter that increments for each I and Q sample and is continuous across measurements.

This feature is currently only supported by icu_init_fw. It is not recommended to use it if the application uses continuous receive, or has non-contiguous RX segments in its measurement queue. Enabling data validation adds approximately 0.8μs per IQ sample to the measurement time. Note that for each sample, the counter value is incremented in the order of Q then I. Data validation must be handled by the application using ch_data_validation_check().

Parameters
dev_ptrThe device pointer
seedInitial value for data validation counter
enableSet to 1 to enable data validation mode, set to 0 to disable
Returns
0 for success and non-zero otherwise

◆ ch_enable_double_buffer()

uint8_t ch_enable_double_buffer ( ch_dev_t dev_ptr,
uint8_t  enable 
)

Enable or disable the double buffering mode.

IMPORTANT: This function is currently only supported with gpt and init firmware.

The ICU-X0201 sensors can be put into a double buffering mode which does the following:

  • Splits the IQ buffer in two
  • Swaps which half of the buffer is written after every measurement

This enables a measurement to be triggered before the readout of the previous measurement is finished (or even started). The disadvantage is that the maximum number of supported samples is reduced by a factor of 2.

You must not exceed the maximum number of supported samples, which can be found as ch_get_max_samples(...)/2. SonicLib will not check this!

Parameters
dev_ptrThe device pointer
enableSet to 1 to enable the double buffer mode or 0 to disable it
Returns
0 for success and non-zero otherwise

◆ ch_enable_metadata_in_iq0()

uint8_t ch_enable_metadata_in_iq0 ( ch_dev_t dev_ptr,
uint8_t  enable 
)

Enable or disable placing metadata in the first IQ sample.

IMPORTANT: This function is currently only supported with gpt and init firmware.

The ICU-X0201 can be configured to place metadata in the first IQ sample, which is otherwise always read out as 0. If enabled, this will place the IQ buffer address as well as the last measurement index in the first IQ sample.

Parameters
dev_ptrThe device pointer
enableSet to 1 to enable metadata in IQ sample 0 or 0 to disable.
Returns
0 for success and non-zero otherwise

◆ ch_freerun_time_hop_disable()

uint8_t ch_freerun_time_hop_disable ( ch_dev_t dev_ptr)

Disable time-hopping on measure period freerunning mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if successful.

This function disable the time-hopping for a sensor operating in freerunning mode (CH_MODE_FREERUN).

Note
This function has no effect for a sensor operating in one of the triggered modes

See also ch_freerun_time_hop_enable(), ch_get_freerun_interval_ticks(), ch_set_freerun_interval(), ch_set_freerun_interval_us(), ch_set_freerun_interval_ticks().

◆ ch_freerun_time_hop_enable()

uint8_t ch_freerun_time_hop_enable ( ch_dev_t dev_ptr)

Enable time-hopping on measure period freerunning mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if successful.

This function enables the time-hopping for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal real-time clock (RTC) to wake and perform a measurement every measure interval plus a random delay to avoid coexistence with other sensors. Mean measure period is however equals to measure interval.

Note
This function has no effect for a sensor operating in one of the triggered modes.

See also ch_freerun_time_hop_disable(), ch_get_freerun_interval_ticks(), ch_set_freerun_interval(), ch_set_freerun_interval_us(), ch_set_freerun_interval_ticks().

◆ ch_get_algo_config()

uint8_t ch_get_algo_config ( ch_dev_t dev_ptr,
void *  algo_cfg_ptr 
)

Get the measurement algorithm configuration data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_cfg_ptrpointer to a buffer to receive configuration data
Returns
0 if success, 1 if error

This function reads the configuration data from an algorithm running on the ICU sensor. This interface is independent of the specific algorithm or configuration format.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware. It is not used directly in a typical application.

◆ ch_get_algo_info()

uint8_t ch_get_algo_info ( ch_dev_t dev_ptr,
ICU_ALGO_SHASTA_INFO algo_info_ptr 
)

Get the measurement algorithm information data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_info_ptrpointer to a ICU_ALGO_SHASTA_INFO structure to receive info
Returns
0 if success, 1 if error

This function reads the information data from an algorithm running on the ICU sensor. This interface is independent of the specific algorithm that is being used.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware. It is not used directly in a typical application.

◆ ch_get_algo_output()

uint8_t ch_get_algo_output ( ch_dev_t dev_ptr,
void *  algo_out_ptr 
)

Get the measurement algorithm output data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_out_ptrpointer to a buffer to receive output data
Returns
0 if success, 1 if error

This function reads the output data from an algorithm running on the ICU sensor. This interface is independent of the specific algorithm or output format.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware. It is not used directly in a typical application.

◆ ch_get_algo_state()

uint8_t ch_get_algo_state ( ch_dev_t dev_ptr,
void *  algo_state_ptr 
)

Get the measurement algorithm state data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_state_ptrpointer to a buffer to receive state data
Returns
0 if success, 1 if error

This function reads the state data from an algorithm running on the ICU sensor. This interface is independent of the specific algorithm or state format.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware. It is not used directly in a typical application.

◆ ch_get_amp_thresh_data()

uint8_t ch_get_amp_thresh_data ( ch_dev_t dev_ptr,
ch_amp_thresh_t buf_ptr,
uint16_t  start_sample,
uint16_t  num_samples,
ch_io_mode_t  mode 
)

Get the amplitude measurement and threshold data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
buf_ptrpointer to data buffer where amplitude and threshold data will be written
start_samplestarting sample number within measurement data (0 = start of data)
num_samplesnumber of samples to read from sensor
modewhether read should block (CH_IO_MODE_BLOCK (0) = blocking, CH_IO_MODE_NONBLOCK (1) = non-blocking)
Returns
0 if successful, 1 if error

This function obtains specially formatted sample data from the sensor, in which both the amplitude and the detection threshold are reported for each sample in a measurement.

This function is similar to ch_get_amplitude_data(), except that the data values each contains a 16-bit unsigned threshold value in addition to the 16-bit unsigned sample amplitude. The threshold value is the required amplitude at that sample offset to detect a target object, as set by ch_set_thresholds(). This output format may be useful in tuning and debugging the detection threshold values.

Each output sample consists of a ch_amp_thresh_t structure, containing one unsigned 16-bit integer value threshold value followed by one unsigned 16-bit amplitude value.

See ch_get_amplitude_data() for more information on reading amplitude values.

◆ ch_get_amplitude()

uint16_t ch_get_amplitude ( ch_dev_t dev_ptr)

Get the measured amplitude from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Amplitude value for most recent successful range reading

This function returns the amplitude value for the most recent successful range measurement by the sensor. The amplitude is representative of the incoming sound pressure. The value is expressed in internal sensor counts and is not calibrated to any standard units.

The amplitude value is not updated if a measurement cycle resulted in CH_NO_TARGET, as returned by ch_get_range().

◆ ch_get_amplitude_avg()

uint16_t ch_get_amplitude_avg ( ch_dev_t dev_ptr)

Get the averaged measured amplitude over the sample window.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Average amplitude value for samples in current sample window

This function returns the average amplitude value for the most recent measurement cycle across the samples within the current sample window. The sample window is a subset of the overall sensor data, and is specified by the ch_set_sample_window() function.

The amplitude is representative of the incoming sound pressure. The value is expressed in internal sensor counts and is not calibrated to any standard units.

Note
Sample window averaging is only available when using special sensor firmware packages from Chirp. It is generally not available in General Purpose Rangefinding (GPR) firmware.

◆ ch_get_amplitude_data()

uint8_t ch_get_amplitude_data ( ch_dev_t dev_ptr,
uint16_t *  buf_ptr,
uint16_t  start_sample,
uint16_t  num_samples,
ch_io_mode_t  mode 
)

Get the raw amplitude measurement data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
buf_ptrpointer to data buffer where amplitude data will be written
start_samplestarting sample number within measurement data (0 = start of data)
num_samplesnumber of samples to read from sensor
modewhether read should block (CH_IO_MODE_BLOCK (0) = blocking, CH_IO_MODE_NONBLOCK (1) = non-blocking)
Returns
0 if successful, 1 if error

The raw amplitude data are updated on every measurement cycle, even if no target was detected (i.e. even if ch_get_range() returns CH_NO_TARGET). (Note that this is different than the regular amplitude value, as returned by ch_get_amplitude(), which is not updated unless a target is detected.)

Each sample amplitude consists of one unsigned 16-bit integer value.

Amplitude values in the sensor are expressed only in internal ADC counts (least-significant bits, or LSBs) and are not calibrated to any standard units.

The number of samples available in each amplitude trace is determined by the maximum range setting for the device. If it is set to less than the maximum possible range, not all samples will contain valid data. To determine the number of active samples within the trace, use ch_get_num_samples().

  • To read all valid amplitude data, set start_sample to zero (0), and set num_samples to the value returned by ch_get_num_samples().

To determine what sample number corresponds to a physical distance, use ch_mm_to_samples().

To allow more flexibility in your application, the amplitude data readout from the device may be done in a non-blocking mode, by setting mode to CH_IO_MODE_NONBLOCK (1). In non-blocking mode, the I/O operation takes place using DMA access in the background. This function will return immediately, and a notification will later be issued when the amplitude has been read. To use the non_block option, the board support package (BSP) you are using must provide the chbsp_i2c_read_nb() and chbsp_i2c_read_mem_nb() functions. To use non-blocking reads of the amplitude data, you must specify a callback routine that will be called when the amplitude read completes. See ch_io_complete_callback_set().

Note
Non-blocking amplitude reads are only supported when using certain Chirp sensor firmware types which support direct readout of the amplitude data. Other firmware types read I/Q data and calculate the amplitudes as part of this function, and will require use of blocking mode (CH_IO_MODE_BLOCK). If non-blocking mode is specified when using sensor f/w that does not support it, this function will return an error.

Non-blocking reads are managed together for a group of sensors. To perform a non-blocking read:

  1. Register a callback function using ch_io_complete_callback_set().
  2. Define and initialize a handler for the DMA interrupts generated.
  3. Synchronize with all sensors whose amplitude data should be read by waiting for all to indicate data ready.
  4. Set up a non-blocking read on each sensor, using ch_get_amplitude_data() with mode = CH_IO_MODE_NONBLOCK (1).
  5. Start the non-blocking reads on all sensors in the group, using ch_io_start_nb().
  6. Your callback function (set in step #1 above) will be called as each individual sensor's read completes. Your callback function should initiate any further processing of the I/Q data, possibly by setting a flag that will be checked from within the application's main execution loop. The callback function will likely be called at interrupt level, so the amount of processing within it should be kept to a minimum.

For a CH101 sensor, up to 150 samples are taken during each measurement cycle; for a CH201 sensor, up to 450 samples are taken. So, a complete CH101 amplitude trace will contain up to 300 bytes of data (150 samples x 2 bytes per sample), and a CH201 amplitude trace may contain up to 900 bytes. The buffer specified by buf_ptr must be large enough to hold this amount of data.

When the amplitude data is read from the sensor, the additional time required to transfer the amplitude data over the SPI/I2C bus must be taken into account when planning how often the sensor can be read (sample interval).

Note
It is important that any data I/O operations to or from the sensor, including reading the amplitude data, complete before a new measurement cycle is triggered, or the new measurement may be affected.
This function only obtains the data from the most recently completed measurement cycle. It does not actually trigger a measurement.

◆ ch_get_bandwidth()

uint16_t ch_get_bandwidth ( ch_dev_t dev_ptr)

Get the bandwidth of a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure

This function returns the operating frequency of the sensor. This is the primary frequency of the ultrasonic pulse that is emitted by the device when transmitting.

Returns
Sensor bandwidth, in Hz, or 0 if error or bandwidth measurement is not available
Note
The bandwidth measurement is only available when using special sensor firmware packages from Chirp. It is generally not available in General Purpose Rangefinding (GPR) firmware.

◆ ch_get_bus()

uint8_t ch_get_bus ( ch_dev_t dev_ptr)

Get the active SPI/I2C bus for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
SPI/I2C bus index

This function returns the SPI/I2C bus index for a sensor device. This function may be used by board support package routines to determine the proper SPI/I2C bus to use for a specified sensor.

◆ ch_get_cal_result()

uint8_t ch_get_cal_result ( ch_dev_t dev_ptr,
ch_cal_result_t cal_ptr 
)

Get the calibration result.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
cal_ptrpointer to ch_cal_result_t structure to receive calibration data
Returns
0 if success, 1 if error

This function obtains the current calibration result from the sensor and returns them in a ch_cal_result_t structure specified by cal_ptr. The ch_cal_result_t structure contains DCO period and reverse drive cycles.

See also ch_set_cal_result().

◆ ch_get_config()

uint8_t ch_get_config ( ch_dev_t dev_ptr,
ch_config_t config_ptr 
)

Get current configuration settings for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
config_ptrpointer to a ch_config_t structure to receive configuration values
Returns
0 if successful, 1 if error

This function obtains the current configuration settings from the sensor and returns them in a ch_config_t structure, whose address is specified by config_ptr.

Note
The individual configuration values returned in the ch_config_t structure may also be obtained by using dedicated single-value functions. See ch_get_mode(), ch_get_max_range(), ch_get_freerun_interval(), ch_get_static_range(), and ch_get_thresholds().

◆ ch_get_cpu_frequency()

uint32_t ch_get_cpu_frequency ( ch_dev_t dev_ptr)

Get the sensor CPU frequency, in Hz.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
sensor CPU frequency, in Hz

This function returns the processor speed, in Hz, for the micro-controller in the ultrasound sensor.

◆ ch_get_data_ready_delay()

uint8_t ch_get_data_ready_delay ( ch_dev_t dev_ptr)

Get data ready interrupt delay interval.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
time, in milliseconds, that sensor will delay after measurement

This function returns the time, in milliseconds, that the sensor will wait between the completion of a measurement cycle and generating a data ready interrupt. The delay may be slightly greater than the value specified during ch_set_data_ready_delay(), due to the granularity of the sensor's wake cycle timer.

Note
This function is only available in select Chirp sensor firmware versions.

◆ ch_get_dev_num()

uint8_t ch_get_dev_num ( ch_dev_t dev_ptr)

Get device number (I/O index values) for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Device number

This function returns the device number (I/O index) of the sensor within its sensor group. Normally, this also corresponds to the sensor's port number on the board, and is used for indexing arrays of pin definitions etc. within the board support package routines.

◆ ch_get_dev_ptr()

ch_dev_t* ch_get_dev_ptr ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Get device descriptor pointer for a sensor.

Parameters
grp_ptrpointer to the ch_group_t descriptor for this group of sensors
dev_numdevice number within sensor group
Returns
Pointer to ch_dev_t descriptor structure

This function returns the address of the ch_dev_t device descriptor for a certain sensor in a sensor group. The sensor is identified within the group by the dev_num device number.

◆ ch_get_freerun_interval()

uint16_t ch_get_freerun_interval ( ch_dev_t dev_ptr)

Get the internal sensing timing interval for a sensor, in milliseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Interval between samples (in ms), or 0 if device is not in free-running mode

This function returns the interval between measurements, in milliseconds, for a sensor operating in free-running mode. If the sensor is in a different operating mode (e.g. a triggered mode), zero is returned.

See also ch_get_freerun_interval_us(), ch_get_freerun_interval_ticks().

◆ ch_get_freerun_interval_ticks()

uint16_t ch_get_freerun_interval_ticks ( ch_dev_t dev_ptr)

Get the internal sensing timing interval for a sensor, in RTC clock ticks.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Interval between measurements (in sensor RTC clock periods), or 0 if device is not in free-running mode

This function returns the interval between measurements, in sensor RTC clock periods, for a sensor operating in free-running mode. If the sensor is in a different operating mode (e.g. a triggered mode), zero is returned.

See also ch_get_freerun_interval_us(), ch_get_freerun_interval_ticks().

◆ ch_get_freerun_interval_us()

uint32_t ch_get_freerun_interval_us ( ch_dev_t dev_ptr)

Get the internal sensing timing interval for a sensor, in microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Interval between samples (in ms), or 0 if device is not in free-running mode

This function returns the interval between measurements, in milliseconds, for a sensor operating in free-running mode. If the sensor is in a different operating mode (e.g. a triggered mode), zero is returned.

See also ch_get_freerun_interval_us(), ch_get_freerun_interval_ticks().

◆ ch_get_frequency()

uint32_t ch_get_frequency ( ch_dev_t dev_ptr)

Get the operating frequency of a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure

This function returns the acoustic operating frequency of the sensor. This is the primary frequency of the ultrasonic pulse that is emitted by the device when transmitting.

Normally, the returned operating frequency value is the natural resonant frequency for the sensor. However, if the frequency has been changed by using ch_set_frequency() or ch_group_set_frequency(), the returned value will be the adjusted operating frequency.

Returns
Acoustic operating frequency, in Hz

◆ ch_get_fw_version_string()

const char* ch_get_fw_version_string ( ch_dev_t dev_ptr)

Get the firmware version description string for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Pointer to character string describing sensor firmware version

This function returns a pointer to a string that describes the sensor firmware being used on the device.

◆ ch_get_i2c_address()

uint8_t ch_get_i2c_address ( ch_dev_t dev_ptr)

Get the active I2C address for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
I2C address, or 0 if error

This function returns the currently active I2C address for a CHx01 sensor device. This function may be used by board support package routines to determine the proper I2C address to use for a specified sensor.

Zero is returned if this function is called for ICU sensors, which use a SPI bus interface.

◆ ch_get_interrupt_drive()

ch_interrupt_drive_t ch_get_interrupt_drive ( ch_dev_t dev_ptr)

Get the pulse interrupt drive setting.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
CH_INTERRUPT_DRIVE_OPEN_DRAIN if interrupt uses open drain drive, CH_INTERRUPT_DRIVE_PUSH_PULL if push pull drive

This function returns the current setting for interrupt drive (open drain or push pull).

Note
CH101 and CH201 sensors always use active-high, pull low interrupt drive for normal sensor interrupts, so this routine will always return CH_INTERRUPT_DRIVE_OPEN_DRAIN.

◆ ch_get_interrupt_mode()

ch_interrupt_mode_t ch_get_interrupt_mode ( ch_dev_t dev_ptr)

Get the pulse interrupt mode setting.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
CH_INTERRUPT_MODE_PULSE if interrupt uses pulse mode, CH_INTERRUPT_MODE_LATCH if latching mode

This function returns the current setting for interrupt mode (pulsed or latching).

Note
CH101 and CH201 sensors always use pulse interrupt mode for normal sensor interrupts, so this routine will always return CH_INTERRUPT_MODE_PULSE.

◆ ch_get_iq_data()

uint8_t ch_get_iq_data ( ch_dev_t dev_ptr,
ch_iq_sample_t buf_ptr,
uint16_t  start_sample,
uint16_t  num_samples,
ch_io_mode_t  mode 
)

Get the raw I/Q measurement data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
buf_ptrpointer to data buffer where I/Q data will be written
start_samplestarting sample number within measurement data (0 = start of data)
num_samplesnumber of samples to read from sensor
modewhether I/Q read should block (CH_IO_MODE_BLOCK (0) = blocking, CH_IO_MODE_NONBLOCK (1) = non-blocking)
Returns
0 if successful, 1 if error

This function reads the raw I/Q measurement data from the sensor. The I/Q data set includes a discrete pair of values for each of the samples that make up a full measurement cycle. Each individual sample is reported as a pair of values, I and Q, in a quadrature format. The I/Q values may be used to calculate the relative amplitude of the measured ultrasound signal.

The contents of the I/Q trace are updated on every measurement cycle, even if no target was detected (i.e. even if ch_get_range() returns CH_NO_TARGET). (Note that this is different than the regular amplitude value, as returned by ch_get_amplitude(), which is not updated unless a target is detected.)

Each sample I/Q pair consists of two signed 16-bit integers and is described by the ch_iq_sample_t structure. To convert any given pair of I/Q values to the amplitude value for that sample, square both I and Q, and take the square root of the sum:

\[Amp_n = \sqrt{(I_n)^2 + (Q_n)^2}\]

Amplitude values in the sensor are expressed only in internal ADC counts (least-significant bits, or LSBs) and are not calibrated to any standard units.

The number of samples used in each I/Q trace is determined by the maximum range setting for the device. If it is set to less than the maximum possible range, not all samples will contain valid data. To determine the number of active samples within the trace, use ch_get_num_samples().

  • To read all valid I/Q data, set start_sample to zero (0), and set num_samples to the value returned by ch_get_num_samples().

To determine what sample number corresponds to a physical distance, use ch_mm_to_samples().

To allow more flexibility in your application, the I/Q data readout from the device may be done in a non-blocking mode, by setting mode to CH_IO_MODE_NONBLOCK (1). In non-blocking mode, the I/O operation takes place using DMA access in the background. This function will return immediately, and a notification will later be issued when the I/Q has been read. To use the non_block option, the board support package (BSP) you are using must provide the chbsp_i2c_read_nb() and chbsp_i2c_read_mem_nb() functions. To use non-blocking reads of the I/Q data, you must specify a callback routine that will be called when the I/Q read completes. See ch_io_complete_callback_set().

Non-blocking reads are managed together for a group of sensors. To perform a non-blocking read:

  1. Register a callback function using ch_io_complete_callback_set().
  2. Define and initialize a handler for the DMA interrupts generated.
  3. Synchronize with all sensors whose I/Q data should be read by waiting for all to indicate data ready.
  4. Set up a non-blocking read on each sensor, using ch_get_iq_data() with mode = CH_IO_MODE_NONBLOCK (1).
  5. Start the non-blocking reads on all sensors in the group, using ch_io_start_nb().
  6. Your callback function (set in step #1 above) will be called as each individual sensor's read completes. Your callback function should initiate any further processing of the I/Q data, possibly by setting a flag that will be checked from within the application's main execution loop. The callback function will likely be called at interrupt level, so the amount of processing within it should be kept to a minimum.

For a CH101 sensor, up to 150 samples are taken during each measurement cycle; for a CH201 sensor, up to 450 samples are taken. So, a complete CH101 I/Q trace will contain up to 600 bytes of data (150 samples x 4 bytes per sample), and a CH201 I/Q trace may contain up to 1800 bytes. The buffer specified by buf_ptr must be large enough to hold this amount of data.

When the I/Q data is read from the sensor, the additional time required to transfer the I/Q data over the SPI/I2C bus must be taken into account when planning how often the sensor can be read (sample interval).

Note
It is important that any data I/O operations to or from the sensor, including reading the I/Q data, complete before a new measurement cycle is triggered, or the new measurement may be affected.
This function only obtains the data from the most recently completed measurement cycle. It does not actually trigger a measurement.

◆ ch_get_max_range()

uint16_t ch_get_max_range ( ch_dev_t dev_ptr)

Get the maximum range setting in mm for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Maximum range setting, in millimeters

This function returns the current maximum detection range setting for the sensor, in millimeters.

For ICU sensors, this function always returns the values for the default measurement definition. To specify which measurement to query, use the ch_meas_get_max_range() function.

See also ch_get_num_samples(), ch_get_config().

◆ ch_get_max_samples()

uint16_t ch_get_max_samples ( ch_dev_t dev_ptr)

Get the maximum possible sample count per measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor struct
Returns
Maximum sample count for this device and firmware

This function returns the maximum number of samples that can be included in a measurement. This maximum sample count will vary depending on the sensor device (CH201 devices will have higher sample counts than CH101 devices) and by the specific sensor firmware that is being used.

To get the number of these possible samples that are currently active (based on the maximum range setting), use ch_get_num_samples().

◆ ch_get_mfg_info()

uint8_t ch_get_mfg_info ( ch_dev_t dev_ptr,
ch_mfg_info_t info_ptr 
)

Get manufacturing information for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
info_ptrpointer to ch_mfg_info_t structure to be updated
Returns
0 if success, 1 if error

This function sets fields in a ch_mfg_info_t structure with manufacturing information for the specific sensor device. These fields include:

  • mfg_site - manufacturing location where sensor was made
  • mfg_year - year when sensor was made
  • mfg_week - work-week number within the year when sensor was made
  • product_code - numeric identifier for the sensor product type
  • package_code - numeric identifier for the sensor package type
  • module_code - numeric identifier for the sensor module type
  • mems_code - numeric identifier for the MEMS ultrasonic transducer type

See also ch_get_sensor_id(), ch_get_part_number().

◆ ch_get_mode()

ch_mode_t ch_get_mode ( ch_dev_t dev_ptr)

Get the current operating mode for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure
Returns
Sensor operating mode

This function returns the current operating mode for the sensor, one of:

  • CH_MODE_IDLE - low power idle mode, no measurements take place
  • CH_MODE_FREERUN - free-running mode, sensor uses internal clock to wake and measure
  • CH_MODE_TRIGGERED_TX_RX - hardware-triggered, sensor both transmits and receives
  • CH_MODE_TRIGGERED_RX_ONLY - hardware triggered, sensor only receives

◆ ch_get_next_buf_addr()

uint16_t ch_get_next_buf_addr ( ch_dev_t dev_ptr)

Get the address of the IQ buffer that will be written by the next measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function returns the address of the buffer that will be written by the next measurement. This is useful in the double buffer mode.

See also ch_update_metadata_from_iq0().

Note
This feature is only available for ICU sensors.

◆ ch_get_num_output_samples()

uint16_t ch_get_num_output_samples ( ch_dev_t dev_ptr)

Get the number of valid output samples in last measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
number of output samples in last measurement

This function returns the number of valid samples in the most recently completed measurement, as reported by the sensor. The sensor will be queried dynamically over the I/O bus interface.

In general, this number will match the configured sample count for the last measurement, which can be obtained using ch_get_num_samples(). That function is recommended for typical use, because it requires no additional I/O to the sensor.

Note
For CH101 and CH201 sensors, this function will always return the configured sample count, not a dynamic value from the sensor (i.e. it is identical to ch_get_num_samples()).

See also ch_get_num_samples(), ch_meas_get_num_samples().

◆ ch_get_num_ports()

uint8_t ch_get_num_ports ( ch_group_t grp_ptr)

Get the total number of sensor ports (possible sensors) in a sensor group.

Parameters
grp_ptrpointer to the ch_group_t descriptor for this group of sensors
Returns
Total number of ports (possible sensors) in the sensor group

This function returns the maximum number of possible sensors within a sensor group. Typically, the number of sensors is limited by the physical connections on the board being used, so the number of sensor ports on the board is returned by this function.

◆ ch_get_num_samples()

uint16_t ch_get_num_samples ( ch_dev_t dev_ptr)

Get the number of samples per measurement cycle.

Parameters
dev_ptrpointer to the ch_dev_t descriptor struct
Returns
Number of samples per measurement cycle

This function returns the configured number of samples which the Chirp sensor will obtain during each measurement cycle. The number of samples directly corresponds to the range at which the sensor can detect, so this value is determined by the current maximum range setting for the sensor.

For ICU sensors, this function always returns the configured value for the last completed measurement. To specify which measurement to indicate, use the ch_meas_get_num_samples() function.

ICU sensors can report the number of output samples directly. To obtain the number of samples in the last measurement as reported by the sensor itself, use ch_get_num_output_samples(). Normally, this will be the same as the configured value reported by this routine.

See also ch_set_num_samples, ch_meas_get_num_samples, ch_get_max_range().

◆ ch_get_part_number()

uint16_t ch_get_part_number ( ch_dev_t dev_ptr)

Get part number for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Integer part number

This function returns the TDK/Chirp part number for the specified device. The part number is a simple integer value, for example 101 for a CH101 sensor, or 20201 for an ICU20201 sensor.

◆ ch_get_pmut_clock()

ch_pmut_clk_cfg_t ch_get_pmut_clock ( ch_dev_t dev_ptr)

Get ultrasound transducer clock configuration.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function returns the current configuration setting for the PMUT clock.

See also ch_set_pmut_clock().

Note
On CH101 and CH201 sensors, this function always returns CH_PMUT_CLK_DEFAULT.

◆ ch_get_range()

uint32_t ch_get_range ( ch_dev_t dev_ptr,
ch_range_t  range_type 
)

Get the measured range from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
range_typethe range type to be reported (e.g. one-way vs. round-trip)
Returns
Range in millimeters times 32, or CH_NO_TARGET (0xFFFFFFFF) if no target was detected, or 0 if error

This function reads the measurement result registers from the sensor and then computes the actual range. It should be called after the sensor has indicated that a measurement cycle is complete by generating a signal on the INT line. (Typically, this will be set up by an interrupt handler associated with that input line.)

The range_type parameter indicates whether the measurement is based on the one-way or round-trip distance to/from a target, or the direct distance between two sensors operating in pitch-catch mode. The possible values are:

  • CH_RANGE_ECHO_ONE_WAY - gets full pulse/echo round-trip distance, then divides by 2
  • CH_RANGE_ECHO_ROUND_TRIP - full pulse/echo round-trip distance
  • CH_RANGE_DIRECT - for receiving sensor in pitch-catch mode (one-way)

This function returns the measured range as a 32-bit integer. For maximum precision, the range value is returned in a fixed-point format with 5 fractional bits. So, the return value is the number of millimeters times 32. Divide the value by 32 (shift right 5 bits) to get whole mm, or use floating point (i.e. divide by 32.0f) to preserve the full sub-millimeter precision.

If the sensor did not successfully find the range of a target during the most recent measurement, the returned range value will be CH_NO_TARGET. If an error occurs when getting or calculating the range, zero (0) will be returned.

Note
This function only reports the results from the most recently completed measurement cycle. It does not actually trigger a measurement.
The range_type parameter only controls how this function interprets the results from the measurement cycle. It does not change the sensor mode.

◆ ch_get_rtc_cal_pulselength()

uint16_t ch_get_rtc_cal_pulselength ( ch_dev_t dev_ptr)

Get the real-time clock calibration pulse length.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
RTC pulse length, in ms

This function returns the length (duration), in milliseconds, of the the real-time clock (RTC) calibration pulse used for the sensor. The pulse is applied to the sensor's INT line during ch_group_start() to calibrate the sensor's internal clock. The pulse length is specified by the board support package during the ch_group_init() function.

The RTC calibration pulse length is used internally in calculations that convert between time and distance.

◆ ch_get_rtc_cal_result()

uint16_t ch_get_rtc_cal_result ( ch_dev_t dev_ptr)

Get the real-time clock calibration value.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
RTC calibration value

This function returns the real-time clock (RTC) calibration value read from the sensor during ch_group_start(). The RTC calibration value is calculated by the sensor during the RTC calibration pulse, and it is used internally in calculations that convert between time and distance.

◆ ch_get_rtc_frequency()

uint16_t ch_get_rtc_frequency ( ch_dev_t dev_ptr)

Get the sensor real-time clock (RTC) frequency, in Hz.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
sensor RTC frequency, in Hz

This function returns the real-time clock (RTC) frequency, in Hz, for the micro-controller in the ultrasound sensor.

◆ ch_get_rx_holdoff()

uint16_t ch_get_rx_holdoff ( ch_dev_t dev_ptr)

Get the receive holdoff sample count.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
number of samples that are ignored at the beginning of each measurement

This function gets the receive (rx) holdoff sample count. The rx holdoff count is the number of samples at the beginning of a measurement that will be ignored for the purpose of detecting a target, as previously set by ch_set_rx_holdoff().

To convert the returned sample count to a physical distance, use ch_samples_to_mm().

For ICU sensors, this function always returns the value for the default measurement definition. To specify which measurement to query, use the icu_gpt_get_rx_holdoff() function.

See also ch_set_rx_holdoff().

◆ ch_get_rx_low_gain()

uint16_t ch_get_rx_low_gain ( ch_dev_t dev_ptr)

Get the receive low-gain sample count.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
number of samples that have low gain at beginning of measurement

This function gets the receive (rx) low-gain range from the sensor. The low-gain range is a count of samples at the beginning of a measurement that will have lower gain applied during the ultrasound receive operation.

The returned low-gain range is either the default value for the sensor firmware, or a value previously set by ch_set_rx_low_gain().

To convert the returned sample count to a physical distance, use ch_samples_to_mm().

See also ch_set_rx_low_gain().

Note
This function is only available in CH201 sensor firmware.

◆ ch_get_rx_pretrigger()

uint8_t ch_get_rx_pretrigger ( ch_group_t grp_ptr)

Get receive-only sensor pre-triggering setting.

Parameters
grp_ptrpointer to the ch_group_t group descriptor structure

This function returns the current state (enabled or disabled) of pre-triggering receive-only sensors.

See also ch_set_rx_pretrigger().

Returns
1 if receive pre-triggering is enabled, 0 if disabled

◆ ch_get_sample_interval()

uint16_t ch_get_sample_interval ( ch_dev_t dev_ptr)

Get the internal sensing timing interval for a sensor (deprecated).

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Interval between samples (in ms), or 0 if device is not in free-running mode
Note
This function is DEPRECATED and is provided only for backwards compatiblity. New applications should use the equivalent ch_get_freerun_interval() function.

This function returns the interval between measurements, in milliseconds, for a sensor operating in free-running mode. If the sensor is in a different operating mode (e.g. a triggered mode), zero is returned.

◆ ch_get_sample_window()

uint8_t ch_get_sample_window ( ch_dev_t dev_ptr,
uint16_t *  start_sample_ptr,
uint16_t *  num_samples_ptr 
)

Get the sample window for amplitude averaging.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
start_sample_ptrpointer to variable to be updated with sample number of first sample
num_samples_ptrpointer to variable to be updated with number of samples
Returns
0 if successful, non-zero if error

This function obtains the current range of samples that are included in the sample window used for amplitude averaging. start_sample_ptr is a pointer to a variable that will be updated with the number of the first sample in the sample window. num_samples_ptr is a pointer to a variable that will be updated with the the total number of samples in the sample window.

See also ch_get_amplitude_avg(), ch_set_sample_window().

Note
Internal sample window averaging is available when using special sensor firmware packages from Chirp. In General Purpose Rangefinding (GPR) firmware, a software only implementation is used.

◆ ch_get_scale_factor()

uint16_t ch_get_scale_factor ( ch_dev_t dev_ptr)

Get the amplitude scale factor of a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure

This function returns the amplitude scale factor of the sensor. The scale factor is an internal value generated during the initialization of the device.

Returns
Scale factor value, or 0 if error or not available
Note
The scale factor value is only available when using special sensor firmware packages from Chirp.

◆ ch_get_sensor_id()

const char* ch_get_sensor_id ( ch_dev_t dev_ptr)

Get the unique Sensor ID String for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Pointer to character string containing unique sensor ID

This function returns a pointer to a string that contains a unique identifier for the sensor device. The ID string consists of 7 ascii alpha-numeric characters, terminated by a null byte (so total size is 8 bytes). CH_SENSOR_ID_LENGTH, is defined as the length of the string, including the null terminator.

The first three bytes in the ID string specify the Production Lot. The remaining four bytes specify the alphanumeric Serial Number within that production lot.

See also ch_get_mfg_info(), ch_get_fw_version_string.

◆ ch_get_target_int_counter()

uint8_t ch_get_target_int_counter ( ch_dev_t dev_ptr,
uint8_t *  meas_hist_ptr,
uint8_t *  thresh_count_ptr,
uint8_t *  reset_ptr 
)

Get the target interrupt counter filter settings.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_hist_ptrpointer to location to receive count of measurements in filter history
thresh_count_ptrpointer to location to receive number of target detections req'd
reset_ptrpointer to location to receive target counter reset setting
Returns
0 if success, 1 if error

This function obtains the current target counter filter settings used to control sensor interrupts. This filter is enabled by calling the ch_set_target_interrupt() (or ch_set_config()) function and specifying CH_TGT_INT_FILTER_COUNTER as the filter type.

The location specified by meas_hist_ptr will be set to the number of previous measurements that are included in the history for filtering. The current measurement is combined with these previous measurements, so a total of meas_hist + 1 measurements are used. The location specified by thresh_count_ptr will be set to the threshold number of those measurements that must positively detect a target for an interrupt to be generated. The location specified by reset_ptr will be set to 1 if the sensor resets the counter filter after an interrupt is generated, 0 otherwise (default).

The maximum value for both meas_hist and thresh_count is 15.

See also ch_set_target_int_counter(), ch_set_target_interrupt().

Note
Target counter filtering is only available in select Chirp sensor firmware versions.

◆ ch_get_target_interrupt()

ch_tgt_int_filter_t ch_get_target_interrupt ( ch_dev_t dev_ptr)

Get the target interrupt filtering mode setting.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
Target interrupt filter mode

This function returns the current setting for target interrupt filtering mode. The mode is one of:

  • CH_TGT_INT_FILTER_OFF - No filtering. The sensor will interrupt after each measurement, even if no target is detected.
  • CH_TGT_INT_FILTER_ANY - Target filtering. The sensor will interrupt after each measurement in which a target is successfully detected. No interrupt is generated if no target is found.
  • CH_TGT_INT_FILTER_COUNTER - Target filtering with a threshold value. The sensor will interrupt if a specified number of measurements detect a target within a certain number of consecutive results.

See also ch_set_target_interrupt(), ch_get_target_int_counter().

Note
Target detection interrupt mode is only available in select Chirp sensor firmware versions.

◆ ch_get_trigger_type()

ch_trigger_type_t ch_get_trigger_type ( ch_dev_t dev_ptr)

Get the trigger type for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
trigger type, either CH_TRIGGER_TYPE_HW or CH_TRIGGER_TYPE_SW

This function gets the current trigger type to be used to initiate a measurement on a sensor when in triggered mode.

By default, sensors are triggered using a hardware signal on the INT line, and this function will return CH_TRIGGER_TYPE_HW.

Alternatively, software triggering may be used, using a special SPI command to the sensor. In this case, this function will return CH_TRIGGER_TYPE_SW.

See also ch_set_trigger_type(), ch_trigger().

◆ ch_get_tx_length()

uint16_t ch_get_tx_length ( ch_dev_t dev_ptr)

Get the ultrasound transmit pulse length.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
transmit pulse length (number of cycles per transmission)

This function gets the length of the ultrasonic pulse sent by the sensor when it transmit. The transmit length is expressed in cycles.

For ICU (Shasta architecture) sensors, cycles are in units of Measurement State Machine Clock (SMCLK) cycles.

For CH101 and CH201 (Whitney architecture) sensors, cycles are ultrasonic transducer (PMUT) cycles.

See also ch_set_tx_length().

Note
This feature is only available in select Chirp sensor firmware versions.

◆ ch_get_version()

void ch_get_version ( ch_version_t version_ptr)

Get the SonicLib version number.

Parameters
version_ptrpointer to a ch_version_t structure to receive version

This function fills the fields in the ch_version_t structure identified by version_ptr with the SonicLib version number.

The version number consists of three x.y.z fields: <major>.<minor>.<rev>

  • Major versions are infrequent architectural releases that may include fundamental changes to interfaces and other compatiblity issues.
  • Minor releases introduce new features and may include minor changes to individual interfaces, but are generally backwards compatible.
  • Revision releases include bug fixes and other changes that do not affect public interfaces.

◆ ch_group_get_frequency()

uint32_t ch_group_get_frequency ( ch_group_t grp_ptr)

Get the operating frequency for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group

This function returns the nominal acoustic operating frequency for a group of sensors whose frequencies have been adjusted using ch_group_set_frequency(). A return value of zero indicates that no group frequency has been set.

In general, the actual operating frequency for each device will vary slightly from the nominal group value. Use ch_get_frequency() to obtain the adjusted operating frequency for an individual sensor.

Returns
Group nominal frequency, in Hz, or zero if no group frequency has been set

See also ch_group_set_frequency(), ch_get_frequency().

Note
For CH101 and CH201 sensors, this function is only available in select sensor firmware versions.

◆ ch_group_get_pmut_clock_freq()

uint32_t ch_group_get_pmut_clock_freq ( ch_group_t grp_ptr)

Get the transducer clock input frequency for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t sensor group descriptor structure
Returns
frequency of group transducer clock signal in Hz, or zero if no shared clock

This function is used only in designs in which the ultrasonic transducers (PMUTs) of multiple sensors in a group share a clock source. The clock source may be output from one of the sensors, or it may be from an independent signal source. (See ch_set_pmut_clock().)

This function returns the frequency of the group PMUT clock signal, in Hz, regardless of its source. The returned frequency will be zero if no sensor is outputting a clock signal and no independent clock rate has been specified using ch_set_pmut_clock_freq().

The sensors operate at an acoustic frequency of 1/16 the PMUT clock rate. For example, if the reported clock rate is 800 kHz, the sensors are operating at 50 kHz.

See also ch_group_set_pmut_clock_freq(), ch_set_pmut_clock().

Note
This feature is not available on CH101 or CH201 sensors.

◆ ch_group_init()

uint8_t ch_group_init ( ch_group_t grp_ptr,
uint8_t  num_devices,
uint8_t  num_buses,
uint16_t  rtc_cal_pulse_ms 
)

Initialize the group descriptor for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group to join
num_devicesnumber of the device within the sensor group
num_devicesnumber of the buses the sensors use
rtc_cal_pulse_msLength of the pulse used to calibrate the sensors RTC
Returns
0 if success, 1 if error

This function is used to initialize few group structure field before initializing sensors

Generally, an application will require only one ch_group_t structure to manage all Chirp sensors.

Note
This function only performs internal initialization of data structures, etc. It does not actually initialize the physical sensor device(s). See ch_group_start(), ch_restart(), and ch_group_restart().

◆ ch_group_reset()

void ch_group_reset ( ch_group_t grp_ptr,
ch_reset_t  reset_type 
)

Reset a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for this group of sensors
reset_typetype of reset (CH_RESET_HARD or CH_RESET_SOFT)

This function resets all sensors in a sensor group. The reset_type parameter indicates if a software reset or full hardware reset is requested.

◆ ch_group_restart()

uint8_t ch_group_restart ( ch_group_t grp_ptr)

Restart a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group to be restarted
Returns
0 if successful, 1 if error

This function performs a re-start of a group of sensors that have previously been initialized and started.

Each sensor will be reprogrammed with firmware (as specified in the most recent call to ch_init()) and then will be started and configured. The sensors will not perform the normal calibration steps (including clock calibration) - they will instead use the values saved by a previous initialization.

After this routine returns successfully, the sensors should be ready to resume measurements.

See also ch_restart(), ch_group_start().

◆ ch_group_set_frequency()

uint8_t ch_group_set_frequency ( ch_group_t grp_ptr,
uint32_t  request_op_freq_hz 
)

Set the operating frequency for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group
request_op_freq_hzrequested operating frequency in Hz, or zero to use group avg
Returns
0 if success, 1 if error

This function requests a desired acoustic operating frequency for a group of sensors. This is the primary frequency of the ultrasonic pulse that is emitted by each device when transmitting.

When a group of sensors are used in paired pitch/catch operation, it is often helpful to set them to a common acoustic operating frequency. A better frequency match between the transmitting and receiving sensors improves the range and reliability.

All sensors in the group must be the same production model (part number). It is not possible to set the frequency to a value that is outside the typical operating frequency range for the sensor model.

If the request_op_freq_hz parameter is CH_OP_FREQ_USE_AVG (zero), all sensors will be set to the average of the unadjusted operating frequencies for the group, which generally gives the best performance. After this call returns, you may use ch_group_get_frequency() to determine the average frequency that was used.

If request_op_freq_hz is non-zero, the specified frequency in Hz will be applied to all sensors. Use this option to request a certain operating frequency for all sensors, regardless of their natural operating frequencies.

In general, the actual operating frequency for each device will vary slightly from the requested value or calculated average frequency. The nominal group operating frequency may be obtained by using ch_group_get_frequency(). To determine the actual operating frequency for each individual sensor, use ch_get_frequency().

See also ch_group_get_frequency(), ch_set_frequency().

Note
For CH101 and CH201 sensors, this function is only available in select sensor firmware versions.

◆ ch_group_set_pmut_clock_freq()

void ch_group_set_pmut_clock_freq ( ch_group_t grp_ptr,
uint32_t  pmut_clock_freq 
)

Specify the transducer clock input frequency for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t sensor group descriptor structure
pmut_clock_freqfrequency of input clock signal, in Hz
Returns
0 if success, 1 if error

This function is used only in unusual designs in which the ultrasonic transducers (PMUTs) of multiple sensors share an independent, external clock source. This function is not needed if the sensors each use their own clock (the default) or if one sensor supplies the PMUT clock signal for others. (See ch_set_pmut_clock().)

This function specifies the frequency of the external clock signal, in Hz. The sensors will operate at an acoustic frequency of 1/16 the input clock rate. For example, if the input clock rate is 800 kHz, the sensor will operate at 50 kHz.

The input clock rate must be appropriate for the specific sensor model being used. Radical shifts in operating frequency are not possible.

The input clock signal must be present, and this function must be called to specify the frequency before ch_set_pmut_clock() is used to enable the external clock input for any sensors.

Only one shared PMUT clock signal can be used within a sensor group.

See also ch_group_get_pmut_clock_freq(), ch_set_pmut_clock().

Note
This feature is not available on CH101 or CH201 sensors.

◆ ch_group_start()

uint8_t ch_group_start ( ch_group_t grp_ptr)

Program and start a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group to be started
Returns
0 if successful, 1 if error

This function performs the actual discovery, programming, and initialization sequence for all sensors within a sensor group. Each sensor must have previously been added to the group by calling ch_init().

In brief, this function does the following for each sensor:

  • Probe the possible sensor ports using SPI/I2C bus and each sensor's PROG line, to discover if sensor is connected.
  • Reset sensor.
  • Program sensor with firmware (version specified during ch_init()).
  • For CH101/CH201 sensors only, assign unique I2C address to sensor (specified by board support package, see chbsp_i2c_get_info()).
  • Start sensor execution.
  • Wait for sensor to lock (complete initialization, including self-test).
  • Send timed pulse on INT line to calibrate sensor Real-Time Clock (RTC).

After this routine returns successfully, the sensor configuration may be set and ultrasonic measurements may begin.

See also ch_init(), ch_restart(), ch_group_restart().

Note
When the sensor is programmed, the entire sensor firmware image is normally written in a single, large SPI/I2C transfer. To limit the size of this transfer for a specific hardware platform, define the MAX_PROG_XFER_SIZE symbol in the chirp_board_config.h header file. For more information, see chirp_bsp.h.

◆ ch_group_trigger()

void ch_group_trigger ( ch_group_t grp_ptr)

Trigger a measurement on a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for this group of sensors

This function generates a pulse on the INT line for each sensor in the sensor group. If a sensor is in either CH_MODE_TRIGGERED_TX_RX or CH_MODE_TRIGGERED_RX_ONLY mode, this pulse will begin a measurement cycle.

If a two or more sensors are operating in pitch-catch mode (in which one transmits and the others receive), this function must be used to start a measurement cycle, so that the devices are synchronized.

To trigger a single sensor, use ch_trigger().

Note
Do not trigger a new measurement until the previous measurement has completed and all needed data has been read from the device (including I/Q data, if ch_get_iq_data() is used). If any I/O operations are still active, the new measurement may be corrupted.

◆ ch_init()

uint8_t ch_init ( ch_dev_t dev_ptr,
ch_group_t grp_ptr,
uint8_t  dev_num,
ch_fw_init_func_t  fw_init_func 
)

Initialize the device descriptor for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
grp_ptrpointer to the ch_group_t descriptor for sensor group to join
dev_numnumber of the device within the sensor group (identifies which physical sensor)
fw_init_funcpointer to the sensor firmware initialization function (determines sensor feature set)
Returns
0 if success, 1 if error

This function is used to initialize various Chirp SonicLib structures before using a sensor. The ch_dev_t device descriptor is the primary data structure used to manage a sensor, and its address will subsequently be used as a handle to identify the sensor when calling most API functions.

The dev_ptr parameter is the address of the ch_dev_t descriptor structure that will be initialized and then used to identify and manage this sensor. The grp_ptr parameter is the address of a ch_group_t structure describing the sensor group that will include the new sensor. Both the ch_dev_t structure and the ch_group_t structure must have already been allocated before this function is called.

A separate ch_dev_t structure must be allocated for each sensor.

dev_num is a simple index value that uniquely identifies a sensor within a group. Each possible sensor (i.e. each physical port on the board that could have a Chirp sensor attached) has a number, starting with zero (0). The device number is constant - it remains associated with a specific port even if no sensor is actually attached. Often, the dev_num value is used by both the application and the board support package as an index into arrays containing per-sensor information (e.g. data read from the sensors, pin assignments, etc.).

The Chirp sensor is fully re-programmable, and the specific features and capabilities can be modified by using different sensor firmware images. The fw_init_func parameter is the address (name) of the sensor firmware initialization routine that should be used to program the sensor and prepare it for operation. The selection of this routine name is the only required change when switching from one sensor firmware image to another.

Note
This function only performs internal initialization of data structures, etc. It does not actually initialize the physical sensor device(s). See ch_group_start(), ch_restart(), and ch_group_restart().

Initialize the device descriptor for a sensor.

Parameters
dev_ptra pointer to the ch_dev_t config structure for a sensor
Returns
0 (RET_OK) if successful, non-zero otherwise

◆ ch_init_algo()

uint8_t ch_init_algo ( ch_dev_t dev_ptr)

Initialize the measurement algorithm on a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_info_ptrpointer to a ICU_ALGO_SHASTA_INFO structure to receive info
Returns
0 if success, 1 if error

This function initializes a measurement algorithm that has been loaded into a sensor and configured.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware. It is not used directly in a typical application.

See also ch_meas_import(), ch_get_algo_state().

◆ ch_interrupt()

void ch_interrupt ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Run SonicLib's full-featured interrupt handler.

Parameters
grp_ptrpointer to the ch_group_t sensor group descriptor structure
dev_numdevice number within group for interrupting sensor

This function is used from the board support package (BSP) handler routine for the sensor interrupt to announce that the interrupt has occurred. dev_num identifies which sensor has interrupted.

The SonicLib driver layer will handle further processing of the interrupt, including disabling the interrupt processing (to allow for next trigger), reading sensor metadata, and calling the application-supplied callback function.

Only one of ch_interrupt() and ch_minimal_int_handler() should be called. The latter function is a simplified handler that gives the user more control of exactly what happens during the interrupt handling.

Note
Upon return from this routine, the sensor interrupt is disabled.

See also ch_io_int_callback_set() and ch_minimal_int_handler().

Run SonicLib's full-featured interrupt handler.

This function is used from the board support package (BSP) handler routine for the sensor interrupt to notify SonicLib that the interrupt has occurred. The SonicLib driver layer will handle further processing of the interrupt, including a call to the application-supplied callback function.

◆ ch_io_complete_callback_set()

void ch_io_complete_callback_set ( ch_group_t grp_ptr,
ch_io_complete_callback_t  callback_func_ptr 
)

Register non-blocking I/O complete callback routine for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t group descriptor structure
callback_func_ptrpointer to callback function to be called when non-blocking I/O operations complete

This function registers the routine specified by callback_func_ptr to be called when all outstanding non-blocking I/O operations complete for a group of sensors. The non-blocking I/O operations must have previously been initiated using ch_io_start_nb().

Register non-blocking I/O complete callback routine for a group of sensors.

Note

◆ ch_io_int_callback_set()

void ch_io_int_callback_set ( ch_group_t grp_ptr,
ch_io_int_callback_t  callback_func_ptr 
)

Register sensor interrupt callback routine for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t sensor group descriptor structure
callback_func_ptrpointer to callback function to be called when sensor interrupts

This function registers the routine specified by callback_func_ptr to be called whenever the sensor interrupts. Generally, such an interrupt indicates that a measurement cycle has completed and the sensor has data ready to be read. All sensors in a sensor group use the same callback function, which receives the interrupting device's device number (port number) as an input parameter to identify the specific interrupting device. The callback function also receives the ch_interrupt_type_t interrupt type parameter that identifies the type (reason) for the sensor interrupt).

Register sensor interrupt callback routine for a group of sensors.

Note

◆ ch_io_notify()

void ch_io_notify ( ch_group_t grp_ptr,
uint8_t  i2c_bus_index 
)

Notify SonicLib that a non-blocking I/O operation has completed.

Parameters
grp_ptrpointer to the ch_group_t sensor group descriptor structure
bus_indexidentifier indicating on which SPI/I2C bus the I/O operation was completed

This function should be called from your non-blocking I/O interrupt handler each time a non-blocking I/O operation completes. The bus_index parameter should indicate which SPI/I2C bus is being reported.

When all outstanding non-blocking I/O operations are complete, SonicLib will call the callback function previously registered using ch_io_complete_callback_set().

Notify SonicLib that a non-blocking I/O operation has completed.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
i2c_bus_indexindex value identifying I2C/SPI bus within group

Call this function once from your I2C interrupt handler each time it completes an I/O operation. It will call the function previously specified during ch_io_complete_callback_set() when all group transactions are complete.

◆ ch_io_start_nb()

uint8_t ch_io_start_nb ( ch_group_t grp_ptr)

Start non-blocking I/O operation(s) for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor for sensor group
Returns
0 if success, 1 if error

This function starts one or more non-blocking I/O operations on a group of sensors. Generally, the I/O operations are non-blocking I/Q data read requests individually generated using ch_get_iq_data().

This function will return immediately after the I/O operations are started. When the I/O operations complete, the callback function registered using ch_io_complete_callback_set() will be called.

See ch_get_iq_data() for more information.

Start non-blocking I/O operation(s) for a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors

This function starts a non-blocking I/O operation on the specified group of sensors.

◆ ch_iq_to_amplitude()

uint16_t ch_iq_to_amplitude ( ch_iq_sample_t iq_sample_ptr)

Calculate amplitude from sample I/Q values.

Parameters
iq_sample_ptrpointer to ch_iq_data_t structure containing the I/Q data
Returns
Amplitude value

This function converts the I and Q values from a single raw sensor sample to an amplitude value according to the following formula:

\[Amp = \sqrt{(I)^2 + (Q)^2}\]

Amplitude values in the sensor are expressed only in internal ADC counts (least-significant bits, or LSBs) and are not calibrated to any standard units.

See also ch_get_iq_data(), ch_get_amplitude_data().

◆ ch_log_append()

void ch_log_append ( uint8_t  log_id,
ch_log_fmt_t  format,
uint64_t  timestamp,
ch_log_data_t log_data_ptr 
)

Append received sensor data to log.

Parameters
log_idlog ID to specify the log to use
formatformat of the log
timestampcurrent time in us
log_data_ptrpointer to log data structure that contains the log data

This function appends received sensor data (including I/Q data) to the log in the specified log format. The function takes a new Log ID returns by ch_log_init() function to specify the log to use.

The function should be used when the previous measurement has completed and all needed data has been read from the device (including I/Q data)

◆ ch_log_init()

uint8_t ch_log_init ( ch_group_t grp_ptr,
ch_log_fmt_t  format,
ch_log_cfg_t config_ptr 
)

Initialize a log in the specified log format.

Parameters
grp_ptrpointer to the ch_group_t descriptor for this group of sensors
formatformat of the log. For example, CH_LOG_FMT_REDSWALLOW
config_ptrpointer to log config structure that contains the input values of the log
Returns
a Log ID value to be used later when appending the log

This function initializes a sensor data log in the specified log format.

◆ ch_meas_activate()

void ch_meas_activate ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Activate a defined measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_numnumber of measurement to activate

This function sets a measurement to active mode. The specified measurement definition will be used when the sensor makes a measurement. The measurement must have previously been defined, either by using ch_meas_init() and related calls to specify the measurement segments, or by importing a complete measurement definition.

If the measurement specified by meas_num was previously in standby mode (inactive), it is made active. In all cases, this definition will be used during the the next measurement performed by the sensor, even if the other measurement is also active.

This function does not affect the active vs. standby status of the other measurement. If both measurements are active after calling this function, they will alternate each time the sensor performs a measurement.

See also ch_meas_standby(), ch_meas_switch(), ch_meas_init(), ch_meas_import().

Note
This feature is only available for ICU sensors.

◆ ch_meas_add_segment()

uint8_t ch_meas_add_segment ( ch_dev_t dev_ptr,
uint8_t  meas_num,
ch_meas_segment_t seg_ptr 
)

Add a segment to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
seg_ptrpointer to measurement segment to be added
Returns
0 if success, 1 if error

This function adds a measurement segment to the measurement specified by meas_num. seg_ptr points to a segment descriptor, which must have already been initialized.

See also ch_meas_add_segment_tx(),ch_meas_add_segment_rx(), ch_meas_init_segment_tx(), ch_meas_init_segment_rx(),

◆ ch_meas_add_segment_count()

uint8_t ch_meas_add_segment_count ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_cycles,
uint8_t  int_enable 
)

Add a count (delay) segment to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
num_cycleslength of the segment, in cycles
int_enableif non-zero, the sensor will interrupt at the completion of this segment
Returns
0 if success, 1 if error

This function adds a count (delay) segment to the measurement specified by meas_num. Such a segment does not transmit a signal nor does it sample received ultrasound. So, no samples are associated with this portion of the measurement time.

This function combines the operations of ch_meas_init_segment_count() and ch_meas_add_segment().

◆ ch_meas_add_segment_rx()

uint8_t ch_meas_add_segment_rx ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_samples,
uint8_t  gain_reduce,
uint8_t  atten,
uint8_t  int_enable 
)

Add a receive segment to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
num_sampleslength of the segment, in sample periods
gain_reducegain reduction value, 0 = max gain
attenattenuation level
int_enableif non-zero, the sensor will interrupt at the completion of this segment
Returns
0 if success, 1 if error

This function adds a receive segment to the measurement specified by meas_num. It combines the operations of ch_meas_init_segment_rx() and ch_meas_add_segment().

◆ ch_meas_add_segment_tx()

uint8_t ch_meas_add_segment_tx ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_cycles,
uint8_t  pulse_width,
uint8_t  phase,
uint8_t  int_enable 
)

Add a transmit segment to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
num_cycleslength of the segment, in cycles
pulse_widthtransmit pulse width
phasetransmit phase
int_enableif non-zero, the sensor will interrupt at the completion of this segment
Returns
0 if success, 1 if error

This function adds a transmit segment to the measurement specified by meas_num. It combines the operations of ch_meas_init_segment_tx() and ch_meas_add_segment().

The cycles parameter specifies the overall length of the transmit pulse that will be generated. The units are internal sensor cycles.

See also ch_meas)add_segment_rx(), ch_meas_add_segment_count(), ch_usec_to_cycles().

◆ ch_meas_get_info()

void ch_meas_get_info ( ch_dev_t dev_ptr,
uint8_t  meas_num,
ch_meas_info_t info_ptr 
)

Get configuration information for a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
info_ptrpointer to ch_meas_info_t structure to be updated
Returns
0 if success, 1 if error

This function obtains configuration information for the measurement specified by meas_num. The ch_meas_info_t structure specified by info_ptr will be completed with the settings for the measurement, including:

  • mode - whether the measurement is active or in standby mode
  • num_segments - number of active segments in measurement
  • num_samples - total number of sample periods in all segments
  • num_ranges - maximum number of separate target range values to report
  • odr - output data rate for the sensor (time between samples within measurement)
  • meas_period - repeat period for measurement (0 if not used)
  • ringdown_cancel_samples - number of samples close to sensor to use ringdown cancellation filter
  • static_filter_samples - number of samples close to sensor to have static target rejection (STR) filter
  • iq_output_format - 0=normal (Q,I) pairs; 1=mag,threshold pairs, 2=mag,phase pairs
  • filter_update_interval - how often to update the ringdown and STR filters

◆ ch_meas_get_interval()

uint16_t ch_meas_get_interval ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the repeat interval for a measurement, in milliseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
sensor measurement interval

This function returns the internal measurement interval in the sensor, in milliseconds.

See also ch_meas_set_interval(), ch_get_freerun_interval().

◆ ch_meas_get_interval_ticks()

uint32_t ch_meas_get_interval_ticks ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the repeat interval for a measurement, in sensor RTC clock ticks.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
sensor measurement interval

This function returns the internal measurement interval in the sensor, in sensor RTC clock periods.

See also ch_meas_set_interval_ticks().

◆ ch_meas_get_interval_us()

uint32_t ch_meas_get_interval_us ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the repeat interval for a measurement, in microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
sensor measurement interval

This function returns the internal measurement interval in the sensor, in microseconds.

See also ch_meas_set_interval_us().

◆ ch_meas_get_iq_output()

ch_output_type_t ch_meas_get_iq_output ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the I/Q data output format for a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
Returns
I/Q data output format

This function returns the measurement I/Q data output format, as follows:

  • CH_OUTPUT_IQ (0) - Standard pairs of {Q,I} int16_t values
  • CH_OUTPUT_AMP_THRESH (1) - Output amplitude + threshold uint16_t pair values
  • CH_OUTPUT_AMP (2) - Output uint16_t amplitude values only

See also ch_meas_set_iq_output().

◆ ch_meas_get_last_num()

uint8_t ch_meas_get_last_num ( ch_dev_t dev_ptr)

Get number of last completed measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function returns the measurement number (0 or 1) for the last measurement that completed. It is useful if both measurements are active and are being executed alternately.

Note
This feature is only available for ICU sensors.

◆ ch_meas_get_max_range()

uint16_t ch_meas_get_max_range ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the maximum range setting in mm for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
Returns
Maximum range setting, in millimeters

This function returns the current maximum detection range setting for the specified measurement, in millimeters.

The ch_get_max_range() function performs the same operation for the default measurement (same as setting meas_num to CH_DEFAULT_MEAS_NUM).

See also ch_meas_set_max_range(), ch_meas_get_num_samples().

◆ ch_meas_get_num_samples()

uint16_t ch_meas_get_num_samples ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the number of samples per measurement cycle for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor struct
meas_nummeasurement number
Returns
Number of samples per measurement cycle

This function returns the configured number of samples which the Chirp sensor will obtain during each measurement cycle for the specified measurement. The number of samples directly corresponds to the range at which the sensor can detect, so this value is determined by the current maximum range setting for the sensor.

The ch_get_num_samples() function may be used to obtain the number of samples in the most recently completed measurement.

See also ch_meas_get_max_range(), ch_get_num_output_samples().

◆ ch_meas_get_odr()

ch_odr_t ch_meas_get_odr ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get the output data rate for a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
Returns
ODR setting

This function returns the output data rate (ODR) for the sensor. The ODR setting determines the spacing in time (and therefore in measured distance) between the individual samples within a measurement.

See also ch_meas_set_odr().

◆ ch_meas_get_queue()

uint8_t ch_meas_get_queue ( ch_dev_t dev_ptr,
measurement_queue_t *  meas_queue_ptr 
)

Get measurement queue values for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_queue_ptrpointer to location to receive measurement queue values
Returns
0 if success, 1 if error

This function copies the current measurement queue values for a sensor to the measurement_queue_t structure specified by meas_queue_ptr.

This function may be used to save the original measurement queue values before calling ch_meas_import() or ch_meas_optimize().

See also ch_meas_write_config().

Note
This feature is only available for ICU sensors.

◆ ch_meas_get_queue_info()

void ch_meas_get_queue_info ( ch_dev_t dev_ptr,
ch_meas_queue_info_t info_ptr 
)

Get configuration information for the sensor measurement queue.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
info_ptrpointer to ch_meas_queue_info_t structure to be updated
Returns
0 if success, 1 if error

This function obtains configuration information for the sensor's measurement queue. The measurement queue contains all defined measurements plus common configuration settings. The ch_meas_queue_info_t structure specified by info_ptr will be completed with the settings for the measurement queue, including:

  • int_config - interrupt pin selection
  • meas_start - which measurement do we start on
  • meas_stop - which measurement do we stop on
  • current_meas - which measurement do we do next
  • trig_src - trigger source: INT1, INT2, or internal timer

◆ ch_meas_get_seg_info()

void ch_meas_get_seg_info ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint8_t  seg_num,
ch_meas_seg_info_t info_ptr 
)

Get configuration information for a measurement segment.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
seg_numsegment number
info_ptrpointer to ch_meas_seg_info_t structure to be updated
Returns
0 if success, 1 if error

This function obtains configuration information for the measurement segment specified by meas_num and seg_num.

The ch_meas_seg_info_t structure specified by info_ptr will be completed with the settings for the measurement segment, including:

  • num_rx_samples - length in sample periods (determined by num_cycles and output data rate)
  • num_cycles - length in cycles
  • rdy_int_en - sensor will interrupt when ready
  • done_int_en - sensor will interrupt when done with segment
  • tx_phase - phase (transmit segments only)
  • tx_pulse_width - pulse width (transmit segments only)
  • rx_gain_reduce - gain reduction (receive segments only)
  • rx_atten - attenuation (receive segments only)

◆ ch_meas_get_status()

ch_meas_status_t ch_meas_get_status ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Get measurement status.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
Returns
status

This function returns the current measurement status in the sensor. It may be used to help determine if valid measurement I/Q data can be read from the sensor.

A status value of CH_MEAS_STATUS_DONE indicates that complete measurement data is available for reading. A value of CH_MEAS_STATUS_PENDING indicates that a measurement is in progress, and the current data values should not be used.

Note that this routine only reports the status at the time it is called.

See also ch_trigger(), ch_trigger_soft().

Note
For CH101 and CH201 sensors, meas_num should be set to CH_DEFAULT_MEAS_NUM.
This function is only available in select Chirp sensor firmware versions.

◆ ch_meas_import()

uint8_t ch_meas_import ( ch_dev_t dev_ptr,
measurement_queue_t *  meas_queue_ptr,
void *  algo_cfg_ptr 
)

Import an externally defined measurement configuration.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_queue_ptrpointer to a complete measurement queue structure, or NULL
algo_cfg_ptrpointer to a buffer containing algorithm configuration, or NULL
Returns
0 if success, 1 if error

This function allows a fully defined measurement queue structure (measurement_queue_t) and algorithm-specific configuration to be imported as a unit. Taken together, these two structures fully define the measurement to be performed.

Alternatively, it is possible to import either the measurement queue or the algorithm configuration individually, by supplying a NULL pointer for the other structure. In this case, the current settings will continue to be used for the values specified in the other structure. An error is returned if both pointers are NULL.

The format of the algorithm configuration data will vary depending on the sensor firmware and algorithm that are being used.

See also ch_meas_optimize(), which combines importing and optimizing a measurement queue.

◆ ch_meas_init()

uint8_t ch_meas_init ( ch_dev_t dev_ptr,
uint8_t  meas_num,
const ch_meas_config_t meas_config_ptr,
const void *  thresh_ptr 
)

Initialize a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
meas_config_ptrpointer to measurement configuration settings
thresh_ptrdeprecated. Parameter not used. Shall be set to NULL
Returns
0 if success, 1 if error

This function initializes the measurement specified by meas_num with the specified configuration. meas_config_ptr is a pointer to a ch_meas_config_t structure which must have already been initialized. The fields in this structure specify various parameters for the measurement including

  • odr - output data rate for the sensor (time between samples within measurement)
  • meas_period - repeat period for measurement, in ticks (optional, freerun interval may be set later)
  • mode - if CH_MEAS_MODE_STANDBY, this measurement will initially be put in standby mode (not active), if CH_MEAS_MODE_ACTIVE (zero), this measurement will initially be active and will be performed

thresh_ptr was used to initialize GPT thresholds. Now use icu_gpt_algo_configure() to configure algo.

◆ ch_meas_init_queue()

uint8_t ch_meas_init_queue ( ch_dev_t dev_ptr)

Initialize the sensor measurement queue.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function resets and re-initializes the sensor measurement queue. All configuration settings and all measurements are cleared.

◆ ch_meas_init_segment_count()

void ch_meas_init_segment_count ( ch_meas_segment_t seg_ptr,
uint16_t  num_cycles,
uint8_t  int_enable 
)

Initialize a count (delay) measurement segment.

Parameters
seg_ptrpointer to the ch_meas_segment_t descriptor structure to be initialized
num_cycleslength of the segment, in cycles
int_enableif non-zero, the sensor will interrupt at the completion of this segment

This function initializes the measurement segment descriptor specified by seg_ptr as a count (delay) segment. Such a segment does not transmit a signal nor does it sample received ultrasound. So, no samples are associated with this portion of the measurement time.

The cycles parameter specifies the overall length of the delay. The units are internal sensor cycles. Use the ch_usec_to_cycles() function to calculate the number of cycles for a specific delay duration.

Returns
0 if success, 1 if error

◆ ch_meas_init_segment_rx()

void ch_meas_init_segment_rx ( ch_meas_segment_t seg_ptr,
uint16_t  num_samples,
ch_odr_t  odr,
uint8_t  gain_reduce,
uint8_t  atten,
uint8_t  int_enable 
)

Initialize a receive measurement segment.

Parameters
seg_ptrpointer to the ch_meas_segment_t descriptor structure to be initialized
num_sampleslength of the segment, in sample periods
odroutput data rate setting to be used (set during ch_meas_init())
gain_reducegain reduction value, 0 = max gain
attenattenuation level
int_enableif non-zero, the sensor will interrupt at the completion of this segment
Returns
0 if success, 1 if error

This function initializes the measurement segment descriptor specified by seg_ptr as a receive segment. The number of samples of added to the segments is limited by the maximum number of rx samples that firmware can read and by the number of cycles a segment can store. The length of segment in samples is converted to a number of cycles. A segment have a maximum length of 65535 cycles. If the number of sample exceeds the limitation, define the segments manually and import them to a measure queue using ch_meas_import()

◆ ch_meas_init_segment_tx()

void ch_meas_init_segment_tx ( ch_meas_segment_t seg_ptr,
uint16_t  num_cycles,
uint8_t  pulse_width,
uint8_t  phase,
uint8_t  int_enable 
)

Initialize a transmit measurement segment.

Parameters
seg_ptrpointer to the ch_meas_segment_t descriptor structure to be initialized
num_cycleslength of the segment, in cycles
pulse_widthtransmit pulse width
phasetransmit phase
int_enableif non-zero, the sensor will interrupt at the completion of this segment
Returns
0 if success, 1 if error

This function initializes the measurement segment descriptor specified by seg_ptr as a transmit segment.

The cycles parameter specifies the overall length of the transmit pulse that will be generated. The units are internal sensor cycles.

See also ch_meas_init_segment_rx(), ch_meas_init_segment_count(), ch_usec_to_cycles().

◆ ch_meas_insert_instruction()

uint8_t ch_meas_insert_instruction ( ch_dev_t dev_ptr,
uint8_t  meas_num,
const ch_meas_segment_t inst_ptr,
uint8_t  index_to_insert 
)

Insert an instruction(segment) to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
inst_ptrpointer to measurement instruction(segment) to be inserted
index_to_insertinstruction(segment) number to be remove
Returns
0 if success, 1 if error

This function inserts a measurement instruction(segment) to the measurement specified by meas_num. inst_ptr points to an instruction(segment) descriptor, which must have already been initialized.

◆ ch_meas_insert_segment()

uint8_t ch_meas_insert_segment ( ch_dev_t dev_ptr,
uint8_t  meas_num,
const ch_meas_segment_t inst_ptr,
uint8_t  index_to_insert 
)

Insert an instruction(segment) to a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
inst_ptrpointer to measurement instruction(segment) to be inserted
index_to_insertinstruction(segment) number to be inserted
Returns
0 if success, 1 if error

This function inserts a measurement instruction(segment) to the measurement specified by meas_num. inst_ptr points to an instruction(segment) descriptor, which must have already been initialized.

Will be deprecated by the new equivalent function ch_meas_insert_instruction.

◆ ch_meas_mm_to_samples()

uint16_t ch_meas_mm_to_samples ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_mm 
)

Convert millimeters to sample count for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
num_mmnumber of millimeters to be converted
Returns
Number of samples

This function converts the distance in millimeters specified by num_mm and converts it to the corresponding number of sensor samples for a specific measurement number. The conversion uses values set during device initialization and calibration that describe the internal timing of the sensor, which affects how many samples correspond to a given distance.

Note
In ICU sensors, the ODR is configurable. The default is one sample per 8 transceiver cycles (CH_ODR_FREQ_DIV_8, also known as CH_ODR_DEFAULT). If the default ODR will not be not used, the new ODR must be set for the specified measurement before this function is called, either as a standard parameter during ch_meas_init(), or by calling ch_meas_set_odr().

The ch_mm_to_samples() function performs the same operation for the default measurement (same as setting meas_num to CH_DEFAULT_MEAS_NUM).

See also ch_samples_to_mm(), ch_meas_set_odr().

◆ ch_meas_optimize()

uint8_t ch_meas_optimize ( ch_dev_t dev_ptr,
measurement_queue_t *  meas_queue_ptr,
void *  algo_cfg_ptr 
)

Optimize ultrasound measurement sequences for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_queue_ptrpointer to measurement queue to optimize, or NULL
algo_cfg_ptrpointer to a buffer containing algorithm configuration, or NULL
Returns
0 if success, 1 if error

This function optimizes the transmit sequences during measurements for a sensor. The original transmit segments are replaced by a longer sequence that is tuned to the specific sensor. In particular, the "ringdown" in the sensor following a transmission is actively reduced. The sensor is able to receive the echo signal sooner, thus permitting measurements at closer distances.

Optimization is performed on a defined measurement, such as the result of combining measurement segments using ch_meas_add_segment() etc. These segments are part of the "measurement queue" for the sensor.

To optimize the current measurement settings and make no other changes to the configuration, specify NULL for both meas_queue_ptr and algo_cfg_ptr.

Alternatively, a new measurement queue may be imported, optimized, and applied using this function, similar to the ch_meas_import() function (e.g. to use an exported measurement queue definition from the SonicLink development kit). In this case, set meas_queue_ptr to the location containing the measurement queue to be optimized. The new measurement queue will be optimized, and the resulting settings will be written to the sensor. The input measurement queue definition specified by meas_queue_ptr will not be modified.

The algo_cfg_ptr parameter specifies a new measurement algorithm configuration to be applied. If algo_cfg_ptr is NULL, the current configuration will be left unchanged.

When optimization occurs, the sensor will be briefly re-programmed with special initialization firmware that analyzes the sensor's operation and determines the appropriate optimization. The results are read from the sensor and are combined with the original settings. Finally, the measurement firmware is again programmed into the sensor, and the new settings are applied. This entire sequence will typically take about 250 ms to complete.

Note
A single set of measurement queue values should only be optimized once, because new transmit segments will be inserted each time. If your application needs to perform optimization periodically, it should maintain a copy of the original measurement queue values (before optimization) and pass that in again during each call to this function. A copy of the internal measurement_queue_t structure can be obtained using ch_meas_get_queue().
This feature is only available for ICU sensors.

See also ch_meas_import(), ch_meas_get_queue().

◆ ch_meas_remove_instruction()

uint8_t ch_meas_remove_instruction ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint8_t  index_to_remove 
)

Remove an instruction(segment) in a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
index_to_removeinstruction(segment) number to be removed
Returns
0 if success, 1 if error

This function removes a measurement instruction(segment) to the measurement specified by meas_num. inst_ptr points to an instruction(segment) descriptor, which must have already been initialized.

◆ ch_meas_remove_segment()

uint8_t ch_meas_remove_segment ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint8_t  index_to_remove 
)

Remove an instruction(segment) in a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
index_to_removeinstruction(segment) number to be removed
Returns
0 if success, 1 if error

This function removes a measurement instruction(segment) to the measurement specified by meas_num. inst_ptr points to an instruction(segment) descriptor, which must have already been initialized.

Will be deprecated by the new equivalent function ch_meas_remove_instruction.

◆ ch_meas_reset()

uint8_t ch_meas_reset ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Reset a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
Returns
0 if success, 1 if error

This function resets and re-initializes the measurement specified by meas_num. All segments in the measurement are removed.

After calling this function, transmit and receive segments may be added to the measurement. See ch_meas_add_segment().

◆ ch_meas_samples_to_mm()

uint16_t ch_meas_samples_to_mm ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_samples 
)

Convert sample count to millimeters for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
num_samplessample count to be converted
Returns
Number of millimeters

This function converts the sample count specified in num_samples and converts it to the corresponding physical distance in millimeters for the specified measurement. The conversion uses values set during device initialization and calibration that describe the internal timing of the sensor.

This function may be helpful when working with both physical distances (as reported by the ch_get_range() function) and sample-oriented values, such as data obtained from ch_get_iq_data() or parameters for static target rejection (see ch_set_static_range()).

Note
The number of samples corresponding to a certain distance is determined by the ODR (output data rate) for the sensor, which is the rate at which the received ultrasound is sampled within each measurement. So, the ODR must be known to calculate this conversion.
In ICU sensors, the ODR is configurable. The default is one sample per 8 transceiver cycles (CH_ODR_FREQ_DIV_8, also known as CH_ODR_DEFAULT). If the default ODR will not be not used, the new ODR must be set for the specified measurement before this function is called, either as a standard parameter during ch_meas_init(), or by calling ch_meas_set_odr().

The ch_samples_to_mm() function performs the same operation for the default measurement (same as setting meas_num to CH_DEFAULT_MEAS_NUM).

See also ch_mm_to_samples(), ch_meas_set_odr().

◆ ch_meas_set_interval()

uint8_t ch_meas_set_interval ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  interval_ms 
)

Set the repeat interval for a measurement, in milliseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
interval_msmeasurement interval, in milliseconds
Returns
0 if success, 1 if error

This function sets the internal measurement interval in the sensor. The sensor will perform a measurement every interval_ms milliseconds. No external trigger is required.

To set the sensing interval with greater precision, use ch_meas_set_interval_us() or ch_meas_set_interval_ticks().

See also ch_set_freerun_interval(), ch_meas_get_interval().

◆ ch_meas_set_interval_ticks()

uint8_t ch_meas_set_interval_ticks ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint32_t  rtc_ticks 
)

Set the repeat interval for a measurement, in sensor RTC clock ticks.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
rtc_ticksmeasurement interval, in sensor RTC clock periods
Returns
0 if success, 1 if error

This function sets the internal measurement interval in the sensor. The sensor will perform a measurement every rtc_ticks sensor RTC clock periods. No external trigger is required.

See also ch_meas_set_interval(), ch_meas_get_interval_ticks().

◆ ch_meas_set_interval_us()

uint8_t ch_meas_set_interval_us ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint32_t  interval_us 
)

Set the repeat interval for a measurement, in microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
interval_usmeasurement interval, in microseconds
Returns
0 if success, 1 if error

This function sets the internal measurement interval in the sensor. The sensor will perform a measurement every interval_us microseconds. No external trigger is required.

See also ch_meas_set_interval(), ch_meas_get_interval_ticks().

◆ ch_meas_set_iq_output()

uint8_t ch_meas_set_iq_output ( ch_dev_t dev_ptr,
uint8_t  meas_num,
ch_output_type_t  output_format 
)

Set the I/Q data output format for a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
output_formatI/Q output format 0=normal (Q,I) pairs; 1=amplitude,threshold pairs, 2=amplitude array
Returns
0 if success, 1 if error

This function sets the measurement I/Q data output format. The data may be output in three different formats, based on the value of output_format:

  • CH_OUTPUT_IQ - Standard pairs of {Q,I} int16_t values
  • CH_OUTPUT_AMP_THRESH - Output amplitude + threshold uint16_t pair values
  • CH_OUTPUT_AMP - Output uint16_t amplitude values only

See also ch_meas_get_iq_output(), ch_set_data_output(), ch_meas_init().

◆ ch_meas_set_max_range()

uint8_t ch_meas_set_max_range ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  max_range_mm 
)

Set the maximum range in mm for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_nummeasurement number
max_rangemaximum range, in millimeters
Returns
0 if successful, non-zero if error

This function sets the maximum detection range for the specified measurement, in millimeters. The detection range setting controls how long the sensor will listen (i.e. how many samples it will capture) during each measurement cycle. (The number of samples is automatically calculated for the specified range.)

Note that this function changes the number of samples in an existing measurement. The existing measurement definition will be shortened or extended to match the new sample count. If the measurement is extended, the new samples will use the same settings as in the final receive segment.

The ch_set_max_range() function performs the same operation for the default measurement (same as setting meas_num to CH_DEFAULT_MEAS_NUM).

See also ch_meas_set_num_samples(), ch_meas_get_max_range().

◆ ch_meas_set_num_samples()

uint8_t ch_meas_set_num_samples ( ch_dev_t dev_ptr,
uint8_t  meas_num,
uint16_t  num_samples 
)

Set the sensor sample count for a specific measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor struct
meas_nummeasurement number
num_samplesnumber of samples during each measurement cycle
Returns
0 if successful

This function directly sets the number of samples which the Chirp sensor will obtain during a specific measurement (0 or 1). The number of samples directly corresponds to the range at which the sensor can detect.

Note that this function changes the number of samples in an existing measurement. The existing measurement definition will be shortened or extended to match the new sample count. If the measurement is extended, the new samples will use the same settings as in the final receive segment.

The ch_set_num_samples() function performs the same operation for the default measurement (same as setting meas_num to CH_DEFAULT_MEAS_NUM).

See also ch_meas_set_max_range(), ch_set_num_samples().

◆ ch_meas_set_odr()

uint8_t ch_meas_set_odr ( ch_dev_t dev_ptr,
uint8_t  meas_num,
ch_odr_t  odr 
)

Set the output data rate for a measurement.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function sets the output data rate (ODR) for the sensor. The ODR setting determines the spacing in time (and therefore in measured distance) between the individual sample points within a measurement.

The standard ODR value is CH_ODR_FREQ_DIV_8 (also known as CH_ODR_DEFAULT), or one sample per 8 transceiver cycles. The ODR may be adjusted higher or lower - each higher or value will increase or decrease the output rate (i.e. the time between samples) by a factor of 2. The maximum ODR is CH_ODR_FREQ_DIV_2 (one sample every 2 transceiver cycles); the minimum ODR is CH_ODR_FREQ_DIV_32 (one sample every 32 transceiver cycles).

See also ch_meas_init(), ch_meas_get_odr().

◆ ch_meas_standby()

void ch_meas_standby ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Put a measurement in standby mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_numnumber of measurement to place in standby mode

This function places the specified measurement in standby mode. This measurement's definition will not be used by the sensor - the other measurement definition will be used to perform all readings.

Because there must always be at least one active measurement, this function will activate the other measurement if it was not already active. It is not possible to have both measurements in standby mode simultaneously.

A measurement may be set to initially be in standby mode, see ch_meas_init().

See also ch_meas_activate(), ch_meas_switch().

Note
This feature is only available for ICU sensors.

◆ ch_meas_switch()

uint8_t ch_meas_switch ( ch_dev_t dev_ptr)

Switch active and standby measurement definitions.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_numnumber of measurement to place in standby mode
Returns
measurement number of newly active measurement

This function switches the roles of the two measurement definitions between active and standby. The currently active measurement is put into standby mode, and the standby measurement is made active.

If this function is called when both measurements are active, the next measurement due to operate (the current measurement) will be placed into standby mode, and the other measurement will remain active.

This routine returns the number of the new active measurement. This will be the next measurement performed by the sensor.

See also ch_meas_activate(), ch_meas_standby(), ch_meas_get_info().

Note
This feature is only available for ICU sensors.

◆ ch_meas_time_hop_disable()

uint8_t ch_meas_time_hop_disable ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Disable time-hopping on measure period freerunning mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if successful.

This function disable the time-hopping for a sensor operating in freerunning mode (CH_MODE_FREERUN).

Note
This function has no effect for a sensor operating in one of the triggered modes

See also ch_meas_time_hop_enable(), ch_meas_get_interval_ticks(), ch_meas_set_interval(), ch_meas_set_interval_us(), ch_meas_set_interval_ticks().

◆ ch_meas_time_hop_enable()

uint8_t ch_meas_time_hop_enable ( ch_dev_t dev_ptr,
uint8_t  meas_num 
)

Enable time-hopping on measure period freerunning mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if successful.

This function enables the time-hopping for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal real-time clock (RTC) to wake and perform a measurement every measure interval plus a random delay to avoid coexistence with other sensors. Mean measure period is however equals to measure interval.

Note
This function has no effect for a sensor operating in one of the triggered modes.

See also ch_meas_time_hop_disable(), ch_meas_get_interval_ticks(), ch_meas_set_interval(), ch_meas_set_interval_us(), ch_meas_set_interval_ticks().

◆ ch_meas_write_config()

uint8_t ch_meas_write_config ( ch_dev_t dev_ptr)

Write measurement configuration to sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function writes a complete measurement queue configuration to the sensor device. The measurement queue settings must have already been defined, by using the standard API functions (initializing one or more measurements and adding a sequence of measurement segments).

This function additionally sanitizes the measurement queue by performing several checks to ensure it is compatible with the selected sensor mode. This function potentially modifies the queue, so users should examine the passed queue after loading it.

◆ ch_measure_pmut_frequency()

uint32_t ch_measure_pmut_frequency ( ch_dev_t dev_ptr)

Measure PMUT frequency on an ICU device.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
PMUT operating frequency in Hz

This function must only be called after initialization (ie after calling ch_group_start()).

◆ ch_minimal_int_handler()

uint8_t ch_minimal_int_handler ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Notify SonicLib that a sensor interrupt was received.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
dev_numinterrupting sensor's device number within group
Returns
0 for success, non-zero otherwise.

This function should be called from the board support package when an interrupt from the sensor is received. The dev_num parameter indicates which sensor interrupted.

Unlike ch_interrupt(), this function does not call the user supplied callback. It is intended to be used when the user would like more control of exactly what happens when an interrupt is received from the sensor.

Other differences from ch_interrupt():

  • This function does not disable interrupt handling. This must be done in user code if needed.
  • This function does not read any metadata from the sensor, with one exception. During sensor programming, this funciton performs one SPI read in order to cause the ASIC to release the interrupt line.
  • This function does not update state of the dev_ptr

See also ch_interrupt().

◆ ch_mm_to_samples()

uint16_t ch_mm_to_samples ( ch_dev_t dev_ptr,
uint16_t  num_mm 
)

Convert millimeters to sample count for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_mmnumber of millimeters to be converted
Returns
Number of samples

This function converts the distance in millimeters specified by num_mm and converts it to the corresponding number of sensor samples. The conversion uses values set during device initialization and calibration that describe the internal timing of the sensor, which affects how many samples correspond to a given distance.

This function may be helpful when working with both physical distances (as reported by the ch_get_range() function) and sample-oriented values, such as data obtained from ch_get_iq_data() or parameters for filtering such as static target rejection (see ch_set_static_range()).

Note
The number of samples corresponding to a certain distance is determined by the ODR (output data rate) for the sensor, which is the rate at which the received ultrasound is sampled within each measurement. So, the ODR must be known to calculate this conversion. This function always uses the ODR value for the default measurement (CH_DEFAULT_MEAS_NUM). To get the conversion for a specific measurement, use ch_meas_mm_to_samples().
In ICU sensors, the ODR is configurable. The default is one sample per 8 transceiver cycles (CH_ODR_FREQ_DIV_8, also known as CH_ODR_DEFAULT). If the default ODR will not be not used, the new ODR must be applied before this function is called, either as a standard parameter during ch_meas_init(), or by calling ch_meas_set_odr() using CH_DEFAULT_MEAS_NUM as the measurement number.
For ICU sensors, this function always returns the conversion values for the default measurement. If multiple measurements are being used with different ODR settings, use the ch_meas_mm_to_samples() function to get the correct value for the specific measurement.

See also ch_samples_to_mm(), ch_meas_set_odr().

◆ ch_reset()

void ch_reset ( ch_dev_t dev_ptr,
ch_reset_t  reset_type 
)

Reset a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
reset_typetype of reset (CH_RESET_HARD or CH_RESET_SOFT)

This function resets a sensor. The reset_type parameter indicates if a software reset or full hardware reset is requested.

◆ ch_restart()

uint8_t ch_restart ( ch_dev_t dev_ptr)

Restart a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if successful, 1 if error

This function performs a re-start of a sensor that has previously been initialized and started. The sensor is reset, the sensor firmware is reloaded, and the configuration settings are re-applied. The sensor will not perform the normal calibration steps (including clock calibration) - it will instead use the values saved during a previous initialization.

Normally, this function should not be needed. It may be useful for special error handling or other application-specific requirements.

Different sensor firmware can be loaded, by calling ch_init() before this function and specifying a new firmware init routine. This is normally not recommended for applications, but this mechanism is sometimes used internally by SonicLib.

After this routine returns successfully, the sensor should be ready to resume measurements.

See also ch_group_restart(), ch_group_start().

◆ ch_samples_to_cycles()

uint32_t ch_samples_to_cycles ( uint16_t  num_samples,
ch_odr_t  odr 
)

Convert samples to sensor cycles.

Parameters
num_samplesnumber of samples
odroutput data rate
Returns
Number of sensor cycles.

This function takes a count of samples and converts it to the corresponding number of internal sensor cycles. The cycles are the same units used to specify measurement segment lengths.

The odr parameter is the current output data rate setting for the sensor. The ODR affects the timing between samples, and therefore the number of internal cycles per sample.

See also ch_cycles_to_samples, ch_meas_get_odr.

◆ ch_samples_to_mm()

uint16_t ch_samples_to_mm ( ch_dev_t dev_ptr,
uint16_t  num_samples 
)

Convert sample count to millimeters for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_samplessample count to be converted
Returns
Number of millimeters

This function converts the sample count specified in num_samples and converts it to the corresponding physical distance in millimeters. The conversion uses values set during device initialization and calibration that describe the internal timing of the sensor.

This function may be helpful when working with both physical distances (as reported by the ch_get_range() function) and sample-oriented values, such as data obtained from ch_get_iq_data() or parameters for static target rejection (see ch_set_static_range()).

Note
The number of samples corresponding to a certain distance is determined by the ODR (output data rate) for the sensor, which is the rate at which the received ultrasound is sampled within each measurement. So, the ODR must be known to calculate this conversion.
In ICU sensors, the ODR is configurable. The default is one sample per 8 transceiver cycles (CH_ODR_FREQ_DIV_8, also known as CH_ODR_DEFAULT). If the default ODR will not be not used, the new ODR must be specified before this function is called, either as a standard parameter during ch_meas_init(), or by calling ch_meas_set_odr() using CH_DEFAULT_MEAS_NUM as the measurement number.
For ICU sensors, this function always returns the conversion values for the default measurement. If multiple measurements are being used with different ODR settings, use the ch_meas_samples_to_mm() function to get the correct value for the specific measurement.

See also ch_mm_to_samples(), ch_meas_set_odr().

◆ ch_sensor_is_connected()

uint8_t ch_sensor_is_connected ( ch_dev_t dev_ptr)

Indicate if a sensor is connected.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
1 if the sensor is connected, 0 otherwise

◆ ch_set_algo_config()

uint8_t ch_set_algo_config ( ch_dev_t dev_ptr,
const void *  algo_cfg_ptr 
)

Set the measurement algorithm configuration data to a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
algo_cfg_ptrpointer to a buffer to send configuration data
Returns
0 if success, 1 if error

This function writes the configuration data to an algorithm running on the ICU sensor. This interface is independent of the specific algorithm or configuration format.

Normally, this routine will only be used by special applications or libraries which interact with specific sensor firmware.

◆ ch_set_cal_result()

uint8_t ch_set_cal_result ( ch_dev_t dev_ptr,
ch_cal_result_t cal_ptr 
)

Set the calibration result.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
cal_ptrpointer to ch_cal_result_t structure to receive calibration data
Returns
0 if success, 1 if error

WARNING: This function should not be used to set the calibration result to a fixed value, even one individually calculated for each sensor, as this could change over the lifetime of the sensor; rather, this function could be used to update the calibration result if the calibration result calculated by CHx01 at startup (i.e. returned by ch_get_cal_result()) is sufficiently different than expected or sensor performance is not good.

This function sets the calibration result with a ch_cal_result_t structure specified by cal_ptr for the sensor. The ch_cal_result_t structure contains DCO period and reverse drive cycles.

To use this function, first initialize the ch_cal_result_t DCO period/reverse drive cycles pair of values

See also ch_get_cal_result().

◆ ch_set_config()

uint8_t ch_set_config ( ch_dev_t dev_ptr,
ch_config_t config_ptr 
)

Set multiple configuration settings for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
config_ptrpointer to a ch_config_t structure containing new configuration values
Returns
0 if successful, 1 if error

This function sets multiple configuration options within the sensor. The configuration settings are passed in a ch_config_t structure, whose address is specified by config_ptr. The fields in the ch_config_t structure must have been set with your new configuration values before this function is called.

Note
The individual configuration values set by this function may also be set using dedicated single-value functions. These two methods are completely equivalent and may be freely mixed. See ch_set_mode(), ch_set_max_range(), ch_set_freerun_interval(), ch_set_static_range(), ch_set_thresholds(), and ch_set_target_interrupt().

◆ ch_set_data_output()

uint8_t ch_set_data_output ( ch_dev_t dev_ptr,
ch_output_t output_ptr 
)

Set data output format and rate.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
output_ptrpointer to the data output type, including format and decimation factor

This function sets both the data output format type and rate for sample data within a measurement. The values are passed in a ch_output_t structure specified by output_ptr, which contains two fields, output_type and decimation_factor. The decimation factor is equivalent to the sample output data rate (ODR) of the sensor, expressed differently.

The possible values for output_type are:

  • CH_OUTPUT_IQ - Standard pairs of {Q,I} int16_t values (ch_iq_sample_t)
  • CH_OUTPUT_AMP_THRESH - Output amplitude + threshold uint16_t pair values (ch_amp_thresh_t)
  • CH_OUTPUT_AMP - Output uint16_t amplitude values only

The possible values for decimation_factor and the equivalent output rate (ODR) values are as follows:

Decimation Factor ODR Value Sample Rate vs. Default
CH_DECIMATION_NONE CH_ODR_FREQ_DIV_8 (CH_ODR_DEFAULT) default
CH_DECIMATION_0_25 CH_ODR_FREQ_DIV_2 4 x default
CH_DECIMATION_0_50 CH_ODR_FREQ_DIV_4 2 x default
CH_DECIMATION_2 CH_ODR_FREQ_DIV_16 1/2 default
CH_DECIMATION_3 no equivalent 1/3 default - only in special CHx01 f/w
CH_DECIMATION_4 CH_ODR_FREQ_DIV_32 1/4 default

For ICU sensors, both measurements will be set to the specified output type. To change the output format for a single measurement, use ch_meas_set_iq_output(). To change the output data rate for a single measurement, use ch_meas_set_odr().

Note
For CH101 and CH201 sensors, this function is only available in select sensor firmware versions.

◆ ch_set_data_ready_delay()

uint8_t ch_set_data_ready_delay ( ch_dev_t dev_ptr,
uint8_t  delay_ms 
)

Set data ready interrupt delay interval.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
delay_mstime, in milliseconds, for sensor to delay after measurement
Returns
0 if success, 1 if error

This function sets a delay interval that will cause the sensor to wait slightly after a measurement completes before issuing a data ready interrupt. It is used in special circumstances to handle unusual timing constraints. Normally, this function should not be used.

delay_ms specifies the time, in milliseconds, that the sensor will delay after the measurement completes before generating the interrupt signal.

The granularity of this delay is limited by the period of the sensor's internal wake cycle timer, so in some cases the delay_ms value will be increased to match the next whole number of wake cycles. (A granularity of about 4 ms is typical.)

The ch_get_data_ready_delay() function may be used to determine the actual delay period, after any adjustment to match the sensor wake cycles.

Note
This function is only available in select Chirp sensor firmware versions.

◆ ch_set_freerun_interval()

uint8_t ch_set_freerun_interval ( ch_dev_t dev_ptr,
uint16_t  interval_ms 
)

Set the internal sensing interval for freerunning mode, in milliseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
interval_msinterval between samples, in milliseconds.
Returns
0 if successful, 1 if arguments are invalid.

This function sets the sample interval for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal clock to wake and perform a measurement every interval_ms milliseconds. A value of zero for interval_ms is not valid.

To set the sensing interval with greater precision, use ch_set_freerun_interval_us() or ch_set_freerun_interval_ticks().

Note
This function has no effect for a sensor operating in one of the triggered modes. The sample interval for a triggered device is determined by the external trigger timing.

See also ch_get_freerun_interval(), ch_set_freerun_interval_us(), ch_set_sense_interval_cycles().

◆ ch_set_freerun_interval_ticks()

uint8_t ch_set_freerun_interval_ticks ( ch_dev_t dev_ptr,
uint32_t  interval_ticks 
)

Set the internal sensing interval for freerunning mode, in RTC clock ticks.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
interval_ticksinterval between samples, in sensor RTC clock periods
Returns
0 if successful, 1 if arguments are invalid.

This function sets the sample interval for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal real-time clock (RTC) to wake and perform a measurement every interval_ticks clock periods. A value of zero for interval_ticks is not valid.

Note
This function has no effect for a sensor operating in one of the triggered modes. The sample interval for a triggered device is determined by the external trigger timing.

See also ch_get_freerun_interval_ticks(), ch_set_freerun_interval(), ch_set_freerun_interval_us().

◆ ch_set_freerun_interval_us()

uint8_t ch_set_freerun_interval_us ( ch_dev_t dev_ptr,
uint32_t  interval_us 
)

Set the internal sensing interval for freerunning mode, in microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
interval_usinterval between samples, in microseconds.
Returns
0 if successful, 1 if arguments are invalid.

This function sets the sample interval for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal clock to wake and perform a measurement every interval_us microseconds. A value of zero for interval_us is not valid.

Note
This function has no effect for a sensor operating in one of the triggered modes. The sample interval for a triggered device is determined by the external trigger timing.

See also ch_get_freerun_interval_us(), ch_set_freerun_interval(), ch_set_freerun_interval_ticks().

◆ ch_set_frequency()

uint8_t ch_set_frequency ( ch_dev_t dev_ptr,
uint32_t  request_op_freq_hz 
)

Set the operating frequency of a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
request_op_freq_hzrequested operating frequency in Hz
Returns
0 if success, 1 if error

This function requests a desired acoustic operating frequency for a sensor. This is the primary frequency of the ultrasonic pulse that is emitted by the device when transmitting.

The request_op_freq_hz parameter specifies the frequency, in Hz, that is requested. The operating frequency for the sensor will be set as close as possible to this value. The operating frequency cannot be set to a value that is outside the typical operating frequency range for the sensor model.

In general, the actual operating frequency will be slightly different than the requested value. Use ch_get_frequency() to obtain the sensor's operating frequency after the adjustment.

Often, a group of sensors will be set to a common acoustic operating frequency to optimize the transmit/receive efficiency for sensors operating in paired pitch/catch operation. Use ch_group_set_frequency(), instead of this function, to set all sensors in a group to a common value. That function can automatically apply a calculated value based on the sensors' natural frequencies.

See also ch_get_frequency(), ch_group_set_frequency().

Note
For CH101 and CH201 sensors, this function is only available in select sensor firmware versions.

◆ ch_set_init_firmware()

uint8_t ch_set_init_firmware ( ch_dev_t dev_ptr,
ch_fw_init_func_t  fw_init_func 
)

Initialize the init firmware to use for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
fw_init_funcpointer to the sensor init firmware initialization function
Returns
0 if success, 1 if error

This function is used to define the init firmware for a sensor if the main firwmware (determined with ch_init) doesn't have initialization features in it. It can be necessary to set a specific initialization firmware (with tx optimization) if using measure optimization API.

Note
This function only performs internal initialization of data structures, etc. It does not actually initialize the physical sensor device(s). See ch_group_start(), ch_restart(), ch_group_restart() and ch_meas_optimize().

◆ ch_set_interrupt_drive()

uint8_t ch_set_interrupt_drive ( ch_dev_t dev_ptr,
ch_interrupt_drive_t  drive 
)

Set interrupt drive (open drain or push pull)

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
driveCH_INTERRUPT_DRIVE_OPEN_DRAIN for open drain interrupt drive, CH_INTERRUPT_DRIVE_PUSH_PULL for push pull drive
Returns
0 if success, 1 if error

This function sets the sensor interrupt to use an open-drain or push-pull drive. In open drain, the sensor will actively drive the line low and use a pull-up resistor for the hight level. In push-pull drive, the sensor will actively drive the line both low and high. Additionally, the pull-up resistor on the interrupt pin used for hardware trigger is disabled. By default, ICU sensors use open drain interrupt drive (CH_INTERRUPT_DRIVE_OPEN_DRAIN).

To use this function, set drive to CH_INTERRUPT_DRIVE_OPEN_DRAIN to enable open drain drive. Set drive to CH_INTERRUPT_DRIVE_PUSH_PULL to use push-pull drive.

Note
This option is only available for ICU sensors. CH101 and CH201 sensors always use active-high, pull low interrupts. Attempting to set drive to CH_INTERRUPT_MODE_PUSH_PULL on a CH101 or CH201 will return an error.

◆ ch_set_interrupt_mode()

uint8_t ch_set_interrupt_mode ( ch_dev_t dev_ptr,
ch_interrupt_mode_t  mode 
)

Set interrupt mode (pulsed or latching)

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
modeCH_INTERRUPT_MODE_PULSE for pulse interrupt mode, CH_INTERRUPT_MODE_LATCH for latching mode
Returns
0 if success, 1 if error

This function sets the sensor interrupt to use a pulsed or latching level change. In pulse mode, the sensor will briefly change the INT line level and then restore it to the original state. In latching mode, the sensor will change the INT line level, and it will stay at that level until reset by the interrupt handler in the board support package. By default, ICU sensors use latching interrupt mode (CH_INTERRUPT_MODE_LATCH).

To use this function, set mode to CH_INTERRUPT_MODE_PULSE to enable pulsed interrupt mode. Set mode to CH_INTERRUPT_MODE_LATCH to disable the pulse interrupt mode and use latching behavior.

Note
This option is only available for ICU sensors. CH101 and CH201 sensors always use pulse interrupt mode for normal sensor interrupts. Attempting to set mode to CH_INTERRUPT_MODE_LATCH on a CH101 or CH201 will return an error.

◆ ch_set_max_range()

uint8_t ch_set_max_range ( ch_dev_t dev_ptr,
uint16_t  max_range 
)

Set the maximum range for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
max_rangemaximum range, in millimeters
Returns
0 if successful, non-zero if error

This function sets the maximum detection range for the sensor, in millimeters. The detection range setting controls how long the sensor will listen (i.e. how many samples it will capture) during each measurement cycle. (The number of samples is automatically calculated for the specified range.)

For ICU sensors, this function always controls the default measurement definition. To specify which measurement to modify, use the ch_meas_set_max_range() function.

See also ch_set_num_samples(), ch_get_max_range(), ch_set_config().

◆ ch_set_mode()

uint8_t ch_set_mode ( ch_dev_t dev_ptr,
ch_mode_t  mode 
)

Configure a sensor for the specified operating mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
modethe new operating mode for the sensor
Returns
0 if successful.

This function sets the sensor to operate in the specified mode, which must be one of the following:

  • CH_MODE_IDLE - low power idle mode, no measurements take place
  • CH_MODE_FREERUN - free-running mode, sensor uses internal clock to wake and measure
  • CH_MODE_TRIGGERED_TX_RX - hardware-triggered, sensor both transmits and receives
  • CH_MODE_TRIGGERED_RX_ONLY - hardware triggered, sensor only receives
  • CH_MODE_CONTINUOUS_RX - (ICU parts only) In this mode, the sensor receives continuously. There is no frame-based trigger. Receive samples are double-buffered. While the host is reading one buffer, the sensor is writing new samples into the other buffer.

◆ ch_set_num_samples()

uint8_t ch_set_num_samples ( ch_dev_t dev_ptr,
uint16_t  num_samples 
)

Set the sensor sample count directly.

Parameters
dev_ptrpointer to the ch_dev_t descriptor struct
num_samplesnumber of samples during each measurement cycle
Returns
0 if successful

This function directly sets the number of samples which the Chirp sensor will perform during a single measurement cycle. The number of samples directly corresponds to the range at which the sensor can detect.

For ICU sensors, note that this function changes the number of samples in an existing measurement. The existing measurement definition will be shortened or extended to match the new sample count. If the measurement is extended, the new samples will use the same settings as in the final receive segment. This function always controls the default measurement definition. To specify which measurement to modify, use the ch_meas_set_num_samples() function.

Note
Often, the sample is count is not set using this function, but is instead set indirectly using ch_set_max_range(), which will automatically set the sample count based on a specified range in millimeters.

See also ch_set_max_range(), ch_get_num_samples().

◆ ch_set_pmut_clock()

uint8_t ch_set_pmut_clock ( ch_dev_t dev_ptr,
ch_pmut_clk_cfg_t  clock_cfg 
)

Configure ultrasound transducer clock.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
clock_cfgclock configuration setting
Returns
0 if success, 1 if error

This function configures the PMUT clock input and output settings to allow the multiple sensors to share a common clock signal. One sensor may be set to output the signal from the PMUT clock, while others may be set to use that signal as a clock input. This permits very exact frequency matching for critical applications. Alternatively, all sensors may be set to use an independent, external clock signal.

This function may only be called after ch_group_start() has initialized the sensors. The original PMUT clock settings will be modified, and the new settings will be applied immediately. The PMUT clock settings must be set separately for each sensor.

  • Normally, the PMUT clock is internal and the signal is not output on the sensor MUTCLK pad. This function is not needed in this case. (This is the default CH_PMUT_CLK_DEFAULT configuration.)
  • To enable output of the sensor's PMUT clock on the MUTCLK pad, set clock_cfg to CH_PMUT_CLK_OUTPUT_AUTO or CH_PMUT_CLK_OUTPUT_ENABLE. The AUTO setting allows the ICU part to control the power state of the clock. In this case, the clock will only be available while the ICU part is actively performing a measurement. This is a good option to use when multiple parts will be active simultaneously. The ENABLE option will unconditionally force the clock on. This can be used in situations where the clock should be available even if the part providing it is inactive, such as during transmit optimization.
  • The output frequency of the signal on the pad will be 16 times the sensor's acoustic operating frequency.
  • To use an input signal on the MUTCLK pad as the external PMUT clock source, set clock_cfg to CH_PMUT_CLK_SRC_EXTERNAL. In this configuration, the sensor's PMUT will operate at 1/16 the input clock signal frequency.
  • To restore the default PMUT clock configuration (i.e. to un-do either operation), set clock_cfg to CH_PMUT_CLK_DEFAULT.

When one sensor supplies the clock for one or more other sensors, the sequence of enabling and disabling the clock settings across the sensors is important. The clock source must be present whenever a secondary sensor is configured to use an external clock source.

  • When enabling, the clock source sensor should be set to CH_PMUT_CLK_OUTPUT_AUTO or CH_PMUT_CLK_OUTPUT_ENABLE first, then the other sensor(s) should be set to CH_PMUT_CLK_SRC_EXTERNAL.
  • When disabling, the secondary sensor(s) should be set to CH_PMUT_CLK_DEFAULT first, then the clock source sensor should be set to CH_PMUT_CLK_DEFAULT.

If an independent clock source (not from a sensor) is used, that input signal must be present and ch_group_set_pmut_clock_freq() must be called to specify the clock frequency before the sensors are set to CH_PMU_CLK_SRC_EXTERNAL.

The ch_get_frequency() function will report the current acoustic operating frequency of the PMUT, regardless of the clock source. So, if the sensor is using an external clock source, the indicated frequency will match that of the sensor supplying the clock signal, or 1/16 the input clock rate if an independent signal.

Only one shared PMUT clock signal can be used within a sensor group. Individual sensors are not required to use the shared clock.

See also ch_get_pmut_clock(), ch_group_set_pmut_clock_freq().

Note
This feature is not available on CH101 or CH201 sensors.

◆ ch_set_rtc()

uint8_t ch_set_rtc ( ch_dev_t dev_ptr,
ch_rtc_src_t  rtc_source,
uint16_t  rtc_freq 
)

Configure the sensor real-time clock (RTC).

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
rtc_sourceRTC source (internal or external)
rtc_freqRTC frequency in Hz, or CH_RTC_USE_BUS_SPEED, or zero to use factory test result
Returns
0 if success, 1 if error

This function changes the default real-time clock (RTC) configuration to meet special requirements and system limitations. In most applications, this function is not needed and should not be called.

Two options may be set. For the internal RTC clock, this function can specify alternatives to the standard clock calibration. Or, this function can indicate that an external clock source be used to drive the sensor's RTC functions.

An accurate measurement of the sensor's RTC clock is an important part of the time-of-flight calculations performed by the ultrasonic sensor and SonicLib. Any inaccuracy in the RTC frequency value will directly result in inaccuracy in time-of-flight, and therefore range, measurements.

Internal RTC Calibration

Normally, the sensor's internal RTC clock frequency is measured during sensor initialization, using an external timed pulse (typically 100 ms) on the sensor INT line. This pulse takes place during ch_group_start(). Using a timed calibration pulse is recommended, because it gives the best overall sensor accuracy. In some situations, however, it may be impossible or inconvenient to apply a sufficiently accurate timed pulse to calibrate the RTC. This function provides two alternative ways to set the frequency value, with some sacrifice in ultimate sensor accuracy.

This function can specify the frequency, in Hz, for the RTC using either the stored factory test result or a custom value. This function does not actually change the sensor's internal RTC frequency, it simply sets the numeric value that will be used in calculations where the RTC frequency is needed.

Using the Factory RTC Calibration

ICU sensors contain factory test data that includes a measurement of the sensor's internal RTC frequency. This value provides a reasonable substitute for performing full calibration using a calibration pulse.

To use the factory RTC calibration data, specify CH_RTC_SRC_INTERNAL for rtc_source and a value of zero for rtc_freq.

Factory RTC calibration values are not available for CH101 or CH201 sensors.

Using the I/O Bus Clock to Estimate RTC Frequency

In some cases, it is possible to use the I/O bus clock as a reference for calibrating the RTC. (This feature is only available in select sensor f/w variants.)

To use the bus clock for calibration, specify CH_RTC_SRC_INTERNAL for rtc_source, and set rtc_freq to CH_RTC_USE_BUS_SPEED.

For CH101/CH201 sensor types that support this calibration mode, the I2C bus clock (SCL) speed is assumed to be 400000 Hz by default. If a different, more accurate value for the bus clock speed is available, it can be specified by defining CHIRP_I2C_BUS_SPEED_HZ in the chirp_board_config.h file in the board support package, and setting the value to the correct bus speed. Inaccuracies in the bus clock rate value will affect frequency and range measurements by the sensor.

Supplying an Estimated RTC Frequency

If rtc_freq is not zero or CH_RTC_USE_BUS_SPEED, the specified value will be used in all calculations requiring the RTC frequency. Normal calibration using a pulse is not performed. The rtc_freq value should be the best available estimate of the RTC frequency for this device.

To use an estimated RTC frequency, specify CH_RTC_SRC_INTERNAL for rtc_source, and set rtc_freq to the approximate RTC frequency, in Hz.

If no other estimate is available, rtc_freq may be specified as CH_RTC_FREQ_TYPICAL (29000 Hz) for a rough approximation of a typical RTC frequency.

This option is a last choice, due to the impact on measurement accuracy, but it will allow measurements to be completed.

Using an External RTC Clock

This function can also set the source of the sensor's real-time clock. By default, the sensor will use its internal oscillator as the RTC clock time base. To use the internal RTC, no special action is required, and this routine does not have to be called unless you are changing the calibration values described above.

For enhanced timing accuracy, an external clock source (e.g. crystal oscillator) may be connected to the ICU sensor. This may be used to maintain a more exact measurement interval for sensors operating in free-running mode (CH_MODE_FREERUN).

To enable an external clock source for the RTC, set rtc_source to CH_RTC_SRC_EXTERNAL, and set rtc_freq to the frequency of the clock signal in Hz (e.g. 32768 for a 32.768 kHz crystal).

When to Call this Function

This function should be called after ch_init() but before ch_group_start(). This function must be called before ch_group_start(), because RTC calibration is normally done then. When this function is used, the sensor will not require or perform automatic RTC calibration using a timed pulse.

All sensors in a sensor group must use the same calibration method, automatic (default) or manual (using this routine for each sensor in the group before ch_group_start()).

Note
This function may only be called during sensor initialization, after ch_init() and before ch_group_start(). Use at any other time will result in undefined behavior.

See also ch_get_rtc_frequency().

◆ ch_set_rx_holdoff()

uint8_t ch_set_rx_holdoff ( ch_dev_t dev_ptr,
uint16_t  num_samples 
)

Set the receive holdoff sample count.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_samplesnumber of samples to be ignored at the beginning of each measurement
Returns
0 if success, 1 if error

This function sets the receive (rx) holdoff sample count. num_samples specifies a number of samples at the beginning of a measurement that will be ignored for the purpose of detecting a target. (These samples correspond to the closest distances from the sensor.)

To convert a physical distance into a sample count value to use here, use ch_mm_to_samples().

For ICU sensors, this function always controls the default measurement definition. To specify which measurement to modify, use the icu_gpt_set_rx_holdoff() function.

See also ch_get_rx_holdoff().

◆ ch_set_rx_low_gain()

uint8_t ch_set_rx_low_gain ( ch_dev_t dev_ptr,
uint16_t  num_samples 
)

Set the receive low-gain sample count.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_samplesnumber of samples that have low gain at beginning of measurement
Returns
0 if success, 1 if error

This function sets the receive (rx) low-gain range in the sensor. The low-gain range consists of samples at the beginning of a measurement that will have a lower gain applied during the sensor receive operation. (These samples correspond to the closest distances from the sensor.)

The low-gain range must be less than the current maximum range setting. If num_samples is greater than or equal to the maximum range setting, it will automatically be reduced.

See also ch_get_rx_low_gain(), ch_get_num_samples().

Note
This function is only available in CH201 sensor firmware.

◆ ch_set_rx_pretrigger()

void ch_set_rx_pretrigger ( ch_group_t grp_ptr,
uint8_t  enable 
)

Enable/disable receive-only sensor pre-triggering.

Parameters
grp_ptrpointer to the ch_group_t group descriptor structure
enable1 to enable pre-triggering, 0 to disable

This function enables or disables pre-triggering of the receive-only sensor during Pitch-Catch operation. When pre-triggering is enabled, sensors in CH_MODE_TRIGGERED_RX_ONLY mode will be triggered slightly before sensors in CH_MODE_TRIGGERED_TX_RX mode when ch_group_trigger() is called. This improves the ability of a receive-only sensor to detect the transmitted pulse at very short distances.

If enabled, pre-triggering is used for all receive-only sensors in the sensor group.

To use this function, set enable to 1 to enable pre-triggering, or 0 to disable pre-triggering.

See also ch_get_rx_pretrigger().

Note
Enabling pre-triggering will reduce the maximum range of the receive-only sensor(s), relative to the setting specified in ch_set_max_range(), by about 200mm. You may want to increase the maximum range setting accordingly.

◆ ch_set_sample_interval()

uint8_t ch_set_sample_interval ( ch_dev_t dev_ptr,
uint16_t  interval_ms 
)

Set the internal sensing interval (deprecated).

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
interval_msinterval between samples, in milliseconds.
Returns
0 if successful, 1 if arguments are invalid.
Note
This function is DEPRECATED and is provided for backwards compatibility only. New applications should use the equivalent ch_set_freerun_interval() function.

This function sets the sample interval for a sensor operating in freerunning mode (CH_MODE_FREERUN). The sensor will use its internal clock to wake and perform a measurement every interval_ms milliseconds. A value of zero for interval_ms is not valid.

◆ ch_set_sample_window()

uint8_t ch_set_sample_window ( ch_dev_t dev_ptr,
uint16_t  start_sample,
uint16_t  num_samples 
)

Set the sample window for amplitude averaging.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
start_samplesample number of first sample in window
num_samplesnumber of samples to include in window
Returns
0 if successful, non-zero if error

This function sets the sample range to be included in the sample window used for amplitude averaging. start_sample is the number of the first sample that will be included in the averaging window. num_samples is the total number of samples that will be included.

See also ch_get_amplitude_avg(), ch_get_sample_window().

Note
Internal sample window averaging is available when using special sensor firmware packages from Chirp. In General Purpose Rangefinding (GPR) firmware, a software only implementation is used.

◆ ch_set_target_int_counter()

uint8_t ch_set_target_int_counter ( ch_dev_t dev_ptr,
uint8_t  meas_hist,
uint8_t  thresh_count,
uint8_t  reset 
)

Configure the target interrupt counter filter.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
meas_histnumber of previous measurements to include in target count
thresh_countnumber of target detections req'd to generate interrupt
resetif non-zero, counter filter resets when int is generated
Returns
0 if success, 1 if error

This function sets the counter filter used to control target interrupts. The counter filter is by enabled using the ch_set_target_interrupt() function and specifying CH_TGT_INT_FILTER_COUNTER as the filter type.

When the counter filter is used, a certain threshold number of positive target detections must be observed within a specified number of measurements in order for an interrupt to be generated by the sensor.

meas_hist specifies the number of previous measurements that will be included in the history buffer for filtering. The current measurement is combined with these previous measurements, so a total of meas_hist + 1 measurements are used.

thresh_count is the number of those measurements that must positively detect a target for an interrupt to be generated.

At the end of each measurement, the total number of measurements with target detection within all the history and the new measurement is compared against the threshold value. If it meets the threshold, the sensor will interrupt. For example, if meas_hist is 5 and thresh_count is 3, an interrupt will be generated if 3 of the most recent 6 measurements (the 5 in the history plus the new result) detected a target.

If reset is non-zero, the counter filter counts are reset when an interrupt is generated. The sensor will not interrupt again until thresh_count new measurements detect a target, using the same threshold conditions as before. If reset is zero, the sensor will maintain its history and will continue to interrupt after each measurement if the threshold number of detections within recent results is met. Counter filter resetting is disabled by default.

The maximum value for both meas_hist and thresh_count is 15.

See also ch_get_target_int_counter(), ch_set_target_interrupt().

Note
Target counter filtering is only available in select Chirp sensor firmware versions.

◆ ch_set_target_interrupt()

uint8_t ch_set_target_interrupt ( ch_dev_t dev_ptr,
ch_tgt_int_filter_t  tgt_int_filter 
)

Configure target interrupt filtering mode.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
tgt_int_filtertarget interrupt filter mode
Returns
0 if success, 1 if error

This function configures the filtering of data ready interrupts from the sensor based on target detection.

In normal operation (if target detection interrupt filtering is not enabled), the sensor will assert the INT line at the end of each measurement even if no target is detected. This is the default behavior if this function is not used, or if tgt_int_filter is CH_TGT_INT_FILTER_OFF.

When basic target interrupt filtering is enabled, the sensor will assert the INT line at the end of each measurement only if a target object was detected. If no target is detected, the sensor will not interrupt, and there is no indication from the sensor that the measurement has completed.

To use basic target interrupt filtering, set tgt_int_filter to CH_TGT_INT_FILTER_ANY.

Target counter mode provides another level of filtering, across multiple measurements. When counter filtering is enabled, the sensor will only interrupt after multiple measurements have detected a target within a certain total number of consecutive recent measurements. A configurable history of previous measurements is recorded, and the results are compared against a threshold number of target detections. The sensor will generate an interrupt only when the count of target detections within the set of recent measurements meets the threshold value,

To use counter mode filtering, set tgt_int_filter to CH_TGT_INT_FILTER_COUNTER. The measurement history and target detection threshold count used in the filter can be set by using the ch_set_target_int_counter() function.

If not otherwise specified, the default measurement history length is 5 measurements. The current measurement is combined with the measurements from the history, so a total of 6 measurements are used. The default interrupt threshold is 3 target detections. So by default, 3 of the 6 most recent measurements must detect a target to generate an interrupt.

By default, the counter filter maintains its history and counter values after an interrupt is generated, so the next measurement may again interrupt based on the threshold comparison as usual. The counter filter may instead be configured to reset after generating an interrupt by using ch_set_target_int_counter(). In this case, the full thresh_count threshold must be met based on new detections, so that minimum number of measurements must occur before another interrupt will be generated.

See also ch_set_target_int_counter(), ch_get_target_interrupt().

Note
Target interrupt filtering is only available in select Chirp sensor firmware versions.

◆ ch_set_trigger_type()

void ch_set_trigger_type ( ch_dev_t dev_ptr,
ch_trigger_type_t  trig_type 
)

Set the trigger type for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
trig_typetrigger type to be used, CH_TRIGGER_TYPE_HW or CH_TRIGGER_TYPE_SW

This function sets the trigger type to be used to initiate a measurement on a sensor that is in triggered mode. (Sensors in free-running mode are self-triggered based on an internal timer.)

By default (if this routine is not called), sensors are triggered using a hardware signal on the INT line. For ICU sensors, either there are two INT lines, INT1 and INT2. The line to be used for triggering is selected by the CHIRP_SENSOR_TRIG_PIN definition in the chirp_board_config.h file.

Alternatively, a measurement may be initiated via software, using a SPI command sent to the sensor. This may be used in place of a standard hardware trigger using a GPIO line, although there will be more latency and less exact timing control. To enable software triggering, set trig_type to CH_TRIGGER_TYPE_SW.

See also ch_trigger(), ch_trigger_soft(), ch_get_trigger_type().

Note
Software triggering is not available for CH101 and CH201 sensors, so hardware triggering is always used. Calling this routine will have no effect.

◆ ch_set_tx_length()

uint8_t ch_set_tx_length ( ch_dev_t dev_ptr,
uint16_t  num_cycles 
)

Set the ultrasound transmit pulse length.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_cyclestransmit pulse length (number of cycles per transmission)
Returns
0 if success, 1 if error

This function sets the length (duration) of the ultrasonic pulse sent by the sensor when it transmits. num_cycles specifies the length of the pulse.

For ICU (Shasta architecture) sensors, num_cycles are in units of Measurement State Machine Clock (SMCLK) cycles.

For CH101 and CH201 (Whitney architecture) sensors, num_cycles are ultrasonic transducer (PMUT) cycles, so are 1/16 the corresponding ICU sensor value.

See also ch_get_tx_length().

Note
This feature is only available in select Chirp sensor firmware versions.

◆ ch_ticks_to_usec()

uint32_t ch_ticks_to_usec ( ch_dev_t dev_ptr,
uint16_t  num_ticks 
)

Convert sensor RTC clock ticks to microseconds.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
rtc_ticksnumber of sensor RTC clock periods
Returns
Number of microseconds.

This function takes a number of internal sensor RTC clock periods and converts it to the corresponding time in microseconds.

See also ch_usec_to_ticks(), ch_set_rtc().

◆ ch_trigger()

void ch_trigger ( ch_dev_t dev_ptr)

Trigger a measurement on one sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure

This function generates a pulse on the INT line for a single sensor. If the sensor is in either CH_MODE_TRIGGERED_TX_RX or CH_MODE_TRIGGERED_RX_ONLY mode, this pulse will begin a measurement cycle.

To simultaneously trigger all sensors in a group, use ch_group_trigger().

Note
Do not trigger a new measurement until the previous measurement has completed and all needed data has been read from the device (including I/Q data, if ch_get_iq_data() is used). If any I/O operations are still active, the new measurement may be corrupted.

◆ ch_trigger_soft()

void ch_trigger_soft ( ch_dev_t dev_ptr)

Trigger a measurement using software (SPI) interface.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function sends a special command to the sensor over the SPI bus to trigger a measurement. The software interface is always used regardless of the trigger type that has been set using ch_set_trigger_type().

This may be used in place of a standard hardware trigger using a GPIO line, although there will be more latency and less exact timing control.

See also ch_trigger().

◆ ch_update_metadata_from_iq0()

uint8_t ch_update_metadata_from_iq0 ( ch_dev_t dev_ptr,
ch_iq_sample_t iq_data 
)

Extract the metadata from the first IQ sample and update the device pointer.

The ICU-X0201 can be configured to place metadata in the first IQ sample, which is otherwise always read out as 0. If enabled, this will place the IQ buffer address as well as the last measurement index in the first IQ sample. See ch_enable_metadata_in_iq0().

This function is used to extract metadata from the read IQ data. The metadata will be updated into dev_ptr. That is, after calling this function, the device pointer will be updated with the correct buffer address and last measurement index.

After running this function and getting a 0 exit status, the last measurement index can be retrieved using ch_meas_get_last_num() and the next buffer address with ch_get_next_buf_addr().

Parameters
dev_ptrThe device pointer
iq_dataPointer to the read IQ data. The metadata is extracted from the first sample, then the first sample is set back to 0.
Returns
0 for success and non-zero otherwise. If this function returns non-zero, then the device pointer is not updated. This most likely means that data was read from the incorrect buffer in double buffer mode. The situation should resolve itself on the next read since the same buffer will be read again, and the ASIC will swap write buffers on each measurement.

◆ ch_usec_to_cycles()

uint32_t ch_usec_to_cycles ( ch_dev_t dev_ptr,
uint32_t  num_usec 
)

Convert microseconds to sensor cycles.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_usecnumber of microseconds
Returns
Number of sensor cycles.

This function takes a period of time specified in microseconds and converts it to the corresponding number of internal sensor cycles.

For ICU (Shasta architecture) sensors, cycles are in units of PMUT State Machine Clock (SMCLK) cycles. The PMUT clock rate is 16 times the ultrasonic transducer acoustic operating frequency. These are the same cycle units used to specify measurement transmit and count segment lengths.

For CH101 and CH201 (Whitney architecture) sensors, cycles are ultrasonic transducer cycles, so are 1/16 the corresponding ICU sensor value.

See also ch_cycles_to_usec().

◆ ch_usec_to_ticks()

uint16_t ch_usec_to_ticks ( ch_dev_t dev_ptr,
uint32_t  num_usec 
)

Convert microseconds to sensor RTC clock ticks.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
num_usecnumber of microseconds
Returns
Number of sensor RTC clock ticks.

This function takes a time specified in microseconds and converts it to the corresponding number of sensor RTC clock periods.

See also ch_ticks_to_usec(), ch_set_rtc().

◆ ch_watchdog_disable()

uint8_t ch_watchdog_disable ( ch_dev_t dev_ptr)

Disable watchdog timer in sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function disables the watchdog timer function in the sensor.

Note
This feature is only available on ICU sensors. For CH101 and CH201 sensors, the watchdog timer is enabled or disabled by using a different sensor firmware image.

See also ch_watchdog_enable().

◆ ch_watchdog_enable()

uint8_t ch_watchdog_enable ( ch_dev_t dev_ptr)

Enable watchdog timer in sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
Returns
0 if success, 1 if error

This function enables the watchdog timer function in the sensor. When the watchdog timer is enabled, the sensor must complete a measurement within approximately one second or the timer will expire. The timer is reset every time a measurement completes.

If the watchdog timer expires, the sensor will generate an interrupt and will specify CH_INTERRUPT_TYPE_WATCHDOG as the interrupt type. This interrupt type is passed as a parameter to the application's sensor interrupt callback routine that was registered using ch_io_int_callback_set(). That callback routine should examine the interrupt type and take appropriate action if a watchdog timeout occurred.

Note
This feature is only available on ICU sensors. For CH101 and CH201 sensors, the watchdog timer is enabled by using a different sensor firmware image (these firmware types have "_wd" in their names). Not all CH101 and CH201 firmware types have equivalent watchdog-enabled versions.

See also ch_watchdog_disable().