mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-10-01 21:17:21 +00:00
apps/bttester: Keep BTP command in buffer for delayed response
This allows to avoid copying data for async callbacks.
This commit is contained in:
committed by
Szymon Janc
parent
7d25c1c718
commit
e88212a5da
@@ -40,6 +40,7 @@
|
|||||||
static struct os_eventq avail_queue;
|
static struct os_eventq avail_queue;
|
||||||
static struct os_eventq *cmds_queue;
|
static struct os_eventq *cmds_queue;
|
||||||
static struct os_event bttester_ev[CMD_QUEUED];
|
static struct os_event bttester_ev[CMD_QUEUED];
|
||||||
|
static struct btp_buf *delayed_cmd;
|
||||||
|
|
||||||
struct btp_buf {
|
struct btp_buf {
|
||||||
struct os_event *ev;
|
struct os_event *ev;
|
||||||
@@ -165,14 +166,22 @@ cmd_handler(struct os_event *ev)
|
|||||||
status = BTP_STATUS_UNKNOWN_CMD;
|
status = BTP_STATUS_UNKNOWN_CMD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != BTP_STATUS_DELAY_REPLY) {
|
/* Allow to delay only 1 command. This is for convenience only
|
||||||
if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) {
|
* of using cmd data without need of copying those in async
|
||||||
tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode,
|
* functions. Should be not needed eventually.
|
||||||
cmd->hdr.index, cmd->rsp, rsp_len);
|
*/
|
||||||
} else {
|
if (status == BTP_STATUS_DELAY_REPLY) {
|
||||||
tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode,
|
assert(delayed_cmd == NULL);
|
||||||
cmd->hdr.index, status);
|
delayed_cmd = cmd;
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status == BTP_STATUS_SUCCESS) && rsp_len > 0) {
|
||||||
|
tester_send_with_index(cmd->hdr.service, cmd->hdr.opcode,
|
||||||
|
cmd->hdr.index, cmd->rsp, rsp_len);
|
||||||
|
} else {
|
||||||
|
tester_rsp_with_index(cmd->hdr.service, cmd->hdr.opcode,
|
||||||
|
cmd->hdr.index, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_eventq_put(&avail_queue, ev);
|
os_eventq_put(&avail_queue, ev);
|
||||||
@@ -325,10 +334,35 @@ void
|
|||||||
tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len)
|
tester_send(uint8_t service, uint8_t opcode, uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
tester_send_with_index(service, opcode, BTP_INDEX, data, len);
|
tester_send_with_index(service, opcode, BTP_INDEX, data, len);
|
||||||
|
|
||||||
|
/* async response to command */
|
||||||
|
if (opcode < 0x80) {
|
||||||
|
struct btp_buf *cmd;
|
||||||
|
|
||||||
|
assert(delayed_cmd != NULL);
|
||||||
|
|
||||||
|
cmd = delayed_cmd;
|
||||||
|
delayed_cmd = NULL;
|
||||||
|
|
||||||
|
(void)memset(cmd, 0, sizeof(*cmd));
|
||||||
|
os_eventq_put(&avail_queue,
|
||||||
|
CONTAINER_OF(cmd, struct btp_buf, data)->ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tester_rsp(uint8_t service, uint8_t opcode, uint8_t status)
|
tester_rsp(uint8_t service, uint8_t opcode, uint8_t status)
|
||||||
{
|
{
|
||||||
|
struct btp_buf *cmd;
|
||||||
|
|
||||||
tester_rsp_with_index(service, opcode, BTP_INDEX, status);
|
tester_rsp_with_index(service, opcode, BTP_INDEX, status);
|
||||||
|
|
||||||
|
assert(delayed_cmd != NULL);
|
||||||
|
|
||||||
|
cmd = delayed_cmd;
|
||||||
|
delayed_cmd = NULL;
|
||||||
|
|
||||||
|
(void)memset(cmd, 0, sizeof(*cmd));
|
||||||
|
os_eventq_put(&avail_queue,
|
||||||
|
CONTAINER_OF(cmd, struct btp_buf, data)->ev);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user