Esempio n. 1
0
/**
 * @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 *tp;
  const ThreadConfig *tcp;

  /* Port layer initialization.*/
  port_init();

  /* Iterates through the list of defined threads.*/
  for (tp = &nil.threads[0], tcp = nil_thd_configs;
#if WHG_MOD
       tp < nil.idlep;
#else  /* WHG_MOD */
       tp < &nil.threads[NIL_CFG_NUM_THREADS];
#endif  /* WHG_MOD */
       tp++, tcp++) {

    /* Port dependent thread initialization.*/
    SETUP_CONTEXT(tcp->wap, tcp->size, tcp->funcp, tcp->arg);
  }

  /* Runs the highest priority thread, the current one becomes the null
     thread.*/
  nil.currp = nil.nextp = 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();
}
Esempio n. 2
0
/**
 * @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();
}