Skip to content

Commit

Permalink
fixup! nrf_rpc: add NOWAIT group type
Browse files Browse the repository at this point in the history
  • Loading branch information
e-rk committed May 22, 2024
1 parent 216842a commit 5d9dc1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 13 additions & 6 deletions nrf_rpc/include/nrf_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ extern "C" {
/** @brief Special value to indicate that ID is unknown or irrelevant. */
#define NRF_RPC_ID_UNKNOWN 0xFF

/** @brief Flag indicating that the group does not block on initialization.
*/
#define NRF_RPC_FLAGS_WAIT_ON_INIT BIT(0)

/** @brief Flag indicating that the peer must initiate group binding. */
#define NRF_RPC_FLAGS_INITIATOR BIT(1)

/** @brief Helper macro for conditional flag initialization. */
#define NRF_RPC_FLAG_COND(cond, flag) (cond ? flag : 0UL)

/* Forward declaration. */
struct nrf_rpc_err_report;
struct nrf_rpc_group;
Expand Down Expand Up @@ -137,8 +147,7 @@ struct nrf_rpc_group {
const char *strid;
nrf_rpc_err_handler_t err_handler;
nrf_rpc_group_bound_handler_t bound_handler;
bool wait_on_init;
bool initiator;
uint32_t flags;
};

/** @brief Error report.
Expand Down Expand Up @@ -202,8 +211,7 @@ struct nrf_rpc_err_report {
.transport = _transport, \
.err_handler = _err_handler, \
.bound_handler = NULL, \
.wait_on_init = true, \
.initiator = true, \
.flags = NRF_RPC_FLAGS_WAIT_ON_INIT | NRF_RPC_FLAGS_INITIATOR, \
}

/** @brief Define a non-blocking group of commands and events.
Expand Down Expand Up @@ -260,8 +268,7 @@ struct nrf_rpc_err_report {
.transport = _transport, \
.err_handler = _err_handler, \
.bound_handler = _bound_handler, \
.wait_on_init = false, \
.initiator = _initiator, \
.flags = NRF_RPC_FLAG_COND(_initiator, NRF_RPC_FLAGS_INITIATOR), \
}

/** @brief Extern declaration of a group.
Expand Down
6 changes: 3 additions & 3 deletions nrf_rpc/nrf_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int transport_init(nrf_rpc_tr_receive_handler_t receive_cb)

group->data->transport_initialized = true;

if (group->initiator) {
if (group->flags & NRF_RPC_FLAGS_INITIATOR) {
err = group_init_send(group);
if (err) {
NRF_RPC_ERR("Failed to send group init packet for group id: %d strid: %s err: %d",
Expand Down Expand Up @@ -612,7 +612,7 @@ static int init_packet_handle(struct header *hdr, const struct nrf_rpc_group **g
group_data = (*group)->data;
first_init = group_data->dst_group_id == NRF_RPC_ID_UNKNOWN;
group_data->dst_group_id = hdr->src_group_id;
wait_on_init = (*group)->wait_on_init;
wait_on_init = (*group)->flags & NRF_RPC_FLAGS_WAIT_ON_INIT;
nrf_rpc_group_bound_handler_t bound_handler = (*group)->bound_handler;

NRF_RPC_DBG("Found corresponding local group. Remote id: %d, Local id: %d",
Expand Down Expand Up @@ -1021,7 +1021,7 @@ int nrf_rpc_init(nrf_rpc_err_handler_t err_handler)
NRF_RPC_DBG("Group '%s' has id %d", group->strid, group_id);
data->src_group_id = group_id;
group_id++;
if (group->wait_on_init) {
if (group->flags & NRF_RPC_FLAGS_WAIT_ON_INIT) {
wait_count++;
}
}
Expand Down

0 comments on commit 5d9dc1f

Please sign in to comment.