From 4fc627f08b942df8312ad02f24a361b18c4b790b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 18 Nov 2007 09:45:45 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@95 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chinit.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/chinit.c') diff --git a/src/chinit.c b/src/chinit.c index 4a25567a8..918da1796 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -24,27 +24,17 @@ #include -static Thread idlethread; /** * ChibiOS/RT initialization. After executing this function the current - * instructions stream becomes the idle thread. The thread must execute the - * first user thread and then go to sleep into the \p chSysPause() where it - * will just serve the interrupts while keeping the lowest possible power - * mode.

- * @code - * chSysInit(); - * chThdCreate(...); // Starts one or more user threads. - * chSysPause(); - * @endcode + * instructions stream becomes the main thread. * @note Interrupts should be still disabled when \p chSysInit() is invoked * and are internally enabled. - * @note The idle thread has absolute priority when exiting from the - * \p chSysInit(), this is done to make sure that all the initializations - * performed in the \p main() procedure are completed before any thread - * starts. The priority is set to \p IDLEPRIO into the \p chSysPause(). + * @note The main thread is created with priority \p NORMALPRIO. */ void chSysInit(void) { + static Thread mainthread; + static BYTE8 waIdleThread[UserStackSize(IDLE_THREAD_STACK_SIZE)]; chSchInit(); chDbgInit(); @@ -52,13 +42,23 @@ void chSysInit(void) { chVTInit(); #endif /* - * Now this instructions flow becomes the idle thread. + * Now this instructions flow becomes the main thread. */ - _InitThread(ABSPRIO, 0, &idlethread); - idlethread.p_state = PRCURR; - currp = &idlethread; + _InitThread(NORMALPRIO, 0, &mainthread); + mainthread.p_state = PRCURR; + currp = &mainthread; chSysUnlock(); + + /* + * The idle thread is created using the port-provided implementation. + * This thread has the lowest priority in the system, its role is just to + * execute the chSysPause() and serve interrupts in its context. + * In ChibiOS/RT at least one thread in the system *must* execute + * chThdPause(), it can be done in a dedicated thread or in the main() + * function (that would never exit the call). + */ + chThdCreate(IDLEPRIO, 0, waIdleThread, sizeof(waIdleThread), (t_tfunc)_IdleThread, NULL); } /** @} */ -- cgit v1.2.3