Hardware Abstraction Layer for FreeRTOS
Collaboration diagram for Useful Macros:

Macros

#define WEAK   __attribute__ ((weak))
 
#define ALIAS(x)   __attribute__ ((alias(#x)))
 
#define INTERRUPT(x)   __attribute__ ((interrut(x)))
 
#define SECTION(x)   __attribute__ ((section(x)))
 
#define NAKED   __attribute__ ((naked))
 
#define USED   __attribute__ ((used))
 
#define PACKED   __attribute__ ((__packed__))
 
#define NO_REORDER
 
#define ALIGN(x)   __attribute__((aligned(x)))
 
#define NSEC_PER_SEC   1000000000ULL
 
#define BIT(x)   ((uint32_t) (1UL << (x)))
 
#define BITS(x, mask, shift)   ((uint32_t) ((((uint32_t) (x))<<(shift)) & (mask)))
 
#define BITS_INV(x, mask, shift)   ((uint32_t) ((((uint32_t) (x)) & (mask))>>(shift)))
 
#define BITS_MASK(bits, shift)   ((uint32_t) ((~(0xFFFFFFFFUL << (bits))) << (shift)))
 
#define BIT64(x)   ((uint64_t) (1ULL << (x)))
 
#define BITS64(x, mask, shift)   ((uint64_t) ((((uint64_t) (x))<<(shift)) & (mask)))
 
#define BITS64_INV(x, mask, shift)   ((uint64_t) ((((uint64_t) (x)) & (mask))>>(shift)))
 
#define BITS64_MASK(bits, shift)   ((uint64_t) ((~(0xFFFFFFFFFFFFFFFFULL << (bits))) << (shift)))
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 
#define DIV_ROUND_UP(n, d)   (((n) + (d) - 1) / (d))
 
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
 
#define swap32(d)
 
#define swap16(d)
 
#define cpu_to_be32(d)   swap32(d)
 
#define be32_to_cpu(d)   swap32(d)
 
#define cpu_to_be16(d)   swap16(d)
 
#define be16_to_cpu(d)   swap16(d)
 
#define cpu_to_le32(d)   d
 
#define le32_to_cpu(d)   d
 
#define cpu_to_le16(d)   d
 
#define le16_to_cpu(d)   d
 

Detailed Description

#include <system.h>

Useful Macros docu mostly copy from GCC Webpage

Macro Definition Documentation

◆ ALIAS

#define ALIAS (   x)    __attribute__ ((alias(#x)))

The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,

void __f () { / * do something * /; }
void f () WEAK ALIAS("__f");

declares f to be a weak alias for __f. In C++, the mangled name for the target must be used. Not all target machines support this attribute.

◆ ALIGN

#define ALIGN (   x)    __attribute__((aligned(x)))

This attribute specifies a minimum alignment for the variable or structure field, measured in bytes.

◆ ARRAY_SIZE

#define ARRAY_SIZE (   x)    (sizeof(x) / sizeof((x)[0]))

Get Array Size

Warning
Waring only posibile with const arrays!
Parameters
xconst Variable
Returns
return Size

◆ be16_to_cpu

#define be16_to_cpu (   d)    swap16(d)

Big Endian to CPU in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ be32_to_cpu

#define be32_to_cpu (   d)    swap32(d)

Big Endian to CPU in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ BIT

#define BIT (   x)    ((uint32_t) (1UL << (x)))

Set a Bit on Value

Parameters
xbit position to set

◆ BIT64

#define BIT64 (   x)    ((uint64_t) (1ULL << (x)))

Set a Bit on 64Bit Value

Parameters
xbit position to set

◆ BITS

#define BITS (   x,
  mask,
  shift 
)    ((uint32_t) ((((uint32_t) (x))<<(shift)) & (mask)))

Set bits (32 bit), shift them and apply a mask

Parameters
xbits to set
maskmask applied after shifting
shiftnumber of bits x gets shifted

◆ BITS64

#define BITS64 (   x,
  mask,
  shift 
)    ((uint64_t) ((((uint64_t) (x))<<(shift)) & (mask)))

Set bits (64 bit), shift them and apply a mask

Parameters
xbits to set
maskmask applied after shifting
shiftnumber of bits x gets shifted

◆ BITS64_INV

#define BITS64_INV (   x,
  mask,
  shift 
)    ((uint64_t) ((((uint64_t) (x)) & (mask))>>(shift)))

Extract bits (64 bit) by applying a mask and a shift

Parameters
x32-bit input value to extract the bits from
maskmask applied to the input value
shiftnumberof bits masked x gets shifted

◆ BITS64_MASK

#define BITS64_MASK (   bits,
  shift 
)    ((uint64_t) ((~(0xFFFFFFFFFFFFFFFFULL << (bits))) << (shift)))

Generate a mask (64 bit) given the number of bits and the shift

Parameters
bitsnumber of bits set to 1
shiftnumber of bits the block of ones gets shifted

◆ BITS_INV

#define BITS_INV (   x,
  mask,
  shift 
)    ((uint32_t) ((((uint32_t) (x)) & (mask))>>(shift)))

Extract bits (32 bit) by applying a mask and a shift

Parameters
x32-bit input value to extract the bits from
maskmask applied to the input value
shiftnumberof bits masked x gets shifted

◆ BITS_MASK

#define BITS_MASK (   bits,
  shift 
)    ((uint32_t) ((~(0xFFFFFFFFUL << (bits))) << (shift)))

Generate a mask (32 bit) given the number of bits and the shift

Parameters
bitsnumber of bits set to 1
shiftnumber of bits the block of ones gets shifted

◆ cpu_to_be16

#define cpu_to_be16 (   d)    swap16(d)

CPU to Big Endian in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ cpu_to_be32

#define cpu_to_be32 (   d)    swap32(d)

CPU to Big Endian in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ cpu_to_le16

#define cpu_to_le16 (   d)    d

Little Endian to CPU in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ cpu_to_le32

#define cpu_to_le32 (   d)    d

CPU to Big Endian in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ DIV_ROUND_UP

#define DIV_ROUND_UP (   n,
 
)    (((n) + (d) - 1) / (d))

Div Integer and round up

Parameters
nDividend
dDivisor

◆ INTERRUPT

#define INTERRUPT (   x)    __attribute__ ((interrut(x)))

Use this attribute on the ARM, AVR, M32R/D and Xstormy16 ports to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. Note, interrupt handlers for the H8/300, H8/300H and SH processors can be specified via the interrupt_handler attribute.

Note, on the AVR interrupts will be enabled inside the function.

Note, for the ARM you can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:

void f () INTERRUPT("IRQ");

Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.

◆ le16_to_cpu

#define le16_to_cpu (   d)    d

Little Endian to CPU in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ le32_to_cpu

#define le32_to_cpu (   d)    d

Liddel Endian to CPU in 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ MAX

#define MAX (   a,
 
)    (((a) > (b)) ? (a) : (b))

Maximum of two values

Parameters
afirst Parameter
bsecond Parameter
Returns
a or b

◆ MIN

#define MIN (   a,
 
)    (((a) < (b)) ? (a) : (b))

Minimum of two values

Parameters
afirst Parameter
bsecond Parameter
Returns
a or b

◆ NAKED

#define NAKED   __attribute__ ((naked))

Use this attribute on the ARM or AVR ports to indicate that the specified function do not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences.

◆ NO_REORDER

#define NO_REORDER

Do not reorder functions or variables marked no_reorder against each other or top level assembler statements the executable. The actual order in the program will depend on the linker command line. Static variables marked like this are also not removed. This has a similar effect as the -fno-toplevel-reorder option, but only applies to the marked symbols.

Needed for Globale Device Instance Table

Warning
in < GCC 5.0 not available -fno-toplevel-reorder automated activated in Makefile

◆ NSEC_PER_SEC

#define NSEC_PER_SEC   1000000000ULL

Nanosecond per Second

◆ PACKED

#define PACKED   __attribute__ ((__packed__))

This attribute, attached to struct or union type definition, specifies that each member (other than zero-width bit-fields) of the structure or union is placed to minimize the memory required. When attached to an enum definition, it indicates that the smallest integral type should be used.

Specifying the packed attribute for struct and union types is equivalent to specifying the packed attribute on each of the structure or union members. Specifying the -fshort-enums flag on the command line is equivalent to specifying the packed attribute on all enum definitions.

In the following example struct my_packed_struct's members are packed closely together, but the internal layout of its s member is not packed—to do that, struct my_unpacked_struct needs to be packed too.

struct my_unpacked_struct {
char c;
int i;
};
struct PACKED my_packed_struct {
char c;
int i;
struct my_unpacked_struct s;
};

You may only specify the packed attribute attribute on the definition of an enum, struct or union, not on a typedef that does not also define the enumerated type, structure or union.

◆ SECTION

#define SECTION (   x)    __attribute__ ((section(x)))

Normally, the compiler places the code it generates in the text section. Sometimes, however, you need additional sections, or you need certain particular functions to appear in special sections. The section attribute specifies that a function lives in a particular section. For example, the declaration:

extern void foobar (void) SECTION("bar");

puts the function foobar in the bar section.

Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.

◆ swap16

#define swap16 (   d)
Value:
({ \
union {uint16_t ret; uint8_t ret8[2];} tmp;\
tmp.ret = (d); \
/* use XOR Swap */ \
tmp.ret8[0] ^= tmp.ret8[1]; \
tmp.ret8[1] ^= tmp.ret8[0]; \
tmp.ret8[0] ^= tmp.ret8[1]; \
tmp.ret; \
})

Swap 16 Bit

Parameters
d16 Bit data
Returns
swaped 16 Bit data

◆ swap32

#define swap32 (   d)
Value:
({ \
union {uint32_t ret; uint8_t ret8[4];} tmp;\
tmp.ret = (d); \
/* swap 0 -> 3 and 1 -> 2 -> 0123 -> 3210 */ \
/* use XOR Swap */ \
tmp.ret8[0] ^= tmp.ret8[3]; \
tmp.ret8[3] ^= tmp.ret8[0]; \
tmp.ret8[0] ^= tmp.ret8[3]; \
tmp.ret8[1] ^= tmp.ret8[2]; \
tmp.ret8[2] ^= tmp.ret8[1]; \
tmp.ret8[1] ^= tmp.ret8[2]; \
tmp.ret; \
})

Swap 32 Bit

Parameters
d32 Bit data
Returns
swaped 32 Bit data

◆ USED

#define USED   __attribute__ ((used))

This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly.

◆ WEAK

#define WEAK   __attribute__ ((weak))

The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.

PACKED
#define PACKED
Definition: system.h:89
ALIAS
#define ALIAS(x)
Definition: system.h:37
system.h
INTERRUPT
#define INTERRUPT(x)
Definition: system.h:50
WEAK
#define WEAK
Definition: system.h:27
SECTION
#define SECTION(x)
Definition: system.h:60