drivers/wireless/bluetooth: Partition bt_uart.c adding bt_uart.h and bt_uart_generic.c. This will now permit adding HCI UART drivers that have custom initialization requirements.. such as parts the need to download a configuration file to the HCI UART before they are usable.
This commit is contained in:
parent
1d044e6952
commit
9b83737821
@ -1254,6 +1254,12 @@ Configuration Sub-directories
|
||||
The command to write the initialization script into NVRAM is another
|
||||
story for another time and another place.
|
||||
|
||||
If you use a different HCI UART, you will need to modify this setting:
|
||||
|
||||
CONFIG_BLUETOOTH_UART_GENERIC=y
|
||||
|
||||
and you may have to add some support in drivers/wireless/bluetooth.
|
||||
|
||||
ipv6:
|
||||
----
|
||||
This is another version of the NuttShell configuration for the
|
||||
|
@ -18,6 +18,7 @@ CONFIG_ARCH="arm"
|
||||
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y
|
||||
CONFIG_BLUETOOTH_MAX_CONN=2
|
||||
CONFIG_BLUETOOTH_MAX_PAIRED=2
|
||||
CONFIG_BLUETOOTH_UART_BT860=y
|
||||
CONFIG_BLUETOOTH_UART=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
|
@ -1,43 +1,7 @@
|
||||
#############################################################################
|
||||
# wireless/bluetooth/Kconfig
|
||||
# Bluetooth LE driver configuration options
|
||||
#
|
||||
# Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
# Ported from the Intel/Zephyr arduino101_firmware_source-v1.tar package
|
||||
# where the code was released with a compatible 3-clause BSD license:
|
||||
#
|
||||
# Copyright (c) 2016, Intel Corporation
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
if DRIVERS_BLUETOOTH
|
||||
|
||||
@ -48,13 +12,39 @@ config BLUETOOTH_UART
|
||||
---help---
|
||||
Enable Bluetooth UART driver.
|
||||
|
||||
config BLUETOOTH_UART_GENERIC
|
||||
bool
|
||||
default n
|
||||
|
||||
if BLUETOOTH_UART
|
||||
|
||||
choice
|
||||
prompt "Bluetooth UART HCI device"
|
||||
default BLUETOOTH_UART_OTHER
|
||||
|
||||
config BLUETOOTH_UART_BT860
|
||||
bool "Laird BT860"
|
||||
select BLUETOOTH_UART_GENERIC
|
||||
|
||||
config BLUETOOTH_UART_CC2564
|
||||
bool "TI CC2564"
|
||||
depends on EXPERIMENTAL
|
||||
|
||||
config BLUETOOTH_UART_OTHER
|
||||
bool "Other generic HCI UART device"
|
||||
select BLUETOOTH_UART_GENERIC
|
||||
|
||||
endchoice # Bluetooth UART HCI device
|
||||
|
||||
config BLUETOOTH_UART_DUMP
|
||||
bool "Dump HCI UART I/O buffers"
|
||||
default n
|
||||
depends on BLUETOOTH_UART && DEBUG_WIRELESS_INFO
|
||||
depends on DEBUG_WIRELESS_INFO
|
||||
---help---
|
||||
Dump the full content of all outgoing and incoming messages.
|
||||
|
||||
endif # BLUETOOTH_UART
|
||||
|
||||
config BLUETOOTH_NULL
|
||||
bool "NULL Bluetooth device"
|
||||
default n
|
||||
|
@ -41,6 +41,9 @@ ifeq ($(CONFIG_DRIVERS_BLUETOOTH),y)
|
||||
|
||||
ifeq ($(CONFIG_BLUETOOTH_UART),y)
|
||||
CSRCS += bt_uart.c
|
||||
ifeq ($(CONFIG_BLUETOOTH_UART_GENERIC),y)
|
||||
CSRCS += bt_uart_generic.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_BLUETOOTH_NULL),y)
|
||||
|
@ -45,55 +45,17 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/wireless/bt_core.h>
|
||||
#include <nuttx/wireless/bt_hci.h>
|
||||
#include <nuttx/wireless/bt_driver.h>
|
||||
#include <nuttx/wireless/bt_uart.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define H4_HEADER_SIZE 1
|
||||
|
||||
#define H4_CMD 0x01
|
||||
#define H4_ACL 0x02
|
||||
#define H4_SCO 0x03
|
||||
#define H4_EVT 0x04
|
||||
|
||||
#ifdef CONFIG_BLUETOOTH_UART_DUMP
|
||||
# define BT_DUMP(m,b,l) lib_dumpbuffer(m,b,l)
|
||||
#else
|
||||
# define BT_DUMP(m,b,l)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct btuart_upperhalf_s
|
||||
{
|
||||
/* This structure must appear first in the structure so that this structure
|
||||
* is cast compatible with struct bt_driver_s.
|
||||
*/
|
||||
|
||||
struct bt_driver_s dev;
|
||||
|
||||
/* The cached lower half interface */
|
||||
|
||||
FAR const struct btuart_lowerhalf_s *lower;
|
||||
|
||||
/* Work queue support */
|
||||
|
||||
struct work_s work;
|
||||
volatile bool busy;
|
||||
};
|
||||
#include "bt_uart.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@ -331,8 +293,11 @@ static void btuart_rxcallback(FAR const struct btuart_lowerhalf_s *lower,
|
||||
}
|
||||
}
|
||||
|
||||
static int btuart_send(FAR const struct bt_driver_s *dev,
|
||||
FAR struct bt_buf_s *buf)
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_send(FAR const struct bt_driver_s *dev, FAR struct bt_buf_s *buf)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
FAR const struct btuart_lowerhalf_s *lower;
|
||||
@ -386,7 +351,7 @@ static int btuart_send(FAR const struct bt_driver_s *dev,
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int btuart_open(FAR const struct bt_driver_s *dev)
|
||||
int btuart_open(FAR const struct bt_driver_s *dev)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
FAR const struct btuart_lowerhalf_s *lower;
|
||||
@ -405,71 +370,12 @@ static int btuart_open(FAR const struct bt_driver_s *dev)
|
||||
|
||||
(void)lower->rxdrain(lower);
|
||||
|
||||
/* Attach the Rx event handler */
|
||||
|
||||
lower->rxattach(lower, btuart_rxcallback, upper);
|
||||
|
||||
/* Re-enable Rx callbacks */
|
||||
|
||||
lower->rxenable(lower, true);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
*
|
||||
* Description:
|
||||
* Create the UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
int ret;
|
||||
|
||||
wlinfo("lower %p\n", lower);
|
||||
|
||||
DEBUGASSERT(lower != NULL);
|
||||
|
||||
/* Allocate a new instance of the upper half driver state structure */
|
||||
|
||||
upper = (FAR struct btuart_upperhalf_s *)
|
||||
kmm_zalloc(sizeof(struct btuart_upperhalf_s));
|
||||
|
||||
if (upper == NULL)
|
||||
{
|
||||
wlerr("ERROR: Failed to allocate upper-half state\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Initialize the upper half driver state */
|
||||
|
||||
upper->dev.head_reserve = H4_HEADER_SIZE;
|
||||
upper->dev.open = btuart_open;
|
||||
upper->dev.send = btuart_send;
|
||||
upper->lower = lower;
|
||||
|
||||
/* Attach the interrupt handler */
|
||||
|
||||
lower->rxattach(lower, btuart_rxcallback, upper);
|
||||
|
||||
/* And register the driver with the network and the Bluetooth stack. */
|
||||
|
||||
ret = bt_netdev_register(&upper->dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_driver_register failed: %d\n", ret);
|
||||
kmm_free(upper);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
104
drivers/wireless/bluetooth/bt_uart.h
Normal file
104
drivers/wireless/bluetooth/bt_uart.h
Normal file
@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* drivers/wireless/bluetooth/bt_uart.h
|
||||
* UART based Bluetooth driver
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Ported from the Intel/Zephyr arduino101_firmware_source-v1.tar package
|
||||
* where the code was released with a compatible 3-clause BSD license:
|
||||
*
|
||||
* Copyright (c) 2016, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/wireless/bt_driver.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define H4_HEADER_SIZE 1
|
||||
|
||||
#define H4_CMD 0x01
|
||||
#define H4_ACL 0x02
|
||||
#define H4_SCO 0x03
|
||||
#define H4_EVT 0x04
|
||||
|
||||
#ifdef CONFIG_BLUETOOTH_UART_DUMP
|
||||
# define BT_DUMP(m,b,l) lib_dumpbuffer(m,b,l)
|
||||
#else
|
||||
# define BT_DUMP(m,b,l)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This type defines the state data generic UART upper half driver */
|
||||
|
||||
struct btuart_lowerhalf_s; /* Forward reference */
|
||||
|
||||
struct btuart_upperhalf_s
|
||||
{
|
||||
/* This structure must appear first in the structure so that this structure
|
||||
* is cast compatible with struct bt_driver_s.
|
||||
*/
|
||||
|
||||
struct bt_driver_s dev;
|
||||
|
||||
/* The cached lower half interface */
|
||||
|
||||
FAR const struct btuart_lowerhalf_s *lower;
|
||||
|
||||
/* Work queue support */
|
||||
|
||||
struct work_s work;
|
||||
volatile bool busy;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Generic implementations of HCI UART methods */
|
||||
|
||||
struct bt_buf_s; /* Forward reference */
|
||||
|
||||
int btuart_send(FAR const struct bt_driver_s *dev, FAR struct bt_buf_s *buf);
|
||||
int btuart_open(FAR const struct bt_driver_s *dev);
|
117
drivers/wireless/bluetooth/bt_uart_generic.c
Normal file
117
drivers/wireless/bluetooth/bt_uart_generic.c
Normal file
@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
* drivers/wireless/bluetooth/bt_uart_generic.c
|
||||
* Generic UART based Bluetooth driver
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/wireless/bt_uart.h>
|
||||
|
||||
#if 0
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/wireless/bt_core.h>
|
||||
#include <nuttx/wireless/bt_hci.h>
|
||||
#include <nuttx/wireless/bt_driver.h>
|
||||
#endif
|
||||
|
||||
#include "bt_uart.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btuart_register
|
||||
*
|
||||
* Description:
|
||||
* Create the UART-based Bluetooth device and register it with the
|
||||
* Bluetooth stack.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - an instance of the lower half driver interface
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success; a negated errno value is returned on any
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
||||
{
|
||||
FAR struct btuart_upperhalf_s *upper;
|
||||
int ret;
|
||||
|
||||
wlinfo("lower %p\n", lower);
|
||||
|
||||
DEBUGASSERT(lower != NULL);
|
||||
|
||||
/* Allocate a new instance of the upper half driver state structure */
|
||||
|
||||
upper = (FAR struct btuart_upperhalf_s *)
|
||||
kmm_zalloc(sizeof(struct btuart_upperhalf_s));
|
||||
|
||||
if (upper == NULL)
|
||||
{
|
||||
wlerr("ERROR: Failed to allocate upper-half state\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Initialize the upper half driver state */
|
||||
|
||||
upper->dev.head_reserve = H4_HEADER_SIZE;
|
||||
upper->dev.open = btuart_open;
|
||||
upper->dev.send = btuart_send;
|
||||
upper->lower = lower;
|
||||
|
||||
/* And register the driver with the network and the Bluetooth stack. */
|
||||
|
||||
ret = bt_netdev_register(&upper->dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: bt_driver_register failed: %d\n", ret);
|
||||
kmm_free(upper);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user