Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nrf_rpc: two-way handshake and NOWAIT group type #1335

Merged
merged 2 commits into from
May 24, 2024

Conversation

e-rk
Copy link
Contributor

@e-rk e-rk commented May 20, 2024

This PR consists of two commits:

  • nrf_rpc: Two-way handshake initialization
  • nrf_rpc: add NOWAIT group type

See descriptions for more details.

Copy link
Contributor

@Damian-Nordic Damian-Nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have some comments, mostly to improve comments, but I like the idea overall :)

nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/nrf_rpc.c Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
@e-rk e-rk force-pushed the nrf-rpc-improvements branch from 2e6aa11 to 4e84aa2 Compare May 21, 2024 11:26
Comment on lines +384 to 394
if (waiting_group_count > 0) {
err = nrf_rpc_os_event_wait(&groups_init_event, CONFIG_NRF_RPC_GROUP_INIT_WAIT_TIME);
if (err) {
NRF_RPC_ERR("Not all groups are ready to use.");
}
}

return err;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case waiting_group_count is zero, the err value from either transport->api->init(), nrf_rpc_os_event_init() or group_init_send() (in the last round of the for-loop) will be returned.

Should err be zeroed before the waiting_group_count > 0 conditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. Thanks for catching it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@e-rk e-rk force-pushed the nrf-rpc-improvements branch from 4e84aa2 to e577715 Compare May 22, 2024 09:59
Copy link
Contributor

@doki-nordic doki-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor suggestions.

bound_handler(*group);
}

if (first_init && wait_on_init && ++initialized_group_count == waiting_group_count) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use ++x operator inside "if" expression (it should not have side-effects).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the side effect from if.

group_data = (*group)->data;
first_init = group_data->dst_group_id == NRF_RPC_ID_UNKNOWN;
group_data->dst_group_id = hdr->src_group_id;
bool wait_on_init = (*group)->wait_on_init;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local variable declarations should be at the beginning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the declaration to the beginning.

@e-rk e-rk force-pushed the nrf-rpc-improvements branch from e577715 to 216842a Compare May 22, 2024 12:38
@e-rk
Copy link
Contributor Author

e-rk commented May 22, 2024

I have applied @Damian-Nordic suggestion in a separate commit. Let me know if you prefer groups to have single flags field. If yes, I will squash the commit. If not, I will remove it.

@e-rk e-rk force-pushed the nrf-rpc-improvements branch 3 times, most recently from 5d9dc1f to 00de5c9 Compare May 22, 2024 13:32
@e-rk e-rk force-pushed the nrf-rpc-improvements branch from 00de5c9 to aa9b85b Compare May 23, 2024 06:22
@KAGA164 KAGA164 requested a review from peknis May 23, 2024 08:46
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
* to reset the local state.
* @param _initiator The group is the initiator.
*/
#define NRF_RPC_GROUP_DEFINE_NOWAIT(_name, _strid, _transport, _ack_handler, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro looks almost the same like NRF_RPC_GROUP_DEFINE You can consider simplification by creating, local macro and use it under these two. For example NRF_RPC_GROUP_DEFINE_INTERNAL__()

Copy link
Contributor Author

@e-rk e-rk May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, then the user could use the internal macro to create a group that is neither NOWAIT or normal. Do we want to encourage that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to keep both macros and use internal macro under them to avoid duplication in macro body

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when user use something which has internal in name then he does it on his own responsibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as suggested.

nrf_rpc/nrf_rpc.c Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/Kconfig Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
nrf_rpc/include/nrf_rpc.h Outdated Show resolved Hide resolved
@e-rk e-rk force-pushed the nrf-rpc-improvements branch from 84b8597 to 47293c1 Compare May 23, 2024 09:40
@e-rk
Copy link
Contributor Author

e-rk commented May 23, 2024

@peknis applied your suggestions.

@e-rk e-rk force-pushed the nrf-rpc-improvements branch 2 times, most recently from 3ff8922 to 3c477d9 Compare May 23, 2024 10:25
@e-rk e-rk added this to the 2.7.0 milestone May 23, 2024
Damian-Nordic and others added 2 commits May 24, 2024 13:05
Implement two-way handshake nRF RPC initialization:
When an initialization packet with the unknown destination
group ID is received, reply to that with an initialization
packet with the right destination group ID.

This makes it possible to re-establish the link even if
either peer has rebooted, or has booted with a delay.

Also, allow to configure infinite group init timeout.

Signed-off-by: Damian Krolik <[email protected]>
The NOWAIT group type does not block nrf_rpc_init until binding
completion. The user can define regular and NOINIT groups
simultaneously, but nrf_rpc_init will only wait for regular groups to
complete the binding.

The NOINIT group can be assigned a callback, which notifies that the
group binding has been completed.
If a remote peer resets and binds again, the callback will be executed
again.

When `initiator` flag is set, the nrf_rpc will initiate group
binding when nrf_rpc_init is called. There must be at least one
initiator on either side of the IPC channel. Both peers can be
the initiator at the same time.

Signed-off-by: Rafał Kuźnia <[email protected]>
@e-rk e-rk force-pushed the nrf-rpc-improvements branch from 3c477d9 to 0924311 Compare May 24, 2024 11:05
@rlubos rlubos merged commit dd0aa77 into nrfconnect:main May 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants