You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2019/03/19 18:39:24 UTC

[mynewt-core] branch master updated: imgmgr: added image upload callbacks to imgmgr (#1700)

This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 8cc6226  imgmgr: added image upload callbacks to imgmgr (#1700)
8cc6226 is described below

commit 8cc6226d580a8b221601f58f9f2ff280cf5549b4
Author: JustineKH <35...@users.noreply.github.com>
AuthorDate: Tue Mar 19 11:39:19 2019 -0700

    imgmgr: added image upload callbacks to imgmgr (#1700)
---
 hw/drivers/led/lp5523/src/lp5523.c  |  1 -
 mgmt/imgmgr/include/imgmgr/imgmgr.h | 16 +++++++++++++-
 mgmt/imgmgr/src/imgmgr.c            | 43 +++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/hw/drivers/led/lp5523/src/lp5523.c b/hw/drivers/led/lp5523/src/lp5523.c
index 847bb1a..e9f1471 100644
--- a/hw/drivers/led/lp5523/src/lp5523.c
+++ b/hw/drivers/led/lp5523/src/lp5523.c
@@ -424,7 +424,6 @@ lp5523_get_output_reg(struct led_itf *itf, enum lp5523_output_registers addr,
     return lp5523_get_reg(itf, addr + (output - 1), value);
 }
 
-
 int
 lp5523_set_engine_reg(struct led_itf *itf, enum lp5523_engine_registers addr,
     uint8_t engine, uint8_t value)
diff --git a/mgmt/imgmgr/include/imgmgr/imgmgr.h b/mgmt/imgmgr/include/imgmgr/imgmgr.h
index 29a4b51..d1cbb2f 100644
--- a/mgmt/imgmgr/include/imgmgr/imgmgr.h
+++ b/mgmt/imgmgr/include/imgmgr/imgmgr.h
@@ -44,6 +44,17 @@ extern "C" {
 #define IMGMGR_STATE_F_ACTIVE           0x04
 #define IMGMGR_STATE_F_PERMANENT        0x08
 
+/** @brief Generic callback function for events */
+typedef void (*imgrmgr_dfu_cb)(void);
+
+/** Callback function pointers */
+typedef struct
+{
+    imgrmgr_dfu_cb dfu_started_cb;
+    imgrmgr_dfu_cb dfu_stopped_cb;
+    imgrmgr_dfu_cb dfu_complete_cb;
+} imgmgr_dfu_callbacks_t;
+
 /** @typedef imgr_upload_fn
  * @brief Application callback that is executed when an image upload request is
  * received.
@@ -111,7 +122,10 @@ int imgmgr_state_slot_in_use(int slot);
 int imgmgr_state_set_pending(int slot, int permanent);
 int imgmgr_state_confirm(void);
 int imgmgr_find_best_area_id(void);
-
+int imgmgr_register_callbacks(const imgmgr_dfu_callbacks_t *cb_struct);
+void imgr_dfu_stopped(void);
+void imgr_dfu_started(void);
+void imgr_dfu_complete(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index c5dedf7..3cef6e5 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -35,6 +35,8 @@
 #include "imgmgr/imgmgr.h"
 #include "imgmgr_priv.h"
 
+const imgmgr_dfu_callbacks_t *imgmgr_dfu_callbacks_fn;
+
 static int imgr_upload(struct mgmt_cbuf *);
 static int imgr_erase(struct mgmt_cbuf *);
 static int imgr_erase_state(struct mgmt_cbuf *);
@@ -737,6 +739,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     /* Determine what actions to take as a result of this request. */
     rc = imgr_upload_inspect(&req, &action, &errstr);
     if (rc != 0) {
+        imgr_dfu_stopped();
         return rc;
     }
 
@@ -753,6 +756,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     if (imgr_upload_cb != NULL) {
         rc = imgr_upload_cb(req.off, action.size, imgr_upload_arg);
         if (rc != 0) {
+            imgr_dfu_stopped();
             return imgr_error_rsp(cb, rc, imgmgr_err_str_app_reject);
         }
     }
@@ -763,6 +767,7 @@ imgr_upload(struct mgmt_cbuf *cb)
 
     rc = flash_area_open(imgr_state.area_id, &fa);
     if (rc != 0) {
+        imgr_dfu_stopped();
         return imgr_error_rsp(cb, MGMT_ERR_EUNKNOWN,
                               imgmgr_err_str_flash_open_failed);
     }
@@ -773,6 +778,8 @@ imgr_upload(struct mgmt_cbuf *cb)
          */
         imgr_state.off = 0;
 
+        imgr_dfu_started();
+
         /*
          * We accept SHA trimmed to any length by client since it's up to client
          * to make sure provided data are good enough to avoid collisions when
@@ -821,12 +828,14 @@ imgr_upload(struct mgmt_cbuf *cb)
 #endif
         rc = flash_area_write(fa, req.off, req.img_data, action.write_bytes);
         if (rc != 0) {
+            imgr_dfu_stopped();
             rc = MGMT_ERR_EUNKNOWN;
             errstr = imgmgr_err_str_flash_write_failed;
         } else {
             imgr_state.off += action.write_bytes;
             if (imgr_state.off == imgr_state.size) {
                 /* Done */
+                imgr_dfu_complete();
                 imgr_state.area_id = -1;
             }
         }
@@ -845,12 +854,46 @@ end:
 }
 
 void
+imgr_dfu_stopped(void)
+{
+    if (imgmgr_dfu_callbacks_fn->dfu_stopped_cb != NULL)
+    {
+        imgmgr_dfu_callbacks_fn->dfu_stopped_cb();
+    }
+}
+
+void
+imgr_dfu_started(void)
+{
+    if (imgmgr_dfu_callbacks_fn->dfu_started_cb != NULL)
+    {
+        imgmgr_dfu_callbacks_fn->dfu_started_cb();
+    }
+}
+
+void
+imgr_dfu_complete(void)
+{
+    if (imgmgr_dfu_callbacks_fn->dfu_complete_cb != NULL)
+    {
+        imgmgr_dfu_callbacks_fn->dfu_complete_cb();
+    }
+}
+
+void
 imgr_set_upload_cb(imgr_upload_fn *cb, void *arg)
 {
     imgr_upload_cb = cb;
     imgr_upload_arg = arg;
 }
 
+int
+imgmgr_register_callbacks(const imgmgr_dfu_callbacks_t *cb_struct)
+{
+    imgmgr_dfu_callbacks_fn = cb_struct;
+    return 0;
+}
+
 void
 imgmgr_module_init(void)
 {