arch/sim: remove BT uart implement
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
1965485167
commit
6837d4e1ba
@ -544,21 +544,6 @@ config SIM_HCISOCKET
|
||||
control of the device, but is abstracted from the
|
||||
physical interface which is still handled by Linux.
|
||||
|
||||
config SIM_BTUART
|
||||
bool "Attach Host Bluetooth As TTY Device"
|
||||
default false
|
||||
depends on (DRIVERS_BLUETOOTH && HOST_LINUX && SIM_WALLTIME)
|
||||
select BLUETOOTH_UART_SHIM if BLUETOOTH_UART
|
||||
---help---
|
||||
Attached the local bluetooth device to the simulation
|
||||
target via HCI_CHANNEL_USER. This gives NuttX full
|
||||
control of the device, but is abstracted from the
|
||||
physical interface which is still handled by Linux.
|
||||
Unlike SIM_HCISOCKET, BTUART will wrap the bluetooth
|
||||
interface/controller as a TTY device, which provides
|
||||
an option for developers to setup the bluetooth host in
|
||||
userspace.
|
||||
|
||||
config SIM_I2CBUS
|
||||
bool "Simulated I2C Bus"
|
||||
default n
|
||||
|
@ -204,11 +204,6 @@ ifeq ($(CONFIG_SIM_HCISOCKET),y)
|
||||
CSRCS += up_hcisocket.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SIM_BTUART),y)
|
||||
HOSTSRCS += up_hcisocket_host.c
|
||||
CSRCS += up_btuart.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_I2C_RESET),y)
|
||||
HOSTCFLAGS += -DCONFIG_I2C_RESET=1
|
||||
endif
|
||||
|
@ -1,439 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/sim/up_btuart.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/nuttx.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include <queue.h>
|
||||
|
||||
#include <nuttx/wireless/bluetooth/bt_uart.h>
|
||||
#include <nuttx/wireless/bluetooth/bt_hci.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
#include "up_hcisocket_host.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_HCI_RECVBUF_SIZE 1024
|
||||
#define CONFIG_HCI_SENDBUF_SIZE 1024
|
||||
#define CONFIG_HCI_NPOLLWAITERS 2
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
union bt_hdr_u
|
||||
{
|
||||
struct bt_hci_cmd_hdr_s cmd;
|
||||
struct bt_hci_acl_hdr_s acl;
|
||||
struct bt_hci_evt_hdr_s evt;
|
||||
struct bt_hci_iso_hdr_s iso;
|
||||
};
|
||||
|
||||
struct sim_btuart_s
|
||||
{
|
||||
sq_entry_t link;
|
||||
uint8_t recvbuf[CONFIG_HCI_RECVBUF_SIZE];
|
||||
size_t recvpos;
|
||||
size_t recvlen;
|
||||
sem_t recvsem;
|
||||
sem_t recvlock;
|
||||
|
||||
uint8_t sendbuf[CONFIG_HCI_SENDBUF_SIZE];
|
||||
size_t sendlen;
|
||||
sem_t sendlock;
|
||||
|
||||
sem_t fdslock;
|
||||
FAR struct pollfd *fds[CONFIG_HCI_NPOLLWAITERS];
|
||||
|
||||
unsigned short id;
|
||||
int fd;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_btuart_open (FAR struct file *filep);
|
||||
static int sim_btuart_close(FAR struct file *filep);
|
||||
static ssize_t sim_btuart_read (FAR struct file *filep,
|
||||
FAR char *buffer, size_t buflen);
|
||||
static ssize_t sim_btuart_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t buflen);
|
||||
static int sim_btuart_ioctl(FAR struct file *filep,
|
||||
int cmd, unsigned long arg);
|
||||
static int sim_btuart_poll (FAR struct file *filep,
|
||||
FAR struct pollfd *fds, bool setup);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations g_sim_btuart_ops =
|
||||
{
|
||||
.open = sim_btuart_open,
|
||||
.close = sim_btuart_close,
|
||||
.read = sim_btuart_read,
|
||||
.write = sim_btuart_write,
|
||||
.ioctl = sim_btuart_ioctl,
|
||||
.poll = sim_btuart_poll
|
||||
};
|
||||
|
||||
static sq_queue_t g_sim_btuart_list;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static inline void sim_btuart_post(FAR sem_t *sem)
|
||||
{
|
||||
int semcount;
|
||||
|
||||
nxsem_get_value(sem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(sem);
|
||||
}
|
||||
}
|
||||
|
||||
static void sim_btuart_pollnotify(FAR struct sim_btuart_s *dev,
|
||||
pollevent_t eventset)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CONFIG_HCI_NPOLLWAITERS; i++)
|
||||
{
|
||||
FAR struct pollfd *fds = dev->fds[i];
|
||||
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & eventset);
|
||||
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
sim_btuart_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sim_btuart_post(&dev->recvsem);
|
||||
}
|
||||
|
||||
static int sim_btuart_open(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sim_btuart_s *dev = inode->i_private;
|
||||
int fd;
|
||||
|
||||
fd = bthcisock_host_open(dev->id);
|
||||
if (fd < 0)
|
||||
{
|
||||
return fd;
|
||||
}
|
||||
|
||||
dev->sendlen = 0;
|
||||
dev->recvpos = 0;
|
||||
dev->recvlen = 0;
|
||||
dev->fd = fd;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int sim_btuart_close(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sim_btuart_s *dev = inode->i_private;
|
||||
|
||||
bthcisock_host_close(dev->fd);
|
||||
|
||||
dev->fd = -1;
|
||||
|
||||
sim_btuart_pollnotify(dev, POLLIN | POLLOUT);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static ssize_t sim_btuart_read(FAR struct file *filep,
|
||||
FAR char *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sim_btuart_s *dev = inode->i_private;
|
||||
size_t len = dev->recvlen;
|
||||
int ret;
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->recvlock);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (dev->recvpos >= dev->recvlen)
|
||||
{
|
||||
while (!bthcisock_host_avail(dev->fd))
|
||||
{
|
||||
nxsem_wait_uninterruptible(&dev->recvsem);
|
||||
}
|
||||
|
||||
len = bthcisock_host_read(dev->fd, dev->recvbuf,
|
||||
CONFIG_HCI_RECVBUF_SIZE);
|
||||
if (len <= 0)
|
||||
{
|
||||
nxsem_post(&dev->recvlock);
|
||||
return len;
|
||||
}
|
||||
|
||||
dev->recvpos = 0;
|
||||
dev->recvlen = len;
|
||||
}
|
||||
|
||||
if (buflen > dev->recvlen - dev->recvpos)
|
||||
{
|
||||
buflen = dev->recvlen - dev->recvpos;
|
||||
}
|
||||
|
||||
memcpy(buffer, dev->recvbuf + dev->recvpos, buflen);
|
||||
dev->recvpos += buflen;
|
||||
|
||||
nxsem_post(&dev->recvlock);
|
||||
return buflen;
|
||||
}
|
||||
|
||||
static ssize_t sim_btuart_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sim_btuart_s *dev = inode->i_private;
|
||||
FAR union bt_hdr_u *hdr;
|
||||
size_t pktlen;
|
||||
size_t hdrlen;
|
||||
int ret;
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->sendlock);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (dev->sendlen + buflen > CONFIG_HCI_SENDBUF_SIZE)
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
memcpy(dev->sendbuf + dev->sendlen, buffer, buflen);
|
||||
dev->sendlen += buflen;
|
||||
|
||||
hdr = (FAR union bt_hdr_u *)(dev->sendbuf + 1);
|
||||
|
||||
while (1)
|
||||
{
|
||||
switch (dev->sendbuf[0])
|
||||
{
|
||||
case H4_CMD:
|
||||
hdrlen = sizeof(struct bt_hci_cmd_hdr_s);
|
||||
pktlen = hdr->cmd.param_len;
|
||||
break;
|
||||
case H4_ACL:
|
||||
hdrlen = sizeof(struct bt_hci_acl_hdr_s);
|
||||
pktlen = hdr->acl.len;
|
||||
break;
|
||||
case H4_ISO:
|
||||
hdrlen = sizeof(struct bt_hci_iso_hdr_s);
|
||||
pktlen = hdr->iso.len;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Reassembly is incomplete ? */
|
||||
|
||||
hdrlen += H4_HEADER_SIZE;
|
||||
|
||||
if (dev->sendlen < hdrlen)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
pktlen += hdrlen;
|
||||
if (dev->sendlen < pktlen)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Got the full packet, send out */
|
||||
|
||||
ret = bthcisock_host_send(dev->fd, dev->sendbuf, pktlen);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
dev->sendlen -= pktlen;
|
||||
if (dev->sendlen == 0)
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
|
||||
memmove(dev->sendbuf, dev->sendbuf + pktlen, dev->sendlen);
|
||||
}
|
||||
|
||||
err:
|
||||
dev->sendlen = 0;
|
||||
out:
|
||||
nxsem_post(&dev->sendlock);
|
||||
return ret < 0 ? ret : buflen;
|
||||
}
|
||||
|
||||
static int sim_btuart_ioctl(FAR struct file *filep,
|
||||
int cmd, unsigned long arg)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int sim_btuart_poll(FAR struct file *filep,
|
||||
FAR struct pollfd *fds, bool setup)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sim_btuart_s *dev = inode->i_private;
|
||||
pollevent_t eventset = 0;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
ret = nxsem_wait_uninterruptible(&dev->fdslock);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (setup)
|
||||
{
|
||||
for (i = 0; i < CONFIG_HCI_NPOLLWAITERS; i++)
|
||||
{
|
||||
/* Find an available slot */
|
||||
|
||||
if (!dev->fds[i])
|
||||
{
|
||||
/* Bind the poll structure and this slot */
|
||||
|
||||
dev->fds[i] = fds;
|
||||
fds->priv = &dev->fds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= CONFIG_HCI_NPOLLWAITERS)
|
||||
{
|
||||
fds->priv = NULL;
|
||||
ret = -EBUSY;
|
||||
}
|
||||
|
||||
if (bthcisock_host_avail(dev->fd))
|
||||
{
|
||||
eventset |= (fds->events & POLLIN);
|
||||
}
|
||||
|
||||
eventset |= (fds->events & POLLOUT);
|
||||
|
||||
if (eventset)
|
||||
{
|
||||
sim_btuart_pollnotify(dev, eventset);
|
||||
}
|
||||
}
|
||||
else if (fds->priv != NULL)
|
||||
{
|
||||
for (i = 0; i < CONFIG_HCI_NPOLLWAITERS; i++)
|
||||
{
|
||||
if (fds == dev->fds[i])
|
||||
{
|
||||
dev->fds[i] = NULL;
|
||||
fds->priv = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nxsem_post(&dev->fdslock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void sim_btuart_loop(void)
|
||||
{
|
||||
FAR struct sim_btuart_s *dev;
|
||||
FAR sq_entry_t *entry;
|
||||
|
||||
for (entry = sq_peek(&g_sim_btuart_list); entry; entry = sq_next(entry))
|
||||
{
|
||||
dev = container_of(entry, struct sim_btuart_s, link);
|
||||
if (bthcisock_host_avail(dev->fd))
|
||||
{
|
||||
sim_btuart_pollnotify(dev, POLLIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sim_btuart_register(const char *name, int id)
|
||||
{
|
||||
FAR struct sim_btuart_s *dev;
|
||||
int ret;
|
||||
|
||||
dev = (FAR struct sim_btuart_s *)kmm_zalloc(sizeof(struct sim_btuart_s));
|
||||
if (dev == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dev->fd = -1;
|
||||
dev->id = id;
|
||||
|
||||
nxsem_init(&dev->recvlock, 0, 1);
|
||||
nxsem_init(&dev->sendlock, 0, 1);
|
||||
nxsem_init(&dev->recvsem, 0, 0);
|
||||
nxsem_init(&dev->fdslock, 0, 1);
|
||||
|
||||
nxsem_set_protocol(&dev->recvsem, SEM_PRIO_NONE);
|
||||
|
||||
ret = register_driver(name, &g_sim_btuart_ops, 0666, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
nxsem_destroy(&dev->recvlock);
|
||||
nxsem_destroy(&dev->sendlock);
|
||||
nxsem_destroy(&dev->recvsem);
|
||||
nxsem_destroy(&dev->fdslock);
|
||||
kmm_free(dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sq_addlast(&dev->link, &g_sim_btuart_list);
|
||||
return OK;
|
||||
}
|
@ -99,10 +99,6 @@ void up_idle(void)
|
||||
bthcisock_loop();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SIM_BTUART
|
||||
sim_btuart_loop();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SIM_SOUND
|
||||
sim_audio_loop();
|
||||
#endif
|
||||
|
@ -331,13 +331,6 @@ int bthcisock_register(int dev_id);
|
||||
int bthcisock_loop(void);
|
||||
#endif
|
||||
|
||||
/* up_btuart.c **************************************************************/
|
||||
|
||||
#ifdef CONFIG_SIM_BTUART
|
||||
int sim_btuart_register(const char *name, int id);
|
||||
void sim_btuart_loop(void);
|
||||
#endif
|
||||
|
||||
/* up_audio.c ***************************************************************/
|
||||
|
||||
#ifdef CONFIG_SIM_SOUND
|
||||
|
@ -1,73 +0,0 @@
|
||||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NET_ETHERNET is not set
|
||||
# CONFIG_NET_IPv4 is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ARCH="sim"
|
||||
CONFIG_ARCH_BOARD="sim"
|
||||
CONFIG_ARCH_BOARD_SIM=y
|
||||
CONFIG_ARCH_CHIP="sim"
|
||||
CONFIG_ARCH_SIM=y
|
||||
CONFIG_BLUETOOTH_MAX_CONN=2
|
||||
CONFIG_BLUETOOTH_MAX_PAIRED=2
|
||||
CONFIG_BLUETOOTH_SMP_SELFTEST=y
|
||||
CONFIG_BLUETOOTH_UART=y
|
||||
CONFIG_BOARDCTL_POWEROFF=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=0
|
||||
CONFIG_BOOT_RUNFROMEXTSRAM=y
|
||||
CONFIG_BTSAK=y
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
CONFIG_DEV_LOOP=y
|
||||
CONFIG_DEV_ZERO=y
|
||||
CONFIG_DRIVERS_BLUETOOTH=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_EXAMPLES_HELLO=y
|
||||
CONFIG_FAT_LCNAMES=y
|
||||
CONFIG_FAT_LFN=y
|
||||
CONFIG_FSUTILS_PASSWD=y
|
||||
CONFIG_FSUTILS_PASSWD_READONLY=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=4096
|
||||
CONFIG_LIBC_EXECFUNCS=y
|
||||
CONFIG_LIB_ENVPATH=y
|
||||
CONFIG_LIB_HOSTNAME="NuttX-SIM"
|
||||
CONFIG_MAX_TASKS=64
|
||||
CONFIG_NET=y
|
||||
CONFIG_NETDEVICES=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETINIT_NETLOCAL=y
|
||||
CONFIG_NET_BLUETOOTH=y
|
||||
CONFIG_NET_STATISTICS=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_ARCHROMFS=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FATDEVNO=2
|
||||
CONFIG_NSH_FILE_APPS=y
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_ROMFSDEVNO=1
|
||||
CONFIG_NSH_ROMFSETC=y
|
||||
CONFIG_PATH_INITIAL="/bin"
|
||||
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=2048
|
||||
CONFIG_PREALLOC_MQ_MSGS=64
|
||||
CONFIG_READLINE_TABCOMPLETION=y
|
||||
CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIM_BTUART=y
|
||||
CONFIG_START_DAY=3
|
||||
CONFIG_START_MONTH=4
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_USERMAIN_STACKSIZE=4096
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_BLUETOOTH=y
|
@ -369,24 +369,6 @@ int sim_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SIM_BTUART
|
||||
/* Register the HCI TTY device via HCI socket */
|
||||
|
||||
ret = sim_btuart_register("/dev/ttyHCI", 0); /* Use HCI0 */
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: sim_btuart_register() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
# ifdef CONFIG_BLUETOOTH_UART_SHIM
|
||||
ret = btuart_register(btuart_shim_getdevice("/dev/ttyHCI"));
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: btuart_register() failed: %d\n", ret);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SIM_I2CBUS
|
||||
/* Initialize the i2c master bus device */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user