You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/27 06:48:33 UTC

incubator-mynewt-larva git commit: bleshell - mutex to prevent gatt conflicts.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master de4f67bc1 -> 162c23506


bleshell - mutex to prevent gatt conflicts.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/162c2350
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/162c2350
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/162c2350

Branch: refs/heads/master
Commit: 162c23506ce885ac09126930347fe641136ac196
Parents: de4f67b
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 27 00:47:39 2016 -0500
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 27 00:47:39 2016 -0500

----------------------------------------------------------------------
 project/bleshell/src/bleshell_priv.h |  2 ++
 project/bleshell/src/cmd.c           | 25 +++++++++++++++++---
 project/bleshell/src/main.c          | 39 +++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/162c2350/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index e03fb9c..b6534ac 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -85,6 +85,8 @@ int parse_err_too_few_args(char *cmd_name);
 int parse_arg_all(int argc, char **argv);
 int cmd_init(void);
 void periph_init(void);
+void bleshell_lock(void);
+void bleshell_unlock(void);
 int bleshell_exchange_mtu(uint16_t conn_handle);
 int bleshell_disc_svcs(uint16_t conn_handle);
 int bleshell_disc_svc_by_uuid(uint16_t conn_handle, uint8_t *uuid128);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/162c2350/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index f3d8e32..880b319 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -671,10 +671,14 @@ cmd_scan(int argc, char **argv)
 static int
 cmd_show_addr(int argc, char **argv)
 {
+    bleshell_lock();
+
     bleshell_printf("myaddr=");
     print_addr(g_dev_addr);
     bleshell_printf("\n");
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -685,6 +689,8 @@ cmd_show_chr(int argc, char **argv)
     struct bleshell_svc *svc;
     int i;
 
+    bleshell_lock();
+
     for (i = 0; i < bleshell_num_conns; i++) {
         conn = bleshell_conns + i;
 
@@ -697,6 +703,8 @@ cmd_show_chr(int argc, char **argv)
         }
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -706,6 +714,8 @@ cmd_show_conn(int argc, char **argv)
     struct bleshell_conn *conn;
     int i;
 
+    bleshell_lock();
+
     for (i = 0; i < bleshell_num_conns; i++) {
         conn = bleshell_conns + i;
 
@@ -714,6 +724,8 @@ cmd_show_conn(int argc, char **argv)
         bleshell_printf(" addr_type=%d\n", conn->addr_type);
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -724,6 +736,8 @@ cmd_show_svc(int argc, char **argv)
     struct bleshell_svc *svc;
     int i;
 
+    bleshell_lock();
+
     for (i = 0; i < bleshell_num_conns; i++) {
         conn = bleshell_conns + i;
 
@@ -736,6 +750,8 @@ cmd_show_svc(int argc, char **argv)
         }
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -1324,16 +1340,19 @@ cmd_b_exec(int argc, char **argv)
 
     rc = parse_arg_all(argc - 1, argv + 1);
     if (rc != 0) {
-        return rc;
+        goto done;
     }
 
     rc = cmd_exec(cmd_b_entries, argc, argv);
     if (rc != 0) {
         bleshell_printf("error\n");
-        return rc;
+        goto done;
     }
 
-    return 0;
+    rc = 0;
+
+done:
+    return rc;
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/162c2350/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index 45e5ffd..8b151e3 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -46,6 +46,8 @@
 #define SHELL_TASK_STACK_SIZE   (OS_STACK_ALIGN(384))
 os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
 
+static struct os_mutex bleshell_mutex;
+
 /* For LED toggling */
 int g_led_pin;
 
@@ -111,6 +113,24 @@ uint8_t bleshell_reconnect_addr[6];
 uint8_t bleshell_pref_conn_params[8];
 uint8_t bleshell_gatt_service_changed[4];
 
+void
+bleshell_lock(void)
+{
+    int rc;
+
+    rc = os_mutex_pend(&bleshell_mutex, 0xffffffff);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+void
+bleshell_unlock(void)
+{
+    int rc;
+
+    rc = os_mutex_release(&bleshell_mutex);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
 static void
 bleshell_print_error(char *msg, uint16_t conn_handle,
                      struct ble_gatt_error *error)
@@ -640,6 +660,8 @@ static int
 bleshell_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
                    struct ble_gatt_service *service, void *arg)
 {
+    bleshell_lock();
+
     if (error != NULL) {
         bleshell_print_error("ERROR DISCOVERING SERVICE", conn_handle, error);
     } else if (service != NULL) {
@@ -648,6 +670,8 @@ bleshell_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
         /* Service discovery complete. */
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -657,6 +681,8 @@ bleshell_on_disc_c(uint16_t conn_handle, struct ble_gatt_error *error,
 {
     intptr_t *svc_start_handle;
 
+    bleshell_lock();
+
     svc_start_handle = arg;
 
     if (error != NULL) {
@@ -668,6 +694,8 @@ bleshell_on_disc_c(uint16_t conn_handle, struct ble_gatt_error *error,
         /* Service discovery complete. */
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -678,6 +706,8 @@ bleshell_on_disc_d(uint16_t conn_handle, struct ble_gatt_error *error,
 {
     intptr_t *chr_def_handle;
 
+    bleshell_lock();
+
     chr_def_handle = arg;
 
     if (error != NULL) {
@@ -689,6 +719,8 @@ bleshell_on_disc_d(uint16_t conn_handle, struct ble_gatt_error *error,
         /* Descriptor discovery complete. */
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -800,6 +832,8 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
 {
     int conn_idx;
 
+    bleshell_lock();
+
     switch (event) {
     case BLE_GAP_EVENT_CONN:
         bleshell_printf("connection complete; status=%d ", status);
@@ -837,6 +871,8 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
         break;
     }
 
+    bleshell_unlock();
+
     return 0;
 }
 
@@ -1275,6 +1311,9 @@ main(void)
     htole16(bleshell_pref_conn_params + 4, 0);
     htole16(bleshell_pref_conn_params + 6, BSWAP16(0x100));
 
+    rc = os_mutex_init(&bleshell_mutex);
+    assert(rc == 0);
+
     /* Start the OS */
     os_start();