diff --git a/loader/source/fatfs/sdmmc/delay.h b/loader/source/fatfs/sdmmc/delay.h index d08c0ccc..afad4389 100644 --- a/loader/source/fatfs/sdmmc/delay.h +++ b/loader/source/fatfs/sdmmc/delay.h @@ -6,4 +6,4 @@ #include "common.h" -void waitcycles(u32 us); +void ioDelay(u32 us); diff --git a/loader/source/fatfs/sdmmc/delay.s b/loader/source/fatfs/sdmmc/delay.s index 5386fd8a..b3baccd4 100644 --- a/loader/source/fatfs/sdmmc/delay.s +++ b/loader/source/fatfs/sdmmc/delay.s @@ -1,10 +1,17 @@ -.arm -.global waitcycles -.type waitcycles STT_FUNC +// Copyright 2014 Normmatt +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. -@waitcycles ( u32 us ) -waitcycles: - waitcycles_loop: - subs r0, #1 - bgt waitcycles_loop - bx lr +.arm +.global ioDelay +.type ioDelay STT_FUNC + +@ioDelay ( u32 us ) +ioDelay: + ldr r1, =0x18000000 @ VRAM +1: + @ Loop doing uncached reads from VRAM to make loop timing more reliable + ldr r2, [r1] + subs r0, #1 + bgt 1b + bx lr diff --git a/loader/source/fatfs/sdmmc/sdmmc.c b/loader/source/fatfs/sdmmc/sdmmc.c index 6d128487..34b8c6d5 100644 --- a/loader/source/fatfs/sdmmc/sdmmc.c +++ b/loader/source/fatfs/sdmmc/sdmmc.c @@ -286,7 +286,7 @@ static void InitSD() static int Nand_Init() { inittarget(&handleNAND); - waitcycles(0xF000); + ioDelay(0xF000); sdmmc_send_command(&handleNAND,0,0); @@ -337,7 +337,7 @@ static int SD_Init() { inittarget(&handleSD); - waitcycles(1u << 18); //Card needs a little bit of time to be detected, it seems + ioDelay(1u << 18); //Card needs a little bit of time to be detected, it seems //If not inserted if (!(*((vu16*)0x1000601c) & TMIO_STAT0_SIGSTATE)) return -1; diff --git a/source/fatfs/sdmmc/delay.h b/source/fatfs/sdmmc/delay.h index d08c0ccc..afad4389 100644 --- a/source/fatfs/sdmmc/delay.h +++ b/source/fatfs/sdmmc/delay.h @@ -6,4 +6,4 @@ #include "common.h" -void waitcycles(u32 us); +void ioDelay(u32 us); diff --git a/source/fatfs/sdmmc/delay.s b/source/fatfs/sdmmc/delay.s index 5386fd8a..b3baccd4 100644 --- a/source/fatfs/sdmmc/delay.s +++ b/source/fatfs/sdmmc/delay.s @@ -1,10 +1,17 @@ -.arm -.global waitcycles -.type waitcycles STT_FUNC +// Copyright 2014 Normmatt +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. -@waitcycles ( u32 us ) -waitcycles: - waitcycles_loop: - subs r0, #1 - bgt waitcycles_loop - bx lr +.arm +.global ioDelay +.type ioDelay STT_FUNC + +@ioDelay ( u32 us ) +ioDelay: + ldr r1, =0x18000000 @ VRAM +1: + @ Loop doing uncached reads from VRAM to make loop timing more reliable + ldr r2, [r1] + subs r0, #1 + bgt 1b + bx lr diff --git a/source/fatfs/sdmmc/sdmmc.c b/source/fatfs/sdmmc/sdmmc.c index 6d128487..34b8c6d5 100644 --- a/source/fatfs/sdmmc/sdmmc.c +++ b/source/fatfs/sdmmc/sdmmc.c @@ -286,7 +286,7 @@ static void InitSD() static int Nand_Init() { inittarget(&handleNAND); - waitcycles(0xF000); + ioDelay(0xF000); sdmmc_send_command(&handleNAND,0,0); @@ -337,7 +337,7 @@ static int SD_Init() { inittarget(&handleSD); - waitcycles(1u << 18); //Card needs a little bit of time to be detected, it seems + ioDelay(1u << 18); //Card needs a little bit of time to be detected, it seems //If not inserted if (!(*((vu16*)0x1000601c) & TMIO_STAT0_SIGSTATE)) return -1;