From 1fef2664e4ea32345e961fe092d2a04eb36d37b2 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 17 Feb 2024 01:31:28 -0500 Subject: [PATCH] honestly, no idea at this point, bunch of stuff --- .cargo/config.toml | 3 +- build.rs | 21 +- c_src/wrapper.h | 5 +- rss/include/{ => arm}/acc_alg_basic_utils.h | 0 rss/include/{ => arm}/acc_config.h | 0 rss/include/{ => arm}/acc_config_subsweep.h | 0 rss/include/{ => arm}/acc_definitions_a121.h | 0 .../{ => arm}/acc_definitions_common.h | 0 rss/include/{ => arm}/acc_detector_distance.h | 0 .../acc_detector_distance_definitions.h | 0 rss/include/{ => arm}/acc_detector_presence.h | 0 .../{ => arm}/acc_hal_definitions_a121.h | 0 rss/include/{ => arm}/acc_processing.h | 0 rss/include/{ => arm}/acc_rss_a121.h | 0 rss/include/{ => arm}/acc_sensor.h | 0 rss/include/{ => arm}/acc_version.h | 0 rss/include/{ => arm}/inttypes.h | 0 rss/include/{ => arm}/stdio.h | 0 rss/include/{ => arm}/stdlib.h | 0 rss/include/xtensa/acc_config.h | 479 +++++++++++ rss/include/xtensa/acc_config_subsweep.h | 284 +++++++ rss/include/xtensa/acc_control_helper.h | 88 ++ rss/include/xtensa/acc_definitions_a121.h | 138 ++++ rss/include/xtensa/acc_definitions_common.h | 50 ++ rss/include/xtensa/acc_detector_distance.h | 569 +++++++++++++ .../acc_detector_distance_definitions.h | 65 ++ rss/include/xtensa/acc_detector_presence.h | 773 ++++++++++++++++++ rss/include/xtensa/acc_hal_definitions_a121.h | 93 +++ rss/include/xtensa/acc_hal_integration_a121.h | 74 ++ rss/include/xtensa/acc_integration.h | 71 ++ rss/include/xtensa/acc_integration_log.h | 54 ++ rss/include/xtensa/acc_processing.h | 155 ++++ rss/include/xtensa/acc_processing_helpers.h | 371 +++++++++ rss/include/xtensa/acc_rss_a121.h | 243 ++++++ rss/include/xtensa/acc_sensor.h | 218 +++++ rss/include/xtensa/acc_version.h | 25 + rss/include/xtensa/example_bring_up.h | 18 + rss/include/xtensa/example_control_helper.h | 18 + .../xtensa/example_detector_distance.h | 18 + ...le_detector_distance_calibration_caching.h | 18 + ...ple_detector_distance_with_iq_data_print.h | 18 + .../xtensa/example_detector_presence.h | 18 + ...etector_presence_multiple_configurations.h | 18 + rss/include/xtensa/example_diagnostic_test.h | 18 + .../xtensa/example_processing_amplitude.h | 18 + .../xtensa/example_processing_coherent_mean.h | 18 + .../example_processing_noncoherent_mean.h | 18 + .../example_processing_peak_interpolation.h | 18 + .../example_processing_static_presence.h | 18 + .../example_processing_subtract_adaptive_bg.h | 18 + rss/include/xtensa/example_service.h | 18 + .../example_service_calibration_caching.h | 18 + .../example_service_multiple_configurations.h | 18 + .../xtensa/example_service_sensor_disable.h | 18 + .../xtensa/example_service_sensor_hibernate.h | 18 + .../xtensa/example_service_sensor_off.h | 18 + .../xtensa/example_service_subsweeps.h | 18 + rust-toolchain.toml | 6 - rust-toolchain.toml.bak | 8 + 59 files changed, 4157 insertions(+), 14 deletions(-) rename rss/include/{ => arm}/acc_alg_basic_utils.h (100%) rename rss/include/{ => arm}/acc_config.h (100%) rename rss/include/{ => arm}/acc_config_subsweep.h (100%) rename rss/include/{ => arm}/acc_definitions_a121.h (100%) rename rss/include/{ => arm}/acc_definitions_common.h (100%) rename rss/include/{ => arm}/acc_detector_distance.h (100%) rename rss/include/{ => arm}/acc_detector_distance_definitions.h (100%) rename rss/include/{ => arm}/acc_detector_presence.h (100%) rename rss/include/{ => arm}/acc_hal_definitions_a121.h (100%) rename rss/include/{ => arm}/acc_processing.h (100%) rename rss/include/{ => arm}/acc_rss_a121.h (100%) rename rss/include/{ => arm}/acc_sensor.h (100%) rename rss/include/{ => arm}/acc_version.h (100%) rename rss/include/{ => arm}/inttypes.h (100%) rename rss/include/{ => arm}/stdio.h (100%) rename rss/include/{ => arm}/stdlib.h (100%) create mode 100644 rss/include/xtensa/acc_config.h create mode 100644 rss/include/xtensa/acc_config_subsweep.h create mode 100644 rss/include/xtensa/acc_control_helper.h create mode 100644 rss/include/xtensa/acc_definitions_a121.h create mode 100644 rss/include/xtensa/acc_definitions_common.h create mode 100644 rss/include/xtensa/acc_detector_distance.h create mode 100644 rss/include/xtensa/acc_detector_distance_definitions.h create mode 100644 rss/include/xtensa/acc_detector_presence.h create mode 100644 rss/include/xtensa/acc_hal_definitions_a121.h create mode 100644 rss/include/xtensa/acc_hal_integration_a121.h create mode 100644 rss/include/xtensa/acc_integration.h create mode 100644 rss/include/xtensa/acc_integration_log.h create mode 100644 rss/include/xtensa/acc_processing.h create mode 100644 rss/include/xtensa/acc_processing_helpers.h create mode 100644 rss/include/xtensa/acc_rss_a121.h create mode 100644 rss/include/xtensa/acc_sensor.h create mode 100644 rss/include/xtensa/acc_version.h create mode 100644 rss/include/xtensa/example_bring_up.h create mode 100644 rss/include/xtensa/example_control_helper.h create mode 100644 rss/include/xtensa/example_detector_distance.h create mode 100644 rss/include/xtensa/example_detector_distance_calibration_caching.h create mode 100644 rss/include/xtensa/example_detector_distance_with_iq_data_print.h create mode 100644 rss/include/xtensa/example_detector_presence.h create mode 100644 rss/include/xtensa/example_detector_presence_multiple_configurations.h create mode 100644 rss/include/xtensa/example_diagnostic_test.h create mode 100644 rss/include/xtensa/example_processing_amplitude.h create mode 100644 rss/include/xtensa/example_processing_coherent_mean.h create mode 100644 rss/include/xtensa/example_processing_noncoherent_mean.h create mode 100644 rss/include/xtensa/example_processing_peak_interpolation.h create mode 100644 rss/include/xtensa/example_processing_static_presence.h create mode 100644 rss/include/xtensa/example_processing_subtract_adaptive_bg.h create mode 100644 rss/include/xtensa/example_service.h create mode 100644 rss/include/xtensa/example_service_calibration_caching.h create mode 100644 rss/include/xtensa/example_service_multiple_configurations.h create mode 100644 rss/include/xtensa/example_service_sensor_disable.h create mode 100644 rss/include/xtensa/example_service_sensor_hibernate.h create mode 100644 rss/include/xtensa/example_service_sensor_off.h create mode 100644 rss/include/xtensa/example_service_subsweeps.h delete mode 100644 rust-toolchain.toml create mode 100644 rust-toolchain.toml.bak diff --git a/.cargo/config.toml b/.cargo/config.toml index 04dee16..55fa0e2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,5 @@ [build] +#target = "xtensa-esp32s3-none-elf" #target = "thumbv7em-none-eabihf" [target.xtensa-esp32s3-none-elf] runner = "espflash flash --monitor" @@ -7,5 +8,5 @@ rustflags = [ "-C", "link-arg=-Tlinkall.x", "-C", "link-arg=-nostartfiles", "-C", "link-arg=-Trom_functions.x", - "-C", "target-feature=-loop", + #"-C", "target-feature=-loop", ] diff --git a/build.rs b/build.rs index 3106d04..c8a310a 100644 --- a/build.rs +++ b/build.rs @@ -10,6 +10,7 @@ fn main() { let target = match target.as_str() { "thumbv7em-none-eabihf" => "thumbv7em-none-eabihf", "xtensa-esp32s3-none-elf" => "xtensa-esp32s3-none-elf", + "xtensa-esp32s3-espidf" => "xtensa-esp32s3-espidf", _ => "thumbv7em-none-eabihf", }; println!("Target we are using: {}", target); @@ -28,8 +29,12 @@ fn main() { .extra_warnings(true) .compile("log"); xmpath.join("lib/arm") - } else if target.eq("xtensa-esp32s3-none-elf") { - cc::Build::new().file("c_src/wrapper.c").include("c_src"); + } else if target.eq("xtensa-esp32s3-none-elf") | target.eq("xtensa-esp32s3-espidf") { + cc::Build::new() + .file("c_src/wrapper.c") + .include("c_src") + .warnings_into_errors(true) + .extra_warnings(true); xmpath.join("lib/xtensa") } else { panic!("Target is not set or not supported."); @@ -43,7 +48,13 @@ fn main() { ); println!("cargo:rerun-if-changed=c_src/wrapper.c"); - let headers = xmpath.join("include"); + let headers = match target.into() { + "thumbv7em-none-eabihf" => xmpath.join("include/arm"), + "xtensa-esp32s3-none-elf" => xmpath.join("include/xtensa"), + "xtensa-esp32s3-espidf" => xmpath.join("include/xtensa"), + _ => panic!("Honestly shouldn't arrive here."), + }; + //let headers = xmpath.join("include"); if !headers.exists() { panic!("headers not found"); } @@ -55,9 +66,9 @@ fn main() { .layout_tests(false) .generate_cstr(true) .use_core() - } else if target.eq("xtensa-esp32s3-none-elf") { + } else if target.eq("xtensa-esp32s3-none-elf") | target.eq("xtensa-esp32s3-espidf") { bindgen::Builder::default() - .clang_arg("--target=xtensa-esp32s3-none-elf") + .clang_arg("--target=xtensa") .clang_arg(format!("-I{}", headers.display())) .layout_tests(false) .generate_cstr(true) diff --git a/c_src/wrapper.h b/c_src/wrapper.h index 992eaed..4969649 100644 --- a/c_src/wrapper.h +++ b/c_src/wrapper.h @@ -1,10 +1,11 @@ #ifndef WRAPPER_H #define WRAPPER_H -#include "../rss/include/acc_definitions_common.h" +#include "../rss/include/arm/acc_definitions_common.h" #include #include -void c_log_stub(acc_log_level_t level, const char *module, const char *format, ...); +void c_log_stub(acc_log_level_t level, const char *module, const char *format, + ...); #endif // WRAPPER_H diff --git a/rss/include/acc_alg_basic_utils.h b/rss/include/arm/acc_alg_basic_utils.h similarity index 100% rename from rss/include/acc_alg_basic_utils.h rename to rss/include/arm/acc_alg_basic_utils.h diff --git a/rss/include/acc_config.h b/rss/include/arm/acc_config.h similarity index 100% rename from rss/include/acc_config.h rename to rss/include/arm/acc_config.h diff --git a/rss/include/acc_config_subsweep.h b/rss/include/arm/acc_config_subsweep.h similarity index 100% rename from rss/include/acc_config_subsweep.h rename to rss/include/arm/acc_config_subsweep.h diff --git a/rss/include/acc_definitions_a121.h b/rss/include/arm/acc_definitions_a121.h similarity index 100% rename from rss/include/acc_definitions_a121.h rename to rss/include/arm/acc_definitions_a121.h diff --git a/rss/include/acc_definitions_common.h b/rss/include/arm/acc_definitions_common.h similarity index 100% rename from rss/include/acc_definitions_common.h rename to rss/include/arm/acc_definitions_common.h diff --git a/rss/include/acc_detector_distance.h b/rss/include/arm/acc_detector_distance.h similarity index 100% rename from rss/include/acc_detector_distance.h rename to rss/include/arm/acc_detector_distance.h diff --git a/rss/include/acc_detector_distance_definitions.h b/rss/include/arm/acc_detector_distance_definitions.h similarity index 100% rename from rss/include/acc_detector_distance_definitions.h rename to rss/include/arm/acc_detector_distance_definitions.h diff --git a/rss/include/acc_detector_presence.h b/rss/include/arm/acc_detector_presence.h similarity index 100% rename from rss/include/acc_detector_presence.h rename to rss/include/arm/acc_detector_presence.h diff --git a/rss/include/acc_hal_definitions_a121.h b/rss/include/arm/acc_hal_definitions_a121.h similarity index 100% rename from rss/include/acc_hal_definitions_a121.h rename to rss/include/arm/acc_hal_definitions_a121.h diff --git a/rss/include/acc_processing.h b/rss/include/arm/acc_processing.h similarity index 100% rename from rss/include/acc_processing.h rename to rss/include/arm/acc_processing.h diff --git a/rss/include/acc_rss_a121.h b/rss/include/arm/acc_rss_a121.h similarity index 100% rename from rss/include/acc_rss_a121.h rename to rss/include/arm/acc_rss_a121.h diff --git a/rss/include/acc_sensor.h b/rss/include/arm/acc_sensor.h similarity index 100% rename from rss/include/acc_sensor.h rename to rss/include/arm/acc_sensor.h diff --git a/rss/include/acc_version.h b/rss/include/arm/acc_version.h similarity index 100% rename from rss/include/acc_version.h rename to rss/include/arm/acc_version.h diff --git a/rss/include/inttypes.h b/rss/include/arm/inttypes.h similarity index 100% rename from rss/include/inttypes.h rename to rss/include/arm/inttypes.h diff --git a/rss/include/stdio.h b/rss/include/arm/stdio.h similarity index 100% rename from rss/include/stdio.h rename to rss/include/arm/stdio.h diff --git a/rss/include/stdlib.h b/rss/include/arm/stdlib.h similarity index 100% rename from rss/include/stdlib.h rename to rss/include/arm/stdlib.h diff --git a/rss/include/xtensa/acc_config.h b/rss/include/xtensa/acc_config.h new file mode 100644 index 0000000..4692b21 --- /dev/null +++ b/rss/include/xtensa/acc_config.h @@ -0,0 +1,479 @@ +// Copyright (c) Acconeer AB, 2020-2023 +// All rights reserved + +#ifndef ACC_CONFIG_H_ +#define ACC_CONFIG_H_ + +#include +#include + +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" + + +/** + * @defgroup config Config + * @ingroup service + * + * @brief Module to configure sensor and processing + * + * @{ + */ + + +struct acc_config; + +typedef struct acc_config acc_config_t; + + +/** + * @brief Create a configuration + * + * A configuration is created and populated with default values. + * + * @return A configuration instance + */ +acc_config_t *acc_config_create(void); + + +/** + * @brief Destroy a configuration freeing any resources allocated + * + * Destroy a configuration that is no longer needed. + * + * @param[in] config The configuration to destroy, can be NULL + */ +void acc_config_destroy(acc_config_t *config); + + +/** + * @brief Print a configuration to the log + * + * @param[in] config The configuration to log + */ +void acc_config_log(const acc_config_t *config); + + +/** + * @brief Set the starting point of the sweep + * + * This sets the starting point of the sweep. The corresponding start + * in millimeter is approximately start_point * 2.5 mm. For the exact + * distance in meter, use the @ref acc_processing_points_to_meter function. + * + * @param[in] config The configuration + * @param[in] start_point The starting point of the sweep + */ +void acc_config_start_point_set(acc_config_t *config, int32_t start_point); + + +/** + * @brief Get the starting point of the sweep + * + * @see acc_config_start_point_set + * + * @param[in] config The configuration + * @return The starting point of the sweep + */ +int32_t acc_config_start_point_get(const acc_config_t *config); + + +/** + * @brief Set the number of data points to measure + * + * This sets the number of data points to measure in a sweep. + * + * @param[in] config The configuration + * @param[in] num_points Number of data points to measure + */ +void acc_config_num_points_set(acc_config_t *config, uint16_t num_points); + + +/** + * @brief Get the number of data points to measure + * + * @see acc_config_num_points_set + * + * @param[in] config The configuration + * @return Number of data points to measure + */ +uint16_t acc_config_num_points_get(const acc_config_t *config); + + +/** + * @brief Set the step length in a sweep + * + * This sets the number of steps to have between each data point. + * + * Sampling produces complex (IQ) data points with configurable distance spacing, + * starting from ~2.5mm. + * + * @param[in] config The configuration + * @param[in] step_length The step length + */ +void acc_config_step_length_set(acc_config_t *config, uint16_t step_length); + + +/** + * @brief Get the step length in a sweep + * + * @see acc_config_step_length_set + * + * @param[in] config The configuration + * @return The step length + */ +uint16_t acc_config_step_length_get(const acc_config_t *config); + + +/** + * @brief Set a profile + * + * Each profile consists of a number of settings for the sensor that configures + * the RX and TX paths. Lower profiles have higher depth resolution while + * higher profiles have higher SNR. + * + * @param[in] config The config to set a profile for + * @param[in] profile The profile to set + */ +void acc_config_profile_set(acc_config_t *config, + acc_config_profile_t profile); + + +/** + * @brief Get the currently used profile + * + * See @ref acc_config_profile_set + * + * @param[in] config The config to get a profile for + * @return The profile currently used + */ +acc_config_profile_t acc_config_profile_get(const acc_config_t *config); + + +/** + * @brief Set the hardware accelerated average samples (HWAAS) + * + * Each data point can be sampled several times and the sensor hardware then + * produces an average value of those samples. The time needed to measure a sweep is roughly proportional + * to the number of averaged samples. Hence, if there is a need to obtain a higher update rate, HWAAS + * could be decreased but this leads to lower SNR. + * + * HWAAS must be between 1 and 511 inclusive + * + * @param[in] config The config to set HWAAS for + * @param[in] hwaas Hardware accelerated average samples + */ +void acc_config_hwaas_set(acc_config_t *config, uint16_t hwaas); + + +/** + * @brief Get the hardware accelerated average samples (HWAAS) + * + * @see acc_config_hwaas_set + * + * @param[in] config The config to get HWAAS from + * @return Hardware accelerated average samples + */ +uint16_t acc_config_hwaas_get(const acc_config_t *config); + + +/** + * @brief Set receiver gain setting + * + * Must be a value between 0 and 23 inclusive where 23 is the highest gain and 0 the lowest. + * + * Lower gain gives higher SNR. However, too low gain may result in quantization, lowering SNR. + * Too high gain may result in saturation, corrupting the data. + * + * @param[in] config The configuration + * @param[in] gain Receiver gain setting + */ +void acc_config_receiver_gain_set(acc_config_t *config, uint8_t gain); + + +/** + * @brief Get receiver gain setting + * + * See @ref acc_config_receiver_gain_set + * + * @param[in] config The configuration + * @return Receiver gain setting + */ +uint8_t acc_config_receiver_gain_get(const acc_config_t *config); + + +/** + * @brief Set sweeps per frame + * + * Sets the number of sweeps that will be captured in each frame (measurement). + * Can be set to 0 if e.g. only temperature measurement is wanted. + * + * @param[in] config The configuration + * @param[in] sweeps Sweeps per frame + */ +void acc_config_sweeps_per_frame_set(acc_config_t *config, uint16_t sweeps); + + +/** + * @brief Get the number of sweeps per frame + * + * See @ref acc_config_sweeps_per_frame_set + * + * @param[in] config The configuration + * @return Sweeps per frame + */ +uint16_t acc_config_sweeps_per_frame_get(const acc_config_t *config); + + +/** + * @brief Set the sweep rate + * + * Sets the sweep rate for sweeps in a frame (measurement). + * + * @param[in] config The configuration + * @param[in] sweep_rate Sweep rate in Hz. Must be >= 0, 0 is interpreted as max sweep rate + */ +void acc_config_sweep_rate_set(acc_config_t *config, float sweep_rate); + + +/** + * @brief Get the sweep rate + * + * See @ref acc_config_sweep_rate_set + * + * @param[in] config The configuration + * @return Sweep rate in Hz + */ +float acc_config_sweep_rate_get(const acc_config_t *config); + + +/** + * @brief Set continuous sweep mode + * + * In continuous sweep mode the timing will be identical over all sweeps, not + * just the sweeps in a frame. + * + * Constraints: + * - Frame rate must be set to unlimited (0.0) + * - Sweep rate must be set (> 0) + * - Inter frame idle state must be set equal to inter sweep idle state + * + * @param[in] config The configuration + * @param[in] enabled true if continuous sweep mode should be enabled, false otherwise + */ +void acc_config_continuous_sweep_mode_set(acc_config_t *config, bool enabled); + + +/** + * @brief Get continuous sweep mode + * + * See @ref acc_config_continuous_sweep_mode_set + * + * @param[in] config The configuration + * @return true if continuous sweep mode is enabled, false otherwise + */ +bool acc_config_continuous_sweep_mode_get(const acc_config_t *config); + + +/** + * @brief Set the frame rate + * + * Sets the frame rate. + * + * Setting the frame rate to unlimited (0) means that the rate is not limited by the + * sensor but the rate that the host acknowledge and reads out the measurement data. + * + * @param[in] config The configuration + * @param[in] frame_rate Frame rate in Hz. Must be >= 0, 0 is interpreted as unlimited + */ +void acc_config_frame_rate_set(acc_config_t *config, float frame_rate); + + +/** + * @brief Get the frame rate + * + * See @ref acc_config_frame_rate_set + * + * @param[in] config The configuration + * @return Frame rate + */ +float acc_config_frame_rate_get(const acc_config_t *config); + + +/** + * @brief Enable or disable the transmitter + * + * If set to true, TX is enabled. This will enable the radio transmitter. + * By turning the transmitter off the RX noise floor can be measured. + * + * @param[in] config The configuration + * @param[in] enable true to enable the transmitter, false to disable it + */ +void acc_config_enable_tx_set(acc_config_t *config, bool enable); + + +/** + * @brief Get transmitter enable configuration + * + * See @ref acc_config_enable_tx_set + * + * @param[in] config The configuration + * @return true if the transmitter is enabled, false if it is disabled + */ +bool acc_config_enable_tx_get(const acc_config_t *config); + + +/** + * @brief Set inter frame idle state + * + * The 'inter-frame idle state' is the state the sensor idles in between each frame. + * + * See also @ref acc_config_idle_state_t. + * + * The inter frame idle state of the frame must be deeper or the same as the inter sweep idle state. + * + * @param[in] config The configuration + * @param[in] idle_state The idle state to use between frames + */ +void acc_config_inter_frame_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state); + + +/** + * @brief Get inter frame idle state + * + * See @ref acc_config_inter_frame_idle_state_set + * + * @param[in] config The configuration + * @return The idle state to use between frames + */ +acc_config_idle_state_t acc_config_inter_frame_idle_state_get(const acc_config_t *config); + + +/** + * @brief Set inter sweep idle state + * + * The 'inter-sweep idle state' is the state the sensor idles in between each sweep in a frame. + * + * See also @ref acc_config_idle_state_t. + * + * @param[in] config The configuration + * @param[in] idle_state The idle state to use between sweeps within a frame + */ +void acc_config_inter_sweep_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state); + + +/** + * @brief Get inter sweep idle state + * + * See @ref acc_config_inter_sweep_idle_state_set + * + * @param[in] config The configuration + * @return The idle state to use between sweeps within a frame + */ +acc_config_idle_state_t acc_config_inter_sweep_idle_state_get(const acc_config_t *config); + + +/** + * @brief Set Pulse Repetition Frequency + * + * See @ref acc_config_prf_t for details. + * + * @param[in] config The configuration + * @param[in] prf The Pulse Repetition Frequency to use + */ +void acc_config_prf_set(acc_config_t *config, acc_config_prf_t prf); + + +/** + * @brief Get Pulse Repetition Frequency + * + * See @ref acc_config_prf_t for details. + * + * @param[in] config The configuration + * @return Pulse Repetition Frequency + */ +acc_config_prf_t acc_config_prf_get(const acc_config_t *config); + + +/** + * @brief Enable or disable phase enhancement + * + * If enabled, the data phase will be enhanced such that coherent distance filtering can be applied. + * Given a single reflection from an object, the phase will appear as "flat" around the amplitude peak. + * + * Enabling the phase enhancement increases the processing execution time. + * + * @param[in] config The configuration + * @param[in] enable true if phase enhancement should be enabled, false otherwise + */ +void acc_config_phase_enhancement_set(acc_config_t *config, bool enable); + + +/** + * @brief Get the phase enhancement configuration + * + * See @ref acc_config_phase_enhancement_set + * + * @param[in] config The configuration + * @return true if phase enhancement is enabled, false otherwise + */ +bool acc_config_phase_enhancement_get(const acc_config_t *config); + + +/** + * @brief Enable or disable loopback + * + * Constraints: + * - Loopback can't be enabled together with profile 2. + * + * @param[in] config The configuration + * @param[in] enable true if loopback should be enabled, false otherwise + */ +void acc_config_enable_loopback_set(acc_config_t *config, bool enable); + + +/** + * @brief Get the enable loopback configuration + * + * See @ref acc_config_enable_loopback_set + * + * @param[in] config The configuration + * @return true if loopback is enabled, false otherwise + */ +bool acc_config_enable_loopback_get(const acc_config_t *config); + + +/** + * @brief Enable or disable double buffering + * + * If enabled, the sensor buffer will be split in two halves reducing the + * maximum number of samples. A frame can be read using @ref acc_sensor_read while + * sampling is done into the other buffer. Switching of buffers is done automatically + * by @ref acc_sensor_measure. + * + * When using double buffering, measurements coinciding with SPI activity may have distorted phase. + * To mitigate this issue, applying a median filter is recommended. + * + * @param[in] config The configuration + * @param[in] enable true if double buffering should be enabled, false otherwise + */ +void acc_config_double_buffering_set(acc_config_t *config, bool enable); + + +/** + * @brief Get the double buffering configuration + * + * See @ref acc_config_double_buffering_set + * + * @param[in] config The configuration + * @return true if double buffering is enabled, false otherwise + */ +bool acc_config_double_buffering_get(const acc_config_t *config); + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_config_subsweep.h b/rss/include/xtensa/acc_config_subsweep.h new file mode 100644 index 0000000..85f5f9c --- /dev/null +++ b/rss/include/xtensa/acc_config_subsweep.h @@ -0,0 +1,284 @@ +// Copyright (c) Acconeer AB, 2021-2023 +// All rights reserved + +#ifndef ACC_CONFIG_SUBSWEEP_H_ +#define ACC_CONFIG_SUBSWEEP_H_ + +#include + +#include "acc_config.h" +#include "acc_definitions_a121.h" + +/** + * @defgroup subsweep Subsweep + * @ingroup config + * + * @brief Module to configure subsweeps + * + * @{ + */ + +/** + * @brief Set the number of subsweeps to use + * + * @param[in] config The configuration + * @param[in] num_subsweeps The number of subsweeps + */ +void acc_config_num_subsweeps_set(acc_config_t *config, uint8_t num_subsweeps); + + +/** + * @brief Get the number of subsweeps to use + * + * @param[in] config The configuration + * @return The number of subsweeps + */ +uint8_t acc_config_num_subsweeps_get(const acc_config_t *config); + + +/** + * @brief Set the starting point of the sweep + * + * See @ref acc_config_start_point_set + * + * @param[in] config The configuration + * @param[in] start_point The starting point of the sweep + * @param[in] index The subsweep index + */ +void acc_config_subsweep_start_point_set(acc_config_t *config, int32_t start_point, uint8_t index); + + +/** + * @brief Get the starting point of the sweep + * + * See @ref acc_config_start_point_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return The starting point of the sweep + */ +int32_t acc_config_subsweep_start_point_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set the number of data points to measure + * + * See @ref acc_config_num_points_set + * + * @param[in] config The configuration + * @param[in] num_points Number of data points to measure + * @param[in] index The subsweep index + */ +void acc_config_subsweep_num_points_set(acc_config_t *config, uint16_t num_points, uint8_t index); + + +/** + * @brief Get the number of data points to measure + * + * See @ref acc_config_num_points_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return Number of data points to measure + */ +uint16_t acc_config_subsweep_num_points_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set the step length in a sweep + * + * See @ref acc_config_step_length_set + * + * @param[in] config The configuration + * @param[in] step_length The step length + * @param[in] index The subsweep index + */ +void acc_config_subsweep_step_length_set(acc_config_t *config, uint16_t step_length, uint8_t index); + + +/** + * @brief Get the step length in a sweep + * + * See @ref acc_config_step_length_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return The step length + */ +uint16_t acc_config_subsweep_step_length_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set a profile + * + * See @ref acc_config_profile_set + * + * @param[in] config The config to set a profile for + * @param[in] profile The profile to set + * @param[in] index The subsweep index + */ +void acc_config_subsweep_profile_set(acc_config_t *config, acc_config_profile_t profile, uint8_t index); + + +/** + * @brief Get the currently used profile + * + * See @ref acc_config_profile_get + * + * @param[in] config The config to get a profile for + * @param[in] index The subsweep index + * @return The current profile, 0 if config is invalid + */ +acc_config_profile_t acc_config_subsweep_profile_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set the hardware accelerated average samples (HWAAS) + * + * See @ref acc_config_hwaas_set + * + * @param[in] config The config to set hwaas for + * @param[in] hwaas Hardware accelerated average samples + * @param[in] index The subsweep index + */ +void acc_config_subsweep_hwaas_set(acc_config_t *config, uint16_t hwaas, uint8_t index); + + +/** + * @brief Get the hardware accelerated average samples (HWAAS) + * + * See @ref acc_config_hwaas_get + * + * @param[in] config The config to get hwaas from + * @param[in] index The subsweep index + * @return Hardware accelerated average samples + */ +uint16_t acc_config_subsweep_hwaas_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set receiver gain setting + * + * See @ref acc_config_receiver_gain_set + * + * @param[in] config The configuration + * @param[in] gain Receiver gain setting + * @param[in] index The subsweep index + */ +void acc_config_subsweep_receiver_gain_set(acc_config_t *config, uint8_t gain, uint8_t index); + + +/** + * @brief Get receiver gain setting + * + * See @ref acc_config_receiver_gain_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return Receiver gain setting + */ +uint8_t acc_config_subsweep_receiver_gain_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Enable or disable the transmitter + * + * See @ref acc_config_enable_tx_set + * + * @param[in] config The configuration + * @param[in] enable true to enable the transmitter + * @param[in] index The subsweep index + */ +void acc_config_subsweep_enable_tx_set(acc_config_t *config, bool enable, uint8_t index); + + +/** + * @brief Get transmitter enable mode + * + * See @ref acc_config_enable_tx_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return true if the transmitter is enabled + */ +bool acc_config_subsweep_enable_tx_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set Pulse Repetition Frequency + * + * See @ref acc_config_prf_t for details. + * + * @param[in] config The configuration + * @param[in] prf The Pulse Repetition Frequency to use + * @param[in] index The subsweep index + */ +void acc_config_subsweep_prf_set(acc_config_t *config, acc_config_prf_t prf, uint8_t index); + + +/** + * @brief Get Pulse Repetition Frequency + * + * See @ref acc_config_prf_t for details. + * + * @param[in] config The configuration + * @return Pulse Repetition Frequency + * @param[in] index The subsweep index + */ +acc_config_prf_t acc_config_subsweep_prf_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set the phase enhancement enabled configuration + * + * See @ref acc_config_phase_enhancement_set + * + * @param[in] config The configuration + * @param[in] enable true if phase enhancement to be enabled, false otherwise + * @param[in] index The subsweep index + */ +void acc_config_subsweep_phase_enhancement_set(acc_config_t *config, bool enable, uint8_t index); + + +/** + * @brief Get the phase enhancement enabled configuration + * + * See @ref acc_config_phase_enhancement_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return true if phase enhancement is enabled, false otherwise + */ +bool acc_config_subsweep_phase_enhancement_get(const acc_config_t *config, uint8_t index); + + +/** + * @brief Set the loopback enabled configuration + * + * See @ref acc_config_enable_loopback_set + * + * @param[in] config The configuration + * @param[in] enable true if loopback to be enabled, false otherwise + * @param[in] index The subsweep index + */ +void acc_config_subsweep_enable_loopback_set(acc_config_t *config, bool enable, uint8_t index); + + +/** + * @brief Get the enable loopback configuration + * + * See @ref acc_config_enable_loopback_get + * + * @param[in] config The configuration + * @param[in] index The subsweep index + * @return true if loopback is enabled, false otherwise + */ +bool acc_config_subsweep_enable_loopback_get(const acc_config_t *config, uint8_t index); + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_control_helper.h b/rss/include/xtensa/acc_control_helper.h new file mode 100644 index 0000000..b49510b --- /dev/null +++ b/rss/include/xtensa/acc_control_helper.h @@ -0,0 +1,88 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef ACC_CONTROL_HELPER_H_ +#define ACC_CONTROL_HELPER_H_ +#include + +#include "acc_config.h" +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" +#include "acc_processing.h" +#include "acc_sensor.h" + +/** \example acc_control_helper.c + * @brief This is a simplified API that can be used to easier get started + * The implementation of this API is provided as source code which can + * be examined and modified in order to suit your needs. + */ + +typedef struct +{ + acc_config_t *config; + acc_sensor_t *sensor; + acc_sensor_id_t sensor_id; + acc_processing_t *processing; + void *buffer; + uint32_t buffer_size; + acc_cal_result_t cal_result; + acc_processing_metadata_t proc_meta; + acc_processing_result_t proc_result; +} acc_control_helper_t; + + +/** + * @brief Create a helper instance + * + * After a successful call to this function all members of the the acc_control_helper_t + * are initialized to default values and the config member is created. + * + * @param radar A pointer to an acc_control_helper_t struct. The members in this struct will be initialized. + * @param sensor_id The sensor id + * @return true if successful, false otherwise + */ +bool acc_control_helper_create(acc_control_helper_t *radar, acc_sensor_id_t sensor_id); + + +/** + * @brief Destroy a helper instance + * + * @param radar A pointer to an acc_control_helper_t struct + */ +void acc_control_helper_destroy(acc_control_helper_t *radar); + + +/** + * @brief Activate the sensor + * + * After a successful call to this function the following members of the + * acc_control_helper_t struct are updated: + * + * buffer_size: The size of the allocated buffer + * sensor: Pointer to sensor instance + * processing: Pointer to processing instance + * cal_result: The calibration data + * + * @param radar A pointer to an acc_control_helper_t struct + * @return true if successful, false otherwise + * + */ +bool acc_control_helper_activate(acc_control_helper_t *radar); + + +/** + * @brief Perform a radar measurement and wait for the result. + * + * After each call to this function the "proc_result" member of the acc_control_helper_t + * is updated. + * + * @param radar A pointer to an acc_control_helper_t struct + * @return true if successful, false otherwise + */ +bool acc_control_helper_get_next(acc_control_helper_t *radar); + + +#endif diff --git a/rss/include/xtensa/acc_definitions_a121.h b/rss/include/xtensa/acc_definitions_a121.h new file mode 100644 index 0000000..4074a79 --- /dev/null +++ b/rss/include/xtensa/acc_definitions_a121.h @@ -0,0 +1,138 @@ +// Copyright (c) Acconeer AB, 2022-2024 +// All rights reserved + +#ifndef ACC_DEFINITIONS_A121_H_ +#define ACC_DEFINITIONS_A121_H_ + +#include + + +/** + * @defgroup definitions Definitions + * + * @brief Various definitions and types used in the RSS API + * + * @{ + */ + + +/** + * @brief The size of a sensor calibration result + */ +#define ACC_CAL_RESULT_DATA_SIZE (192) + +/** + * @brief The maximum number of subsweeps in a configuration. + */ +#define ACC_MAX_NUM_SUBSWEEPS (4U) + +/** + * @brief The result from a completed calibration. + */ +typedef struct +{ + uint8_t data[ACC_CAL_RESULT_DATA_SIZE]; +} acc_cal_result_t; + +/** + * @brief Information about calibration. + */ +typedef struct +{ + int16_t temperature; +} acc_cal_info_t; + + +/** + * @brief Profile + * + * Each profile consists of a number of settings for the sensor that configures the RX and TX paths. + * Lower profiles have higher depth resolution while higher profiles have higher radar loop gain. + */ +typedef enum +{ + /*! The profile with the highest depth resolution and lowest radar loop gain. */ + ACC_CONFIG_PROFILE_1 = 1, + ACC_CONFIG_PROFILE_2, + ACC_CONFIG_PROFILE_3, + ACC_CONFIG_PROFILE_4, + /*! The profile with the lowest depth resolution and highest radar loop gain. */ + ACC_CONFIG_PROFILE_5, +} acc_config_profile_t; + + +/** + * @brief Idle state + * + * Idle state 'DEEP_SLEEP' is the deepest state where as much of the sensor hardware as + * possible is shut down and idle state 'READY' is the shallowest state where most of the sensor + * hardware is kept on. + * + * DEEP_SLEEP is the slowest to transition from while READY is the fastest. + * + */ +typedef enum +{ + /*! The deepest state where as much of the sensor hardware is shut down. */ + ACC_CONFIG_IDLE_STATE_DEEP_SLEEP, + ACC_CONFIG_IDLE_STATE_SLEEP, + /*! The shallowest state where most of the sensor hardware is kept on. */ + ACC_CONFIG_IDLE_STATE_READY, +} acc_config_idle_state_t; + + +/** + * @brief Pulse Repetition Frequency + * + * Pulse Repetition Frequency, PRF, is the frequency at + * which pulses are sent out from the radar system. The + * measurement time is approximately proportional to the + * PRF. The higher the PRF, the shorter the measurement time. + * + * This parameter sets the Maximum Measurable Distance, MMD, + * that can be achieved. MMD is the maximum value for the end point, + * i.e.,the start point + (number of points * step length). + * For example, an MMD of 7.0 m means that the range cannot + * be set further out than 7.0 m. + * + * It also sets the Maximum Unambiguous Range, MUR, that can be achieved. + * MUR is the maximum distance at which an object can be located to guarantee + * that its reflection corresponds to the most recent transmitted pulse. + * Objects farther away than the MUR may fold into the measured range. + * For example, with a MUR of 11.5 m, an object at 13.5 m could become + * visible at 2 m. + * + * | PRF Setting | PRF | MMD | MUR | + * |-------------------------:|---------:|-------:|-------:| + * | ACC_CONFIG_PRF_19_5_MHZ* | 19.5 MHz | 3.1 m | 7.7 m | + * | ACC_CONFIG_PRF_15_6_MHZ | 15.6 MHz | 5.1 m | 9.6 m | + * | ACC_CONFIG_PRF_13_0_MHZ | 13.0 MHz | 7.0 m | 11.5 m | + * | ACC_CONFIG_PRF_8_7_MHZ | 8.7 MHz | 12.7 m | 17.3 m | + * | ACC_CONFIG_PRF_6_5_MHZ | 6.5 MHz | 18.5 m | 23.1 m | + * | ACC_CONFIG_PRF_5_2_MHZ | 5.2 MHz | 24.3 m | 28.8 m | + * + * *19.5MHz is only available for profile 1. + */ +typedef enum +{ + /*! 19.5 MHz */ + ACC_CONFIG_PRF_19_5_MHZ, + /*! 15.6 MHz */ + ACC_CONFIG_PRF_15_6_MHZ, + /*! 13.0 MHz */ + ACC_CONFIG_PRF_13_0_MHZ, + /*! 8.7 MHz */ + ACC_CONFIG_PRF_8_7_MHZ, + /*! 6.5 MHz */ + ACC_CONFIG_PRF_6_5_MHZ, + /*! 5.2 MHz */ + ACC_CONFIG_PRF_5_2_MHZ, +} acc_config_prf_t; + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_definitions_common.h b/rss/include/xtensa/acc_definitions_common.h new file mode 100644 index 0000000..e688f67 --- /dev/null +++ b/rss/include/xtensa/acc_definitions_common.h @@ -0,0 +1,50 @@ +// Copyright (c) Acconeer AB, 2018-2023 +// All rights reserved + +#ifndef ACC_DEFINITIONS_COMMON_H_ +#define ACC_DEFINITIONS_COMMON_H_ + +#include +#include + + +/** + * @brief Type representing a sensor ID + */ +typedef uint32_t acc_sensor_id_t; + +/** + * @brief Macro for printing sensor id + */ +#define PRIsensor_id PRIu32 + + +/** + * @brief This enum represents the different log levels for RSS + */ +typedef enum +{ + /*! ERROR log level. */ + ACC_LOG_LEVEL_ERROR, + /*! WARNING log level. */ + ACC_LOG_LEVEL_WARNING, + /*! INFO log level. */ + ACC_LOG_LEVEL_INFO, + /*! VERBOSE log level. */ + ACC_LOG_LEVEL_VERBOSE, + /*! DEBUG log level. */ + ACC_LOG_LEVEL_DEBUG +} acc_log_level_t; + + +/** + * @brief Data type for interger-based representation of complex numbers + */ +typedef struct +{ + int16_t real; + int16_t imag; +} acc_int16_complex_t; + + +#endif diff --git a/rss/include/xtensa/acc_detector_distance.h b/rss/include/xtensa/acc_detector_distance.h new file mode 100644 index 0000000..1596268 --- /dev/null +++ b/rss/include/xtensa/acc_detector_distance.h @@ -0,0 +1,569 @@ +// Copyright (c) Acconeer AB, 2022-2023 +// All rights reserved + +#ifndef ACC_DETECTOR_DISTANCE_H_ +#define ACC_DETECTOR_DISTANCE_H_ + + +#include +#include + +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" +#include "acc_detector_distance_definitions.h" +#include "acc_processing.h" +#include "acc_sensor.h" + +/** + * @defgroup Distance Distance Detector + * @ingroup Detectors + * + * @brief Distance detector API description + * + * For a detailed description of the algorithm and its parameters, see + * docs.acconeer.com + * @{ + */ + +#define ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES (10U) + + +/** + * @brief Distance detector handle + */ +struct acc_detector_distance_handle; + +typedef struct acc_detector_distance_handle acc_detector_distance_handle_t; + + +/** + * @brief Configuration of the distance detector + */ +struct acc_detector_distance_config; + +typedef struct acc_detector_distance_config acc_detector_distance_config_t; + + +/** + * @brief Distance detector result + */ +typedef struct +{ + /** + * The detected distances in meters + */ + float distances[ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES]; + /** + * The reflective strengths of each distance + */ + float strengths[ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES]; + /** + * The number of detected distances. If 0, no distances where detected + */ + uint8_t num_distances; + /** + * Indicating that there might be an object near the start point of the measured range + */ + bool near_start_edge_status; + /** + * Indication of calibration needed. + * + * The sensor calibration needs to be redone if this indication is set. + * + * A detector calibration update should then be done after the new sensor calibration. + * A detector calibration update is done by calling @ref acc_detector_distance_update_calibration + */ + bool calibration_needed; + /** Temperature in sensor during measurement (in degree Celsius). + * Note that it has poor absolute accuracy and should only be used + * for relative temperature measurements. + */ + int16_t temperature; + /** + * Radar data that the distance detection is based on. + * This will point to memory in the buffer supplied to @ref acc_detector_distance_process + * + * Note: The processing result is only valid until the next time + * @ref acc_detector_distance_process is called. + */ + acc_processing_result_t *processing_result; + /** + * The metadata for the processing result + * + * Note: The processing metedata is only valid until the next time + * @ref acc_detector_distance_process is called. + */ + acc_processing_metadata_t *processing_metadata; + /** + * The sensor_config used for the processing result + * + * Note: The sensor_config is only valid until the next time + * @ref acc_detector_distance_process is called. + */ + const acc_config_t *sensor_config; +} acc_detector_distance_result_t; + + +/** + * @brief Create a configuration for a distance detector + * + * @return Distance detector configuration, NULL in case of error + */ +acc_detector_distance_config_t *acc_detector_distance_config_create(void); + + +/** + * @brief Destroy a configuration for a distance detector + * + * @param[in] config The configuration to destroy + */ +void acc_detector_distance_config_destroy(acc_detector_distance_config_t *config); + + +/** + * @brief Print a configuration to the log + * + * @param[in] handle The distance detector handle, if NULL only distance config will be logged + * @param[in] config The configuration to log + */ +void acc_detector_distance_config_log(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config); + + +/** + * @brief Get the sizes needed given the provided detector handle + * + * buffer_size is the size of memory needed by the detector for proper operation. This includes memory + * for sensor handling and detector calculations. This memory can be reused between instances. + * + * detector_cal_result_static_size is the size of the static part of the detector calibration result. + * + * Both size are dependent on the configuration used which is contained in the provided handle. + * + * @param[in] handle The distance detector handle + * @param[out] buffer_size The buffer size + * @param[out] detector_cal_result_static_size The calibration result size + * @return true if successful, false otherwise + */ +bool acc_detector_distance_get_sizes(const acc_detector_distance_handle_t *handle, + uint32_t *buffer_size, + uint32_t *detector_cal_result_static_size); + + +/** + * @brief Create a distance detector with the provided configuration + * + * @param[in] config The configuration to create a distance detector with + * @return Distance detector handle, NULL if distance detector was not possible to create + */ +acc_detector_distance_handle_t *acc_detector_distance_create(const acc_detector_distance_config_t *config); + + +/** + * @brief Destroy the distance detector handle, freeing its resources + * + * @param[in] handle The handle to destroy + */ +void acc_detector_distance_destroy(acc_detector_distance_handle_t *handle); + + +/** + * @brief Do a detector calibration + * + * The calibration is dependent on the config used. This means that the duration of the + * calibration is dependent on the config used. For example, a config with a fixed threshold + * will not need to record the background as opposed to a config with a recorded threshold. + * + * The calibration needs a valid sensor calibration result for proper operation. + * + * The calibration produces two results, one static and one dynamic. The static result is not + * temperature dependent and thus can be used in all temperatures. The dynamic result is + * temperature dependent and needs to be updated if the temperature changes, which is indicated + * by the 'calibration_needed' indication. + * + * @param[in] sensor The sensor instance to use for calibration + * @param[in] handle The detector handle + * @param[in] sensor_cal_result Sensor calibration result + * @param[in] buffer Working memory buffer needed by function + * @param[in] buffer_size The size of buffer. Needs to be at least + * the result of @ref acc_detector_distance_get_sizes + * @param[out] detector_cal_result_static Static result of calibration + * @param[in] detector_cal_result_static_size The size of detector_cal_result_static. + * Needs to be at least the result of @ref acc_detector_distance_get_sizes + * @param[out] detector_cal_result_dynamic Dynamic result of calibration + * @param[out] calibration_complete Will be set to true when the calibration is complete. + * If false; at least one more call to this function is needed. + * Note that it's necessary to wait for interrupt between calls. + * @return true if successful, false otherwise + */ +bool acc_detector_distance_calibrate(acc_sensor_t *sensor, + acc_detector_distance_handle_t *handle, + const acc_cal_result_t *sensor_cal_result, + void *buffer, + uint32_t buffer_size, + uint8_t *detector_cal_result_static, + uint32_t detector_cal_result_static_size, + acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, + bool *calibration_complete); + + +/** + * @brief Update the calibration + * + * This function should be called if the 'calibration_needed' indication is set, + * after a new sensor calibration has been done. + * + * The calibration update needs a valid sensor calibration result for proper operation. + * + * @param[in] sensor The sensor instance to use for calibration update + * @param[in] handle The detector handle + * @param[in] sensor_cal_result Sensor calibration result + * @param[in] buffer Working memory buffer needed by function + * @param[in] buffer_size The size of buffer. Needs to be at least + * the result of @ref acc_detector_distance_get_sizes + * @param[out] detector_cal_result_dynamic Result of the calibration update + * @param[out] calibration_complete Will be set to true when the calibration update is complete. + * If false; at least one more call to this function is needed. + * Note that it's necessary to wait for interrupt between calls. + * @return true if successful, false otherwise + */ +bool acc_detector_distance_update_calibration(acc_sensor_t *sensor, + acc_detector_distance_handle_t *handle, + const acc_cal_result_t *sensor_cal_result, + void *buffer, + uint32_t buffer_size, + acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, + bool *calibration_complete); + + +/** + * @brief Prepare the detector for measurements + * + * This should to be done before every measure/wait for interrupt/read, as it reconfigures the sensor. + * + * @param[in, out] handle The distance detector handle + * @param[in] config The distance detector config + * @param[in] sensor The sensor instance to prepare + * @param[in] sensor_cal_result The sensor calibration result to prepare with + * @param[in] buffer Memory used by the detector. Should be at least buffer_size bytes + * @param[in] buffer_size The buffer size received by @ref acc_detector_distance_get_sizes + * @return true if successful, false otherwise + */ +bool acc_detector_distance_prepare(const acc_detector_distance_handle_t *handle, + const acc_detector_distance_config_t *config, + acc_sensor_t *sensor, + const acc_cal_result_t *sensor_cal_result, + void *buffer, + uint32_t buffer_size); + + +/** + * @brief Process the data according to the configuration used in @ref acc_detector_distance_config_create + * + * @param[in] handle The distance detector handle + * @param[in] buffer A reference to the buffer (populated by @ref acc_sensor_read) containing the + * data to be processed. + * @param[in] detector_cal_result_static The result from @ref acc_detector_distance_calibrate + * @param[in] detector_cal_result_dynamic The result from @ref acc_detector_distance_calibrate or @ref acc_detector_distance_update_calibration + * @param[out] result_available Whether result will contain a new result + * @param[out] result Distance detector result + * @return true if successful, false otherwise + */ +bool acc_detector_distance_process(acc_detector_distance_handle_t *handle, + void *buffer, + uint8_t *detector_cal_result_static, + acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, + bool *result_available, + acc_detector_distance_result_t *result); + + +/** + * @brief Set the sensor ID + * + * @param[out] config The distance detector config + * @param[in] sensor Sensor ID + */ +void acc_detector_distance_config_sensor_set(acc_detector_distance_config_t *config, acc_sensor_id_t sensor); + + +/** + * @brief Get the sensor ID + * + * @param[in] config The distance detector config + * @return Sensor ID + */ +acc_sensor_id_t acc_detector_distance_config_sensor_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the start of measured interval in meters. + * + * @param[out] config The distance detector config + * @param[in] start_m Starting point in meters. + */ +void acc_detector_distance_config_start_set(acc_detector_distance_config_t *config, float start_m); + + +/** + * @brief Get the start of measured interval in meters. + * + * @param[in] config The distance detector config + * @return the start point in meters + */ +float acc_detector_distance_config_start_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the end of measured interval in meters. + * + * @param[out] config The distance detector config + * @param[in] end_m End point in meters. + */ +void acc_detector_distance_config_end_set(acc_detector_distance_config_t *config, float end_m); + + +/** + * @brief Get the end of measured interval in meters. + * + * @param[in] config The distance detector config + * @return the end point in meters + */ +float acc_detector_distance_config_end_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the maximum step length + * + * Used to limit step length. If set to 0 (default), the step length is calculated + * based on profile. + * + * @param[out] config The distance detector config + * @param[in] max_step_length The maximum step length + */ +void acc_detector_distance_config_max_step_length_set(acc_detector_distance_config_t *config, uint16_t max_step_length); + + +/** + * @brief Get the maximum step length + * + * @param[in] config The distance detector config + * @return the maximum step length + */ +uint16_t acc_detector_distance_config_max_step_length_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Enable the close range leakage cancellation logic + * + * Close range leakage cancellation refers to the process of measuring close to the + * sensor(<100mm) by first characterizing the direct leakage, and then subtracting it + * from the measured sweep in order to isolate the signal component of interest. + * The close range leakage cancellation process requires the sensor to be installed in its + * intended geometry with free space in front of the sensor during detector calibration. + * + * @param[out] config The distance detector config + * @param[in] enable true to enable close range leakage cancellation logic, false to disable + */ +void acc_detector_distance_config_close_range_leakage_cancellation_set(acc_detector_distance_config_t *config, bool enable); + + +/** + * @brief Get if the close range leakage cancellation logic is enabled + * + * @param[in] config The distance detector config + * @return true if close range leakage cancellation logic is enabled, false if disabled + */ +bool acc_detector_distance_config_close_range_leakage_cancellation_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the signal quality + * + * High signal quality results in a better SNR (because of higher HWAAS) and higher power consumption. + * Signal quality can be set within the interval [-10, 35]. + * + * @param[out] config The distance detector config + * @param[in] signal_quality The signal quality + */ +void acc_detector_distance_config_signal_quality_set(acc_detector_distance_config_t *config, float signal_quality); + + +/** + * @brief Get the signal quality + * + * @param[in] config The distance detector config + * @return the signal quality + */ +float acc_detector_distance_config_signal_quality_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the max profile + * + * Specifies the highest allowed profile (the default is the highest, Profile 5). + * A higher profile yields better SNR but worse distance resolution. + * + * @param[out] config The distance detector config + * @param[in] max_profile The max profile + */ +void acc_detector_distance_config_max_profile_set(acc_detector_distance_config_t *config, acc_config_profile_t max_profile); + + +/** + * @brief Get the max profile + * + * @param[in] config The distance detector config + * @return the max profile + */ +acc_config_profile_t acc_detector_distance_config_max_profile_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the threshold method + * + * See @ref acc_detector_distance_threshold_method_t for details + * + * @param[out] config The distance detector config + * @param[in] threshold_method The threshold method + */ +void acc_detector_distance_config_threshold_method_set(acc_detector_distance_config_t *config, + acc_detector_distance_threshold_method_t threshold_method); + + +/** + * @brief Get the threshold method + * + * @param[in] config The distance detector config + * @return the threshold method + */ +acc_detector_distance_threshold_method_t acc_detector_distance_config_threshold_method_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the peak sorting method + * + * See @ref acc_detector_distance_peak_sorting_t for details + * + * @param[out] config The distance detector config + * @param[in] peak_sorting The peak sorting method + */ +void acc_detector_distance_config_peak_sorting_set(acc_detector_distance_config_t *config, acc_detector_distance_peak_sorting_t peak_sorting); + + +/** + * @brief Get the peak sorting method + * + * See @ref acc_detector_distance_config_peak_sorting_set + * + * @param[in] config The distance detector config + * @return The peak sorting method + */ +acc_detector_distance_peak_sorting_t acc_detector_distance_config_peak_sorting_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set the number frames to use for recorded threshold + * + * @param[out] config The distance detector config + * @param[in] num_frames Number of frames + */ +void acc_detector_distance_config_num_frames_recorded_threshold_set(acc_detector_distance_config_t *config, uint16_t num_frames); + + +/** + * @brief Get the number of frames to use for recorded threshold + * + * @param[in] config The distance detector config + * @return Number of frames + */ +uint16_t acc_detector_distance_config_num_frames_recorded_threshold_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set fixed amplitude threshold value + * + * This value is used when the threshold method is set to @ref ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_FIXED_AMPLITUDE + * + * @param[out] config The distance detector config + * @param[in] fixed_threshold_value The fixed threshold value + */ +void acc_detector_distance_config_fixed_amplitude_threshold_value_set(acc_detector_distance_config_t *config, float fixed_threshold_value); + + +/** + * @brief Get fixed amplitude threshold value + * + * See @ref acc_detector_distance_config_fixed_amplitude_threshold_value_set + * + * @param[in] config The distance detector config + * @return The fixed threshold value + */ +float acc_detector_distance_config_fixed_amplitude_threshold_value_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set fixed strength threshold value + * + * This value is used when the threshold method is set to @ref ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_FIXED_STRENGTH + * + * @param[out] config The distance detector config + * @param[in] fixed_threshold_value The fixed threshold value + */ +void acc_detector_distance_config_fixed_strength_threshold_value_set(acc_detector_distance_config_t *config, float fixed_threshold_value); + + +/** + * @brief Get fixed strength threshold value + * + * See @ref acc_detector_distance_config_fixed_strength_threshold_value_set + * + * @param[in] config The distance detector config + * @return The fixed threshold value + */ +float acc_detector_distance_config_fixed_strength_threshold_value_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set threshold sensitivity + * + * High sensitivity yields a low detection threshold, low sensitivity yields a high detection threshold. + * Threshold sensitivity can be set within the interval [0, 1]. + * + * @param[out] config The distance detector config + * @param[in] threshold_sensitivity The threshold sensitivity + */ +void acc_detector_distance_config_threshold_sensitivity_set(acc_detector_distance_config_t *config, float threshold_sensitivity); + + +/** + * @brief Get threshold sensitivity + * + * @param[in] config The distance detector config + * @return The threshold sensitivity + */ +float acc_detector_distance_config_threshold_sensitivity_get(const acc_detector_distance_config_t *config); + + +/** + * @brief Set reflector shape + * + * @param[out] config The distance detector config + * @param[in] reflector_shape The reflector shape + */ +void acc_detector_distance_config_reflector_shape_set(acc_detector_distance_config_t *config, + acc_detector_distance_reflector_shape_t reflector_shape); + + +/** + * @brief Get reflector shape + * + * @param[in] config The distance detector config + * @return The reflector shape + */ +acc_detector_distance_reflector_shape_t acc_detector_distance_config_reflector_shape_get(const acc_detector_distance_config_t *config); + + +/** + * @} + */ + +#endif diff --git a/rss/include/xtensa/acc_detector_distance_definitions.h b/rss/include/xtensa/acc_detector_distance_definitions.h new file mode 100644 index 0000000..79d5ce5 --- /dev/null +++ b/rss/include/xtensa/acc_detector_distance_definitions.h @@ -0,0 +1,65 @@ +// Copyright (c) Acconeer AB, 2022-2023 +// All rights reserved + +#ifndef ACC_DETECTOR_DISTANCE_DEFINITIONS_H_ +#define ACC_DETECTOR_DISTANCE_DEFINITIONS_H_ + + +#include + + +/** + * The size of the result from a completed calibration update. + */ +#define ACC_DETECTOR_CAL_RESULT_DYNAMIC_DATA_SIZE (8U) + +/** + * The result from a completed calibration update. + */ +typedef struct +{ + uint8_t data[ACC_DETECTOR_CAL_RESULT_DYNAMIC_DATA_SIZE]; +} acc_detector_cal_result_dynamic_t; + + +/** + * @brief Enum for peak sorting algorithms + */ +typedef enum +{ + /*! Return peaks with the closest detection first. */ + ACC_DETECTOR_DISTANCE_PEAK_SORTING_CLOSEST, + /*! Return peaks with the peak with the highest RCS first. */ + ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST, +} acc_detector_distance_peak_sorting_t; + + +/** + * @brief Enum for threshold methods + */ +typedef enum +{ + /*! Compares processed data against a fixed amplitude value */ + ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_FIXED_AMPLITUDE, + /*! Compares processed data against a fixed strength value */ + ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_FIXED_STRENGTH, + /*! Compares processed data against a recorded threshold */ + ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_RECORDED, + /*! Uses the CFAR algorithm as a threshold */ + ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_CFAR +} acc_detector_distance_threshold_method_t; + + +/** + * @brief Enum for reflector shapes + */ +typedef enum +{ + /*! Use a generic reflector shape for RCS calculation */ + ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_GENERIC, + /*! Use a planar reflector shape for RCS calculation */ + ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR, +} acc_detector_distance_reflector_shape_t; + + +#endif diff --git a/rss/include/xtensa/acc_detector_presence.h b/rss/include/xtensa/acc_detector_presence.h new file mode 100644 index 0000000..fc938d5 --- /dev/null +++ b/rss/include/xtensa/acc_detector_presence.h @@ -0,0 +1,773 @@ +// Copyright (c) Acconeer AB, 2022-2023 +// All rights reserved + +#ifndef ACC_DETECTOR_PRESENCE_H_ +#define ACC_DETECTOR_PRESENCE_H_ + +#include +#include +#include + +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" +#include "acc_processing.h" +#include "acc_sensor.h" + +/** + * @defgroup Presence Presence Detector + * @ingroup Detectors + * + * @brief Presence detector API description + * + * For a detailed description of the presence detector algorithm and its + * configuration parameters, see + * + * docs.acconeer.com + * + * @{ + */ + + +/** + * @brief Presence detector handle + */ +struct acc_detector_presence_handle; + +typedef struct acc_detector_presence_handle acc_detector_presence_handle_t; + + +/** + * @brief Presence detector configuration container + */ +struct acc_detector_presence_config; + +typedef struct acc_detector_presence_config acc_detector_presence_config_t; + + +/** + * @brief Presence detector results container + */ +typedef struct +{ + /** + * true if presence was detected, false otherwise + */ + bool presence_detected; + /** + * A measure of the amount of fast motion detected + */ + float intra_presence_score; + /** + * A measure of the amount of slow motion detected + */ + float inter_presence_score; + /** + * The distance, in meters, to the detected object + */ + float presence_distance; + /** + * An array of measures of the amount of fast motion detected per distance point. + * This will point to memory in the buffer supplied to @ref acc_detector_presence_process + */ + float *depthwise_intra_presence_scores; + /** + * An array of measures of the amount of slow motion detected per distance point. + * This will point to memory in the buffer supplied to @ref acc_detector_presence_process + */ + float *depthwise_inter_presence_scores; + /** + * The number of elements in the depthwise presence scores arrays + */ + uint32_t depthwise_presence_scores_length; + /** + * Radar data that the presence detection is based on. + * This will point to memory in the buffer supplied to @ref acc_detector_presence_process + */ + acc_processing_result_t processing_result; +} acc_detector_presence_result_t; + + +/** + * brief Metadata for presence detector + */ +typedef struct +{ + /** + * Actual start point of measurement in m. + * This can be useful to know the exact start point of the measurement in m. + * The resolution of each point is approximately 2.5mm + */ + float start_m; + /** + * Actual step length between each data point of the measurement in m. + * This can be useful when automatic selection of step length based on the profile + * is enabled through @ref acc_detector_presence_config_auto_step_length_set + */ + float step_length_m; + /** + * Number of data points in measurement. + * This is calculated from the requested start and end point and the resulting + * step length. This corresponds to the length of the depthwise inter/intra + * presence score results, which can be useful to know already at detector creation. + */ + uint16_t num_points; + /** + * Profile used. + * This can be useful when automatic selection of profile based on start point + * is enabled through @ref acc_detector_presence_config_auto_profile_set + */ + acc_config_profile_t profile; +} acc_detector_presence_metadata_t; + + +/** + * @brief Create a configuration for a presence detector + * + * @return Presence detector configuration, NULL if creation was not possible + */ +acc_detector_presence_config_t *acc_detector_presence_config_create(void); + + +/** + * @brief Destroy a presence detector configuration + * + * @param[in] presence_config The configuration to destroy + */ +void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config); + + +/** + * @brief Print a configuration to the log + * + * @param[in] presence_config The configuration to log + */ +void acc_detector_presence_config_log(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Get the buffer size needed for the provided presence detector handle + * + * This buffer size can be used to allocate a memory buffer in the + * application, which is needed for several functions in the detector library. + * This size will also include memory for holding the depthwise inter/intra presence + * score arrays that will be part of the result, see @ref acc_detector_presence_result_t + * + * @param[in] presence_handle The presence detector handle to to get the buffer size for + * @param[out] buffer_size The buffer size + * @return true if successful, false otherwise + */ +bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size); + + +/** + * @brief Create a presence detector with the provided configuration + * + * @param[in] presence_config The presence detector configuration to create a presence detector with + * @param[out] metadata Metadata for the presence detector given the presence_config + * @return Presence detector handle, NULL if presence detector was not possible to create + */ +acc_detector_presence_handle_t *acc_detector_presence_create(acc_detector_presence_config_t *presence_config, + acc_detector_presence_metadata_t *metadata); + + +/** + * @brief Destroy a presence detector identified with the provided handle + * + * Destroy the context of a presence detector allowing another presence detector to be created using the + * same resources. + * If NULL is sent in, nothing happens. + * + * @param[in] presence_handle A reference to the presence detector handle to destroy + */ +void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle); + + +/** + * @brief Prepare the detector to do a measurement + * + * @param[in] presence_handle The presence detector handle to prepare for + * @param[in] presence_config The configuration to prepare with + * @param[in] sensor The sensor instance to prepare + * @param[in] cal_result The calibration result to prepare with + * @param[in] buffer Memory used by the detector to prepare the sensor for measurements + * The buffer will only be used during the duration of this call + * @param[in] buffer_size The size in bytes of the buffer, should be at least buffer_size + * from @ref acc_detector_presence_get_buffer_size + * @return true if successful, false otherwise + */ +bool acc_detector_presence_prepare(acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, + acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size); + + +/** + * @brief Process the data according to the configuration used in @ref acc_detector_presence_config_create + * + * @param[in] presence_handle The presence detector handle for the presence detector to get the next result for + * @param[in] buffer A reference to the buffer (populated by @ref acc_sensor_read) containing the + * data to be processed. + * After this function returns, the depthwise inter/intra presence that is part of the + * result (@ref acc_detector_presence_result_t) will point to memory located in this buffer. + * If these arrays are of interest for the application they need to be processed + * before the buffer is used in any other function. + * @param[out] result Presence detector results + * @return true if successful, otherwise false + */ +bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, + acc_detector_presence_result_t *result); + + +/** + * @brief Set the start point of measurement interval in meters + * + * @param[in] presence_config The configuration + * @param[in] start The start point of measurement interval in meters + */ +void acc_detector_presence_config_start_set(acc_detector_presence_config_t *presence_config, float start); + + +/** + * @brief Get the start point of measurement interval in meters + * + * @param[in] presence_config The configuration + * @return The start point of measurement interval in meters + */ +float acc_detector_presence_config_start_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the end point of measurement interval in meters + * + * @param[in] presence_config The configuration + * @param[in] end The end point of measurement interval in meters + */ +void acc_detector_presence_config_end_set(acc_detector_presence_config_t *presence_config, float end); + + +/** + * @brief Get the end point of measurement interval in meters + * + * @param[in] presence_config The configuration + * @return The end point of measurement interval in meters + */ +float acc_detector_presence_config_end_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the step length in points + * + * This sets the number of steps between each data point. + * + * The set step length will only be used if step length auto selection was disabled + * through @ref acc_detector_presence_config_auto_step_length_set + * + * Sampling produces complex (IQ) data points with configurable distance spacing, + * starting from ~2.5mm. + * + * @param[in] presence_config The configuration + * @param[in] step_length The step length + */ +void acc_detector_presence_config_step_length_set(acc_detector_presence_config_t *presence_config, uint16_t step_length); + + +/** + * @brief Get the step length in points + * + * @see acc_detector_presence_config_step_length_set + * + * @param[in] presence_config The configuration + * @return The step length + */ +uint16_t acc_detector_presence_config_step_length_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Enable automatic selection of step length based on the profile + * + * The highest possible step length based on the fwhm of the set profile + * with the goal to achieve detection on the complete range with minimum number + * of sampling points + * + * @param[in] presence_config The configuration + * @param[in] enable true to enable auto selection, false to disable + */ +void acc_detector_presence_config_auto_step_length_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if automatic selection of step length based on the profile is enabled + * + * See @ref acc_detector_presence_config_auto_step_length_set + * + * @param[in] presence_config The configuration + * @return true if automatic selection of step length is enabled, false if disabled + */ +bool acc_detector_presence_config_auto_step_length_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set a profile + * + * Each profile consists of a number of settings for the sensor that configures + * the RX and TX paths. Lower profiles have higher depth resolution while + * higher profiles have higher SNR. + * + * The set profile will only be used if profile auto selection was disabled + * through @ref acc_detector_presence_config_auto_profile_set + * + * @param[in] presence_config The configuration + * @param[in] profile The profile to set + */ +void acc_detector_presence_config_profile_set(acc_detector_presence_config_t *presence_config, acc_config_profile_t profile); + + +/** + * @brief Get the currently set profile + * + * See @ref acc_detector_presence_config_profile_set + * + * @param[in] presence_config The configuration + * @return The profile currently used + */ +acc_config_profile_t acc_detector_presence_config_profile_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Enable automatic selection of profile based on start point of measurement + * + * The highest possible profile without interference of direct leakage will used to maximize SNR + * + * @param[in] presence_config The configuration + * @param[in] enable true to enable auto selection, false to disable + */ +void acc_detector_presence_config_auto_profile_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if automatic selection of profile based on start point of measurement is enabled + * + * See @ref acc_detector_presence_config_auto_profile_set + * + * @param[in] presence_config The configuration + * @return true if automatic selection of profile is enabled, false if disabled + */ +bool acc_detector_presence_config_auto_profile_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set inter frame idle state + * + * The 'inter-frame idle state' is the state the sensor idles in between each frame. + * + * See also @ref acc_config_idle_state_t. + * + * @param[in] presence_config The configuration + * @param[in] idle_state The idle state to use between frames + */ +void acc_detector_presence_config_inter_frame_idle_state_set(acc_detector_presence_config_t *presence_config, + acc_config_idle_state_t idle_state); + + +/** + * @brief Get inter frame idle state + * + * See @ref acc_detector_presence_config_inter_frame_idle_state_set + * + * @param[in] presence_config The configuration + * @return The idle state to use between frames + */ +acc_config_idle_state_t acc_detector_presence_config_inter_frame_idle_state_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the hardware accelerated average samples (HWAAS) + * + * See @ref acc_config_hwaas_set for more details + * + * @param[in] presence_config The configuration + * @param[in] hwaas Hardware accelerated average samples + */ +void acc_detector_presence_config_hwaas_set(acc_detector_presence_config_t *presence_config, uint16_t hwaas); + + +/** + * @brief Get the hardware accelerated average samples (HWAAS) + * + * See @ref acc_detector_presence_config_hwaas_set + * + * @param[in] presence_config The configuration + * @return Hardware accelerated average samples + */ +uint16_t acc_detector_presence_config_hwaas_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the number of sweeps per frame + * + * Sets the number of sweeps that will be captured in each frame (measurement). + * + * @param[in] presence_config The configuration + * @param[in] sweeps_per_frame Sweeps per frame, must be at least 6 + */ +void acc_detector_presence_config_sweeps_per_frame_set(acc_detector_presence_config_t *presence_config, uint16_t sweeps_per_frame); + + +/** + * @brief Get the number of sweeps per frame + * + * See @ref acc_detector_presence_config_sweeps_per_frame_set + * + * @param[in] presence_config The configuration + * @return Sweeps per frame + */ +uint16_t acc_detector_presence_config_sweeps_per_frame_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the frame rate + * + * This frame rate is maintained by the sensor if @ref acc_detector_presence_config_frame_rate_app_driven_set + * is invoked with false (default) and the application must maintain the given frame rate if invoked with true. + * If the application maintains the frame rate it is important that it doesn't deviate more than 10% + * from the set value for the presence algorithm to work optimally. + * See @ref acc_config_frame_rate_set for details + * + * @param[in] presence_config The configuration + * @param[in] frame_rate Frame rate in Hz. Must be > 0 + */ +void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate); + + +/** + * @brief Get the frame rate + * + * See @ref acc_detector_presence_config_frame_rate_set + * + * @param[in] presence_config The configuration + * @return Frame rate in Hz + */ +float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set if the application should maintain the requested frame rate + * + * If set to true, the application must maintain the frame rate set using + * @ref acc_detector_presence_config_frame_rate_set + * If set to false, the frame rate is maintained by the sensor at the frame rate given by + * @ref acc_detector_presence_config_frame_rate_set. + * + * @param[in] presence_config The configuration + * @param[in] enable true to enable application driven frame rate, false to disable + */ +void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if the application should maintain the requested frame rate + * + * See @ref acc_detector_presence_config_frame_rate_app_driven_set + * + * @param[in] presence_config The configuration + * @return true if application driven frame rate is enabled, false if disabled + */ +bool acc_detector_presence_config_frame_rate_app_driven_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set sensor ID + * + * @param[in] presence_config The configuration to set the sensor ID for + * @param[in] sensor_id The sensor ID + */ +void acc_detector_presence_config_sensor_set(acc_detector_presence_config_t *presence_config, acc_sensor_id_t sensor_id); + + +/** + * @brief Get sensor ID + * + * @param[in] presence_config The configuration to get the sensor ID for + * @return sensor ID + */ +acc_sensor_id_t acc_detector_presence_config_sensor_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set if the presence filters should reset on prepare + * + * If set to true, the presence filters will be reset when + * @ref acc_detector_presence_prepare is invoked. + * + * @param[in] presence_config The configuration + * @param[in] enable true to reset the filters on prepare, false to not reset + */ +void acc_detector_presence_config_reset_filters_on_prepare_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if the presence filters should reset on prepare + * + * See @ref acc_detector_presence_config_reset_filters_on_prepare_set + * + * @param[in] presence_config The configuration + * @return true if filters should reset on prepare, false otherwise + */ +bool acc_detector_presence_config_reset_filters_on_prepare_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the inter-frame presence timeout in seconds + * + * Number of seconds the inter-frame presence score needs to decrease before exponential + * scaling starts for faster decline. Should be between 0 and 30 where 0 means no timeout + * + * @param[in] presence_config The configuration + * @param[in] inter_frame_presence_timeout Timeout in seconds between 0 and 30 + */ +void acc_detector_presence_config_inter_frame_presence_timeout_set(acc_detector_presence_config_t *presence_config, + uint16_t inter_frame_presence_timeout); + + +/** + * @brief Get the inter-frame presence timeout in seconds + * + * See @ref acc_detector_presence_config_inter_frame_presence_timeout_set + * + * @param[in] presence_config The configuration + * @return Inter-frame presence timeout in s + */ +uint16_t acc_detector_presence_config_inter_frame_presence_timeout_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set inter-frame phase boost + * + * Used to increase detection of slow motions by utilizing the phase information in the Sparse IQ data. + * + * @param[in] presence_config The configuration to set inter phase boost for + * @param[in] enable true if inter phase boost should be enabled + */ +void acc_detector_presence_config_inter_phase_boost_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if inter-frame phase boost is enabled + * + * See @ref acc_detector_presence_config_inter_phase_boost_set + * + * @param[in] presence_config The configuration to get inter phase boost for + * @return true if inter-frame phase boost is enabled, false otherwise + */ +bool acc_detector_presence_config_inter_phase_boost_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set intra-frame presence detection + * + * This is used for detecting faster movements inside frames + * + * @param[in] presence_config The configuration to set intra-frame detection for + * @param[in] enable true if intra-frame detection should be enabled + */ +void acc_detector_presence_config_intra_detection_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if frame intra-frame presence detection is enabled + * + * See @ref acc_detector_presence_config_intra_detection_set + * + * @param[in] presence_config The configuration to get intra detection for + * @return true if intra-frame detection is enabled, false otherwise + */ +bool acc_detector_presence_config_intra_detection_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the detection threshold for the intra-frame presence detection + * + * This is the threshold for detecting faster movements inside frames + * + * @param[in] presence_config The configuration to set the detection threshold for + * @param[in] intra_detection_threshold The intra-frame detection threshold to set + */ +void acc_detector_presence_config_intra_detection_threshold_set(acc_detector_presence_config_t *presence_config, + float intra_detection_threshold); + + +/** + * @brief Get the detection threshold for the intra-frame presence detection + * + * See @ref acc_detector_presence_config_intra_detection_threshold_set + * + * @param[in] presence_config The configuration to get the detection threshold for + * @return The intra-frame detection threshold + */ +float acc_detector_presence_config_intra_detection_threshold_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set inter-frame presence detection + * + * This is used for detecting slower movements between frames + * + * @param[in] presence_config The configuration to set inter-frame detection for + * @param[in] enable true if inter-frame presence detection should be enabled + */ +void acc_detector_presence_config_inter_detection_set(acc_detector_presence_config_t *presence_config, bool enable); + + +/** + * @brief Get if inter-frame presence detection is enabled + * + * See @ref acc_detector_presence_config_inter_detection_set + * + * @param[in] presence_config The configuration to get inter-frame presence detection for + * @return true if inter-frame presence detection is enabled, false otherwise + */ +bool acc_detector_presence_config_inter_detection_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the detection threshold for the inter-frame presence detection + * + * This is the threshold for detecting slower movements between frames + * + * @param[in] presence_config The configuration to set the detection threshold for + * @param[in] inter_detection_threshold The threshold + */ +void acc_detector_presence_config_inter_detection_threshold_set(acc_detector_presence_config_t *presence_config, + float inter_detection_threshold); + + +/** + * @brief Get the detection threshold for the inter-frame presence detection + * + * See @ref acc_detector_presence_config_inter_detection_threshold_set + * + * @param[in] presence_config The configuration to get the detection threshold for + * @return detection threshold + */ +float acc_detector_presence_config_inter_detection_threshold_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the time constant of the low pass filter for the inter-frame deviation between fast and slow + * + * @param[in] presence_config The configuration + * @param[in] inter_frame_deviation_time_const Time constant to set + */ +void acc_detector_presence_config_inter_frame_deviation_time_const_set(acc_detector_presence_config_t *presence_config, + float inter_frame_deviation_time_const); + + +/** + * @brief Get the time constant of the low pass filter for the inter-frame deviation between fast and slow + * + * @param[in] presence_config The configuration to get the time constant for + * @return time constant in s + */ +float acc_detector_presence_config_inter_frame_deviation_time_const_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the cutoff frequency of the low pass filter for the fast filtered absolute sweep mean + * + * No filtering is applied if the cutoff is set over half the frame rate (Nyquist limit). + * + * @param[in] presence_config The configuration + * @param[in] inter_frame_fast_cutoff Cutoff frequency to set + */ +void acc_detector_presence_config_inter_frame_fast_cutoff_set(acc_detector_presence_config_t *presence_config, + float inter_frame_fast_cutoff); + + +/** + * @brief Get the cutoff frequency of the low pass filter for the fast filtered absolute sweep mean + * + * @param[in] presence_config The configuration to get the cutoff frequency for + * @return the cutoff frequency in Hz + */ +float acc_detector_presence_config_inter_frame_fast_cutoff_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the cutoff frequency of the low pass filter for the slow filtered absolute sweep mean + * + * @param[in] presence_config The configuration + * @param[in] inter_frame_slow_cutoff Cutoff frequency to set + */ +void acc_detector_presence_config_inter_frame_slow_cutoff_set(acc_detector_presence_config_t *presence_config, + float inter_frame_slow_cutoff); + + +/** + * @brief Get the cutoff frequency of the low pass filter for the slow filtered absolute sweep mean + * + * @param[in] presence_config The configuration to get the cutoff frequency for + * @return the cutoff frequency in Hz + */ +float acc_detector_presence_config_inter_frame_slow_cutoff_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the time constant for the depthwise filtering in the intra-frame part + * + * @param[in] presence_config The configuration + * @param[in] intra_frame_time_const Time constant to set + */ +void acc_detector_presence_config_intra_frame_time_const_set(acc_detector_presence_config_t *presence_config, + float intra_frame_time_const); + + +/** + * @brief Get the time constant for the depthwise filtering in the intra-frame part + * + * @param[in] presence_config The configuration to get the time constant for + * @return time constant in s + */ +float acc_detector_presence_config_intra_frame_time_const_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the time constant for the output in the intra-frame part + * + * @param[in] presence_config The configuration + * @param[in] intra_output_time_const Time constant to set + */ +void acc_detector_presence_config_intra_output_time_const_set(acc_detector_presence_config_t *presence_config, + float intra_output_time_const); + + +/** + * @brief Get the time constant for the output in the intra-frame part + * + * @param[in] presence_config The configuration to get the time constant for + * @return time constant in s + */ +float acc_detector_presence_config_intra_output_time_const_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @brief Set the time constant for the output in the inter-frame part + * + * @param[in] presence_config The configuration + * @param[in] inter_output_time_const Time constant to set + */ +void acc_detector_presence_config_inter_output_time_const_set(acc_detector_presence_config_t *presence_config, + float inter_output_time_const); + + +/** + * @brief Get the time constant for the output in the inter-frame part + * + * @param[in] presence_config The configuration to get the time constant for + * @return time constant in s + */ +float acc_detector_presence_config_inter_output_time_const_get(const acc_detector_presence_config_t *presence_config); + + +/** + * @} + */ + +#endif diff --git a/rss/include/xtensa/acc_hal_definitions_a121.h b/rss/include/xtensa/acc_hal_definitions_a121.h new file mode 100644 index 0000000..260b577 --- /dev/null +++ b/rss/include/xtensa/acc_hal_definitions_a121.h @@ -0,0 +1,93 @@ +// Copyright (c) Acconeer AB, 2021-2023 +// All rights reserved + +#ifndef ACC_HAL_DEFINITIONS_A121_H_ +#define ACC_HAL_DEFINITIONS_A121_H_ + +#include +#include +#include +#include + +#include "acc_definitions_common.h" + + +/** + * @brief Specifies the minimal size in bytes that SPI transfers must be able to handle + */ +#define ACC_HAL_SPI_TRANSFER_SIZE_REQUIRED 16U + +/** + * @brief Definition of a memory allocation function + * + * Allocated memory should be suitably aligned for any built-in type. Returning NULL is seen as failure. + */ +typedef void *(*acc_hal_mem_alloc_function_t)(size_t); + + +/** + * @brief Definition of a memory free function + * + * Free memory which is previously allocated. + */ +typedef void (*acc_hal_mem_free_function_t)(void *); + + +/** + * @brief Definition of a sensor transfer function + * + * This function shall transfer data to and from the sensor over spi. It's beneficial from a performance perspective + * to use dma if available. + * The buffer is naturally aligned to a maximum of 4 bytes. + * + */ +typedef void (*acc_hal_sensor_transfer8_function_t)(acc_sensor_id_t sensor_id, uint8_t *buffer, size_t buffer_size); + + +/** + * @brief Definition of an optimized 16-bit sensor transfer function + * + * This function shall transfer data to and from the sensor over spi with 16 bits data size. + * It's beneficial from a performance perspective to use dma if available. + * The buffer is naturally aligned to a minimum of 4 bytes. + * + * If defined it will supersede the normal 8-bit function @ref acc_hal_sensor_transfer8_function_t + * + */ +typedef void (*acc_hal_sensor_transfer16_function_t)(acc_sensor_id_t sensor_id, uint16_t *buffer, size_t buffer_length); + + +/** + * @brief This struct contains function pointers that are optional to support different optimizations + * + * Optional + * + * This struct contains function pointers to support different optimizations. + * These optimizations can be utilized for some integrations. + * If they are defined, they will override the corresponding non-optimized function. + * + * For example, if the transfer16 function is implemented, it will be used instead of the transfer function. + */ +typedef struct +{ + acc_hal_sensor_transfer16_function_t transfer16; +} acc_hal_optimization_t; + + +/** + * @brief Definition of a log function + */ +typedef void (*acc_hal_log_function_t)(acc_log_level_t level, const char *module, const char *format, ...); + +typedef struct +{ + uint16_t max_spi_transfer_size; + + acc_hal_mem_alloc_function_t mem_alloc; + acc_hal_mem_free_function_t mem_free; + acc_hal_sensor_transfer8_function_t transfer; + acc_hal_log_function_t log; + acc_hal_optimization_t optimization; +} acc_hal_a121_t; + +#endif diff --git a/rss/include/xtensa/acc_hal_integration_a121.h b/rss/include/xtensa/acc_hal_integration_a121.h new file mode 100644 index 0000000..9cd091c --- /dev/null +++ b/rss/include/xtensa/acc_hal_integration_a121.h @@ -0,0 +1,74 @@ +// Copyright (c) Acconeer AB, 2021-2022 +// All rights reserved + +#ifndef ACC_HAL_INTEGRATION_A121_H_ +#define ACC_HAL_INTEGRATION_A121_H_ + +#include +#include + +#include "acc_definitions_common.h" +#include "acc_hal_definitions_a121.h" + + +/** + * @brief Get hal implementation reference + */ +const acc_hal_a121_t *acc_hal_rss_integration_get_implementation(void); + + +/** + * @brief Power on sensor supply + * + * @param[in] sensor_id The id of the sensor to power on + */ +void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id); + + +/** + * @brief Power off sensor supply + * + * @param[in] sensor_id The id of the sensor to power off + */ +void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id); + + +/** + * @brief Enable sensor + * + * Any pending sensor interrupts should be cleared before returning from function. + * The sensor supply needs to be enabled by invoking @ref acc_hal_integration_sensor_supply_on + * before calling this function. + * + * @param[in] sensor_id The id of the sensor to enable + */ +void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id); + + +/** + * @brief Disable sensor + * + * @param[in] sensor_id The id of the sensor to disable + */ +void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id); + + +/** + * @brief Wait for a sensor interrupt + * + * @param[in] sensor_id The sensor to wait for the interrupt on + * @param[in] timeout_ms The maximum time to wait in milliseconds + * @return True if an interrupt has occurred within timeout, false if timeout occurred + */ +bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms); + + +/** + * @brief Get the max number of sensors the integration supports + * + * @return The max sensor count + */ +uint16_t acc_hal_integration_sensor_count(void); + + +#endif diff --git a/rss/include/xtensa/acc_integration.h b/rss/include/xtensa/acc_integration.h new file mode 100644 index 0000000..8ae0733 --- /dev/null +++ b/rss/include/xtensa/acc_integration.h @@ -0,0 +1,71 @@ +// Copyright (c) Acconeer AB, 2019-2023 +// All rights reserved + +#ifndef ACC_INTEGRATION_H_ +#define ACC_INTEGRATION_H_ + +#include +#include +#include + + +typedef void (*acc_integration_uart_read_func_t)(uint8_t data, uint32_t status); + + +/** + * @brief Sleep for a specified number of microseconds + * + * @param time_usec Time in microseconds to sleep + */ +void acc_integration_sleep_us(uint32_t time_usec); + + +/** + * @brief Sleep for a specified number of milliseconds + * + * @param time_msec Time in milliseconds to sleep + */ +void acc_integration_sleep_ms(uint32_t time_msec); + + +/** + * @brief Allocate dynamic memory + * + * @param[in] size The bytesize of the reuested memory block + * @return Returns either NULL or a unique pointer to a memory block + */ +void *acc_integration_mem_alloc(size_t size); + + +/** + * @brief Allocate dynamic memory + * + * Allocate an array of nmemb elements of size bytes each. + * + * @param[in] nmemb The number of elements in the array + * @param[in] size The bytesize of the element + * @return Returns either NULL or a unique pointer to a memory block + */ +void *acc_integration_mem_calloc(size_t nmemb, size_t size); + + +/** + * @brief Free dynamic memory + * + * @param[in] ptr A pointer to the memory space to be freed + */ +void acc_integration_mem_free(void *ptr); + + +/** + * @brief Get current time + * + * It is important that this value wraps correctly and uses all bits. I.e. it should count + * upwards to 2^32 - 1 and then 0 again. + * + * @returns Current time as milliseconds + */ +uint32_t acc_integration_get_time(void); + + +#endif diff --git a/rss/include/xtensa/acc_integration_log.h b/rss/include/xtensa/acc_integration_log.h new file mode 100644 index 0000000..22a4802 --- /dev/null +++ b/rss/include/xtensa/acc_integration_log.h @@ -0,0 +1,54 @@ +// Copyright (c) Acconeer AB, 2016-2021 +// All rights reserved + +#ifndef ACC_INTEGRATION_LOG_H_ +#define ACC_INTEGRATION_LOG_H_ + +#include "acc_definitions_common.h" +#include "acc_integration.h" + +#ifdef ACC_LOG_RSS_H_ +#error "acc_integration_log.h and acc_log_rss.h cannot coexist" +#endif + +#define ACC_LOG(level, ...) acc_integration_log(level, MODULE, __VA_ARGS__) + +#define ACC_LOG_ERROR(...) ACC_LOG(ACC_LOG_LEVEL_ERROR, __VA_ARGS__) +#define ACC_LOG_WARNING(...) ACC_LOG(ACC_LOG_LEVEL_WARNING, __VA_ARGS__) +#define ACC_LOG_INFO(...) ACC_LOG(ACC_LOG_LEVEL_INFO, __VA_ARGS__) +#define ACC_LOG_VERBOSE(...) ACC_LOG(ACC_LOG_LEVEL_VERBOSE, __VA_ARGS__) +#define ACC_LOG_DEBUG(...) ACC_LOG(ACC_LOG_LEVEL_DEBUG, __VA_ARGS__) + +#define ACC_LOG_SIGN(a) (((a) < 0.0f) ? (-1.0f) : (1.0f)) +#define ACC_LOG_FLOAT_INT(a) ((unsigned long int)((a) + 0.0000005f)) +#define ACC_LOG_FLOAT_DEC(a) (unsigned long int)((1000000.0f * (((a) + 0.0000005f) - ((unsigned int)((a) + 0.0000005f))))) + +#define ACC_LOG_FLOAT_TO_INTEGER(a) (((a) < 0.0f) ? "-" : ""), ACC_LOG_FLOAT_INT((a) * ACC_LOG_SIGN(a)), ACC_LOG_FLOAT_DEC((a) * ACC_LOG_SIGN(a)) + +/** + * @brief Specifier for printing float type using integers. + */ +#define PRIfloat "s%lu.%06lu" + + +#if defined(__GNUC__) +#define PRINTF_ATTRIBUTE_CHECK(a, b) __attribute__((format(printf, a, b))) +#else +#define PRINTF_ATTRIBUTE_CHECK(a, b) +#endif + + +/** + * @brief Log function + * + * This log function can be used as a complement to for example printf. + * It adds useful information to the log such as time and log level + * + * @param[in] level The severity level for the log + * @param[in] module The name of the SW module from where the log is called + * @param[in] format The information to be logged, same format as for printf + */ +void acc_integration_log(acc_log_level_t level, const char *module, const char *format, ...) PRINTF_ATTRIBUTE_CHECK(3, 4); + + +#endif diff --git a/rss/include/xtensa/acc_processing.h b/rss/include/xtensa/acc_processing.h new file mode 100644 index 0000000..fa9326f --- /dev/null +++ b/rss/include/xtensa/acc_processing.h @@ -0,0 +1,155 @@ +// Copyright (c) Acconeer AB, 2020-2023 +// All rights reserved + +#ifndef ACC_PROCESSING_H_ +#define ACC_PROCESSING_H_ + +#include +#include + +#include "acc_config_subsweep.h" +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" + + +/** + * @defgroup processing Processing + * @ingroup service + * + * @brief Module to interpret and process data read from sensor + * + * @{ + */ + + +/** + * @brief Generic processing handle + */ +struct acc_processing_handle; + +typedef struct acc_processing_handle acc_processing_t; + + +/** + * @brief Metadata that will be populated by the processing module during creation + */ +typedef struct +{ + /** Number of elements in the frame */ + uint16_t frame_data_length; + /** Number of elements in the sweep */ + uint16_t sweep_data_length; + /** Offset to the subsweeps data */ + uint16_t subsweep_data_offset[ACC_MAX_NUM_SUBSWEEPS]; + /** Number of elements in the subsweeps */ + uint16_t subsweep_data_length[ACC_MAX_NUM_SUBSWEEPS]; + /** Maximum sweep rate that the sensor can provide for the given configuration. + * Note that this is not the actual exact sweep rate. To obtain an exact rate, + * use the sweep rate parameter, @ref acc_config_sweep_rate_set. + * + * If no max sweep rate is applicable, it's set to 0.0f. + */ + float max_sweep_rate; + /** Flag indicating if high speed mode is used. + * If true, it means that the sensor has been configured in a way where it + * can optimize its measurements and obtain a high max_sweep_rate. + * + * Configuration limitations to enable high speed mode: + * + * continuous_sweep_mode false, see @ref acc_config_continuous_sweep_mode_set + * inter_sweep_idle_state READY, see @ref acc_config_inter_sweep_idle_state_set + * num_subsweeps 1, see @ref acc_config_num_subsweeps_set + * profile 3-5, see @ref acc_config_profile_set + */ + bool high_speed_mode; +} acc_processing_metadata_t; + + +/** + * @brief Result provided by the processing module + */ +typedef struct +{ + /** Indication of sensor data being saturated, can cause data corruption. + * Lower the receiver gain if this indication is set. + */ + bool data_saturated; + /** Indication of a delayed frame. + * The frame rate might need to be lowered if this indication is set. + */ + bool frame_delayed; + /** Indication of calibration needed + * The sensor calibration needs to be redone if this indication is set. + */ + bool calibration_needed; + /** Temperature in sensor during measurement (in degree Celsius). + * Note that it has poor absolute accuracy and should only be used + * for relative temperature measurements. + */ + int16_t temperature; + /** Pointer to the frame data */ + acc_int16_complex_t *frame; +} acc_processing_result_t; + + +/** + * @brief Create a processing instance with the provided configuration + * + * @param[in] config The configuration to create a processing instance with + * @param[out] processing_metadata The metadata of the created processing instance + * @return Processing handle, NULL if processing instance was not possible to create + */ +acc_processing_t *acc_processing_create(const acc_config_t *config, acc_processing_metadata_t *processing_metadata); + + +/** + * @brief Process the data according to the configuration used in create + * + * @param[in] handle A reference to the processing handle + * @param[in] buffer A reference to the buffer (populated by @ref acc_sensor_read) containing the + * data to be processed. + * + * @param[out] result Processing result + */ +void acc_processing_execute(acc_processing_t *handle, void *buffer, + acc_processing_result_t *result); + + +/** + * @brief Destroy a processing instance identified with the provided processing handle + * + * @param[in] handle A reference to the processing handle to destroy, can be NULL + */ +void acc_processing_destroy(acc_processing_t *handle); + + +/** + * @brief Convert a distance or step length in points to meter + * + * Does not include any zero-point offset since it is highly integration dependant. In other words, + * calling this function with a 0 always returns 0.0. + * + * @param[in] points Number of points to convert to meter + * @return The corresponding length in meters + */ +float acc_processing_points_to_meter(int32_t points); + + +/** + * @brief Convert a distance or step length in meter to points + * + * Does not include any zero-point offset since it is highly integration dependant. In other words, + * calling this function with a 0.0 always returns 0. + * + * @param[in] length Length in meter to convert to points + * @return The corresponding length in points + */ +int32_t acc_processing_meter_to_points(float length); + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_processing_helpers.h b/rss/include/xtensa/acc_processing_helpers.h new file mode 100644 index 0000000..2512c28 --- /dev/null +++ b/rss/include/xtensa/acc_processing_helpers.h @@ -0,0 +1,371 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef ACC_PROCESSING_HELPERS_H_ +#define ACC_PROCESSING_HELPERS_H_ + +#include +#include +#include + +#include "acc_control_helper.h" + +/** \example acc_processing_helpers.c + * @brief This is a collection of helper functions for processing of + * the sparse IQ data that is generated by Acconeer's A121 radar sensor. + * The functions are used by Acconeer's processing examples to show + * common processing steps when working on sparse IQ data. + * The purpose of the helper functions is to increase the readability + * of the example programs. The helper functions do not provide optimized + * implementations of the processing steps. + */ + + +typedef struct +{ + uint32_t data_length; + float complex *data; +} acc_vector_iq_t; + +typedef struct +{ + uint32_t data_length; + float *data; +} acc_vector_float_t; + + +/** + * @brief Allocate storage for an IQ vector + * + * @param[in] data_length Length of the vector + * @return Pointer to vector or NULL if allocation failed + */ + +acc_vector_iq_t *acc_vector_iq_alloc(uint32_t data_length); + + +/** + * @brief Allocate storage for a float vector + * + * @param[in] data_length Length of the vector + * @return Pointer to vector or NULL if allocation failed + */ +acc_vector_float_t *acc_vector_float_alloc(uint32_t data_length); + + +/** + * @brief Free storage of data elements in an IQ vector + * + * @param[in] vector Vector to be freed + */ +void acc_vector_iq_free(acc_vector_iq_t *vector); + + +/** + * @brief Free storage of data elements in a float vector + * + * @param[in] vector Vector to be freed + */ +void acc_vector_float_free(acc_vector_float_t *vector); + + +/** + * @brief Convert time constant to smoothing factor + * + * @param[in] time_constant_s Time constant + * @param[in] update_rate_hz Update rate + * @return Smoothing factor + */ +float acc_processing_helper_tc_to_sf(float time_constant_s, float update_rate_hz); + + +/** + * @brief Calculate a dynamic smoothing factor + * + * Calculate a smoothing factor that are lower for the + * first sweeps. For the first n sweeps the exponential average will + * be equal to the arithmetic mean of the first n sweeps. + * + * @param[in] static_sf The target smoothing factor that will be used after the first sweeps + * @param[in] update_count The update count should be 0 for the first sweep and increased by one for each update + * @return Dynamic smoothing factor + */ +float acc_processing_helper_dynamic_sf(float static_sf, uint32_t update_count); + + +/** + * @brief Update the exponential average of an IQ vector + * + * @param[in] current The new IQ vector that will be included in the updated exponential average + * @param[in, out] averaged_data The filtered data or exponential average that should be updated + * @param[in] sf Smoothing factor that determines how much of the old data that should be kept + */ + +void acc_vector_iq_update_exponential_average(const acc_vector_iq_t *current, acc_vector_iq_t *averaged_data, float sf); + + +/** + * @brief Update the exponential average of a float vector + * + * @param[in] current The new IQ float that will be included in the updated exponential average + * @param[in, out] averaged_data The filtered data or exponential average that should be updated + * @param[in] sf Smoothing factor that determines how much of the old data that should be kept + */ + +void acc_vector_float_update_exponential_average(const acc_vector_float_t *current, acc_vector_float_t *averaged_data, float sf); + + +/** + * @brief Converts a newly captured IQ frame with one sweep to an IQ vector + * + * The resulting vector can be used with the processing functions in this file. + * + * @param[in] control_helper_state Pointer to control helper radar state struct + * @param[out] vector_out IQ vector + */ +void acc_get_iq_sweep_vector(const acc_control_helper_t *control_helper_state, acc_vector_iq_t *vector_out); + + +/** + * @brief Extract an IQ vector with sweep data for a specific point from a newly captured IQ frame with multiple sweeps + * + * The resulting vector can be used with the processing functions in this file. + * + * @param[in] control_helper_state Pointer to control helper radar state struct + * @param[in] point The point to get the IQ vector for + * @param[out] vector_out IQ vector + */ +void acc_get_iq_point_vector(const acc_control_helper_t *control_helper_state, uint32_t point, acc_vector_iq_t *vector_out); + + +/** + * @brief Calculate filter vector length + * + * Calculate filter vector length given peak width and step size. The peak width + * varies depending on profile. + * + * @param[in] peak_width_points Peak width in base points + * @param[in] step_length Step length in base points + * @return Filter vector length + */ +uint32_t acc_processing_helper_get_filter_length(uint32_t peak_width_points, uint32_t step_length); + + +/** + * @brief Create a distance filter vector + * + * Create a triangle shaped distance filter vector. Use the function + * acc_processing_helper_get_filter_length when allocating memory for the + * output vector to get the right length of the filter for a given peak width + * and step size. + * + * @param[out] vector_out Filter vector + */ + +void acc_vector_float_create_depth_filter_vector(acc_vector_float_t *vector_out); + + +/** + * @brief Apply a FIR filter to an IQ vector + * + * Performs coherent filtering of the input vector. + * + * @param[in] vector_a IQ vector + * @param[in] filter_vector Filter vector + * @param[out] vector_out Filtered result + * + */ +void acc_vector_iq_apply_filter(const acc_vector_iq_t *vector_a, acc_vector_float_t *filter_vector, acc_vector_iq_t *vector_out); + + +/** + * @brief Copy an IQ vector + * + * Copy the contents of one IQ vector to another IQ vector. + * + * @param[in] vector_a Source IQ vector + * @param[out] vector_out Destination IQ vector + * + */ +void acc_vector_iq_copy(const acc_vector_iq_t *vector_a, acc_vector_iq_t *vector_out); + + +/** + * @brief Add two IQ vectors + * + * @param[in] vector_a First input vector + * @param[in] vector_b Second input vector + * @param[out] vector_out The result a + b + */ +void acc_vector_iq_add(const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out); + + +/** + * @brief Subtract two IQ vectors + * + * @param[in] vector_a First input vector + * @param[in] vector_b Second input vector + * @param[out] vector_out The result a - b + */ +void acc_vector_iq_subtract(const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out); + + +/** + * @brief Multiply two IQ vectors + * + * Perform element wise multiplication of two IQ vectors. + * + * @param[in] vector_a First input vector + * @param[in] vector_b Second input vector + * @param[out] vector_out The result a * b + */ +void acc_vector_iq_mult(const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out); + + +/** + * @brief Multiply first IQ vector with conjugate of second IQ vector + * + * Make element wise multiplication of an IQ vector with the conjugate + * of another IQ vector. The amplitudes of the result will be the product of the amplitudes + * of the input vectors. The phases of the result will be the phase differences of the two + * input vectors. + * + * The function can be used when calculating the phase difference between two consecutive + * sweeps. + * + * @param[in] vector_a First input vector + * @param[in] vector_b Second input vector + * @param[out] vector_out The result: a * conj(b) + */ +void acc_vector_iq_mult_conj(const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out); + + +/** + * @brief Rotate the phase of elements in an IQ vector + * + * @param[in, out] vector_a The IQ vector to be modified + * @param[in] radians The angle in radians to rotate the phase + */ +void acc_vector_iq_rotate_phase_inline(acc_vector_iq_t *vector_a, float radians); + + +/** + * @brief Update an IQ vector with its conjugate + * + * Replace the elements in an IQ vector with the conjugate of the elements. + * + * @param[in, out] vector_a The IQ vector to be modified + */ +void acc_vector_iq_conj_inline(acc_vector_iq_t *vector_a); + + +/** + * @brief Amplitude of an IQ vector + * + * Calculate the amplitude of the elements in an IQ vector. + * + * @param[in] vector_a Input IQ vector + * @param[out] vector_out The amplitude of the elements in the input vector + */ +void acc_vector_iq_amplitude(const acc_vector_iq_t *vector_a, acc_vector_float_t *vector_out); + + +/** + * @brief Coherent mean amplitude of IQ vector + * + * Calculate the coherent mean amplitude of the elements in an IQ vector. + * + * @param[in] vector_a Input IQ vector + * @return The coherent mean amplitude of the elements in vector_a + */ +float acc_vector_iq_coherent_mean_amplitude(const acc_vector_iq_t *vector_a); + + +/** + * @brief Non-coherent mean amplitude of IQ vector + * + * Calculate the non-coherent mean amplitude of the elements in an IQ vector. + * + * @param[in] vector_a Input IQ vector + * @return The non-coherent mean amplitude of the elements in vector_a + */ +float acc_vector_iq_noncoherent_mean_amplitude(const acc_vector_iq_t *vector_a); + + +/** + * @brief Phase of an IQ vector + * + * Calculate the phase of the elements in an IQ vector. + * + * @param[in] vector_a Input IQ vector + * @param[out] vector_out The phase of the elements in the input vector + */ +void acc_vector_iq_phase(const acc_vector_iq_t *vector_a, acc_vector_float_t *vector_out); + + +/** + * @brief Index of element with maximum value in a float vector + * + * @param[in] vector_a Input vector + * @return The index of the element with the highest value + */ +uint32_t acc_vector_float_argmax(acc_vector_float_t *vector_a); + + +/** + * @brief Index of element with maximum value in a float vector disregarding edge elements + * + * Find the index of the maximum element in a float vector disregarding + * the first and last elements in the vector. + * + * @param[in] vector_a Input vector + * @param[in] elements_to_skip The number of elements to skip + * @return The index of the element with the highest value + */ +uint32_t acc_vector_float_argmax_skip_edges(acc_vector_float_t *vector_a, uint32_t elements_to_skip); + + +/** + * @brief Interpolate peak position + * + * The function fits a second degree polynomial to three consecutive amplitude + * values where second element is expected to contain the maximum measured amplitude. + * The function then finds the position of the maximum amplitude of the polynomial. + * The position is normalized and a return value of 0 means that the peak is at the + * position of the second amplitude. A value of -1 and 1 means that the peak is at + * the position of the first or third input amplitude respectively. + * + * @param[in] y1 The first amplitude value + * @param[in] y2 The second amplitude value + * @param[in] y3 The third amplitude value + * @return Interpolated peak position + */ +float acc_processing_helper_interpolate_peak_position(float y1, float y2, float y3); + + +/** + * @brief Print float vector + * + * Print a float vector to stdout. + * + * @param[in] label A string description of the vector + * @param[in] vector_a The float vector to print + */ +void acc_vector_float_print(const char *label, acc_vector_float_t *vector_a); + + +/** + * @brief Print IQ vector + * + * Print an IQ vector to stdout. + * + * @param[in] label A string description of the vector + * @param[in] vector_a The IQ vector to print + */ +void acc_vector_iq_print(const char *label, acc_vector_iq_t *vector_a); + + +#endif diff --git a/rss/include/xtensa/acc_rss_a121.h b/rss/include/xtensa/acc_rss_a121.h new file mode 100644 index 0000000..04a8698 --- /dev/null +++ b/rss/include/xtensa/acc_rss_a121.h @@ -0,0 +1,243 @@ +// Copyright (c) Acconeer AB, 2021-2023 +// All rights reserved + +#ifndef ACC_RSS_A121_H_ +#define ACC_RSS_A121_H_ + +#include + +#include "acc_config.h" +#include "acc_definitions_common.h" +#include "acc_hal_definitions_a121.h" + + +/** + * @defgroup rss RSS + * + * @brief RSS API description + * + * @{ + */ + + +/** + * @brief The minimum buffer size needed for the assembly test + * + */ +#define ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE 4096U + + +/** + * @brief Return code for rss tests + * + */ +typedef enum +{ + /*! The test is ongoing, the application should call test function again */ + ACC_RSS_TEST_STATE_ONGOING = 0, + /*! The application should toggle enable pin and then call test function again */ + ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN, + /*! The application should wait for interrupt and then call test function again */ + ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT, + /*! The test is complete */ + ACC_RSS_TEST_STATE_COMPLETE, +} acc_rss_test_state_t; + + +/** + * @brief Integration status for rss tests + * + */ +typedef enum +{ + /*! The test status is OK */ + ACC_RSS_TEST_INTEGRATION_STATUS_OK = 0, + /*! The test has timed out */ + ACC_RSS_TEST_INTEGRATION_STATUS_TIMEOUT, +} acc_rss_test_integration_status_t; + + +/** + * @brief Test identity enum for acc_rss_assembly_test + * + */ +typedef enum +{ + /*! Test SPI basic read functionality. */ + ACC_RSS_ASSEMBLY_TEST_ID_BASIC_READ, + /*! Test SPI communication. */ + ACC_RSS_ASSEMBLY_TEST_ID_COMMUNICATION, + /*! Test enable pin. */ + ACC_RSS_ASSEMBLY_TEST_ID_ENABLE_PIN, + /*! Test interrupt pin. */ + ACC_RSS_ASSEMBLY_TEST_ID_INTERRUPT, + /*! Test clock and supply stability. */ + ACC_RSS_ASSEMBLY_TEST_ID_CLOCK_AND_SUPPLY, + /*! Test sensor calibration. */ + ACC_RSS_ASSEMBLY_TEST_ID_SENSOR_CALIBRATION, +} acc_rss_assembly_test_test_id_t; + + +/** + * @brief The result struct of acc_rss_assembly_test + * + */ +typedef struct +{ + const char *test_name; + bool test_result; +} acc_rss_assembly_test_result_t; + + +/** + * @brief The acc_rss_assembly_test instance + * + */ +struct acc_rss_assembly_test; + +typedef struct acc_rss_assembly_test acc_rss_assembly_test_t; + + +/** + * @brief Register an integration + * + * @param[in] hal A reference to the hal to register + * @return True if a valid integration is registered, false otherwise + */ +bool acc_rss_hal_register(const acc_hal_a121_t *hal); + + +/** + * @brief Get the buffer size needed for the specified config + * + * This buffer size can be used to allocate a memory buffer in the + * application, which is needed for several functions in the RSS library. + * + * @param[in] config The config to get the buffer size for + * @param[out] buffer_size The buffer size + * @return True if successful, false otherwise + */ +bool acc_rss_get_buffer_size(const acc_config_t *config, uint32_t *buffer_size); + + +/** + * @brief Set the log level that determines when the integration HAL logger function is called + * + * Shall be called when there is a hal registered in RSS as it has no effect otherwise. + * + * @param[in] level The severity level for log output. + */ +void acc_rss_set_log_level(acc_log_level_t level); + + +/** + * @brief Create a sensor assembly test instance + * + * The assembly test instance is used to keep track of internal state and + * results of the assembly test. + * + * The provided buffer start address should be 32-bit aligned. + * The size of the provided buffer must be at least ACC_RSS_ASSEMBLY_TEST_MIN_BUFFER_SIZE bytes. + * The size of the provided buffer should be a multiple of 8 bytes. + * The test will not behave differently if a larger buffer is provided. + * + * All assembly tests are enabled by default after creation. + * + * @param[in] sensor_id The sensor id to be used to communicate with + * @param[in] buffer A buffer used for assembly test + * @param[in] buffer_size The size of the buffer + * + * @return Assembly test instance, NULL if the creation of the instance failed + */ +acc_rss_assembly_test_t *acc_rss_assembly_test_create(acc_sensor_id_t sensor_id, void *buffer, uint32_t buffer_size); + + +/** + * @brief Destroy a sensor assembly test instance freeing any resources allocated. + * + * @param[in] assembly_test The assembly_test instance to destroy, can be NULL + */ +void acc_rss_assembly_test_destroy(acc_rss_assembly_test_t *assembly_test); + + +/** + * @brief Enable disagnostic logs for the assembly test, + */ +void acc_rss_assembly_test_enable_diagnostic_logs(void); + + +/** + * @brief Enable all assembly tests + * + * @param[in] assembly_test The assembly_test instance + */ +void acc_rss_assembly_test_enable_all_tests(acc_rss_assembly_test_t *assembly_test); + + +/** + * @brief Disable all assembly tests + * + * @param[in] assembly_test The assembly_test instance + */ +void acc_rss_assembly_test_disable_all_tests(acc_rss_assembly_test_t *assembly_test); + + +/** + * @brief Enable a test in assembly test + * + * @param[in] assembly_test The assembly_test instance + * @param[in] test_id The id of the test to be enabled + */ +void acc_rss_assembly_test_enable(acc_rss_assembly_test_t *assembly_test, acc_rss_assembly_test_test_id_t test_id); + + +/** + * @brief Disable a test in assembly test + * + * @param[in] assembly_test The assembly_test instance + * @param[in] test_id The id of the test to be enabled + */ +void acc_rss_assembly_test_disable(acc_rss_assembly_test_t *assembly_test, acc_rss_assembly_test_test_id_t test_id); + + +/** + * @brief Execute the assembly test + * + * The sensor must be powered on and enabled before this function is called. + * + * The function should be called repeatedly until it returns ACC_RSS_TEST_STATE_COMPLETE. + * If the function returns ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN the caller should toggle the + * enable pin to reset the sensor and then call @ref acc_rss_assembly_test_execute() again. + * If the function returns ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT the caller have to wait for + * the interrupt pin before calling @ref acc_rss_assembly_test_execute() again. + * + * After assembly test has been run the sensor enable pin should be toggled to reset the sensor. + * + * @param[in, out] assembly_test The sensor assembly test instance + * @param[in] integration_status Report back to assembly test if 'wait for interrupt' timed out + * @return ACC_RSS_TEST_STATE_ONGOING if caller should call this function again. + * ACC_RSS_TEST_STATE_TOGGLE_ENABLE_PIN if caller should toggle the enable pin. + * ACC_RSS_TEST_STATE_WAIT_FOR_INTERRUPT if caller should wait for interrupt pin. + * or ACC_RSS_TEST_STATE_COMPLETE if the assembly test is complete. + */ +acc_rss_test_state_t acc_rss_assembly_test_execute(acc_rss_assembly_test_t *assembly_test, + acc_rss_test_integration_status_t integration_status); + + +/** + * @brief A function to get the results from the sensor assembly test + * + * @param[in] assembly_test The sensor assembly test instance + * @param[out] nbr_of_test_results The number of test results returned + * @return The assembly test result array + */ +const acc_rss_assembly_test_result_t *acc_rss_assembly_test_get_results(const acc_rss_assembly_test_t *assembly_test, + uint16_t *nbr_of_test_results); + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_sensor.h b/rss/include/xtensa/acc_sensor.h new file mode 100644 index 0000000..b41ed21 --- /dev/null +++ b/rss/include/xtensa/acc_sensor.h @@ -0,0 +1,218 @@ +// Copyright (c) Acconeer AB, 2020-2022 +// All rights reserved + +#ifndef ACC_SENSOR_H_ +#define ACC_SENSOR_H_ + +#include +#include + +#include "acc_config.h" +#include "acc_definitions_a121.h" +#include "acc_definitions_common.h" + + +/** + * @defgroup service Service + * + * @brief Service API + * + * @defgroup sensor Sensor + * @ingroup service + * + * @brief Module to control the sensor + * + * @{ + */ + + +struct acc_sensor; + +typedef struct acc_sensor acc_sensor_t; + + +/** + * @brief Create a sensor instance + * + * A sensor instance represents a physical radar sensor and handles the communication + * with it. + * + * Before this function is called the sensor must be powered on and not used + * in another sensor instance without a power or reset cycle between. + * + * @param[in] sensor_id The sensor id to be used to communicate with + * + * @return Sensor instance, NULL if sensor instance was not possible to create + */ +acc_sensor_t *acc_sensor_create(acc_sensor_id_t sensor_id); + + +/** + * @brief Destroy a sensor instance freeing any resources allocated. + * + * @param[in] sensor The sensor instance to destroy, can be NULL + */ +void acc_sensor_destroy(acc_sensor_t *sensor); + + +/** + * @brief Calibrate a sensor + * + * Note that the sensor must be powered on before calling this function. + * To calibrate the sensor, call this function and wait for sensor interrupt, + * repeat until calibration is complete (or fails). + * + * @param[in] sensor The sensor instance to calibrate + * @param[out] cal_complete True if calibration is complete + False if caller should wait for interrupt and + then call again + * @param[out] cal_result The result after a completed calibration + * @param[in] buffer Memory used during calibration. + * A larger buffer might mean fewer transactions between host and sensor. + * The buffer will only be used during the calibration. + * The client has to make sure this buffer is suitably aligned for + * any built-in type. + * @param[in] buffer_size The size in bytes of the buffer, should be at least buffer_size + from @ref acc_rss_get_buffer_size + * @return true if successful, false otherwise + */ +bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, + void *buffer, uint32_t buffer_size); + + +/** + * @brief Gets calibration information from a calibration result + * + * @param[in] cal_result The calibration result + * @param[out] cal_info The calibration information + * @return true if successful, false otherwise + */ +bool acc_sensor_get_cal_info(const acc_cal_result_t *cal_result, acc_cal_info_t *cal_info); + + +/** + * @brief Prepare a sensor to do a measurement + * + * It's possible to reconfigure the sensor by calling the function multiple times. + * + * Note: + * - The sensor must be powered on when calling this function. + * - The sensor must not be measuring when calling this function, if previous call was + * @ref acc_sensor_measure use @ref acc_hal_integration_wait_for_sensor_interrupt to + * wait for measurement to complete. + * - Reconfiguring is not supported when double buffering is active, however enabling + * double buffering through reconfiguration is. + * + * @param[in] sensor The sensor instance to prepare + * @param[in] config The configuration to prepare for + * @param[in] cal_result The calibration result to prepare for + * @param[in] buffer Memory used during preparation. + * A larger buffer might mean fewer transactions between host and sensor. + * The buffer will only be used during the duration of this call. + * The client has to make sure this buffer is suitably aligned for + * any built-in type. + * @param[in] buffer_size The size in bytes of the buffer, should be at least buffer_size + * from @ref acc_rss_get_buffer_size + * @return true if successful, false otherwise + */ +bool acc_sensor_prepare(acc_sensor_t *sensor, const acc_config_t *config, const acc_cal_result_t *cal_result, + void *buffer, uint32_t buffer_size); + + +/** + * @brief Start a radar measurement with previously prepared configuration + * + * Note that the following preconditions apply + * - The sensor must be powered on + * - @ref acc_sensor_calibrate must have been called + * - @ref acc_sensor_prepare must have been called + * + * @param[in] sensor The sensor instance to measure with + * @return true if successful, false otherwise + */ +bool acc_sensor_measure(acc_sensor_t *sensor); + + +/** + * @brief Read out radar data + * + * Note that the following preconditions apply + * - The sensor must be powered on + * - @ref acc_sensor_measure must be called before each call to this function + * - The sensor interrupt must be active + * + * @param[in] sensor The sensor to read the radar data from + * @param[in] buffer The buffer to read radar data into. + * The buffer will only be used during the duration of this call. + * The client has to make sure this buffer is suitably aligned for + * any built-in type. + * @param[in] buffer_size The size in bytes of the buffer, should be at least buffer_size + * from @ref acc_rss_get_buffer_size + * @return true if successful, false otherwise + */ +bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size); + + +/** + * @brief Check if a sensor is connected and responsive + * + * Note that the sensor must be powered on before calling this function. + * + * @param[in] sensor_id The sensor id to be used to communicate with + * @return true if it is possible to communicate with the sensor + */ +bool acc_sensor_connected(acc_sensor_id_t sensor_id); + + +/** + * @brief Check the status of the sensor + * + * This function reads out the internal status from the sensor and prints it for debugging purposes. + * It can for example be called when the function @ref acc_hal_integration_wait_for_sensor_interrupt() + * fails. Note that the sensor must be powered on before calling this function. + * + * @param[in] sensor The sensor instance to get status from + */ +void acc_sensor_status(const acc_sensor_t *sensor); + + +/** + * @brief Prepare sensor for entering hibernation + * + * Prepare sensor for entering hibernation. + * Should be invoked prior to calling @ref acc_hal_integration_sensor_disable() + * + * @param[in] sensor The sensor to prepare for hibernation + * @return True if prepare was successful + */ +bool acc_sensor_hibernate_on(acc_sensor_t *sensor); + + +/** + * @brief Restore sensor after exiting hibernation + * + * Restore sensor after exiting hibernation. + * Should be invoked after calling @ref acc_hal_integration_sensor_enable() + * + * @param[in] sensor The sensor to unprepare for hibernation + * @return True if unprepare was successful + */ +bool acc_sensor_hibernate_off(const acc_sensor_t *sensor); + + +/** + * @brief Validate calibration result + * + * @param[in] cal_result Result of a calibration + * + * @return True if calibration is valid + */ +bool acc_sensor_validate_calibration(const acc_cal_result_t *cal_result); + + +/** + * @} + */ + + +#endif diff --git a/rss/include/xtensa/acc_version.h b/rss/include/xtensa/acc_version.h new file mode 100644 index 0000000..d4c2934 --- /dev/null +++ b/rss/include/xtensa/acc_version.h @@ -0,0 +1,25 @@ +// Copyright (c) Acconeer AB, 2019-2023 +// All rights reserved + +#ifndef ACC_VERSION_H_ +#define ACC_VERSION_H_ + +#include + +/** + * @brief Get the version of the Acconeer software + * + * @return A string describing the software version. + */ +const char *acc_version_get(void); + + +/** + * @brief Get the version of the Acconeer software as a hex number + * + * @return An uint32 number, 0xMMMMmmPP where M is major, m is minor and P is patch + */ +uint32_t acc_version_get_hex(void); + + +#endif diff --git a/rss/include/xtensa/example_bring_up.h b/rss/include/xtensa/example_bring_up.h new file mode 100644 index 0000000..d3e1ed8 --- /dev/null +++ b/rss/include/xtensa/example_bring_up.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_BRING_UP_H_ +#define EXAMPLE_BRING_UP_H_ + +/** + * @brief Assembly test example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_control_helper.h b/rss/include/xtensa/example_control_helper.h new file mode 100644 index 0000000..7be28d1 --- /dev/null +++ b/rss/include/xtensa/example_control_helper.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_CONTROL_HELPER_H_ +#define EXAMPLE_CONTROL_HELPER_H_ + +/** + * @brief Control helper example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_detector_distance.h b/rss/include/xtensa/example_detector_distance.h new file mode 100644 index 0000000..d7a7cb4 --- /dev/null +++ b/rss/include/xtensa/example_detector_distance.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DETECTOR_DISTANCE_H_ +#define EXAMPLE_DETECTOR_DISTANCE_H_ + +/** + * @brief Detector distance example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_detector_distance_calibration_caching.h b/rss/include/xtensa/example_detector_distance_calibration_caching.h new file mode 100644 index 0000000..a624d7f --- /dev/null +++ b/rss/include/xtensa/example_detector_distance_calibration_caching.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2024 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DETECTOR_DISTANCE_CALIBRATION_CACHING_H_ +#define EXAMPLE_DETECTOR_DISTANCE_CALIBRATION_CACHING_H_ + +/** + * @brief Detector distance with calibration caching example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_detector_distance_with_iq_data_print.h b/rss/include/xtensa/example_detector_distance_with_iq_data_print.h new file mode 100644 index 0000000..dc14200 --- /dev/null +++ b/rss/include/xtensa/example_detector_distance_with_iq_data_print.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DETECTOR_DISTANCE_WITH_IQ_DATA_PRINT_H_ +#define EXAMPLE_DETECTOR_DISTANCE_WITH_IQ_DATA_PRINT_H_ + +/** + * @brief Detector distance example with iq data print + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_detector_presence.h b/rss/include/xtensa/example_detector_presence.h new file mode 100644 index 0000000..fa732f0 --- /dev/null +++ b/rss/include/xtensa/example_detector_presence.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DETECTOR_PRESENCE_H_ +#define EXAMPLE_DETECTOR_PRESENCE_H_ + +/** + * @brief Detector presence example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_detector_presence_multiple_configurations.h b/rss/include/xtensa/example_detector_presence_multiple_configurations.h new file mode 100644 index 0000000..4705db7 --- /dev/null +++ b/rss/include/xtensa/example_detector_presence_multiple_configurations.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DETECTOR_PRESENCE_MULTIPLE_CONFIGURATIONS_H_ +#define EXAMPLE_DETECTOR_PRESENCE_MULTIPLE_CONFIGURATIONS_H_ + +/** + * @brief Detector presence example with multiple configurations + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_diagnostic_test.h b/rss/include/xtensa/example_diagnostic_test.h new file mode 100644 index 0000000..8095ed5 --- /dev/null +++ b/rss/include/xtensa/example_diagnostic_test.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_DIAGNOSTIC_TEST_H_ +#define EXAMPLE_DIAGNOSTIC_TEST_H_ + +/** + * @brief Assembly test example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_amplitude.h b/rss/include/xtensa/example_processing_amplitude.h new file mode 100644 index 0000000..c392b25 --- /dev/null +++ b/rss/include/xtensa/example_processing_amplitude.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_AMPLITUDE_H_ +#define EXAMPLE_PROCESSING_AMPLITUDE_H_ + +/** + * @brief Processing amplitude example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_coherent_mean.h b/rss/include/xtensa/example_processing_coherent_mean.h new file mode 100644 index 0000000..29759da --- /dev/null +++ b/rss/include/xtensa/example_processing_coherent_mean.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_COHERENT_MEAN_H_ +#define EXAMPLE_PROCESSING_COHERENT_MEAN_H_ + +/** + * @brief Processing coherent mean example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_noncoherent_mean.h b/rss/include/xtensa/example_processing_noncoherent_mean.h new file mode 100644 index 0000000..e31ed20 --- /dev/null +++ b/rss/include/xtensa/example_processing_noncoherent_mean.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_NONCOHERENT_MEAN_H_ +#define EXAMPLE_PROCESSING_NONCOHERENT_MEAN_H_ + +/** + * @brief Processing noncoherent mean example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_peak_interpolation.h b/rss/include/xtensa/example_processing_peak_interpolation.h new file mode 100644 index 0000000..45a526d --- /dev/null +++ b/rss/include/xtensa/example_processing_peak_interpolation.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_PEAK_INTERPOLATION_H_ +#define EXAMPLE_PROCESSING_PEAK_INTERPOLATION_H_ + +/** + * @brief Processing peak interpolation example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_static_presence.h b/rss/include/xtensa/example_processing_static_presence.h new file mode 100644 index 0000000..1a45ac2 --- /dev/null +++ b/rss/include/xtensa/example_processing_static_presence.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_STATIC_PRESENCE_H_ +#define EXAMPLE_PROCESSING_STATIC_PRESENCE_H_ + +/** + * @brief Processing static presence example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_processing_subtract_adaptive_bg.h b/rss/include/xtensa/example_processing_subtract_adaptive_bg.h new file mode 100644 index 0000000..ede7592 --- /dev/null +++ b/rss/include/xtensa/example_processing_subtract_adaptive_bg.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_PROCESSING_SUBTRACT_ADAPTIVE_BG_H_ +#define EXAMPLE_PROCESSING_SUBTRACT_ADAPTIVE_BG_H_ + +/** + * @brief Processing subtract adaptive background example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service.h b/rss/include/xtensa/example_service.h new file mode 100644 index 0000000..2d3afb6 --- /dev/null +++ b/rss/include/xtensa/example_service.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_H_ +#define EXAMPLE_SERVICE_H_ + +/** + * @brief Service example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_calibration_caching.h b/rss/include/xtensa/example_service_calibration_caching.h new file mode 100644 index 0000000..2deccba --- /dev/null +++ b/rss/include/xtensa/example_service_calibration_caching.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_CALIBRATION_CACHING_H_ +#define EXAMPLE_SERVICE_CALIBRATION_CACHING_H_ + +/** + * @brief Service sensor calibration caching example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_multiple_configurations.h b/rss/include/xtensa/example_service_multiple_configurations.h new file mode 100644 index 0000000..fd75f63 --- /dev/null +++ b/rss/include/xtensa/example_service_multiple_configurations.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_MULTIPLE_CONFIGURATIONS_H_ +#define EXAMPLE_SERVICE_MULTIPLE_CONFIGURATIONS_H_ + +/** + * @brief Service multple configurations example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_sensor_disable.h b/rss/include/xtensa/example_service_sensor_disable.h new file mode 100644 index 0000000..87e238c --- /dev/null +++ b/rss/include/xtensa/example_service_sensor_disable.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_LOW_POWER_H_ +#define EXAMPLE_SERVICE_LOW_POWER_H_ + +/** + * @brief Low power service example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_sensor_hibernate.h b/rss/include/xtensa/example_service_sensor_hibernate.h new file mode 100644 index 0000000..87e238c --- /dev/null +++ b/rss/include/xtensa/example_service_sensor_hibernate.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_LOW_POWER_H_ +#define EXAMPLE_SERVICE_LOW_POWER_H_ + +/** + * @brief Low power service example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_sensor_off.h b/rss/include/xtensa/example_service_sensor_off.h new file mode 100644 index 0000000..87e238c --- /dev/null +++ b/rss/include/xtensa/example_service_sensor_off.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2020-2023 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_LOW_POWER_H_ +#define EXAMPLE_SERVICE_LOW_POWER_H_ + +/** + * @brief Low power service example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rss/include/xtensa/example_service_subsweeps.h b/rss/include/xtensa/example_service_subsweeps.h new file mode 100644 index 0000000..2bbb09b --- /dev/null +++ b/rss/include/xtensa/example_service_subsweeps.h @@ -0,0 +1,18 @@ +// Copyright (c) Acconeer AB, 2021-2022 +// All rights reserved +// This file is subject to the terms and conditions defined in the file +// 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part +// of this source code package. + +#ifndef EXAMPLE_SERVICE_SUBSWEEPS_H_ +#define EXAMPLE_SERVICE_SUBSWEEPS_H_ + +/** + * @brief Service subsweeps example + * + * @return Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE + */ +int app_main(int argc, char *argv[]); + + +#endif diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 87f73c3..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,6 +0,0 @@ -[toolchain] -channel = "1.75" -components = [ "rust-src", "rustfmt", "clippy" ] -targets = [ - "thumbv7em-none-eabihf", -] \ No newline at end of file diff --git a/rust-toolchain.toml.bak b/rust-toolchain.toml.bak new file mode 100644 index 0000000..8581633 --- /dev/null +++ b/rust-toolchain.toml.bak @@ -0,0 +1,8 @@ +[toolchain] +#channel = "1.75" +#components = [ "rust-src", "rustfmt", "clippy" ] +#targets = [ +# "thumbv7em-none-eabihf", +#] + +channel = "esp"