summaryrefslogtreecommitdiffstats
path: root/lib/reg/regdefs.h
blob: 6a38c767e6aaac43c93e34e85723acf00d85fa95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef LIB_REG_REGDEFS_H
#define LIB_REG_REGDEFS_H

#include <stdint.h>

#define REG_8(a) (*(volatile uint8_t *)(a))
#define REG_16(a) (*(volatile uint16_t *)(a))
#define REG_32(a) (*(volatile uint32_t *)(a))

#define BV(b) (1 << (b))
#define IS_BIT_SET(reg, bit) (!!((reg) & BV(bit)))
#define WAIT_BIT_UNSET(reg, bit) do { } while (IS_BIT_SET(reg, bit))
#define WAIT_BIT_SET(reg, bit) do { } while (!IS_BIT_SET(reg, bit))

#define SET_BIT(reg, bit) ((reg) |= BV(bit))
#define UNSET_BIT(reg, bit) ((reg) &= ~BV(bit))

#define GET_BIT(reg, bit) !!((reg) & BV(bit))
#define GET_BITS(reg, offset) (((reg) & (offset ## _M)) >> (offset))

#define SET_MASKED(reg, mask, bits) ((reg) = ((reg) & ~(mask)) | ((bits) & (mask)))

#define BITS(n) (0xffffffff >> (32 - (n)))

#endif /* LIB_REG_REGDEFS_H */