Skip to content

Commit 5c186d8

Browse files
Added ability to reset and relaunch core 1 (#493)
1 parent 25b3491 commit 5c186d8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cores/rp2040/RP2040Support.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ class _MFIFO {
9494
// once otherIdled == false.
9595
}
9696

97+
void clear() {
98+
uint32_t val;
99+
100+
while (queue_try_remove(&_queue[0], &val)) {
101+
tight_loop_contents();
102+
}
103+
104+
while (queue_try_remove(&_queue[1], &val)) {
105+
tight_loop_contents();
106+
}
107+
}
108+
97109
private:
98110
static void __no_inline_not_in_flash_func(_irq)() {
99111
multicore_fifo_clear_irq();
@@ -118,6 +130,8 @@ class _MFIFO {
118130

119131
class RP2040;
120132
extern RP2040 rp2040;
133+
extern "C" void main1();
134+
121135
class RP2040 {
122136
public:
123137
RP2040() {
@@ -172,6 +186,12 @@ class RP2040 {
172186
fifo.resumeOtherCore();
173187
}
174188

189+
void restartCore1() {
190+
multicore_reset_core1();
191+
fifo.clear();
192+
multicore_launch_core1(main1);
193+
}
194+
175195
// Multicore comms FIFO
176196
_MFIFO fifo;
177197

cores/rp2040/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void initVariant() { }
4141
// Optional 2nd core setup and loop
4242
extern void setup1() __attribute__((weak));
4343
extern void loop1() __attribute__((weak));
44-
static void main1() {
44+
extern "C" void main1() {
4545
rp2040.fifo.registerCore();
4646
if (setup1) {
4747
setup1();

0 commit comments

Comments
 (0)