libctr9
libctr9 copied to clipboard
ioDelay appears to be useless (on k9lh, at least)
I did some testing myself with sdmmc.c ages ago, and I tried again last night by cloning and editing this lib; All the tests pass, other personal projects work too. I don't have any other entrypoint to test this with, so I only speak for k9lh
Useless? In what sense? If you mean with sdmmc.c, it isn't useless. Try removing it and compiling stage2 of a9lh with an sdmmc that doesn't have that nor the waits for the SD card. It will fall into an infinite loop for some reason-- the SD card isn't detected right at boot for reasons no one understands. This is why ioDelay is used-- it's a corner case, sure, but it's one that needs to be taken into account. I am open to suggestions on how to better deal with this corner case.
I see. I will try some things with stage2 then.
If I remember my codebase correctly, there are two delay functions I currently use, wait_cycles or something like that and ioDelay. iirc ioDelay is used by the 3DS cart reading code, and wait_cycles is the one used by sdmmc.c . Feel free to play around with removing such things (I hope you have a hardmod if you are playing around with stage2). Note that the problem only occurs in the first moments after booting-- if you launch stage2 as an application (e.g. arm9loaderhax.bin) you won't see the problem.
In the future I hope to use the timer hardware for timing purposes, I just haven't finished fixing some issues with the timing resolution.
Based on information that has been handed to me, when inserting any SD card (SD, SDHC, SDXC) the 3DS SD/MMC subsystem takes 250 ms to detect the change. Perhaps one way to improve the current handling is to add a check to see if the card is detected. If it is detected, don't bother waiting for whatever long is currently being waited in sdmmc.c, but if it isn't detected, we can't be sure if the card was just inserted or not, thus wait.