use enum for drive numbers
This commit is contained in:
@@ -10,6 +10,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <utils/types.h>
|
||||
#include <fatfs_cfg.h>
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
@@ -23,14 +24,6 @@ typedef enum {
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
typedef enum {
|
||||
DRIVE_SD = 0,
|
||||
DRIVE_RAM = 1,
|
||||
DRIVE_EMMC = 2,
|
||||
DRIVE_BIS = 3,
|
||||
DRIVE_EMU = 4
|
||||
} DDRIVE;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
#include <bdk.h>
|
||||
|
||||
#include <libs/fatfs/diskio.h> /* FatFs lower layer API */
|
||||
#include "ffconf.h"
|
||||
#include <fatfs_cfg.h>
|
||||
|
||||
static bool ensure_partition(BYTE pdrv){
|
||||
u8 part;
|
||||
switch(pdrv){
|
||||
case FF_DEV_SD:
|
||||
case DRIVE_SD:
|
||||
return true;
|
||||
case FF_DEV_BOOT1:
|
||||
case FF_DEV_BOOT1_1MB:
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
part = EMMC_BOOT1;
|
||||
break;
|
||||
case FF_DEV_GPP:
|
||||
case DRIVE_EMMC:
|
||||
part = EMMC_GPP;
|
||||
break;
|
||||
default:
|
||||
@@ -72,13 +72,13 @@ DRESULT disk_read (
|
||||
sdmmc_storage_t *storage = &sd_storage;
|
||||
u32 actual_sector = sector;
|
||||
switch(pdrv){
|
||||
case FF_DEV_SD:
|
||||
case DRIVE_SD:
|
||||
break;
|
||||
case FF_DEV_BOOT1:
|
||||
case FF_DEV_GPP:
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
storage = &emmc_storage;
|
||||
break;
|
||||
case FF_DEV_BOOT1_1MB:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
storage = &emmc_storage;
|
||||
actual_sector = sector + (0x100000 / 512);
|
||||
break;
|
||||
@@ -105,13 +105,13 @@ DRESULT disk_write (
|
||||
sdmmc_storage_t *storage = &sd_storage;
|
||||
u32 actual_sector = sector;
|
||||
switch(pdrv){
|
||||
case FF_DEV_SD:
|
||||
case DRIVE_SD:
|
||||
break;
|
||||
case FF_DEV_BOOT1:
|
||||
case FF_DEV_GPP:
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
storage = &emmc_storage;
|
||||
break;
|
||||
case FF_DEV_BOOT1_1MB:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
storage = &emmc_storage;
|
||||
actual_sector = sector + (0x100000 / 512);
|
||||
break;
|
||||
|
||||
@@ -300,9 +300,12 @@
|
||||
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
#define FF_DEV_BOOT1 1
|
||||
#define FF_DEV_BOOT1_1MB 2
|
||||
#define FF_DEV_SD 0
|
||||
#define FF_DEV_GPP 3
|
||||
|
||||
typedef enum {
|
||||
DRIVE_SD = 0,
|
||||
DRIVE_BOOT1 = 1,
|
||||
DRIVE_BOOT1_1MB = 2,
|
||||
DRIVE_EMMC = 3,
|
||||
} DDRIVE;
|
||||
|
||||
/*--- End of configuration options ---*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "boot_storage.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../libs/fatfs/ffconf.h"
|
||||
#include <fatfs_cfg.h>
|
||||
#include <storage/sd.h>
|
||||
#include <storage/emmc.h>
|
||||
#include <utils/types.h>
|
||||
@@ -11,10 +11,10 @@ static FATFS boot_storage_fs;
|
||||
static BYTE drive = -1;
|
||||
|
||||
static const char* drive_base_paths[] = {
|
||||
[FF_DEV_SD] = XSTR(FF_DEV_SD) ":",
|
||||
[FF_DEV_BOOT1] = XSTR(FF_DEV_BOOT1) ":",
|
||||
[FF_DEV_BOOT1_1MB] = XSTR(FF_DEV_BOOT1_1MB) ":",
|
||||
[FF_DEV_GPP] = XSTR(FF_DEV_GPP) ":",
|
||||
[DRIVE_SD] = XSTR(DRIVE_SD) ":",
|
||||
[DRIVE_BOOT1] = XSTR(DRIVE_BOOT1) ":",
|
||||
[DRIVE_BOOT1_1MB] = XSTR(DRIVE_BOOT1_1MB) ":",
|
||||
[DRIVE_EMMC] = XSTR(DRIVE_EMMC) ":",
|
||||
};
|
||||
|
||||
static bool _is_eligible(){
|
||||
@@ -30,11 +30,11 @@ bool boot_storage_get_mounted(){
|
||||
|
||||
bool boot_storage_get_initialized(){
|
||||
switch(drive){
|
||||
case FF_DEV_BOOT1:
|
||||
case FF_DEV_GPP:
|
||||
case FF_DEV_BOOT1_1MB:
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
return emmc_get_initialized();
|
||||
case FF_DEV_SD:
|
||||
case DRIVE_SD:
|
||||
return sd_get_card_initialized();
|
||||
}
|
||||
return false;
|
||||
@@ -42,11 +42,11 @@ bool boot_storage_get_initialized(){
|
||||
|
||||
static bool _boot_storage_initialize(){
|
||||
switch(drive){
|
||||
case FF_DEV_BOOT1:
|
||||
case FF_DEV_GPP:
|
||||
case FF_DEV_BOOT1_1MB:
|
||||
case DRIVE_BOOT1:
|
||||
case DRIVE_EMMC:
|
||||
case DRIVE_BOOT1_1MB:
|
||||
return emmc_initialize(false);
|
||||
case FF_DEV_SD:
|
||||
case DRIVE_SD:
|
||||
return sd_initialize(false);
|
||||
}
|
||||
return false;
|
||||
@@ -54,7 +54,7 @@ static bool _boot_storage_initialize(){
|
||||
|
||||
static void _boot_storage_end(bool deinit){
|
||||
if(boot_storage_get_mounted()){
|
||||
if(drive == FF_DEV_SD){
|
||||
if(drive == DRIVE_SD){
|
||||
sd_unmount();
|
||||
}else{
|
||||
f_mount(NULL, drive_base_paths[drive], false);
|
||||
@@ -62,7 +62,7 @@ static void _boot_storage_end(bool deinit){
|
||||
drive = DEV_INVALID;
|
||||
}
|
||||
if(deinit){
|
||||
if(drive == FF_DEV_SD){
|
||||
if(drive == DRIVE_SD){
|
||||
sd_end();
|
||||
}else{
|
||||
emmc_end();
|
||||
@@ -87,7 +87,7 @@ static bool _boot_storage_mount(){
|
||||
goto emmc_init_fail;
|
||||
}
|
||||
|
||||
static const BYTE emmc_drives[] = {FF_DEV_BOOT1_1MB, FF_DEV_BOOT1, FF_DEV_GPP};
|
||||
static const BYTE emmc_drives[] = {DRIVE_BOOT1_1MB, DRIVE_BOOT1, DRIVE_EMMC};
|
||||
|
||||
for(BYTE i = 0; i < ARRAY_SIZE(emmc_drives); i++){
|
||||
res = f_mount(&boot_storage_fs, drive_base_paths[i], true);
|
||||
@@ -121,10 +121,10 @@ emmc_init_fail:
|
||||
goto out;
|
||||
}
|
||||
|
||||
res = f_chdrive(drive_base_paths[FF_DEV_SD]);
|
||||
res = f_chdrive(drive_base_paths[DRIVE_SD]);
|
||||
|
||||
if(res == FR_OK && _is_eligible()){
|
||||
drive = FF_DEV_SD;
|
||||
drive = DRIVE_SD;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user