Add avr-kern example.
[bertos.git] / bertos / kern / idle.c
index ede234c34f4c296738e3da6ab1a8c8049b6853d6..592d17b16401e2ca4e6699c3b0cdefb549124173 100644 (file)
  *
  * \brief Idle loop for preemptive scheduling
  *
- * \version $Id: proc.c 1616 2008-08-10 19:41:26Z bernie $
+ * \version $Id$
  * \author Bernie Innocenti <bernie@codewiz.org>
  */
 
+#include "idle.h"
 #include "proc.h"
 
+#include <cpu/power.h> // cpu_relax()
 #include <cfg/module.h>
+#include <cpu/types.h> // INT_MIN
 
+#include <kern/proc_p.h>
 
-static cpustack_t idle_stack[CONFIG_PROC_DEFSTACKSIZE / sizeof(cpustack_t)];
+struct Process *idle_proc;
+
+static PROC_DEFINE_STACK(idle_stack, KERN_MINSTACKSIZE);
 
 /**
  * The idle process
@@ -58,13 +64,21 @@ static NORETURN void idle(void)
 {
        for (;;)
        {
-               TRACE;
-               //monitor_report();
-               proc_yield(); // FIXME: CPU_IDLE
+               CPU_IDLE;
+               proc_switch();
        }
 }
 
 void idle_init(void)
 {
-       proc_new(idle, NULL, sizeof(idle_stack), idle_stack);
+       /*
+        * Idle will be added to the ProcReadyList, but immediately removed
+        * after the first cpu_relax() execution.
+        *
+        * XXX: it would be better to never add idle_proc to the ProcReadyList,
+        * e.g., changing the prototype of proc_new() (or introducing a
+        * proc_new_nostart()) to allow the creation of "sleeping" tasks.
+        */
+       idle_proc = proc_new(idle, NULL, sizeof(idle_stack), idle_stack);
+       proc_setPri(idle_proc, INT_MIN);
 }