Skip to content

Commit d6f7407

Browse files
authored
Merge pull request #865 from iabdalkader/rpc_cpu_id
RPC Library: Add a function to return the current CPU ID.
2 parents 105c172 + 2c5d982 commit d6f7407

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

libraries/RPC/examples/Basic_AddSub/Basic_AddSub.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void setup() {
1717
RPC.begin();
1818
RPC.bind("add", add);
1919
RPC.bind("sub", sub);
20-
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
20+
if (RPC.cpu_id() == CM7_CPUID) {
2121
// Introduce a brief delay to allow the M4 sufficient time
2222
// to bind remote functions before invoking them.
2323
delay(100);
@@ -29,20 +29,20 @@ void loop() {
2929
static size_t loop_count = 0;
3030

3131
// Blink every 512 iterations
32-
if (HAL_GetCurrentCPUID() == CM4_CPUID && (loop_count++ % 512) == 0) {
32+
if (RPC.cpu_id() == CM4_CPUID && (loop_count++ % 512) == 0) {
3333
digitalWrite(LEDG, LOW);
3434
delay(10);
3535
digitalWrite(LEDG, HIGH);
3636
delay(10);
3737
}
3838

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

4444
res = RPC.call("sub", res, 1).as<int>();
45-
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
45+
if (RPC.cpu_id() == CM7_CPUID) {
4646
Serial.println("sub(3, 1) = " + String(res));
4747
}
4848
delay(250);

libraries/RPC/examples/RPC_m4/RPC_m4.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Thread subtractThread;
1111
Note that the sketch has to be uploaded to both cores.
1212
**/
1313
String currentCPU() {
14-
if (HAL_GetCurrentCPUID() == CM7_CPUID) {
14+
if (RPC.cpu_id() == CM7_CPUID) {
1515
return "M7";
1616
} else {
1717
return "M4";

libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void setup() {
99
}
1010

1111
void loop() {
12-
if (HAL_GetCurrentCPUID() == CM4_CPUID) {
12+
if (RPC.cpu_id() == CM4_CPUID) {
1313
RPC.println("Printed from M4 core");
1414
delay(1000);
1515
} else {

libraries/RPC/src/RPC.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,26 @@ class RPCClass : public Stream, public rpc::detail::dispatcher {
4242
for (int i = 0; i< 10; i++) {
4343
clients[i] = NULL;
4444
}
45-
};
45+
}
4646
int begin();
47-
void end() {};
47+
void end() {
48+
49+
}
4850
int available(void) {
4951
return rx_buffer.available();
50-
};
52+
}
5153
int peek(void) {
5254
return rx_buffer.peek();
5355
}
5456
int read(void) {
5557
return rx_buffer.read_char();
5658
}
57-
void flush(void) {};
59+
void flush(void) {
60+
61+
}
62+
uint32_t cpu_id() {
63+
return HAL_GetCurrentCPUID();
64+
}
5865
size_t write(uint8_t c);
5966
size_t write(const uint8_t *buf, size_t len, bool raw = true);
6067

0 commit comments

Comments
 (0)