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/11/01 17:16:52 UTC
[09/11] incubator-mynewt-core git commit: Sample apps: Event codes ->
callbacks
Sample apps: Event codes -> callbacks
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7cf94f61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7cf94f61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7cf94f61
Branch: refs/heads/develop
Commit: 7cf94f6111b6de3c73a7926878dd87ff57e60e2d
Parents: 146da29
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Oct 27 18:11:05 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:36 2016 -0700
----------------------------------------------------------------------
apps/blecent/src/main.c | 33 ++++++++-----------------------
apps/bleprph/src/main.c | 39 ++++++++----------------------------
apps/bletest/src/main.c | 33 +++++++++++--------------------
apps/bletiny/src/main.c | 41 +++++++++++++-------------------------
apps/bleuart/src/main.c | 35 ++++++--------------------------
apps/ocf_sample/src/main.c | 7 -------
apps/slinky/src/main.c | 44 ++++++++++++++++++++++++++++++++++-------
7 files changed, 84 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index a65b724..4d52a0f 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -461,29 +461,8 @@ blecent_on_sync(void)
static void
blecent_task_handler(void *unused)
{
- struct os_event *ev;
- struct os_callout_func *cf;
- int rc;
-
- /* Activate the host. This causes the host to synchronize with the
- * controller.
- */
- rc = ble_hs_start();
- assert(rc == 0);
-
while (1) {
- ev = os_eventq_get(&blecent_evq);
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)ev;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
-
- default:
- assert(0);
- break;
- }
+ os_eventq_run(&blecent_evq);
}
}
@@ -505,7 +484,8 @@ main(void)
sysinit();
/* Initialize the blecent log. */
- log_register("blecent", &blecent_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+ log_register("blecent", &blecent_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
/* Initialize the eventq for the application task. */
os_eventq_init(&blecent_evq);
@@ -518,8 +498,8 @@ main(void)
blecent_stack, BLECENT_STACK_SIZE);
/* Configure the host. */
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
- ble_hs_cfg.parent_evq = &blecent_evq;
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
ble_hs_cfg.reset_cb = blecent_on_reset;
ble_hs_cfg.sync_cb = blecent_on_sync;
ble_hs_cfg.store_read_cb = ble_store_ram_read;
@@ -533,6 +513,9 @@ main(void)
rc = ble_svc_gap_device_name_set("nimble-blecent");
assert(rc == 0);
+ /* Set the default eventq for packages that lack a dedicated task. */
+ os_eventq_dflt_set(&blecent_evq);
+
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index e9a99e0..3e0a818 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -253,34 +253,8 @@ bleprph_on_sync(void)
static void
bleprph_task_handler(void *unused)
{
- struct os_event *ev;
- struct os_callout_func *cf;
- int rc;
-
- /* Activate the host. This causes the host to synchronize with the
- * controller.
- */
- rc = ble_hs_start();
-
while (1) {
- ev = os_eventq_get(&bleprph_evq);
-
- /* Check if the event is a nmgr ble mqueue event */
- rc = nmgr_ble_proc_mq_evt(ev);
- if (!rc) {
- continue;
- }
-
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)ev;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
- default:
- assert(0);
- break;
- }
+ os_eventq_run(&bleprph_evq);
}
}
@@ -301,13 +275,12 @@ main(void)
/* Set initial BLE device address. */
memcpy(g_dev_addr, (uint8_t[6]){0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}, 6);
- ble_hs_cfg.parent_evq = &bleprph_evq;
-
/* Initialize OS */
sysinit();
/* Initialize the bleprph log. */
- log_register("bleprph", &bleprph_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+ log_register("bleprph", &bleprph_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
/* Initialize eventq */
os_eventq_init(&bleprph_evq);
@@ -320,7 +293,8 @@ main(void)
bleprph_stack, BLEPRPH_STACK_SIZE);
/* Initialize the NimBLE host configuration. */
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
ble_hs_cfg.reset_cb = bleprph_on_reset;
ble_hs_cfg.sync_cb = bleprph_on_sync;
ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
@@ -332,6 +306,9 @@ main(void)
rc = ble_svc_gap_device_name_set("nimble-bleprph");
assert(rc == 0);
+ /* Set the default eventq for packages that lack a dedicated task. */
+ os_eventq_dflt_set(&bleprph_evq);
+
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 92b3c0d..8f3f52b 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -120,7 +120,7 @@ uint8_t g_host_adv_len;
uint32_t g_next_os_time;
int g_bletest_state;
struct os_eventq g_bletest_evq;
-struct os_callout_func g_bletest_timer;
+struct os_callout g_bletest_timer;
struct os_task bletest_task;
bssnz_t os_stack_t bletest_stack[BLETEST_STACK_SIZE];
uint32_t g_bletest_conn_end;
@@ -853,13 +853,13 @@ bletest_execute(void)
* @param arg
*/
void
-bletest_timer_cb(void *arg)
+bletest_timer_cb(struct os_event *ev)
{
/* Call the bletest code */
bletest_execute();
/* Re-start the timer (run every 10 msecs) */
- os_callout_reset(&g_bletest_timer.cf_c, OS_TICKS_PER_SEC / 100);
+ os_callout_reset(&g_bletest_timer, OS_TICKS_PER_SEC / 100);
}
/**
@@ -873,8 +873,6 @@ bletest_task_handler(void *arg)
int rc;
uint64_t rand64;
uint64_t event_mask;
- struct os_event *ev;
- struct os_callout_func *cf;
/* Set LED blink rate */
g_bletest_led_rate = OS_TICKS_PER_SEC / 20;
@@ -883,8 +881,8 @@ bletest_task_handler(void *arg)
os_time_delay(OS_TICKS_PER_SEC);
/* Initialize the host timer */
- os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
- NULL);
+ os_callout_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
+ NULL);
ble_hs_dbg_set_sync_state(BLE_HS_SYNC_STATE_GOOD);
@@ -999,17 +997,7 @@ bletest_task_handler(void *arg)
bletest_timer_cb(NULL);
while (1) {
- ev = os_eventq_get(&g_bletest_evq);
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)ev;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
- default:
- assert(0);
- break;
- }
+ os_eventq_run(&g_bletest_evq);
}
}
@@ -1061,10 +1049,8 @@ main(void)
g_bletest_cur_peer_addr[5] = 0x08;
#endif
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
-
- /* Set the NimBLE host's parent event queue. */
- ble_hs_cfg.parent_evq = &g_bletest_evq;
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
/* Set the led pin as an output */
g_led_pin = LED_BLINK_PIN;
@@ -1078,6 +1064,9 @@ main(void)
BLETEST_STACK_SIZE);
assert(rc == 0);
+ /* Set the default eventq for packages that lack a dedicated task. */
+ os_eventq_dflt_set(&g_bletest_evq);
+
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 7ee26e8..048a3c7 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -105,7 +105,7 @@ static struct os_mempool bletiny_chr_pool;
static void *bletiny_dsc_mem;
static struct os_mempool bletiny_dsc_pool;
-static struct os_callout_func bletiny_tx_timer;
+static struct os_callout bletiny_tx_timer;
struct bletiny_tx_data_s
{
uint16_t tx_num;
@@ -1029,7 +1029,7 @@ bletiny_on_l2cap_update(uint16_t conn_handle, int status, void *arg)
}
static void
-bletiny_tx_timer_cb(void *arg)
+bletiny_tx_timer_cb(struct os_event *ev)
{
int i;
uint8_t len;
@@ -1081,7 +1081,7 @@ bletiny_tx_timer_cb(void *arg)
if (bletiny_tx_data.tx_num) {
timeout = (int32_t)bletiny_tx_data.tx_rate;
timeout = (timeout * OS_TICKS_PER_SEC) / 1000;
- os_callout_reset(&bletiny_tx_timer.cf_c, timeout);
+ os_callout_reset(&bletiny_tx_timer, timeout);
}
}
@@ -1523,7 +1523,7 @@ bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate, uint16_t num)
bletiny_tx_data.tx_len = len;
bletiny_tx_data.tx_handle = handle;
- os_callout_reset(&bletiny_tx_timer.cf_c, 0);
+ os_callout_reset(&bletiny_tx_timer, 0);
return 0;
}
@@ -1555,25 +1555,8 @@ bletiny_on_reset(int reason)
static void
bletiny_task_handler(void *arg)
{
- struct os_callout_func *cf;
- struct os_event *ev;
- int rc;
-
- rc = ble_hs_start();
- assert(rc == 0);
-
while (1) {
- ev = os_eventq_get(&bletiny_evq);
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)ev;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
- default:
- assert(0);
- break;
- }
+ os_eventq_run(&bletiny_evq);
}
}
@@ -1623,7 +1606,8 @@ main(void)
assert(rc == 0);
/* Initialize the logging system. */
- log_register("bletiny", &bletiny_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+ log_register("bletiny", &bletiny_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
/* Initialize eventq for the application task. */
os_eventq_init(&bletiny_evq);
@@ -1636,8 +1620,8 @@ main(void)
bletiny_stack, BLETINY_STACK_SIZE);
/* Initialize the NimBLE host configuration. */
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
- ble_hs_cfg.parent_evq = &bletiny_evq;
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
ble_hs_cfg.reset_cb = bletiny_on_reset;
ble_hs_cfg.store_read_cb = ble_store_ram_read;
ble_hs_cfg.store_write_cb = ble_store_ram_write;
@@ -1656,8 +1640,11 @@ main(void)
/* Create a callout (timer). This callout is used by the "tx" bletiny
* command to repeatedly send packets of sequential data bytes.
*/
- os_callout_func_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
- NULL);
+ os_callout_init(&bletiny_tx_timer, &bletiny_evq, bletiny_tx_timer_cb,
+ NULL);
+
+ /* Set the default eventq for packages that lack a dedicated task. */
+ os_eventq_dflt_set(&bletiny_evq);
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 4f6369a..d6fed4d 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -193,33 +193,7 @@ bleuart_on_sync(void)
static void
bleuart_task_handler(void *unused)
{
- struct os_event *ev;
- struct os_callout_func *cf;
- int rc;
-
- rc = ble_hs_start();
- assert(rc == 0);
-
- while (1) {
- ev = os_eventq_get(&bleuart_evq);
-
- /* Check if the event is a nmgr ble mqueue event */
- rc = nmgr_ble_proc_mq_evt(ev);
- if (!rc) {
- continue;
- }
-
- switch (ev->ev_type) {
- case OS_EVENT_T_TIMER:
- cf = (struct os_callout_func *)ev;
- assert(cf->cf_func);
- cf->cf_func(CF_ARG(cf));
- break;
- default:
- assert(0);
- break;
- }
- }
+ os_eventq_run(&bleuart_evq);
}
/**
@@ -244,8 +218,8 @@ main(void)
bleuart_stack, bleuart_STACK_SIZE);
/* Initialize the BLE host. */
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
- ble_hs_cfg.parent_evq = &bleuart_evq;
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
+ LOG_SYSLEVEL);
ble_hs_cfg.sync_cb = bleuart_on_sync;
ble_hs_cfg.store_read_cb = ble_store_ram_read;
ble_hs_cfg.store_write_cb = ble_store_ram_write;
@@ -260,6 +234,9 @@ main(void)
rc = ble_svc_gap_device_name_set("Mynewt_BLEuart");
assert(rc == 0);
+ /* Set the default eventq for packages that lack a dedicated task. */
+ os_eventq_dflt_set(&bleuart_evq);
+
/* Start the OS */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index c1f1b4c..d9888f7 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -233,13 +233,6 @@ oc_signal_main_loop(void)
void
ocf_task_handler(void *arg)
{
-#if MYNEWT_VAL(OC_TRANSPORT_GATT)
- int rc;
-
- rc = ble_hs_start();
- assert(rc == 0);
-#endif
-
os_sem_init(&ocf_main_loop_sem, 1);
while (1) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7cf94f61/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 143690f..cb808de 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -52,7 +52,6 @@
/* Init all tasks */
static volatile int tasks_initialized;
-int init_tasks(void);
/* Task 1 */
#define TASK1_PRIO (8)
@@ -63,9 +62,14 @@ static volatile int g_task1_loops;
/* Task 2 */
#define TASK2_PRIO (9)
-#define TASK2_STACK_SIZE OS_STACK_ALIGN(128)
+#define TASK2_STACK_SIZE OS_STACK_ALIGN(64)
static struct os_task task2;
+/* Task 3 */
+#define TASK3_PRIO (10)
+#define TASK3_STACK_SIZE OS_STACK_ALIGN(384)
+static struct os_task task3;
+
static struct log my_log;
static volatile int g_task2_loops;
@@ -106,6 +110,8 @@ static char test_str[32];
static uint32_t cbmem_buf[MAX_CBMEM_BUF];
static struct cbmem cbmem;
+static struct os_eventq slinky_evq;
+
static char *
test_conf_get(int argc, char **argv, char *buf, int max_len)
{
@@ -151,7 +157,7 @@ test_conf_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt)
return 0;
}
-void
+static void
task1_handler(void *arg)
{
struct os_task *t;
@@ -191,7 +197,7 @@ task1_handler(void *arg)
}
}
-void
+static void
task2_handler(void *arg)
{
struct os_task *t;
@@ -210,6 +216,18 @@ task2_handler(void *arg)
}
/**
+ * This task serves as a container for the shell and newtmgr packages. These
+ * packages enqueue timer events when they need this task to do work.
+ */
+static void
+task3_handler(void *arg)
+{
+ while (1) {
+ os_eventq_run(&slinky_evq);
+ }
+}
+
+/**
* init_tasks
*
* Called by main.c after sysinit(). This function performs initializations
@@ -217,7 +235,7 @@ task2_handler(void *arg)
*
* @return int 0 success; error otherwise.
*/
-int
+static void
init_tasks(void)
{
os_stack_t *pstack;
@@ -236,8 +254,20 @@ init_tasks(void)
os_task_init(&task2, "task2", task2_handler, NULL,
TASK2_PRIO, OS_WAIT_FOREVER, pstack, TASK2_STACK_SIZE);
+ pstack = malloc(sizeof(os_stack_t)*TASK3_STACK_SIZE);
+ assert(pstack);
+
+ os_task_init(&task3, "task3", task3_handler, NULL,
+ TASK3_PRIO, OS_WAIT_FOREVER, pstack, TASK3_STACK_SIZE);
+
+ /* Initialize eventq and designate it as the default. Packages that need
+ * to schedule work items will piggyback on this eventq. Example packages
+ * which do this are sys/shell and mgmt/newtmgr.
+ */
+ os_eventq_init(&slinky_evq);
+ os_eventq_dflt_set(&slinky_evq);
+
tasks_initialized = 1;
- return 0;
}
/**
@@ -288,7 +318,7 @@ main(int argc, char **argv)
}
#endif
- rc = init_tasks();
+ init_tasks();
os_start();