Skip to content

Commit 974301e

Browse files
Add rp2040.cpuid() call to get running core (earlephilhower#1190)
Per question received via email.
1 parent 2acc161 commit 974301e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cores/rp2040/RP2040Support.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ class RP2040 {
246246
return clock_get_hz(clk_sys);
247247
}
248248

249+
// Get current CPU core number
250+
static int cpuid() {
251+
return sio_hw->cpuid;
252+
}
253+
249254
// Get CPU cycle count. Needs to do magic to extens 24b HW to something longer
250255
volatile uint64_t _epoch = 0;
251256
inline uint32_t getCycleCount() {

docs/rp2040.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Returns the current frequency of the core clock. This is read at runtime,
1313
versus the constant ``F_CPU`` macro that is also available. This is useful
1414
in cases where your code changes the core clock (i.e. low power modes, etc.)
1515

16+
int rp2040.cpuid()
17+
~~~~~~~~~~~~~~~~~~
18+
Returns the current core ID (0 or 1) of the executing task.
19+
1620
uint32_t rp2040.getCycleCount()
1721
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1822
Returns a 32-bit cycle count from then the core started running. Because it

0 commit comments

Comments
 (0)