You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/07/25 22:21:46 UTC

[GitHub] wes3 closed pull request #1293: checking device initialization register for init completed

wes3 closed pull request #1293: checking device initialization register for init completed
URL: https://github.com/apache/mynewt-core/pull/1293
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/bq27z561/include/bq27z561/bq27z561.h b/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
index 82a4072600..6d4b27cb83 100644
--- a/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
+++ b/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
@@ -179,6 +179,9 @@ struct bq27z561
 
     /* Interface */
     struct bq27z561_itf bq27_itf;
+
+    /* Device initialization complete flag */
+    uint8_t bq27_initialized;
 };
 
 /**
@@ -349,6 +352,14 @@ int bq27z561_set_voltage_hi_set_threshold(struct bq27z561 *dev,
 int bq27z561_set_voltage_hi_clr_threshold(struct bq27z561 *dev,
         uint16_t voltage);
 
+/**
+ * Check if bq27z561 is initialized and sets bq27z561 initialized flag
+ * @param dev pointer to device
+ * @param initialized device initialized flag
+ * @return int 0: success, -1 error
+ */
+int
+bq27z561_get_init_status(struct bq27z561 *dev, uint8_t *initialized);
 /**
  * bq27z561 get batt status
  *
diff --git a/hw/drivers/bq27z561/src/bq27z561.c b/hw/drivers/bq27z561/src/bq27z561.c
index 860bd0b02d..539a4a3736 100644
--- a/hw/drivers/bq27z561/src/bq27z561.c
+++ b/hw/drivers/bq27z561/src/bq27z561.c
@@ -540,6 +540,24 @@ bq27z561_get_chip_id(struct bq27z561 *dev, uint8_t *chip_id)
 }
 #endif
 
+/* Check if bq27z561 is initialized and sets bq27z561 initialized flag */
+int
+bq27z561_get_init_status(struct bq27z561 *dev, uint8_t *init_flag)
+{
+    int rc;
+    uint16_t init;
+    rc = bq27z561_rd_std_reg_word(dev, BQ27Z561_REG_FLAGS, &init);
+    if (init & BQ27Z561_BATTERY_STATUS_INIT)
+    {
+    	    *init_flag = 1;
+    }
+    else
+    {
+	    *init_flag = 0;
+    }
+    return rc;
+}
+
 /* XXX: no support for control register yet */
 
 int
@@ -918,6 +936,20 @@ bq27z561_battery_property_get(struct battery_driver *driver,
                           struct battery_property *property, uint32_t timeout)
 {
     int rc = 0;
+    struct bq27z561 * bq_dev;
+    bq_dev = (struct bq27z561 *)&driver->dev;
+
+    if (!bq_dev->bq27_initialized)
+    {
+        rc = bq27z561_get_init_status((struct bq27z561 *) driver->bd_driver_data,
+                                          &bq_dev->bq27_initialized);
+        if (!bq_dev->bq27_initialized)
+        {
+            rc = -2;
+            property->bp_valid = 0;
+            return rc;
+        }
+    }
 
     battery_property_value_t val;
     if (property->bp_type == BATTERY_PROP_VOLTAGE_NOW &&
@@ -1145,6 +1177,9 @@ bq27z561_init(struct os_dev *dev, void *arg)
     OS_DEV_SETHANDLERS(dev, bq27z561_open, bq27z561_close);
 
     bq27 = (struct bq27z561 *)dev;
+
+    bq27->bq27_initialized = 0;
+
     /* Copy the interface struct */
     bq27->bq27_itf = init_arg->itf;
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services