我参考https://docs.espressif.com/projects/esp ... ation.html和https://docs.espressif.com/projects/esp ... artup.html中的esp_system_init_fn用法,自己添加了link文件:
Code: Select all
[sections:plugins_desc]
entries:
.init_fn+
[scheme:plugins_desc_default]
entries:
plugins_desc -> flash_rodata
[mapping:plugins_desc]
archive: *
entries:
* (plugins_desc_default);
plugins_desc -> flash_rodata KEEP() SORT(name) SURROUND(init)
Code: Select all
// @brief 定义各个模块
typedef struct init_desc {
char name[CONFIG_MODULE_NAME_LEN];
int priority; // 任务优先级:0为最低
int core; // 运行在哪个核, 0, 1, tskNO_AFFINITY:不指定
int stack_size; // 堆栈大小,单位字节
int (*init)(struct init_desc *self);
void (*thread)(struct init_desc *self);
void* priv_data; // 一些参数
} init_desc_t;
/** @brief 通过该宏实现定义一个初始化描述变量,初始化系统会根据设置的参数进行按顺序初始化和启动
* @param nm 模块名称
* @param priv 本模块私有的一些数据的指针
* @param level 模块级别,字符串,字符串排序越小越先初始化和执行
* @param init_func 初始化函数,类型为:int (*)(init_desc_t *self)
* @param run_core 运行在哪个核, tskNO_AFFINITY:不指定
* @param run_stack_size 堆栈大小,单位字节
* @param thread_priority 线程优先级 tskIDLE_PRIORITY 到 configMAX_PRIORITIES-1
* @param thread_func
*/
#define INIT_FN_EXPORT(nm, priv, level, init_func, run_core, run_stack_size, thread_priority, thread_func) \
static __attribute__((section(".init_fn" level),used)) \
init_desc_t init_fn_##nm = { \
.name = #nm, \
.priority = (thread_priority), \
.core = (run_core), \
.stack_size = (run_stack_size), \
.init = (init_func), \
.thread = (thread_func), \
.priv_data = (priv), \
};
Code: Select all
0x3c040120 _init_start = ABSOLUTE (.)
*(SORT_BY_NAME(.init_fn) SORT_BY_NAME(.init_fn.*))
0x3c040120 _init_end = ABSOLUTE (.)
Code: Select all
0x3c04f9c0 _esp_system_init_fn_array_start = ABSOLUTE (.)
*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*))
.esp_system_init_fn.100
0x3c04f9c0 0x8 esp-idf/esp_timer/libesp_timer.a(esp_timer.c.obj)
.esp_system_init_fn.105
0x3c04f9c8 0x8 esp-idf/esp_hw_support/libesp_hw_support.a(sleep_gpio.c.obj)
.esp_system_init_fn.200
0x3c04f9d0 0x8 esp-idf/esp_system/libesp_system.a(startup.c.obj)
0x3c04f9d8 _esp_system_init_fn_array_end = ABSOLUTE (.)
Code: Select all
Linux MAGIC14-WSL 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 GNU/Linux
Debian GNU/Linux 12