Loading...
Searching...
No Matches
helpers.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Tom Hert <git@annsann.eu>
3 * SPDX-FileCopyrightText: 2025 HAW Hamburg
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
18
20#define ATOMIC_XOR_WRITE 0x1000u
22#define ATOMIC_BITMASK_SET_WRITE 0x2000u
24#define ATOMIC_BITMASK_CLEAR_WRITE 0x3000u
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
36static inline void atomic_xor(volatile uint32_t *reg, uint32_t val) {
37 *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_XOR_WRITE) = val;
38}
39
46static inline void atomic_set(volatile uint32_t *reg, uint32_t val) {
47 *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_BITMASK_SET_WRITE) = val;
48}
49
56static inline void atomic_clear(volatile uint32_t *reg, uint32_t val) {
57 *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_BITMASK_CLEAR_WRITE) = val;
58}
59
66static inline void reset_component(uint32_t reset_value,
67 uint32_t reset_done_value) {
68 atomic_clear(&RESETS->RESET, reset_value);
69 while (~RESETS->RESET_DONE & reset_done_value) {
70 /* Wait for the reset to complete */
71 }
72}
73
74#ifdef __cplusplus
75}
76#endif
77
#define ATOMIC_XOR_WRITE
Bit to be set for an atomic XOR operation.
Definition helpers.h:20
static void atomic_xor(volatile uint32_t *reg, uint32_t val)
Perform an atomic XOR write to a register.
Definition helpers.h:36
#define ATOMIC_BITMASK_CLEAR_WRITE
Bits to be set for an atomic clear operation.
Definition helpers.h:24
static void reset_component(uint32_t reset_value, uint32_t reset_done_value)
Reset a component by clearing its reset bits and waiting for the reset to complete.
Definition helpers.h:66
#define ATOMIC_BITMASK_SET_WRITE
Bit to be set for an atomic set operation.
Definition helpers.h:22
static void atomic_clear(volatile uint32_t *reg, uint32_t val)
Clear bits in a register atomically.
Definition helpers.h:56
static void atomic_set(volatile uint32_t *reg, uint32_t val)
Set bits in a register atomically.
Definition helpers.h:46