Skip to content

samples: Bluetooth: hci_uart: Implement NOP Command Complete #14682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/bluetooth/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ struct bt_hci_cmd_hdr {
/* Construct OpCode from OGF and OCF */
#define BT_OP(ogf, ocf) ((ocf) | ((ogf) << 10))

/* Invalid opcode */
#define BT_OP_NOP 0x0000

/* Obtain OGF from OpCode */
#define BT_OGF(opcode) (((opcode) >> 10) & BIT_MASK(6))
/* Obtain OCF from OpCode */
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/hci_uart/microbit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ CONFIG_IDLE_STACK_SIZE=256
CONFIG_ISR_STACK_SIZE=512
CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_BT_MAX_CONN=20
CONFIG_BT_MAX_CONN=16
27 changes: 27 additions & 0 deletions samples/bluetooth/hci_uart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,33 @@ void main(void)

/* Enable the raw interface, this will in turn open the HCI driver */
bt_enable_raw(&rx_queue);

if (IS_ENABLED(CONFIG_BT_WAIT_NOP)) {
/* Issue a Command Complete with NOP */
int i;

const struct {
const u8_t h4;
const struct bt_hci_evt_hdr hdr;
const struct bt_hci_evt_cmd_complete cc;
} __packed cc_evt = {
.h4 = H4_EVT,
.hdr = {
.evt = BT_HCI_EVT_CMD_COMPLETE,
.len = sizeof(struct bt_hci_evt_cmd_complete),
},
.cc = {
.ncmd = 1,
.opcode = sys_cpu_to_le16(BT_OP_NOP),
},
};

for (i = 0; i < sizeof(cc_evt); i++) {
uart_poll_out(hci_uart_dev,
*(((const u8_t *)&cc_evt)+i));
}
}

/* Spawn the TX thread and start feeding commands and data to the
* controller
*/
Expand Down
7 changes: 7 additions & 0 deletions subsys/bluetooth/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ config BT_HCI_MESH_EXT
help
Enable support for the Bluetooth Mesh HCI Commands.

config BT_WAIT_NOP
bool "Wait for \"NOP\" Command Complete event during init"
help
Emit a Command Complete event from the Controller (and wait for it
from the Host) for the NOP opcode to indicate that the Controller is
ready to receive commands.

config BT_RPA
# Virtual/hidden option
bool
Expand Down
8 changes: 0 additions & 8 deletions subsys/bluetooth/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ config BT_HCI_TX_PRIO
int
default 7

config BT_WAIT_NOP
bool "Wait for \"NOP\" Command Complete event during init"
help
Some controllers emit a Command Complete event for the NOP
opcode to indicate that they're ready to receive commands.
This option should be selected if the controller used
exhibits such behavior.

config BT_HCI_RESERVE
int
default 0 if BT_H4
Expand Down