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 > Reinitializing wifi [SOLVED]

#139125 - melw - Sun Sep 02, 2007 10:45 am

Does anyone have an idea why deinitilializing and then reinitializing the DS wifi won't work all the way? Even if the initialization seems to go through on a second time, no socket connections can be created afterwards.

A working solution:
Code:

// ARM9 side, assuming ARM7 is straight from wifi_lib_test template
void preinit_wifi() // call only once when firing up the wifi
{
   u32 Wifi_pass = Wifi_Init(WIFIINIT_OPTION_USELED);
   REG_IPC_FIFO_TX = 0x12345678;
   REG_IPC_FIFO_TX = Wifi_pass;
      
   *((volatile u16 *)0x0400010E) = 0; // disable timer3
   
   irqSet(IRQ_TIMER3, Timer_50ms); // setup timer IRQ
   irqEnable(IRQ_TIMER3);
      
    Wifi_SetSyncHandler(arm9_synctoarm7); // tell wifi lib to use our handler to notify arm7

   *((volatile u16 *)0x0400010C) = (u16)-6553; // 6553.1 * 256 cycles = ~50ms;
   *((volatile u16 *)0x0400010E) = 0x00C2; // enable, irq, 1/256 clock

   while(Wifi_CheckInit()==0)
      swiWaitForVBlank();
}

void init_wifi() // can be called each time
{
   Wifi_EnableWifi();
   Wifi_AutoConnect();
}

void uninit_wifi()
{
   Wifi_DisconnectAP();
   Wifi_DisableWifi();
}


Last edited by melw on Mon Sep 03, 2007 9:25 am; edited 2 times in total

#139133 - DragonMinded - Sun Sep 02, 2007 4:06 pm

Why would you want to de and re-init wifi? It's meant to be init'd at the beginning of the software. It doesn't connect or even activate until you associate with a hotspot, so just associate when you need, and then disconnect again.
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#139134 - tepples - Sun Sep 02, 2007 4:13 pm

DragonMinded wrote:
Why would you want to de and re-init wifi? It's meant to be init'd at the beginning of the software.

To save wear and tear on the DS Lite's power switch. Does and should the following work?
  1. Start DSOrganize.
  2. Use IRC, Web Browser, or Homebrew Database.
  3. Return to the menu.
  4. Launch a .nds that uses dswifi.

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#139137 - pas - Sun Sep 02, 2007 4:50 pm

As far as I tried it, it works. DM, I still got no reply to my last mail (I mailed to shaun.taylor@gmail.com) I just ask cause I can't be sure that you read it...

#139139 - melw - Sun Sep 02, 2007 4:57 pm

What Tepples said. In a perfect world it would be nice if you could use wifi homebrew after another. DM: But yeah - for saving battery life, disconnecting from AP is probably already enough, so it's not that big deal.

#139163 - knight0fdragon - Mon Sep 03, 2007 1:15 am

well, do you sync the wifi back up with the arm7 side when you reinitialize it?
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#139185 - melw - Mon Sep 03, 2007 7:46 am

knight0fdragon wrote:
well, do you sync the wifi back up with the arm7 side when you reinitialize it?

Yes. The point was if you try to reinitialize the wifi all the way including Wifi_Init(), Wifi_Pass etc. the initialization itself goes through, but all the connections created after this fail.

Having slept over this, DM has a very valid point. There's no need to do more than disconnecting from the AP and disabling the Wifi_Timer(). In the beginning I tried this since having wifi enabled all the time sucked the DS battery empty in mere 2 hours.

#139188 - DragonMinded - Mon Sep 03, 2007 8:03 am

OF COURSE booted homebrew works fine in DSO. DSO init's the wifi before even showing the main screen. The only thing going to a wifi enabled app does is associate and de-associate from an AP. And from all the wifi-enabled homebrew that boots fine from DSO, I'd say it re-init's fine from new software. So why is this even an issue? It's MEANT to be called just once at the beginning.
_________________
Enter the mind of the dragon.

http://dragonminded.blogspot.com

Seriously guys, how hard is it to simply TRY something yourself?

#140646 - Jesse - Tue Sep 18, 2007 8:41 pm

Thanks for the info in this topic. I do still have one problem though, and that is that the LED never stops blinking. I checked the dswifi code, and there is code to do that, but I guess it never executes for me. Any ideas?

#140711 - melw - Wed Sep 19, 2007 12:46 pm

Jesse wrote:
Thanks for the info in this topic. I do still have one problem though, and that is that the LED never stops blinking. I checked the dswifi code, and there is code to do that, but I guess it never executes for me. Any ideas?

Wifi_DisableWifi() should stop the blinking, but if it doesn't you can always manually stop the wifi timer (irqDisable(IRQ_TIMER3) if using same source code from the wifi_lib_test template).

#140716 - Jesse - Wed Sep 19, 2007 1:52 pm

My mistake. It works now. Thanks a bunch!

#140781 - knight0fdragon - Wed Sep 19, 2007 7:53 pm

melw wrote:
knight0fdragon wrote:
well, do you sync the wifi back up with the arm7 side when you reinitialize it?

Yes. The point was if you try to reinitialize the wifi all the way including Wifi_Init(), Wifi_Pass etc. the initialization itself goes through, but all the connections created after this fail.

Having slept over this, DM has a very valid point. There's no need to do more than disconnecting from the AP and disabling the Wifi_Timer(). In the beginning I tried this since having wifi enabled all the time sucked the DS battery empty in mere 2 hours.

I dont think you are getting my point, you need to init the Wifi on the arm 7 side again also, since this is your comment // ARM9 side, assuming ARM7 is straight from wifi_lib_test template

your arm7 is doing this

// Keep the ARM7 out of main RAM
while (1) swiWaitForVBlank();

when you try to initialize it a second time, which means you are missing some of the arm7 stuff needed to get the wifi going
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206