[<<][c][>>][..]
Sun Feb 8 15:21:28 EST 2015

union tagging

/* Note that "static inline" doesn't necessarily inline.  Adding this
   attribute will force GCC to inline the function even if
   optimization is off. */
#define INLINE static inline __attribute__((__always_inline__))

/* Union tagging.  libopencm3 uses untyped uint32_t for almost all
 * peripherals.  This is error prone in the abstractions uses below,
 * so the code here wraps identifiers in a union.  The wrapper is
 * optimized away leaving no run-time overhead. */
#define HW_WRAP_UNION(name, type)         \
    union name { type id; };              \
    INLINE union name name(type id) {     \
        union name u = {.id = id};        \
        return u;                         \
    }
//            wrapper | original libopencm3 type
// -------------------+------------------------
HW_WRAP_UNION(hw_rcc,   enum rcc_periph_clken)
HW_WRAP_UNION(hw_tim,   uint32_t)
HW_WRAP_UNION(hw_gpio,  uint32_t)




[Reply][About]
[<<][c][>>][..]