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
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_PICO_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_PICO_SUPPORT_MULTICORE_LOCKOUT
113#if LIB_PICO_MULTICORE
114#define PICO_FLASH_SAFE_EXECUTE_PICO_SUPPORT_MULTICORE_LOCKOUT 1
115#endif
116#endif
117
118typedef struct {
119 bool (*core_init_deinit)(bool init);
120 int (*enter_safe_zone_timeout_ms)(uint32_t timeout_ms);
121 int (*exit_safe_zone_timeout_ms)(uint32_t timeout_ms);
123
134
135#ifdef __cplusplus
136}
137#endif
138
139#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:64
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:74
bool flash_safe_execute_core_deinit(void)
De-initialize work done by flash_safe_execute_core_init.
Definition: flash.c:69
flash_safety_helper_t * get_flash_safety_helper(void)
Internal method to return the flash safety helper implementation.
Definition: flash.c:60
Definition: flash.h:118