Просмотр исходного кода

Added bmi160_get_power_mode API
In the bmi160_init API, dereferenced dev struct only after null pointer check.

Bosch Sensortec 8 лет назад
Родитель
Сommit
41bed07d96
5 измененных файлов с 116 добавлено и 14 удалено
  1. 3 3
      README.md
  2. 27 6
      bmi160.c
  3. 28 2
      bmi160.h
  4. 51 3
      bmi160_defs.h
  5. 7 0
      changelog.md

+ 3 - 3
README.md

@@ -7,9 +7,9 @@ The sensor driver package includes bmi160.h, bmi160.c and bmi160_defs.h files
 ## Version
 ## Version
 File          | Version | Date
 File          | Version | Date
 --------------|---------|---------------
 --------------|---------|---------------
-bmi160.c      |   3.7.4 |   24 Nov 2017
-bmi160.h      |   3.7.4 |   24 Nov 2017
-bmi160_defs.h |   3.7.4 |   24 Nov 2017
+bmi160.c      |   3.7.5 |   11 Jan 2018
+bmi160.h      |   3.7.5 |   11 Jan 2018
+bmi160_defs.h |   3.7.5 |   11 Jan 2018
 
 
 ## Integration details
 ## Integration details
 * Integrate bmi160.h, bmi160_defs.h and bmi160.c file in to your project.
 * Integrate bmi160.h, bmi160_defs.h and bmi160.c file in to your project.

+ 27 - 6
bmi160.c

@@ -40,8 +40,8 @@
  * patent rights of the copyright holder.
  * patent rights of the copyright holder.
  *
  *
  * @file    bmi160.c
  * @file    bmi160.c
- * @date    24 Nov 2017
- * @version 3.7.4
+ * @date    11 Jan 2018
+ * @version 3.7.5
  * @brief
  * @brief
  *
  *
  */
  */
@@ -1425,9 +1425,6 @@ int8_t bmi160_init(struct bmi160_dev *dev)
 	uint8_t data;
 	uint8_t data;
 	uint8_t try = 3;
 	uint8_t try = 3;
 
 
-	/* Assign chip id as zero */
-	dev->chip_id = 0;
-
 	/* Null-pointer check */
 	/* Null-pointer check */
 	rslt = null_ptr_check(dev);
 	rslt = null_ptr_check(dev);
 
 
@@ -1437,6 +1434,8 @@ int8_t bmi160_init(struct bmi160_dev *dev)
 		rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev);
 		rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev);
 
 
 	if (rslt == BMI160_OK) {
 	if (rslt == BMI160_OK) {
+		/* Assign chip id as zero */
+		dev->chip_id = 0;
 
 
 		while ((try--) && (dev->chip_id != BMI160_CHIP_ID)) {
 		while ((try--) && (dev->chip_id != BMI160_CHIP_ID)) {
 			/* Read chip_id */
 			/* Read chip_id */
@@ -1529,7 +1528,30 @@ int8_t bmi160_set_power_mode(struct bmi160_dev *dev)
 	}
 	}
 
 
 	return rslt;
 	return rslt;
+}
 
 
+/*!
+ * @brief This API gets the power mode of the sensor.
+ */
+int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct bmi160_dev *dev)
+{
+	int8_t rslt = 0;
+	uint8_t power_mode = 0;
+
+	/* Null-pointer check */
+	if ((dev == NULL) || (dev->delay_ms == NULL)) {
+		rslt = BMI160_E_NULL_PTR;
+	} else {
+		rslt = bmi160_get_regs(BMI160_PMU_STATUS_ADDR, &power_mode, 1, dev);
+		if (rslt == BMI160_OK) {
+			/* Power mode of the accel,gyro,aux sensor is obtained */
+			pmu_status->aux_pmu_status = BMI160_GET_BITS_POS_0(power_mode, BMI160_MAG_POWER_MODE);
+			pmu_status->gyro_pmu_status = BMI160_GET_BITS(power_mode, BMI160_GYRO_POWER_MODE);
+			pmu_status->accel_pmu_status = BMI160_GET_BITS(power_mode, BMI160_ACCEL_POWER_MODE);
+		}
+	}
+
+	return rslt;
 }
 }
 
 
 /*!
 /*!
@@ -1584,7 +1606,6 @@ int8_t bmi160_get_sensor_data(uint8_t select_sensor, struct bmi160_sensor_data *
 	}
 	}
 
 
 	return rslt;
 	return rslt;
-
 }
 }
 
 
 /*!
 /*!

+ 28 - 2
bmi160.h

@@ -40,8 +40,8 @@
  * patent rights of the copyright holder.
  * patent rights of the copyright holder.
  *
  *
  * @file    bmi160.h
  * @file    bmi160.h
- * @date    24 Nov 2017
- * @version 3.7.4
+ * @date    11 Jan 2018
+ * @version 3.7.5
  * @brief
  * @brief
  *
  *
  */
  */
@@ -146,6 +146,32 @@ int8_t bmi160_set_sens_conf(struct bmi160_dev *dev);
  */
  */
 int8_t bmi160_set_power_mode(struct bmi160_dev *dev);
 int8_t bmi160_set_power_mode(struct bmi160_dev *dev);
 
 
+/*!
+ * @brief This API gets the power mode of the sensor.
+ *
+ * @param[in] power_mode  : Power mode of the sensor
+ * @param[in] dev         : Structure instance of bmi160_dev
+ *
+ * power_mode Macros possible values for pmu_status->aux_pmu_status :
+ *  - BMI160_AUX_PMU_SUSPEND
+ *  - BMI160_AUX_PMU_NORMAL
+ *  - BMI160_AUX_PMU_LOW_POWER
+ *
+ * power_mode Macros possible values for pmu_status->gyro_pmu_status :
+ *  - BMI160_GYRO_PMU_SUSPEND
+ *  - BMI160_GYRO_PMU_NORMAL
+ *  - BMI160_GYRO_PMU_FSU
+ *
+ * power_mode Macros possible values for pmu_status->accel_pmu_status :
+ *  - BMI160_ACCEL_PMU_SUSPEND
+ *  - BMI160_ACCEL_PMU_NORMAL
+ *  - BMI160_ACCEL_PMU_LOW_POWER
+ *
+ * @return Result of API execution status
+ * @retval zero -> Success / -ve value -> Error.
+ */
+int8_t bmi160_get_power_mode(struct bmi160_pmu_status *pmu_status, const struct bmi160_dev *dev);
+
 /*!
 /*!
  * @brief This API reads sensor data, stores it in
  * @brief This API reads sensor data, stores it in
  * the bmi160_sensor_data structure pointer passed by the user.
  * the bmi160_sensor_data structure pointer passed by the user.

+ 51 - 3
bmi160_defs.h

@@ -40,8 +40,8 @@
  * patent rights of the copyright holder.
  * patent rights of the copyright holder.
  *
  *
  * @file    bmi160_defs.h
  * @file    bmi160_defs.h
- * @date    24 Nov 2017
- * @version 3.7.4
+ * @date    11 Jan 2018
+ * @version 3.7.5
  * @brief
  * @brief
  *
  *
  */
  */
@@ -138,6 +138,19 @@
 #define BMI160_FLAT_INT_EN_MASK                 UINT8_C(0x80)
 #define BMI160_FLAT_INT_EN_MASK                 UINT8_C(0x80)
 #define BMI160_DATA_RDY_INT_EN_MASK             UINT8_C(0x10)
 #define BMI160_DATA_RDY_INT_EN_MASK             UINT8_C(0x10)
 
 
+/** PMU status Macros */
+#define BMI160_AUX_PMU_SUSPEND         UINT8_C(0x00)
+#define BMI160_AUX_PMU_NORMAL          UINT8_C(0x01)
+#define BMI160_AUX_PMU_LOW_POWER       UINT8_C(0x02)
+
+#define BMI160_GYRO_PMU_SUSPEND        UINT8_C(0x00)
+#define BMI160_GYRO_PMU_NORMAL         UINT8_C(0x01)
+#define BMI160_GYRO_PMU_FSU            UINT8_C(0x03)
+
+#define BMI160_ACCEL_PMU_SUSPEND       UINT8_C(0x00)
+#define BMI160_ACCEL_PMU_NORMAL        UINT8_C(0x01)
+#define BMI160_ACCEL_PMU_LOW_POWER     UINT8_C(0x02)
+
 /** Mask definitions for INT_OUT_CTRL register */
 /** Mask definitions for INT_OUT_CTRL register */
 #define BMI160_INT1_EDGE_CTRL_MASK              UINT8_C(0x01)
 #define BMI160_INT1_EDGE_CTRL_MASK              UINT8_C(0x01)
 #define BMI160_INT1_OUTPUT_MODE_MASK            UINT8_C(0x04)
 #define BMI160_INT1_OUTPUT_MODE_MASK            UINT8_C(0x04)
@@ -266,6 +279,7 @@
 /** BMI160 Register map */
 /** BMI160 Register map */
 #define BMI160_CHIP_ID_ADDR		UINT8_C(0x00)
 #define BMI160_CHIP_ID_ADDR		UINT8_C(0x00)
 #define BMI160_ERROR_REG_ADDR		UINT8_C(0x02)
 #define BMI160_ERROR_REG_ADDR		UINT8_C(0x02)
+#define BMI160_PMU_STATUS_ADDR		UINT8_C(0x03)
 #define BMI160_AUX_DATA_ADDR		UINT8_C(0x04)
 #define BMI160_AUX_DATA_ADDR		UINT8_C(0x04)
 #define BMI160_GYRO_DATA_ADDR		UINT8_C(0x0C)
 #define BMI160_GYRO_DATA_ADDR		UINT8_C(0x0C)
 #define BMI160_ACCEL_DATA_ADDR		UINT8_C(0x12)
 #define BMI160_ACCEL_DATA_ADDR		UINT8_C(0x12)
@@ -656,7 +670,6 @@
 #define BMI160_ACCEL_OFFSET_EN_POS	UINT8_C(6)
 #define BMI160_ACCEL_OFFSET_EN_POS	UINT8_C(6)
 #define BMI160_ACCEL_OFFSET_EN_MSK	UINT8_C(0x40)
 #define BMI160_ACCEL_OFFSET_EN_MSK	UINT8_C(0x40)
 
 
-
 #define BMI160_GYRO_OFFSET_POS	        UINT16_C(8)
 #define BMI160_GYRO_OFFSET_POS	        UINT16_C(8)
 #define BMI160_GYRO_OFFSET_MSK	        UINT16_C(0x0300)
 #define BMI160_GYRO_OFFSET_MSK	        UINT16_C(0x0300)
 
 
@@ -666,6 +679,15 @@
 #define BMI160_NVM_STATUS_POS	        UINT8_C(4)
 #define BMI160_NVM_STATUS_POS	        UINT8_C(4)
 #define BMI160_NVM_STATUS_MSK	        UINT8_C(0x10)
 #define BMI160_NVM_STATUS_MSK	        UINT8_C(0x10)
 
 
+#define BMI160_MAG_POWER_MODE_MSK       UINT8_C(0x03)
+
+#define BMI160_ACCEL_POWER_MODE_MSK     UINT8_C(0x30)
+#define BMI160_ACCEL_POWER_MODE_POS     UINT8_C(4)
+
+#define BMI160_GYRO_POWER_MODE_MSK      UINT8_C(0x0C)
+#define BMI160_GYRO_POWER_MODE_POS      UINT8_C(2)
+
+
 /* BIT SLICE GET AND SET FUNCTIONS */
 /* BIT SLICE GET AND SET FUNCTIONS */
 #define	BMI160_GET_BITS(regvar, bitname)\
 #define	BMI160_GET_BITS(regvar, bitname)\
 		((regvar & bitname##_MSK) >> bitname##_POS)
 		((regvar & bitname##_MSK) >> bitname##_POS)
@@ -694,6 +716,32 @@ typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
 typedef void (*bmi160_delay_fptr_t)(uint32_t period);
 typedef void (*bmi160_delay_fptr_t)(uint32_t period);
 
 
 /*************************** Data structures *********************************/
 /*************************** Data structures *********************************/
+
+struct bmi160_pmu_status {
+	/*! Power mode status of Accel
+	 * Possible values :
+	 *  - BMI160_ACCEL_PMU_SUSPEND
+	 *  - BMI160_ACCEL_PMU_NORMAL
+	 *  - BMI160_ACCEL_PMU_LOW_POWER
+	 */
+	uint8_t accel_pmu_status;
+	/*! Power mode status of Gyro
+	 * Possible values :
+	 *  - BMI160_GYRO_PMU_SUSPEND
+	 *  - BMI160_GYRO_PMU_NORMAL
+	 *  - BMI160_GYRO_PMU_FSU
+	 */
+	uint8_t gyro_pmu_status;
+	/*! Power mode status of 'Auxiliary sensor interface' whereas the actual
+	 *  power mode of the aux. sensor should be configured
+	 *  according to the connected sensor specifications
+	 * Possible values :
+	 *  - BMI160_AUX_PMU_SUSPEND
+	 *  - BMI160_AUX_PMU_NORMAL
+	 *  - BMI160_AUX_PMU_LOW_POWER
+	 */
+	uint8_t aux_pmu_status;
+};
 /*!
 /*!
  * @brief bmi160 interrupt status selection enum.
  * @brief bmi160 interrupt status selection enum.
  */
  */

+ 7 - 0
changelog.md

@@ -1,6 +1,13 @@
 # Change Log
 # Change Log
 All notable changes to bmi160 Sensor API will be documented in this file.
 All notable changes to bmi160 Sensor API will be documented in this file.
 
 
+## v3.7.5, 11 Jan 2018
+#### Added
+	- "bmi160_get_power_mode" API added
+#### Changed
+	- bmi160_init function github comment fixed
+
+
 ## v3.7.4, 24 Nov 2017
 ## v3.7.4, 24 Nov 2017
 #### Added
 #### Added
 	- Linux compatibility issue fixed
 	- Linux compatibility issue fixed