Add seconds timer + bugfixes

This commit is contained in:
Kostas Missos
2018-06-26 19:00:46 +03:00
parent c215b1c74c
commit 3f18713f53
13 changed files with 54 additions and 45 deletions

View File

@@ -161,20 +161,20 @@ static int _sdmmc_wait_type4(sdmmc_t *sdmmc)
sdmmc->regs->field_1B0 |= 0x80000000;
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 5000;
u32 timeout = get_tmr_us() + 5000;
while (sdmmc->regs->field_1B0 & 0x80000000)
{
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
res = 0;
goto out;
}
}
timeout = get_tmr() + 10000;
timeout = get_tmr_us() + 10000;
while (sdmmc->regs->field_1BC & 0x80000000)
{
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
res = 0;
goto out;
@@ -376,8 +376,8 @@ static void _sdmmc_reset(sdmmc_t *sdmmc)
sdmmc->regs->swrst |=
TEGRA_MMC_SWRST_SW_RESET_FOR_CMD_LINE | TEGRA_MMC_SWRST_SW_RESET_FOR_DAT_LINE;
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 2000000;
while (sdmmc->regs->swrst << 29 >> 30 && get_tmr() < timeout)
u32 timeout = get_tmr_us() + 2000000;
while (sdmmc->regs->swrst << 29 >> 30 && get_tmr_us() < timeout)
;
}
@@ -385,9 +385,9 @@ static int _sdmmc_wait_prnsts_type0(sdmmc_t *sdmmc, u32 wait_dat)
{
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 2000000;
u32 timeout = get_tmr_us() + 2000000;
while(sdmmc->regs->prnsts & 1) //CMD inhibit.
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
_sdmmc_reset(sdmmc);
return 0;
@@ -395,9 +395,9 @@ static int _sdmmc_wait_prnsts_type0(sdmmc_t *sdmmc, u32 wait_dat)
if (wait_dat)
{
timeout = get_tmr() + 2000000;
timeout = get_tmr_us() + 2000000;
while (sdmmc->regs->prnsts & 2) //DAT inhibit.
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
_sdmmc_reset(sdmmc);
return 0;
@@ -411,9 +411,9 @@ static int _sdmmc_wait_prnsts_type1(sdmmc_t *sdmmc)
{
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 2000000;
u32 timeout = get_tmr_us() + 2000000;
while (!(sdmmc->regs->prnsts & 0x100000)) //DAT0 line level.
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
_sdmmc_reset(sdmmc);
return 0;
@@ -509,8 +509,8 @@ static int _sdmmc_config_tuning_once(sdmmc_t *sdmmc, u32 cmd)
sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_SD_CLOCK_ENABLE;
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 5000;
while (get_tmr() < timeout)
u32 timeout = get_tmr_us() + 5000;
while (get_tmr_us() < timeout)
{
if (sdmmc->regs->norintsts & 0x20)
{
@@ -573,10 +573,10 @@ static int _sdmmc_enable_internal_clock(sdmmc_t *sdmmc)
//Enable internal clock and wait till it is stable.
sdmmc->regs->clkcon |= TEGRA_MMC_CLKCON_INTERNAL_CLOCK_ENABLE;
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 2000000;
u32 timeout = get_tmr_us() + 2000000;
while (!(sdmmc->regs->clkcon & TEGRA_MMC_CLKCON_INTERNAL_CLOCK_STABLE))
{
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
return 0;
}
@@ -649,10 +649,10 @@ static void _sdmmc_autocal_execute(sdmmc_t *sdmmc, u32 power)
_sdmmc_get_clkcon(sdmmc);
sleep(1);
u32 timeout = get_tmr() + 10000;
u32 timeout = get_tmr_us() + 10000;
while (sdmmc->regs->autocalcfg & 0x80000000)
{
if (get_tmr() > timeout)
if (get_tmr_us() > timeout)
{
//In case autocalibration fails, we load suggested standard values.
_sdmmc_pad_config_fallback(sdmmc, power);
@@ -710,13 +710,13 @@ static int _sdmmc_wait_request(sdmmc_t *sdmmc)
{
_sdmmc_get_clkcon(sdmmc);
u32 timeout = get_tmr() + 2000000;
u32 timeout = get_tmr_us() + 2000000;
while (1)
{
int res = _sdmmc_check_mask_interrupt(sdmmc, 0, TEGRA_MMC_NORINTSTS_CMD_COMPLETE);
if (res == SDMMC_MASKINT_MASKED)
break;
if (res != SDMMC_MASKINT_NOERROR || get_tmr() > timeout)
if (res != SDMMC_MASKINT_NOERROR || get_tmr_us() > timeout)
{
_sdmmc_reset(sdmmc);
return 0;
@@ -817,7 +817,7 @@ static int _sdmmc_update_dma(sdmmc_t *sdmmc)
do
{
blkcnt = sdmmc->regs->blkcnt;
u32 timeout = get_tmr() + 1500000;
u32 timeout = get_tmr_us() + 1500000;
do
{
int res = 0;
@@ -843,7 +843,7 @@ static int _sdmmc_update_dma(sdmmc_t *sdmmc)
_sdmmc_reset(sdmmc);
return 0;
}
} while (get_tmr() < timeout);
} while (get_tmr_us() < timeout);
} while (sdmmc->regs->blkcnt != blkcnt);
_sdmmc_reset(sdmmc);