Use both CPU's at the same time
-
- Posts: 11
- Joined: Mon May 11, 2009 1:11 am
Use both CPU's at the same time
Hi there.
I'm new to nds programming, and I was looking for a way to execute code on both cpu's at a time. Kind of threads.
Is it possible ?
BTW: Thank you very much for the great work libnds and devkitARM represent !
I'm new to nds programming, and I was looking for a way to execute code on both cpu's at a time. Kind of threads.
Is it possible ?
BTW: Thank you very much for the great work libnds and devkitARM represent !
Re: Use both CPU's at the same time
Well, yes it is. BUT, communication between the two processors is quite hard...
First you have to make two programs, one compiler to run on the arm7 and one compiled to run on the arm9 (see "templates/combined" in the examples to see how to build the two programs in your nds image)
If you make your own arm7 program, you must remember to call the arm7 version of the libs that require it (dswifi, maxmod, etc. : see the default arm7 code for this)
For comunication between the CPUs, I'll let others tell you how as I'm still not sure on how to do it right... If I recall correctly, it's done by the FIFOs(maybe reading fifocommon.h cound help) using the shared ram([1] [2]), but that's all I know as I never had time to try more on multi-cpu programming on the NDS...
First you have to make two programs, one compiler to run on the arm7 and one compiled to run on the arm9 (see "templates/combined" in the examples to see how to build the two programs in your nds image)
If you make your own arm7 program, you must remember to call the arm7 version of the libs that require it (dswifi, maxmod, etc. : see the default arm7 code for this)
For comunication between the CPUs, I'll let others tell you how as I'm still not sure on how to do it right... If I recall correctly, it's done by the FIFOs(maybe reading fifocommon.h cound help) using the shared ram([1] [2]), but that's all I know as I never had time to try more on multi-cpu programming on the NDS...
try, crash, debug and learn
-
- Posts: 11
- Joined: Mon May 11, 2009 1:11 am
Re: Use both CPU's at the same time
Thank you for this helpful answer
I just had a look at fifocommon.h, looks interresting.
However I have a question about it: there's a callback for addresses, u32, but not for messages... what about it ?
fifoSendAddress ==> fifoSetAddressHandler
fifoSendValue32 ==> fifoSetValue32Handler
fifoSendDatamsg ==> ?
And is there any lock mechanism available (ok, I guess it's not really needed with the fifo, but that would be easier to handle, maybe) ?
I just had a look at fifocommon.h, looks interresting.
However I have a question about it: there's a callback for addresses, u32, but not for messages... what about it ?
fifoSendAddress ==> fifoSetAddressHandler
fifoSendValue32 ==> fifoSetValue32Handler
fifoSendDatamsg ==> ?
And is there any lock mechanism available (ok, I guess it's not really needed with the fifo, but that would be easier to handle, maybe) ?
-
- Site Admin
- Posts: 2003
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Use both CPU's at the same time
It really depends on what you want to do. Given that the ARM7 has only 96K of available RAM and sustained use of the shared 4meg EWRAM will impact the ARM9 performance it's generally not a good idea.
It's best to leave the ARM7 to it's assigned tasks and not attempt "threading".
It's best to leave the ARM7 to it's assigned tasks and not attempt "threading".
-
- Site Admin
- Posts: 2003
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Use both CPU's at the same time
fifoSetDatamsgHandlerAntoine_935 wrote:
fifoSendDatamsg ==> ?
And is there any lock mechanism available (ok, I guess it's not really needed with the fifo, but that would be easier to handle, maybe) ?
That's one of the things that will cause issues - if the ARM7 sits in a loop waiting for a value in EWRAM to change then it takes most of the bus & in some cases has been known to halt the ARM9 entirely. It's probably better to initiate small tasks via FIFO and make use of the handlers.
-
- Posts: 11
- Joined: Mon May 11, 2009 1:11 am
Re: Use both CPU's at the same time
Yes, for a game it looks like a bad idea to do so. Moreover, if you tell so I guess I'd better trust you.It's best to leave the ARM7 to it's assigned tasks and not attempt "threading".
However, my case is slightly different. The program will run 2 separate tasks (ok, somewhat linked, but not much). One of them will require some time to be finished, and the other one will be a small tetris, in order to help the user wait.
This tetris should not require that much ram or processing power, but the other task will.
That's why I thought about using both CPU's.
Knowing this, is it still a bad idea, or do you think it can be done correctly ?
How can I explicitly access this ram ? Or maybe it's the default ?Given that the ARM7 has only 96K of available RAM
Mmmh, so obvious... thank youfifoSetDatamsgHandler
-
- Site Admin
- Posts: 2003
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Use both CPU's at the same time
Unfortunately the ARM7 has no access to graphics hardware in DS mode and the ARM9 is the more powerful processor so dual CPU probably isn't the best solution.Antoine_935 wrote:[
However, my case is slightly different. The program will run 2 separate tasks (ok, somewhat linked, but not much). One of them will require some time to be finished, and the other one will be a small tetris, in order to help the user wait.
This tetris should not require that much ram or processing power, but the other task will.
That's why I thought about using both CPU's.
Knowing this, is it still a bad idea, or do you think it can be done correctly ?
Tetris isn't at all resource intensive though so you could run both on the ARM9 relatively easily. Using maxmod will offload music & sound effects to the ARM7 anyway so all you really need to worry about is the game loop itself. Given that pretty much all games consist of a main loop which waits for vblank at some point all you really need to do is get rid of the the wait & the loop then put the code into the vblank interrupt.
Instead of
Code: Select all
while(1){
read input
move objects
update screen
swiWaitForVblank();
}
Code: Select all
void TetrisVblank() {
read input
move objects
update screen
}
int main(void) {
irqSet(IRQ_VBLANK, TetrisVblank);
...
resource intensive stuff
...
}
Note: Avoid stdio & malloc inside interrupt code, things will break.
-
- Posts: 11
- Joined: Mon May 11, 2009 1:11 am
Re: Use both CPU's at the same time
Thank you very much for these answers
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest