1
0
Fork 0
forked from nuttx/nuttx-update

[bt_uart.c] fix bug:cant receive data

rootcause: in btuart_rxwork, read data in blocking mode and btuart_read do three times, maybe remote send some packets one time,so it wont read the sencond packets.

Signed-off-by: wangzhi7 <wangzhi7@xiaomi.com>
This commit is contained in:
wangzhi7 2023-12-29 17:02:45 +08:00 committed by Xiang Xiao
parent 31605b6335
commit 8b68f9d816
4 changed files with 64 additions and 72 deletions

View file

@ -24,7 +24,7 @@ config BLUETOOTH_UART_GENERIC
default n
config BLUETOOTH_UART_SHIM
bool
bool "Bluetooth UART SHIM driver"
default n
if BLUETOOTH_UART

View file

@ -121,71 +121,69 @@ static void btuart_rxwork(FAR void *arg)
* Read the first byte to get the packet type.
*/
nread = btuart_read(upper, data, H4_HEADER_SIZE, 0);
if (nread != H4_HEADER_SIZE)
while (true)
{
wlwarn("WARNING: Unable to read H4 packet type: %zd\n", nread);
goto errout_with_busy;
}
nread = btuart_read(upper, data, H4_HEADER_SIZE, 0);
if (nread != H4_HEADER_SIZE)
{
wlwarn("WARNING: Unable to read H4 packet type: %zd\n", nread);
break;
}
if (data[0] == H4_EVT)
{
hdrlen = sizeof(struct bt_hci_evt_hdr_s);
}
else if (data[0] == H4_ACL)
{
hdrlen = sizeof(struct bt_hci_acl_hdr_s);
}
else
{
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
goto errout_with_busy;
}
if (data[0] == H4_EVT)
{
hdrlen = sizeof(struct bt_hci_evt_hdr_s);
}
else if (data[0] == H4_ACL)
{
hdrlen = sizeof(struct bt_hci_acl_hdr_s);
}
else
{
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
break;
}
nread = btuart_read(upper, data + H4_HEADER_SIZE,
hdrlen, hdrlen);
if (nread != hdrlen)
{
wlwarn("WARNING: Unable to read H4 packet header: %zd\n", nread);
goto errout_with_busy;
nread = btuart_read(upper, data + H4_HEADER_SIZE,
hdrlen, hdrlen);
if (nread != hdrlen)
{
wlwarn("WARNING: Unable to read H4 packet header: %zd\n", nread);
break;
}
hdr = (FAR void *)(data + H4_HEADER_SIZE);
if (data[0] == H4_EVT)
{
pktlen = hdr->evt.len;
type = BT_EVT;
}
else if (data[0] == H4_ACL)
{
pktlen = hdr->acl.len;
type = BT_ACL_IN;
}
else
{
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
break;
}
nread = btuart_read(upper, data + H4_HEADER_SIZE + hdrlen,
pktlen, pktlen);
if (nread != pktlen)
{
wlwarn("WARNING: Unable to read H4 packet: %zd\n", nread);
break;
}
/* Pass buffer to the stack */
BT_DUMP("Received", data, H4_HEADER_SIZE + hdrlen + pktlen);
bt_netdev_receive(&upper->dev, type, data + H4_HEADER_SIZE,
hdrlen + pktlen);
}
hdr = (FAR void *)(data + H4_HEADER_SIZE);
if (data[0] == H4_EVT)
{
pktlen = hdr->evt.len;
type = BT_EVT;
}
else if (data[0] == H4_ACL)
{
pktlen = hdr->acl.len;
type = BT_ACL_IN;
}
else
{
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
goto errout_with_busy;
}
nread = btuart_read(upper, data + H4_HEADER_SIZE + hdrlen,
pktlen, pktlen);
if (nread != pktlen)
{
wlwarn("WARNING: Unable to read H4 packet: %zd\n", nread);
goto errout_with_busy;
}
/* Pass buffer to the stack */
BT_DUMP("Received", data, H4_HEADER_SIZE + hdrlen + pktlen);
upper->busy = false;
bt_netdev_receive(&upper->dev, type, data + H4_HEADER_SIZE,
hdrlen + pktlen);
return;
errout_with_busy:
upper->busy = false;
}
static void btuart_rxcallback(FAR const struct btuart_lowerhalf_s *lower,
@ -196,15 +194,10 @@ static void btuart_rxcallback(FAR const struct btuart_lowerhalf_s *lower,
DEBUGASSERT(lower != NULL && arg != NULL);
upper = (FAR struct btuart_upperhalf_s *)arg;
if (!upper->busy)
int ret = work_queue(HPWORK, &upper->work, btuart_rxwork, arg, 0);
if (ret < 0)
{
upper->busy = true;
int ret = work_queue(HPWORK, &upper->work, btuart_rxwork, arg, 0);
if (ret < 0)
{
upper->busy = false;
wlerr("ERROR: work_queue failed: %d\n", ret);
}
wlerr("ERROR: work_queue failed: %d\n", ret);
}
}

View file

@ -78,7 +78,6 @@ struct btuart_upperhalf_s
/* Work queue support */
struct work_s work;
volatile bool busy;
};
/****************************************************************************

View file

@ -359,7 +359,7 @@ FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path)
s = &n->state;
ret = file_open(&s->f, path, O_RDWR | O_CLOEXEC);
ret = file_open(&s->f, path, O_RDWR | O_CLOEXEC | O_NONBLOCK);
if (ret < 0)
{
kmm_free(n);