mirror of
https://github.com/wiiu-env/libfat.git
synced 2024-11-22 09:59:18 +01:00
Changed all IO_INTERFACEs to const. M3SD and SCSD drivers no longer delay card detection when it is not inserted.
This commit is contained in:
parent
58996ae0d2
commit
eb2b6d1e20
@ -87,7 +87,7 @@ bool fatMountNormalInterface (PARTITION_INTERFACE partitionNumber, u32 cacheSize
|
|||||||
/*
|
/*
|
||||||
Mount a partition on a custom device
|
Mount a partition on a custom device
|
||||||
*/
|
*/
|
||||||
bool fatMountCustomInterface (struct IO_INTERFACE_STRUCT* device, u32 cacheSize);
|
bool fatMountCustomInterface (const struct IO_INTERFACE_STRUCT* device, u32 cacheSize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Unmount the partition specified by partitionNumber
|
Unmount the partition specified by partitionNumber
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
#define CACHE_FREE 0xFFFFFFFF
|
#define CACHE_FREE 0xFFFFFFFF
|
||||||
|
|
||||||
CACHE* _FAT_cache_constructor (u32 numberOfPages, IO_INTERFACE* discInterface) {
|
CACHE* _FAT_cache_constructor (u32 numberOfPages, const IO_INTERFACE* discInterface) {
|
||||||
CACHE* cache;
|
CACHE* cache;
|
||||||
u32 i;
|
u32 i;
|
||||||
CACHE_ENTRY* cacheEntries;
|
CACHE_ENTRY* cacheEntries;
|
||||||
|
@ -51,7 +51,7 @@ typedef struct {
|
|||||||
} CACHE_ENTRY;
|
} CACHE_ENTRY;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IO_INTERFACE* disc;
|
const IO_INTERFACE* disc;
|
||||||
u32 numberOfPages;
|
u32 numberOfPages;
|
||||||
CACHE_ENTRY* cacheEntries;
|
CACHE_ENTRY* cacheEntries;
|
||||||
u8* pages;
|
u8* pages;
|
||||||
@ -111,7 +111,7 @@ Clear out the contents of the cache without writing any dirty sectors first
|
|||||||
*/
|
*/
|
||||||
void _FAT_cache_invalidate (CACHE* cache);
|
void _FAT_cache_invalidate (CACHE* cache);
|
||||||
|
|
||||||
CACHE* _FAT_cache_constructor (u32 numberOfPages, IO_INTERFACE* discInterface);
|
CACHE* _FAT_cache_constructor (u32 numberOfPages, const IO_INTERFACE* discInterface);
|
||||||
|
|
||||||
void _FAT_cache_destructor (CACHE* cache);
|
void _FAT_cache_destructor (CACHE* cache);
|
||||||
|
|
||||||
|
@ -58,8 +58,9 @@
|
|||||||
* Removed SUPPORT_* defines
|
* Removed SUPPORT_* defines
|
||||||
* Rewrote device detection functions
|
* Rewrote device detection functions
|
||||||
* First libfat release
|
* First libfat release
|
||||||
|
|
||||||
|
2006-07-25 - Chishm
|
||||||
|
* Changed IO_INTERFACEs to const
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "disc.h"
|
#include "disc.h"
|
||||||
@ -81,7 +82,7 @@
|
|||||||
#include "io_efa2.h"
|
#include "io_efa2.h"
|
||||||
#include "io_mmcf.h"
|
#include "io_mmcf.h"
|
||||||
|
|
||||||
IO_INTERFACE* ioInterfaces[] = {
|
const IO_INTERFACE* ioInterfaces[] = {
|
||||||
#ifdef NDS
|
#ifdef NDS
|
||||||
// Place Slot 1 (DS Card) interfaces here
|
// Place Slot 1 (DS Card) interfaces here
|
||||||
&_io_nmmc,
|
&_io_nmmc,
|
||||||
@ -98,7 +99,7 @@ IO_INTERFACE* ioInterfaces[] = {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void)
|
const IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void)
|
||||||
{
|
{
|
||||||
// If running on an NDS, make sure the correct CPU can access
|
// If running on an NDS, make sure the correct CPU can access
|
||||||
// the GBA cart. First implemented by SaTa.
|
// the GBA cart. First implemented by SaTa.
|
||||||
@ -128,7 +129,7 @@ IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void)
|
|||||||
* and it returns true. Otherwise the default interface is left
|
* and it returns true. Otherwise the default interface is left
|
||||||
* untouched and it returns false.
|
* untouched and it returns false.
|
||||||
*/
|
*/
|
||||||
IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void)
|
const IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void)
|
||||||
{
|
{
|
||||||
#ifdef ARM9
|
#ifdef ARM9
|
||||||
WAIT_CR &= ~ARM9_OWNS_CARD;
|
WAIT_CR &= ~ARM9_OWNS_CARD;
|
||||||
@ -157,7 +158,7 @@ IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void)
|
|||||||
* untouched and it returns false.
|
* untouched and it returns false.
|
||||||
*/
|
*/
|
||||||
#ifdef NDS
|
#ifdef NDS
|
||||||
IO_INTERFACE* _FAT_disc_findInterface (void)
|
const IO_INTERFACE* _FAT_disc_findInterface (void)
|
||||||
{
|
{
|
||||||
#ifdef ARM9
|
#ifdef ARM9
|
||||||
WAIT_CR &= ~(ARM9_OWNS_CARD | ARM9_OWNS_ROM);
|
WAIT_CR &= ~(ARM9_OWNS_CARD | ARM9_OWNS_ROM);
|
||||||
@ -177,7 +178,7 @@ IO_INTERFACE* _FAT_disc_findInterface (void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
IO_INTERFACE* _FAT_disc_findInterface (void)
|
const IO_INTERFACE* _FAT_disc_findInterface (void)
|
||||||
{
|
{
|
||||||
return _FAT_disc_gbaSlotFindInterface();
|
return _FAT_disc_gbaSlotFindInterface();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ Search for a block based device in the GBA slot.
|
|||||||
Return a pointer to a usable interface if one is found,
|
Return a pointer to a usable interface if one is found,
|
||||||
NULL if not.
|
NULL if not.
|
||||||
*/
|
*/
|
||||||
extern IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void);
|
extern const IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Search for a block based device in the DS slot.
|
Search for a block based device in the DS slot.
|
||||||
@ -49,7 +49,7 @@ Return a pointer to a usable interface if one is found,
|
|||||||
NULL if not.
|
NULL if not.
|
||||||
*/
|
*/
|
||||||
#ifdef NDS
|
#ifdef NDS
|
||||||
extern IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void);
|
extern const IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -57,13 +57,13 @@ Search for a block based device in the both slots.
|
|||||||
Return a pointer to a usable interface if one is found,
|
Return a pointer to a usable interface if one is found,
|
||||||
NULL if not.
|
NULL if not.
|
||||||
*/
|
*/
|
||||||
extern IO_INTERFACE* _FAT_disc_findInterface (void);
|
extern const IO_INTERFACE* _FAT_disc_findInterface (void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if a disc is inserted
|
Check if a disc is inserted
|
||||||
Return true if a disc is inserted and ready, false otherwise
|
Return true if a disc is inserted and ready, false otherwise
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_isInserted (IO_INTERFACE* disc) {
|
static inline bool _FAT_disc_isInserted (const IO_INTERFACE* disc) {
|
||||||
return disc->fn_isInserted();
|
return disc->fn_isInserted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ numSectors is between 1 and 256
|
|||||||
sector is from 0 to 2^28
|
sector is from 0 to 2^28
|
||||||
buffer is a pointer to the memory to fill
|
buffer is a pointer to the memory to fill
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_readSectors (IO_INTERFACE* disc, u32 sector, u32 numSectors, void* buffer) {
|
static inline bool _FAT_disc_readSectors (const IO_INTERFACE* disc, u32 sector, u32 numSectors, void* buffer) {
|
||||||
return disc->fn_readSectors (sector, numSectors, buffer);
|
return disc->fn_readSectors (sector, numSectors, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,21 +83,21 @@ numSectors is between 1 and 256
|
|||||||
sector is from 0 to 2^28
|
sector is from 0 to 2^28
|
||||||
buffer is a pointer to the memory to read from
|
buffer is a pointer to the memory to read from
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_writeSectors (IO_INTERFACE* disc, u32 sector, u32 numSectors, const void* buffer) {
|
static inline bool _FAT_disc_writeSectors (const IO_INTERFACE* disc, u32 sector, u32 numSectors, const void* buffer) {
|
||||||
return disc->fn_writeSectors (sector, numSectors, buffer);
|
return disc->fn_writeSectors (sector, numSectors, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Reset the card back to a ready state
|
Reset the card back to a ready state
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_clearStatus (IO_INTERFACE* disc) {
|
static inline bool _FAT_disc_clearStatus (const IO_INTERFACE* disc) {
|
||||||
return disc->fn_clearStatus();
|
return disc->fn_clearStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initialise the disc to a state ready for data reading or writing
|
Initialise the disc to a state ready for data reading or writing
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_startup (IO_INTERFACE* disc) {
|
static inline bool _FAT_disc_startup (const IO_INTERFACE* disc) {
|
||||||
return disc->fn_startup();
|
return disc->fn_startup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,21 +105,21 @@ static inline bool _FAT_disc_startup (IO_INTERFACE* disc) {
|
|||||||
Put the disc in a state ready for power down.
|
Put the disc in a state ready for power down.
|
||||||
Complete any pending writes and disable the disc if necessary
|
Complete any pending writes and disable the disc if necessary
|
||||||
*/
|
*/
|
||||||
static inline bool _FAT_disc_shutdown (IO_INTERFACE* disc) {
|
static inline bool _FAT_disc_shutdown (const IO_INTERFACE* disc) {
|
||||||
return disc->fn_shutdown();
|
return disc->fn_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return a 32 bit value unique to each type of interface
|
Return a 32 bit value unique to each type of interface
|
||||||
*/
|
*/
|
||||||
static inline u32 _FAT_disc_hostType (IO_INTERFACE* disc) {
|
static inline u32 _FAT_disc_hostType (const IO_INTERFACE* disc) {
|
||||||
return disc->ioType;
|
return disc->ioType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return a 32 bit value that specifies the capabilities of the disc
|
Return a 32 bit value that specifies the capabilities of the disc
|
||||||
*/
|
*/
|
||||||
static inline u32 _FAT_disc_features (IO_INTERFACE* disc) {
|
static inline u32 _FAT_disc_features (const IO_INTERFACE* disc) {
|
||||||
return disc->features;
|
return disc->features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ bool _EFA2_startUp(void)
|
|||||||
/*-----------------------------------------------------------------
|
/*-----------------------------------------------------------------
|
||||||
the actual interface structure
|
the actual interface structure
|
||||||
-----------------------------------------------------------------*/
|
-----------------------------------------------------------------*/
|
||||||
IO_INTERFACE _io_efa2 = {
|
const IO_INTERFACE _io_efa2 = {
|
||||||
DEVICE_TYPE_EFA2,
|
DEVICE_TYPE_EFA2,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_EFA2_startUp,
|
(FN_MEDIUM_STARTUP)&_EFA2_startUp,
|
||||||
|
@ -18,6 +18,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_efa2;
|
extern const IO_INTERFACE _io_efa2;
|
||||||
|
|
||||||
#endif // define IO_EFA2_H
|
#endif // define IO_EFA2_H
|
||||||
|
@ -322,7 +322,7 @@ bool _FCSR_startUp(void)
|
|||||||
/*-----------------------------------------------------------------
|
/*-----------------------------------------------------------------
|
||||||
the actual interface structure
|
the actual interface structure
|
||||||
-----------------------------------------------------------------*/
|
-----------------------------------------------------------------*/
|
||||||
IO_INTERFACE _io_fcsr = {
|
const IO_INTERFACE _io_fcsr = {
|
||||||
DEVICE_TYPE_FCSR, // 'FCSR'
|
DEVICE_TYPE_FCSR, // 'FCSR'
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_FCSR_startUp,
|
(FN_MEDIUM_STARTUP)&_FCSR_startUp,
|
||||||
|
@ -39,6 +39,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_fcsr ;
|
extern const IO_INTERFACE _io_fcsr ;
|
||||||
|
|
||||||
#endif // define IO_FCSR_H
|
#endif // define IO_FCSR_H
|
||||||
|
@ -84,7 +84,7 @@ bool _M3CF_startup(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IO_INTERFACE _io_m3cf = {
|
const IO_INTERFACE _io_m3cf = {
|
||||||
DEVICE_TYPE_M3CF,
|
DEVICE_TYPE_M3CF,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_M3CF_startup,
|
(FN_MEDIUM_STARTUP)&_M3CF_startup,
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_m3cf ;
|
extern const IO_INTERFACE _io_m3cf ;
|
||||||
|
|
||||||
#endif // define IO_M3CF_H
|
#endif // define IO_M3CF_H
|
||||||
|
@ -29,6 +29,12 @@
|
|||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
2006-07-25 - Chishm
|
||||||
|
* Improved startup function that doesn't delay hundreds of seconds
|
||||||
|
before reporting no card inserted.
|
||||||
|
* Fixed writeData function to timeout on error
|
||||||
|
* writeSectors function now wait until the card is ready before continuing with a transfer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "io_m3sd.h"
|
#include "io_m3sd.h"
|
||||||
@ -47,10 +53,11 @@
|
|||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Send / receive timeouts, to stop infinite wait loops
|
// Send / receive timeouts, to stop infinite wait loops
|
||||||
#define MAX_STARTUP_TRIES 10 // Arbitrary value, check if the card is ready 10 times before giving up
|
#define MAX_STARTUP_TRIES 20 // Arbitrary value, check if the card is ready 20 times before giving up
|
||||||
#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
|
#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
|
||||||
#define TRANSMIT_TIMEOUT 2000 // Time to wait for the M3 to respond to transmit or receive requests
|
#define TRANSMIT_TIMEOUT 2000 // Time to wait for the M3 to respond to transmit or receive requests
|
||||||
#define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up
|
#define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up
|
||||||
|
#define WRITE_TIMEOUT 300 // Time to wait for the card to finish writing
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Variables required for tracking SD state
|
// Variables required for tracking SD state
|
||||||
@ -245,7 +252,9 @@ static bool _M3SD_initCard (void) {
|
|||||||
|
|
||||||
for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
|
for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
|
||||||
_M3SD_sendCommand (APP_CMD, 0);
|
_M3SD_sendCommand (APP_CMD, 0);
|
||||||
_M3SD_getResponse_R1 (responseBuffer);
|
if (!_M3SD_getResponse_R1 (responseBuffer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_M3SD_sendCommand (SD_APP_OP_COND, 3<<16);
|
_M3SD_sendCommand (SD_APP_OP_COND, 3<<16);
|
||||||
if ((_M3SD_getResponse_R3 (responseBuffer)) && ((responseBuffer[1] & 0x80) != 0)) {
|
if ((_M3SD_getResponse_R3 (responseBuffer)) && ((responseBuffer[1] & 0x80) != 0)) {
|
||||||
@ -372,9 +381,9 @@ static bool _M3SD_writeData (u8* data, u8* crc) {
|
|||||||
int i;
|
int i;
|
||||||
u8 temp;
|
u8 temp;
|
||||||
|
|
||||||
_M3SD_clkin();
|
do {
|
||||||
|
_M3SD_clkin();
|
||||||
while ((REG_M3SD_DAT & 0x100) == 0);
|
} while ((REG_M3SD_DAT & 0x100) == 0);
|
||||||
|
|
||||||
REG_M3SD_DAT = 0; // Start bit
|
REG_M3SD_DAT = 0; // Start bit
|
||||||
|
|
||||||
@ -472,7 +481,7 @@ bool _M3SD_readSectors (u32 sector, u32 numSectors, void* buffer) {
|
|||||||
_M3SD_sendCommand (STOP_TRANSMISSION, 0);
|
_M3SD_sendCommand (STOP_TRANSMISSION, 0);
|
||||||
_M3SD_getResponse_R1b (responseBuffer);
|
_M3SD_getResponse_R1b (responseBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,8 +490,12 @@ bool _M3SD_writeSectors (u32 sector, u32 numSectors, const void* buffer) {
|
|||||||
u8 responseBuffer[6];
|
u8 responseBuffer[6];
|
||||||
u32 offset = sector * BYTES_PER_READ;
|
u32 offset = sector * BYTES_PER_READ;
|
||||||
u8* data = (u8*) buffer;
|
u8* data = (u8*) buffer;
|
||||||
|
int i;
|
||||||
|
// Precalculate the data CRC
|
||||||
|
_SD_CRC16 ( data, BYTES_PER_READ, crc);
|
||||||
|
|
||||||
while (numSectors--) {
|
while (numSectors--) {
|
||||||
|
// Send a single sector write command
|
||||||
_M3SD_sendCommand (WRITE_BLOCK, offset);
|
_M3SD_sendCommand (WRITE_BLOCK, offset);
|
||||||
if (!_M3SD_getResponse_R1 (responseBuffer)) {
|
if (!_M3SD_getResponse_R1 (responseBuffer)) {
|
||||||
return false;
|
return false;
|
||||||
@ -491,12 +504,29 @@ bool _M3SD_writeSectors (u32 sector, u32 numSectors, const void* buffer) {
|
|||||||
REG_M3SD_DIR = 0x4;
|
REG_M3SD_DIR = 0x4;
|
||||||
REG_M3SD_STS = 0x0;
|
REG_M3SD_STS = 0x0;
|
||||||
|
|
||||||
_SD_CRC16 ( data, BYTES_PER_READ, crc);
|
// Send the data
|
||||||
if (! _M3SD_writeData( data, crc)) {
|
if (! _M3SD_writeData( data, crc)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
offset += BYTES_PER_READ;
|
|
||||||
data += BYTES_PER_READ;
|
if (numSectors > 0) {
|
||||||
|
offset += BYTES_PER_READ;
|
||||||
|
data += BYTES_PER_READ;
|
||||||
|
// Calculate the next CRC while waiting for the card to finish writing
|
||||||
|
_SD_CRC16 ( data, BYTES_PER_READ, crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the card to be ready for the next transfer
|
||||||
|
i = WRITE_TIMEOUT;
|
||||||
|
responseBuffer[3] = 0;
|
||||||
|
do {
|
||||||
|
_M3SD_sendCommand (SEND_STATUS, _M3SD_relativeCardAddress);
|
||||||
|
_M3SD_getResponse_R1 (responseBuffer);
|
||||||
|
i--;
|
||||||
|
if (i <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} while (((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -512,7 +542,7 @@ bool _M3SD_shutdown (void) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IO_INTERFACE _io_m3sd = {
|
const IO_INTERFACE _io_m3sd = {
|
||||||
DEVICE_TYPE_M3SD,
|
DEVICE_TYPE_M3SD,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_M3SD_startUp,
|
(FN_MEDIUM_STARTUP)&_M3SD_startUp,
|
||||||
|
@ -43,6 +43,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_m3sd ;
|
extern const IO_INTERFACE _io_m3sd ;
|
||||||
|
|
||||||
#endif // define IO_M3SD_H
|
#endif // define IO_M3SD_H
|
||||||
|
@ -89,7 +89,7 @@ bool _MMCF_startup(void) {
|
|||||||
/*-----------------------------------------------------------------
|
/*-----------------------------------------------------------------
|
||||||
the actual interface structure
|
the actual interface structure
|
||||||
-----------------------------------------------------------------*/
|
-----------------------------------------------------------------*/
|
||||||
IO_INTERFACE _io_mmcf = {
|
const IO_INTERFACE _io_mmcf = {
|
||||||
DEVICE_TYPE_MMCF,
|
DEVICE_TYPE_MMCF,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_MMCF_startup,
|
(FN_MEDIUM_STARTUP)&_MMCF_startup,
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_mmcf ;
|
extern const IO_INTERFACE _io_mmcf ;
|
||||||
|
|
||||||
#endif // define IO_MMCF_H
|
#endif // define IO_MMCF_H
|
||||||
|
@ -88,7 +88,7 @@ bool _MPCF_startup(void) {
|
|||||||
/*-----------------------------------------------------------------
|
/*-----------------------------------------------------------------
|
||||||
the actual interface structure
|
the actual interface structure
|
||||||
-----------------------------------------------------------------*/
|
-----------------------------------------------------------------*/
|
||||||
IO_INTERFACE _io_mpcf = {
|
const IO_INTERFACE _io_mpcf = {
|
||||||
DEVICE_TYPE_MPCF,
|
DEVICE_TYPE_MPCF,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_MPCF_startup,
|
(FN_MEDIUM_STARTUP)&_MPCF_startup,
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_mpcf ;
|
extern const IO_INTERFACE _io_mpcf ;
|
||||||
|
|
||||||
#endif // define IO_MPCF_H
|
#endif // define IO_MPCF_H
|
||||||
|
@ -334,7 +334,7 @@ bool _NMMC_readSectors (u32 sector, u32 totalSecs, void* buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IO_INTERFACE _io_nmmc = {
|
const IO_INTERFACE _io_nmmc = {
|
||||||
DEVICE_TYPE_NMMC,
|
DEVICE_TYPE_NMMC,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_NDS,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_NDS,
|
||||||
(FN_MEDIUM_STARTUP)&_NMMC_startUp,
|
(FN_MEDIUM_STARTUP)&_NMMC_startUp,
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_nmmc;
|
extern const IO_INTERFACE _io_nmmc;
|
||||||
|
|
||||||
#endif // defined NDS
|
#endif // defined NDS
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ bool _SCCF_startup(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IO_INTERFACE _io_sccf = {
|
const IO_INTERFACE _io_sccf = {
|
||||||
DEVICE_TYPE_SCCF,
|
DEVICE_TYPE_SCCF,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_SCCF_startup,
|
(FN_MEDIUM_STARTUP)&_SCCF_startup,
|
||||||
|
@ -40,6 +40,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_sccf;
|
extern const IO_INTERFACE _io_sccf;
|
||||||
|
|
||||||
#endif // define IO_SCCF_H
|
#endif // define IO_SCCF_H
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
2006-07-22 - Chishm
|
2006-07-22 - Chishm
|
||||||
* First release of stable code
|
* First release of stable code
|
||||||
|
|
||||||
|
2006-07-25 - Chishm
|
||||||
|
* Improved startup function that doesn't delay hundreds of seconds
|
||||||
|
before reporting no card inserted.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "io_scsd.h"
|
#include "io_scsd.h"
|
||||||
@ -59,12 +63,12 @@
|
|||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Send / receive timeouts, to stop infinite wait loops
|
// Send / receive timeouts, to stop infinite wait loops
|
||||||
#define MAX_STARTUP_TRIES 100 // Arbitrary value, check if the card is ready 100 times before giving up
|
#define MAX_STARTUP_TRIES 20 // Arbitrary value, check if the card is ready 20 times before giving up
|
||||||
#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
|
#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
|
||||||
#define TRANSMIT_TIMEOUT 10000 // Time to wait for the SC to respond to transmit or receive requests
|
#define TRANSMIT_TIMEOUT 10000 // Time to wait for the SC to respond to transmit or receive requests
|
||||||
#define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up
|
#define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up
|
||||||
#define BUSY_WAIT_TIMEOUT 500000
|
#define BUSY_WAIT_TIMEOUT 500000
|
||||||
#define WRITE_TIMEOUT 10000 // Time to wait for the card to finish writing
|
#define WRITE_TIMEOUT 300 // Time to wait for the card to finish writing
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Variables required for tracking SD state
|
// Variables required for tracking SD state
|
||||||
static u32 _SCSD_relativeCardAddress = 0; // Preshifted Relative Card Address
|
static u32 _SCSD_relativeCardAddress = 0; // Preshifted Relative Card Address
|
||||||
@ -200,7 +204,9 @@ static bool _SCSD_initCard (void) {
|
|||||||
|
|
||||||
for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
|
for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
|
||||||
_SCSD_sendCommand (APP_CMD, 0);
|
_SCSD_sendCommand (APP_CMD, 0);
|
||||||
_SCSD_getResponse_R1 (responseBuffer);
|
if (!_SCSD_getResponse_R1 (responseBuffer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_SCSD_sendCommand (SD_APP_OP_COND, 3<<16);
|
_SCSD_sendCommand (SD_APP_OP_COND, 3<<16);
|
||||||
if ((_SCSD_getResponse_R3 (responseBuffer)) && ((responseBuffer[1] & 0x80) != 0)) {
|
if ((_SCSD_getResponse_R3 (responseBuffer)) && ((responseBuffer[1] & 0x80) != 0)) {
|
||||||
@ -406,7 +412,7 @@ bool _SCSD_shutdown (void) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IO_INTERFACE _io_scsd = {
|
const IO_INTERFACE _io_scsd = {
|
||||||
DEVICE_TYPE_SCSD,
|
DEVICE_TYPE_SCSD,
|
||||||
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
|
||||||
(FN_MEDIUM_STARTUP)&_SCSD_startUp,
|
(FN_MEDIUM_STARTUP)&_SCSD_startUp,
|
||||||
|
@ -43,6 +43,6 @@
|
|||||||
#include "disc_io.h"
|
#include "disc_io.h"
|
||||||
|
|
||||||
// export interface
|
// export interface
|
||||||
extern IO_INTERFACE _io_scsd ;
|
extern const IO_INTERFACE _io_scsd ;
|
||||||
|
|
||||||
#endif // define IO_SCSD_H
|
#endif // define IO_SCSD_H
|
||||||
|
@ -105,7 +105,7 @@ bool fatMountNormalInterface (PARTITION_INTERFACE partitionNumber, u32 cacheSize
|
|||||||
return _FAT_partition_mount (partitionNumber, cacheSize);
|
return _FAT_partition_mount (partitionNumber, cacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fatMountCustomInterface (IO_INTERFACE* device, u32 cacheSize) {
|
bool fatMountCustomInterface (const IO_INTERFACE* device, u32 cacheSize) {
|
||||||
return _FAT_partition_mountCustomInterface (device, cacheSize);
|
return _FAT_partition_mountCustomInterface (device, cacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ PARTITION* _partitions[MAXIMUM_PARTITIONS] = {NULL};
|
|||||||
// Use a single static buffer for the partitions
|
// Use a single static buffer for the partitions
|
||||||
|
|
||||||
|
|
||||||
static PARTITION* _FAT_partition_constructor ( IO_INTERFACE* disc, u32 cacheSize) {
|
static PARTITION* _FAT_partition_constructor ( const IO_INTERFACE* disc, u32 cacheSize) {
|
||||||
PARTITION* partition;
|
PARTITION* partition;
|
||||||
int i;
|
int i;
|
||||||
u32 bootSector;
|
u32 bootSector;
|
||||||
@ -231,7 +231,7 @@ static void _FAT_partition_destructor (PARTITION* partition) {
|
|||||||
bool _FAT_partition_mount (PARTITION_INTERFACE partitionNumber, u32 cacheSize) {
|
bool _FAT_partition_mount (PARTITION_INTERFACE partitionNumber, u32 cacheSize) {
|
||||||
#ifdef NDS
|
#ifdef NDS
|
||||||
int i;
|
int i;
|
||||||
IO_INTERFACE* disc = NULL;
|
const IO_INTERFACE* disc = NULL;
|
||||||
|
|
||||||
if (_partitions[partitionNumber] != NULL) {
|
if (_partitions[partitionNumber] != NULL) {
|
||||||
return false;
|
return false;
|
||||||
@ -273,7 +273,7 @@ bool _FAT_partition_mount (PARTITION_INTERFACE partitionNumber, u32 cacheSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else // not defined NDS
|
#else // not defined NDS
|
||||||
IO_INTERFACE* disc = NULL;
|
const IO_INTERFACE* disc = NULL;
|
||||||
|
|
||||||
if (_partitions[partitionNumber] != NULL) {
|
if (_partitions[partitionNumber] != NULL) {
|
||||||
return false;
|
return false;
|
||||||
@ -288,7 +288,7 @@ bool _FAT_partition_mount (PARTITION_INTERFACE partitionNumber, u32 cacheSize) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _FAT_partition_mountCustomInterface (IO_INTERFACE* device, u32 cacheSize) {
|
bool _FAT_partition_mountCustomInterface (const IO_INTERFACE* device, u32 cacheSize) {
|
||||||
#ifdef NDS
|
#ifdef NDS
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ typedef struct {
|
|||||||
} FAT;
|
} FAT;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
IO_INTERFACE* disc;
|
const IO_INTERFACE* disc;
|
||||||
CACHE* cache;
|
CACHE* cache;
|
||||||
// Info about the partition
|
// Info about the partition
|
||||||
bool readOnly; // If this is set, then do not try writing to the disc
|
bool readOnly; // If this is set, then do not try writing to the disc
|
||||||
@ -87,7 +87,7 @@ bool _FAT_partition_mount (PARTITION_INTERFACE partitionNumber, u32 cacheSize);
|
|||||||
/*
|
/*
|
||||||
Mount a partition on a custom device
|
Mount a partition on a custom device
|
||||||
*/
|
*/
|
||||||
bool _FAT_partition_mountCustomInterface (IO_INTERFACE* device, u32 cacheSize);
|
bool _FAT_partition_mountCustomInterface (const IO_INTERFACE* device, u32 cacheSize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Unmount the partition specified by partitionNumber
|
Unmount the partition specified by partitionNumber
|
||||||
|
Loading…
Reference in New Issue
Block a user