diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2017-01-21 14:55:27 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2017-01-21 14:55:27 +0000 |
commit | 68c89856c1fc310ad0d75ae1df9d000704e87c8a (patch) | |
tree | aa60906eb89e33f967d51fa304600f44dd684cdc /reg/regdefs.h | |
download | mk20dx256-68c89856c1fc310ad0d75ae1df9d000704e87c8a.tar.gz mk20dx256-68c89856c1fc310ad0d75ae1df9d000704e87c8a.tar.xz mk20dx256-68c89856c1fc310ad0d75ae1df9d000704e87c8a.zip |
Init commit
Diffstat (limited to 'reg/regdefs.h')
-rw-r--r-- | reg/regdefs.h | 25 |
1 files changed, 25 insertions, 0 deletions
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 <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 */ |