Zephyr Project API  3.3.0
A Scalable Open Source RTOS
common.h File Reference

Common toolchain abstraction. More...

Go to the source code of this file.

Macros

#define EXTERN_C   extern
 
#define ZRESTRICT   restrict
 
#define REQUIRES(sym)   __asm__ (".set " # sym "_Requires, " # sym "\n\t");
 
#define ALWAYS_INLINE   inline __attribute__((always_inline))
 
#define STRINGIFY(s)   Z_STRINGIFY(s)
 
#define IS_PTR_ALIGNED_BYTES(ptr, bytes)   ((((uintptr_t)ptr) % bytes) == 0)
 
#define IS_PTR_ALIGNED(ptr, type)   IS_PTR_ALIGNED_BYTES(ptr, __alignof(type))
 
#define STRUCT_SECTION_ITERABLE(struct_type, name)
 Defines a new element for an iterable section. More...
 
#define STRUCT_SECTION_ITERABLE_ALTERNATE(out_type, struct_type, name)
 Defines a new element of alternate data type for an iterable section. More...
 
#define STRUCT_SECTION_FOREACH(struct_type, iterator)
 Iterate over a specified iterable section. More...
 
#define STRUCT_SECTION_GET(struct_type, i, dst)
 Get element from section. More...
 
#define STRUCT_SECTION_COUNT(struct_type, dst)
 Count elements in a section. More...
 
#define LINKER_KEEP(symbol)
 Tag a symbol (e.g. function) to be kept in the binary even though it is not used. More...
 
#define LOG2CEIL(x)
 

Detailed Description

Common toolchain abstraction.

Macros to abstract compiler capabilities (common to all toolchains).

Macro Definition Documentation

◆ ALWAYS_INLINE

#define ALWAYS_INLINE   inline __attribute__((always_inline))

◆ EXTERN_C

#define EXTERN_C   extern

◆ IS_PTR_ALIGNED

#define IS_PTR_ALIGNED (   ptr,
  type 
)    IS_PTR_ALIGNED_BYTES(ptr, __alignof(type))

◆ IS_PTR_ALIGNED_BYTES

#define IS_PTR_ALIGNED_BYTES (   ptr,
  bytes 
)    ((((uintptr_t)ptr) % bytes) == 0)

◆ LINKER_KEEP

#define LINKER_KEEP (   symbol)
Value:
static const void * const symbol##_ptr __used \
__attribute__((__section__(".symbol_to_keep"))) = (void *)&symbol

Tag a symbol (e.g. function) to be kept in the binary even though it is not used.

It prevents symbol from being removed by the linker garbage collector. It is achieved by adding a pointer to that symbol to the kept memory section.

Parameters
symbolSymbol to keep.

◆ LOG2CEIL

#define LOG2CEIL (   x)
Value:
((((x) <= 4) ? 2 : (((x) <= 8) ? 3 : (((x) <= 16) ? \
4 : (((x) <= 32) ? 5 : (((x) <= 64) ? 6 : (((x) <= 128) ? \
7 : (((x) <= 256) ? 8 : (((x) <= 512) ? 9 : (((x) <= 1024) ? \
10 : (((x) <= 2048) ? 11 : (((x) <= 4096) ? 12 : (((x) <= 8192) ? \
13 : (((x) <= 16384) ? 14 : (((x) <= 32768) ? 15:(((x) <= 65536) ? \
16 : (((x) <= 131072) ? 17 : (((x) <= 262144) ? 18:(((x) <= 524288) ? \
19 : (((x) <= 1048576) ? 20 : (((x) <= 2097152) ? \
21 : (((x) <= 4194304) ? 22 : (((x) <= 8388608) ? \
23 : (((x) <= 16777216) ? 24 : (((x) <= 33554432) ? \
25 : (((x) <= 67108864) ? 26 : (((x) <= 134217728) ? \
27 : (((x) <= 268435456) ? 28 : (((x) <= 536870912) ? \
29 : (((x) <= 1073741824) ? 30 : (((x) <= 2147483648) ? \
31 : 32)))))))))))))))))))))))))))))))

◆ REQUIRES

#define REQUIRES (   sym)    __asm__ (".set " # sym "_Requires, " # sym "\n\t");

◆ STRINGIFY

#define STRINGIFY (   s)    Z_STRINGIFY(s)

◆ ZRESTRICT

#define ZRESTRICT   restrict