libnds 1.3.1 - FIFO Problem

kadrim1983
Posts: 6
Joined: Mon Dec 22, 2008 12:46 am

libnds 1.3.1 - FIFO Problem

Post by kadrim1983 » Fri Dec 26, 2008 5:24 pm

Hi there,

i have a little Problem understanding the new FIFO based arm7<->arm9
communication.

I tried to send a simple message to arm7 (from arm9) and respond back to
arm9 as soon as the message arrives.

This should be very straightforward, especially since the wifi init does
work in the exact same application (and it's almost the same IPC
mechanism)

In my example the message only is sent (by arm9) but never comes back.

Could someone please tell me why?

So here are the code snippets:

Code: Select all

// ************* arm7 main:

int main() {
irqInit();
fifoInit();

readUserSettings();

initClockIRQ();
SetYtrigger(80);

installUserFIFO();
installWifiFIFO();

// ... ... ...

while (1) {
swiWaitForVBlank();
}

// ---



// *********** user_fifo7.c

#include <nds.h>
#include "user_fifo7.h"

static void userValue32Handler(u32 value, void* data) {
fifoSendValue32(FIFO_USER_07, 4);
}

void installUserFIFO() {
fifoSetValue32Handler(FIFO_USER_07, userValue32Handler, 0);
}

// ---


// ************ arm9 main
int main(int argc, const char* argv[]) {
irqInit();
irqEnable(IRQ_VBLANK);
irqSet (IRQ_VBLANK, vidBuf_VblankHandler);

installUserFIFO();

sendMessageToArm7();
// ... ... ...

while(1) {
swiWaitForVBlank();
}
}

// ************* user_fifo9.c
#include <nds.h>
#include <stdio.h>
#include "user_fifo9.h"

static int test;

static void userValue32Handler(u32 value, void* data) {
test = 0;

}

void installUserFIFO() {
fifoSetValue32Handler(FIFO_USER_07, userValue32Handler, 0);
}

void sendMessageToArm7() {
test = 1;
if(fifoSendValue32(FIFO_USER_07, 2))
iprintf("Message on the way... \n");
else
iprintf("Message broadcast failed.\n");

while(test == 1) {
swiWaitForVBlank();
}
iprintf("message is back!!!\n");
}
// ---

kadrim1983
Posts: 6
Joined: Mon Dec 22, 2008 12:46 am

Re: libnds 1.3.1 - FIFO Problem

Post by kadrim1983 » Sun Dec 28, 2008 12:06 am

found the problem :-)

So for anyone else interested:

In my very old project i had the wrong cpu architecture selected

in the arm9 makefile was

Code: Select all

ARCH	:=	-marm -mthumb-interwork
which has to be changed to this, so the fifo works:

Code: Select all

ARCH	:=	-mthumb -mthumb-interwork

additionally the arm9 main shouldn't contain

irqinit();

and enabling the vblank irq is not neccessary.

WinterMute
Site Admin
Posts: 1911
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libnds 1.3.1 - FIFO Problem

Post by WinterMute » Sun Dec 28, 2008 1:11 am

kadrim1983 wrote:found the problem :-)

So for anyone else interested:

In my very old project i had the wrong cpu architecture selected

in the arm9 makefile was

Code: Select all

ARCH	:=	-marm -mthumb-interwork
which has to be changed to this, so the fifo works:

Code: Select all

ARCH	:=	-mthumb -mthumb-interwork
That should make absolutely no difference to the FIFO functioning.

additionally the arm9 main shouldn't contain

irqinit();

and enabling the vblank irq is not neccessary.
On the other hand, we noted that irqInit should no longer be used in arm9 code on the release notes, This was the cause.

FWIW, we are currently discouraging use of custom arm7 code in user projects - if there is some feature that the default arm7 code is missing that you think you require then please feel free to ask. Using custom code is likely to cause maintenance issues when we update the tools.
Help keep devkitPro toolchains free, Donate today

Personal Blog

kadrim1983
Posts: 6
Joined: Mon Dec 22, 2008 12:46 am

Re: libnds 1.3.1 - FIFO Problem

Post by kadrim1983 » Sun Dec 28, 2008 8:55 pm

well the march flag was the culprit, c
double checked it even without irqinit.

and yes, usually i would use the default arm7 core but i need my own code in arm7 for special tasks (i.e. when arm9 is busy) with special fifo callbacks

WinterMute
Site Admin
Posts: 1911
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libnds 1.3.1 - FIFO Problem

Post by WinterMute » Wed Dec 31, 2008 12:11 am

kadrim1983 wrote:well the march flag was the culprit, c
double checked it even without irqinit.
Checked & double checked here, the FIFO code works fine regardless of -marm or -mthumb in either makefile of a combined project.

and yes, usually i would use the default arm7 core but i need my own code in arm7 for special tasks (i.e. when arm9 is busy) with special fifo callbacks

What specifically do you need that the current default arm7 doesn't provide?
Help keep devkitPro toolchains free, Donate today

Personal Blog

kadrim1983
Posts: 6
Joined: Mon Dec 22, 2008 12:46 am

Re: libnds 1.3.1 - FIFO Problem

Post by kadrim1983 » Thu Jan 01, 2009 3:02 pm

what i need from the arm7 isn't something everyone else will be in need for:

1) lets assume arm7 decodes a raw mp3 stream with a helix decoder, a bug appears and arm7 sends a fifo message to arm9 with the exact problem while decoding. (i don't know if there is a way to do this with MM now)

2) lets assume arm9 has a bunch of processing tasks (application is neither a graphical nor sound or whatever like game...), arm7 has to poll arm9 every now and then to check the load of arm9 and if it has been to high for a while then get a processing task from arm9 to share the load.

3) i do this because i want to learn about the system, not to only use the high level api :-) => much more fun for me

WinterMute
Site Admin
Posts: 1911
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libnds 1.3.1 - FIFO Problem

Post by WinterMute » Sat Jan 03, 2009 1:36 am

Honestly I think you're really wasting your time with anything of this nature.

As things stand the arm7 has a total of 96K for user code & data. If you start having the arm7 accessing main RAM frequently in order to use extra memory for other things then you will have a dramatic effect on the speed of the arm9. In some cases I've seen arm7 code actually block the arm9 completely for quite long periods due to the bus arbitration.

The DS isn't really well suited to mp3 decoding, especially not in a game of any real complexity. For a simple mp3 player helix is rather effective but the code I'm currently testing seems to be using approximately 60% of the arm9 for streaming & decoding.
Help keep devkitPro toolchains free, Donate today

Personal Blog

kadrim1983
Posts: 6
Joined: Mon Dec 22, 2008 12:46 am

Re: libnds 1.3.1 - FIFO Problem

Post by kadrim1983 » Mon Jan 05, 2009 11:37 am

hmm well thats your opinion ;-)

just curious: do you think "tunavids" by chrism was also a waste of time for him? basically it's the same thing :-)

GrizzlyAdams
Posts: 3
Joined: Tue Jan 06, 2009 4:37 am

Re: libnds 1.3.1 - FIFO Problem

Post by GrizzlyAdams » Tue Jan 06, 2009 5:01 am

I have to agree with WinterMute that MP3 decoding is a waste on the DS as you won't have time left to do much else. Video decoding is very much a waste too, look at any retail games that use Act Imagine, low framerate (12-15fps) and noticeable compression artifacts.

Now on why -mthumb would have made things work:Your program was likely using up all the memory available and hanging. Thumb instructions are smaller, but more are needed for complex operations. You probably shaved a couple KB at most by switching to -mthumb so you will still have problems. That shows even more that you have too much going on for the arm7 to cope with.

WinterMute
Site Admin
Posts: 1911
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libnds 1.3.1 - FIFO Problem

Post by WinterMute » Tue Jan 06, 2009 5:27 am

Pretty much, yes. There are cheaper devices than the DS that do a much better job of video than the DS ever will.

http://www.engadget.com/tag/Gemei/
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests