Q群:
电话:
邮箱:
地址:
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#define __CLANG_ARM
#endif
/* Compiler related definitions */
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* For ARM compiler */
#define OS_SECTION(x) __attribute__((section(x)))
#define OS_ALIGN(n) __attribute__((aligned(n)))
#define OS_UNUSED __attribute__((unused))
#define OS_USED __attribute__((used))
#define OS_WEAK __attribute__((weak))
#define OS_INLINE static __inline
#elif defined (__IAR_SYSTEMS_ICC__) /* For IAR compiler */
#define OS_SECTION(x) @ x
#define OS_PRAGMA(x) _Pragma(#x)
#define OS_ALIGN(n) OS_PRAGMA(data_alignment=n)
#define OS_UNUSED
#define OS_USED __root
#define OS_WEAK __weak
#define OS_INLINE static inline
#elif defined (__GNUC__) /* For GNU GCC compiler */
#define OS_SECTION(x) __attribute__((section(x)))
#define OS_ALIGN(n) __attribute__((aligned(n)))
#define OS_UNUSED __attribute__((unused))
#define OS_USED __attribute__((used))
#define OS_WEAK __attribute__((weak))
#define OS_INLINE static __inline
#elif defined (__ADSPBLACKFIN__) /* For VisualDSP++ compiler */
#define OS_SECTION(x) __attribute__((section(x)))
#define OS_ALIGN(n) __attribute__((aligned(n)))
#define OS_UNUSED __attribute__((unused))
#define OS_USED __attribute__((used))
#define OS_WEAK __attribute__((weak))
#define OS_INLINE static inline
#else
#error Not supported tool chain
#endif
定义 | 说明 |
---|---|
OS_SECTION(x) | 段定义,将变量或函数放到指定的段中 |
OS_ALIGN(n) | 字节对齐,作用是在给某对象分配地址空间时,指定n字节对齐,n一般为2的幂次方 |
OS_UNUSED | 表示函数或者变量可能不使用,避免编译器产生告警 |
OS_USED | 告诉编译器静态函数即使没有被调用也要链接 |
OS_WEAK | 编译器链接时优先链接没有该关键字的函数,如果找不到才链接由该关键字修饰的函数 |
OS_INLINE | 内联函数 |
该功能用于在系统初始化过程中,自动执行被OS_INIT_EXPORT修饰的函数,其中的数字越小,优先级越高,越先被执行。定义如下:
/* Auto initialization function type */
typedef os_err_t (*os_init_fn_t)(void);
#define OS_INIT_EXPORT(fn, level) \
OS_USED const os_init_fn_t __os_call_##fn OS_SECTION(".init_call."level) = fn
#define OS_BOARD_INIT(fn) OS_INIT_EXPORT(fn, "1") /* board init */
#define OS_PREV_INIT(fn) OS_INIT_EXPORT(fn, "2") /* pre-initialization except board(pure software initilization) */
#define OS_DEVICE_INIT(fn) OS_INIT_EXPORT(fn, "3") /* device initialization */
#define OS_CMPOENT_INIT(fn) OS_INIT_EXPORT(fn, "4") /* components initialization (dfs, lwip, ...) */
#define OS_ENV_INIT(fn) OS_INIT_EXPORT(fn, "5") /* environment initialization (mount disk, ...) */
#define OS_APP_INIT(fn) OS_INIT_EXPORT(fn, "6") /* appliation initialization */
定义 | 说明 |
---|---|
OS_BOARD_INIT(fn) | 板级自动初始化,优先级最高 |
OS_PREV_INIT(fn) | 前置自动初始化,主要用于纯软件且没有太多依赖的初始化 |
OS_DEVICE_INIT(fn) | 设备驱动级自动初始化 |
OS_CMPOENT_INIT(fn) | 组件级自动初始化 |
OS_ENV_INIT(fn) | 环境级自动初始化 |
OS_APP_INIT(fn) | 应用程序级自动初始化 |
#ifdef __cplusplus
#define OS_NULL 0
#else
#define OS_NULL ((void *)0)
#endif
#define OS_FALSE 0
#define OS_TRUE 1
#define OS_ALIGN_UP(size, align) (((size) + (align) - 1) & ~((align) - 1))
#define OS_ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
#define OS_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define os_container_of(ptr, type, member) \
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
#define os_offsetof(type, member) ((os_size_t) &((type *)0)->member)
定义 | 说明 |
---|---|
OS_ALIGN_UP(size, align) | 数字大小向上对齐,如OS_ALIGN_UP(5,4),返回8 |
OS_ALIGN_DOWN(size, align) | 数字大小向下对齐,如OS_ALIGN_DOWN(5,4),返回4 |
OS_ARRAY_SIZE | 求数组尺寸 |
os_container_of(ptr, type, member) | 已知结构体type的成员member的地址ptr,求结构体type的起始地址 |
os_offsetof(type, member) | 求成员member在结构体type内的偏移 |