Place CPU in P0 state while idle
authorKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 21:43:23 +0000 (14:43 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 25 Apr 2009 21:43:23 +0000 (14:43 -0700)
ao_task.c
cc1111.h

index 81a71dda3d258ba5c24d5691282eab0f73b18c5d..b69f51ee432f61c5b0f408df01c5123301f11e00 100644 (file)
--- a/ao_task.c
+++ b/ao_task.c
@@ -114,13 +114,23 @@ ao_yield(void) _naked
        /* Find a task to run. If there isn't any runnable task,
         * this loop will run forever, which is just fine
         */
-       for (;;) {
-               ++ao_cur_task_index;
-               if (ao_cur_task_index == ao_num_tasks)
-                       ao_cur_task_index = 0;
-               ao_cur_task = ao_tasks[ao_cur_task_index];
-               if (ao_cur_task->wchan == NULL)
-                       break;
+       {
+               __pdata uint8_t ao_next_task_index = ao_cur_task_index;
+               for (;;) {
+                       ++ao_next_task_index;
+                       if (ao_next_task_index == ao_num_tasks)
+                               ao_next_task_index = 0;
+
+                       ao_cur_task = ao_tasks[ao_next_task_index];
+                       if (ao_cur_task->wchan == NULL) {
+                               ao_cur_task_index = ao_next_task_index;
+                               break;
+                       }
+
+                       /* Enter lower power mode when there isn't anything to do */
+                       if (ao_next_task_index == ao_cur_task_index)
+                               PCON = PCON_IDLE;
+               }
        }
 
        {
index 10d446c0c908b075414e32c15aaa0790a8bceb31..2045c71640a490e22cda2626f541f5d1c14c5cb0 100644 (file)
--- a/cc1111.h
+++ b/cc1111.h
@@ -96,6 +96,11 @@ sfr at 0x9A IEN2;            /* Interrupt Enable 2 Register */
 #define SLEEP_MODE_PM3         (3 << 0)
 #define SLEEP_MODE_MASK                (3 << 0)
 
+/* PCON 0x87 */
+sfr at 0x87 PCON;              /* Power Mode Control Register */
+
+#define PCON_IDLE              (1 << 0)
+
 /*
  * TCON
  */