From 4953ea50d0a565c4495b84db16d6f2bea5070f95 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 15 Jun 2017 10:31:06 +0200 Subject: [PATCH] Bluetooth: Enforce cooperative priorities in Bluetooth threads The Bluetooth subsystem assumes execution of its system threads in cooperative priority, including the system workqueue and the thread that interact with the controller (i.e. calling bt_send). This commit adds a compile-time check for the system workqueue priority and documentation for the bt_send API call. Signed-off-by: Carles Cufi --- include/drivers/bluetooth/hci_driver.h | 2 ++ subsys/bluetooth/common/Makefile | 1 + subsys/bluetooth/common/dummy.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 subsys/bluetooth/common/dummy.c diff --git a/include/drivers/bluetooth/hci_driver.h b/include/drivers/bluetooth/hci_driver.h index 56c7e6d4cedeb3..da1bc6ae0ce44b 100644 --- a/include/drivers/bluetooth/hci_driver.h +++ b/include/drivers/bluetooth/hci_driver.h @@ -134,6 +134,8 @@ struct bt_hci_driver { * Send an HCI command or ACL data to the controller. The exact * type of the data can be checked with the help of bt_buf_get_type(). * + * @note This function must only be called from a cooperative thread. + * * @param buf Buffer containing data to be sent to the controller. * * @return 0 on success or negative error number on failure. diff --git a/subsys/bluetooth/common/Makefile b/subsys/bluetooth/common/Makefile index b0097f5f7002f8..d8415350b0d550 100644 --- a/subsys/bluetooth/common/Makefile +++ b/subsys/bluetooth/common/Makefile @@ -1,4 +1,5 @@ ccflags-y += -I$(srctree)/subsys/bluetooth +obj-y += dummy.o obj-$(CONFIG_BLUETOOTH_DEBUG) += log.o obj-$(CONFIG_BLUETOOTH_RPA) += rpa.o diff --git a/subsys/bluetooth/common/dummy.c b/subsys/bluetooth/common/dummy.c new file mode 100644 index 00000000000000..9349262005ceeb --- /dev/null +++ b/subsys/bluetooth/common/dummy.c @@ -0,0 +1,19 @@ +/** + * @file dummy.c + * Static compilation checks. + */ + +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* The Bluetooth subsystem requires the system workqueue to execute at a + * cooperative priority to function correctly. If this build assert triggers + * verify your configuration to ensure that cooperative threads are enabled + * and that the system workqueue priority is negative (cooperative). + */ +BUILD_ASSERT(CONFIG_SYSTEM_WORKQUEUE_PRIORITY < 0);