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 > fifo breaking wifi?

#168474 - Toaster Mage - Thu Apr 30, 2009 1:53 am

When I try and use wifi with the following code, it just sits on Wifi_InitDefault till it fails, but when I comment out the other fifo handling code the wifi works as expected.
I have spent the last few days trying things to see if I can find what the problem is. I failed horribly so here I am.

arm7/main.c:
Code:
#include <nds.h>
#include <dswifi7.h>

#include "as_lib7.h"
#include "../common/fifo.h"


u8 isOldDS = 0;
u8 backlight = 1;

void vCountHandler() {
    u16 pressed = REG_KEYXY;

    inputGetAndSend();

    //Sleep mode
    if (pressed & BIT(7)) {
        systemSleep();
    }
}

void vBlankHandler() {
    AS_SoundVBL();
    Wifi_Update();
}

int main(int argc, char** argv) {
    irqInit();
    fifoInit();
   
    readUserSettings();
    initClockIRQ();
    SetYtrigger(80);

    //Setup FIFO
    installWifiFIFO();
    installSystemFIFO();

    //installSoundFIFO();
    //mmInstall(FIFO_MAXMOD);

    //Setup IRQ
    irqSet(IRQ_VCOUNT, vCountHandler);
    irqSet(IRQ_VBLANK, vBlankHandler);
    irqEnable(IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);

    //Send backlight state
    isOldDS = !(readPowerManagement(4) & BIT(6));
    backlight = isOldDS ? 3 : readPowerManagement(4);
    fifoSendValue32(TCOMMON_FIFO_CHANNEL_ARM9, MSG_TOGGLE_BACKLIGHT);
    fifoSendValue32(TCOMMON_FIFO_CHANNEL_ARM9, backlight);

    //Enable sound
    REG_SOUNDCNT = SOUND_ENABLE | SOUND_VOL(0x7F);

    do {
        if (fifoCheckValue32(TCOMMON_FIFO_CHANNEL_ARM7)) {
            u32 value = fifoGetValue32(TCOMMON_FIFO_CHANNEL_ARM7);

            // ==== comment from here ====
            switch (value) {
            case MSG_TOGGLE_BACKLIGHT:
                if (isOldDS) {
                    u32 power = readPowerManagement(PM_CONTROL_REG) & ~(PM_BACKLIGHT_TOP|PM_BACKLIGHT_BOTTOM);
                    if (backlight) {
                        backlight = 0;
                    } else {
                        backlight = 3;
                        power = power | PM_BACKLIGHT_TOP | PM_BACKLIGHT_BOTTOM;
                    }
                    writePowerManagement(PM_CONTROL_REG, power);
                } else {
                    backlight = ((backlight+1) & 0x3); //b should be in range 0..3
                    writePowerManagement(4, backlight);
                }
                fifoSendValue32(TCOMMON_FIFO_CHANNEL_ARM9, MSG_TOGGLE_BACKLIGHT);
                fifoSendValue32(TCOMMON_FIFO_CHANNEL_ARM9, backlight);
                break;
            case MSG_INIT_SOUND_ARM7:
                while (!fifoCheckValue32(TCOMMON_FIFO_CHANNEL_ARM7));
                int v = fifoGetValue32(TCOMMON_FIFO_CHANNEL_ARM7);
                AS_Init((IPC_SoundSystem*)v);
                break;
            }
            // ==== down to here ====
        }

        swiWaitForVBlank();
        AS_MP3Engine();
    } while(1);
}




I have also noticed just having the relevant code in the program breaks it, even if it isn`t called.

#168477 - elhobbs - Thu Apr 30, 2009 3:05 am

why are you constantly polling for fifo messages? is there a reason you do not want to setup a handler to be called on fifo interrupts?

fifoSetValue32Handler or fifoSetDatamsgHandler depending on the data being sent.

however, I think this might point to an issue that I have been experiencing with fifo and wifi myself. I think that the fifo code does not properly disable and enable interrupts. the fifo sets IME to 0 to disable interrupts then sets it 1 when it is done. the wifi code saves IME then sets it 0 to disable interrupts. dswifi then restores the saved value when it is done. I think the fifo code can enable interrupts when dswifi has it enabled. particulary when the syncfunction is called in dswifi while interrupts are disabled.

#168490 - AxemRed - Thu Apr 30, 2009 8:07 pm

You're probably running out of memory on the ARM7. TouhouDS uses the same ARM7 code, but with SHRINK_AS_LIB enabled and SUPPORT_BACKLIGHT disabled.