[freenos] r419 committed - Implemented api_proc_idle() to put the CPU in low power mode in the id...

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Fri, 22 Oct 2010 22:46:31 +0000

Revision: 419
Author: nieklinnenbank
Date: Fri Oct 22 15:42:27 2010
Log: Implemented api_proc_idle() to put the CPU in low power mode in the idle server.

http://code.google.com/p/freenos/source/detail?r=419

Modified:
 /branches/scratch/include/kernel/api.h
 /branches/scratch/include/x86/cpu.h
 /branches/scratch/server/idle/main.c
 /branches/scratch/server/serial/main.c
 /branches/scratch/system/api.c

=======================================
--- /branches/scratch/include/kernel/api.h      Fri Oct 22 15:05:50 2010
+++ /branches/scratch/include/kernel/api.h      Fri Oct 22 15:42:27 2010
@@ -22,8 +22,9 @@

 #define API_PROC_ID      (1 << 0)
 #define API_PROC_DESTROY (1 << 1)
-#define API_IO_READ      (1 << 2)
-#define API_IO_WRITE     (1 << 3)
+#define API_PROC_IDLE   (1 << 2)
+#define API_IO_READ      (1 << 3)
+#define API_IO_WRITE     (1 << 4)

 __inline__ static pid_t api_proc_id(void)
 {
@@ -34,6 +35,11 @@
 {
     return sys_call1(API_PROC_DESTROY, pid);
 }
+
+__inline__ static void api_proc_idle(void)
+{
+    sys_call0(API_PROC_IDLE);
+}

 __inline__ static result_t api_io_read(uint port, size_t size)
 {
=======================================
--- /branches/scratch/include/x86/cpu.h Mon Oct 18 16:59:47 2010
+++ /branches/scratch/include/x86/cpu.h Fri Oct 22 15:42:27 2010
@@ -124,6 +124,12 @@
     __asm__ volatile ("ltr %0\n" :: "r"(tr)); \
 })

+/**
+ * Puts the CPU in a lower power consuming state.
+ */
+#define idle() \
+    __asm__ volatile ("hlt");
+
 typedef struct cpu_state
 {
     /* Segments. */
=======================================
--- /branches/scratch/server/idle/main.c        Mon Oct 18 16:26:59 2010
+++ /branches/scratch/server/idle/main.c        Fri Oct 22 15:42:27 2010
@@ -15,11 +15,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

-#include <string.h>
-#include <unistd.h>
+#include <FreeNOS/api.h>

 int main(void)
 {
-    for (;;);
+    api_proc_idle();
     return 0;
 }
=======================================
--- /branches/scratch/server/serial/main.c      Fri Oct 22 15:05:50 2010
+++ /branches/scratch/server/serial/main.c      Fri Oct 22 15:42:27 2010
@@ -46,7 +46,7 @@
     /* Let kill init. */
     api_proc_destroy(0);

-    /* Loop forever. */
-    for (;;);
+    /* Don't die but also don't busy loop. */
+    api_proc_idle();
     return 0;
 }
=======================================
--- /branches/scratch/system/api.c      Fri Oct 22 15:05:50 2010
+++ /branches/scratch/system/api.c      Fri Oct 22 15:42:27 2010
@@ -17,6 +17,8 @@

 #include <FreeNOS/api.h>
 #include <FreeNOS/io.h>
+#include <FreeNOS/irq.h>
+#include <FreeNOS/cpu.h>
 #include <FreeNOS/types.h>
 #include <FreeNOS/process.h>
 #include <FreeNOS/printk.h>
@@ -41,6 +43,10 @@
            else
                return -ESRCH;

+       case API_PROC_IDLE:
+           irq_enable();
+           for (;;) idle();
+
        case API_IO_READ:
            return inb(arg1);


Other related posts:

  • » [freenos] r419 committed - Implemented api_proc_idle() to put the CPU in low power mode in the id... - freenos