设为首页 加入收藏

TOP

源码解读·RT-Thread操作系统从开机到关机(四)
2019-08-27 07:20:57 】 浏览:101
Tags:源码 解读 RT-Thread 操作系统 开机 关机
/
#define INIT_EXPORT(fn,level) #else #if RT_DEBUG_INIT struct rt_init_desc { const char* fn_name; const init_fn_t fn; }; #define INIT_EXPORT(fn, level) \ const char __rti_##fn##_name[] =#fn; \ RT_USED const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level)=\ { __rti_##fn##_name, fn}; #else #define INIT_EXPORT(fn, level) \ RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn."level)= fn #endif #endif #else #define INIT_EXPORT(fn, level) #endif /* board initroutines 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 */ /* componentspre-initialization (pure software initilization) */ #define INIT_PREV_EXPORT(fn) INIT_EXPORT(fn,"2") /* deviceinitialization */ #define INIT_DEVICE_EXPORT(fn) INIT_EXPORT(fn,"3") /* componentsinitialization (dfs, lwip, ...) */ #define INIT_COMPONENT_EXPORT(fn) INIT_EXPORT(fn,"4") /* environmentinitialization (mount disk, ...) */ #define INIT_ENV_EXPORT(fn) INIT_EXPORT(fn,"5") /* appliationinitialization (rtgui application etc ...) */ #define INIT_APP_EXPORT(fn) INIT_EXPORT(fn,"6")
其中不同的数字代表不同的初始化顺序,可以根据需要来选择。接着如上文提到的两个函数rt_components_board_init和rt_components_init是如何实现的:摘录自components.c
#ifdef RT_USING_COMPONENTS_INIT
/*
 * Components Initialization will initializesome driver and components as following
 * order:
 * rti_start         --> 0
 * BOARD_EXPORT      --> 1
 * rti_board_end     --> 1.end
 *
 * DEVICE_EXPORT     --> 2
 * COMPONENT_EXPORT  --> 3
 * FS_EXPORT         --> 4
 * ENV_EXPORT        --> 5
 * APP_EXPORT        --> 6
 *
 * rti_end           --> 6.end
 *
 * These automatically initialization, thedriver or component initial function must
 * be defined with:
 * INIT_BOARD_EXPORT(fn);
 * INIT_DEVICE_EXPORT(fn);
 * ...
 * INIT_APP_EXPORT(fn);
 * etc.
 */
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");
 
/**
 * RT-Thread Components Initialization forboard
 */
void rt_components_board_init(void)
{
#if RT_DEBUG_INIT
    int result;
    const struct rt_init_desc *desc;
    for (desc = &__rt_init_desc_rti_board_start; desc < &__rt_init_desc_rti_board_end; desc ++)
    {
        rt_kprintf("initialize %s", desc->fn_name);
        result = desc->fn();
        rt_kprintf(":%d done\n", result);
    }
#else
    const init_fn_t *fn_ptr;
 
    for (fn_ptr = &__rt_init_rti_board_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++)
    {
        (*fn_ptr)();
    }
#endif
}
 
/**
 * RT-Thread Components Initialization
 */
void rt_components_init(void)
{
#if RT_DEBUG_INIT
    int result;
    const struct rt_init_desc *desc;
 
    rt_kprintf("do components initialization.\n");
    for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc++)
    {
        rt_kprin
首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇解决SDL/SDL.h: No such file or .. 下一篇初级模拟电路:3-2 BJT的工作原理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目