Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
control.hpp
Go to the documentation of this file.
1/**
2 * @file control.hpp
3 * @brief ARM Cortex-M interrupt control primitives
4 * @ingroup hal
5 *
6 * Low-level hardware operations for ARM interrupt control using CMSIS intrinsics.
7 * Provides minimal hardware primitives without RAII - use patterns layer for convenience.
8 */
9
10#ifndef SBL_HAL_INTERRUPTS_CONTROL_HPP_
11#define SBL_HAL_INTERRUPTS_CONTROL_HPP_
12
13#include <cstdint>
14
15// ARM CMSIS intrinsics - platform provides implementation
16#ifndef __get_PRIMASK
17#define __get_PRIMASK() (0) // Fallback for non-ARM builds
18#endif
19
20#ifndef __disable_irq
21#define __disable_irq() do {} while(0) // Fallback for non-ARM builds
22#endif
23
24#ifndef __set_PRIMASK
25#define __set_PRIMASK(x) do { (void)(x); } while(0) // Fallback for non-ARM builds
26#endif
27
28namespace sbl {
29namespace hal {
30namespace interrupts {
31
32/**
33 * @brief Disable ARM interrupts and return previous state
34 *
35 * Disables all interrupts (except NMI/Hard Fault) using ARM PRIMASK register.
36 * Returns previous PRIMASK state for later restoration.
37 *
38 * @return Previous PRIMASK register value
39 */
40inline uint32_t disable_and_save() {
41 uint32_t saved_primask = __get_PRIMASK();
43 return saved_primask;
44}
45
46/**
47 * @brief Restore ARM interrupt state
48 *
49 * Restores PRIMASK register to specified state.
50 * Typically used with value returned from disable_and_save().
51 *
52 * @param saved_state Previous PRIMASK value to restore
53 */
54inline void restore(uint32_t saved_state) {
55 __set_PRIMASK(saved_state);
56}
57
58/**
59 * @brief Get current ARM interrupt state
60 *
61 * @return Current PRIMASK register value (0 = enabled, 1 = disabled)
62 */
63inline uint32_t get_state() {
64 return __get_PRIMASK();
65}
66
67/**
68 * @brief Check if ARM interrupts are enabled
69 *
70 * @return true if interrupts enabled, false if disabled
71 */
72inline bool are_enabled() {
73 return __get_PRIMASK() == 0;
74}
75
76} // namespace interrupts
77} // namespace hal
78} // namespace sbl
79
80#endif // SBL_HAL_INTERRUPTS_CONTROL_HPP_
#define __get_PRIMASK()
Definition control.hpp:17
#define __set_PRIMASK(x)
Definition control.hpp:25
#define __disable_irq()
Definition control.hpp:21
void restore(uint32_t saved_state)
Restore ARM interrupt state.
Definition control.hpp:54
uint32_t disable_and_save()
Disable ARM interrupts and return previous state.
Definition control.hpp:40
uint32_t get_state()
Get current ARM interrupt state.
Definition control.hpp:63
bool are_enabled()
Check if ARM interrupts are enabled.
Definition control.hpp:72
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24