RT-Thread OS的启动流程

摘要:
1.在RT进入main之前,SystemInit函数初始化时钟。2.主功能位于启动C文件。在启动两个工作系统之前,rt_ hw_中断_禁用将关闭所有中断。然后使用rtthread_ Startup Start RTThread3,函数rtthread_Work done by Startup():1.调用函数rt_ hw_ board_ Init完成板初始化。2.显示版本信息:rt_sho

1、RT进入main之前,

SystemInit函数初始化时钟。

2、main函数位于startup.c文件中。进行两个工作

系统开始前,rt_hw_interrupt_disable关闭所有中断。

之后使用rtthread_startup启动RTThread

3、函数rtthread_startup()完成的工作:

1、调用函数rt_hw_board_init 完成板子初始化工作

2、显示版本信息:rt_show_version

3、初始化系统滴答:rt_system_tick_init

4、系统内核对象初始化:rt_system_object_init

5、定时器初始化:rt_system_timer_init

6、系统堆栈初始化rt_system_heap_init

7、任务调度器初始化:rt_system_scheduler_init

8、rt_application_init //加入用户自定义的任务

9、FINSH模块初始化 ,

10、定时器线程初始化:rt_system_timer_thread_init

11、空闲任务初始化rt_thread_idle_init

12、开始任务调度,OS接管MCU:rt_system_scheduler_start

任务调度开始之后,OS就算是启动好了。之后的东西都是在OS的管理下运行了。

4、在RTT示例工程中添加外设驱动的方法:

  驱动头文件加入board.h

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       //replace finsh_set_device() after the function of rt_components_init() in rt_init_thread_entry() of application.c
    /* init finsh */
    //finsh_system_init();    //INIT_COMPONENT_EXPORT(finsh_system_init) in shell.c, so it needn't finsh_system_init here
    //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 OS的启动流程》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇iOS:quartz2D绘图小项目(涂鸦画板)python Selenium+phantomjs 小技巧下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

RT Thread的SPI设备驱动框架的使用以及内部机制分析

注释:这是19年初的博客,写得很一般,理解不到位也不全面。19年末得空时又重新看了RTThread的SPI和GPIO,这次理解得比较深刻。有时间时再整理上传。 --------------------------------------------------------------------------------------------------...

KEIL 中结构体对指定元素(函数指针)初始化的探索(呼吸灯为例)

结构体对指定元素初始化就是类似下面的操作: 1 struct lzh { int x; int y; }; 2 struct lzh xianjue = 3 { .x = 1, 4 .y = 2 5 }; 在KEIL MDK中使用却报错:“expected an expression”。其实就是编译器不支持C99标准,我们可以打开C99模式让编...

c/c++中变量的作用域

作用域规则告诉我们一个变量的有效范围,它在哪儿创建,在哪儿销毁(也就是说超出了作用域)。变量的有效作用域从它的定义点开始,到和定义变量之前最邻近的开括号配对的第一个闭括号。也就是说,作用域由变量所在的最近一对括号确定。 (1) 全局变量:    全局变量是在所有函数体的外部定义的,程序的所在部分(甚至其它文件中的代码)都可以使用。全局变量不受作用域的影响...

Swift-可选值(Optional)讲解

前提:Swift中有规定:对象中的任何属性在创建时,都必须要有明确的初始化值 1.定义可选类型 方式一:常规方式(不常用) var name : Optional<String> = nil 方式二:语法糖(常用) var name:String? = nil Optional理解:   Optional也是Objective-C没有的数据类型...

JVM 详解

1 jdk  和jre 的区别     jre 石 Java 运行环境,只能运行 class 不能编辑 Java文件,不能dubug。  2  jdk下面的  bin/jconsole.exe 监控 一些内存,线程,jvm 。 3 Java 的 层级 ,以前我们关注的是三面 三次。jvm 是最下面一层    4 Java的  作者是  詹姆斯·高斯林   ...

java基本类型数组初始化

1.byte、short、int、long类型数组,数组元素默认初始化为0。 byte[] i= new byte[10]; //short[] i = new short[10]; //int[] i = new int[10];   System.out.println(i); //是一个内存地址   //每个元素都已默认初始化为0   for(in...