码迷,mamicode.com
首页 > 其他好文 > 详细

RT-thread main函数分析

时间:2015-06-14 15:10:12      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

RT-thread系统的main函数位于startup.c文件中。

/**
 * This function will startup RT-Thread RTOS.
 */
void rtthread_startup(void)
{
    /* init board */
    rt_hw_board_init();//NVIC_config, SysTick_config, serial_device register, set CONSOLE for output(rt_kprintf(...)) in board.c

    /* show version */
    rt_show_version(); //show the version of rtthread by serial device(set to be console-device in board.c) in kservice.c 

    /* init tick */
    rt_system_tick_init();  //empty fucntion(since 1.1.0) in clock.c

    /* init kernel object */
    rt_system_object_init();//empty fucntion(since 0.3.0) in object.c

    /* init timer system */
    rt_system_timer_init(); //init rt_timer_list[0].next=rt_timer_list[0].prev=rt_timer_list[0](means rt_timer_list is empty) in timer.c

    rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);//init system heap in mem.c

    /* init scheduler system */
    rt_system_scheduler_init();//init the system scheduler, and init rt_thread_defunct(dead thread list) to be empty in scheduler.c

    /* init application */
    rt_application_init();     //init all defined thread in application.c

#ifdef RT_USING_FINSH
    /* init finsh */
    finsh_system_init();       //If use components_init, and INIT_COMPONENT_EXPORT(finsh_system_init) in shell.c, then it can be commentted
    finsh_set_device( FINSH_DEVICE_NAME );//sets the input device of finsh shell(rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX |                                            RT_DEVICE_FLAG_STREAM) in shell.c
#endif

    /* init timer thread */
    rt_system_timer_thread_init();//init system software timer thread(opened by #define RT_USING_TIMER_SOFT in rtconfig.h) in timer.c

    /* init idle thread */
    rt_thread_idle_init();        //init idle thread(cleanup all dead thread), then start to be ready in idle.c

    /* start scheduler */
    rt_system_scheduler_start();  //startup scheduler(first swith to the highest priority thread and enable interrupt )in scheduler.c

    /* never reach here */
    return ;
}
int main(void)
{
    /* disable interrupt first *///enable interrupt(CPSIE I) when the first thread switch(rt_hw_context_switch_to) in lipcpu/cortex-m4/context_rvds.S
    rt_hw_interrupt_disable();

    /* startup RT-Thread RTOS */
    rtthread_startup();

    return 0;
}

 

RT-thread main函数分析

标签:

原文地址:http://www.cnblogs.com/King-Gentleman/p/4574705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!