2019-09-21 15:16:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/wireless/bluetooth/bt_uart_shim.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Dave Marples <dave@marples.net>
|
|
|
|
*
|
|
|
|
* 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 NuttX 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 OWNER 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 <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2020-12-27 12:15:58 +01:00
|
|
|
#include <termios.h>
|
2019-09-21 15:16:37 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/fs/ioctl.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/kthread.h>
|
|
|
|
#include <nuttx/semaphore.h>
|
|
|
|
#include <nuttx/serial/tioctl.h>
|
2019-10-04 17:29:51 +02:00
|
|
|
#include <nuttx/wireless/bluetooth/bt_uart_shim.h>
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This structure is the variable state of the binding to the UART */
|
|
|
|
|
|
|
|
struct hciuart_state_s
|
2019-10-04 17:29:51 +02:00
|
|
|
{
|
|
|
|
/* Registered Rx callback */
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
btuart_rxcallback_t callback; /* Rx callback function */
|
|
|
|
FAR void *arg; /* Rx callback argument */
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 16:02:13 +01:00
|
|
|
struct file f; /* File structure */
|
2019-10-04 17:29:51 +02:00
|
|
|
bool enabled; /* Flag indicating that reception is enabled */
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
int serialmontask; /* The receive serial octets task handle */
|
|
|
|
};
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
struct hciuart_config_s
|
2019-10-04 17:29:51 +02:00
|
|
|
{
|
|
|
|
/* Setup the interface from the upper to the lower */
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
struct btuart_lowerhalf_s lower; /* Generic UART lower half */
|
|
|
|
struct hciuart_state_s state; /* Variable state */
|
|
|
|
};
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* UART Lower-Half Methods */
|
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
static void hciuart_rxattach(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
btuart_rxcallback_t callback, FAR void *arg);
|
|
|
|
static void hciuart_rxenable(FAR const struct btuart_lowerhalf_s *lower,
|
2019-09-21 15:16:37 +02:00
|
|
|
bool enable);
|
2019-10-04 17:29:51 +02:00
|
|
|
static int hciuart_setbaud(FAR const struct btuart_lowerhalf_s *lower,
|
2019-09-21 15:16:37 +02:00
|
|
|
uint32_t baud);
|
2019-10-04 17:29:51 +02:00
|
|
|
static ssize_t hciuart_read(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
FAR void *buffer, size_t buflen);
|
|
|
|
static ssize_t hciuart_write(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
FAR const void *buffer, size_t buflen);
|
|
|
|
static ssize_t hciuart_rxdrain(FAR const struct btuart_lowerhalf_s *lower);
|
|
|
|
|
2019-09-21 15:16:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_rxattach
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Attach/detach the upper half Rx callback.
|
|
|
|
*
|
|
|
|
* rxattach() allows the upper half logic to attach a callback function
|
|
|
|
* that will be used to inform the upper half that an Rx frame is
|
|
|
|
* available. This callback will, most likely, be invoked in the
|
|
|
|
* context of an interrupt callback. The receive() method should then
|
|
|
|
* be invoked in order to receive the obtain the Rx frame data.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2019-10-04 17:29:51 +02:00
|
|
|
hciuart_rxattach(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
btuart_rxcallback_t callback, FAR void *arg)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 12:15:58 +01:00
|
|
|
struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
2019-09-21 15:16:37 +02:00
|
|
|
struct hciuart_state_s *state;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
state = &config->state;
|
|
|
|
|
|
|
|
/* If the callback is NULL, then we are detaching */
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2019-09-21 15:16:37 +02:00
|
|
|
if (callback == NULL)
|
|
|
|
{
|
|
|
|
/* Disable Rx callbacks and detach the Rx callback */
|
|
|
|
|
|
|
|
state->callback = NULL;
|
|
|
|
state->arg = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, we are attaching */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->arg = arg;
|
|
|
|
state->callback = callback;
|
|
|
|
}
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_rxenable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable/disable RX callbacks from the HCI UART.
|
|
|
|
*
|
|
|
|
* hciuart_rxenable() may be used to enable or disable callback events.
|
|
|
|
* This probably translates to enabling and disabled Rx interrupts at
|
|
|
|
* the UART. NOTE: Rx event notification should be done sparingly:
|
|
|
|
* Rx data overrun may occur when Rx events are disabled!
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
static void hciuart_rxenable(FAR const struct btuart_lowerhalf_s *lower,
|
2019-09-21 15:16:37 +02:00
|
|
|
bool enable)
|
|
|
|
{
|
2019-10-04 17:29:51 +02:00
|
|
|
FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
|
|
|
FAR struct hciuart_state_s *s = &config->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
irqstate_t flags = spin_lock_irqsave(NULL);
|
2019-10-04 17:29:51 +02:00
|
|
|
if (enable != s->enabled)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 12:15:58 +01:00
|
|
|
wlinfo(enable ? "Enable\n" : "Disable\n");
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
s->enabled = enable;
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_setbaud
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The HCI UART comes up with some initial BAUD rate. Some support
|
|
|
|
* auto-BAUD detection, some support writing a configuration file to
|
|
|
|
* select the initial BAUD. The simplest strategy, however, is simply
|
|
|
|
* to use the HCI UART's default initial BAUD to perform the basic
|
|
|
|
* bring up, then send a vendor-specific command to increase the HCI
|
|
|
|
* UARTs BAUD. This method then may be used to adjust the lower half
|
|
|
|
* driver to the new HCI UART BAUD.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int
|
2019-10-04 17:29:51 +02:00
|
|
|
hciuart_setbaud(FAR const struct btuart_lowerhalf_s *lower, uint32_t baud)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 12:15:58 +01:00
|
|
|
#ifdef CONFIG_SERIAL_TERMIOS
|
2019-10-04 17:29:51 +02:00
|
|
|
FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
|
|
|
FAR struct hciuart_state_s *state = &config->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
struct termios tio;
|
2020-12-27 12:15:58 +01:00
|
|
|
int ret;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
ret = file_ioctl(&state->f, TCGETS, (long unsigned int)&tio);
|
|
|
|
if (ret)
|
|
|
|
{
|
2020-05-17 16:47:40 +02:00
|
|
|
wlerr("ERROR during TCGETS\n");
|
2019-09-21 15:16:37 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baud != 0)
|
|
|
|
{
|
|
|
|
cfsetspeed(&tio, baud);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To be a H4 interface, CTS/RTS are needed */
|
|
|
|
|
|
|
|
tio.c_cflag |= CRTS_IFLOW | CCTS_OFLOW;
|
|
|
|
|
2020-12-27 12:15:58 +01:00
|
|
|
ret = file_ioctl(&state->f, TCSETS, (unsigned long int)&tio);
|
2019-09-21 15:16:37 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2020-05-17 16:47:40 +02:00
|
|
|
wlerr("ERROR during TCSETS, does UART support CTS/RTS?\n");
|
2019-09-21 15:16:37 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
2020-12-27 12:15:58 +01:00
|
|
|
#else
|
|
|
|
return -ENOSYS;
|
|
|
|
#endif
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_read
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read UART data.
|
|
|
|
*
|
|
|
|
* hciuart_read() after receipt of a callback notifying the upper half of
|
|
|
|
* the availability of Rx frame, the upper half may call the receive()
|
|
|
|
* method in order to obtain the buffered Rx frame data.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t
|
2019-10-04 17:29:51 +02:00
|
|
|
hciuart_read(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
FAR void *buffer, size_t buflen)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2019-10-04 17:29:51 +02:00
|
|
|
FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
|
|
|
FAR struct hciuart_state_s *state = &config->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
wlinfo("config %p buffer %p buflen %lu\n",
|
2020-12-27 12:15:58 +01:00
|
|
|
config, buffer, (unsigned long)buflen);
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
/* NOTE: This assumes that the caller has exclusive access to the Rx
|
|
|
|
* buffer, i.e., one lower half instance can server only one upper half!
|
2019-09-21 15:16:37 +02:00
|
|
|
*/
|
|
|
|
|
2020-12-27 12:15:58 +01:00
|
|
|
return file_read(&state->f, buffer, buflen);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write UART data.
|
|
|
|
*
|
|
|
|
* hciuart_write() will add the outgoing frame to the Tx buffer and will
|
|
|
|
* return immediately. This function may block only in the event that
|
|
|
|
* there is insufficient buffer space to hold the Tx frame data. In that
|
|
|
|
* case the lower half will block until there is sufficient to buffer
|
|
|
|
* the entire outgoing packet.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t
|
2019-10-04 17:29:51 +02:00
|
|
|
hciuart_write(FAR const struct btuart_lowerhalf_s *lower,
|
|
|
|
FAR const void *buffer, size_t buflen)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 12:15:58 +01:00
|
|
|
FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
|
|
|
FAR struct hciuart_state_s *state = &config->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
wlinfo("config %p buffer %p buflen %lu\n",
|
2020-12-27 12:15:58 +01:00
|
|
|
config, buffer, (unsigned long)buflen);
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 12:15:58 +01:00
|
|
|
return file_write(&state->f, buffer, buflen);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hciuart_rxdrain
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Flush/drain all buffered RX data
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-04 17:29:51 +02:00
|
|
|
static ssize_t hciuart_rxdrain(FAR const struct btuart_lowerhalf_s *lower)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2019-10-04 17:29:51 +02:00
|
|
|
FAR struct hciuart_config_s *config = (FAR struct hciuart_config_s *)lower;
|
|
|
|
FAR struct hciuart_state_s *s = &config->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 12:15:58 +01:00
|
|
|
return file_ioctl(&s->f, TCDRN, 0);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: hcicollecttask
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Loop and alert when serial data arrive
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int hcicollecttask(int argc, FAR char **argv)
|
|
|
|
{
|
2020-12-27 10:16:21 +01:00
|
|
|
FAR struct hciuart_config_s *n;
|
|
|
|
FAR struct hciuart_state_s *s;
|
2020-12-27 16:02:13 +01:00
|
|
|
struct pollfd p;
|
2020-12-27 10:16:21 +01:00
|
|
|
|
|
|
|
n = (FAR struct hciuart_config_s *)
|
|
|
|
((uintptr_t)strtoul(argv[1], NULL, 0));
|
|
|
|
s = &n->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 16:02:13 +01:00
|
|
|
/* Put materials into poll structure */
|
|
|
|
|
|
|
|
p.ptr = &s->f;
|
|
|
|
p.events = POLLIN | POLLFILE;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
{
|
|
|
|
/* Wait for data to arrive */
|
|
|
|
|
2020-12-27 16:02:13 +01:00
|
|
|
int ret = nx_poll(&p, 1, -1);
|
2019-09-21 15:16:37 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
wlwarn("Poll interrupted %d\n", ret);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-27 16:02:13 +01:00
|
|
|
wlinfo("Poll completed %d\n", p.revents);
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
/* Given the nature of file_poll, there are multiple reasons why
|
|
|
|
* we might be here, so make sure we only consider the read.
|
|
|
|
*/
|
|
|
|
|
2020-12-27 16:02:13 +01:00
|
|
|
if (p.revents & POLLIN)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
|
|
|
if (!s->enabled)
|
|
|
|
{
|
|
|
|
/* We aren't expected to be listening, so drop these data */
|
|
|
|
|
|
|
|
wlwarn("Dropping data\n");
|
2020-12-27 10:16:21 +01:00
|
|
|
hciuart_rxdrain(&n->lower);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s->callback != NULL)
|
|
|
|
{
|
|
|
|
wlinfo("Activating callback\n");
|
2020-12-27 10:16:21 +01:00
|
|
|
s->callback(&n->lower, s->arg);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wlwarn("Dropping data (no CB)\n");
|
2020-12-27 10:16:21 +01:00
|
|
|
hciuart_rxdrain(&n->lower);
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2021-01-17 20:58:53 +01:00
|
|
|
* Name: btuart_shim_getdevice
|
2019-09-21 15:16:37 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get a pointer to the device that will be used to communicate with the
|
|
|
|
* regular serial port on the HCI.
|
|
|
|
*
|
2019-10-04 17:29:51 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* Entry in filesystem hierarchy for device
|
2019-09-21 15:16:37 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to device interface
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-01-17 20:58:53 +01:00
|
|
|
FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 10:16:21 +01:00
|
|
|
FAR struct hciuart_config_s *n;
|
2019-10-04 17:29:51 +02:00
|
|
|
FAR struct hciuart_state_s *s;
|
2020-12-27 10:16:21 +01:00
|
|
|
FAR char *argv[2];
|
|
|
|
char arg1[16];
|
2020-09-21 09:02:23 +02:00
|
|
|
int ret;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
|
|
|
/* Get the memory for this shim instance */
|
|
|
|
|
2020-12-27 10:16:21 +01:00
|
|
|
n = (FAR struct hciuart_config_s *)
|
2020-05-17 16:47:40 +02:00
|
|
|
kmm_zalloc(sizeof(struct hciuart_config_s));
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 10:16:21 +01:00
|
|
|
if (!n)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 10:16:21 +01:00
|
|
|
return NULL;
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
2020-12-27 10:16:21 +01:00
|
|
|
s = &n->state;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-09-21 09:02:23 +02:00
|
|
|
ret = file_open(&s->f, path, O_RDWR | O_BINARY);
|
|
|
|
if (ret < 0)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2020-12-27 10:16:21 +01:00
|
|
|
kmm_free(n);
|
|
|
|
return NULL;
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hook the routines in */
|
|
|
|
|
2020-12-27 11:54:24 +01:00
|
|
|
n->lower.rxattach = hciuart_rxattach;
|
|
|
|
n->lower.rxenable = hciuart_rxenable;
|
|
|
|
n->lower.setbaud = hciuart_setbaud;
|
|
|
|
n->lower.read = hciuart_read;
|
|
|
|
n->lower.write = hciuart_write;
|
|
|
|
n->lower.rxdrain = hciuart_rxdrain;
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 10:16:21 +01:00
|
|
|
/* Create the monitor thread */
|
|
|
|
|
|
|
|
snprintf(arg1, 16, "%p", n);
|
|
|
|
argv[0] = arg1;
|
|
|
|
argv[1] = NULL;
|
|
|
|
|
2019-10-08 15:55:47 +02:00
|
|
|
s->serialmontask = kthread_create("BT HCI Rx",
|
2019-09-21 15:16:37 +02:00
|
|
|
CONFIG_BLUETOOTH_TXCONN_PRIORITY,
|
2020-12-27 10:31:31 +01:00
|
|
|
CONFIG_DEFAULT_TASK_STACKSIZE,
|
|
|
|
hcicollecttask, argv);
|
2019-09-21 15:16:37 +02:00
|
|
|
|
2020-12-27 10:16:21 +01:00
|
|
|
return (FAR struct btuart_lowerhalf_s *)n;
|
2019-09-21 15:16:37 +02:00
|
|
|
}
|