分散加载系列2--动态注册【我们BLE-制卡器是静态注册】

RT-Thead SHELL 命令段定义实现方法

https://blog.csdn.net/qq_21000937/article/details/69374714

上面文章 看上去和我研究的类似

继续RTT回答了分散加载,当时上传的CSDN的范例其实还有一个WARN 因为我--keep了2个 其实只用了一个

这个文章回答另外一个的使用!

(目前不是很懂它的用法 感觉像定义变量的2中情况 1个是给const这样死死 的就像1个是给static __attribuate__这样随时更换数据的)

如何用?

main。c前面写

void finsh_system_function_init(const void *begin, const void *end);
extern const int FSymTab$$Base;
extern const int FSymTab$$Limit;//不知道哪里来的 貌似定义FINSH_FUNCTION_EXPORT_CMD来的
const struct finsh_syscall *P;//测试用的



/
//1准备
#define rt_kprintf printf
#define FINSH_NEXT_SYSCALL(index)  index++
#define SECTION(x)                  __attribute__((section(x)))
//2定义函数指针
typedef long (*syscall_func)(void);
//3做一个结构体
struct finsh_syscall
{
    const char*     name;       /* the name of system call */
    const char*     desc;       /* description of system call */
    syscall_func func;         /* the function address of system call */
};
//4定义
struct finsh_syscall *_syscall_table_begin  = NULL;
struct finsh_syscall *_syscall_table_end    = NULL;
//5接口
void finsh_system_function_init(const void *begin, const void *end)
{
    _syscall_table_begin = (struct finsh_syscall *) begin;
    _syscall_table_end = (struct finsh_syscall *) end;
}	
//6调用 在函数中 参数哪儿来的?KEIL
// finsh_system_function_init(__section_begin("FSymTab"), __section_end("FSymTab"));

//7定义操作宏
#define FINSH_FUNCTION_EXPORT_CMD(name, cmd, desc)      \
        const char __fsym_##cmd##_name[] SECTION(".rodata.name") = #cmd;   \
        const char __fsym_##cmd##_desc[] SECTION(".rodata.name") = #desc;  \
        const struct finsh_syscall __fsym_##cmd SECTION("FSymTab")= \
        {                           \
                __fsym_##cmd##_name,    \
                __fsym_##cmd##_desc,    \
                (syscall_func)&name     \
        };

//8定义操作宏
#define FINSH_FUNCTION_EXPORT(name, desc)   \
    FINSH_FUNCTION_EXPORT_CMD(name, name, desc)

//使用举例				
static void enc28j60(void)
{
	printf("%s",__FUNCTION__);
}
//直接用宏
FINSH_FUNCTION_EXPORT(enc28j60, dump enc28j60 registers);  

main中间调一下

finsh_system_function_init(&FSymTab$$Base, &FSymTab$$Limit);
P = &__fsym_enc28j60;
P->func();

可以看到函数调用成功!

动态注册!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值