@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
multicore.h
Go to the documentation of this file.
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_MULTICORE_H
#define _PICO_MULTICORE_H
#include "pico/types.h"
#include "pico/sync.h"
#include "hardware/structs/sio.h"
#ifdef __cplusplus
extern "C" {
#endif
// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PICO_MULTICORE, Enable/disable assertions in the pico_multicore module, type=bool, default=0, group=pico_multicore
#ifndef PARAM_ASSERTIONS_ENABLED_PICO_MULTICORE
#define PARAM_ASSERTIONS_ENABLED_PICO_MULTICORE 0
#endif
// PICO_CONFIG: PICO_CORE1_STACK_SIZE, Minimum amount of stack space reserved in the linker script for core 1 - if zero then no space is reserved and the user must provide their own stack, min=0, max=0x10000, default=PICO_STACK_SIZE (0x800), group=pico_multicore
#ifndef PICO_CORE1_STACK_SIZE
#ifdef PICO_STACK_SIZE
#define PICO_CORE1_STACK_SIZE PICO_STACK_SIZE
#else
#define PICO_CORE1_STACK_SIZE 0x800
#endif
#endif
#ifndef SIO_FIFO_IRQ_NUM
#if !PICO_RP2040
#define SIO_FIFO_IRQ_NUM(core) SIO_IRQ_FIFO
#else
static_assert(SIO_IRQ_PROC1 == SIO_IRQ_PROC0 + 1, "");
#define SIO_FIFO_IRQ_NUM(core) (SIO_IRQ_PROC0 + (core))
#endif
#endif
void multicore_reset_core1(void);
void multicore_launch_core1(void (*entry)(void));
void multicore_launch_core1_with_stack(void (*entry)(void), uint32_t *stack_bottom, size_t stack_size_bytes);
void multicore_launch_core1_raw(void (*entry)(void), uint32_t *sp, uint32_t vector_table);
static inline bool multicore_fifo_rvalid(void) {
return sio_hw->fifo_st & SIO_FIFO_ST_VLD_BITS;
}
static inline bool multicore_fifo_wready(void) {
return sio_hw->fifo_st & SIO_FIFO_ST_RDY_BITS;
}
void multicore_fifo_push_blocking(uint32_t data);
static inline void multicore_fifo_push_blocking_inline(uint32_t data) {
// We wait for the fifo to have some space
while (!multicore_fifo_wready())
tight_loop_contents();
sio_hw->fifo_wr = data;
// Fire off an event to the other core
__sev();
}
bool multicore_fifo_push_timeout_us(uint32_t data, uint64_t timeout_us);
uint32_t multicore_fifo_pop_blocking(void);
static inline uint32_t multicore_fifo_pop_blocking_inline(void) {
// If nothing there yet, we wait for an event first,
// to try and avoid too much busy waiting
while (!multicore_fifo_rvalid())
__wfe();
return sio_hw->fifo_rd;
}
bool multicore_fifo_pop_timeout_us(uint64_t timeout_us, uint32_t *out);
static inline void multicore_fifo_drain(void) {
while (multicore_fifo_rvalid())
(void) sio_hw->fifo_rd;
}
static inline void multicore_fifo_clear_irq(void) {
// Write any value to clear the error flags
sio_hw->fifo_st = 0xff;
}
static inline uint32_t multicore_fifo_get_status(void) {
return sio_hw->fifo_st;
}
#if NUM_DOORBELLS
static inline void check_doorbell_num_param(__unused uint doorbell_num) {
invalid_params_if(PICO_MULTICORE, doorbell_num >= NUM_DOORBELLS);
}
void multicore_doorbell_claim(uint doorbell_num, uint core_mask);
int multicore_doorbell_claim_unused(uint core_mask, bool required);
void multicore_doorbell_unclaim(uint doorbell_num, uint core_mask);
static inline void multicore_doorbell_set_other_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
sio_hw->doorbell_out_set = 1u << doorbell_num;
}
static inline void multicore_doorbell_clear_other_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
sio_hw->doorbell_out_clr = 1u << doorbell_num;
}
static inline void multicore_doorbell_set_current_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
sio_hw->doorbell_in_set = 1u << doorbell_num;
}
static inline void multicore_doorbell_clear_current_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
sio_hw->doorbell_in_clr = 1u << doorbell_num;
}
static inline bool multicore_doorbell_is_set_current_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
return sio_hw->doorbell_in_set & (1u << doorbell_num);
}
static inline bool multicore_doorbell_is_set_other_core(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
return sio_hw->doorbell_out_set & (1u << doorbell_num);
}
#ifndef DOORBELL_IRQ_NUM
#define DOORBELL_IRQ_NUM(doorbell_num) SIO_IRQ_BELL
#endif
static inline uint multicore_doorbell_irq_num(uint doorbell_num) {
check_doorbell_num_param(doorbell_num);
return DOORBELL_IRQ_NUM(doorbell_num);
}
#endif
void multicore_lockout_victim_init(void);
void multicore_lockout_victim_deinit(void);
bool multicore_lockout_victim_is_initialized(uint core_num);
void multicore_lockout_start_blocking(void);
bool multicore_lockout_start_timeout_us(uint64_t timeout_us);
void multicore_lockout_end_blocking(void);
bool multicore_lockout_end_timeout_us(uint64_t timeout_us);
#ifdef __cplusplus
}
#endif
#endif
sync.h
SIO_IRQ_PROC0
@ SIO_IRQ_PROC0
Select SIO_PROC0's IRQ output.
Definition intctrl.h:69
SIO_IRQ_PROC1
@ SIO_IRQ_PROC1
Select SIO_PROC1's IRQ output.
Definition intctrl.h:70
__sev
static __force_inline void __sev(void)
Insert a SEV instruction in to the code path.
Definition sync.h:90
__wfe
static __force_inline void __wfe(void)
Insert a WFE instruction in to the code path.
Definition sync.h:106
multicore_fifo_push_timeout_us
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:37
multicore_fifo_push_blocking
void multicore_fifo_push_blocking(uint32_t data)
Push data on to the write FIFO (data to the other core).
Definition multicore.c:33
multicore_fifo_pop_timeout_us
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:56
multicore_fifo_pop_blocking_inline
static uint32_t multicore_fifo_pop_blocking_inline(void)
Pop data from the read FIFO (data from the other core).
Definition multicore.h:231
multicore_fifo_drain
static void multicore_fifo_drain(void)
Discard any data in the read FIFO.
Definition multicore.h:258
multicore_fifo_push_blocking_inline
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
multicore_fifo_wready
static bool multicore_fifo_wready(void)
Check the write FIFO to see if it has space for more data.
Definition multicore.h:156
multicore_fifo_get_status
static uint32_t multicore_fifo_get_status(void)
Get FIFO statuses.
Definition multicore.h:293
multicore_fifo_pop_blocking
uint32_t multicore_fifo_pop_blocking(void)
Pop data from the read FIFO (data from the other core).
Definition multicore.c:52
multicore_fifo_clear_irq
static void multicore_fifo_clear_irq(void)
Clear FIFO interrupt.
Definition multicore.h:273
multicore_fifo_rvalid
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
multicore_lockout_victim_is_initialized
bool multicore_lockout_victim_is_initialized(uint core_num)
Determine if multicore_lockout_victim_init() has been called on the specified core.
Definition multicore.c:347
multicore_lockout_victim_init
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:244
multicore_lockout_victim_deinit
void multicore_lockout_victim_deinit(void)
Stop the current core being able to be a "victim" of lockout (i.e. forced to pause in a known state b...
Definition multicore.c:255
multicore_lockout_start_blocking
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:324
multicore_lockout_start_timeout_us
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:320
multicore_lockout_end_blocking
void multicore_lockout_end_blocking(void)
Release the other core from a locked out state.
Definition multicore.c:343
multicore_lockout_end_timeout_us
bool multicore_lockout_end_timeout_us(uint64_t timeout_us)
Release the other core from a locked out state.
Definition multicore.c:339
multicore_launch_core1
void multicore_launch_core1(void(*entry)(void))
Run code on core 1.
Definition multicore.c:164
multicore_launch_core1_with_stack
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:141
multicore_launch_core1_raw
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:176
multicore_reset_core1
void multicore_reset_core1(void)
Reset core 1.
Definition multicore.c:101
tight_loop_contents
static __force_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition common.h:74