• zephyr初始化流程


    1、调用应用层main()函数
            kernel/init.c      181行
     1 /**
     2  *
     3  * @brief Mainline for kernel's background task
     4  *
     5  * This routine completes kernel initialization by invoking the remaining
     6  * init functions, then invokes application's main() routine.
     7  *
     8  * @return N/A
     9  */
    10 static void _main(void *unused1, void *unused2, void *unused3)
    2、调取_main()函数
        kernel/init.c    241行    317行
     1 /**
     2  *
     3  * @brief Initializes kernel data structures
     4  *
     5  * This routine initializes various kernel data structures, including
     6  * the init and idle threads and any architecture-specific initialization.
     7  *
     8  * Note that all fields of "_kernel" are set to zero on entry, which may
     9  * be all the initialization many of them require.
    10  *
    11  * @return N/A
    12  */
    13 static void prepare_multithreading(struct k_thread *dummy_thread)
    14 
    15 static void switch_to_main_thread(void)
    初始化内核数据结构,该函数初始化各种内核数据结构,包括init和idle线程、任意指定架构的初始化
    3、调用prepare_multithreading(),switch_to_main_thread()函数
        kernel/init.c        347行
     1 /**
     2  *
     3  * @brief Initialize kernel
     4  *
     5  * This routine is invoked when the system is ready to run C code. The
     6  * processor must be running in 32-bit mode, and the BSS must have been
     7  * cleared/zeroed.
     8  *
     9  * @return Does not return
    10  */
    11 FUNC_NORETURN void _Cstart(void)
        当系统可以运行C代码试调用,处理器必须以32位模式运行,BSS必须清除或置零。
        BSS段用来存放程序中未初始化的全局变量和静态变量的内存区域,可读写,在程序运行前自动清0
    4、调用_Cstart()函数
            arch/arm/core/cortex_m    prep_c.c    104行
    /**
     *
     * @brief Prepare to and run C code
     *
     * This routine prepares for the execution of and runs C code.
     *
     * @return N/A
     */
    void _PrepC(void)
        此函数准备执行并运行C代码
    5、调用_PrepC()函数
        arch/arm/core/cortex_m/    reset.S        50行 58行
    /**
     *
     * @brief Reset vector
     *
     * Ran when the system comes out of reset. The processor is in thread mode with
     * privileged level. At this point, the main stack pointer (MSP) is already
     * pointing to a valid area in SRAM.
     *
     * Locking interrupts prevents anything but NMIs and hard faults from        NMI非屏蔽中断
     * interrupting the CPU. A default NMI handler is already in place in the
     * vector table, and the boot code should not generate hard fault, or we're in
     * deep trouble.
     *
     * We want to use the process stack pointer (PSP) instead of the MSP, since the
     * MSP is to be set up to point to the one-and-only interrupt stack during later
     * boot. That would not be possible if in use for running C code.
     *
     * When these steps are completed, jump to _PrepC(), which will finish setting
     * up the system for running C code.
     *
     * @return N/A
     */
    SECTION_SUBSEC_FUNC(TEXT,_reset_section,__reset)
        /*
     * The entry point is located at the __reset symbol, which
     * is fetched by a XIP image playing the role of a bootloader, which jumps to
     * it, not through the reset vector mechanism. Such bootloaders might want to
     * search for a __start symbol instead, so create that alias here.
     */
    SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
  • 相关阅读:
    JS调用App方法及App调用JS方法
    提升用户体验之 选用合适的鼠标光标
    js仿QQ拖拽删除
    Linux下安装 mongodb
    QQ分享-定制分享卡片
    js判断浏览器语言实现网站国际化
    js复制内容到剪切板
    为什么会有堆内存和栈内存之分
    Avro实现RPC
    zookeeper学习day01
  • 原文地址:https://www.cnblogs.com/skawu/p/8110520.html
Copyright © 2020-2023  润新知