Skip to content

Commit

Permalink
RPC: fix bool() and begin() return value
Browse files Browse the repository at this point in the history
This allows `while (!SerialRPC)` construct to work
  • Loading branch information
facchinm committed Nov 2, 2023
1 parent 3490221 commit 7fc89ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions libraries/RPC/src/RPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ int RPCClass::begin(long unsigned int np, uint16_t nd) {
* The rpmsg service is initiate by the remote processor, on H7 new_service_cb
* callback is received on service creation. Wait for the callback
*/
OPENAMP_Wait_EndPointready(&rp_endpoints[ENDPOINT_RAW], millis() + 500);
OPENAMP_Wait_EndPointready(&rp_endpoints[ENDPOINT_RESPONSE], millis() + 500);
auto err = OPENAMP_Wait_EndPointready(&rp_endpoints[ENDPOINT_RAW], millis() + 500);
err |= OPENAMP_Wait_EndPointready(&rp_endpoints[ENDPOINT_RESPONSE], millis() + 500);

if (err == 0) {
initialized = true;
} else {
return 0;
}

// Send first dummy message to enable the channel
uint8_t message = 0x00;
Expand Down Expand Up @@ -226,6 +232,8 @@ int RPCClass::begin(long unsigned int np, uint16_t nd) {
return 0;
}

initialized = true;

return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion libraries/openamp_arduino/src/openamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ int OPENAMP_check_for_message(void)

unsigned long millis();

void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline)
int OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline)
{
while(!is_rpmsg_ept_ready(rp_ept) && (millis() < deadline)) {
MAILBOX_Poll(rvdev.vdev);
}
if (millis() >= deadline) {
printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept);
return -1;
}
return 0;
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2 changes: 1 addition & 1 deletion libraries/openamp_arduino/src/openamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int OPENAMP_create_endpoint(struct rpmsg_endpoint *ept, const char *name,
int OPENAMP_check_for_message(void);

/* Wait loop on endpoint ready ( message dest address is know)*/
void OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline);
int OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 7fc89ba

Please sign in to comment.