nyx: Add SD Card error report in Console Info

This commit is contained in:
CTCaer
2020-04-30 01:09:48 +03:00
parent 96654d9620
commit 67ae7b9dcb
4 changed files with 72 additions and 0 deletions

View File

@@ -24,6 +24,29 @@
static bool sd_mounted = false;
static bool sd_init_done = false;
static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
static u32 sd_mode = SD_UHS_SDR104;
void sd_error_count_increment(u8 type)
{
switch (type)
{
case SD_ERROR_INIT_FAIL:
sd_errors[0]++;
break;
case SD_ERROR_RW_FAIL:
sd_errors[1]++;
break;
case SD_ERROR_RW_RETRY:
sd_errors[2]++;
break;
}
}
u16 *sd_get_error_count()
{
return sd_errors;
}
bool sd_get_card_removed()
{
@@ -93,6 +116,8 @@ bool sd_initialize(bool power_cycle)
}
else
{
sd_errors[0]++; // Increment init errors.
if (sd_mode == SD_INIT_FAIL)
break;
else

View File

@@ -31,10 +31,19 @@ enum
SD_UHS_SDR104 = 4
};
enum
{
SD_ERROR_INIT_FAIL = 0,
SD_ERROR_RW_FAIL = 1,
SD_ERROR_RW_RETRY = 2
};
sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage;
FATFS sd_fs;
void sd_error_count_increment(u8 type);
u16 *sd_get_error_count();
bool sd_get_card_removed();
u32 sd_get_mode();
int sd_init_retry(bool power_cycle);

View File

@@ -187,6 +187,8 @@ reinit_try:
else
retries--;
sd_error_count_increment(SD_ERROR_RW_RETRY);
msleep(50);
} while (retries);
@@ -195,10 +197,16 @@ reinit_try:
{
int res;
sd_error_count_increment(SD_ERROR_RW_FAIL);
if (!first_reinit)
res = sd_initialize(true);
else
{
res = sd_init_retry(true);
if (!res)
sd_error_count_increment(SD_ERROR_INIT_FAIL);
}
retries = 3;
first_reinit = true;