Remove unnecessary AND for VAL2FIELD macro
Added VAL2FIELD_M / SET_FIELD_M for rare cases when there might actually be some need for it.
This commit is contained in:
parent
22d35ed5f2
commit
2a939e97b5
1 changed files with 10 additions and 1 deletions
|
@ -20,12 +20,21 @@
|
||||||
* and shift) constants. Used primarily with ESP8266 register access.
|
* and shift) constants. Used primarily with ESP8266 register access.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define VAL2FIELD(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
|
#define VAL2FIELD(fieldname, value) ((value) << fieldname##_S)
|
||||||
#define FIELD2VAL(fieldname, regbits) (((regbits) >> fieldname##_S) & fieldname##_M)
|
#define FIELD2VAL(fieldname, regbits) (((regbits) >> fieldname##_S) & fieldname##_M)
|
||||||
|
|
||||||
#define FIELD_MASK(fieldname) (fieldname##_M << fieldname##_S)
|
#define FIELD_MASK(fieldname) (fieldname##_M << fieldname##_S)
|
||||||
#define SET_FIELD(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD(fieldname, value))
|
#define SET_FIELD(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD(fieldname, value))
|
||||||
|
|
||||||
|
/* VAL2FIELD/SET_FIELD do not normally check to make sure that the passed value
|
||||||
|
* will fit in the specified field (without clobbering other bits). This makes
|
||||||
|
* them faster and is usually fine. If you do need to make sure that the value
|
||||||
|
* will not overflow the field, use VAL2FIELD_M or SET_FIELD_M (which will
|
||||||
|
* first mask the supplied value to only the allowed number of bits) instead.
|
||||||
|
*/
|
||||||
|
#define VAL2FIELD_M(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
|
||||||
|
#define SET_FIELD_M(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD_M(fieldname, value))
|
||||||
|
|
||||||
/* Use this macro to store constant values in IROM flash instead
|
/* Use this macro to store constant values in IROM flash instead
|
||||||
of having them loaded into rodata (which resides in DRAM)
|
of having them loaded into rodata (which resides in DRAM)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue