/** * @brief Initializes the kernel. * @details Initializes the kernel structures, the current instructions flow * becomes the idle thread upon return. The idle thread must not * invoke any kernel primitive able to change state to not runnable. * @note This function assumes that the @p nil global variable has been * zeroed by the runtime environment. If this is not the case then * make sure to clear it before calling this function. * * @special */ void chSysInit(void) { thread_t *tp; const thread_config_t *tcp; /* Port layer initialization.*/ port_init(); /* System initialization hook.*/ NIL_CFG_SYSTEM_INIT_HOOK(); /* Iterates through the list of defined threads.*/ tp = &nil.threads[0]; tcp = nil_thd_configs; while (tp < &nil.threads[NIL_CFG_NUM_THREADS]) { #if NIL_CFG_ENABLE_STACK_CHECK tp->stklim = (stkalign_t *)tcp->wbase; #endif /* Port dependent thread initialization.*/ PORT_SETUP_CONTEXT(tp, tcp->wend, tcp->funcp, tcp->arg); /* Initialization hook.*/ NIL_CFG_THREAD_EXT_INIT_HOOK(tp); tp++; tcp++; } #if NIL_CFG_ENABLE_STACK_CHECK /* The idle thread is a special case because its stack is set up by the runtime environment.*/ tp->stklim = THD_IDLE_BASE; #endif /* Runs the highest priority thread, the current one becomes the null thread.*/ nil.current = nil.next = nil.threads; port_switch(nil.current, tp); /* Interrupts enabled for the idle thread.*/ chSysEnable(); }
/** * @brief Initializes the kernel. * @details Initializes the kernel structures, the current instructions flow * becomes the idle thread upon return. The idle thread must not * invoke any kernel primitive able to change state to not runnable. * * @special */ void nilSysInit(void) { thread_ref_t tr; const thread_config_t *tcp; /* Port layer initialization.*/ port_init(); /* Iterates through the list of defined threads.*/ for (tr = &nil.threads[0], tcp = nil_thd_configs; #if WHG_MOD tr < nil.idlep; #else /* WHG_MOD */ tr < &nil.threads[NIL_CFG_NUM_THREADS]; #endif /* WHG_MOD */ tr++, tcp++) { tr->state = NIL_THD_READY; tr->timeout = 0; /* Port dependent thread initialization.*/ SETUP_CONTEXT(tr, tcp->wap, tcp->size, tcp->funcp, tcp->arg); /* Initialization hook.*/ #if defined(NIL_CFG_THREAD_EXT_INIT_HOOK) NIL_CFG_THREAD_EXT_INIT_HOOK(tr); #endif } /* Runs the highest priority thread, the current one becomes the null thread.*/ nil.current = nil.next = nil.threads; #if WHG_MOD port_switch(nil.threads, nil.idlep); #else /* WHG_MOD */ port_switch(nil.threads, &nil.threads[NIL_CFG_NUM_THREADS]); #endif /* WHG_MOD */ /* Interrupts enabled for the idle thread.*/ nilSysEnable(); }