dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Re: time to sleep?

Re: time to sleep?

From: Paul Suade <>
Date: Sat, 24 Aug 2002 23:27:52 +0200

----- Original Message -----
From: "Sven Karlsson" <>
To: <>
Sent: Thursday, August 22, 2002 2:22 PM
Subject: Re: time to sleep?

> 1. Write very efficient code. Every cycle wasted in vain is power wasted!

algorithmic speaking ?

> 2. Do not access memory if not needed. Memory accesses actually take a lot
> of power. There are a lot coding tips one can use to minimise the amount
> memory accesses performed here are a few:
> * Use the "register" keyword whenever possible.

"register" is no use with gcc since itself will try to put the first local
variables in registers (not always a good thing by the way...)

> * Use the "restrict" keyword whenever possible. This keyword was just
> recently introduced into the ANSI C spec.

exactly, it is now part of ANSI C like bool is too.

> * Use the "const" keyword whenever possible.

and a good practice : you know if you are right to modify the content.

> * Don't count on the compiler doing obvious optimizations for you. The
> compiler might not "see" them. It is always a good idea to look at the
> assembly code generated by the compiler. You might be surprised!

The only bemol is that you need to be a good assembly programmer too ;).

> 3. Never busy wait for a long time. Use interrupts or go to sleep.


> 4. Never use interrupts for short timeouts. If you know the timeout is
> a few microseconds then wait that amount of time using a loop and then
> wait. This often consumes less power.

And much more simple to program too. In fact, using a timer interrupt to
wakeup would demand for installing a handler and setting a timeout which
takes much more time to do so and ruin cache effort (if you cpu has ICACHE
of course), spoiling power.

> 5. Don't touch IO chips if can avoid it. The busdrivers often consume a
> of power. This also applies to a lesser degree to microcontroller on-chip
> IO. Remember that IO devices consume a bit of power when being poked at.
> IIRC LCDs consume a lot more power when you change the screen contents
> when they are static.

In short, simply toggle i/o bit when necessary.

Well, I suppose it is not an evidence for all people, especially for those
who only program in higher level language to respect all those rules. :/
Received on 2002-08-24

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy