Skip to content

RPC Library: Add a function to return the current CPU ID. #865

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

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void setup() {
RPC.begin();
RPC.bind("add", add);
RPC.bind("sub", sub);
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
if (RPC.cpu_id() == CM7_CPUID) {
// Introduce a brief delay to allow the M4 sufficient time
// to bind remote functions before invoking them.
delay(100);
Expand All @@ -29,20 +29,20 @@ void loop() {
static size_t loop_count = 0;

// Blink every 512 iterations
if (HAL_GetCurrentCPUID() == CM4_CPUID && (loop_count++ % 512) == 0) {
if (RPC.cpu_id() == CM4_CPUID && (loop_count++ % 512) == 0) {
digitalWrite(LEDG, LOW);
delay(10);
digitalWrite(LEDG, HIGH);
delay(10);
}

int res = RPC.call("add", 1, 2).as<int>();
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
if (RPC.cpu_id() == CM7_CPUID) {
Serial.println("add(1, 2) = " + String(res));
}

res = RPC.call("sub", res, 1).as<int>();
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
if (RPC.cpu_id() == CM7_CPUID) {
Serial.println("sub(3, 1) = " + String(res));
}
delay(250);
Expand Down
2 changes: 1 addition & 1 deletion libraries/RPC/examples/RPC_m4/RPC_m4.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Thread subtractThread;
Note that the sketch has to be uploaded to both cores.
**/
String currentCPU() {
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
if (RPC.cpu_id() == CM7_CPUID) {
return "M7";
} else {
return "M4";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void setup() {
}

void loop() {
if (HAL_GetCurrentCPUID() == CM4_CPUID) {
if (RPC.cpu_id() == CM4_CPUID) {
RPC.println("Printed from M4 core");
delay(1000);
} else {
Expand Down
15 changes: 11 additions & 4 deletions libraries/RPC/src/RPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,26 @@ class RPCClass : public Stream, public rpc::detail::dispatcher {
for (int i = 0; i< 10; i++) {
clients[i] = NULL;
}
};
}
int begin();
void end() {};
void end() {

}
int available(void) {
return rx_buffer.available();
};
}
int peek(void) {
return rx_buffer.peek();
}
int read(void) {
return rx_buffer.read_char();
}
void flush(void) {};
void flush(void) {

}
uint32_t cpu_id() {
return HAL_GetCurrentCPUID();
}
size_t write(uint8_t c);
size_t write(const uint8_t *buf, size_t len, bool raw = true);

Expand Down
Loading