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)

 

转载于:https://www.cnblogs.com/skawu/p/8110520.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值