[2/2] incubator-mynewt-core git commit: MYNEWT-388: HCI uart should not assert if a command, event or ACL buffer not available
MYNEWT-388: HCI uart should not assert if a command, event or ACL buffer not available There were a number of changes committed to fix a few BLE HCI issues 1) On HCI sync loss, the controller will now send a HW error and wait to find a reset command in the byyte stream in order to re-sync. 2) If no ACL data buffer available, the ACL packet is skipped and a data buffer overflow event is sent. 3) If no command buffer is available, the current command is simply skipped. No response is sent in this case. The spec was not clear and since this should never happen we simply decided to skip the command. 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/aed4343e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/aed4343e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/aed4343e Branch: refs/heads/develop Commit: aed4343e6047a4c837b1db89ac4d6d9500ec8a41 Parents: 622b462 Author: William San FilippoAuthored: Fri Sep 16 16:39:43 2016 -0700 Committer: William San Filippo Committed: Fri Sep 16 16:43:46 2016 -0700 -- apps/blehci/src/main.c | 20 +- .../controller/include/controller/ble_ll.h | 13 + .../controller/include/controller/ble_ll_ctrl.h | 3 + net/nimble/controller/src/ble_ll.c | 53 +++ net/nimble/controller/src/ble_ll_hci_ev.c | 44 +++ net/nimble/include/nimble/ble.h | 4 + net/nimble/include/nimble/hci_common.h | 4 + .../uart/include/transport/uart/ble_hci_uart.h | 4 +- net/nimble/transport/uart/src/ble_hci_uart.c| 377 --- 9 files changed, 465 insertions(+), 57 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aed4343e/apps/blehci/src/main.c -- diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c index 0dd77e8..52aab99 100755 --- a/apps/blehci/src/main.c +++ b/apps/blehci/src/main.c @@ -23,6 +23,7 @@ /* BLE */ #include "nimble/ble.h" +#include "nimble/hci_common.h" #include "controller/ble_ll.h" #include "transport/uart/ble_hci_uart.h" @@ -41,8 +42,6 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = { 0 }; /* Our random address (in case we need it) */ uint8_t g_random_addr[BLE_DEV_ADDR_LEN] = { 0 }; -#define HCI_MAX_BUFS(5) - os_membuf_t default_mbuf_mpool_data[MBUF_MEMPOOL_SIZE]; struct os_mbuf_pool default_mbuf_pool; @@ -51,7 +50,7 @@ struct os_mempool default_mbuf_mpool; int main(void) { -const struct ble_hci_uart_cfg *hci_cfg; +struct ble_hci_uart_cfg hci_cfg; int rc; /* Initialize OS */ @@ -74,12 +73,19 @@ main(void) assert(rc == 0); /* Initialize the BLE LL */ -hci_cfg = _hci_uart_cfg_dflt; -rc = ble_ll_init(BLE_LL_TASK_PRI, hci_cfg->num_acl_bufs, - BLE_MBUF_PAYLOAD_SIZE); +hci_cfg = ble_hci_uart_cfg_dflt; +rc = ble_ll_init(BLE_LL_TASK_PRI, hci_cfg.num_acl_bufs, + BLE_MBUF_PAYLOAD_SIZE - BLE_HCI_DATA_HDR_SZ); assert(rc == 0); -rc = ble_hci_uart_init(hci_cfg); +/* + * XXX: for now, the developer MUST configure the number of msys buffers + * and not rely on the default value. The number of msys buffers must + * be >= to the number of pool elements registered to os_msys. In this + * project, we only register the default mbuf pool. + */ +hci_cfg.num_msys_bufs = MBUF_NUM_MBUFS; +rc = ble_hci_uart_init(_cfg); assert(rc == 0); /* Start the OS */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aed4343e/net/nimble/controller/include/controller/ble_ll.h -- diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h index 7865cf8..ee4fe24 100644 --- a/net/nimble/controller/include/controller/ble_ll.h +++ b/net/nimble/controller/include/controller/ble_ll.h @@ -76,6 +76,12 @@ struct ble_ll_obj /* Packet transmit queue */ struct os_event ll_tx_pkt_ev; struct ble_ll_pkt_q ll_tx_pkt_q; + +/* Data buffer overflow event */ +struct os_event ll_dbuf_overflow_ev; + +/* HW error callout */ +struct os_callout_func ll_hw_err_timer; }; extern struct ble_ll_obj g_ble_ll_data; @@ -130,6 +136,7 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats; #define BLE_LL_EVENT_CONN_SPVN_TMO (OS_EVENT_T_PERUSER + 4) #define BLE_LL_EVENT_CONN_EV_END(OS_EVENT_T_PERUSER + 5) #define BLE_LL_EVENT_TX_PKT_IN (OS_EVENT_T_PERUSER + 6) +#define BLE_LL_EVENT_DBUF_OVERFLOW (OS_EVENT_T_PERUSER + 7) /* LL Features */ #define BLE_LL_FEAT_LE_ENCRYPTION (0x01) @@
[2/2] incubator-mynewt-core git commit: MYNEWT-388: HCI uart should not assert if a command, event or ACL buffer not available
MYNEWT-388: HCI uart should not assert if a command, event or ACL buffer not available There were a number of changes committed to fix a few BLE HCI issues 1) On HCI sync loss, the controller will now send a HW error and wait to find a reset command in the byyte stream in order to re-sync. 2) If no ACL data buffer available, the ACL packet is skipped and a data buffer overflow event is sent. 3) If no command buffer is available, the current command is simply skipped. No response is sent in this case. The spec was not clear and since this should never happen we simply decided to skip the command. 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/473e050f Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/473e050f Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/473e050f Branch: refs/heads/master Commit: 473e050f7fde744ad198d9ce3234115fa5940750 Parents: dd79d93 Author: William San FilippoAuthored: Fri Sep 16 16:39:43 2016 -0700 Committer: William San Filippo Committed: Fri Sep 16 16:39:43 2016 -0700 -- apps/blehci/src/main.c | 20 +- .../controller/include/controller/ble_ll.h | 13 + .../controller/include/controller/ble_ll_ctrl.h | 3 + net/nimble/controller/src/ble_ll.c | 53 +++ net/nimble/controller/src/ble_ll_hci_ev.c | 44 +++ net/nimble/include/nimble/ble.h | 4 + net/nimble/include/nimble/hci_common.h | 4 + .../uart/include/transport/uart/ble_hci_uart.h | 4 +- net/nimble/transport/uart/src/ble_hci_uart.c| 377 --- 9 files changed, 465 insertions(+), 57 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/473e050f/apps/blehci/src/main.c -- diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c index 0dd77e8..52aab99 100755 --- a/apps/blehci/src/main.c +++ b/apps/blehci/src/main.c @@ -23,6 +23,7 @@ /* BLE */ #include "nimble/ble.h" +#include "nimble/hci_common.h" #include "controller/ble_ll.h" #include "transport/uart/ble_hci_uart.h" @@ -41,8 +42,6 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = { 0 }; /* Our random address (in case we need it) */ uint8_t g_random_addr[BLE_DEV_ADDR_LEN] = { 0 }; -#define HCI_MAX_BUFS(5) - os_membuf_t default_mbuf_mpool_data[MBUF_MEMPOOL_SIZE]; struct os_mbuf_pool default_mbuf_pool; @@ -51,7 +50,7 @@ struct os_mempool default_mbuf_mpool; int main(void) { -const struct ble_hci_uart_cfg *hci_cfg; +struct ble_hci_uart_cfg hci_cfg; int rc; /* Initialize OS */ @@ -74,12 +73,19 @@ main(void) assert(rc == 0); /* Initialize the BLE LL */ -hci_cfg = _hci_uart_cfg_dflt; -rc = ble_ll_init(BLE_LL_TASK_PRI, hci_cfg->num_acl_bufs, - BLE_MBUF_PAYLOAD_SIZE); +hci_cfg = ble_hci_uart_cfg_dflt; +rc = ble_ll_init(BLE_LL_TASK_PRI, hci_cfg.num_acl_bufs, + BLE_MBUF_PAYLOAD_SIZE - BLE_HCI_DATA_HDR_SZ); assert(rc == 0); -rc = ble_hci_uart_init(hci_cfg); +/* + * XXX: for now, the developer MUST configure the number of msys buffers + * and not rely on the default value. The number of msys buffers must + * be >= to the number of pool elements registered to os_msys. In this + * project, we only register the default mbuf pool. + */ +hci_cfg.num_msys_bufs = MBUF_NUM_MBUFS; +rc = ble_hci_uart_init(_cfg); assert(rc == 0); /* Start the OS */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/473e050f/net/nimble/controller/include/controller/ble_ll.h -- diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h index 7865cf8..ee4fe24 100644 --- a/net/nimble/controller/include/controller/ble_ll.h +++ b/net/nimble/controller/include/controller/ble_ll.h @@ -76,6 +76,12 @@ struct ble_ll_obj /* Packet transmit queue */ struct os_event ll_tx_pkt_ev; struct ble_ll_pkt_q ll_tx_pkt_q; + +/* Data buffer overflow event */ +struct os_event ll_dbuf_overflow_ev; + +/* HW error callout */ +struct os_callout_func ll_hw_err_timer; }; extern struct ble_ll_obj g_ble_ll_data; @@ -130,6 +136,7 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats; #define BLE_LL_EVENT_CONN_SPVN_TMO (OS_EVENT_T_PERUSER + 4) #define BLE_LL_EVENT_CONN_EV_END(OS_EVENT_T_PERUSER + 5) #define BLE_LL_EVENT_TX_PKT_IN (OS_EVENT_T_PERUSER + 6) +#define BLE_LL_EVENT_DBUF_OVERFLOW (OS_EVENT_T_PERUSER + 7) /* LL Features */ #define BLE_LL_FEAT_LE_ENCRYPTION (0x01) @@