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 c523d33  net/osdp: Add a stop api
     new 4243264  Merge pull request #2515 from vikrant-proxy/osdp-stop
c523d33 is described below

commit c523d33c635bd61d4a8b54a9b0b1659c79ba6bb0
Author: Vikrant More <vikr...@proxy.com>
AuthorDate: Wed Mar 3 15:52:04 2021 -0800

    net/osdp: Add a stop api
---
 net/osdp/include/osdp/osdp.h |  5 +++++
 net/osdp/src/osdp.c          | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/net/osdp/include/osdp/osdp.h b/net/osdp/include/osdp/osdp.h
index 4ca01c0..491e1ce 100644
--- a/net/osdp/include/osdp/osdp.h
+++ b/net/osdp/include/osdp/osdp.h
@@ -700,6 +700,11 @@ uint32_t osdp_get_sc_status_mask(osdp_t *ctx);
  */
 void osdp_init(osdp_pd_info_t *info, uint8_t *scbk);
 
+/**
+ * @brief Stop OSDP library.
+ */
+void osdp_stop(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/net/osdp/src/osdp.c b/net/osdp/src/osdp.c
index ebd7be8..05d799e 100644
--- a/net/osdp/src/osdp.c
+++ b/net/osdp/src/osdp.c
@@ -193,6 +193,41 @@ osdp_refresh_handler(struct os_event *ev)
 }
 
 /*
+ * Stop OSDP library. Called by application
+ */
+void
+osdp_stop(void)
+{
+    int rc;
+    struct osdp *ctx;
+    struct osdp_device *od = &osdp_device;
+
+    ctx = osdp_get_ctx();
+    assert(ctx);
+
+    /* Stop timer */
+    os_callout_stop(&osdp_refresh_timer);
+
+    /* Cleanup */
+#if MYNEWT_VAL(OSDP_MODE_PD)
+    osdp_pd_teardown(ctx);
+#else
+    osdp_cp_teardown(ctx);
+#endif
+
+    /* Stop uart */
+    assert(od->uart);
+    rc = os_dev_close((struct os_dev *)od->uart);
+    assert(rc == 0);
+
+    /* Flush circular buffers */
+    osdp_uart_flush((void *)od);
+
+    /* Reset OSDP context */
+    memset(&osdp_ctx, 0, sizeof(struct osdp_ctx));
+}
+
+/*
  * Start OSDP. Called by application
  */
 void

Reply via email to