7#ifndef _PICO_MULTICORE_H
8#define _PICO_MULTICORE_H
10#include "pico/types.h"
12#include "hardware/structs/sio.h"
19#ifndef PARAM_ASSERTIONS_ENABLED_PICO_MULTICORE
20#define PARAM_ASSERTIONS_ENABLED_PICO_MULTICORE 0
33#ifndef PICO_CORE1_STACK_SIZE
35#define PICO_CORE1_STACK_SIZE PICO_STACK_SIZE
37#define PICO_CORE1_STACK_SIZE 0x800
57#ifndef SIO_FIFO_IRQ_NUM
59#define SIO_FIFO_IRQ_NUM(core) SIO_IRQ_FIFO
62#define SIO_FIFO_IRQ_NUM(core) (SIO_IRQ_PROC0 + (core))
146 return sio_hw->fifo_st & SIO_FIFO_ST_VLD_BITS;
157 return sio_hw->fifo_st & SIO_FIFO_ST_RDY_BITS;
189 sio_hw->fifo_wr = data;
237 return sio_hw->fifo_rd;
260 (void) sio_hw->fifo_rd;
275 sio_hw->fifo_st = 0xff;
294 return sio_hw->fifo_st;
308static inline void check_doorbell_num_param(__unused uint doorbell_num) {
309 invalid_params_if(PICO_MULTICORE, doorbell_num >= NUM_DOORBELLS);
321void multicore_doorbell_claim(uint doorbell_num, uint core_mask);
333int multicore_doorbell_claim_unused(uint core_mask,
bool required);
342void multicore_doorbell_unclaim(uint doorbell_num, uint core_mask);
348static inline void multicore_doorbell_set_other_core(uint doorbell_num) {
349 check_doorbell_num_param(doorbell_num);
350 sio_hw->doorbell_out_set = 1u << doorbell_num;
357static inline void multicore_doorbell_clear_other_core(uint doorbell_num) {
358 check_doorbell_num_param(doorbell_num);
359 sio_hw->doorbell_out_clr = 1u << doorbell_num;
366static inline void multicore_doorbell_set_current_core(uint doorbell_num) {
367 check_doorbell_num_param(doorbell_num);
368 sio_hw->doorbell_in_set = 1u << doorbell_num;
375static inline void multicore_doorbell_clear_current_core(uint doorbell_num) {
376 check_doorbell_num_param(doorbell_num);
377 sio_hw->doorbell_in_clr = 1u << doorbell_num;
384static inline bool multicore_doorbell_is_set_current_core(uint doorbell_num) {
385 check_doorbell_num_param(doorbell_num);
386 return sio_hw->doorbell_in_set & (1u << doorbell_num);
393static inline bool multicore_doorbell_is_set_other_core(uint doorbell_num) {
394 check_doorbell_num_param(doorbell_num);
395 return sio_hw->doorbell_out_set & (1u << doorbell_num);
406#ifndef DOORBELL_IRQ_NUM
407#define DOORBELL_IRQ_NUM(doorbell_num) SIO_IRQ_BELL
410static inline uint multicore_doorbell_irq_num(uint doorbell_num) {
411 check_doorbell_num_param(doorbell_num);
412 return DOORBELL_IRQ_NUM(doorbell_num);
@ SIO_IRQ_PROC0
Select SIO_PROC0's IRQ output.
Definition intctrl.h:63
@ SIO_IRQ_PROC1
Select SIO_PROC1's IRQ output.
Definition intctrl.h:64
static __force_inline void __sev(void)
Insert a SEV instruction in to the code path.
Definition sync.h:90
static __force_inline void __wfe(void)
Insert a WFE instruction in to the code path.
Definition sync.h:106
bool multicore_fifo_push_timeout_us(uint32_t data, uint64_t timeout_us)
Push data on to the write FIFO (data to the other core) with timeout.
Definition multicore.c:38
void multicore_fifo_push_blocking(uint32_t data)
Push data on to the write FIFO (data to the other core).
Definition multicore.c:34
bool multicore_fifo_pop_timeout_us(uint64_t timeout_us, uint32_t *out)
Pop data from the read FIFO (data from the other core) with timeout.
Definition multicore.c:57
static uint32_t multicore_fifo_pop_blocking_inline(void)
Pop data from the read FIFO (data from the other core).
Definition multicore.h:231
static void multicore_fifo_drain(void)
Discard any data in the read FIFO.
Definition multicore.h:258
static void multicore_fifo_push_blocking_inline(uint32_t data)
Push data on to the write FIFO (data to the other core).
Definition multicore.h:184
static bool multicore_fifo_wready(void)
Check the write FIFO to see if it has space for more data.
Definition multicore.h:156
static uint32_t multicore_fifo_get_status(void)
Get FIFO statuses.
Definition multicore.h:293
uint32_t multicore_fifo_pop_blocking(void)
Pop data from the read FIFO (data from the other core).
Definition multicore.c:53
static void multicore_fifo_clear_irq(void)
Clear FIFO interrupt.
Definition multicore.h:273
static bool multicore_fifo_rvalid(void)
Check the read FIFO to see if there is data available (sent by the other core)
Definition multicore.h:145
bool multicore_lockout_victim_is_initialized(uint core_num)
Determine if multicore_victim_init() has been called on the specified core.
Definition multicore.c:309
void multicore_lockout_victim_init(void)
Initialize the current core such that it can be a "victim" of lockout (i.e. forced to pause in a know...
Definition multicore.c:229
void multicore_lockout_start_blocking(void)
Request the other core to pause in a known state and wait for it to do so.
Definition multicore.c:283
bool multicore_lockout_start_timeout_us(uint64_t timeout_us)
Request the other core to pause in a known state and wait up to a time limit for it to do so.
Definition multicore.c:279
void multicore_lockout_end_blocking(void)
Release the other core from a locked out state amd wait for it to acknowledge.
Definition multicore.c:305
bool multicore_lockout_end_timeout_us(uint64_t timeout_us)
Release the other core from a locked out state amd wait up to a time limit for it to acknowledge.
Definition multicore.c:301
void multicore_launch_core1(void(*entry)(void))
Run code on core 1.
Definition multicore.c:155
void multicore_launch_core1_with_stack(void(*entry)(void), uint32_t *stack_bottom, size_t stack_size_bytes)
Launch code on core 1 with stack.
Definition multicore.c:132
void multicore_launch_core1_raw(void(*entry)(void), uint32_t *sp, uint32_t vector_table)
Launch code on core 1 with no stack protection.
Definition multicore.c:163
void multicore_reset_core1(void)
Reset core 1.
Definition multicore.c:100