Skip to content

Instantly share code, notes, and snippets.

@patocarr
Created March 23, 2019 05:00
Show Gist options
  • Save patocarr/fbefbc74b5f724e89a50caf469fa93c4 to your computer and use it in GitHub Desktop.
Save patocarr/fbefbc74b5f724e89a50caf469fa93c4 to your computer and use it in GitHub Desktop.
C Macros for field addressing
#define MACB_RMII_OFFSET 0
#define MACB_RMII_SIZE 1
#define GEM_RGMII_OFFSET 0 /* GEM gigabit mode */
#define GEM_RGMII_SIZE 1
#define MACB_CLKEN_OFFSET 1
#define MACB_CLKEN_SIZE 1
<...>
/* Bit manipulation macros */
#define MACB_BIT(name) \
(1 << MACB_##name##_OFFSET)
#define MACB_BF(name,value) \
(((value) & ((1 << MACB_##name##_SIZE) - 1)) \
<< MACB_##name##_OFFSET)
#define MACB_BFEXT(name,value)\
(((value) >> MACB_##name##_OFFSET) \
& ((1 << MACB_##name##_SIZE) - 1))
#define MACB_BFINS(name,value,old) \
(((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
<< MACB_##name##_OFFSET)) \
| MACB_BF(name,value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment