io_reg.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
29 #include <stdint.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 #define REG_ATOMIC_XOR_BIT (0x1000U)
39 
43 #define REG_ATOMIC_SET_BIT (0x2000U)
44 
48 #define REG_ATOMIC_CLEAR_BIT (0x3000U)
49 
54 #define REG_ATOMIC_XOR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_XOR_BIT))
55 
60 #define REG_ATOMIC_SET(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_SET_BIT))
61 
66 #define REG_ATOMIC_CLEAR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_CLEAR_BIT))
67 
75 static inline void io_reg_atomic_xor(volatile uint32_t *reg, uint32_t mask)
76 {
77  *REG_ATOMIC_XOR(reg) = mask;
78 }
79 
87 static inline void io_reg_atomic_set(volatile uint32_t *reg, uint32_t mask)
88 {
89  *REG_ATOMIC_SET(reg) = mask;
90 }
91 
99 static inline void io_reg_atomic_clear(volatile uint32_t *reg, uint32_t mask)
100 {
101  *REG_ATOMIC_CLEAR(reg) = mask;
102 }
103 
127 static inline void io_reg_write_dont_corrupt(volatile uint32_t *reg, uint32_t value, uint32_t mask)
128 {
129  *reg = (*reg & (~mask)) | value;
130 }
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
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:75
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:99
#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:66
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:127
#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:60
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:87
#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:54