Loading...
Searching...
No Matches
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
27#ifndef IO_REG_H
28#define IO_REG_H
29
30#include <stdint.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
39#define REG_ATOMIC_XOR_BIT (0x1000U)
40
44#define REG_ATOMIC_SET_BIT (0x2000U)
45
49#define REG_ATOMIC_CLEAR_BIT (0x3000U)
50
55#define REG_ATOMIC_XOR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_XOR_BIT))
56
61#define REG_ATOMIC_SET(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_SET_BIT))
62
67#define REG_ATOMIC_CLEAR(reg) ((volatile uint32_t *)(((uintptr_t)(reg)) | REG_ATOMIC_CLEAR_BIT))
68
76static inline void io_reg_atomic_xor(volatile uint32_t *reg, uint32_t mask)
77{
78 *REG_ATOMIC_XOR(reg) = mask;
79}
80
88static inline void io_reg_atomic_set(volatile uint32_t *reg, uint32_t mask)
89{
90 *REG_ATOMIC_SET(reg) = mask;
91}
92
100static inline void io_reg_atomic_clear(volatile uint32_t *reg, uint32_t mask)
101{
102 *REG_ATOMIC_CLEAR(reg) = mask;
103}
104
128static inline void io_reg_write_dont_corrupt(volatile uint32_t *reg, uint32_t value, uint32_t mask)
129{
130 *reg = (*reg & (~mask)) | value;
131}
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* IO_REG_H */
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:76
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:100
#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:67
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:128
#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:61
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:88
#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:55