io_reg.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Otto-von-Guericke-Universität Magdeburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
26 #include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
35 #define REG_ATOMIC_XOR_BIT (0x1000U)
36 
40 #define REG_ATOMIC_SET_BIT (0x2000U)
41 
45 #define REG_ATOMIC_CLEAR_BIT (0x3000U)
46 
51 #define REG_ATOMIC_XOR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_XOR_BIT))
52 
57 #define REG_ATOMIC_SET(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_SET_BIT))
58 
63 #define REG_ATOMIC_CLEAR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_CLEAR_BIT))
64 
72 static inline void io_reg_atomic_xor(volatile uint32_t *reg, uint32_t mask)
73 {
74  *REG_ATOMIC_XOR(reg) = mask;
75 }
76 
84 static inline void io_reg_atomic_set(volatile uint32_t *reg, uint32_t mask)
85 {
86  *REG_ATOMIC_SET(reg) = mask;
87 }
88 
96 static inline void io_reg_atomic_clear(volatile uint32_t *reg, uint32_t mask)
97 {
98  *REG_ATOMIC_CLEAR(reg) = mask;
99 }
100 
124 static inline void io_reg_write_dont_corrupt(volatile uint32_t *reg, uint32_t value, uint32_t mask)
125 {
126  *reg = (*reg & (~mask)) | value;
127 }
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
static void io_reg_atomic_xor(volatile uint32_t *reg, uint32_t mask)
Performed an atomic XOR of the set bits in op with the bits in the register at address reg.
Definition: io_reg.h:72
static void io_reg_atomic_clear(volatile uint32_t *reg, uint32_t mask)
Clear the bits in the register at address reg as given by the set bits in operand op.
Definition: io_reg.h:96
#define REG_ATOMIC_CLEAR(reg)
The operation to be performed to the register at address reg will be an atomic clear of the bits of t...
Definition: io_reg.h:63
static void io_reg_write_dont_corrupt(volatile uint32_t *reg, uint32_t value, uint32_t mask)
Updates part of an I/O register without corrupting its contents.
Definition: io_reg.h:124
#define REG_ATOMIC_SET(reg)
The operation to be performed to the register at address reg will be an atomic set of the bits of the...
Definition: io_reg.h:57
static void io_reg_atomic_set(volatile uint32_t *reg, uint32_t mask)
Set the bits in the register at address reg as given by the set bits in operand op.
Definition: io_reg.h:84
#define REG_ATOMIC_XOR(reg)
The operation to be performed to the register at address reg will be an atomic XOR of the bits of the...
Definition: io_reg.h:51