Hardware Abstraction Layer for FreeRTOS
|
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 |
Useful Macros docu mostly copy from GCC Webpage
#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,
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.
#define ALIGN | ( | x | ) | __attribute__((aligned(x))) |
This attribute specifies a minimum alignment for the variable or structure field, measured in bytes.
#define ARRAY_SIZE | ( | x | ) | (sizeof(x) / sizeof((x)[0])) |
Get Array Size
x | const Variable |
#define be16_to_cpu | ( | d | ) | swap16(d) |
Big Endian to CPU in 32 Bit
d | 32 Bit data |
#define be32_to_cpu | ( | d | ) | swap32(d) |
Big Endian to CPU in 32 Bit
d | 32 Bit data |
#define BIT | ( | x | ) | ((uint32_t) (1UL << (x))) |
Set a Bit on Value
x | bit position to set |
#define BIT64 | ( | x | ) | ((uint64_t) (1ULL << (x))) |
Set a Bit on 64Bit Value
x | bit position to set |
#define BITS | ( | x, | |
mask, | |||
shift | |||
) | ((uint32_t) ((((uint32_t) (x))<<(shift)) & (mask))) |
Set bits (32 bit), shift them and apply a mask
x | bits to set |
mask | mask applied after shifting |
shift | number of bits x gets shifted |
#define BITS64 | ( | x, | |
mask, | |||
shift | |||
) | ((uint64_t) ((((uint64_t) (x))<<(shift)) & (mask))) |
Set bits (64 bit), shift them and apply a mask
x | bits to set |
mask | mask applied after shifting |
shift | number of bits x gets shifted |
#define BITS64_INV | ( | x, | |
mask, | |||
shift | |||
) | ((uint64_t) ((((uint64_t) (x)) & (mask))>>(shift))) |
Extract bits (64 bit) by applying a mask and a shift
x | 32-bit input value to extract the bits from |
mask | mask applied to the input value |
shift | numberof bits masked x gets shifted |
#define BITS64_MASK | ( | bits, | |
shift | |||
) | ((uint64_t) ((~(0xFFFFFFFFFFFFFFFFULL << (bits))) << (shift))) |
Generate a mask (64 bit) given the number of bits and the shift
bits | number of bits set to 1 |
shift | number of bits the block of ones gets shifted |
#define BITS_INV | ( | x, | |
mask, | |||
shift | |||
) | ((uint32_t) ((((uint32_t) (x)) & (mask))>>(shift))) |
Extract bits (32 bit) by applying a mask and a shift
x | 32-bit input value to extract the bits from |
mask | mask applied to the input value |
shift | numberof bits masked x gets shifted |
#define BITS_MASK | ( | bits, | |
shift | |||
) | ((uint32_t) ((~(0xFFFFFFFFUL << (bits))) << (shift))) |
Generate a mask (32 bit) given the number of bits and the shift
bits | number of bits set to 1 |
shift | number of bits the block of ones gets shifted |
#define cpu_to_be16 | ( | d | ) | swap16(d) |
CPU to Big Endian in 32 Bit
d | 32 Bit data |
#define cpu_to_be32 | ( | d | ) | swap32(d) |
CPU to Big Endian in 32 Bit
d | 32 Bit data |
#define cpu_to_le16 | ( | d | ) | d |
Little Endian to CPU in 32 Bit
d | 32 Bit data |
#define cpu_to_le32 | ( | d | ) | d |
CPU to Big Endian in 32 Bit
d | 32 Bit data |
#define DIV_ROUND_UP | ( | n, | |
d | |||
) | (((n) + (d) - 1) / (d)) |
Div Integer and round up
n | Dividend |
d | Divisor |
#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:
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.
#define le16_to_cpu | ( | d | ) | d |
Little Endian to CPU in 32 Bit
d | 32 Bit data |
#define le32_to_cpu | ( | d | ) | d |
Liddel Endian to CPU in 32 Bit
d | 32 Bit data |
#define MAX | ( | a, | |
b | |||
) | (((a) > (b)) ? (a) : (b)) |
Maximum of two values
a | first Parameter |
b | second Parameter |
#define MIN | ( | a, | |
b | |||
) | (((a) < (b)) ? (a) : (b)) |
Minimum of two values
a | first Parameter |
b | second Parameter |
#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.
#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
#define NSEC_PER_SEC 1000000000ULL |
Nanosecond per Second
#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.
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.
#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:
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.
#define swap16 | ( | d | ) |
Swap 16 Bit
d | 16 Bit data |
#define swap32 | ( | d | ) |
Swap 32 Bit
d | 32 Bit data |
#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.
#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.