multicore.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _PICO_MULTICORE_H
8 #define _PICO_MULTICORE_H
9 
10 #include "pico/types.h"
11 #include "pico/sync.h"
12 #include "hardware/structs/sio.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
27 // PICO_CONFIG: PICO_CORE1_STACK_SIZE, Stack size for core 1, min=0x100, max=0x10000, default=PICO_STACK_SIZE (0x800), group=pico_multicore
28 #ifndef PICO_CORE1_STACK_SIZE
29 #ifdef PICO_STACK_SIZE
30 #define PICO_CORE1_STACK_SIZE PICO_STACK_SIZE
31 #else
32 #define PICO_CORE1_STACK_SIZE 0x800
33 #endif
34 #endif
35 
43 void multicore_reset_core1(void);
44 
57 void multicore_launch_core1(void (*entry)(void));
58 
73 void multicore_launch_core1_with_stack(void (*entry)(void), uint32_t *stack_bottom, size_t stack_size_bytes);
74 
90 void multicore_launch_core1_raw(void (*entry)(void), uint32_t *sp, uint32_t vector_table);
91 
115 static inline bool multicore_fifo_rvalid(void) {
116  return !!(sio_hw->fifo_st & SIO_FIFO_ST_VLD_BITS);
117 }
118 
126 static inline bool multicore_fifo_wready(void) {
127  return !!(sio_hw->fifo_st & SIO_FIFO_ST_RDY_BITS);
128 }
129 
141 void multicore_fifo_push_blocking(uint32_t data);
142 
153 bool multicore_fifo_push_timeout_us(uint32_t data, uint64_t timeout_us);
154 
166 uint32_t multicore_fifo_pop_blocking(void);
167 
179 bool multicore_fifo_pop_timeout_us(uint64_t timeout_us, uint32_t *out);
180 
186 static inline void multicore_fifo_drain(void) {
187  while (multicore_fifo_rvalid())
188  (void) sio_hw->fifo_rd;
189 }
190 
201 static inline void multicore_fifo_clear_irq(void) {
202  // Write any value to clear the error flags
203  sio_hw->fifo_st = 0xff;
204 }
205 
221 static inline uint32_t multicore_fifo_get_status(void) {
222  return sio_hw->fifo_st;
223 }
224 
259 
269 
281 bool multicore_lockout_start_timeout_us(uint64_t timeout_us);
282 
290 
305 bool multicore_lockout_end_timeout_us(uint64_t timeout_us);
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 #endif
multicore_lockout_end_blocking
void multicore_lockout_end_blocking(void)
Release the other core from a locked out state amd wait for it to acknowledge.
Definition: multicore.c:271
multicore_reset_core1
void multicore_reset_core1(void)
Reset core 1.
Definition: multicore.c:92
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:29
multicore_fifo_drain
static void multicore_fifo_drain(void)
Discard any data in the read FIFO.
Definition: multicore.h:186
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:33
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:57
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:249
multicore_lockout_end_timeout_us
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:267
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:126
multicore_launch_core1
void multicore_launch_core1(void(*entry)(void))
Run code on core 1.
Definition: multicore.c:124
multicore_fifo_get_status
static uint32_t multicore_fifo_get_status(void)
Get FIFO statuses.
Definition: multicore.h:221
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:132
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:115
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:61
sync.h
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:199
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:109
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:245
multicore_fifo_clear_irq
static void multicore_fifo_clear_irq(void)
Clear FIFO interrupt.
Definition: multicore.h:201