aboutsummaryrefslogtreecommitdiffstats
path: root/src/chinit.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-11-18 09:45:45 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2007-11-18 09:45:45 +0000
commit4fc627f08b942df8312ad02f24a361b18c4b790b (patch)
tree04258a6a07f8982114d883b55f71b89080e4d0bd /src/chinit.c
parent195a9c7951c29828d7eddefcd77d7a98d18f75f3 (diff)
downloadChibiOS-4fc627f08b942df8312ad02f24a361b18c4b790b.tar.gz
ChibiOS-4fc627f08b942df8312ad02f24a361b18c4b790b.tar.bz2
ChibiOS-4fc627f08b942df8312ad02f24a361b18c4b790b.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@95 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src/chinit.c')
-rw-r--r--src/chinit.c36
1 files changed, 18 insertions, 18 deletions
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 <ch.h>
-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.<br><br>
- * @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);
}
/** @} */