打印
[其他]

RT-Thread函数指针块自动初始化简介

[复制链接]
60|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jcky001|  楼主 | 2024-12-27 14:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
环境:rt-thread 4.0.3 rt-thread studio 2.2.1 ART-Pi

定义 函数指针块

主要用于map文件标记
components.c 中

static int rti_start(void)

return 0;

}

INIT_EXPORT(rti_start, "0");

static int rti_board_start(void)

{

return 0;

}

INIT_EXPORT(rti_board_start, "0.end");

static int rti_board_end(void)

return 0;

}

INIT_EXPORT(rti_board_end, "1.end");

static int rti_end(void)

{

return 0;

}

INIT_EXPORT(rti_end, "6.end");

执行

void rt_components_board_init(void) 执行第0等级

void rt_components_init(void) 执行其余等级 rtthread.map

*(SORT(.rti_fn*))

.rti_fn.0 0x9002a5fc 0x4 ./rt-thread/src/components.o

0x9002a5fc __rt_init_rti_start

.rti_fn.0.end 0x9002a600 0x4 ./rt-thread/src/components.o

0x9002a600 __rt_init_rti_board_start

.rti_fn.1 0x9002a604 0x4 ./libraries/drivers/drv_adc.o

0x9002a604 __rt_init_STM32_adc_init

.rti_fn.1 0x9002a608 0x4 ./board/board.o

0x9002a608 __rt_init_clock_information

.rti_fn.1 0x9002a60c 0x4 ./board/drv_mpu.o

0x9002a60c __rt_init_mpu_init

.rti_fn.1 0x9002a610 0x4 ./applications/main.o

0x9002a610 __rt_init_vtor_config

.rti_fn.1.end 0x9002a614 0x4 ./rt-thread/src/components.o

0x9002a614 __rt_init_rti_board_end

.rti_fn.2 0x9002a618 0x4 ./rt-thread/components/utilities/ulog/backend/console_be.o

0x9002a618 __rt_init_ulog_console_backend_init

.rti_fn.2 0x9002a61c 0x4 ./rt-thread/components/utilities/ulog/ulog.o

0x9002a61c __rt_init_ulog_init

.rti_fn.2 0x9002a620 0x4 ./rt-thread/components/dfs/src/dfs.o

0x9002a620 __rt_init_dfs_init

.rti_fn.4 0x9002a624 0x4 ./rt-thread/components/utilities/utest/utest.o

0x9002a624 __rt_init_utest_init

.rti_fn.4 0x9002a628 0x4 ./rt-thread/components/libc/compilers/newlib/libc.o

0x9002a628 __rt_init_libc_system_init

.rti_fn.5 0x9002a62c 0x4 ./applications/uart_sample.o

0x9002a62c __rt_init_uart_dma_sample

.rti_fn.6 0x9002a630 0x4 ./rt-thread/components/finsh/shell.o

0x9002a630 __rt_init_finsh_system_init

.rti_fn.6.end 0x9002a634 0x4 ./rt-thread/src/components.o

0x9002a634 __rt_init_rti_end

0x9002a638 __rt_init_end = .

0x9002a638 . = ALIGN (0x4)

[!provide] PROVIDE (__ctors_start__, .)

怎样插入函数指针

rtdef.h 中 宏定义

/* board init routines will be called in board_init() function */

#define INIT_BOARD_EXPORT(fn) INIT_EXPORT(fn, "1")

/* pre/device/component/env/app init routines will be called in init_thread */

/* components pre-initialization (pure software initilization) */

#define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn, "2")

/* device initialization */

#define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn, "3")

/* components initialization (dfs, lwip, ...) */

#define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn, "4")

/* environment initialization (mount disk, ...) */

#define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn, "5")

/* appliation initialization (rtgui application etc ...) */

#define INIT_APP_EXPORT(fn) INIT_EXPORT(fn, "6")

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

#define RT_UNUSED __attribute__((unused))

#define RT_USED __attribute__((used))

#define ALIGN(n) __attribute__((aligned(n)))

#define RT_WEAK __attribute__((weak))

#define rt_inline static __inline

typedef int (*init_fn_t)(void);

RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn." level) = fn

编译保留 RT_USED

函数指针 init_fn_t

函数名—宏连接 __rt_init_##fn

编译位置 SECTION(".rti_fn." level)

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1526

主题

4638

帖子

6

粉丝