Fun with empeg_power

Posted by: tonyc

Fun with empeg_power - 21/08/2005 01:44

According to the comments in arch/arm/special/empeg_power.c, and a couple
of old BBS posts, the empeg's power PIC can wake up the empeg at more or
less user-definable intervals. I've tried to play with this functionality, but
so far I'm not seeing what I expect. Here's what I'm doing:

Code:

int fd = open("/dev/empeg_power", O_RDONLY);
int time = 1;
if (fd < 1)
{
printf("couldn't open empeg_power\n");
exit(-1);
}
int rc = ioctl(fd, EMPEG_POWER_WAKETIME, &time);
sleep(1);
printf("goodbye, cruel world...\n");
rc = ioctl(fd, EMPEG_POWER_TURNOFF, NULL);




So, if I'm understanding the comments in empeg_power.c correctly, the above
code should be setting the power PIC's wakeup timer to wake up the empeg in
roughly 15 seconds, and then powering the empeg off. What I see is the empeg
does indeed power off, but doesn't wake up, or, rather, doesn't boot up.

Now, this part of the empeg_power.c comments is where I'm thinking I might
be losing:

Code:

* If there are no events pending when the system wakes up, it just powers
* itself off again. Generally, this brief flash of power lasts no more than
* 300ms (using 200mA - an average hourly drain of 16uAH).



What I don't understand is "if there are no events pending when the system wakes
up." What's a pending event in this context? Is my code fragment above actually
waking the empeg up, but it's going right back to sleep again? How can I get it to
actually wake itself up and boot into the player, for instance?
Posted by: tman

Re: Fun with empeg_power - 22/08/2005 20:01

Appears it won't won't work by default.
Posted by: altman

Re: Fun with empeg_power - 23/08/2005 13:52

You could try to copy what's in 0xe000 to 0xc000 (though I can't remember if there is any non-relocatable code in there) - this way, it *should* boot if the PIC wakes the unit.

The code at 0xc000 should really check (before booting linux & spinning up the drives) whether the alarm time has been reached.

I've attached the state that the 0xc000 code got to... ie, it just powers down! (complies with gas). If you get something working, please post it - the debug print routines are in the attached code so you can print stuff to help debug it.

Hugo
Posted by: tonyc

Re: Fun with empeg_power - 24/08/2005 02:15

Success! Copying e000 to c000 does the trick.

Now, in terms of perfecting it by checking the RTC, I'm afraid my slightly-above-zero knowledge of ARM assembly prevents me from doing that. I guess I'll just be happy with full wakeups "about every hour" for now, unless someone else comes along who's better equipped to do it.
Posted by: tfabris

Re: Fun with empeg_power - 24/08/2005 03:29

Quote:
Success! Copying e000 to c000 does the trick.


Off the wall thought, with no actual knowledge of what you're doing: Are those flash addresses? Remember that flash is a limited resource that can handle only so many "burns" before petering out. I don't know what your code is doing, but if it's copying into flash addresses repeatedly, you might consider how many writes it'll take.
Posted by: tman

Re: Fun with empeg_power - 24/08/2005 07:09

Quote:
Off the wall thought, with no actual knowledge of what you're doing: Are those flash addresses? Remember that flash is a limited resource that can handle only so many "burns" before petering out. I don't know what your code is doing, but if it's copying into flash addresses repeatedly, you might consider how many writes it'll take.

It's a one off process which Tony did manually. The flash has two short chunks of assembler which do some initialisation and then load the kernel. One gets called when you powerup normally and the other gets called when the empeg wakes up from the power PIC timer. The stock code for the timer wake up just automatically turns the empeg back off again, what Tony has done is copy the code from the normal bootup over the timer one.
Posted by: matthew_k

Re: Fun with empeg_power - 24/08/2005 07:12

No need to worry. When a computer starts up, it jumps to a certain memory address and begins executing the machine code located there. When the empeg does it wake up, it does the same thing, but jumps to machine code located at a different address. What he's doing it replacing the code that says "nope, go back to sleep" with code that says "wake up". Once the wake up code is there, there isn't any need to write over it, much like installing hijack doesn't increase the wear on the flash memory.

That being said, I'm looking forward to seeing how this all ends. Wireless syncing sure sounds like fun.

Matthew
Posted by: tonyc

Re: Fun with empeg_power - 24/08/2005 13:03

Yeah, what they said. It's a one-shot deal. But thanks for your concern.
Posted by: tonyc

Re: Fun with empeg_power - 24/08/2005 13:24

Quote:
That being said, I'm looking forward to seeing how this all ends. Wireless syncing sure sounds like fun.


Yeah. I will probably be releasing the results of my work as some kind of software package, tentatively named "empsyncd." Right now it just sits in the background and waits for accessory to go low, then wakes the empeg up, phones home, runs rsync if it gets an answer, sets the wakeup timer, powers down, lathers, rinses, and repeats. It still needs lots of work but it's "working" at this point.