Skip to content

Commit

Permalink
Switch to Normmatt's iodelay
Browse files Browse the repository at this point in the history
Seems to be more reliable in all conditions
  • Loading branch information
AuroraWright committed Mar 16, 2016
1 parent e9410c8 commit 8ce395c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion loader/source/fatfs/sdmmc/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

#include "common.h"

void waitcycles(u32 us);
void ioDelay(u32 us);
23 changes: 15 additions & 8 deletions loader/source/fatfs/sdmmc/delay.s
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// Copyright 2014 Normmatt
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

.arm
.global waitcycles
.type waitcycles STT_FUNC
.global ioDelay
.type ioDelay STT_FUNC

@waitcycles ( u32 us )
waitcycles:
waitcycles_loop:
subs r0, #1
bgt waitcycles_loop
bx lr
@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
4 changes: 2 additions & 2 deletions loader/source/fatfs/sdmmc/sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void InitSD()
static int Nand_Init()
{
inittarget(&handleNAND);
waitcycles(0xF000);
ioDelay(0xF000);

sdmmc_send_command(&handleNAND,0,0);

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/fatfs/sdmmc/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

#include "common.h"

void waitcycles(u32 us);
void ioDelay(u32 us);
23 changes: 15 additions & 8 deletions source/fatfs/sdmmc/delay.s
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// Copyright 2014 Normmatt
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

.arm
.global waitcycles
.type waitcycles STT_FUNC
.global ioDelay
.type ioDelay STT_FUNC

@waitcycles ( u32 us )
waitcycles:
waitcycles_loop:
subs r0, #1
bgt waitcycles_loop
bx lr
@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
4 changes: 2 additions & 2 deletions source/fatfs/sdmmc/sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void InitSD()
static int Nand_Init()
{
inittarget(&handleNAND);
waitcycles(0xF000);
ioDelay(0xF000);

sdmmc_send_command(&handleNAND,0,0);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ce395c

Please sign in to comment.