Skip to content

Commit f316272

Browse files
authored
Move multicore_lockout victim initialzied tracking to pico_multicore (#1427)
* Move multicore_lockout victim initialzied tracking to pico_multicore via new multicore_lockout_victim_is_initialzied method, so user initialization of the multicore_lockout independent of pico_flash will work
1 parent bb460d0 commit f316272

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/rp2_common/pico_flash/flash.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ static flash_safety_helper_t default_flash_safety_helper = {
4646
.exit_safe_zone_timeout_ms = default_exit_safe_zone_timeout_ms
4747
};
4848

49-
#if PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT
50-
// note that these are not reset by core reset, however for now, I think people resetting cores
51-
// and then doing this again without re-initializing pico_flash for that core, is probably
52-
// something we can live with breaking.
53-
static bool core_initialized[NUM_CORES];
54-
#endif
55-
5649
#if PICO_FLASH_SAFE_EXECUTE_USE_FREERTOS_SMP
5750
enum {
5851
FREERTOS_LOCKOUT_NONE = 0,
@@ -105,7 +98,6 @@ static bool default_core_init_deinit(__unused bool init) {
10598
return false;
10699
}
107100
multicore_lockout_victim_init();
108-
core_initialized[get_core_num()] = init;
109101
#endif
110102
return true;
111103
}
@@ -182,7 +174,7 @@ static int default_enter_safe_zone_timeout_ms(__unused uint32_t timeout_ms) {
182174
#endif
183175
rc = PICO_ERROR_NOT_PERMITTED;
184176
#else // !LIB_FREERTOS_KERNEL
185-
if (core_initialized[get_core_num()^1]) {
177+
if (multicore_lockout_victim_is_initialized(get_core_num()^1)) {
186178
if (!multicore_lockout_start_timeout_us(timeout_ms * 1000ull)) {
187179
rc = PICO_ERROR_TIMEOUT;
188180
}

src/rp2_common/pico_multicore/include/pico/multicore.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ static inline uint32_t multicore_fifo_get_status(void) {
257257
*/
258258
void multicore_lockout_victim_init(void);
259259

260+
/*! \brief Determine if \ref multicore_victim_init() has been called on the specified core.
261+
* \ingroup multicore_lockout
262+
*
263+
* \note this state persists even if the core is subsequently reset; therefore you are advised to
264+
* always call \ref multicore_lockout_victim_init() again after resetting a core, which had previously
265+
* been initialized.
266+
*
267+
* \param core_num the core number (0 or 1)
268+
* \return true if \ref multicore_victim_init() has been called on the specified core, false otherwise.
269+
*/
270+
bool multicore_lockout_victim_is_initialized(uint core_num);
271+
260272
/*! \brief Request the other core to pause in a known state and wait for it to do so
261273
* \ingroup multicore_lockout
262274
*

src/rp2_common/pico_multicore/multicore.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#include "pico/runtime.h"
1616
#endif
1717

18+
// note that these are not reset by core reset, however for now, I think people resetting cores
19+
// and then relying on multicore_lockout for that core without re-initializing, is probably
20+
// something we can live with breaking.
21+
//
22+
// whilst we could clear this in core 1 reset path, that doesn't necessarily catch all,
23+
// and means pulling in this array even if multicore_lockout is not used.
24+
static bool lockout_victim_initialized[NUM_CORES];
25+
1826
static inline void multicore_fifo_push_blocking_inline(uint32_t data) {
1927
// We wait for the fifo to have some space
2028
while (!multicore_fifo_wready())
@@ -201,6 +209,7 @@ void multicore_lockout_victim_init(void) {
201209
uint core_num = get_core_num();
202210
irq_set_exclusive_handler(SIO_IRQ_PROC0 + core_num, multicore_lockout_handler);
203211
irq_set_enabled(SIO_IRQ_PROC0 + core_num, true);
212+
lockout_victim_initialized[core_num] = true;
204213
}
205214

206215
static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) {
@@ -268,6 +277,10 @@ bool multicore_lockout_end_timeout_us(uint64_t timeout_us) {
268277
return multicore_lockout_end_block_until(make_timeout_time_us(timeout_us));
269278
}
270279

271-
void multicore_lockout_end_blocking() {
280+
void multicore_lockout_end_blocking(void) {
272281
multicore_lockout_end_block_until(at_the_end_of_time);
273282
}
283+
284+
bool multicore_lockout_victim_is_initialized(uint core_num) {
285+
return lockout_victim_initialized[core_num];
286+
}

0 commit comments

Comments
 (0)