@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
critical_section.h
Go to the documentation of this file.
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_CRITICAL_SECTION_H
#define _PICO_CRITICAL_SECTION_H
#include "pico.h"
#include "pico/lock_core.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct __packed_aligned critical_section {
spin_lock_t *spin_lock;
uint32_t save;
} critical_section_t;
void critical_section_init(critical_section_t *crit_sec);
void critical_section_init_with_lock_num(critical_section_t *crit_sec, uint lock_num);
__force_inline static void critical_section_enter_blocking(critical_section_t *crit_sec) {
crit_sec->save = spin_lock_blocking(crit_sec->spin_lock);
}
__force_inline static void critical_section_exit(critical_section_t *crit_sec) {
spin_unlock(crit_sec->spin_lock, crit_sec->save);
}
void critical_section_deinit(critical_section_t *crit_sec);
static inline bool critical_section_is_initialized(critical_section_t *crit_sec) {
return crit_sec->spin_lock != 0;
}
#ifdef __cplusplus
}
#endif
#endif
critical_section_deinit
void critical_section_deinit(critical_section_t *crit_sec)
De-Initialise a critical_section created by the critical_section_init method.
Definition critical_section.c:22
critical_section_init
void critical_section_init(critical_section_t *crit_sec)
Initialise a critical_section structure allowing the system to assign a spin lock number.
Definition critical_section.c:13
critical_section_enter_blocking
static __force_inline void critical_section_enter_blocking(critical_section_t *crit_sec)
Enter a critical_section.
Definition critical_section.h:62
critical_section_exit
static __force_inline void critical_section_exit(critical_section_t *crit_sec)
Release a critical_section.
Definition critical_section.h:71
critical_section_init_with_lock_num
void critical_section_init_with_lock_num(critical_section_t *crit_sec, uint lock_num)
Initialise a critical_section structure assigning a specific spin lock number.
Definition critical_section.c:17
spin_lock_blocking
static __force_inline uint32_t spin_lock_blocking(spin_lock_t *lock)
Acquire a spin lock safely.
Definition spin_lock.h:301
spin_lock_t
io_rw_32 spin_lock_t
A spin lock identifier.
Definition spin_lock.h:84
spin_unlock
static __force_inline void spin_unlock(spin_lock_t *lock, uint32_t saved_irq)
Release a spin lock safely.
Definition spin_lock.h:332
critical_section_is_initialized
static bool critical_section_is_initialized(critical_section_t *crit_sec)
Test whether a critical_section has been initialized.
Definition critical_section.h:92
__force_inline
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition compiler.h:128
lock_core.h
pico.h
critical_section
Definition critical_section.h:30