Update sample BLE apps to use transports.
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/29b69ddf Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/29b69ddf Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/29b69ddf Branch: refs/heads/develop Commit: 29b69ddf240d49955990a405211b7cf8f48fc585 Parents: d842a43 Author: Christopher Collins <[email protected]> Authored: Wed Aug 3 19:43:50 2016 -0700 Committer: Christopher Collins <[email protected]> Committed: Wed Aug 3 19:54:16 2016 -0700 ---------------------------------------------------------------------- apps/blecent/pkg.yml | 1 + apps/blecent/src/main.c | 25 ++- apps/blehci/pkg.yml | 5 +- apps/blehci/src/main.c | 312 +----------------------------------- apps/bleprph/pkg.yml | 1 + apps/bleprph/src/main.c | 32 +++- apps/bletest/pkg.yml | 1 + apps/bletest/src/bletest_hci.c | 2 +- apps/bletest/src/main.c | 12 +- apps/bletiny/pkg.yml | 1 + apps/bletiny/src/main.c | 24 ++- apps/bleuart/pkg.yml | 1 + apps/bleuart/src/main.c | 11 +- 13 files changed, 94 insertions(+), 334 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/blecent/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/blecent/pkg.yml b/apps/blecent/pkg.yml index b1710aa..3798fee 100644 --- a/apps/blecent/pkg.yml +++ b/apps/blecent/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - net/nimble/host - net/nimble/host/services/mandatory - net/nimble/host/store/ram + - net/nimble/transport/ram - libs/console/full - libs/baselibc http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/blecent/src/main.c ---------------------------------------------------------------------- diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c index 8f10814..66a4e3f 100755 --- a/apps/blecent/src/main.c +++ b/apps/blecent/src/main.c @@ -29,6 +29,9 @@ #include "controller/ble_ll.h" #include "host/ble_hs.h" +/* RAM HCI transport. */ +#include "transport/ram/ble_hci_ram.h" + /* RAM persistence layer. */ #include "store/ram/ble_store_ram.h" @@ -448,6 +451,19 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } } +static void +blecent_on_reset(int reason) +{ + BLECENT_LOG(ERROR, "Resetting state; reason=%d\n", reason); +} + +static void +blecent_on_sync(void) +{ + /* Begin scanning for a peripheral to connect to. */ + blecent_scan(); +} + /** * Event loop for the main blecent task. */ @@ -464,9 +480,6 @@ blecent_task_handler(void *unused) rc = ble_hs_start(); assert(rc == 0); - /* Begin scanning for a peripheral to connect to. */ - blecent_scan(); - while (1) { ev = os_eventq_get(&blecent_evq); switch (ev->ev_type) { @@ -553,6 +566,10 @@ main(void) rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); + /* Initialize the RAM HCI transport. */ + rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt); + assert(rc == 0); + /* Configure the host. */ cfg = ble_hs_cfg_dflt; cfg.max_hci_bufs = 3; @@ -560,6 +577,8 @@ main(void) cfg.sm_bonding = 1; cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; + cfg.reset_cb = blecent_on_reset; + cfg.sync_cb = blecent_on_sync; cfg.store_read_cb = ble_store_ram_read; cfg.store_write_cb = ble_store_ram_write; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/blehci/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/blehci/pkg.yml b/apps/blehci/pkg.yml index f36e383..198e395 100644 --- a/apps/blehci/pkg.yml +++ b/apps/blehci/pkg.yml @@ -23,7 +23,8 @@ pkg.homepage: "http://mynewt.apache.org/" pkg.keywords: pkg.deps: - - libs/os - - net/nimble/controller - libs/baselibc - libs/console/stub + - libs/os + - net/nimble/controller + - net/nimble/transport/uart http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/blehci/src/main.c ---------------------------------------------------------------------- diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c index 09fb456..20fc4bc 100755 --- a/apps/blehci/src/main.c +++ b/apps/blehci/src/main.c @@ -17,24 +17,14 @@ * under the License. */ #include <assert.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> -#include "bsp/bsp.h" #include "os/os.h" -#include "bsp/bsp.h" -#include "hal/hal_gpio.h" #include "hal/hal_cputime.h" #include "hal/hal_uart.h" /* BLE */ #include "nimble/ble.h" -#include "nimble/nimble_opt.h" -#include "nimble/hci_transport.h" #include "controller/ble_ll.h" - -#define HCI_UART_SPEED 1000000 -#define HCI_UART CONSOLE_UART +#include "transport/uart/ble_hci_uart.h" /* Nimble task priorities */ #define BLE_LL_TASK_PRI (OS_TASK_PRI_HIGHEST) @@ -53,291 +43,11 @@ uint8_t g_random_addr[BLE_DEV_ADDR_LEN] = { 0 }; #define HCI_MAX_BUFS (5) -#define HCI_EVT_BUF_SIZE (260) -struct os_mempool g_hci_evt_pool; -static void *hci_cmd_buf; - -#define HCI_OS_EVENT_BUF_SIZE (sizeof(struct os_event)) - -#define BLE_HOST_HCI_EVENT_CTLR_EVENT (OS_EVENT_T_PERUSER + 0) -#define BLE_HOST_HCI_EVENT_CTLR_DATA (OS_EVENT_T_PERUSER + 1) - -struct os_mempool g_hci_os_event_pool; -static void *hci_os_event_buf; - os_membuf_t default_mbuf_mpool_data[MBUF_MEMPOOL_SIZE]; struct os_mbuf_pool default_mbuf_pool; struct os_mempool default_mbuf_mpool; -#define H4_NONE 0x00 -#define H4_CMD 0x01 -#define H4_ACL 0x02 -#define H4_SCO 0x03 -#define H4_EVT 0x04 - -#define HCI_CMD_HDR_LEN 3 -#define HCI_ACL_HDR_LEN 4 -#define HCI_EVT_HDR_LEN 2 - -struct memblock { - uint8_t *data; /* Pointer to memblock data */ - uint16_t cur; /* Number of bytes read/written */ - uint16_t len; /* Total number of bytes to read/write */ -}; - -struct tx_acl { - struct os_mbuf *buf; /* Buffer containing the data */ - uint16_t len; /* Target size when buf is considered complete */ -}; - -static struct { - /* State of data from host to controller */ - uint8_t tx_type; /* Pending packet type. 0 means nothing pending */ - union { - struct memblock tx_cmd; - struct tx_acl tx_acl; - }; - - /* State of data from controller to host */ - uint8_t rx_type; /* Pending packet type. 0 means nothing pending */ - union { - struct memblock rx_evt; - struct os_mbuf *rx_acl; - }; - STAILQ_HEAD(, os_event) rx_pkts; /* Packet queue to send to UART */ -} hci; - -int -ble_hs_rx_data(struct os_mbuf *om) -{ - struct os_event *ev; - os_sr_t sr; - - ev = os_memblock_get(&g_hci_os_event_pool); - if (!ev) { - os_mbuf_free_chain(om); - return -1; - } - - ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_DATA; - ev->ev_arg = om; - ev->ev_queued = 1; - - OS_ENTER_CRITICAL(sr); - STAILQ_INSERT_TAIL(&hci.rx_pkts, ev, ev_next); - OS_EXIT_CRITICAL(sr); - - hal_uart_start_tx(HCI_UART); - - return 0; -} - -int -ble_hci_transport_ctlr_event_send(uint8_t *hci_ev) -{ - struct os_event *ev; - os_sr_t sr; - - ev = os_memblock_get(&g_hci_os_event_pool); - if (!ev) { - os_error_t err; - - err = os_memblock_put(&g_hci_evt_pool, hci_ev); - assert(err == OS_OK); - - return -1; - } - - ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_EVENT; - ev->ev_arg = hci_ev; - ev->ev_queued = 1; - - OS_ENTER_CRITICAL(sr); - STAILQ_INSERT_TAIL(&hci.rx_pkts, ev, ev_next); - OS_EXIT_CRITICAL(sr); - - hal_uart_start_tx(HCI_UART); - - return 0; -} - -static int -uart_tx_pkt_type(void) -{ - struct os_event *ev; - os_sr_t sr; - int rc; - - OS_ENTER_CRITICAL(sr); - - ev = STAILQ_FIRST(&hci.rx_pkts); - if (!ev) { - OS_EXIT_CRITICAL(sr); - return -1; - } - - STAILQ_REMOVE(&hci.rx_pkts, ev, os_event, ev_next); - ev->ev_queued = 0; - - OS_EXIT_CRITICAL(sr); - - switch (ev->ev_type) { - case BLE_HOST_HCI_EVENT_CTLR_EVENT: - hci.rx_type = H4_EVT; - hci.rx_evt.data = ev->ev_arg; - hci.rx_evt.cur = 0; - hci.rx_evt.len = hci.rx_evt.data[1] + HCI_EVT_HDR_LEN; - rc = H4_EVT; - break; - case BLE_HOST_HCI_EVENT_CTLR_DATA: - hci.rx_type = H4_ACL; - hci.rx_acl = ev->ev_arg; - rc = H4_ACL; - break; - default: - rc = -1; - break; - } - - os_memblock_put(&g_hci_os_event_pool, ev); - - return rc; -} - -static int -uart_tx_char(void *arg) -{ - int rc = -1; - - switch (hci.rx_type) { - case H4_NONE: /* No pending packet, pick one from the queue */ - rc = uart_tx_pkt_type(); - break; - case H4_EVT: - rc = hci.rx_evt.data[hci.rx_evt.cur++]; - - if (hci.rx_evt.cur == hci.rx_evt.len) { - os_memblock_put(&g_hci_evt_pool, hci.rx_evt.data); - hci.rx_type = H4_NONE; - } - - break; - case H4_ACL: - rc = *OS_MBUF_DATA(hci.rx_acl, uint8_t *); - os_mbuf_adj(hci.rx_acl, 1); - if (!OS_MBUF_PKTLEN(hci.rx_acl)) { - os_mbuf_free_chain(hci.rx_acl); - hci.rx_type = H4_NONE; - } - - break; - } - - return rc; -} - -static int -uart_rx_pkt_type(uint8_t data) -{ - hci.tx_type = data; - - switch (hci.tx_type) { - case H4_CMD: - hci.tx_cmd.data = os_memblock_get(&g_hci_evt_pool); - hci.tx_cmd.len = 0; - hci.tx_cmd.cur = 0; - break; - case H4_ACL: - hci.tx_acl.buf = os_msys_get_pkthdr(HCI_ACL_HDR_LEN, 0); - hci.tx_acl.len = 0; - break; - default: - hci.tx_type = H4_NONE; - return -1; - } - - return 0; -} - -static int -uart_rx_cmd(uint8_t data) -{ - int rc; - - hci.tx_cmd.data[hci.tx_cmd.cur++] = data; - - if (hci.tx_cmd.cur < HCI_CMD_HDR_LEN) { - return 0; - } else if (hci.tx_cmd.cur == HCI_CMD_HDR_LEN) { - hci.tx_cmd.len = hci.tx_cmd.data[2] + HCI_CMD_HDR_LEN; - } - - if (hci.tx_cmd.cur == hci.tx_cmd.len) { - rc = ble_hci_transport_host_cmd_send(hci.tx_cmd.data); - if (rc != 0) { - os_memblock_put(&g_hci_evt_pool, hci.tx_cmd.data); - } - hci.tx_type = H4_NONE; - } - - return 0; -} - -static int -uart_rx_acl(uint8_t data) -{ - os_mbuf_append(hci.tx_acl.buf, &data, 1); - - if (OS_MBUF_PKTLEN(hci.tx_acl.buf) < HCI_ACL_HDR_LEN) { - return 0; - } else if (OS_MBUF_PKTLEN(hci.tx_acl.buf) == HCI_ACL_HDR_LEN) { - os_mbuf_copydata(hci.tx_acl.buf, 2, sizeof(hci.tx_acl.len), - &hci.tx_acl.len); - hci.tx_acl.len = le16toh(&hci.tx_acl.len) + HCI_ACL_HDR_LEN; - } - - if (OS_MBUF_PKTLEN(hci.tx_acl.buf) == hci.tx_acl.len) { - ble_hci_transport_host_acl_data_send(hci.tx_acl.buf); - hci.tx_type = H4_NONE; - } - - return 0; -} - -static int -uart_rx_char(void *arg, uint8_t data) -{ - switch (hci.tx_type) { - case H4_NONE: - return uart_rx_pkt_type(data); - case H4_CMD: - return uart_rx_cmd(data); - case H4_ACL: - return uart_rx_acl(data); - default: - return -1; - } -} - -static int -uart_init(void) -{ - int rc; - - memset(&hci, 0, sizeof(hci)); - - STAILQ_INIT(&hci.rx_pkts); - - rc = hal_uart_init_cbs(HCI_UART, uart_tx_char, NULL, uart_rx_char, NULL); - if (rc) { - return rc; - } - - return hal_uart_config(HCI_UART, HCI_UART_SPEED, 8, 1, HAL_UART_PARITY_NONE, - HAL_UART_FLOW_CTL_RTS_CTS); -} - int main(void) { @@ -366,25 +76,7 @@ main(void) rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); - hci_cmd_buf = malloc(OS_MEMPOOL_BYTES(HCI_MAX_BUFS, HCI_EVT_BUF_SIZE)); - assert(hci_cmd_buf != NULL); - - /* Create memory pool of command buffers */ - rc = os_mempool_init(&g_hci_evt_pool, HCI_MAX_BUFS, HCI_EVT_BUF_SIZE, - hci_cmd_buf, "HCICmdPool"); - assert(rc == 0); - - hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(HCI_MAX_BUFS, - HCI_OS_EVENT_BUF_SIZE)); - assert(hci_os_event_buf != NULL); - - /* Create memory pool of OS events */ - rc = os_mempool_init(&g_hci_os_event_pool, HCI_MAX_BUFS, - HCI_OS_EVENT_BUF_SIZE, hci_os_event_buf, - "HCIOsEventPool"); - assert(rc == 0); - - rc = uart_init(); + rc = ble_hci_uart_init(&ble_hci_uart_cfg_dflt); assert(rc == 0); /* Start the OS */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bleprph/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml index ec75359..7c45ee2 100644 --- a/apps/bleprph/pkg.yml +++ b/apps/bleprph/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - net/nimble/host - net/nimble/host/services/mandatory - net/nimble/host/store/ram + - net/nimble/transport/ram - libs/console/full - libs/baselibc - libs/newtmgr http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bleprph/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c index 0e6ec14..cff4763 100755 --- a/apps/bleprph/src/main.c +++ b/apps/bleprph/src/main.c @@ -40,9 +40,9 @@ #include "host/ble_l2cap.h" #include "host/ble_sm.h" #include "controller/ble_ll.h" -/* Newtmgr include */ -#include "newtmgr/newtmgr.h" -#include "nmgrble/newtmgr_ble.h" + +/* RAM HCI transport. */ +#include "transport/ram/ble_hci_ram.h" /* RAM persistence layer. */ #include "store/ram/ble_store_ram.h" @@ -51,6 +51,10 @@ #include "services/mandatory/ble_svc_gap.h" #include "services/mandatory/ble_svc_gatt.h" +/* Newtmgr include */ +#include "newtmgr/newtmgr.h" +#include "nmgrble/newtmgr_ble.h" + /* Application-specified header. */ #include "bleprph.h" @@ -266,6 +270,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) return 0; } +static void +bleprph_on_reset(int reason) +{ + BLEPRPH_LOG(ERROR, "Resetting state; reason=%d\n", reason); +} + +static void +bleprph_on_sync(void) +{ + /* Begin advertising. */ + bleprph_advertise(); +} + /** * Event loop for the main bleprph task. */ @@ -280,10 +297,6 @@ bleprph_task_handler(void *unused) * controller. */ rc = ble_hs_start(); - assert(rc == 0); - - /* Begin advertising. */ - bleprph_advertise(); while (1) { ev = os_eventq_get(&bleprph_evq); @@ -383,6 +396,8 @@ main(void) cfg.sm_bonding = 1; cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; + cfg.reset_cb = bleprph_on_reset; + cfg.sync_cb = bleprph_on_sync; cfg.store_read_cb = ble_store_ram_read; cfg.store_write_cb = ble_store_ram_write; cfg.gatts_register_cb = gatt_svr_register_cb; @@ -404,6 +419,9 @@ main(void) rc = ble_hs_init(&bleprph_evq, &cfg); assert(rc == 0); + rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt); + assert(rc == 0); + nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE); imgmgr_module_init(); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bletest/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bletest/pkg.yml b/apps/bletest/pkg.yml index 84b6e71..3e94ede 100644 --- a/apps/bletest/pkg.yml +++ b/apps/bletest/pkg.yml @@ -28,6 +28,7 @@ pkg.deps: - fs/nffs - net/nimble/controller - net/nimble/host + - net/nimble/transport/ram - libs/os - libs/console/full - libs/shell http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bletest/src/bletest_hci.c ---------------------------------------------------------------------- diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c index 5e6c31e..64d0270 100755 --- a/apps/bletest/src/bletest_hci.c +++ b/apps/bletest/src/bletest_hci.c @@ -24,7 +24,7 @@ /* BLE */ #include "nimble/ble.h" -#include "nimble/hci_transport.h" +#include "nimble/ble_hci_trans.h" #include "nimble/hci_common.h" #include "host/ble_hs.h" #include "controller/ble_ll.h" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bletest/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c index f6bb187..be0cf6d 100755 --- a/apps/bletest/src/main.c +++ b/apps/bletest/src/main.c @@ -36,7 +36,7 @@ /* BLE */ #include "nimble/ble.h" -#include "nimble/hci_transport.h" +#include "nimble/ble_hci_trans.h" #include "nimble/hci_common.h" #include "host/ble_hs.h" #include "controller/ble_ll.h" @@ -44,6 +44,7 @@ #include "controller/ble_ll_conn.h" #include "controller/ble_ll_scan.h" #include "controller/ble_ll_adv.h" +#include "transport/ram/ble_hci_ram.h" /* XXX: An app should not include private headers from a library. The bletest * app uses some of nimble's internal details for logging. @@ -767,7 +768,7 @@ bletest_execute_advertiser(void) /* Add length */ OS_MBUF_PKTHDR(om)->omp_len = om->om_len; - ble_hci_transport_host_acl_data_send(om); + ble_hci_trans_hs_acl_data_send(om); /* Increment last handle used */ ++g_last_handle_used; @@ -823,7 +824,7 @@ bletest_execute_advertiser(void) /* Add length */ OS_MBUF_PKTHDR(om)->omp_len = om->om_len; - ble_hci_transport_host_acl_data_send(om); + ble_hci_trans_hs_acl_data_send(om); ++g_bletest_outstanding_pkts; } @@ -895,6 +896,8 @@ bletest_task_handler(void *arg) os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb, NULL); + ble_hs_dbg_set_sync_state(BLE_HS_SYNC_STATE_GOOD); + /* Send the reset command first */ rc = bletest_hci_reset_ctlr(); assert(rc == 0); @@ -1151,6 +1154,9 @@ main(void) rc = ble_hs_init(&g_bletest_evq, NULL); assert(rc == 0); + rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt); + assert(rc == 0); + rc = os_task_init(&bletest_task, "bletest", bletest_task_handler, NULL, BLETEST_TASK_PRIO, OS_WAIT_FOREVER, bletest_stack, BLETEST_STACK_SIZE); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bletiny/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml index a3c6ee7..625adc6 100644 --- a/apps/bletiny/pkg.yml +++ b/apps/bletiny/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - net/nimble/host - net/nimble/host/services/mandatory - net/nimble/host/store/ram + - net/nimble/transport/ram - libs/console/full - libs/shell http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bletiny/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c index 2f3c474..38ee467 100755 --- a/apps/bletiny/src/main.c +++ b/apps/bletiny/src/main.c @@ -35,8 +35,8 @@ /* BLE */ #include "nimble/ble.h" #include "nimble/nimble_opt.h" -#include "nimble/hci_transport.h" -#include "host/host_hci.h" +#include "nimble/ble_hci_trans.h" +#include "controller/ble_ll.h" #include "host/ble_hs.h" #include "host/ble_hs_adv.h" #include "host/ble_uuid.h" @@ -45,7 +45,7 @@ #include "host/ble_gatt.h" #include "host/ble_store.h" #include "host/ble_sm.h" -#include "controller/ble_ll.h" +#include "transport/ram/ble_hci_ram.h" /* RAM persistence layer. */ #include "store/ram/ble_store_ram.h" @@ -1084,7 +1084,7 @@ bletiny_tx_timer_cb(void *arg) /* Set packet header length */ OS_MBUF_PKTHDR(om)->omp_len = om->om_len; - ble_hci_transport_host_acl_data_send(om); + ble_hci_trans_hs_acl_tx(om); --bletiny_tx_data.tx_num; } @@ -1552,6 +1552,12 @@ bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi) return 0; } +static void +bletiny_on_reset(int reason) +{ + console_printf("Error: Resetting state; reason=%d\n", reason); +} + /** * BLE test task * @@ -1594,6 +1600,7 @@ bletiny_task_handler(void *arg) int main(void) { + struct ble_hci_ram_cfg hci_cfg; struct ble_hs_cfg cfg; uint32_t seed; int rc; @@ -1688,10 +1695,17 @@ main(void) rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); + /* Initialize the RAM HCI transport. */ + hci_cfg = ble_hci_ram_cfg_dflt; + hci_cfg.num_evt_bufs = 3; + rc = ble_hci_ram_init(&hci_cfg); + assert(rc == 0); + /* Initialize the NimBLE host configuration. */ cfg = ble_hs_cfg_dflt; - cfg.max_hci_bufs = 3; + cfg.max_hci_bufs = hci_cfg.num_evt_bufs; cfg.max_gattc_procs = 2; + cfg.reset_cb = bletiny_on_reset; cfg.store_read_cb = ble_store_ram_read; cfg.store_write_cb = ble_store_ram_write; cfg.gatts_register_cb = gatt_svr_register_cb; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bleuart/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bleuart/pkg.yml b/apps/bleuart/pkg.yml index a79077f..c93011b 100644 --- a/apps/bleuart/pkg.yml +++ b/apps/bleuart/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - net/nimble/host - net/nimble/host/services/mandatory - net/nimble/host/store/ram + - net/nimble/transport/ram - libs/console/full - libs/baselibc - libs/newtmgr http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/29b69ddf/apps/bleuart/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c index 0a5dd82..f7c7714 100755 --- a/apps/bleuart/src/main.c +++ b/apps/bleuart/src/main.c @@ -195,6 +195,13 @@ bleuart_gap_event(struct ble_gap_event *event, void *arg) return 0; } +static void +bleuart_on_sync(void) +{ + /* Begin advertising. */ + bleuart_advertise(); +} + /** * Event loop for the main bleuart task. */ @@ -208,9 +215,6 @@ bleuart_task_handler(void *unused) rc = ble_hs_start(); assert(rc == 0); - /* Begin advertising. */ - bleuart_advertise(); - while (1) { ev = os_eventq_get(&bleuart_evq); @@ -298,6 +302,7 @@ main(void) cfg.sm_bonding = 1; cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC; + cfg.sync_cb = bleuart_on_sync; cfg.store_read_cb = ble_store_ram_read; cfg.store_write_cb = ble_store_ram_write;
