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 2019/01/09 12:15:08 UTC

[GitHub] mkiiskila closed pull request #1590: Adding Flash Write Functionality

mkiiskila closed pull request #1590: Adding Flash Write Functionality
URL: https://github.com/apache/mynewt-core/pull/1590
 
 
   

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 ae8ae6b103..27ce4f9c75 100644
--- a/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
+++ b/hw/drivers/bq27z561/include/bq27z561/bq27z561.h
@@ -562,6 +562,40 @@ bq27z561_err_t bq27x561_rd_alt_mfg_cmd(struct bq27z561 *dev, uint16_t cmd,
 
 bq27z561_err_t bq27x561_wr_alt_mfg_cmd(struct bq27z561 *dev, uint16_t cmd,
                                        uint8_t *buf, int len);
+
+
+
+/**
+ * bq27z561 write flash
+ *
+ * @param dev pointer to device
+ * @param Address location
+ * @param The buffer of data to be written
+ * @param The length of data to be written
+ *
+ * @return int 0: success, -1 error
+ */
+bq27z561_err_t bq27z561_wr_flash(struct bq27z561 *dev, uint16_t addr, 
+                                 uint8_t *buf, int buflen);
+
+/**
+ * bq27x561 write flash. This function is deprecated due to naming convention.
+ *
+ * @param dev pointer to device
+ * @param Address location
+ * @param The buffer of data to be written
+ * @param The length of data to be written
+ *
+ * @return int 0: success, -1 error
+ */
+__attribute__((deprecated))
+static inline bq27z561_err_t bq27x561_wr_flash(struct bq27z561 *dev, 
+                                               uint16_t addr, uint8_t *buf, 
+                                               int buflen)
+{
+    return bq27z561_wr_flash(dev, addr, buf, buflen);
+}
+
 /**
  * bq27z561 rd std reg word
  *
diff --git a/hw/drivers/bq27z561/src/bq27z561.c b/hw/drivers/bq27z561/src/bq27z561.c
index c693d641a9..e5438dc7f1 100644
--- a/hw/drivers/bq27z561/src/bq27z561.c
+++ b/hw/drivers/bq27z561/src/bq27z561.c
@@ -588,7 +588,7 @@ bq27x561_rd_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
 }
 
 bq27z561_err_t
-bq27x561_wr_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
+bq27z561_wr_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
 {
     uint8_t tmpbuf[BQ27Z561_MAX_FLASH_RW_LEN + 2];
     uint8_t chksum;
@@ -604,7 +604,7 @@ bq27x561_wr_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
         return BQ27Z561_ERR_INV_PARAMS;
     }
 
-    if ((addr < BQ27Z561_FLASH_BEG_ADDR) || (addr > BQ27Z561_FLASH_END_ADDR)) {
+    if ((addr < BQ27Z561_FLASH_BEG_ADDR) || (addr + buflen > BQ27Z561_FLASH_END_ADDR)) {
         return BQ27Z561_ERR_INV_FLASH_ADDR;
     }
 
@@ -631,7 +631,6 @@ bq27x561_wr_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
 #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
     rc = bus_node_simple_write(odev, tmpbuf, buflen + 3);
     if (rc) {
-        (void)bus_node_unlock(odev);
         ret = BQ27Z561_ERR_I2C_ERR;
         goto err;
     }
@@ -658,16 +657,16 @@ bq27x561_wr_flash(struct bq27z561 *dev, uint16_t addr, uint8_t *buf, int buflen)
 #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
     rc = bus_node_simple_write(odev, tmpbuf, 3);
     if (rc) {
-        (void)bus_node_unlock(odev);
         ret = BQ27Z561_ERR_I2C_ERR;
         goto err;
     }
 
     (void)bus_node_unlock(odev);
 
-    ret = BQ27Z561_OK;
+    return BQ27Z561_OK;
 
 err:
+    (void)bus_node_unlock(odev);
 #else
     i2c.len = 3;
     i2c.buffer = tmpbuf;


 

----------------------------------------------------------------
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