From eef80f379012e0a0c80a48586944556a1c898a61 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Thu, 2 May 2024 02:00:05 +0100 Subject: [PATCH 1/8] Provide functions enabling non-blocking operation --- inc/mlx90632.h | 96 +++++++++++++++++++++++++- inc/mlx90632_extended_meas.h | 29 +++++++- src/mlx90632.c | 127 ++++++++++++++++++++++++----------- src/mlx90632_extended_meas.c | 41 ++++++----- 4 files changed, 229 insertions(+), 64 deletions(-) diff --git a/inc/mlx90632.h b/inc/mlx90632.h index c90463d..238f8b4 100644 --- a/inc/mlx90632.h +++ b/inc/mlx90632.h @@ -210,6 +210,40 @@ typedef enum mlx90632_meas_e { #define MLX90632_NEW_REG_VALUE(old_reg, new_value, h, l) \ ((old_reg & (0xFFFF ^ GENMASK(h, l))) | (new_value << MLX90632_EE_REFRESH_RATE_SHIFT)) +/** Read raw ambient and object temperature only when measurement data is ready + * + * Read raw ambient and object temperatures without waiting. This values still need + * to be pre-processed via @link mlx90632_preprocess_temp_ambient @endlink and @link + * mlx90632_preprocess_temp_object @endlink functions and then processed via @link + * mlx90632_calc_temp_ambient @endlink and @link mlx90632_calc_temp_object @endlink + * to retrieve values in milliCelsius. This function assumes that measurement cycle + * has been triggered and completed via @link mlx90632_start_measurement @endlink or + * @link mlx90632_trigger_measurement @endlink or @link mlx90632_wait_for_measurement @endlink, + * and channel position has been checked via @link mlx90632_get_channel_position @endlink + * in case of continuous mode. This function assumes that measurement cycle has been + * triggered and completed via @link mlx90632_start_measurement_burst @endlink, or @link + * mlx90632_trigger_measurement_burst @endlink and @link mlx90632_wait_for_measurement_burst + * @endlink with sufficient time in between needed to refresh the whole measurement table + * in case of burst mode. + * + * @param[in] channel_position Channel position where new (recently updated) measurement can be found, + * usually return value of @link mlx90632_start_measurement @endlink or + * @link mlx90632_wait_for_measurement @endlink or @link + * mlx90632_get_channel_position @endlink + * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written + * @param[out] object_new_raw Pointer to where new raw object temperature is written + * @param[out] ambient_old_raw Pointer to where old raw ambient temperature is written + * @param[out] object_old_raw Pointer to where old raw object temperature is written + * + * @retval 0 Successfully read both temperatures + * @retval <0 Something went wrong. Check errno.h for more details + * + * @note This function is not blocking! + */ +int32_t mlx90632_read_temp_raw_wo_wait(int32_t channel_position, + int16_t *ambient_new_raw, int16_t *ambient_old_raw, + int16_t *object_new_raw, int16_t *object_old_raw); + /** Read raw ambient and object temperature * * Trigger and read raw ambient and object temperatures. This values still need @@ -368,6 +402,30 @@ double mlx90632_calc_temp_object_reflected(int32_t object, int32_t ambient, doub */ int32_t mlx90632_init(void); +/** Trigger measurement for mlx90632 + * + * Trigger measurement cycle. It does not read anything, just triggers measurement. + * + * @retval <0 Something failed. Check errno.h for more information + * @retval 0 Successfully triggered and started measuremeent + * + * @note This function is not blocking! + */ +int32_t mlx90632_trigger_measurement(void); + +/** Wait for measurement to complete for mlx90632 + * + * Wait for measurement data to be ready. It does not read anything, just completes measurement. + * This function assumes that measurement cycle has been triggered via @link + * mlx90632_trigger_measurement @endlink. + * + * @retval <0 Something failed. Check errno.h for more information + * @retval >=0 Channel position where new (recently updated) measurement can be found + * + * @note This function is using usleep so it is blocking! + */ +int32_t mlx90632_wait_for_measurement(void); + /** Trigger start measurement for mlx90632 * * Trigger measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes. @@ -377,7 +435,7 @@ int32_t mlx90632_init(void); * * @note This function is using usleep so it is blocking! */ -int mlx90632_start_measurement(void); +int32_t mlx90632_start_measurement(void); /** Set emissivity which is retained in single variable. * @@ -391,6 +449,33 @@ void mlx90632_set_emissivity(double value); */ double mlx90632_get_emissivity(void); +/** Trigger burst measurement for mlx90632 + * + * Trigger a single measurement cycle. It does not read anything, just triggers measurement. + * The SOB bit is set so that the complete measurement table is re-freshed. + * + * @note The SOB bit is cleared internally by the mlx90632 immediately after the measurement has started. + * + * @retval <0 Something failed. Check errno.h for more information + * @retval 0 Successfully triggered and started measuremeent + * + * @note This function is not blocking! + */ +int32_t mlx90632_trigger_measurement_burst(void); + +/** Wait for burst measurement to complete for mlx90632 + * + * Wait for measurement data to be ready. It does not read anything, just completes measurement. + * This function assumes that burst measurement cycle has been triggered via @link + * mlx90632_trigger_measurement_burst @endlink. + * + * @retval <0 Something failed. Check errno.h for more information + * @retval 0 New data is available and waiting to be processed + * + * @note This function is using usleep so it is blocking! + */ +int32_t mlx90632_wait_for_measurement_burst(void); + /** Trigger start of burst measurement for mlx90632 * * Trigger a single measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes. @@ -453,11 +538,18 @@ int32_t mlx90632_set_refresh_rate(mlx90632_meas_t measRate); */ mlx90632_meas_t mlx90632_get_refresh_rate(void); +/** Gets the channel position where new (recently updated) measurement can be found + * + * @retval <0 Something failed. Check errno.h for more information + * @retval >=0 Channel position where new (recently updated) measurement can be found + */ +int32_t mlx90632_get_channel_position(void); + ///@} #ifdef TEST int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw); -int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, +int32_t mlx90632_read_temp_object_raw(int32_t channel_position, int16_t *object_new_raw, int16_t *object_old_raw); #endif diff --git a/inc/mlx90632_extended_meas.h b/inc/mlx90632_extended_meas.h index fd71ae9..889627c 100644 --- a/inc/mlx90632_extended_meas.h +++ b/inc/mlx90632_extended_meas.h @@ -24,6 +24,33 @@ #ifndef _MLX90632_EXTENDED_MEAS_LIB_ #define _MLX90632_EXTENDED_MEAS_LIB_ +/** Read raw ambient and object temperature for extended range only when measurement data is ready + * + * Read raw ambient and object temperatures without waiting. This values still need + * to be pre-processed via @link mlx90632_preprocess_temp_ambient_extended @endlink and @link + * mlx90632_preprocess_temp_object_extended @endlink functions and then processed via @link + * mlx90632_calc_temp_ambient_extended @endlink and @link mlx90632_calc_temp_object_extended @endlink + * to retrieve values in milliCelsius. This function assumes that measurement cycle + * has been triggered and completed via @link mlx90632_start_measurement @endlink or + * @link mlx90632_trigger_measurement @endlink or @link mlx90632_wait_for_measurement @endlink, + * and channel position has been checked via @link mlx90632_get_channel_position @endlink + * in case of continuous mode. This function assumes that measurement cycle has been + * triggered and completed via @link mlx90632_start_measurement_burst @endlink, or @link + * mlx90632_trigger_measurement_burst @endlink and @link mlx90632_wait_for_measurement_burst + * @endlink with sufficient time in between needed to refresh the whole measurement table + * in case of burst mode. + * + * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written + * @param[out] object_new_raw Pointer to where new raw object temperature is written + * @param[out] ambient_old_raw Pointer to where old raw ambient temperature is written + * + * @retval 0 Successfully read both temperatures + * @retval <0 Something went wrong. Check errno.h for more details + * + * @note This function is not blocking! + */ +int32_t mlx90632_read_temp_raw_extended_wo_wait(int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw); + /** Read raw ambient and object temperature for extended range * * Trigger and read raw ambient and object temperatures. This values still need @@ -35,7 +62,6 @@ * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written * @param[out] object_new_raw Pointer to where new raw object temperature is written * @param[out] ambient_old_raw Pointer to where old raw ambient temperature is written - * @param[out] object_old_raw Pointer to where old raw object temperature is written * * @retval 0 Successfully read both temperatures * @retval <0 Something went wrong. Check errno.h for more details @@ -53,7 +79,6 @@ int32_t mlx90632_read_temp_raw_extended(int16_t *ambient_new_raw, int16_t *ambie * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written * @param[out] object_new_raw Pointer to where new raw object temperature is written * @param[out] ambient_old_raw Pointer to where old raw ambient temperature is written - * @param[out] object_old_raw Pointer to where old raw object temperature is written * * @retval 0 Successfully read both temperatures * @retval <0 Something went wrong. Check errno.h for more details diff --git a/src/mlx90632.c b/src/mlx90632.c index 6a6c8dc..e2588cb 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -44,9 +44,9 @@ static const char mlx90632version[] __attribute__((used)) = { VERSION }; #define STATIC static #endif -int mlx90632_start_measurement(void) +int32_t mlx90632_trigger_measurement(void) { - int ret, tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; + int32_t ret; uint16_t reg_status; ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®_status); @@ -54,8 +54,15 @@ int mlx90632_start_measurement(void) return ret; ret = mlx90632_i2c_write(MLX90632_REG_STATUS, reg_status & (~MLX90632_STAT_DATA_RDY)); - if (ret < 0) - return ret; + + return ret; +} + +int32_t mlx90632_wait_for_measurement(void) +{ + int32_t ret; + uint16_t reg_status; + int tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; while (tries-- > 0) { @@ -80,6 +87,17 @@ int mlx90632_start_measurement(void) return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2; } +int32_t mlx90632_start_measurement(void) +{ + int32_t ret = mlx90632_trigger_measurement(); + if (ret < 0) + return ret; + + ret = mlx90632_wait_for_measurement(); + + return ret; +} + /** Based on @link mlx90632_start_measurement @endlink return value fill channel_new and channel_old * variables with proper values. This is to provide a bit more flexibility in case other channels are * returned and need a bit more mingeling than usual maths can provide. @@ -152,14 +170,17 @@ STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t * calculation functions. Because one value is newer than other (see @link mlx90632_start_measurement @endlink) this * function provides dynamics based on return value of the @link mlx90632_start_measurement @endlink. * - * @param[in] start_measurement_ret Return value of @link mlx90632_start_measurement @endlink + * @param[in] channel_position Channel position where new (recently updated) measurement can be found, + * usually return value of @link mlx90632_start_measurement @endlink or + * @link mlx90632_wait_for_measurement @endlink or @link + * mlx90632_get_channel_position @endlink * @param[out] *object_new_raw Pointer to memory location where average of new object values from sensor is stored * @param[out] *object_old_raw Pointer to memory location where average of old object values from sensor is stored * * @retval 0 Successfully read both values * @retval <0 Something went wrong. Check errno.h for more details. */ -STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, +STATIC int32_t mlx90632_read_temp_object_raw(int32_t channel_position, int16_t *object_new_raw, int16_t *object_old_raw) { int32_t ret; @@ -167,7 +188,7 @@ STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, int16_t read; uint8_t channel, channel_old; - ret = mlx90632_channel_new_select(start_measurement_ret, &channel, &channel_old); + ret = mlx90632_channel_new_select(channel_position, &channel, &channel_old); if (ret != 0) return -EINVAL; @@ -195,46 +216,47 @@ STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, return ret; } -int32_t mlx90632_read_temp_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw, - int16_t *object_new_raw, int16_t *object_old_raw) +int32_t mlx90632_read_temp_raw_wo_wait(int32_t channel_position, + int16_t *ambient_new_raw, int16_t *ambient_old_raw, + int16_t *object_new_raw, int16_t *object_old_raw) { - int32_t ret, start_measurement_ret; - - // trigger and wait for measurement to complete - start_measurement_ret = mlx90632_start_measurement(); - if (start_measurement_ret < 0) - return start_measurement_ret; - /** Read new and old **ambient** values from sensor */ - ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw); + int32_t ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw); if (ret < 0) return ret; /** Read new and old **object** values from sensor */ - ret = mlx90632_read_temp_object_raw(start_measurement_ret, object_new_raw, object_old_raw); + ret = mlx90632_read_temp_object_raw(channel_position, object_new_raw, object_old_raw); return ret; } +int32_t mlx90632_read_temp_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw, + int16_t *object_new_raw, int16_t *object_old_raw) +{ + // trigger and wait for measurement to complete + int32_t start_measurement_ret = mlx90632_start_measurement(); + if (start_measurement_ret < 0) + return start_measurement_ret; + + /** Read raw ambient and object temperature */ + return mlx90632_read_temp_raw_wo_wait(start_measurement_ret, ambient_new_raw, ambient_old_raw, + object_new_raw, object_old_raw); +} + int32_t mlx90632_read_temp_raw_burst(int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw, int16_t *object_old_raw) { - int32_t ret, start_measurement_ret; + int32_t start_measurement_ret; // trigger and wait for measurement to complete start_measurement_ret = mlx90632_start_measurement_burst(); if (start_measurement_ret < 0) return start_measurement_ret; - /** Read new and old **ambient** values from sensor */ - ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw); - if (ret < 0) - return ret; - - /** Read new and old **object** values from sensor */ - ret = mlx90632_read_temp_object_raw(2, object_new_raw, object_old_raw); - - return ret; + /** Read raw ambient and object temperature */ + return mlx90632_read_temp_raw_wo_wait(2, ambient_new_raw, ambient_old_raw, + object_new_raw, object_old_raw); } @@ -564,10 +586,9 @@ int32_t mlx90632_calculate_dataset_ready_time(void) return refresh_time; } -int32_t mlx90632_start_measurement_burst(void) +int32_t mlx90632_trigger_measurement_burst(void) { int32_t ret; - int tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; uint16_t reg; ret = mlx90632_i2c_read(MLX90632_REG_CTRL, ®); @@ -577,20 +598,22 @@ int32_t mlx90632_start_measurement_burst(void) reg |= MLX90632_START_BURST_MEAS; ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg); - if (ret < 0) - return ret; - ret = mlx90632_calculate_dataset_ready_time(); - if (ret < 0) - return ret; - msleep(ret); /* Waiting for refresh of all the measurement tables */ + return ret; +} + +int32_t mlx90632_wait_for_measurement_burst(void) +{ + int32_t ret; + uint16_t reg_status; + int tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; while (tries-- > 0) { - ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®); + ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®_status); if (ret < 0) return ret; - if ((reg & MLX90632_STAT_BUSY) == 0) + if ((reg_status & MLX90632_STAT_BUSY) == 0) break; /* minimum wait time to complete measurement * should be calculated according to refresh rate @@ -608,6 +631,22 @@ int32_t mlx90632_start_measurement_burst(void) return 0; } +int32_t mlx90632_start_measurement_burst(void) +{ + int32_t ret = mlx90632_trigger_measurement_burst(); + if (ret < 0) + return ret; + + ret = mlx90632_calculate_dataset_ready_time(); + if (ret < 0) + return ret; + msleep(ret); /* Waiting for refresh of all the measurement tables */ + + ret = mlx90632_wait_for_measurement_burst(); + + return ret; +} + STATIC int32_t mlx90632_unlock_eeporm() { @@ -704,4 +743,16 @@ mlx90632_meas_t mlx90632_get_refresh_rate(void) return (mlx90632_meas_t)MLX90632_REFRESH_RATE(meas1); } +int32_t mlx90632_get_channel_position(void) +{ + int32_t ret; + uint16_t reg_status; + + ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®_status); + if (ret < 0) + return ret; + + return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2; +} + ///@} diff --git a/src/mlx90632_extended_meas.c b/src/mlx90632_extended_meas.c index 2561cb1..ad0c9bf 100644 --- a/src/mlx90632_extended_meas.c +++ b/src/mlx90632_extended_meas.c @@ -130,9 +130,22 @@ STATIC int32_t mlx90632_read_temp_object_raw_extended(int16_t *object_new_raw) return ret; } +int32_t mlx90632_read_temp_raw_extended_wo_wait(int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw) +{ + /** Read new and old **ambient** values from sensor */ + int32_t ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw); + if (ret < 0) + return ret; + + /** Read new **object** value from sensor */ + ret = mlx90632_read_temp_object_raw_extended(object_new_raw); + + return ret; +} + int32_t mlx90632_read_temp_raw_extended(int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw) { - int32_t ret, start_measurement_ret; + int32_t start_measurement_ret; int tries = 3; // trigger and wait for measurement to complete @@ -152,35 +165,19 @@ int32_t mlx90632_read_temp_raw_extended(int16_t *ambient_new_raw, int16_t *ambie return -ETIMEDOUT; } - /** Read new and old **ambient** values from sensor */ - ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw); - if (ret < 0) - return ret; - - /** Read new **object** value from sensor */ - ret = mlx90632_read_temp_object_raw_extended(object_new_raw); - - return ret; + /** Read raw ambient and object temperature for extended range */ + return mlx90632_read_temp_raw_extended_wo_wait(ambient_new_raw, ambient_old_raw, object_new_raw); } int32_t mlx90632_read_temp_raw_extended_burst(int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw) { - int32_t ret, start_measurement_ret; - // trigger and wait for measurement to complete - start_measurement_ret = mlx90632_start_measurement_burst(); + int32_t start_measurement_ret = mlx90632_start_measurement_burst(); if (start_measurement_ret < 0) return start_measurement_ret; - /** Read new and old **ambient** values from sensor */ - ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw); - if (ret < 0) - return ret; - - /** Read new **object** value from sensor */ - ret = mlx90632_read_temp_object_raw_extended(object_new_raw); - - return ret; + /** Read raw ambient and object temperature for extended range */ + return mlx90632_read_temp_raw_extended_wo_wait(ambient_new_raw, ambient_old_raw, object_new_raw); } double mlx90632_preprocess_temp_ambient_extended(int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb) From 727c57afdf01bd474b26e418c2cff35173f09518 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Mon, 20 May 2024 19:44:31 +0100 Subject: [PATCH 2/8] Provide functions enabling non-blocking operation in single measurement mode --- inc/mlx90632.h | 31 +++++++++++++++++++++++++++---- inc/mlx90632_extended_meas.h | 6 +++++- src/mlx90632.c | 25 ++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/inc/mlx90632.h b/inc/mlx90632.h index 238f8b4..55c7163 100644 --- a/inc/mlx90632.h +++ b/inc/mlx90632.h @@ -163,6 +163,8 @@ typedef enum mlx90632_meas_e { /* Start of burst measurement options */ #define MLX90632_START_BURST_MEAS MLX90632_CFG_SOB(1) #define MLX90632_BURST_MEAS_NOT_PENDING MLX90632_CFG_SOB(0) +/* Start of single measurement option */ +#define MLX90632_START_SINGLE_MEAS (1 << MLX90632_CFG_SOC_SHIFT) /* Device status register - volatile */ #define MLX90632_REG_STATUS 0x3fff /**< Device status register */ @@ -224,12 +226,19 @@ typedef enum mlx90632_meas_e { * triggered and completed via @link mlx90632_start_measurement_burst @endlink, or @link * mlx90632_trigger_measurement_burst @endlink and @link mlx90632_wait_for_measurement_burst * @endlink with sufficient time in between needed to refresh the whole measurement table - * in case of burst mode. + * in case of burst mode. This function assumes that measurement cycle has been + * triggered and completed via @link mlx90632_trigger_measurement_single @endlink and + * @link mlx90632_wait_for_measurement @endlink with sufficient time in between needed to + * refresh a single measurement in case of single mode (must be triggered and completed + * two times after power-up before calling this function). * * @param[in] channel_position Channel position where new (recently updated) measurement can be found, * usually return value of @link mlx90632_start_measurement @endlink or * @link mlx90632_wait_for_measurement @endlink or @link - * mlx90632_get_channel_position @endlink + * mlx90632_get_channel_position @endlink in case of continuous mode, + * 2 in case of burst mode, and return value of @link + * mlx90632_wait_for_measurement @endlink or @link + * mlx90632_get_channel_position @endlink in case of single mode * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written * @param[out] object_new_raw Pointer to where new raw object temperature is written * @param[out] ambient_old_raw Pointer to where old raw ambient temperature is written @@ -417,7 +426,7 @@ int32_t mlx90632_trigger_measurement(void); * * Wait for measurement data to be ready. It does not read anything, just completes measurement. * This function assumes that measurement cycle has been triggered via @link - * mlx90632_trigger_measurement @endlink. + * mlx90632_trigger_measurement @endlink or @link mlx90632_trigger_measurement_single @endlink. * * @retval <0 Something failed. Check errno.h for more information * @retval >=0 Channel position where new (recently updated) measurement can be found @@ -451,7 +460,7 @@ double mlx90632_get_emissivity(void); /** Trigger burst measurement for mlx90632 * - * Trigger a single measurement cycle. It does not read anything, just triggers measurement. + * Trigger a full measurement cycle. It does not read anything, just triggers measurement. * The SOB bit is set so that the complete measurement table is re-freshed. * * @note The SOB bit is cleared internally by the mlx90632 immediately after the measurement has started. @@ -492,6 +501,20 @@ int32_t mlx90632_wait_for_measurement_burst(void); */ int32_t mlx90632_start_measurement_burst(void); +/** Trigger single measurement for mlx90632 + * + * Trigger a single measurement cycle. It does not read anything, just triggers measurement. + * The SOC bit is set so that the single measurement is triggered. + * + * @note The SOC bit is cleared internally by the mlx90632 immediately after the measurement has started. + * + * @retval <0 Something failed. Check errno.h for more information + * @retval 0 Successfully triggered and started measuremeent + * + * @note This function is not blocking! + */ +int32_t mlx90632_trigger_measurement_single(void); + /** Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM settings. * * @param[in] meas Measurement to read the frefresh rate for diff --git a/inc/mlx90632_extended_meas.h b/inc/mlx90632_extended_meas.h index 889627c..8fd898a 100644 --- a/inc/mlx90632_extended_meas.h +++ b/inc/mlx90632_extended_meas.h @@ -38,7 +38,11 @@ * triggered and completed via @link mlx90632_start_measurement_burst @endlink, or @link * mlx90632_trigger_measurement_burst @endlink and @link mlx90632_wait_for_measurement_burst * @endlink with sufficient time in between needed to refresh the whole measurement table - * in case of burst mode. + * in case of burst mode. This function assumes that measurement cycle has been + * triggered and completed via @link mlx90632_trigger_measurement_single @endlink and + * @link mlx90632_wait_for_measurement @endlink with sufficient time in between needed to + * refresh a single measurement in case of single mode (must be triggered and completed + * three times after power-up before calling this function). * * @param[out] ambient_new_raw Pointer to where new raw ambient temperature is written * @param[out] object_new_raw Pointer to where new raw object temperature is written diff --git a/src/mlx90632.c b/src/mlx90632.c index e2588cb..c9dbf17 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -173,7 +173,10 @@ STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t * @param[in] channel_position Channel position where new (recently updated) measurement can be found, * usually return value of @link mlx90632_start_measurement @endlink or * @link mlx90632_wait_for_measurement @endlink or @link - * mlx90632_get_channel_position @endlink + * mlx90632_get_channel_position @endlink in case of continuous mode, + * 2 in case of burst mode, and return value of @link + * mlx90632_wait_for_measurement @endlink or @link + * mlx90632_get_channel_position @endlink in case of single mode * @param[out] *object_new_raw Pointer to memory location where average of new object values from sensor is stored * @param[out] *object_old_raw Pointer to memory location where average of old object values from sensor is stored * @@ -647,6 +650,26 @@ int32_t mlx90632_start_measurement_burst(void) return ret; } +int32_t mlx90632_trigger_measurement_single(void) +{ + int32_t ret; + uint16_t reg; + + // Clear NEW_DATA flag + ret = mlx90632_trigger_measurement(); + if (ret < 0) + return ret; + + ret = mlx90632_i2c_read(MLX90632_REG_CTRL, ®); + if (ret < 0) + return ret; + + reg |= MLX90632_START_SINGLE_MEAS; + + ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg); + + return ret; +} STATIC int32_t mlx90632_unlock_eeporm() { From 7316ce04fa32e4ea56b4dc7b70467cba1f310337 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Tue, 6 Aug 2024 10:25:34 +0100 Subject: [PATCH 3/8] Arrange variables in reverse Christmas tree Co-Authored-By: Crt Mori --- src/mlx90632.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mlx90632.c b/src/mlx90632.c index c9dbf17..2b51603 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -46,8 +46,8 @@ static const char mlx90632version[] __attribute__((used)) = { VERSION }; int32_t mlx90632_trigger_measurement(void) { - int32_t ret; uint16_t reg_status; + int32_t ret; ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®_status); if (ret < 0) @@ -60,9 +60,9 @@ int32_t mlx90632_trigger_measurement(void) int32_t mlx90632_wait_for_measurement(void) { - int32_t ret; - uint16_t reg_status; int tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; + uint16_t reg_status; + int32_t ret; while (tries-- > 0) { @@ -591,8 +591,8 @@ int32_t mlx90632_calculate_dataset_ready_time(void) int32_t mlx90632_trigger_measurement_burst(void) { - int32_t ret; uint16_t reg; + int32_t ret; ret = mlx90632_i2c_read(MLX90632_REG_CTRL, ®); if (ret < 0) @@ -607,9 +607,9 @@ int32_t mlx90632_trigger_measurement_burst(void) int32_t mlx90632_wait_for_measurement_burst(void) { - int32_t ret; - uint16_t reg_status; int tries = MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; + uint16_t reg_status; + int32_t ret; while (tries-- > 0) { @@ -652,8 +652,8 @@ int32_t mlx90632_start_measurement_burst(void) int32_t mlx90632_trigger_measurement_single(void) { - int32_t ret; uint16_t reg; + int32_t ret; // Clear NEW_DATA flag ret = mlx90632_trigger_measurement(); @@ -768,8 +768,8 @@ mlx90632_meas_t mlx90632_get_refresh_rate(void) int32_t mlx90632_get_channel_position(void) { - int32_t ret; uint16_t reg_status; + int32_t ret; ret = mlx90632_i2c_read(MLX90632_REG_STATUS, ®_status); if (ret < 0) From 0f78ee10766555a102d02ef3b1e8e0e43053ab70 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Thu, 8 Aug 2024 16:44:06 +0100 Subject: [PATCH 4/8] Write unit tests for functions enabling non-blocking operation --- test/TestRead.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 529 insertions(+), 6 deletions(-) diff --git a/test/TestRead.c b/test/TestRead.c index 4935a40..6a4214d 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -53,6 +53,119 @@ void tearDown(void) { } +/** Test trigger measurement. + */ +void test_trigger_measurement_success(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + + // Trigger measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_trigger_measurement()); +} + +/** Test different failure paths when triggering measurement. + */ +void test_trigger_measurement_errors(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + + // Trigger measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement()); + + // Trigger measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), -EPERM); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement()); +} + +/** Test wait for measurement with data ready. + */ +void test_wait_for_measurement_success(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + + // Wait for measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + TEST_ASSERT_EQUAL_INT32(1, mlx90632_wait_for_measurement()); +} + +/** Test wait for measurement function, if data is ready and if it is not it waits one usleep period before retry. + * + * First we simulate data not ready with bit0 not set. After one period we flip the bit0 to 1 to indicate + * data ready and wait for measurement should complete with success. + */ +void test_wait_for_measurement_one_wait(void) +{ + uint16_t reg_status_mock = 0x0C86; // cycle position 1 & data not ready + uint16_t reg_status_mock1 = 0x0087; // cycle position 1 & data ready + + // Wait for measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + usleep_Expect(10000, 11000); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock1); + + TEST_ASSERT_EQUAL_INT32(1, mlx90632_wait_for_measurement()); +} + +/** Test failure path when waiting for measurement. + */ +void test_wait_for_measurement_error(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + + // Wait for measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_wait_for_measurement()); +} + +/** Test sensor timeouts while waiting for measurement. + * + * If this happens in real life it means that after 100 tries sensor still did not indicate data ready, which probably + * points to much larger problem than a simple timeout. Timeout is only valid if usleep is a lot shorter than default + * values + */ +void test_wait_for_measurement_timeout(void) +{ + uint16_t reg_status_mock = 0x0C86; // cycle position 1 & data not ready + int i; + + for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) + { + // Wait for measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + usleep_Expect(10000, 11000); + } + + TEST_ASSERT_EQUAL_INT32(-ETIMEDOUT, mlx90632_wait_for_measurement()); +} + /** Test start measurement with data ready. */ void test_start_measurement_success(void) @@ -70,7 +183,7 @@ void test_start_measurement_success(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(1, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(1, mlx90632_start_measurement()); } /** Test start measurement function, if data is ready and if it is not it waits one usleep period before retry. @@ -100,7 +213,7 @@ void test_start_measurement_one_wait(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock1); - TEST_ASSERT_EQUAL_INT(1, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(1, mlx90632_start_measurement()); } /** Test different failure paths in start_measurement */ @@ -113,7 +226,7 @@ void test_start_measurement_busy_i2c(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement()); // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -122,7 +235,7 @@ void test_start_measurement_busy_i2c(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement()); // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -134,7 +247,7 @@ void test_start_measurement_busy_i2c(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement()); } /** Test sensor timeouts while start_measure. @@ -168,10 +281,117 @@ void test_start_measurement_timeout(void) usleep_Expect(10000, 11000); } - TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_start_measurement()); + TEST_ASSERT_EQUAL_INT32(-ETIMEDOUT, mlx90632_start_measurement()); } +/** Test read temperature from sensor without waiting procedure. + * + * Read ambient and object raw values considering channel 1 as new. Channel 2 values are read as old, + * while channel 1 values are read as new. + */ +void test_read_temp_raw_wo_wait_ch1_success(void) +{ + int16_t ambient_new_mock = 22454; + int16_t ambient_old_mock = 23030; + int16_t object_new_mock = 150; + int16_t object_old_mock = 150; + + // Read Ambient raw expectations (based on cycle position 1) + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(2), (uint16_t*)&ambient_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); + + // Read Object raw expectations (based on cycle position 1) + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(1), (uint16_t*)&object_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(2), (uint16_t*)&object_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(2), (uint16_t*)&object_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_wo_wait(1, &ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + + // Confirm all values are as expected + TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); + TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); +} + +/** Test read temperature from sensor without waiting procedure. + * + * Read ambient and object raw values considering channel 2 as new. Channel 1 values are read as old, + * while channel 2 values are read as new. + */ +void test_read_temp_raw_wo_wait_ch2_success(void) +{ + int16_t ambient_new_mock = 22454; + int16_t ambient_old_mock = 23030; + int16_t object_new_mock = 150; + int16_t object_old_mock = 150; + + // Read Ambient raw expectations (based on cycle position 2) + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(2), (uint16_t*)&ambient_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); + + // Read Object raw expectations (based on cycle position 2) + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(2), (uint16_t*)&object_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(2), (uint16_t*)&object_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(1), (uint16_t*)&object_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_wo_wait(2, &ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + + // Confirm all values are as expected + TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); + TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); +} + +/** Test failure path when reading temperature from sensor without waiting procedure. + */ +void test_read_temp_raw_wo_wait_error(void) +{ + int16_t ambient_new_mock = 22454; + + // Read Ambient raw expectations (based on cycle position 1) + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_wo_wait(1, &ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); +} + /** Test whole start and read temperature from sensor procedure. * * Start measurement which returns channel 1 as new, then read ambient and object raw values. @@ -748,6 +968,91 @@ void test_read_object_values_extended_errors(void) TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_read_temp_object_raw_extended(&object_new_raw)); } +/** Test read extended temperature from sensor without waiting procedure. + */ +void test_read_temp_raw_extended_wo_wait_success(void) +{ + int16_t ambient_new_mock = 22454; + int16_t ambient_old_mock = 23030; + int16_t object_mock_l1 = 250; + int16_t object_mock_l2 = 260; + int16_t object_mock_b1 = -25; + int16_t object_mock_b2 = -35; + int16_t object_mock_v1 = 4; + int16_t object_mock_v2 = -2; + + // Read Ambient raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(18), (uint16_t*)&ambient_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); + + // Read Object raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_l1); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(17), (uint16_t*)&object_mock_b1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_b1); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(18), (uint16_t*)&object_mock_b2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_b2); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(18), (uint16_t*)&object_mock_l2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_l2); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(19), (uint16_t*)&object_mock_v1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v1); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(19), (uint16_t*)&object_mock_v2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_extended_wo_wait(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + + // Confirm all values are as expected + TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); + TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); + TEST_ASSERT_EQUAL_INT16(287, object_new_raw); +} + +/** Test different failure paths when reading extended temperature from sensor without waiting procedure. + */ +void test_read_temp_raw_extended_wo_wait_errors(void) +{ + int16_t ambient_new_mock = 22454; + int16_t ambient_old_mock = 23030; + int16_t object_mock_l1 = 250; + + // Read Ambient raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended_wo_wait(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + + // Read Ambient raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(18), (uint16_t*)&ambient_old_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); + + // Read Object raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended_wo_wait(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); +} + /** Test whole start and read extended temperature from sensor procedure. * * Start measurement which returns channel 19 as the last measurement, then read ambient and object raw values. @@ -1042,6 +1347,95 @@ void test_read_temp_raw_extended_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); } +/** Test trigger burst measurement. + */ +void test_trigger_measurement_burst_success(void) +{ + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + + // Trigger burst measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock | MLX90632_START_BURST_MEAS, 0); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_trigger_measurement_burst()); +} + +/** Test different failure paths when triggering burst measurement. + */ +void test_trigger_measurement_burst_errors(void) +{ + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + + // Trigger burst measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_burst()); + + // Trigger burst measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock | MLX90632_START_BURST_MEAS, -EPERM); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_burst()); +} + +/** Test wait for burst measurement with data ready. + */ +void test_wait_for_measurement_burst_success(void) +{ + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy + + // Wait for burst measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_wait_for_measurement_burst()); +} + +/** Test failure path when waiting for burst measurement. + */ +void test_wait_for_measurement_burst_error(void) +{ + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy + + // Wait for burst measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_wait_for_measurement_burst()); +} + +/** Test sensor timeouts while while waiting for burst measurement. + * + * If this happens in real life it means that after some tries sensor still did not indicate data ready, which probably + * points to much larger problem than a simple timeout. Timeout is only valid if usleep is a lot shorter than default + * values + */ +void test_wait_for_measurement_burst_timeout(void) +{ + uint16_t reg_status_mock = 0x0C06; // cycle position 1 & device busy + int i; + + for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) + { + // Wait for measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + usleep_Expect(10000, 11000); + } + + TEST_ASSERT_EQUAL_INT32(-ETIMEDOUT, mlx90632_wait_for_measurement_burst()); +} + /** Test start sleeping step measurement. */ void test_start_measurement_burst_success(void) @@ -1193,6 +1587,79 @@ void test_start_measurement_burst_timeout(void) TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_start_measurement_burst()); } +/** Test trigger single measurement. + */ +void test_trigger_measurement_single_success(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + + // Trigger single measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock | MLX90632_START_SINGLE_MEAS, 0); + + TEST_ASSERT_EQUAL_INT32(0, mlx90632_trigger_measurement_single()); +} + +/** Test failure path when triggering single measurement. + */ +void test_trigger_measurement_single_errors(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + + // Trigger single measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_single()); + + // Trigger single measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), -EPERM); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_single()); + + // Trigger single measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_single()); + + // Trigger single measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock | MLX90632_START_SINGLE_MEAS, -EPERM); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_trigger_measurement_single()); +} + /** Test whole start and read extended temperature in sleeping step mode from sensor procedure. * * Start measurement which returns channel 0 on success, then read ambient and object raw values. @@ -1637,6 +2104,62 @@ void test_calculate_dataset_ready_time_extended_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); } +/** Test get channel position. + */ +void test_get_channel_position_success(void) +{ + uint16_t reg_status_mock_med1 = 0x0087; // cycle position 1 & data ready + uint16_t reg_status_mock_med2 = 0x008B; // cycle position 2 & data ready + uint16_t reg_status_mock_ext1 = 0x00C5; // cycle position 17 & data ready + uint16_t reg_status_mock_ext2 = 0x00C9; // cycle position 18 & data ready + uint16_t reg_status_mock_ext3 = 0x00CF; // cycle position 19 & data ready + + // Read medical measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock_med1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock_med1); + + TEST_ASSERT_EQUAL_INT32(1, mlx90632_get_channel_position()); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock_med2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock_med2); + + TEST_ASSERT_EQUAL_INT32(2, mlx90632_get_channel_position()); + + // Read extended measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock_ext1, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock_ext1); + + TEST_ASSERT_EQUAL_INT32(17, mlx90632_get_channel_position()); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock_ext2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock_ext2); + + TEST_ASSERT_EQUAL_INT32(18, mlx90632_get_channel_position()); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock_ext3, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock_ext3); + + TEST_ASSERT_EQUAL_INT32(19, mlx90632_get_channel_position()); +} + +/** Test failure path when getting channel position. + */ +void test_get_channel_position_error(void) +{ + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready + + // Get channel position expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_get_channel_position()); +} + void test_set_meas_type_success(void) { uint16_t reg_ctrl_mock_med = 0xFE0F; From 48fac6a2c200ec2b0c0f5c3f53dad38e6f1a3651 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Thu, 8 Aug 2024 18:44:35 +0100 Subject: [PATCH 5/8] Fix tests --- inc/mlx90632.h | 4 +-- test/TestRead.c | 84 +++++++++++++++++++++++-------------------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/inc/mlx90632.h b/inc/mlx90632.h index 556d572..ef301a1 100644 --- a/inc/mlx90632.h +++ b/inc/mlx90632.h @@ -61,7 +61,7 @@ /* BIT, GENMASK and ARRAY_SIZE macros are imported from kernel */ #ifndef BIT -#define BIT(x)(1UL << (x)) +#define BIT(x)(1U << (x)) #endif #ifndef GENMASK #ifndef BITS_PER_LONG @@ -69,7 +69,7 @@ #define BITS_PER_LONG 64 /**< Define how many bits per long your CPU has */ #endif #define GENMASK(h, l) \ - (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + ((((1U << h) - 1) | (1U << h)) & ~((1U << l) - 1)) #endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) /**< Return number of elements in array */ diff --git a/test/TestRead.c b/test/TestRead.c index 6a4214d..1d3cbff 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -449,8 +449,8 @@ void test_read_temp_raw_ch1_success(void) // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); - TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_mock); - TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_mock); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); } /** Test whole start and read temperature from sensor procedure. @@ -510,8 +510,8 @@ void test_read_temp_raw_ch2_success(void) // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); - TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_mock); - TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_mock); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); } /** Test Error output on whole start and read temperature from sensor procedure. */ @@ -644,8 +644,8 @@ void test_read_object_values_ch1_success(void) // Trigger the read_temp_raw function TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); - TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_mock); - TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_mock); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); } /** Test reading channel 2 object values from sensor. @@ -677,8 +677,8 @@ void test_read_object_values_ch2_success(void) // Trigger the read_temp_raw function TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_object_raw(2, &object_new_raw, &object_old_raw)); - TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_mock); - TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_mock); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); } /** Test error outputs when reading object values. */ @@ -1271,8 +1271,7 @@ void test_read_temp_raw_extended_success(void) void test_read_temp_raw_extended_errors(void) { uint16_t reg_status_mock1 = 0xC5; // cycle position 17 & data ready - uint16_t reg_status_mock2 = 0xC9; // cycle position 18 & data ready - uint16_t reg_status_mock3 = 0xCF; // cycle position 19 & data ready + uint16_t reg_status_mock2 = 0xCF; // cycle position 19 & data ready int16_t ambient_new_mock = 22454; // 1st read returns an error @@ -1283,7 +1282,7 @@ void test_read_temp_raw_extended_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); - // 3 reads are not enough to reach the end of meas + // read_ambient_raw_extended returns an error //Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output @@ -1295,56 +1294,53 @@ void test_read_temp_raw_extended_errors(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); + // Read Ambient raw expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); + mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock2 & (~MLX90632_STAT_DATA_RDY), 0); + TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); +} - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); - mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); +/** Test retries exhaust on whole start and read extended temperature from sensor procedure. + */ +void test_wait_for_measurement_retries_exhaust(void) +{ + uint16_t reg_status_mock = 0xC9; // cycle position 18 & data ready - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); + // 3 reads are not enough to reach the end of meas + //Start measurement expectations + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock2 & (~MLX90632_STAT_DATA_RDY), 0); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock2 & (~MLX90632_STAT_DATA_RDY), 0); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock2, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock2); - - TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - // read_ambient_raw_extended returns an error - //Start measurement expectations - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock3, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock3); - - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock3 & (~MLX90632_STAT_DATA_RDY), 0); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock3, 0); - mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock3); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); - // Read Ambient raw expectations - mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); } /** Test trigger burst measurement. @@ -1880,8 +1876,8 @@ void test_read_temp_raw_burst_success(void) // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); TEST_ASSERT_EQUAL_INT16(ambient_old_mock, ambient_old_raw); - TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_mock); - TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_mock); + TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); + TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); } void test_read_temp_raw_burst_errors(void) From f7e789878ce520a61855f21a00131459ae490d26 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Thu, 8 Aug 2024 20:22:19 +0100 Subject: [PATCH 6/8] Improve tests --- test/TestDSP.c | 2 + test/TestInit.c | 37 +++--- test/TestRead.c | 280 +++++++++++++++++++---------------------- test/TestRefreshRate.c | 44 +++---- 4 files changed, 169 insertions(+), 194 deletions(-) diff --git a/test/TestDSP.c b/test/TestDSP.c index f063c61..e77207e 100644 --- a/test/TestDSP.c +++ b/test/TestDSP.c @@ -159,6 +159,7 @@ void test_dsp_object(void) void test_dsp_object_reflected(void) { TEST_ASSERT_DOUBLE_WITHIN(0.01, dspv5_object_helper(609, 611, 22454, 23030), dspv5_object_reflected_helper(609, 611, 22454, 23030, 48.724)); + mlx90632_set_emissivity(0.1); TEST_ASSERT_DOUBLE_WITHIN(0.01, 98.141, dspv5_object_reflected_helper(609, 611, 22454, 23030, 49.66)); TEST_ASSERT_DOUBLE_WITHIN(0.01, 143.956, dspv5_object_reflected_helper(609, 611, 22454, 23030, 40.00)); @@ -174,6 +175,7 @@ void test_dsp_object_extended(void) TEST_ASSERT_DOUBLE_WITHIN(0.02, 194.599, object_extended_helper(13550, 22454, 23030, 25.0)); TEST_ASSERT_DOUBLE_WITHIN(0.02, 267.609, object_extended_helper(26900, 22454, 23030, 25.0)); TEST_ASSERT_DOUBLE_WITHIN(0.02, 268.508, object_extended_helper(27100, 22454, 23030, 25.0)); + mlx90632_set_emissivity(0.1); TEST_ASSERT_DOUBLE_WITHIN(0.02, 98.141, object_extended_helper(305, 22454, 23030, 49.66)); TEST_ASSERT_DOUBLE_WITHIN(0.02, 143.956, object_extended_helper(305, 22454, 23030, 40.00)); diff --git a/test/TestInit.c b/test/TestInit.c index ec85ad2..c282871 100644 --- a/test/TestInit.c +++ b/test/TestInit.c @@ -47,7 +47,7 @@ void tearDown(void) void test_init_success(void) { uint16_t eeprom_version_mock = 0x105; - uint16_t reg_status_mock = 0x47; // cycle position 1 & data ready + uint16_t reg_status_mock = 0x00C7; // cycle position 17 & data ready // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -62,10 +62,10 @@ void test_init_success(void) // Reset EOC and NewData mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & ~0x01, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_init()); // test also ID_CONSUMER - eeprom_version_mock = 0x205; + eeprom_version_mock = 0x0205; // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -80,10 +80,10 @@ void test_init_success(void) // Reset EOC and NewData mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & ~0x01, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_init()); // test also another calibration id - eeprom_version_mock = 0x305; + eeprom_version_mock = 0x0305; // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -98,10 +98,10 @@ void test_init_success(void) // Reset EOC and NewData mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & ~0x01, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_init()); // test extended range - eeprom_version_mock = 0x505; + eeprom_version_mock = 0x0505; // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -116,34 +116,34 @@ void test_init_success(void) // Reset EOC and NewData mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & ~0x01, 0); - TEST_ASSERT_EQUAL_INT(ERANGE, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(ERANGE, mlx90632_init()); } void test_init_wrong_eeprom_version(void) { - uint16_t eeprom_version_mock = 0x103; + uint16_t eeprom_version_mock = 0x0103; mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(&eeprom_version_mock); - TEST_ASSERT_EQUAL_INT(-EPROTONOSUPPORT, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(-EPROTONOSUPPORT, mlx90632_init()); } void test_init_i2c_read_fails(void) { - uint16_t eeprom_version_mock = 0x103; + uint16_t eeprom_version_mock = 0x0103; mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, -EBUSY); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EBUSY, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(-EBUSY, mlx90632_init()); } void test_init_i2c_read_fails2(void) { - uint16_t eeprom_version_mock = 0x105; - uint16_t reg_status_mock = 0x47; // cycle position 1 & data ready + uint16_t eeprom_version_mock = 0x0105; + uint16_t reg_status_mock = 0x00C7; // cycle position 17 & data ready // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -153,15 +153,14 @@ void test_init_i2c_read_fails2(void) // Read REG_STATUS mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_init()); } void test_init_i2c_read_fails3(void) { - uint16_t eeprom_version_mock = 0x105; - uint16_t reg_status_mock = 0x47; // cycle position 1 & data ready + uint16_t eeprom_version_mock = 0x0105; + uint16_t reg_status_mock = 0x00C7; // cycle position 17 & data ready // Confirm EEPROM version mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_VERSION, &eeprom_version_mock, 0); @@ -177,7 +176,7 @@ void test_init_i2c_read_fails3(void) // Reset NewData mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & ~0x01, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_init()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_init()); } ///@} diff --git a/test/TestRead.c b/test/TestRead.c index 1d3cbff..582c2c5 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -170,7 +170,7 @@ void test_wait_for_measurement_timeout(void) */ void test_start_measurement_success(void) { - uint16_t reg_status_mock = 0x87; // cycle position 1 & data ready + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -193,8 +193,8 @@ void test_start_measurement_success(void) */ void test_start_measurement_one_wait(void) { - uint16_t reg_status_mock = 0x86; // cycle position 1 & data NOT READY - uint16_t reg_status_mock1 = 0x87; // cycle position 1 & data READY + uint16_t reg_status_mock = 0x0C86; // cycle position 1 & data not reaady + uint16_t reg_status_mock1 = 0x0087; // cycle position 1 & data ready // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -217,14 +217,13 @@ void test_start_measurement_one_wait(void) } /** Test different failure paths in start_measurement */ -void test_start_measurement_busy_i2c(void) +void test_start_measurement_errors(void) { - uint16_t reg_status_mock = 0x06; + uint16_t reg_status_mock = 0x0C86; // cycle position 1 & data not reaady // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement()); @@ -258,25 +257,21 @@ void test_start_measurement_busy_i2c(void) */ void test_start_measurement_timeout(void) { - uint16_t reg_status_first_mock = 0x06; - uint16_t reg_status_mock[MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES]; + uint16_t reg_status_mock = 0x0C06; // cycle position 1 & data not ready int i; - for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) - reg_status_mock[i] = 0x0006; // cycle position 1 & data NOT READY through whole array! - // Start measurement expectations - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_first_mock, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_first_mock); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_first_mock & (~MLX90632_STAT_DATA_RDY), 0); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock & (~MLX90632_STAT_DATA_RDY), 0); for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) { - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock[i], 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock[i]); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); usleep_Expect(10000, 11000); } @@ -400,7 +395,7 @@ void test_read_temp_raw_wo_wait_error(void) */ void test_read_temp_raw_ch1_success(void) { - uint16_t reg_status_mock = 0x87; // cycle position 1 & data ready + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready int16_t ambient_new_mock = 22454; int16_t ambient_old_mock = 23030; int16_t object_new_mock = 150; @@ -444,7 +439,7 @@ void test_read_temp_raw_ch1_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -461,7 +456,7 @@ void test_read_temp_raw_ch1_success(void) */ void test_read_temp_raw_ch2_success(void) { - uint16_t reg_status_mock = 0x8b; // cycle position 2 & data ready + uint16_t reg_status_mock = 0x008B; // cycle position 2 & data ready int16_t ambient_new_mock = 22454; int16_t ambient_old_mock = 23030; int16_t object_new_mock = 150; @@ -505,7 +500,7 @@ void test_read_temp_raw_ch2_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -517,13 +512,14 @@ void test_read_temp_raw_ch2_success(void) /** Test Error output on whole start and read temperature from sensor procedure. */ void test_read_temp_raw_errors(void) { - uint16_t reg_status_mock = 0x87; // cycle position 1 & data ready + uint16_t reg_status_mock = 0x0087; // cycle position 1 & data ready int16_t ambient_new_mock = 22454; // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -539,7 +535,8 @@ void test_read_temp_raw_errors(void) // Read Ambient raw expectations (based on above cycle position) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); } /** Test reading channel 1 ambient values from sensor. @@ -561,7 +558,7 @@ void test_read_ambient_values_ch1_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -587,7 +584,7 @@ void test_read_ambient_values_ch2_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -603,7 +600,8 @@ void test_read_ambient_values_errors(void) // First read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); // Second read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, 0); @@ -612,7 +610,8 @@ void test_read_ambient_values_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(2), (uint16_t*)&ambient_old_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_ambient_raw(&ambient_new_raw, &ambient_old_raw)); } /** Test reading channel 1 object values from sensor. @@ -642,7 +641,7 @@ void test_read_object_values_ch1_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); @@ -675,7 +674,7 @@ void test_read_object_values_ch2_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_object_raw(2, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_object_raw(2, &object_new_raw, &object_old_raw)); TEST_ASSERT_EQUAL_INT16(object_new_mock, object_new_raw); TEST_ASSERT_EQUAL_INT16(object_old_mock, object_old_raw); @@ -690,7 +689,8 @@ void test_read_object_values_errors(void) // First read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); // Second read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_new_mock, 0); @@ -699,7 +699,8 @@ void test_read_object_values_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(1), (uint16_t*)&object_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); // Third read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_new_mock, 0); @@ -712,7 +713,8 @@ void test_read_object_values_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(2), (uint16_t*)&object_old_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); // Forth and last read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(1), (uint16_t*)&object_new_mock, 0); @@ -729,14 +731,15 @@ void test_read_object_values_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(2), (uint16_t*)&object_old_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw(1, &object_new_raw, &object_old_raw)); } /** Test error outputs when reading object values. */ void test_read_object_error_ch(void) { // Input retval is invalid - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_read_temp_object_raw(3, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_read_temp_object_raw(3, &object_new_raw, &object_old_raw)); } /** Test reading ambient values from sensor in extended range measurements. @@ -757,7 +760,7 @@ void test_read_ambient_values_extended_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -773,7 +776,8 @@ void test_read_ambient_values_extended_errors(void) // First read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); // Second read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, 0); @@ -782,7 +786,8 @@ void test_read_ambient_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(18), (uint16_t*)&ambient_old_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_ambient_raw_extended(&ambient_new_raw, &ambient_old_raw)); } void test_read_object_values_extended_success(void) @@ -820,7 +825,7 @@ void test_read_object_values_extended_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(287, object_new_raw); @@ -840,9 +845,8 @@ void test_read_object_values_extended_errors(void) // First read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_l1); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // Second read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -851,9 +855,8 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(17), (uint16_t*)&object_mock_b1, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_b1); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // Third read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -866,9 +869,8 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(18), (uint16_t*)&object_mock_b2, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_b2); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // 4th read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -885,9 +887,8 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(18), (uint16_t*)&object_mock_l2, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_l2); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // 5th read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -908,9 +909,8 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(19), (uint16_t*)&object_mock_v1, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v1); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // 6th read fails mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -935,9 +935,8 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_2(19), (uint16_t*)&object_mock_v2, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_object_raw_extended(&object_new_raw)); // Data overflow mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_1(17), (uint16_t*)&object_mock_l1, 0); @@ -965,7 +964,7 @@ void test_read_object_values_extended_errors(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_read_temp_object_raw_extended(&object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_read_temp_object_raw_extended(&object_new_raw)); } /** Test read extended temperature from sensor without waiting procedure. @@ -1059,9 +1058,9 @@ void test_read_temp_raw_extended_wo_wait_errors(void) */ void test_read_temp_raw_extended_success(void) { - uint16_t reg_status_mock1 = 0xC5; // cycle position 17 & data ready - uint16_t reg_status_mock2 = 0xC9; // cycle position 18 & data ready - uint16_t reg_status_mock3 = 0xCF; // cycle position 19 & data ready + uint16_t reg_status_mock1 = 0x00C5; // cycle position 17 & data ready + uint16_t reg_status_mock2 = 0x00C9; // cycle position 18 & data ready + uint16_t reg_status_mock3 = 0x00CF; // cycle position 19 & data ready int16_t ambient_new_mock = 22454; int16_t ambient_old_mock = 23030; int16_t object_mock_l1 = 250; @@ -1118,7 +1117,7 @@ void test_read_temp_raw_extended_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw_extended function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -1182,7 +1181,7 @@ void test_read_temp_raw_extended_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw_extended function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -1256,7 +1255,7 @@ void test_read_temp_raw_extended_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw_extended function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -1270,17 +1269,16 @@ void test_read_temp_raw_extended_success(void) */ void test_read_temp_raw_extended_errors(void) { - uint16_t reg_status_mock1 = 0xC5; // cycle position 17 & data ready - uint16_t reg_status_mock2 = 0xCF; // cycle position 19 & data ready + uint16_t reg_status_mock1 = 0x00C5; // cycle position 17 & data ready + uint16_t reg_status_mock2 = 0x00CF; // cycle position 19 & data ready int16_t ambient_new_mock = 22454; // 1st read returns an error //Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock1, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock1); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // read_ambient_raw_extended returns an error //Start measurement expectations @@ -1297,16 +1295,15 @@ void test_read_temp_raw_extended_errors(void) // Read Ambient raw expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); } /** Test retries exhaust on whole start and read extended temperature from sensor procedure. */ void test_wait_for_measurement_retries_exhaust(void) { - uint16_t reg_status_mock = 0xC9; // cycle position 18 & data ready + uint16_t reg_status_mock = 0x0CC9; // cycle position 18 & data ready // 3 reads are not enough to reach the end of meas //Start measurement expectations @@ -1340,7 +1337,7 @@ void test_wait_for_measurement_retries_exhaust(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-ETIMEDOUT, mlx90632_read_temp_raw_extended(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); } /** Test trigger burst measurement. @@ -1385,7 +1382,7 @@ void test_trigger_measurement_burst_errors(void) */ void test_wait_for_measurement_burst_success(void) { - uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy // Wait for burst measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); @@ -1399,7 +1396,7 @@ void test_wait_for_measurement_burst_success(void) */ void test_wait_for_measurement_burst_error(void) { - uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy // Wait for burst measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); @@ -1436,8 +1433,8 @@ void test_wait_for_measurement_burst_timeout(void) */ void test_start_measurement_burst_success(void) { - uint16_t reg_ctrl_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected - uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy uint16_t meas1_mock = 0x820D; uint16_t meas2_mock = 0x821D; @@ -1466,22 +1463,21 @@ void test_start_measurement_burst_success(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(0, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_start_measurement_burst()); } void test_start_measurement_burst_errors(void) { - uint16_t reg_ctrl_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected - uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_status_mock = 0x000B; // cycle position 2 & data ready & device not busy uint16_t meas1_mock = 0x820D; uint16_t meas2_mock = 0x821D; //mlx90632_reg_ctrl read error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement_burst()); //mlx90632_reg_ctrl write error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); @@ -1490,7 +1486,7 @@ void test_start_measurement_burst_errors(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock | MLX90632_START_BURST_MEAS, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement_burst()); //calculate measurement time error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); @@ -1501,9 +1497,8 @@ void test_start_measurement_burst_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement_burst()); //mlx90632_reg_status read error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); @@ -1528,9 +1523,8 @@ void test_start_measurement_burst_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_start_measurement_burst()); } /** Test sensor timeouts while start_measure. @@ -1541,15 +1535,12 @@ void test_start_measurement_burst_errors(void) */ void test_start_measurement_burst_timeout(void) { - uint16_t reg_ctrl_mock = 0x0002; - uint16_t reg_status_mock[MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES]; + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_status_mock = 0x0C06; // cycle position 1 & device busy uint16_t meas1_mock = 0x820D; uint16_t meas2_mock = 0x821D; int i; - for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) - reg_status_mock[i] = 0x0C06; // cycle position 1 & device busy for all samples! - // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output @@ -1573,14 +1564,14 @@ void test_start_measurement_burst_timeout(void) for (i = 0; i < MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES; ++i) { - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock[i], 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, ®_status_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock[i]); + mlx90632_i2c_read_ReturnThruPtr_value(®_status_mock); usleep_Expect(10000, 11000); } - TEST_ASSERT_EQUAL_INT(-ETIMEDOUT, mlx90632_start_measurement_burst()); + TEST_ASSERT_EQUAL_INT32(-ETIMEDOUT, mlx90632_start_measurement_burst()); } /** Test trigger single measurement. @@ -1662,8 +1653,8 @@ void test_trigger_measurement_single_errors(void) */ void test_read_temp_raw_extended_burst_success(void) { - uint16_t reg_ctrl_mock = 0x0112; // ctrl_reg value extended sleeping step meas selected - uint16_t reg_status_mock = 0x01CF; // cycle position 19 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0112; // extended sleeping step meas selected + uint16_t reg_status_mock = 0x01CF; // cycle position 19 & data ready & device not busy int16_t ambient_new_mock = 22454; int16_t ambient_old_mock = 23030; int16_t object_mock_l1 = 250; @@ -1740,7 +1731,7 @@ void test_read_temp_raw_extended_burst_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_mock_v2); // Trigger the read_temp_raw_extended function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -1755,8 +1746,8 @@ void test_read_temp_raw_extended_burst_success(void) */ void test_read_temp_raw_extended_burst_errors(void) { - uint16_t reg_ctrl_mock = 0x0112; // ctrl_reg value extended sleeping step meas selected - uint16_t reg_status_mock = 0x01CF; // cycle position 19 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0112; // extended sleeping step meas selected + uint16_t reg_status_mock = 0x01CF; // cycle position 19 & data ready & device not busy int16_t ambient_new_mock = 22454; uint16_t meas1_mock = 0x8300; uint16_t meas2_mock = 0x8312; @@ -1766,9 +1757,8 @@ void test_read_temp_raw_extended_burst_errors(void) //Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); // read_ambient_raw_extended returns an error //Start measurement expectations @@ -1803,15 +1793,14 @@ void test_read_temp_raw_extended_burst_errors(void) // Read Ambient raw expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(17), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&ambient_new_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_extended_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw)); } void test_read_temp_raw_burst_success(void) { - uint16_t reg_ctrl_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected - uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device not busy int16_t ambient_new_mock = 22454; int16_t ambient_old_mock = 23030; int16_t object_new_mock = 150; @@ -1871,7 +1860,7 @@ void test_read_temp_raw_burst_success(void) mlx90632_i2c_read_ReturnThruPtr_value((uint16_t*)&object_old_mock); // Trigger the read_temp_raw function - TEST_ASSERT_EQUAL_INT(0, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); // Confirm all values are as expected TEST_ASSERT_EQUAL_INT16(ambient_new_mock, ambient_new_raw); @@ -1882,8 +1871,8 @@ void test_read_temp_raw_burst_success(void) void test_read_temp_raw_burst_errors(void) { - uint16_t reg_ctrl_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected - uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device is not busy + uint16_t reg_ctrl_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_status_mock = 0x010B; // cycle position 2 & data ready & device not busy int16_t ambient_new_mock = 22454; uint16_t meas1_mock = 0x820D; uint16_t meas2_mock = 0x821D; @@ -1892,9 +1881,8 @@ void test_read_temp_raw_burst_errors(void) //Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); // Start measurement expectations mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock, 0); @@ -1924,12 +1912,13 @@ void test_read_temp_raw_burst_errors(void) // Read Ambient raw expectations (based on above cycle position) mlx90632_i2c_read_ExpectAndReturn(MLX90632_RAM_3(1), (uint16_t*)&ambient_new_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); + + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_read_temp_raw_burst(&ambient_new_raw, &ambient_old_raw, &object_new_raw, &object_old_raw)); } void test_calculate_dataset_ready_time_medical_success(void) { - uint16_t reg_ctrl_medb_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected + uint16_t reg_ctrl_medb_mock = 0x0002; // medical sleeping step meas selected uint16_t med_meas1_mock[] = { 0x800D, 0x810D, 0x820D, 0x830D, 0x840D, 0x850D, 0x860D, 0x870D }; uint16_t med_meas2_mock[] = { 0x801D, 0x811D, 0x821D, 0x831D, 0x841D, 0x851D, 0x861D, 0x871D }; int med_waiting_time[] = { 4000, 2000, 1000, 500, 250, 124, 62, 30 }; @@ -1949,13 +1938,13 @@ void test_calculate_dataset_ready_time_medical_success(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(&med_meas2_mock[i]); - TEST_ASSERT_EQUAL_INT(med_waiting_time[i], mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(med_waiting_time[i], mlx90632_calculate_dataset_ready_time()); } } void test_calculate_dataset_ready_time_extended_success(void) { - uint16_t reg_ctrl_extb_mock = 0x0112; // ctrl_reg value extended sleeping step meas selected + uint16_t reg_ctrl_extb_mock = 0x0112; // extended sleeping step meas selected uint16_t ext_meas1_mock[] = { 0x8000, 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700 }; uint16_t ext_meas2_mock[] = { 0x8012, 0x8112, 0x8212, 0x8312, 0x8412, 0x8512, 0x8612, 0x8712 }; uint16_t ext_meas3_mock[] = { 0x800C, 0x810C, 0x820C, 0x830C, 0x840C, 0x850C, 0x860C, 0x870C }; @@ -1980,30 +1969,29 @@ void test_calculate_dataset_ready_time_extended_success(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(&ext_meas3_mock[i]); - TEST_ASSERT_EQUAL_INT(ext_waiting_time[i], mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(ext_waiting_time[i], mlx90632_calculate_dataset_ready_time()); } } void test_calculate_dataset_ready_time_medical_errors(void) { - uint16_t reg_ctrl_medb_mock = 0x0002; // ctrl_reg value medical sleeping step meas selected - uint16_t reg_ctrl_med_mock = 0x0006; // ctrl_reg value medical continuous meas selected + uint16_t reg_ctrl_medb_mock = 0x0002; // medical sleeping step meas selected + uint16_t reg_ctrl_med_mock = 0x0006; // medical continuous meas selected uint16_t med_meas1_mock = 0x820D; uint16_t med_meas2_mock = 0x821D; //get_meas_type error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_medb_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_medb_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); //invalid meas type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_med_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_med_mock); - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_calculate_dataset_ready_time()); //medical meas 1 error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_medb_mock, 0); @@ -2012,9 +2000,8 @@ void test_calculate_dataset_ready_time_medical_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_MEDICAL_MEAS1, &med_meas1_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(&med_meas1_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); //medical meas 2 error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_medb_mock, 0); @@ -2027,15 +2014,14 @@ void test_calculate_dataset_ready_time_medical_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_MEDICAL_MEAS2, &med_meas2_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(&med_meas2_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); } void test_calculate_dataset_ready_time_extended_errors(void) { - uint16_t reg_ctrl_extb_mock = 0x0112; // ctrl_reg value extended sleeping step meas selected - uint16_t reg_ctrl_ext_mock = 0x0116; // ctrl_reg value extended continuous meas selected + uint16_t reg_ctrl_extb_mock = 0x0112; // extended sleeping step meas selected + uint16_t reg_ctrl_ext_mock = 0x0116; // extended continuous meas selected uint16_t ext_meas1_mock = 0x8200; uint16_t ext_meas2_mock = 0x8212; uint16_t ext_meas3_mock = 0x820C; @@ -2043,16 +2029,15 @@ void test_calculate_dataset_ready_time_extended_errors(void) //get_meas_type error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_extb_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_extb_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); //invalid meas type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_ext_mock, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_ext_mock); - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_calculate_dataset_ready_time()); //extended meas 1 error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_extb_mock, 0); @@ -2061,9 +2046,8 @@ void test_calculate_dataset_ready_time_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_EXTENDED_MEAS1, &ext_meas1_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(&ext_meas1_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); //extended meas 2 error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_extb_mock, 0); @@ -2076,9 +2060,8 @@ void test_calculate_dataset_ready_time_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_EXTENDED_MEAS2, &ext_meas2_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(&ext_meas2_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); //extended meas 3 error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_extb_mock, 0); @@ -2095,9 +2078,8 @@ void test_calculate_dataset_ready_time_extended_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_EXTENDED_MEAS3, &ext_meas3_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(&ext_meas3_mock); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_calculate_dataset_ready_time()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_calculate_dataset_ready_time()); } /** Test get channel position. @@ -2191,7 +2173,7 @@ void test_set_meas_type_success(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Switch from extended to medical measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext, 0); @@ -2217,7 +2199,7 @@ void test_set_meas_type_success(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL)); // Switch from medical to sleeping step medical measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2243,7 +2225,7 @@ void test_set_meas_type_success(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med2, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL_BURST)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL_BURST)); // Switch from medical sleeping step to extended sleeping step measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med2, 0); @@ -2269,7 +2251,7 @@ void test_set_meas_type_success(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext2, 0); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED_BURST)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED_BURST)); } void test_set_meas_type_errors(void) @@ -2279,14 +2261,13 @@ void test_set_meas_type_errors(void) uint16_t reg_ctrl_mock_step = 0xFE0D; // Invalid input parameter - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_set_meas_type(9)); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_set_meas_type(9)); // Addressed reset read current reg value error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Addressed reset write step value error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2295,7 +2276,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Addressed reset command error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2306,7 +2287,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Addressed reset restore value error mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2320,7 +2301,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // First read fail mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2336,9 +2317,8 @@ void test_set_meas_type_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // First write fail mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2358,7 +2338,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext1, -EPERM); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Second read fail mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); @@ -2380,9 +2360,8 @@ void test_set_meas_type_errors(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext1, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_ext1); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); } void test_get_meas_type_success(void) @@ -2397,28 +2376,28 @@ void test_get_meas_type_success(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); - TEST_ASSERT_EQUAL_INT(MLX90632_MTYP_MEDICAL, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(MLX90632_MTYP_MEDICAL, mlx90632_get_meas_type()); // Read extended measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_ext); - TEST_ASSERT_EQUAL_INT(MLX90632_MTYP_EXTENDED, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(MLX90632_MTYP_EXTENDED, mlx90632_get_meas_type()); // Read medical sleeping step measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med_burst, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med_burst); - TEST_ASSERT_EQUAL_INT(MLX90632_MTYP_MEDICAL_BURST, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(MLX90632_MTYP_MEDICAL_BURST, mlx90632_get_meas_type()); // Read extended measurement type mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext_burst, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_ext_burst); - TEST_ASSERT_EQUAL_INT(MLX90632_MTYP_EXTENDED_BURST, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(MLX90632_MTYP_EXTENDED_BURST, mlx90632_get_meas_type()); } void test_get_meas_type_errors(void) @@ -2429,23 +2408,22 @@ void test_get_meas_type_errors(void) // Error reading the register mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_inval, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_inval); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_get_meas_type()); // Invalid measurement type data (measurement type) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_inval, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_inval); - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_get_meas_type()); // Invalid measurement type data (operating mode) mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_inval1, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_inval1); - TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_get_meas_type()); + TEST_ASSERT_EQUAL_INT32(-EINVAL, mlx90632_get_meas_type()); } ///@} diff --git a/test/TestRefreshRate.c b/test/TestRefreshRate.c index 52466ac..c1b6f6c 100644 --- a/test/TestRefreshRate.c +++ b/test/TestRefreshRate.c @@ -118,7 +118,7 @@ void assert_set_refresh_rate(mlx90632_meas_t meas, uint16_t reg_meas1, uint16_t expect_write_meas2_success(reg_meas2); expect_read_status_success_eeprom_not_busy(); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_refresh_rate(meas)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_refresh_rate(meas)); } void test_set_refresh_rate_success(void) @@ -141,7 +141,6 @@ void expect_read_meas1_error() mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_MEDICAL_MEAS1, ®_meas1_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_meas1_mock); } void expect_unlockEEPROM_error() @@ -158,14 +157,13 @@ void expect_read_status_error(uint16_t* reg_status_mock) { mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_STATUS, reg_status_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(reg_status_mock); } void test_set_refresh_rate_error_first_read_fails(void) { expect_read_meas1_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_unlock_erase_fails(void) @@ -173,7 +171,7 @@ void test_set_refresh_rate_error_first_unlock_erase_fails(void) expect_read_meas1_success(); expect_unlockEEPROM_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_erase_fails(void) @@ -182,7 +180,7 @@ void test_set_refresh_rate_error_first_erase_fails(void) expect_unlock_eeprom_success(); expect_write_meas1_error(0x00); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_read_erase_status_fails(void) @@ -194,7 +192,7 @@ void test_set_refresh_rate_error_first_read_erase_status_fails(void) expect_write_meas1_success(0x00); expect_read_status_error(&error); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_unlock_write_fails(void) @@ -205,7 +203,7 @@ void test_set_refresh_rate_error_first_unlock_write_fails(void) expect_read_status_success_eeprom_not_busy(); expect_unlockEEPROM_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_write_fails(void) @@ -217,7 +215,7 @@ void test_set_refresh_rate_error_first_write_fails(void) expect_unlock_eeprom_success(); expect_write_meas1_error(0x870D); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_first_read_write_status_fails(void) @@ -232,7 +230,7 @@ void test_set_refresh_rate_error_first_read_write_status_fails(void) expect_write_meas1_success(0x870D); expect_read_status_error(&error); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void expect_read_meas2_error() @@ -241,7 +239,6 @@ void expect_read_meas2_error() mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_MEDICAL_MEAS2, ®_meas2_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_meas2_mock); } void expect_write_meas2_error(uint16_t data) @@ -261,7 +258,7 @@ void test_set_refresh_rate_error_second_read_fails(void) expect_read_meas2_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_unlock_erase_fails(void) @@ -277,7 +274,7 @@ void test_set_refresh_rate_error_second_unlock_erase_fails(void) expect_read_meas2_success(); expect_unlockEEPROM_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_erase_fails(void) @@ -294,7 +291,7 @@ void test_set_refresh_rate_error_second_erase_fails(void) expect_unlock_eeprom_success(); expect_write_meas2_error(0x00); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_read_erase_status_fails(void) @@ -314,7 +311,7 @@ void test_set_refresh_rate_error_second_read_erase_status_fails(void) expect_write_meas2_success(0x00); expect_read_status_error(&error); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_unlock_write_fails(void) @@ -333,7 +330,7 @@ void test_set_refresh_rate_error_second_unlock_write_fails(void) expect_read_status_success_eeprom_not_busy(); expect_unlockEEPROM_error(); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_write_fails(void) @@ -353,7 +350,7 @@ void test_set_refresh_rate_error_second_write_fails(void) expect_unlock_eeprom_success(); expect_write_meas2_error(0x871D); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_error_second_read_write_status_fails(void) @@ -376,7 +373,7 @@ void test_set_refresh_rate_error_second_read_write_status_fails(void) expect_write_meas2_success(0x871D); expect_read_status_error(&error); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void assert_get_refresh_rate(mlx90632_meas_t meas, uint16_t reg_meas1_mock) @@ -385,7 +382,7 @@ void assert_get_refresh_rate(mlx90632_meas_t meas, uint16_t reg_meas1_mock) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_meas1_mock); - TEST_ASSERT_EQUAL_INT(meas, mlx90632_get_refresh_rate()); + TEST_ASSERT_EQUAL_INT32(meas, mlx90632_get_refresh_rate()); } void test_get_refresh_rate(void) @@ -406,9 +403,8 @@ void test_get_refresh_rate_error(void) mlx90632_i2c_read_ExpectAndReturn(MLX90632_EE_MEDICAL_MEAS1, ®_meas1_mock, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_meas1_mock); - TEST_ASSERT_EQUAL_INT(MLX90632_MEAS_HZ_ERROR, mlx90632_get_refresh_rate()); + TEST_ASSERT_EQUAL_INT32(MLX90632_MEAS_HZ_ERROR, mlx90632_get_refresh_rate()); } void test_set_refresh_rate_success_status_busy_error(void) @@ -421,7 +417,7 @@ void test_set_refresh_rate_success_status_busy_error(void) expect_read_status_success_eepromBusy(); expect_read_status_error(&error); - TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); + TEST_ASSERT_EQUAL_INT32(-EPERM, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_64)); } void test_set_refresh_rate_same_as_old_meas1_doesnt_write_meas1(void) @@ -437,7 +433,7 @@ void test_set_refresh_rate_same_as_old_meas1_doesnt_write_meas1(void) expect_write_meas2_success(0x801D); expect_read_status_success_eeprom_not_busy(); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_HALF)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_HALF)); } void test_set_refresh_rate_same_as_old_meas2_doesnt_write_meas1(void) @@ -453,7 +449,7 @@ void test_set_refresh_rate_same_as_old_meas2_doesnt_write_meas1(void) reg_meas2_mock = 0x801D; expect_read_meas2_success(); - TEST_ASSERT_EQUAL_INT(0, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_HALF)); + TEST_ASSERT_EQUAL_INT32(0, mlx90632_set_refresh_rate(MLX90632_MEAS_HZ_HALF)); } ///@} \ No newline at end of file From 4d930cc7980a3b2e2d35c29de660ca215561bb41 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Fri, 9 Aug 2024 11:44:16 +0100 Subject: [PATCH 7/8] Run uncrustify --- inc/mlx90632.h | 6 +++--- src/mlx90632.c | 4 ++++ src/mlx90632_extended_meas.c | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inc/mlx90632.h b/inc/mlx90632.h index ef301a1..64c0461 100644 --- a/inc/mlx90632.h +++ b/inc/mlx90632.h @@ -69,7 +69,7 @@ #define BITS_PER_LONG 64 /**< Define how many bits per long your CPU has */ #endif #define GENMASK(h, l) \ - ((((1U << h) - 1) | (1U << h)) & ~((1U << l) - 1)) + ((((1U << h) - 1) | (1U << h)) & ~((1U << l) - 1)) #endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) /**< Return number of elements in array */ @@ -210,7 +210,7 @@ typedef enum mlx90632_meas_e { * Masks the old register and shifts the new value in */ #define MLX90632_NEW_REG_VALUE(old_reg, new_value, h, l) \ - ((old_reg & (0xFFFF ^ GENMASK(h, l))) | (new_value << MLX90632_EE_REFRESH_RATE_SHIFT)) + ((old_reg & (0xFFFF ^ GENMASK(h, l))) | (new_value << MLX90632_EE_REFRESH_RATE_SHIFT)) /** Read raw ambient and object temperature only when measurement data is ready * @@ -480,7 +480,7 @@ int32_t mlx90632_trigger_measurement_burst(void); * * @retval <0 Something failed. Check errno.h for more information * @retval 0 New data is available and waiting to be processed - * + * * @note This function is using usleep so it is blocking! */ int32_t mlx90632_wait_for_measurement_burst(void); diff --git a/src/mlx90632.c b/src/mlx90632.c index 2b51603..65433c8 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -90,6 +90,7 @@ int32_t mlx90632_wait_for_measurement(void) int32_t mlx90632_start_measurement(void) { int32_t ret = mlx90632_trigger_measurement(); + if (ret < 0) return ret; @@ -225,6 +226,7 @@ int32_t mlx90632_read_temp_raw_wo_wait(int32_t channel_position, { /** Read new and old **ambient** values from sensor */ int32_t ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw); + if (ret < 0) return ret; @@ -239,6 +241,7 @@ int32_t mlx90632_read_temp_raw(int16_t *ambient_new_raw, int16_t *ambient_old_ra { // trigger and wait for measurement to complete int32_t start_measurement_ret = mlx90632_start_measurement(); + if (start_measurement_ret < 0) return start_measurement_ret; @@ -637,6 +640,7 @@ int32_t mlx90632_wait_for_measurement_burst(void) int32_t mlx90632_start_measurement_burst(void) { int32_t ret = mlx90632_trigger_measurement_burst(); + if (ret < 0) return ret; diff --git a/src/mlx90632_extended_meas.c b/src/mlx90632_extended_meas.c index 6a05b6f..9a6319c 100644 --- a/src/mlx90632_extended_meas.c +++ b/src/mlx90632_extended_meas.c @@ -134,6 +134,7 @@ int32_t mlx90632_read_temp_raw_extended_wo_wait(int16_t *ambient_new_raw, int16_ { /** Read new and old **ambient** values from sensor */ int32_t ret = mlx90632_read_temp_ambient_raw_extended(ambient_new_raw, ambient_old_raw); + if (ret < 0) return ret; @@ -173,6 +174,7 @@ int32_t mlx90632_read_temp_raw_extended_burst(int16_t *ambient_new_raw, int16_t { // trigger and wait for measurement to complete int32_t start_measurement_ret = mlx90632_start_measurement_burst(); + if (start_measurement_ret < 0) return start_measurement_ret; From 585109eb2057ad1c6aaf150ae48107bd34a76b75 Mon Sep 17 00:00:00 2001 From: Adnan Ashraf Date: Fri, 9 Aug 2024 13:15:49 +0100 Subject: [PATCH 8/8] Update stylechecker to use latest version of uncrustify --- .github/workflows/stylechecker.yml | 2 +- tools/uncrustify.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stylechecker.yml b/.github/workflows/stylechecker.yml index 25eb4ed..fbd7383 100644 --- a/.github/workflows/stylechecker.yml +++ b/.github/workflows/stylechecker.yml @@ -16,7 +16,7 @@ jobs: - name: Install recent uncrustify run: | # we need this because of a bug introduced in https://github.com/uncrustify/uncrustify/pull/3655 - git clone https://github.com/uncrustify/uncrustify.git --branch uncrustify-0.75.1 + git clone https://github.com/uncrustify/uncrustify.git --branch uncrustify-0.79.0 cd uncrustify && mkdir build && cd build cmake .. && sudo make install && cd ../.. - name: Run uncrustify diff --git a/tools/uncrustify.cfg b/tools/uncrustify.cfg index 95de9cc..9f48e1a 100644 --- a/tools/uncrustify.cfg +++ b/tools/uncrustify.cfg @@ -20,7 +20,7 @@ nl_for_brace = add # "for () {" vs "for () \n {" nl_else_brace = add # "else {" vs "else \n {" nl_while_brace = add # "while () {" vs "while () \n {" nl_switch_brace = add # "switch () {" vs "switch () \n {" -nl_func_var_def_blk = 1 +nl_var_def_blk_end_func_top = 1 nl_before_case = 1 nl_fcall_brace = add # "foo() {" vs "foo()\n{" nl_fdef_brace = add # "int foo() {" vs "int foo()\n{"