gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Issues with CycloDS? (swiWaitForVBlank on ARM7)

#167325 - Echo49 - Mon Mar 09, 2009 7:37 am

My game runs fine on a Supercard and an R4, but users of the CycloDS experience random crashes during the game. I don't personally own a CycloDS so testing it is a bit of a pain. Does anyone know of any issues with the CycloDS? Perhaps with the FIFO?

Last edited by Echo49 on Tue Mar 10, 2009 11:37 am; edited 2 times in total

#167365 - Echo49 - Tue Mar 10, 2009 4:10 am

I have narrowed the problem down to either FIFO not working, or the ARM7 freezing (or stuck in an infinite loop). My ARM7 main loop is somewhat like the following (please ignore any incorrect function names or incorrect number of arguments, I'm doing this from memory):

Code:
while (1)
{
    while (fifoCheckValue32(FIFO_USER_01))
        fifoGetValue32(FIFO_USER_01); //and do something with it
   
    swiWaitForVBlank();
   
    fifoSendValue32(FIFO_USER_01, someValue);
}

Could it be that I'm sending and receiving on the same channel? I did a few experiments beforehand and it didn't seem like it would clash or cause problems. The important thing to note is that this problem only happens with the CycloDS. There is no problem at all when I use the Supercard or the R4.

Also what would be the best (or easiest/simplest) way to check whether the ARM7 has hung or not? iirc printf() doesn't work from the ARM7.

#167373 - Echo49 - Tue Mar 10, 2009 11:44 am

After even more testing (over the internet) I've discovered it's because of the swiWaitForVBlank() instruction.

When I copmile with both custom ARM9 and ARM7 files, on the ARM7 when using the CycloDS, the following will cause random crashes:
Code:
while (1)
{
    //... do stuff
    swiWaitForVBlank();
}

Whereas the following will not:
Code:
while(1)
{
   //... do stuff
   while (REG_VCOUNT>=192);
   while (REG_VCOUNT<192);
}

Are you allowed to call swiWaitForVBlank() from both CPUs? Does anyone know of a better work-around for this?

can someone reply? being the only replier in my own thread gets kinda depressing >.>

#167376 - Pete_Lockwood - Tue Mar 10, 2009 3:06 pm

Echo49 wrote:
Are you allowed to call swiWaitForVBlank() from both CPUs?


Just so you have a response from someone else.. Yes, you can call swiWaitForVBlank() on the ARM7. Can't help with the actual problem.
_________________
It's not an illusion, it just looks like one.

#167378 - hacker013 - Tue Mar 10, 2009 3:25 pm

I have the same problem on my m3 ds real with m3 sakura firmware :(
_________________
Website / Blog

Let the nds be with you.

#167390 - Lazy1 - Tue Mar 10, 2009 7:20 pm

For arm7 debugging you can always use the sound hardware to generate noise, there are proper ways to do it but I just played a sound with the address of main().

It gave a few pops and some other weird noises so I knew that the one section of code had been executed.
Still, it's a really ugly hack.

#167394 - nanou - Tue Mar 10, 2009 7:44 pm

Lazy1 wrote:
Still, it's a really ugly hack.


That's really not a bad idea though, especially if you can't trust IPC for some reason.
_________________
- nanou

#167399 - Pete_Lockwood - Tue Mar 10, 2009 8:27 pm

Lazy1 wrote:
For arm7 debugging you can always use the sound hardware to generate noise, there are proper ways to do it but I just played a sound with the address of main().


Haha. I use the LED to get an idea of where my ARM7 code is.
_________________
It's not an illusion, it just looks like one.

#167401 - Echo49 - Tue Mar 10, 2009 9:11 pm

I have resolved this by simply not using swiWaitForVBlank() and processing my main loop (which is extremely short) in the vblank interrupt handler.

Code:
#include <nds.h>
#include <dswifi7.h>

void fifoHandler(u32 value, void* buffer)
{
   /* do handler stuff */
}

void VcountHandler()
{
   inputGetAndSend();
}

void VblankHandler(void)
{
   /* do my stuff */

   Wifi_Update();
}

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

   // read User Settings from firmware
   readUserSettings();

   // Start the RTC tracking IRQ
   initClockIRQ();

   SetYtrigger(80);

   installWifiFIFO();
   installSoundFIFO();

   installSystemFIFO();
   
   irqSet(IRQ_VCOUNT, VcountHandler);
   irqSet(IRQ_VBLANK, VblankHandler);

   irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
   
   //fifo handler
   fifoSetValue32Handler(FIFO_USER_01, fifoHandler, NULL);
   
   // Keep the ARM7 mostly idle
   while (1)
   {
      //choose some irq that will never trigger to keep ARM7 idle
      swiIntrWait(1, IRQ_CARD);
   }
}