lock.h
1/*
2 * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_BOOTROM_LOCK_H
8#define _PICO_BOOTROM_LOCK_H
9
10#include "hardware/boot_lock.h"
11#include "pico/bootrom_constants.h"
12
13// PICO_CONFIG: PICO_BOOTROM_LOCKING_ENABLED, Enable/disable locking for bootrom functions that use shared reqsources. If this flag is enabled bootrom lock checking is turned on and BOOT locks are taken around the relevant bootrom functions, type=bool, default=1, group=pico_bootrom
14#ifndef PICO_BOOTROM_LOCKING_ENABLED
15#if NUM_BOOT_LOCKS > 0
16#define PICO_BOOTROM_LOCKING_ENABLED 1
17#endif
18#endif
19
28static inline bool bootrom_try_acquire_lock(uint lock_num) {
29#if PICO_BOOTROM_LOCKING_ENABLED
30 // unsafe as this is a long term lock (so no irq disable)
31 return boot_try_lock_unsafe(boot_lock_instance(lock_num));
32#else
33 (void)lock_num;
34 return true;
35#endif
36}
37
45static inline void bootrom_acquire_lock_blocking(uint lock_num) {
46#if PICO_BOOTROM_LOCKING_ENABLED
47 // unsafe as this is a long term lock (so no irq disable)
48 boot_lock_unsafe_blocking(boot_lock_instance(lock_num));
49#else
50 (void)lock_num;
51#endif
52}
53
61static inline void bootrom_release_lock(uint lock_num) {
62#if PICO_BOOTROM_LOCKING_ENABLED
63 boot_unlock_unsafe(boot_lock_instance(lock_num));
64#else
65 (void)lock_num;
66#endif
67}
68
69#endif