Bluetooth: Make BT buffers connection support optional

This allows to reduce BT buffers used if connection
support is disabled.

Sample beacon application size reduced from 15212 to 14956 bytes.

Change-Id: I431ea5087706a06eaea76d572839c3afebfb963e
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2015-09-16 14:54:20 +02:00 committed by Anas Nashif
commit c0650518d6
2 changed files with 36 additions and 3 deletions

View file

@ -51,13 +51,21 @@
#endif
/* Total number of all types of buffers */
#if defined(CONFIG_BLUETOOTH_CONN)
#define NUM_BUFS 22
#else
#define NUM_BUFS 8
#endif /* CONFIG_BLUETOOTH_CONN */
static struct bt_buf buffers[NUM_BUFS];
/* Available (free) buffers queues */
static struct nano_fifo avail_hci;
#if defined(CONFIG_BLUETOOTH_CONN)
static struct nano_fifo avail_acl_in;
static struct nano_fifo avail_acl_out;
#endif /* CONFIG_BLUETOOTH_CONN */
static struct nano_fifo *get_avail(enum bt_buf_type type)
{
@ -65,10 +73,12 @@ static struct nano_fifo *get_avail(enum bt_buf_type type)
case BT_CMD:
case BT_EVT:
return &avail_hci;
#if defined(CONFIG_BLUETOOTH_CONN)
case BT_ACL_IN:
return &avail_acl_in;
case BT_ACL_OUT:
return &avail_acl_out;
#endif /* CONFIG_BLUETOOTH_CONN */
default:
return NULL;
}
@ -76,11 +86,16 @@ static struct nano_fifo *get_avail(enum bt_buf_type type)
struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head)
{
struct nano_fifo *avail = get_avail(type);
struct nano_fifo *avail;
struct bt_buf *buf;
BT_DBG("type %d reserve %u\n", type, reserve_head);
avail = get_avail(type);
if (!avail) {
return NULL;
}
buf = nano_fifo_get(avail);
if (!buf) {
if (sys_execution_context_type_get() == NANO_CTX_ISR) {
@ -103,8 +118,10 @@ struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head)
return buf;
}
#if defined(CONFIG_BLUETOOTH_CONN)
static void report_completed_packet(struct bt_buf *buf)
{
struct bt_hci_cp_host_num_completed_packets *cp;
struct bt_hci_handle_count *hc;
uint16_t handle;
@ -130,6 +147,7 @@ static void report_completed_packet(struct bt_buf *buf)
bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
}
#endif /* CONFIG_BLUETOOTH_CONN */
void bt_buf_put(struct bt_buf *buf)
{
@ -141,10 +159,18 @@ void bt_buf_put(struct bt_buf *buf)
return;
}
#if defined(CONFIG_BLUETOOTH_CONN)
if (avail == &avail_acl_in) {
report_completed_packet(buf);
return;
}
#endif /* CONFIG_BLUETOOTH_CONN */
/* Even if connection support is disabled avail shall always be not
* null. It is required to first get bt_buf with specific type to be
* able to put it. If connection support is disabled get returns NULL.
*/
BT_ASSERT(avail);
nano_fifo_put(avail, buf);
}
@ -234,7 +260,7 @@ size_t bt_buf_tailroom(struct bt_buf *buf)
int bt_buf_init(int acl_in, int acl_out)
{
int i;
int i = 0;
/* Check that we have enough buffers configured */
if (acl_out + acl_in >= NUM_BUFS - 2) {
@ -245,8 +271,9 @@ int bt_buf_init(int acl_in, int acl_out)
BT_DBG("Available bufs: ACL in: %d, ACL out: %d, cmds/evts: %d\n",
acl_in, acl_out, NUM_BUFS - (acl_in + acl_out));
#if defined(CONFIG_BLUETOOTH_CONN)
nano_fifo_init(&avail_acl_in);
for (i = 0; acl_in > 0; i++, acl_in--) {
for (; acl_in > 0; i++, acl_in--) {
nano_fifo_put(&avail_acl_in, &buffers[i]);
}
@ -254,6 +281,7 @@ int bt_buf_init(int acl_in, int acl_out)
for (; acl_out > 0; i++, acl_out--) {
nano_fifo_put(&avail_acl_out, &buffers[i]);
}
#endif /* CONFIG_BLUETOOTH_CONN */
nano_fifo_init(&avail_hci);
for (; i < NUM_BUFS; i++) {

View file

@ -57,8 +57,13 @@
#endif
/* How many buffers to use for incoming ACL data */
#if defined(CONFIG_BLUETOOTH_CONN)
#define ACL_IN_MAX 7
#define ACL_OUT_MAX 7
#else
#define ACL_IN_MAX 0
#define ACL_OUT_MAX 0
#endif /* CONFIG_BLUETOOTH_CONN */
/* Stacks for the fibers */
static BT_STACK_NOINIT(rx_fiber_stack, 1024);