mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
[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:
@@ -24,7 +24,7 @@ config BLUETOOTH_UART_GENERIC
|
|||||||
default n
|
default n
|
||||||
|
|
||||||
config BLUETOOTH_UART_SHIM
|
config BLUETOOTH_UART_SHIM
|
||||||
bool
|
bool "Bluetooth UART SHIM driver"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
if BLUETOOTH_UART
|
if BLUETOOTH_UART
|
||||||
|
|||||||
@@ -121,71 +121,69 @@ static void btuart_rxwork(FAR void *arg)
|
|||||||
* Read the first byte to get the packet type.
|
* Read the first byte to get the packet type.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
nread = btuart_read(upper, data, H4_HEADER_SIZE, 0);
|
while (true)
|
||||||
if (nread != H4_HEADER_SIZE)
|
|
||||||
{
|
{
|
||||||
wlwarn("WARNING: Unable to read H4 packet type: %zd\n", nread);
|
nread = btuart_read(upper, data, H4_HEADER_SIZE, 0);
|
||||||
goto errout_with_busy;
|
if (nread != H4_HEADER_SIZE)
|
||||||
}
|
{
|
||||||
|
wlwarn("WARNING: Unable to read H4 packet type: %zd\n", nread);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (data[0] == H4_EVT)
|
if (data[0] == H4_EVT)
|
||||||
{
|
{
|
||||||
hdrlen = sizeof(struct bt_hci_evt_hdr_s);
|
hdrlen = sizeof(struct bt_hci_evt_hdr_s);
|
||||||
}
|
}
|
||||||
else if (data[0] == H4_ACL)
|
else if (data[0] == H4_ACL)
|
||||||
{
|
{
|
||||||
hdrlen = sizeof(struct bt_hci_acl_hdr_s);
|
hdrlen = sizeof(struct bt_hci_acl_hdr_s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
|
wlerr("ERROR: Unknown H4 type %u\n", data[0]);
|
||||||
goto errout_with_busy;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nread = btuart_read(upper, data + H4_HEADER_SIZE,
|
nread = btuart_read(upper, data + H4_HEADER_SIZE,
|
||||||
hdrlen, hdrlen);
|
hdrlen, hdrlen);
|
||||||
if (nread != hdrlen)
|
if (nread != hdrlen)
|
||||||
{
|
{
|
||||||
wlwarn("WARNING: Unable to read H4 packet header: %zd\n", nread);
|
wlwarn("WARNING: Unable to read H4 packet header: %zd\n", nread);
|
||||||
goto errout_with_busy;
|
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,
|
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);
|
DEBUGASSERT(lower != NULL && arg != NULL);
|
||||||
upper = (FAR struct btuart_upperhalf_s *)arg;
|
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;
|
wlerr("ERROR: work_queue failed: %d\n", ret);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ struct btuart_upperhalf_s
|
|||||||
/* Work queue support */
|
/* Work queue support */
|
||||||
|
|
||||||
struct work_s work;
|
struct work_s work;
|
||||||
volatile bool busy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ FAR struct btuart_lowerhalf_s *btuart_shim_getdevice(FAR const char *path)
|
|||||||
|
|
||||||
s = &n->state;
|
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)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
kmm_free(n);
|
kmm_free(n);
|
||||||
|
|||||||
Reference in New Issue
Block a user