Equalize hekate main and Nyx sd based functions

This commit is contained in:
CTCaer
2020-06-13 18:32:40 +03:00
parent 7dd3178d48
commit 21548545fc
29 changed files with 167 additions and 103 deletions

View File

@@ -168,7 +168,7 @@ out:
int emummc_storage_end(sdmmc_storage_t *storage)
{
sd_unmount();
sd_end();
sdmmc_storage_end(storage);
return 1;

View File

@@ -23,13 +23,42 @@
#include "../mem/heap.h"
static bool sd_mounted = false;
static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
static u32 sd_mode = SD_UHS_SDR82;
sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage;
FATFS sd_fs;
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()
{
if (!sdmmc_get_sd_inserted())
return true;
return false;
}
u32 sd_get_mode()
{
return sd_mode;
@@ -85,10 +114,15 @@ bool sd_initialize(bool power_cycle)
sd_mode = SD_UHS_SDR82;
break;
}
else if (sd_mode == SD_INIT_FAIL)
break;
else
res = !sd_init_retry(true);
{
sd_errors[SD_ERROR_INIT_FAIL]++;
if (sd_mode == SD_INIT_FAIL)
break;
else
res = !sd_init_retry(true);
}
}
sdmmc_storage_end(&sd_storage);
@@ -130,9 +164,11 @@ bool sd_mount()
return false;
}
void sd_unmount()
static void _sd_deinit()
{
sd_mode = SD_UHS_SDR82;
if (sd_mode == SD_INIT_FAIL)
sd_mode = SD_UHS_SDR82;
if (sd_mounted)
{
f_mount(NULL, "", 1);
@@ -141,6 +177,9 @@ void sd_unmount()
}
}
void sd_unmount() { _sd_deinit(); }
void sd_end() { _sd_deinit(); }
void *sd_file_read(const char *path, u32 *fsize)
{
FIL fp;

View File

@@ -28,17 +28,29 @@ enum
SD_1BIT_HS25 = 1,
SD_4BIT_HS25 = 2,
SD_UHS_SDR82 = 3,
SD_UHS_SDR104 = 4
};
enum
{
SD_ERROR_INIT_FAIL = 0,
SD_ERROR_RW_FAIL = 1,
SD_ERROR_RW_RETRY = 2
};
extern sdmmc_t sd_sdmmc;
extern sdmmc_storage_t sd_storage;
extern 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);
bool sd_initialize(bool power_cycle);
bool sd_mount();
void sd_unmount();
void sd_end();
void *sd_file_read(const char *path, u32 *fsize);
int sd_save_to_file(void *buf, u32 size, const char *filename);

View File

@@ -187,6 +187,8 @@ reinit_try:
else
retries--;
sd_error_count_increment(SD_ERROR_RW_RETRY);
msleep(50);
} while (retries);
@@ -194,10 +196,17 @@ reinit_try:
if (storage->sdmmc->id == SDMMC_1)
{
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;