#128576 - spinal_cord - Sat May 12, 2007 11:03 pm
Just wondering, is there a simple way to switch off the ds within software? I want to add a switch off feature to something I'm working on, and I haven't got a clue how to do it.
Any help?
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage
#128577 - Lick - Sat May 12, 2007 11:07 pm
int temp = readPowerManagement(PM_CONTROL);
writePowerManagement(PM_CONTROL, temp | BIT(6)); // BIT(6): 0=on, 1=off
This is on the ARM7 of course.
#128578 - Sunray - Sat May 12, 2007 11:23 pm
Does it matter what you write except bit 6? I mean, the DS will switch off :)
#128579 - Lick - Sat May 12, 2007 11:53 pm
It probably doesn't matter, because the PowerManagement states won't survive a powercycle anyway. But I gave the "full example" because powering-off isn't the only thing those functions do and it's important to know that with all other changes, you have to make sure you only change the bits you intend to change. (This is a general rule, not just for these values.)
int mask = BIT(6) | BIT(5);
int old = readPowerManagement(PM_CONTROL) & ~mask;
writePowerManagement(PM_CONTROL, old | BIT(6));
Note that this is the ultimate way to change the bit, because as you can see BIT(5) needs to be 0 after this snippet. If you don't mask the old value, and you know how the |-operator doesn't clear the bit, BIT(5) will still be 1 if it was 1 before. So it's important to mask the "potentially changed" bits to 0.
old|new
// without masking
1|1=1 //yes
1|0=1 //no
// masked
0|1=1 //yes
0|0=0 //yes
Anyway, I used way too much time explaning something very logical.
#128599 - spinal_cord - Sun May 13, 2007 10:49 am
How do I do this in palib? I don't yet know the difference between arm7/arm9. (sorry)
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage
#128603 - Lick - Sun May 13, 2007 11:42 am
Is there a way to program the ARM7 in Palib? (In other words, can you have two main-functions? One for ARM9, other for ARM7)
_________________
http://licklick.wordpress.com
#128607 - ThomasS - Sun May 13, 2007 1:24 pm
No, it's not possible to program the arm7 with PALib, but you can abuse the PA_Screenlight function (PALib - arm7) to write the Poweroff flag.
To call this function by the arm9, use:
Code: |
// Turns off the DS.
extern inline void PA_Shutdown()
{
IPC->aux |= BIT(6); // libnds arm7 code: #define PM_POWER_DOWN BIT(6)
} |
#128609 - spinal_cord - Sun May 13, 2007 1:32 pm
Lick wrote: |
Is there a way to program the ARM7 in Palib? (In other words, can you have two main-functions? One for ARM9, other for ARM7) |
Nope, just the one main.c (I assume arm9 only?) is this one of the reasons some people don't like palib?
[edit] It worked, thanks guys![/edit]
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage
#128617 - tondopie - Sun May 13, 2007 2:46 pm
so is there anyway to call this funciton on the ARM9 even though the ARM7 handles this?
#128622 - Sunray - Sun May 13, 2007 3:38 pm
Yes, with FIFO IPC commands.