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 
9 #include "RP2350.h"
10 
22 #define ATOMIC_XOR_WRITE 0x1000u
24 #define ATOMIC_BITMASK_SET_WRITE 0x2000u
26 #define ATOMIC_BITMASK_CLEAR_WRITE 0x3000u
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
38 static inline void atomic_xor(volatile uint32_t *reg, uint32_t val) {
39  *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_XOR_WRITE) = val;
40 }
41 
48 static inline void atomic_set(volatile uint32_t *reg, uint32_t val) {
49  *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_BITMASK_SET_WRITE) = val;
50 }
51 
58 static inline void atomic_clear(volatile uint32_t *reg, uint32_t val) {
59  *(volatile uint32_t *)((uintptr_t)reg | ATOMIC_BITMASK_CLEAR_WRITE) = val;
60 }
61 
68 static inline void reset_component(uint32_t reset_value,
69  uint32_t reset_done_value) {
70  atomic_clear(&RESETS->RESET, reset_value);
71  while (~RESETS->RESET_DONE & reset_done_value) {
72  /* Wait for the reset to complete */
73  }
74 }
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
#define ATOMIC_XOR_WRITE
Bit to be set for an atomic XOR operation.
Definition: helpers.h:22
static void atomic_xor(volatile uint32_t *reg, uint32_t val)
Perform an atomic XOR write to a register.
Definition: helpers.h:38
#define ATOMIC_BITMASK_CLEAR_WRITE
Bits to be set for an atomic clear operation.
Definition: helpers.h:26
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:68
#define ATOMIC_BITMASK_SET_WRITE
Bit to be set for an atomic set operation.
Definition: helpers.h:24
static void atomic_clear(volatile uint32_t *reg, uint32_t val)
Clear bits in a register atomically.
Definition: helpers.h:58
static void atomic_set(volatile uint32_t *reg, uint32_t val)
Set bits in a register atomically.
Definition: helpers.h:48