From 024cf36e47c8706a2f68c3b4253b31aeeb70ae0b Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 12 Apr 2024 14:14:21 +0200 Subject: [PATCH 1/2] RPC: Add a function to return the current CPU ID. Signed-off-by: iabdalkader --- libraries/RPC/src/RPC.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/RPC/src/RPC.h b/libraries/RPC/src/RPC.h index 533988323..d4a8729b8 100644 --- a/libraries/RPC/src/RPC.h +++ b/libraries/RPC/src/RPC.h @@ -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); From 2c5d982bb3902a5203e94d660f0d04cfcd87e122 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 12 Apr 2024 14:17:43 +0200 Subject: [PATCH 2/2] RPC: Update examples. Signed-off-by: iabdalkader --- libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino | 8 ++++---- libraries/RPC/examples/RPC_m4/RPC_m4.ino | 2 +- .../SerialPassthrough_RPC/SerialPassthrough_RPC.ino | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino b/libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino index 2df49f0c0..61f96d53f 100644 --- a/libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino +++ b/libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino @@ -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); @@ -29,7 +29,7 @@ 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); @@ -37,12 +37,12 @@ void loop() { } int res = RPC.call("add", 1, 2).as(); - 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(); - if (HAL_GetCurrentCPUID() == CM7_CPUID) { + if (RPC.cpu_id() == CM7_CPUID) { Serial.println("sub(3, 1) = " + String(res)); } delay(250); diff --git a/libraries/RPC/examples/RPC_m4/RPC_m4.ino b/libraries/RPC/examples/RPC_m4/RPC_m4.ino index 1af8e6e5c..439a85caf 100644 --- a/libraries/RPC/examples/RPC_m4/RPC_m4.ino +++ b/libraries/RPC/examples/RPC_m4/RPC_m4.ino @@ -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"; diff --git a/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino b/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino index 98451da3b..eb8917bb7 100644 --- a/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino +++ b/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino @@ -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 { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy