From 68c89856c1fc310ad0d75ae1df9d000704e87c8a Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 21 Jan 2017 14:55:27 +0000 Subject: Init commit --- reg/regdefs.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 reg/regdefs.h (limited to 'reg/regdefs.h') diff --git a/reg/regdefs.h b/reg/regdefs.h new file mode 100644 index 0000000..6a38c76 --- /dev/null +++ b/reg/regdefs.h @@ -0,0 +1,25 @@ +#ifndef LIB_REG_REGDEFS_H +#define LIB_REG_REGDEFS_H + +#include + +#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 */ -- cgit v1.2.3-54-g00ecf