Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/rp2_common/pico_flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ static flash_safety_helper_t default_flash_safety_helper = {
.exit_safe_zone_timeout_ms = default_exit_safe_zone_timeout_ms
};

#if PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT
// note that these are not reset by core reset, however for now, I think people resetting cores
// and then doing this again without re-initializing pico_flash for that core, is probably
// something we can live with breaking.
static bool core_initialized[NUM_CORES];
#endif

#if PICO_FLASH_SAFE_EXECUTE_USE_FREERTOS_SMP
enum {
FREERTOS_LOCKOUT_NONE = 0,
Expand Down Expand Up @@ -105,7 +98,6 @@ static bool default_core_init_deinit(__unused bool init) {
return false;
}
multicore_lockout_victim_init();
core_initialized[get_core_num()] = init;
#endif
return true;
}
Expand Down Expand Up @@ -182,7 +174,7 @@ static int default_enter_safe_zone_timeout_ms(__unused uint32_t timeout_ms) {
#endif
rc = PICO_ERROR_NOT_PERMITTED;
#else // !LIB_FREERTOS_KERNEL
if (core_initialized[get_core_num()^1]) {
if (multicore_lockout_victim_is_initialized(get_core_num()^1)) {
if (!multicore_lockout_start_timeout_us(timeout_ms * 1000ull)) {
rc = PICO_ERROR_TIMEOUT;
}
Expand Down
12 changes: 12 additions & 0 deletions src/rp2_common/pico_multicore/include/pico/multicore.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ static inline uint32_t multicore_fifo_get_status(void) {
*/
void multicore_lockout_victim_init(void);

/*! \brief Determine if \ref multicore_victim_init() has been called on the specified core.
* \ingroup multicore_lockout
*
* \note this state persists even if the core is subsequently reset; therefore you are advised to
* always call \ref multicore_lockout_victim_init() again after resetting a core, which had previously
* been initialized.
*
* \param core_num the core number (0 or 1)
* \return true if \ref multicore_victim_init() has been called on the specified core, false otherwise.
*/
bool multicore_lockout_victim_is_initialized(uint core_num);

/*! \brief Request the other core to pause in a known state and wait for it to do so
* \ingroup multicore_lockout
*
Expand Down
15 changes: 14 additions & 1 deletion src/rp2_common/pico_multicore/multicore.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
#include "pico/runtime.h"
#endif

// note that these are not reset by core reset, however for now, I think people resetting cores
// and then relying on multicore_lockout for that core without re-initializing, is probably
// something we can live with breaking.
//
// whilst we could clear this in core 1 reset path, that doesn't necessarily catch all,
// and means pulling in this array even if multicore_lockout is not used.
static bool lockout_victim_initialized[NUM_CORES];

static inline void multicore_fifo_push_blocking_inline(uint32_t data) {
// We wait for the fifo to have some space
while (!multicore_fifo_wready())
Expand Down Expand Up @@ -201,6 +209,7 @@ void multicore_lockout_victim_init(void) {
uint core_num = get_core_num();
irq_set_exclusive_handler(SIO_IRQ_PROC0 + core_num, multicore_lockout_handler);
irq_set_enabled(SIO_IRQ_PROC0 + core_num, true);
lockout_victim_initialized[core_num] = true;
}

static bool multicore_lockout_handshake(uint32_t magic, absolute_time_t until) {
Expand Down Expand Up @@ -268,6 +277,10 @@ bool multicore_lockout_end_timeout_us(uint64_t timeout_us) {
return multicore_lockout_end_block_until(make_timeout_time_us(timeout_us));
}

void multicore_lockout_end_blocking() {
void multicore_lockout_end_blocking(void) {
multicore_lockout_end_block_until(at_the_end_of_time);
}

bool multicore_lockout_victim_is_initialized(uint core_num) {
return lockout_victim_initialized[core_num];
}