Loading...
Searching...
No Matches
flash.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_FLASH_H
8#define _PICO_FLASH_H
9
10#include "pico.h"
11
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
64
71
87int flash_safe_execute(void (*func)(void *), void *param, uint32_t enter_exit_timeout_ms);
88
89// PICO_CONFIG: PICO_FLASH_ASSERT_ON_UNSAFE, Assert in debug mode rather than returning an error if flash_safe_execute cannot guarantee safety to catch bugs early, type=bool, default=1, group=pico_flash
90#ifndef PICO_FLASH_ASSERT_ON_UNSAFE
91#define PICO_FLASH_ASSERT_ON_UNSAFE 1
92#endif
93
94// PICO_CONFIG: PICO_FLASH_ASSUME_CORE0_SAFE, Assume that core 0 will never be accessing flash and so doesn't need to be considered during flash_safe_execute, type=bool, default=0, group=pico_flash
95#ifndef PICO_FLASH_ASSUME_CORE0_SAFE
96#define PICO_FLASH_ASSUME_CORE0_SAFE 0
97#endif
98
99// PICO_CONFIG: PICO_FLASH_ASSUME_CORE1_SAFE, Assume that core 1 will never be accessing flash and so doesn't need to be considered during flash_safe_execute, type=bool, default=0, group=pico_flash
100#ifndef PICO_FLASH_ASSUME_CORE1_SAFE
101#define PICO_FLASH_ASSUME_CORE1_SAFE 0
102#endif
103
104// PICO_CONFIG: PICO_FLASH_SAFE_EXECUTE_SUPPORT_FREERTOS_SMP, Support using FreeRTOS SMP to make the other core safe during flash_safe_execute, type=bool, default=1 when using FreeRTOS SMP, group=pico_flash
105#ifndef PICO_FLASH_SAFE_EXECUTE_SUPPORT_FREERTOS_SMP
106#if LIB_FREERTOS_KERNEL && FREE_RTOS_KERNEL_SMP // set by RP2040 SMP port
107#define PICO_FLASH_SAFE_EXECUTE_SUPPORT_FREERTOS_SMP 1
108#endif
109#endif
110
111// PICO_CONFIG: PICO_FLASH_SAFE_EXECUTE_SUPPORT_MULTICORE_LOCKOUT, Support using multicore_lockout functions to make the other core safe during flash_safe_execute, type=bool, default=1 when using pico_multicore, group=pico_flash
112#ifndef PICO_FLASH_SAFE_EXECUTE_SUPPORT_MULTICORE_LOCKOUT
113#ifdef PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT
114// support old misspelling
115#define PICO_FLASH_SAFE_EXECUTE_SUPPORT_MULTICORE_LOCKOUT PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT
116#elif LIB_PICO_MULTICORE
117#define PICO_FLASH_SAFE_EXECUTE_SUPPORT_MULTICORE_LOCKOUT 1
118#endif
119#endif
120
127typedef struct {
128 bool (*core_init_deinit)(bool init);
129 int (*enter_safe_zone_timeout_ms)(uint32_t timeout_ms);
130 int (*exit_safe_zone_timeout_ms)(uint32_t timeout_ms);
132
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif
bool flash_safe_execute_core_init(void)
Initialize a core such that the other core can lock it out during flash_safe_execute.
Definition flash.c:65
int flash_safe_execute(void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)
Execute a function with IRQs disabled and with the other core also not executing/reading flash.
Definition flash.c:75
bool flash_safe_execute_core_deinit(void)
De-initialize work done by flash_safe_execute_core_init.
Definition flash.c:70
flash_safety_helper_t * get_flash_safety_helper(void)
Internal method to return the flash safety helper implementation.
Definition flash.c:61
Helper interface for coordinating safe flash access across cores.
Definition flash.h:127
bool(* core_init_deinit)(bool init)
Initialize (init=true) or de-initialise (init=false) this core's participation in flash safety.
Definition flash.h:128
int(* exit_safe_zone_timeout_ms)(uint32_t timeout_ms)
Exit the safe zone, unblocking the other core, waiting up to timeout_ms milliseconds.
Definition flash.h:130
int(* enter_safe_zone_timeout_ms)(uint32_t timeout_ms)
Enter the safe zone, blocking until safe or until timeout_ms milliseconds elapse.
Definition flash.h:129