summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/nds/libfat/source/disc_io
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/arm/nds/libfat/source/disc_io')
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.c184
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.h126
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc_io.h81
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.c322
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.h78
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.S73
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.h44
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.c307
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.h23
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.c334
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.h44
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.c60
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.h48
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.c96
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.h45
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.c518
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.h48
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.c100
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.h45
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.c595
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.h50
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.c348
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.h53
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.c47
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.h45
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.c83
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.h45
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.c400
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.h48
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd_s.S139
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.c210
-rw-r--r--c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.h117
32 files changed, 0 insertions, 4756 deletions
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.c
deleted file mode 100644
index 8eea5fcaba..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-
- disc.c
-
- uniformed io-interface to work with Chishm's FAT library
-
- Written by MightyMax
-
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2005-11-06 - Chishm
- * Added WAIT_CR modifications for NDS
-
- 2006-02-03 www.neoflash.com
- * Added SUPPORT_* defines, comment out any of the SUPPORT_* defines in disc_io.h to remove support
- for the given interface and stop code being linked to the binary
-
- * Added support for MK2 MMC interface
-
- * Added disc_Cache* functions
-
- 2006-02-05 - Chishm
- * Added Supercard SD support
-
- 2006-02-26 - Cytex
- * Added EFA2 support
-
- 2006-05-18 - Chishm
- * Rewritten for FATlib disc.c
-
- 2006-06-19 - Chishm
- * Changed read and write interface to accept a u32 instead of a u8 for the number of sectors
-
- 2006-07-11 - Chishm
- * Removed disc_Cache* functions, since there is now a proper unified cache
- * Removed SUPPORT_* defines
- * Rewrote device detection functions
- * First libfat release
-
- 2006-07-25 - Chishm
- * Changed IO_INTERFACEs to const
-
- 2006-08-02 - Chishm
- * Added NinjaDS
-
- 2006-12-25 - Chishm
- * Added DLDI
- * Removed experimental interfaces
-
- 2007-05-01 - Chishm
- * Removed FCSR
-*/
-
-#include "disc.h"
-#include "disc_io.h"
-
-#ifdef NDS
- #include <nds.h>
-#endif
-
-
-// Include known io-interfaces:
-#include "io_dldi.h"
-#include "io_njsd.h"
-#include "io_nmmc.h"
-#include "io_mpcf.h"
-#include "io_m3cf.h"
-#include "io_sccf.h"
-#include "io_scsd.h"
-#include "io_m3sd.h"
-
-const IO_INTERFACE* ioInterfaces[] = {
- &_io_dldi, // Reserved for new interfaces
-#ifdef NDS
- // Place Slot 1 (DS Card) interfaces here
- &_io_njsd, &_io_nmmc,
-#endif
- // Place Slot 2 (GBA Cart) interfaces here
- &_io_mpcf, &_io_m3cf, &_io_sccf, &_io_scsd, &_io_m3sd
-};
-
-/*
-
- Hardware level disc funtions
-
-*/
-
-const IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void)
-{
- // If running on an NDS, make sure the correct CPU can access
- // the GBA cart. First implemented by SaTa.
-#ifdef NDS
- #ifdef ARM9
- sysSetCartOwner(BUS_OWNER_ARM9);
- #endif
-#endif
-
- int i;
-
- for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
- if ((ioInterfaces[i]->features & FEATURE_SLOT_GBA) && (ioInterfaces[i]->fn_startup())) {
- return ioInterfaces[i];
- }
- }
- return NULL;
-}
-
-#ifdef NDS
-/*
- * Check the DS card slot for a valid memory card interface
- * If an interface is found, it is set as the default interace
- * and it returns true. Otherwise the default interface is left
- * untouched and it returns false.
- */
-const IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void)
-{
-#ifdef ARM9
- sysSetCardOwner(BUS_OWNER_ARM9);
-#endif
- int i;
-
- for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
- if ((ioInterfaces[i]->features & FEATURE_SLOT_NDS) && (ioInterfaces[i]->fn_startup())) {
- return ioInterfaces[i];
- }
- }
-
- return NULL;
-}
-#endif
-
-/*
- * When running on an NDS, check the either slot for a valid memory
- * card interface.
- * When running on a GBA, call _FAT_disc_gbaSlotFindInterface
- * If an interface is found, it is set as the default interace
- * and it returns true. Otherwise the default interface is left
- * untouched and it returns false.
- */
-#ifdef NDS
-const IO_INTERFACE* _FAT_disc_findInterface (void)
-{
-#ifdef ARM9
- sysSetBusOwners(BUS_OWNER_ARM9, BUS_OWNER_ARM9);
-#endif
-
- int i;
-
- for (i = 0; i < (sizeof(ioInterfaces) / sizeof(IO_INTERFACE*)); i++) {
- if (ioInterfaces[i]->fn_startup()) {
- return ioInterfaces[i];
- }
- }
-
- return NULL;
-}
-#else
-const IO_INTERFACE* _FAT_disc_findInterface (void)
-{
- return _FAT_disc_gbaSlotFindInterface();
-}
-#endif
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.h
deleted file mode 100644
index 5bb21f171f..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- disc.h
- Interface to the low level disc functions. Used by the higher level
- file system code.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-
-*/
-#ifndef _DISC_H
-#define _DISC_H
-
-#include "../common.h"
-#include "disc_io.h"
-
-/*
-Search for a block based device in the GBA slot.
-Return a pointer to a usable interface if one is found,
-NULL if not.
-*/
-extern const IO_INTERFACE* _FAT_disc_gbaSlotFindInterface (void);
-
-/*
-Search for a block based device in the DS slot.
-Return a pointer to a usable interface if one is found,
-NULL if not.
-*/
-#ifdef NDS
-extern const IO_INTERFACE* _FAT_disc_dsSlotFindInterface (void);
-#endif
-
-/*
-Search for a block based device in the both slots.
-Return a pointer to a usable interface if one is found,
-NULL if not.
-*/
-extern const IO_INTERFACE* _FAT_disc_findInterface (void);
-
-/*
-Check if a disc is inserted
-Return true if a disc is inserted and ready, false otherwise
-*/
-static inline bool _FAT_disc_isInserted (const IO_INTERFACE* disc) {
- return disc->fn_isInserted();
-}
-
-/*
-Read numSectors sectors from a disc, starting at sector.
-numSectors is between 1 and 256
-sector is from 0 to 2^28
-buffer is a pointer to the memory to fill
-*/
-static inline bool _FAT_disc_readSectors (const IO_INTERFACE* disc, u32 sector, u32 numSectors, void* buffer) {
- return disc->fn_readSectors (sector, numSectors, buffer);
-}
-
-/*
-Write numSectors sectors to a disc, starting at sector.
-numSectors is between 1 and 256
-sector is from 0 to 2^28
-buffer is a pointer to the memory to read from
-*/
-static inline bool _FAT_disc_writeSectors (const IO_INTERFACE* disc, u32 sector, u32 numSectors, const void* buffer) {
- return disc->fn_writeSectors (sector, numSectors, buffer);
-}
-
-/*
-Reset the card back to a ready state
-*/
-static inline bool _FAT_disc_clearStatus (const IO_INTERFACE* disc) {
- return disc->fn_clearStatus();
-}
-
-/*
-Initialise the disc to a state ready for data reading or writing
-*/
-static inline bool _FAT_disc_startup (const IO_INTERFACE* disc) {
- return disc->fn_startup();
-}
-
-/*
-Put the disc in a state ready for power down.
-Complete any pending writes and disable the disc if necessary
-*/
-static inline bool _FAT_disc_shutdown (const IO_INTERFACE* disc) {
- return disc->fn_shutdown();
-}
-
-/*
-Return a 32 bit value unique to each type of interface
-*/
-static inline u32 _FAT_disc_hostType (const IO_INTERFACE* disc) {
- return disc->ioType;
-}
-
-/*
-Return a 32 bit value that specifies the capabilities of the disc
-*/
-static inline u32 _FAT_disc_features (const IO_INTERFACE* disc) {
- return disc->features;
-}
-
-#endif // _DISC_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc_io.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc_io.h
deleted file mode 100644
index 916f94e5a3..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/disc_io.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- disc_io.h
- Interface template for low level disc functions.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-
- 2006-07-16 - Chishm
- * Renamed _CF_USE_DMA to _IO_USE_DMA
- * Renamed _CF_ALLOW_UNALIGNED to _IO_ALLOW_UNALIGNED
-*/
-
-#ifndef _DISC_IO_H
-#define _DISC_IO_H
-
-#include "../common.h"
-
-//----------------------------------------------------------------------
-// Customisable features
-
-// Use DMA to read the card, remove this line to use normal reads/writes
-// #define _IO_USE_DMA
-
-// Allow buffers not alligned to 16 bits when reading files.
-// Note that this will slow down access speed, so only use if you have to.
-// It is also incompatible with DMA
-#define _IO_ALLOW_UNALIGNED
-
-#if defined _IO_USE_DMA && defined _IO_ALLOW_UNALIGNED
- #error "You cannot use both DMA and unaligned memory"
-#endif
-
-#define FEATURE_MEDIUM_CANREAD 0x00000001
-#define FEATURE_MEDIUM_CANWRITE 0x00000002
-#define FEATURE_SLOT_GBA 0x00000010
-#define FEATURE_SLOT_NDS 0x00000020
-
-typedef bool (* FN_MEDIUM_STARTUP)(void) ;
-typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
-typedef bool (* FN_MEDIUM_READSECTORS)(u32 sector, u32 numSectors, void* buffer) ;
-typedef bool (* FN_MEDIUM_WRITESECTORS)(u32 sector, u32 numSectors, const void* buffer) ;
-typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ;
-typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ;
-
-struct IO_INTERFACE_STRUCT {
- unsigned long ioType ;
- unsigned long features ;
- FN_MEDIUM_STARTUP fn_startup ;
- FN_MEDIUM_ISINSERTED fn_isInserted ;
- FN_MEDIUM_READSECTORS fn_readSectors ;
- FN_MEDIUM_WRITESECTORS fn_writeSectors ;
- FN_MEDIUM_CLEARSTATUS fn_clearStatus ;
- FN_MEDIUM_SHUTDOWN fn_shutdown ;
-} ;
-
-typedef struct IO_INTERFACE_STRUCT IO_INTERFACE ;
-
-#endif // define _DISC_IO_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.c
deleted file mode 100644
index 386d24d5ed..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- io_cf_common.c based on
-
- compact_flash.c
- By chishm (Michael Chisholm)
-
- Common hardware routines for using a compact flash card. This is not reentrant
- and does not do range checking on the supplied addresses. This is designed to
- be as fast as possible.
-
- CF routines modified with help from Darkfader
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include "io_cf_common.h"
-
-//---------------------------------------------------------------
-// DMA
-#ifdef _IO_USE_DMA
- #ifndef NDS
- #include "gba_dma.h"
- #else
- #include <nds/dma.h>
- #ifdef ARM9
- #include <nds/arm9/cache.h>
- #endif
- #endif
-#endif
-
-//---------------------------------------------------------------
-// CF Addresses & Commands
-
-CF_REGISTERS cfRegisters = {0};
-
-
-/*-----------------------------------------------------------------
-_CF_isInserted
-Is a compact flash card inserted?
-bool return OUT: true if a CF card is inserted
------------------------------------------------------------------*/
-bool _CF_isInserted (void) {
- // Change register, then check if value did change
- *(cfRegisters.status) = CF_STS_INSERTED;
- return ((*(cfRegisters.status) & 0xff) == CF_STS_INSERTED);
-}
-
-
-/*-----------------------------------------------------------------
-_CF_clearStatus
-Tries to make the CF card go back to idle mode
-bool return OUT: true if a CF card is idle
------------------------------------------------------------------*/
-bool _CF_clearStatus (void) {
- int i;
-
- // Wait until CF card is finished previous commands
- i=0;
- while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT)) {
- i++;
- }
-
- // Wait until card is ready for commands
- i = 0;
- while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT)) {
- i++;
- }
- if (i >= CF_CARD_TIMEOUT)
- return false;
-
- return true;
-}
-
-
-/*-----------------------------------------------------------------
-_CF_readSectors
-Read 512 byte sector numbered "sector" into "buffer"
-u32 sector IN: address of first 512 byte sector on CF card to read
-u32 numSectors IN: number of 512 byte sectors to read,
- 1 to 256 sectors can be read
-void* buffer OUT: pointer to 512 byte buffer to store data in
-bool return OUT: true if successful
------------------------------------------------------------------*/
-bool _CF_readSectors (u32 sector, u32 numSectors, void* buffer) {
- int i;
-
- u16 *buff = (u16*)buffer;
-#ifdef _IO_ALLOW_UNALIGNED
- u8 *buff_u8 = (u8*)buffer;
- int temp;
-#endif
-
-#if (defined _IO_USE_DMA) && (defined NDS) && (defined ARM9)
- DC_FlushRange( buffer, j * BYTES_PER_READ);
-#endif
-
- // Wait until CF card is finished previous commands
- i=0;
- while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT)) {
- i++;
- }
-
- // Wait until card is ready for commands
- i = 0;
- while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT)) {
- i++;
- }
- if (i >= CF_CARD_TIMEOUT)
- return false;
-
- // Set number of sectors to read
- *(cfRegisters.sectorCount) = (numSectors < 256 ? numSectors : 0); // Read a maximum of 256 sectors, 0 means 256
-
- // Set read sector
- *(cfRegisters.lba1) = sector & 0xFF; // 1st byte of sector number
- *(cfRegisters.lba2) = (sector >> 8) & 0xFF; // 2nd byte of sector number
- *(cfRegisters.lba3) = (sector >> 16) & 0xFF; // 3rd byte of sector number
- *(cfRegisters.lba4) = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number
-
- // Set command to read
- *(cfRegisters.command) = CF_CMD_READ;
-
-
- while (numSectors--)
- {
- // Wait until card is ready for reading
- i = 0;
- while (((*(cfRegisters.status) & 0xff)!= CF_STS_READY) && (i < CF_CARD_TIMEOUT))
- {
- i++;
- }
- if (i >= CF_CARD_TIMEOUT)
- return false;
-
- // Read data
-#ifdef _IO_USE_DMA
- #ifdef NDS
- DMA3_SRC = (u32)(cfRegisters.data);
- DMA3_DEST = (u32)buff;
- DMA3_CR = 256 | DMA_COPY_HALFWORDS | DMA_SRC_FIX;
- #else
- DMA3COPY ( (cfRegisters.data), buff, 256 | DMA16 | DMA_ENABLE | DMA_SRC_FIXED);
- #endif
- buff += BYTES_PER_READ / 2;
-#elif defined _IO_ALLOW_UNALIGNED
- i=256;
- if ((u32)buff_u8 & 0x01) {
- while(i--)
- {
- temp = *(cfRegisters.data);
- *buff_u8++ = temp & 0xFF;
- *buff_u8++ = temp >> 8;
- }
- } else {
- while(i--)
- *buff++ = *(cfRegisters.data);
- }
-#else
- i=256;
- while(i--)
- *buff++ = *(cfRegisters.data);
-#endif
- }
-#if (defined _IO_USE_DMA) && (defined NDS)
- // Wait for end of transfer before returning
- while(DMA3_CR & DMA_BUSY);
-#endif
- return true;
-}
-
-
-
-/*-----------------------------------------------------------------
-_CF_writeSectors
-Write 512 byte sector numbered "sector" from "buffer"
-u32 sector IN: address of 512 byte sector on CF card to read
-u32 numSectors IN: number of 512 byte sectors to read,
- 1 to 256 sectors can be read
-void* buffer IN: pointer to 512 byte buffer to read data from
-bool return OUT: true if successful
------------------------------------------------------------------*/
-bool _CF_writeSectors (u32 sector, u32 numSectors, void* buffer) {
- int i;
-
- u16 *buff = (u16*)buffer;
-#ifdef _IO_ALLOW_UNALIGNED
- u8 *buff_u8 = (u8*)buffer;
- int temp;
-#endif
-
-#if defined _IO_USE_DMA && defined NDS && defined ARM9
- DC_FlushRange( buffer, j * BYTES_PER_READ);
-#endif
-
- // Wait until CF card is finished previous commands
- i=0;
- while ((*(cfRegisters.command) & CF_STS_BUSY) && (i < CF_CARD_TIMEOUT))
- {
- i++;
- }
-
- // Wait until card is ready for commands
- i = 0;
- while ((!(*(cfRegisters.status) & CF_STS_INSERTED)) && (i < CF_CARD_TIMEOUT))
- {
- i++;
- }
- if (i >= CF_CARD_TIMEOUT)
- return false;
-
- // Set number of sectors to write
- *(cfRegisters.sectorCount) = (numSectors < 256 ? numSectors : 0); // Write a maximum of 256 sectors, 0 means 256
-
- // Set write sector
- *(cfRegisters.lba1) = sector & 0xFF; // 1st byte of sector number
- *(cfRegisters.lba2) = (sector >> 8) & 0xFF; // 2nd byte of sector number
- *(cfRegisters.lba3) = (sector >> 16) & 0xFF; // 3rd byte of sector number
- *(cfRegisters.lba4) = ((sector >> 24) & 0x0F )| CF_CMD_LBA; // last nibble of sector number
-
- // Set command to write
- *(cfRegisters.command) = CF_CMD_WRITE;
-
- while (numSectors--)
- {
- // Wait until card is ready for writing
- i = 0;
- while (((*(cfRegisters.status) & 0xff) != CF_STS_READY) && (i < CF_CARD_TIMEOUT))
- {
- i++;
- }
- if (i >= CF_CARD_TIMEOUT)
- return false;
-
- // Write data
-#ifdef _IO_USE_DMA
- #ifdef NDS
- DMA3_SRC = (u32)buff;
- DMA3_DEST = (u32)(cfRegisters.data);
- DMA3_CR = 256 | DMA_COPY_HALFWORDS | DMA_DST_FIX;
- #else
- DMA3COPY( buff, (cfRegisters.data), 256 | DMA16 | DMA_ENABLE | DMA_DST_FIXED);
- #endif
- buff += BYTES_PER_READ / 2;
-#elif defined _IO_ALLOW_UNALIGNED
- i=256;
- if ((u32)buff_u8 & 0x01) {
- while(i--)
- {
- temp = *buff_u8++;
- temp |= *buff_u8++ << 8;
- *(cfRegisters.data) = temp;
- }
- } else {
- while(i--)
- *(cfRegisters.data) = *buff++;
- }
-#else
- i=256;
- while(i--)
- *(cfRegisters.data) = *buff++;
-#endif
- }
-#if defined _IO_USE_DMA && defined NDS
- // Wait for end of transfer before returning
- while(DMA3_CR & DMA_BUSY);
-#endif
-
- return true;
-}
-
-/*-----------------------------------------------------------------
-_CF_shutdown
-shutdown the CF interface
------------------------------------------------------------------*/
-bool _CF_shutdown(void) {
- return _CF_clearStatus() ;
-}
-
-/*-----------------------------------------------------------------
-_CF_startUp
-Initializes the CF interface using the supplied registers
-returns true if successful, otherwise returns false
------------------------------------------------------------------*/
-bool _CF_startup(const CF_REGISTERS *usableCfRegs) {
- cfRegisters = *usableCfRegs;
- // See if there is a read/write register
- u16 temp = *(cfRegisters.lba1);
- *(cfRegisters.lba1) = (~temp & 0xFF);
- temp = (~temp & 0xFF);
- if (!(*(cfRegisters.lba1) == temp)) {
- return false;
- }
- // Make sure it is 8 bit
- *(cfRegisters.lba1) = 0xAA55;
- if (*(cfRegisters.lba1) == 0xAA55) {
- return false;
- }
- return true;
-}
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.h
deleted file mode 100644
index e08c1a9503..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_cf_common.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- io_cf_common.h
-
- By chishm (Michael Chisholm)
-
- Common Compact Flash card values
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-
- 2006-07-16 - Chishm
- * Combined all CF interfaces into one common set of routines
-*/
-
-#ifndef IO_CF_COMMON_H
-#define IO_CF_COMMON_H
-
-#include "disc_io.h"
-
-typedef struct {
- vu16* data;
- vu16* status;
- vu16* command;
- vu16* error;
- vu16* sectorCount;
- vu16* lba1;
- vu16* lba2;
- vu16* lba3;
- vu16* lba4;
-} CF_REGISTERS;
-
-
-// CF Card status
-#define CF_STS_INSERTED 0x50
-#define CF_STS_REMOVED 0x00
-#define CF_STS_READY 0x58
-
-#define CF_STS_DRQ 0x08
-#define CF_STS_BUSY 0x80
-
-// CF Card commands
-#define CF_CMD_LBA 0xE0
-#define CF_CMD_READ 0x20
-#define CF_CMD_WRITE 0x30
-
-#define CF_CARD_TIMEOUT 10000000
-
-bool _CF_isInserted (void);
-bool _CF_clearStatus (void);
-bool _CF_readSectors (u32 sector, u32 numSectors, void* buffer);
-bool _CF_writeSectors (u32 sector, u32 numSectors, void* buffer);
-bool _CF_shutdown(void);
-bool _CF_startup(const CF_REGISTERS *usableCfRegs);
-
-#endif // define IO_CF_COMMON_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.S b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.S
deleted file mode 100644
index d087bbd94d..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.S
+++ /dev/null
@@ -1,73 +0,0 @@
-@---------------------------------------------------------------------------------
- .align 4
- .arm
- .global _io_dldi
-@---------------------------------------------------------------------------------
-.equ FEATURE_MEDIUM_CANREAD, 0x00000001
-.equ FEATURE_MEDIUM_CANWRITE, 0x00000002
-.equ FEATURE_SLOT_GBA, 0x00000010
-.equ FEATURE_SLOT_NDS, 0x00000020
-
-
-_dldi_start:
-
-@---------------------------------------------------------------------------------
-@ Driver patch file standard header -- 16 bytes
- .word 0xBF8DA5ED @ Magic number to identify this region
- .asciz " Chishm" @ Identifying Magic string (8 bytes with null terminator)
- .byte 0x01 @ Version number
- .byte 0x0F @32KiB @ Log [base-2] of the size of this driver in bytes.
- .byte 0x00 @ Sections to fix
- .byte 0x0F @32KiB @ Log [base-2] of the allocated space in bytes.
-
-@---------------------------------------------------------------------------------
-@ Text identifier - can be anything up to 47 chars + terminating null -- 16 bytes
- .align 4
- .asciz "Default (No interface)"
-
-@---------------------------------------------------------------------------------
-@ Offsets to important sections within the data -- 32 bytes
- .align 6
- .word _dldi_start @ data start
- .word _dldi_end @ data end
- .word 0x00000000 @ Interworking glue start -- Needs address fixing
- .word 0x00000000 @ Interworking glue end
- .word 0x00000000 @ GOT start -- Needs address fixing
- .word 0x00000000 @ GOT end
- .word 0x00000000 @ bss start -- Needs setting to zero
- .word 0x00000000 @ bss end
-
-@---------------------------------------------------------------------------------
-@ IO_INTERFACE data -- 32 bytes
-_io_dldi:
- .ascii "DLDI" @ ioType
- .word 0x00000000 @ Features
- .word _DLDI_startup @
- .word _DLDI_isInserted @
- .word _DLDI_readSectors @ Function pointers to standard device driver functions
- .word _DLDI_writeSectors @
- .word _DLDI_clearStatus @
- .word _DLDI_shutdown @
-
-@---------------------------------------------------------------------------------
-
-_DLDI_startup:
-_DLDI_isInserted:
-_DLDI_readSectors:
-_DLDI_writeSectors:
-_DLDI_clearStatus:
-_DLDI_shutdown:
- mov r0, #0x00 @ Return false for every function
- bx lr
-
-
-
-@---------------------------------------------------------------------------------
- .align
- .pool
-
-.space 32632 @ Fill to 32KiB
-
-_dldi_end:
- .end
-@---------------------------------------------------------------------------------
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.h
deleted file mode 100644
index 97483914ff..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_dldi.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- io_dldi.h
-
- Reserved space for post-compilation adding of an extra driver
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-12-22 - Chishm
- * Original release
-*/
-
-#ifndef IO_DLDI_H
-#define IO_DLDI_H
-
-// 'DLDD'
-#define DEVICE_TYPE_DLDD 0x49444C44
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_dldi ;
-
-#endif // define IO_DLDI_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.c
deleted file mode 100644
index f68e74a2ac..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
-io_efa2.c by CyteX
-
-Based on io_mpfc.c by chishm (Michael Chisholm)
-
-Hardware Routines for reading the NAND flash located on
-EFA2 flash carts
-
-This software is completely free. No warranty is provided.
-If you use it, please give me credit and email me about your
-project at cytex <at> gmx <dot> de and do not forget to also
-drop chishm <at> hotmail <dot> com a line
-
- Use with permission by Michael "Chishm" Chisholm
-*/
-
-#include "io_efa2.h"
-
-//
-// EFA2 register addresses
-//
-
-// RTC registers
-#define REG_RTC_CLK (*(vu16*)0x080000c4)
-#define REG_RTC_EN (*(vu16*)0x080000c8)
-
-// "Magic" registers used for unlock/lock sequences
-#define REG_EFA2_MAGIC_A (*(vu16*)0x09fe0000)
-#define REG_EFA2_MAGIC_B (*(vu16*)0x08000000)
-#define REG_EFA2_MAGIC_C (*(vu16*)0x08020000)
-#define REG_EFA2_MAGIC_D (*(vu16*)0x08040000)
-#define REG_EFA2_MAGIC_E (*(vu16*)0x09fc0000)
-
-// NAND flash lock/unlock register
-#define REG_EFA2_NAND_LOCK (*(vu16*)0x09c40000)
-// NAND flash enable register
-#define REG_EFA2_NAND_EN (*(vu16*)0x09400000)
-// NAND flash command write register
-#define REG_EFA2_NAND_CMD (*(vu8*)0x09ffffe2)
-// NAND flash address/data write register
-#define REG_EFA2_NAND_WR (*(vu8*)0x09ffffe0)
-// NAND flash data read register
-#define REG_EFA2_NAND_RD (*(vu8*)0x09ffc000)
-
-// ID of Samsung K9K1G NAND flash chip
-#define EFA2_NAND_ID 0xEC79A5C0
-
-// first sector of udisk
-#define EFA2_UDSK_START 0x40
-
-//
-// EFA2 access functions
-//
-
-// deactivate RTC ports
-static inline void _EFA2_rtc_deactivate(void) {
- REG_RTC_EN = 0;
-}
-
-// unlock register access
-static void _EFA2_reg_unlock(void) {
- REG_EFA2_MAGIC_A = 0x0d200;
- REG_EFA2_MAGIC_B = 0x01500;
- REG_EFA2_MAGIC_C = 0x0d200;
- REG_EFA2_MAGIC_D = 0x01500;
-}
-
-// finish/lock register access
-static inline void _EFA2_reg_lock(void) {
- REG_EFA2_MAGIC_E = 0x1500;
-}
-
-// global reset/init/enable/unlock ?
-static void _EFA2_global_unlock(void) {
- _EFA2_reg_unlock();
- *(vu16*)0x09880000 = 0x08000;
- _EFA2_reg_lock();
-}
-
-// global lock, stealth mode
-/*static void _EFA2_global_lock(void) {
- // quite sure there is such a sequence, but haven't had
- // a look for it upto now
-}*/
-
-// unlock NAND Flash
-static void _EFA2_nand_unlock(void) {
- _EFA2_reg_unlock();
- REG_EFA2_NAND_LOCK = 0x01500;
- _EFA2_reg_lock();
-}
-
-// lock NAND Flash
-static void _EFA2_nand_lock(void) {
- _EFA2_reg_unlock();
- REG_EFA2_NAND_LOCK = 0x0d200;
- _EFA2_reg_lock();
-}
-
-//
-// Set NAND Flash chip enable and write protection bits ?
-//
-// val | ~CE | ~WP |
-// -----+-----+-----+
-// 0 | 0 | 0 |
-// 1 | 1 | 0 |
-// 3 | 1 | 1 |
-// -----+-----+-----+
-//
-static void _EFA2_nand_enable(u16 val) {
- _EFA2_reg_unlock();
- REG_EFA2_NAND_EN = val;
- _EFA2_reg_lock();
-}
-
-//
-// Perform NAND reset
-// NAND has to be unlocked and enabled when called
-//
-static inline void _EFA2_nand_reset(void) {
- REG_EFA2_NAND_CMD = 0xff; // write reset command
-}
-
-//
-// Read out NAND ID information, could be used for card detection
-//
-// | EFA2 1GBit |
-// ------------------+------------+
-// maker code | 0xEC |
-// device code | 0x79 |
-// don't care | 0xA5 |
-// multi plane code | 0xC0 |
-// ------------------+------------+
-//
-static u32 _EFA2_nand_id(void) {
- u8 byte;
- u32 id;
-
- _EFA2_nand_unlock();
- _EFA2_nand_enable(1);
-
- REG_EFA2_NAND_CMD = 0x90; // write id command
- REG_EFA2_NAND_WR = 0x00; // (dummy) address cycle
- byte = REG_EFA2_NAND_RD; // read maker code
- id = byte;
- byte = REG_EFA2_NAND_RD; // read device code
- id = (id << 8) | byte;
- byte = REG_EFA2_NAND_RD; // read don't care
- id = (id << 8) | byte;
- byte = REG_EFA2_NAND_RD; // read multi plane code
- id = (id << 8) | byte;
-
- _EFA2_nand_enable(0);
- _EFA2_nand_lock();
- return (id);
-}
-
-//
-// Start of gba_nds_fat block device description
-//
-
-/*-----------------------------------------------------------------
-EFA2_clearStatus
-Reads and checks NAND status information
-bool return OUT: true if NAND is idle
------------------------------------------------------------------*/
-static bool _EFA2_clearStatus (void)
-{
- // tbd: currently there is no write support, so always return
- // true, there is no possibility for pending operations
- return true;
-}
-
-/*-----------------------------------------------------------------
-EFA2_isInserted
-Checks to see if the NAND chip used by the EFA2 is present
-bool return OUT: true if the correct NAND chip is found
------------------------------------------------------------------*/
-static bool _EFA2_isInserted (void)
-{
- _EFA2_clearStatus();
- return (_EFA2_nand_id() == EFA2_NAND_ID);
-}
-
-/*-----------------------------------------------------------------
-EFA2_readSectors
-Read "numSecs" 512 byte sectors starting from "sector" into "buffer"
-No error correction, no use of spare cells, no use of R/~B signal
-u32 sector IN: number of first 512 byte sector to be read
-u32 numSecs IN: number of 512 byte sectors to read,
-void* buffer OUT: pointer to 512 byte buffer to store data in
-bool return OUT: true if successful
------------------------------------------------------------------*/
-static bool _EFA2_readSectors (u32 sector, u32 numSecs, void* buffer)
-{
- int i;
-
-#ifndef _IO_ALLOW_UNALIGNED
- u8 byte;
- u16 word;
-#endif
-
- // NAND page 0x40 (EFA2_UDSK_START) contains the MBR of the
- // udisk and thus is sector 0. The original EFA2 firmware
- // does never look at this, it only watches page 0x60, which
- // contains the boot block of the FAT16 partition. That is
- // fixed, so the EFA2 udisk must not be reformated, else
- // the ARK Octopus and also the original Firmware won't be
- // able to access the udisk anymore and I have to write a
- // recovery tool.
- u32 page = EFA2_UDSK_START + sector;
-
- // future enhancement: wait for possible write operations to
- // be finisched
- if (!_EFA2_clearStatus()) return false;
-
- _EFA2_nand_unlock();
- _EFA2_nand_enable(1);
- _EFA2_nand_reset();
-
- // set NAND to READ1 operation mode and transfer page address
- REG_EFA2_NAND_CMD = 0x00; // write READ1 command
- REG_EFA2_NAND_WR = 0x00; // write address [7:0]
- REG_EFA2_NAND_WR = (page ) & 0xff; // write address [15:8]
- REG_EFA2_NAND_WR = (page >> 8 ) & 0xff; // write address[23:16]
- REG_EFA2_NAND_WR = (page >> 16) & 0xff; // write address[26:24]
-
- // Due to a bug in EFA2 design there is need to waste some cycles
- // "by hand" instead the possibility to check the R/~B port of
- // the NAND flash via a register. The RTC deactivation is only
- // there to make sure the loop won't be optimized by the compiler
- for (i=0 ; i < 3 ; i++) _EFA2_rtc_deactivate();
-
- while (numSecs--)
- {
- // read page data
-#ifdef _IO_ALLOW_UNALIGNED
- // slow byte access to RAM, but works in principle
- for (i=0 ; i < 512 ; i++)
- ((u8*)buffer)[i] = REG_EFA2_NAND_RD;
-#else
- // a bit faster, but DMA is not possible
- for (i=0 ; i < 256 ; i++) {
- byte = REG_EFA2_NAND_RD; // read lo-byte
- word = byte;
- byte = REG_EFA2_NAND_RD; // read hi-byte
- word = word | (byte << 8);
- ((u16*)buffer)[i] = word;
- }
-#endif
- }
-
- _EFA2_nand_enable(0);
- _EFA2_nand_lock();
- return true;
-}
-
-
-/*-----------------------------------------------------------------
-EFA2_writeSectors
-Write "numSecs" 512 byte sectors starting at "sector" from "buffer"
-u32 sector IN: address of 512 byte sector on card to write
-u32 numSecs IN: number of 512 byte sectors to write
-1 to 256 sectors can be written, 0 = 256
-void* buffer IN: pointer to 512 byte buffer to read data from
-bool return OUT: true if successful
------------------------------------------------------------------*/
-static bool _EFA2_writeSectors (u32 sector, u8 numSecs, void* buffer)
-{
- // Upto now I focused on reading NAND, write operations
- // will follow
- return false;
-}
-
-/*-----------------------------------------------------------------
-EFA2_shutdown
-unload the EFA2 interface
------------------------------------------------------------------*/
-static bool _EFA2_shutdown(void)
-{
- return _EFA2_clearStatus();
-}
-
-/*-----------------------------------------------------------------
-EFA2_startUp
-initializes the EFA2 card, returns true if successful,
-otherwise returns false
------------------------------------------------------------------*/
-static bool _EFA2_startUp(void)
-{
- _EFA2_global_unlock();
- return (_EFA2_nand_id() == EFA2_NAND_ID);
-}
-
-/*-----------------------------------------------------------------
-the actual interface structure
------------------------------------------------------------------*/
-const IO_INTERFACE _io_efa2 = {
- DEVICE_TYPE_EFA2,
- FEATURE_MEDIUM_CANREAD | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_EFA2_startUp,
- (FN_MEDIUM_ISINSERTED)&_EFA2_isInserted,
- (FN_MEDIUM_READSECTORS)&_EFA2_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_EFA2_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_EFA2_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_EFA2_shutdown
-};
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.h
deleted file mode 100644
index d3a5e29c31..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_efa2.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- io_efa2.h by CyteX
-
- Based on io_mpfc.h by chishm (Michael Chisholm)
-
- Hardware Routines for reading the NAND flash located on
- EFA2 flash carts
-
- Used with permission from Cytex.
-*/
-
-#ifndef IO_EFA2_H
-#define IO_EFA2_H
-
-// 'EFA2'
-#define DEVICE_TYPE_EFA2 0x32414645
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_efa2;
-
-#endif // define IO_EFA2_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.c
deleted file mode 100644
index c888db0a0a..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- io_fcsr.c based on
-
- compact_flash.c
- By chishm (Michael Chisholm)
-
- Hardware Routines for using a GBA Flash Cart and SRAM as a
- block device.
-
- The file system must be 512 byte aligned, in cart address space.
- SRAM is supported.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include "io_fcsr.h"
-
-#include <string.h>
-
-//---------------------------------------------------------------
-// DMA
-#ifdef _IO_USE_DMA
- #ifndef NDS
- #include "gba_dma.h"
- #else
- #include <nds/dma.h>
- #ifdef ARM9
- #include <nds/arm9/cache.h>
- #endif
- #endif
-#endif
-
-#ifdef NDS
- #define SRAM_START 0x0A000000
-#else
- #define SRAM_START 0x0E000000
-#endif
-
-#define NO_SRAM 0xFFFFFFFF
-
-#define FCSR 0x52534346
-const char _FCSR_LabelString[] = " Chishm FAT";
-
-u8* _FCSR_FileSysPointer = 0;
-u8* _FCSR_SramSectorPointer[4] = {0,0,0,0};
-u32 _FCSR_SramSectorStart[4] = {0,0,0,0};
-u32 _FCSR_SramSectorEnd[4] = {0,0,0,0};
-
-/*-----------------------------------------------------------------
-_FCSR_isInserted
-Is a GBA Flash Cart with a valid file system inserted?
-bool return OUT: true if a GBA FC card is inserted
------------------------------------------------------------------*/
-static bool _FCSR_isInserted (void)
-{
- bool flagFoundFileSys = false;
-
- u32* fileSysPointer = (u32*)0x08000100; // Start at beginning of cart address space, offset by expected location of string
-
- // Search for file system
- while ((fileSysPointer < (u32*)0x0A000000) && !flagFoundFileSys) // Only search while not at end of cart address space
- {
- while ((*fileSysPointer != FCSR) && (fileSysPointer < (u32*)0x0A000000))
- fileSysPointer += 0x40;
- if ((strncmp(_FCSR_LabelString, (char*)(fileSysPointer + 1), 12) == 0) && (fileSysPointer < (u32*)0x0A000000))
- {
- flagFoundFileSys = true;
- } else {
- fileSysPointer += 0x80;
- }
- }
-
- return flagFoundFileSys;
-}
-
-
-/*-----------------------------------------------------------------
-_FCSR_clearStatus
-Finish any pending operations
-bool return OUT: always true for GBA FC
------------------------------------------------------------------*/
-static bool _FCSR_clearStatus (void)
-{
- return true;
-}
-
-
-/*-----------------------------------------------------------------
-_FCSR_readSectors
-Read 512 byte sector numbered "sector" into "buffer"
-u32 sector IN: address of first 512 byte sector on Flash Cart to read
-u32 numSectors IN: number of 512 byte sectors to read,
- 1 to 256 sectors can be read
-void* buffer OUT: pointer to 512 byte buffer to store data in
-bool return OUT: true if successful
------------------------------------------------------------------*/
-static bool _FCSR_readSectors (u32 sector, u32 numSectors, void* buffer)
-{
- int i;
- bool flagSramSector = false;
- int readLength = numSectors * BYTES_PER_READ;
- u8* src;
- u8* dst;
-
- // Find which region this read is in
- for (i = 0; (i < 4) && !flagSramSector; i++)
- {
- if ((sector >= _FCSR_SramSectorStart[i]) && (sector < _FCSR_SramSectorEnd[i]))
- {
- flagSramSector = true;
- break;
- }
- }
-
- // Make sure read will be completely in SRAM range if it is partially there
- if ( flagSramSector && ((sector + numSectors) > _FCSR_SramSectorEnd[i]))
- return false;
-
- // Copy data to buffer
- if (flagSramSector)
- {
- src = _FCSR_SramSectorPointer[i] + (sector - _FCSR_SramSectorStart[i]) * BYTES_PER_READ;
- } else {
- src = _FCSR_FileSysPointer + sector * BYTES_PER_READ;
- }
- dst = (u8*)buffer;
-
- if (flagSramSector)
- {
- while (readLength--)
- {
- *dst++ = *src++;
- }
- } else { // Reading from Cart ROM
-
-#ifdef _IO_USE_DMA
- #ifdef NDS
- #ifdef ARM9
- DC_FlushRange( buffer, readLength);
- #endif // ARM9
- DMA3_SRC = (u32)src;
- DMA3_DEST = (u32)buffer;
- DMA3_CR = (readLength >> 1) | DMA_COPY_HALFWORDS;
- #else // ! NDS
- DMA3COPY ( src, buffer, (readLength >> 1) | DMA16 | DMA_ENABLE);
- #endif // NDS
-#else // !_IO_USE_DMA
- memcpy (buffer, src, readLength);
-#endif // _IO_USE_DMA
-
- } // if (flagSramSector)
-
- return true;
-}
-
-/*-----------------------------------------------------------------
-_FCSR_writeSectors
-Write 512 byte sector numbered "sector" from "buffer"
-u32 sector IN: address of 512 byte sector on Flash Cart to read
-u32 numSectors IN: number of 512 byte sectors to read,
- 1 to 256 sectors can be read
-void* buffer IN: pointer to 512 byte buffer to read data from
-bool return OUT: true if successful
------------------------------------------------------------------*/
-static bool _FCSR_writeSectors (u32 sector, u8 numSectors, void* buffer)
-{
- int i;
- bool flagSramSector = false;
- u32 writeLength = numSectors * BYTES_PER_READ;
- u8* src = (u8*) buffer;
- u8* dst;
-
- // Find which region this sector belongs in
- for (i = 0; (i < 4) && !flagSramSector; i++)
- {
- if ((sector >= _FCSR_SramSectorStart[i]) && (sector < _FCSR_SramSectorEnd[i]))
- {
- flagSramSector = true;
- break;
- }
- }
-
- if (!flagSramSector)
- return false;
-
- // Entire write must be within an SRAM region
- if ((sector + numSectors) > _FCSR_SramSectorEnd[i])
- return false;
-
- // Copy data to SRAM
- dst = _FCSR_SramSectorPointer[i] + (sector - _FCSR_SramSectorStart[i]) * BYTES_PER_READ;
- while (writeLength--)
- {
- *dst++ = *src++;
- }
-
- return true;
-}
-
-/*-----------------------------------------------------------------
-_FCSR_shutdown
-unload the Flash Cart interface
------------------------------------------------------------------*/
-static bool _FCSR_shutdown(void)
-{
- int i;
- if (_FCSR_clearStatus() == false)
- return false;
-
- _FCSR_FileSysPointer = 0;
-
- for (i=0; i < 4; i++)
- {
- _FCSR_SramSectorPointer[i] = 0;
- _FCSR_SramSectorStart[i] = 0;
- _FCSR_SramSectorEnd[i] = 0;
- }
- return true;
-}
-
-/*-----------------------------------------------------------------
-_FCSR_startUp
-initializes the Flash Cart interface, returns true if successful,
-otherwise returns false
------------------------------------------------------------------*/
-static bool _FCSR_startUp(void)
-{
- bool flagFoundFileSys = false;
- int i;
- int SramRegionSize[4];
- u8* srcByte;
- u8* destByte;
-
- u32* fileSysPointer = (u32*)0x08000100; // Start at beginning of cart address space, offset by expected location of string
-
- // Search for file system
- while ((fileSysPointer < (u32*)0x0A000000) && !flagFoundFileSys) // Only search while not at end of cart address space
- {
- while ((*fileSysPointer != FCSR) && (fileSysPointer < (u32*)0x0A000000))
- fileSysPointer += 0x40;
- if ((strncmp(_FCSR_LabelString, (char*)(fileSysPointer + 1), 12) == 0) && (fileSysPointer < (u32*)0x0A000000))
- {
- flagFoundFileSys = true;
- } else {
- fileSysPointer += 0x80;
- }
- }
-
- if (!flagFoundFileSys)
- return false;
-
- // Flash cart file system pointer has been found
- _FCSR_FileSysPointer = (u8*)(fileSysPointer - 0x40);
-
- // Get SRAM sector regions from header block
- for (i = 0; i < 4; i++)
- {
- _FCSR_SramSectorStart[i] = fileSysPointer[i+4];
- SramRegionSize[i] = fileSysPointer[i+8];
- _FCSR_SramSectorEnd[i] = _FCSR_SramSectorStart[i] + SramRegionSize[i];
- }
-
- // Calculate SRAM region pointers
- _FCSR_SramSectorPointer[0] = (u8*)(SRAM_START + 4);
- for (i = 1; i < 4; i++)
- {
- _FCSR_SramSectorPointer[i] = _FCSR_SramSectorPointer[i-1] + (SramRegionSize[i-1] * BYTES_PER_READ);
- }
-
- // Initialise SRAM with overlay if it hasn't been done so
- if ( (*((u8*)SRAM_START) != 'F') || (*((u8*)(SRAM_START+1)) != 'C') || (*((u8*)(SRAM_START+2)) != 'S') || (*((u8*)(SRAM_START+3)) != 'R') )
- {
- *((u8*)SRAM_START) = 'F';
- *((u8*)(SRAM_START+1)) = 'C';
- *((u8*)(SRAM_START+2)) = 'S';
- *((u8*)(SRAM_START+3)) = 'R';
-
- for (i = 0; i < 4; i++)
- {
- srcByte = _FCSR_FileSysPointer + (_FCSR_SramSectorStart[i] * BYTES_PER_READ);
- destByte = _FCSR_SramSectorPointer[i];
- while (srcByte < _FCSR_FileSysPointer + (_FCSR_SramSectorEnd[i] * BYTES_PER_READ) )
- *destByte++ = *srcByte++;
- }
- }
-
- // Get SRAM sector regions from header block
- for (i = 0; i < 4; i++)
- {
- if (SramRegionSize[i] == 0)
- {
- _FCSR_SramSectorStart[i] = NO_SRAM;
- _FCSR_SramSectorEnd[i] = NO_SRAM;
- }
- }
-
- return true;
-}
-
-/*-----------------------------------------------------------------
-the actual interface structure
------------------------------------------------------------------*/
-const IO_INTERFACE _io_fcsr = {
- DEVICE_TYPE_FCSR, // 'FCSR'
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_FCSR_startUp,
- (FN_MEDIUM_ISINSERTED)&_FCSR_isInserted,
- (FN_MEDIUM_READSECTORS)&_FCSR_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_FCSR_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_FCSR_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_FCSR_shutdown
-} ;
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.h
deleted file mode 100644
index 19b2537960..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_fcsr.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- io_fcsr.h
-
- Hardware Routines for using a GBA Flash Cart with SRAM
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_FCSR_H
-#define IO_FCSR_H
-
-// 'FCSR'
-#define DEVICE_TYPE_FCSR 0x52534346
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_fcsr ;
-
-#endif // define IO_FCSR_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.c
deleted file mode 100644
index 9c8280c808..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- io_m3_common.c
-
- Routines common to all version of the M3
-
- Some code based on M3 SD drivers supplied by M3Adapter.
- Some code written by SaTa may have been unknowingly used.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "io_m3_common.h"
-
-static u16 _M3_readHalfword (u32 addr) {
- return *((vu16*)addr);
-}
-
-void _M3_changeMode (u32 mode) {
- _M3_readHalfword (0x08e00002);
- _M3_readHalfword (0x0800000e);
- _M3_readHalfword (0x08801ffc);
- _M3_readHalfword (0x0800104a);
- _M3_readHalfword (0x08800612);
- _M3_readHalfword (0x08000000);
- _M3_readHalfword (0x08801b66);
- _M3_readHalfword (0x08000000 + (mode << 1));
- _M3_readHalfword (0x0800080e);
- _M3_readHalfword (0x08000000);
-
- if ((mode & 0x0f) != 4) {
- _M3_readHalfword (0x09000000);
- } else {
- _M3_readHalfword (0x080001e4);
- _M3_readHalfword (0x080001e4);
- _M3_readHalfword (0x08000188);
- _M3_readHalfword (0x08000188);
- }
-}
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.h
deleted file mode 100644
index 6d0c669783..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3_common.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- io_m3_common.h
-
- Routines common to all version of the M3
-
- Some code based on M3 SD drivers supplied by M3Adapter.
- Some code written by SaTa may have been unknowingly used.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_M3_COMMON_H
-#define IO_M3_COMMON_H
-
-#include "disc_io.h"
-
-// Values for changing mode
-#define M3_MODE_ROM 0x00400004
-#define M3_MODE_MEDIA 0x00400003
-
-extern void _M3_changeMode (u32 mode);
-
-#endif // IO_M3_COMMON_H
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.c
deleted file mode 100644
index 2db8eec894..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- io_m3cf.c based on
-
- compact_flash.c
- By chishm (Michael Chisholm)
-
- Hardware Routines for reading a compact flash card
- using the M3 Perfect CF Adapter
-
- CF routines modified with help from Darkfader
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include "io_m3cf.h"
-#include "io_m3_common.h"
-#include "io_cf_common.h"
-
-//---------------------------------------------------------------
-// DMA
-#ifdef _IO_USE_DMA
- #ifndef NDS
- #include "gba_dma.h"
- #else
- #include <nds/dma.h>
- #ifdef ARM9
- #include <nds/arm9/cache.h>
- #endif
- #endif
-#endif
-
-//---------------------------------------------------------------
-// M3 CF Addresses
-#define REG_M3CF_STS ((vu16*)0x080C0000) // Status of the CF Card / Device control
-#define REG_M3CF_CMD ((vu16*)0x088E0000) // Commands sent to control chip and status return
-#define REG_M3CF_ERR ((vu16*)0x08820000) // Errors / Features
-
-#define REG_M3CF_SEC ((vu16*)0x08840000) // Number of sector to transfer
-#define REG_M3CF_LBA1 ((vu16*)0x08860000) // 1st byte of sector address
-#define REG_M3CF_LBA2 ((vu16*)0x08880000) // 2nd byte of sector address
-#define REG_M3CF_LBA3 ((vu16*)0x088A0000) // 3rd byte of sector address
-#define REG_M3CF_LBA4 ((vu16*)0x088C0000) // last nibble of sector address | 0xE0
-
-#define REG_M3CF_DATA ((vu16*)0x08800000) // Pointer to buffer of CF data transered from card
-
-static const CF_REGISTERS _M3CF_Registers = {
- REG_M3CF_DATA,
- REG_M3CF_STS,
- REG_M3CF_CMD,
- REG_M3CF_ERR,
- REG_M3CF_SEC,
- REG_M3CF_LBA1,
- REG_M3CF_LBA2,
- REG_M3CF_LBA3,
- REG_M3CF_LBA4
-};
-
-
-static bool _M3CF_startup(void) {
- _M3_changeMode (M3_MODE_MEDIA);
- return _CF_startup (&_M3CF_Registers);
-}
-
-
-const IO_INTERFACE _io_m3cf = {
- DEVICE_TYPE_M3CF,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_M3CF_startup,
- (FN_MEDIUM_ISINSERTED)&_CF_isInserted,
- (FN_MEDIUM_READSECTORS)&_CF_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_CF_shutdown
-} ;
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.h
deleted file mode 100644
index c72da0b4a2..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3cf.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- io_m3cf.h
-
- Hardware Routines for reading a compact flash card
- using the M3 CF
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_M3CF_H
-#define IO_M3CF_H
-
-// 'M3CF'
-#define DEVICE_TYPE_M3CF 0x4643334D
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_m3cf ;
-
-#endif // define IO_M3CF_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.c
deleted file mode 100644
index b5b3173a9d..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- io_m3sd.c
-
- Hardware Routines for reading a Secure Digital card
- using the M3 SD
-
- Some code based on M3 SD drivers supplied by M3Adapter.
- Some code written by SaTa may have been unknowingly used.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- 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
-
- 2006-08-05 - Chishm
- * Tries multiple times to get a Relative Card Address at startup
-
- 2006-08-07 - Chishm
- * Moved the SD initialization to a common function
-*/
-
-#include "io_m3sd.h"
-#include "io_sd_common.h"
-#include "io_m3_common.h"
-
-//---------------------------------------------------------------
-// M3SD register addresses
-
-#define REG_M3SD_DIR (*(vu16*)0x08800000) // direction control register
-#define REG_M3SD_DAT (*(vu16*)0x09000000) // SD data line, 8 bits at a time
-#define REG_M3SD_CMD (*(vu16*)0x09200000) // SD command byte
-#define REG_M3SD_ARGH (*(vu16*)0x09400000) // SD command argument, high halfword
-#define REG_M3SD_ARGL (*(vu16*)0x09600000) // SD command argument, low halfword
-#define REG_M3SD_STS (*(vu16*)0x09800000) // command and status register
-
-//---------------------------------------------------------------
-// Send / receive timeouts, to stop infinite wait loops
-#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
-#define TRANSMIT_TIMEOUT 20000 // 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 WRITE_TIMEOUT 3000 // Time to wait for the card to finish writing
-
-//---------------------------------------------------------------
-// Variables required for tracking SD state
-static u32 _M3SD_relativeCardAddress = 0; // Preshifted Relative Card Address
-
-//---------------------------------------------------------------
-// Internal M3 SD functions
-
-static inline void _M3SD_unlock (void) {
- _M3_changeMode (M3_MODE_MEDIA);
-}
-
-static inline bool _M3SD_waitOnBusy (void) {
- int i = 0;
- while ( (REG_M3SD_STS & 0x01) == 0x00) {
- i++;
- if (i >= TRANSMIT_TIMEOUT) {
- return false;
- }
- }
- return true;
-}
-
-static inline bool _M3SD_waitForDataReady (void) {
- int i = 0;
- while ( (REG_M3SD_STS & 0x40) == 0x00) {
- i++;
- if (i >= TRANSMIT_TIMEOUT) {
- return false;
- }
- }
- return true;
-}
-
-
-static bool _M3SD_sendCommand (u16 command, u32 argument) {
- REG_M3SD_STS = 0x8;
- REG_M3SD_CMD = 0x40 + command; // Include the start bit
- REG_M3SD_ARGH = argument >> 16;
- REG_M3SD_ARGL = argument;
- // The CRC7 of the command is calculated by the M3
-
- REG_M3SD_DIR=0x29;
- if (!_M3SD_waitOnBusy()) {
- REG_M3SD_DIR=0x09;
- return false;
- }
- REG_M3SD_DIR=0x09;
- return true;
-}
-
-static bool _M3SD_sendByte (u8 byte) {
- int i = 0;
- REG_M3SD_DAT = byte;
- REG_M3SD_DIR = 0x03;
- REG_M3SD_STS = 0x01;
- while ((REG_M3SD_STS & 0x04) == 0) {
- i++;
- if (i >= TRANSMIT_TIMEOUT) {
- return false;
- }
- }
- return true;
-}
-
-static u8 _M3SD_getByte (void) {
- int i;
- // Request 8 bits of data from the SD's CMD pin
- REG_M3SD_DIR = 0x02;
- REG_M3SD_STS = 0x02;
- // Wait for the data to be ready
- i = 0;
- while ((REG_M3SD_STS & 0x08) == 0) {
- i++;
- if (i >= TRANSMIT_TIMEOUT) {
- // Return an empty byte if a timeout occurs
- return 0xFF;
- }
- }
- i = 0;
- while ((REG_M3SD_STS & 0x08) != 0) {
- i++;
- if (i >= TRANSMIT_TIMEOUT) {
- // Return an empty byte if a timeout occurs
- return 0xFF;
- }
- }
- // Return the data
- return (REG_M3SD_DAT & 0xff);
-}
-
-// Returns the response from the SD card to a previous command.
-static bool _M3SD_getResponse (u8* dest, u32 length) {
- u32 i;
- u8 dataByte;
- int shiftAmount;
-
- // Wait for the card to be non-busy
- for (i = 0; i < RESPONSE_TIMEOUT; i++) {
- dataByte = _M3SD_getByte();
- if (dataByte != SD_CARD_BUSY) {
- break;
- }
- }
-
- if (dest == NULL) {
- return true;
- }
-
- // Still busy after the timeout has passed
- if (dataByte == 0xff) {
- return false;
- }
-
- // Read response into buffer
- for ( i = 0; i < length; i++) {
- dest[i] = dataByte;
- dataByte = _M3SD_getByte();
- }
- // dataByte will contain the last piece of the response
-
- // Send 16 more clocks, 8 more than the delay required between a response and the next command
- i = _M3SD_getByte();
- i = _M3SD_getByte();
-
- // Shift response so that the bytes are correctly aligned
- // The register may not contain properly aligned data
- for (shiftAmount = 0; ((dest[0] << shiftAmount) & 0x80) != 0x00; shiftAmount++) {
- if (shiftAmount >= 7) {
- return false;
- }
- }
-
- for (i = 0; i < length - 1; i++) {
- dest[i] = (dest[i] << shiftAmount) | (dest[i+1] >> (8-shiftAmount));
- }
- // Get the last piece of the response from dataByte
- dest[i] = (dest[i] << shiftAmount) | (dataByte >> (8-shiftAmount));
-
- return true;
-}
-
-
-static inline bool _M3SD_getResponse_R1 (u8* dest) {
- return _M3SD_getResponse (dest, 6);
-}
-
-static inline bool _M3SD_getResponse_R1b (u8* dest) {
- return _M3SD_getResponse (dest, 6);
-}
-
-static inline bool _M3SD_getResponse_R2 (u8* dest) {
- return _M3SD_getResponse (dest, 17);
-}
-
-static inline bool _M3SD_getResponse_R3 (u8* dest) {
- return _M3SD_getResponse (dest, 6);
-}
-
-static inline bool _M3SD_getResponse_R6 (u8* dest) {
- return _M3SD_getResponse (dest, 6);
-}
-
-static void _M3SD_sendClocks (u32 numClocks) {
- while (numClocks--) {
- _M3SD_sendByte(0xff);
- }
-}
-
-static void _M3SD_getClocks (u32 numClocks) {
- while (numClocks--) {
- _M3SD_getByte();
- }
-}
-
-static bool _M3SD_cmd_6byte_response (u8* responseBuffer, u8 command, u32 data) {
- _M3SD_sendCommand (command, data);
- return _M3SD_getResponse (responseBuffer, 6);
-}
-
-static bool _M3SD_cmd_17byte_response (u8* responseBuffer, u8 command, u32 data) {
- _M3SD_sendCommand (command, data);
- return _M3SD_getResponse (responseBuffer, 17);
-}
-
-static bool _M3SD_initCard (void) {
- // Give the card time to stabilise
- _M3SD_sendClocks (NUM_STARTUP_CLOCKS);
-
- // Reset the card
- if (!_M3SD_sendCommand (GO_IDLE_STATE, 0)) {
- return false;
- }
-
- _M3SD_getClocks (NUM_STARTUP_CLOCKS);
-
- // Card is now reset, including it's address
- _M3SD_relativeCardAddress = 0;
-
- // Init the card
- return _SD_InitCard (_M3SD_cmd_6byte_response,
- _M3SD_cmd_17byte_response,
- true,
- &_M3SD_relativeCardAddress);
-}
-
-static bool _M3SD_readData (void* buffer) {
- u32 i;
- u8* buff_u8 = (u8*)buffer;
- u16* buff = (u16*)buffer;
- u16 temp;
-
- REG_M3SD_DIR = 0x49;
- if (!_M3SD_waitForDataReady()) {
- REG_M3SD_DIR = 0x09;
- return false;
- }
- REG_M3SD_DIR = 0x09;
-
- REG_M3SD_DIR = 0x8;
- REG_M3SD_STS = 0x4;
-
- i = REG_M3SD_DIR;
- // Read data
- i=256;
- if ((u32)buff_u8 & 0x01) {
- while(i--)
- {
- temp = REG_M3SD_DIR;
- *buff_u8++ = temp & 0xFF;
- *buff_u8++ = temp >> 8;
- }
- } else {
- while(i--)
- *buff++ = REG_M3SD_DIR;
- }
- // Read end checksum
- i = REG_M3SD_DIR + REG_M3SD_DIR + REG_M3SD_DIR + REG_M3SD_DIR;
-
- return true;
-}
-
-static void _M3SD_clkout (void) {
- REG_M3SD_DIR = 0x4;
- REG_M3SD_DIR = 0xc;
-/* __asm volatile (
- "ldr r1, =0x08800000 \n"
- "mov r0, #0x04 \n"
- "strh r0, [r1] \n"
- "mov r0, r0 \n"
- "mov r0, r0 \n"
- "mov r0, #0x0c \n"
- "strh r0, [r1] \n"
- : // Outputs
- : // Inputs
- : "r0", "r1" // Clobber list
- );*/
-}
-
-static void _M3SD_clkin (void) {
- REG_M3SD_DIR = 0x0;
- REG_M3SD_DIR = 0x8;
-/* __asm volatile (
- "ldr r1, =0x08800000 \n"
- "mov r0, #0x00 \n"
- "strh r0, [r1] \n"
- "mov r0, r0 \n"
- "mov r0, r0 \n"
- "mov r0, #0x08 \n"
- "strh r0, [r1] \n"
- : // Outputs
- : // Inputs
- : "r0", "r1" // Clobber list
- );*/
-}
-
-static bool _M3SD_writeData (u8* data, u8* crc) {
- int i;
- u8 temp;
-
- do {
- _M3SD_clkin();
- } while ((REG_M3SD_DAT & 0x100) == 0);
-
- REG_M3SD_DAT = 0; // Start bit
-
- _M3SD_clkout();
-
- for (i = 0; i < BYTES_PER_READ; i++) {
- temp = (*data++);
- REG_M3SD_DAT = temp >> 4;
- _M3SD_clkout();
- REG_M3SD_DAT = temp;
- _M3SD_clkout();
- }
-
- if (crc != NULL) {
- for (i = 0; i < 8; i++) {
- temp = (*crc++);
- REG_M3SD_DAT = temp >> 4;
- _M3SD_clkout();
- REG_M3SD_DAT = temp;
- _M3SD_clkout();
- }
- }
-
- i = 32;
- while (i--) {
- temp += 2; // a NOP to stop the compiler optimising out the loop
- }
-
- for (i = 0; i < 32; i++) {
- REG_M3SD_DAT = 0xff;
- _M3SD_clkout();
- }
-
- do {
- _M3SD_clkin();
- } while ((REG_M3SD_DAT & 0x100) == 0);
-
- return true;
-}
-
-//---------------------------------------------------------------
-// Functions needed for the external interface
-
-static bool _M3SD_startUp (void) {
- _M3SD_unlock();
- return _M3SD_initCard();
-}
-
-static bool _M3SD_isInserted (void) {
- u8 responseBuffer [6];
- // Make sure the card receives the command
- if (!_M3SD_sendCommand (SEND_STATUS, 0)) {
- return false;
- }
- // Make sure the card responds
- if (!_M3SD_getResponse_R1 (responseBuffer)) {
- return false;
- }
- // Make sure the card responded correctly
- if (responseBuffer[0] != SEND_STATUS) {
- return false;
- }
- return true;
-}
-
-static bool _M3SD_readSectors (u32 sector, u32 numSectors, void* buffer) {
- u32 i;
- u8* dest = (u8*) buffer;
- u8 responseBuffer[6];
-
- if (numSectors == 1) {
- // If it's only reading one sector, use the (slightly faster) READ_SINGLE_BLOCK
- if (!_M3SD_sendCommand (READ_SINGLE_BLOCK, sector * BYTES_PER_READ)) {
- return false;
- }
-
- if (!_M3SD_readData (buffer)) {
- return false;
- }
-
- } else {
- // Stream the required number of sectors from the card
- if (!_M3SD_sendCommand (READ_MULTIPLE_BLOCK, sector * BYTES_PER_READ)) {
- return false;
- }
-
- for(i=0; i < numSectors; i++, dest+=BYTES_PER_READ) {
- if (!_M3SD_readData(dest)) {
- return false;
- }
- REG_M3SD_STS = 0x8;
- }
-
- // Stop the streaming
- _M3SD_sendCommand (STOP_TRANSMISSION, 0);
- _M3SD_getResponse_R1b (responseBuffer);
- }
-
- return true;
-}
-
-static bool _M3SD_writeSectors (u32 sector, u32 numSectors, const void* buffer) {
- u8 crc[8];
- u8 responseBuffer[6];
- u32 offset = sector * BYTES_PER_READ;
- u8* data = (u8*) buffer;
- int i;
- // Precalculate the data CRC
- _SD_CRC16 ( data, BYTES_PER_READ, crc);
-
- while (numSectors--) {
- // Send a single sector write command
- _M3SD_sendCommand (WRITE_BLOCK, offset);
- if (!_M3SD_getResponse_R1 (responseBuffer)) {
- return false;
- }
-
- REG_M3SD_DIR = 0x4;
- REG_M3SD_STS = 0x0;
-
- // Send the data
- if (! _M3SD_writeData( data, crc)) {
- return false;
- }
-
- 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;
-
-}
-
-static bool _M3SD_clearStatus (void) {
- return _M3SD_initCard ();
-}
-
-static bool _M3SD_shutdown (void) {
- _M3_changeMode (M3_MODE_ROM);
- return true;
-}
-
-const IO_INTERFACE _io_m3sd = {
- DEVICE_TYPE_M3SD,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_M3SD_startUp,
- (FN_MEDIUM_ISINSERTED)&_M3SD_isInserted,
- (FN_MEDIUM_READSECTORS)&_M3SD_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_M3SD_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_M3SD_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_M3SD_shutdown
-} ;
-
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.h
deleted file mode 100644
index 0e4d32b540..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_m3sd.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- io_m3sd.h
-
- Hardware Routines for reading a Secure Digital card
- using the M3 SD
-
- Some code based on M3 SD drivers supplied by M3Adapter.
- Some code written by SaTa may have been unknowingly used.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_M3SD_H
-#define IO_M3SD_H
-
-// 'M3SD'
-#define DEVICE_TYPE_M3SD 0x4453334D
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_m3sd ;
-
-#endif // define IO_M3SD_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.c
deleted file mode 100644
index 3dcafc193e..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- io_mpcf.c based on
-
- compact_flash.c
- By chishm (Michael Chisholm)
-
- Hardware Routines for reading a compact flash card
- using the GBA Movie Player
-
- CF routines modified with help from Darkfader
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include "io_mpcf.h"
-#include "io_cf_common.h"
-
-//---------------------------------------------------------------
-// DMA
-#ifdef _IO_USE_DMA
- #ifndef NDS
- #include "gba_dma.h"
- #else
- #include <nds/dma.h>
- #ifdef ARM9
- #include <nds/arm9/cache.h>
- #endif
- #endif
-#endif
-
-//---------------------------------------------------------------
-// GBAMP CF Addresses
-#define REG_MPCF_STS ((vu16*)0x098C0000) // Status of the CF Card / Device control
-#define REG_MPCF_CMD ((vu16*)0x090E0000) // Commands sent to control chip and status return
-#define REG_MPCF_ERR ((vu16*)0x09020000) // Errors / Features
-
-#define REG_MPCF_SEC ((vu16*)0x09040000) // Number of sector to transfer
-#define REG_MPCF_LBA1 ((vu16*)0x09060000) // 1st byte of sector address
-#define REG_MPCF_LBA2 ((vu16*)0x09080000) // 2nd byte of sector address
-#define REG_MPCF_LBA3 ((vu16*)0x090A0000) // 3rd byte of sector address
-#define REG_MPCF_LBA4 ((vu16*)0x090C0000) // last nibble of sector address | 0xE0
-
-#define REG_MPCF_DATA ((vu16*)0x09000000) // Pointer to buffer of CF data transered from card
-
-static const CF_REGISTERS _MPCF_Registers = {
- REG_MPCF_DATA,
- REG_MPCF_STS,
- REG_MPCF_CMD,
- REG_MPCF_ERR,
- REG_MPCF_SEC,
- REG_MPCF_LBA1,
- REG_MPCF_LBA2,
- REG_MPCF_LBA3,
- REG_MPCF_LBA4
-};
-
-/*-----------------------------------------------------------------
-_MPCF_startup
-initializes the CF interface, returns true if successful,
-otherwise returns false
------------------------------------------------------------------*/
-static bool _MPCF_startup(void) {
- return _CF_startup(&_MPCF_Registers);
-}
-
-/*-----------------------------------------------------------------
-the actual interface structure
------------------------------------------------------------------*/
-const IO_INTERFACE _io_mpcf = {
- DEVICE_TYPE_MPCF,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_MPCF_startup,
- (FN_MEDIUM_ISINSERTED)&_CF_isInserted,
- (FN_MEDIUM_READSECTORS)&_CF_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_CF_shutdown
-} ;
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.h
deleted file mode 100644
index fc5770e18d..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_mpcf.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- io_mpcf.h
-
- Hardware Routines for reading a compact flash card
- using the GBA Movie Player
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_MPCF_H
-#define IO_MPCF_H
-
-// 'MPCF'
-#define DEVICE_TYPE_MPCF 0x4643504D
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_mpcf ;
-
-#endif // define IO_MPCF_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.c
deleted file mode 100644
index e394076e5c..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- io_njsd.c
-
- Hardware Routines for reading an SD card using
- a NinjaDS SD adapter.
-
- Original code supplied by NinjaMod
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-08-05 - Chishm
- * First release
-
- 2006-08-06 - Chishm
- * Removed unneeded _NJSD_writeRAM function
- * Removed casts for calls to cardWriteCommand
-
- 2006-08-07 - Chishm
- * Moved the SD initialization to a common function
-*/
-
-#include "io_njsd.h"
-
-#ifdef NDS
-
-#include <nds.h>
-#include <string.h>
-#include "io_sd_common.h"
-
-#define _NJSD_SYNC
-
-//---------------------------------------------------------------
-// Card communication speeds
-#define SD_CLK_167KHz 00
-#define SD_CLK_250KHz 01
-#define SD_CLK_5MHz 02
-#define SD_CLK_25MHz 03
-
-//---------------------------------------------------------------
-// Response types
-#define SD_RSP_48 0
-#define SD_RSP_136 1
-#define SD_RSP_DATA 2
-#define SD_RSP_STREAM 3
-
-//---------------------------------------------------------------
-// Send / receive timeouts, to stop infinite wait loops
-#define IRQ_TIMEOUT 1000000
-#define RESET_TIMEOUT 10000
-#define COMMAND_TIMEOUT 100000
-#define WRITE_TIMEOUT 3000 // Time to wait for the card to finish writing
-
-
-static const u8 _NJSD_read_cmd[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40};
-static const u8 _NJSD_read_end_cmd[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x00, 0x41};
-
-static int _NJSD_speed = SD_CLK_5MHz; // Default speed;
-
-static u32 _NJSD_cardFlags;
-
-static u32 _NJSD_relativeCardAddress = 0;
-
-static inline bool _NJSD_waitIRQ(void) {
- int i = IRQ_TIMEOUT;
- while (!(REG_IF & 0x100000) && --i);
- REG_IF = 0x100000;
- if (i <= 0) {
- return false;
- } else {
- return true;
- }
-}
-
-static inline void _NJSD_writeCardCommand
- (u8 cmd0, u8 cmd1, u8 cmd2, u8 cmd3, u8 cmd4, u8 cmd5, u8 cmd6, u8 cmd7)
-{
- CARD_COMMAND[0] = cmd0;
- CARD_COMMAND[1] = cmd1;
- CARD_COMMAND[2] = cmd2;
- CARD_COMMAND[3] = cmd3;
- CARD_COMMAND[4] = cmd4;
- CARD_COMMAND[5] = cmd5;
- CARD_COMMAND[6] = cmd6;
- CARD_COMMAND[7] = cmd7;
-}
-
-static bool _NJSD_reset (void) {
- int i;
- CARD_CR1H = CARD_CR1_ENABLE;
- _NJSD_writeCardCommand (0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- CARD_CR2 = 0xA0406000;
- i = RESET_TIMEOUT;
- while ((CARD_CR2 & CARD_BUSY) && --i);
- if (i <= 0) {
- return false;
- }
-
- return true;
-}
-
-static bool _NJSD_init (u32 flags) {
- _NJSD_cardFlags = flags;
-
- REG_IF = 0x100000; // Clear cart IRQ.
-
- irqDisable (IRQ_CARD_LINE);
-
- if (! _NJSD_reset() ) {
- return false;
- }
- return true;
-}
-
-static bool _NJSD_sendCMDR (int speed, u8 *rsp_buf, int type, u8 cmd, u32 param) {
- int i;
- u32 data;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
- old_REG_IME = REG_IME;
- REG_IME = 0;
-#endif
-
- REG_IF = 0x100000;
-
- CARD_CR1H = CARD_CR1_ENABLE;
-
- if ((type & 3) < 2) {
- CARD_COMMAND[0] = 0xF0 | (speed << 2) | 1 | (type << 1);
- } else if ((type & 3) == 2) {
- CARD_COMMAND[0] = 0xE0 | (speed << 2) | 0 | (1 << 1);
- } else {
- CARD_COMMAND[0] = 0xF0 | (speed << 2) | 0 | (1 << 1);
- }
-
- CARD_COMMAND[1] = (type & 0x40) | ((( type >> 2) & 7) << 3);
- CARD_COMMAND[2] = 0x40 | cmd;
- CARD_COMMAND[3] = (param>>24) & 0xFF;
- CARD_COMMAND[4] = (param>>16) & 0xFF;
- CARD_COMMAND[5] = (param>>8) & 0xFF;
- CARD_COMMAND[6] = (param>>0) & 0xFF;
- CARD_COMMAND[7] = 0; // offset = 0
-
- if ((type & 3) < 2) {
- CARD_CR2 = _NJSD_cardFlags | 0x01000000;
-
- // wait for ninja DS to be done!
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- i = 0;
- do {
- // Read data if available
- if (CARD_CR2 & CARD_DATA_READY) {
- data=CARD_DATA_RD;
- if (rsp_buf != NULL) {
- if (i == 4) {
- rsp_buf[0] = (data>>0)&0xFF;
- rsp_buf[1] = (data>>8)&0xFF;
- rsp_buf[2] = (data>>16)&0xFF;
- rsp_buf[3] = (data>>24)&0xFF;
- } else if (i == 5) {
- rsp_buf[4] = (data>>0)&0xFF;
- rsp_buf[5] = (data>>8)&0xFF;
- }
- }
- i++;
- }
- } while (CARD_CR2 & CARD_BUSY);
- } else {
- CARD_CR2 = _NJSD_cardFlags;
- while (CARD_CR2 & CARD_BUSY);
-
- // wait for ninja DS to be done!
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
- }
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return true;
-}
-
-static bool _NJSD_writeSector (u8 *buffer, u8 *crc_buf, u32 offset) {
- int i;
- u8 responseBuffer[6];
- u32 data;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
- old_REG_IME = REG_IME;
- REG_IME = 0;
-#endif
-
- CARD_CR1H = CARD_CR1_ENABLE;
- _NJSD_writeCardCommand (0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
- CARD_CR2 = 0xA0406000;
- i = COMMAND_TIMEOUT;
- while ((CARD_CR2 & CARD_BUSY) && --i);
- if (i <= 0) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- for (i = 0; i < 65; i++)
- {
- CARD_CR1H = CARD_CR1_ENABLE; // | CARD_CR1_IRQ;
- if (i < 64)
- {
- _NJSD_writeCardCommand (buffer[i*8+0], buffer[i*8+1], buffer[i*8+2], buffer[i*8+3],
- buffer[i*8+4], buffer[i*8+5], buffer[i*8+6], buffer[i*8+7]);
- } else {
- _NJSD_writeCardCommand (crc_buf[0], crc_buf[1], crc_buf[2], crc_buf[3],
- crc_buf[4], crc_buf[5], crc_buf[6], crc_buf[7]);
- }
- CARD_CR2 = 0xA7406000;
-
- do {
- // Read data if available
- if (CARD_CR2 & CARD_DATA_READY) {
- data=CARD_DATA_RD;
- }
- } while (CARD_CR2 & CARD_BUSY);
- }
-
- CARD_CR1H = CARD_CR1_ENABLE;
- _NJSD_writeCardCommand (0xF0 | (1 << 2) | 1, 0x80, 0x40 | WRITE_BLOCK, (u8)(offset>>24),
- (u8)(offset>>16), (u8)(offset>>8), (u8)(offset>>0), 0x00);
- CARD_CR2 = 0xA7406000;
-
- // wait for ninja DS to be done!
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- i = 0;
- do {
- // Read data if available
- if (CARD_CR2 & CARD_DATA_READY) {
- data = CARD_DATA_RD;
- if (i == 2) {
- responseBuffer[0] = (u8)(data>>0);
- responseBuffer[1] = (u8)(data>>8);
- responseBuffer[2] = (u8)(data>>16);
- responseBuffer[3] = (u8)(data>>24);
- } else if (i == 3) {
- responseBuffer[4] = (u8)(data>>0);
- responseBuffer[5] = (u8)(data>>8);
- }
- i++;
- }
- } while (CARD_CR2 & CARD_BUSY);
-
- i = WRITE_TIMEOUT;
- responseBuffer[3] = 0;
- do {
- _NJSD_sendCMDR (SD_CLK_167KHz, responseBuffer, SD_RSP_48, SEND_STATUS, _NJSD_relativeCardAddress);
- i--;
- if (i <= 0) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
- } while (((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA)));
-
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
-
- return true;
-}
-
-static bool _NJSD_sendCLK (int speed, int count) {
- int i;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
- old_REG_IME = REG_IME;
- REG_IME = 0;
-
- REG_IF = 0x100000;
-#endif
-
- //CARD_CR1H = CARD_CR1_ENABLE; // | CARD_CR1_IRQ;
- _NJSD_writeCardCommand (0xE0 | ((speed & 3) << 2), 0, (count - 1), 0, 0, 0, 0, 0);
-
- CARD_CR2 = _NJSD_cardFlags;
- i = COMMAND_TIMEOUT;
- while ((CARD_CR2 & CARD_BUSY) && --i);
- if (i <= 0) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- // wait for ninja DS to be done!
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return true;
-}
-
-static bool _NJSD_sendCMDN (int speed, u8 cmd, u32 param) {
- int i;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
- old_REG_IME = REG_IME;
- REG_IME = 0;
-#endif
-
- REG_IF = 0x100000;
-
- CARD_CR1H = CARD_CR1_ENABLE; // | CARD_CR1_IRQ;
- _NJSD_writeCardCommand (0xF0 | ((speed & 3) << 2), 0x00, 0x40 | cmd, (param>>24) & 0xFF,
- (param>>16) & 0xFF, (param>>8) & 0xFF, (param>>0) & 0xFF, 0x00);
-
- CARD_CR2 = _NJSD_cardFlags;
- i = COMMAND_TIMEOUT;
- while ((CARD_CR2 & CARD_BUSY) && --i);
- if (i <= 0) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- // wait for ninja DS to be done!
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return true;
-}
-
-static bool _NJSD_cmd_6byte_response (u8* responseBuffer, u8 command, u32 data) {
- return _NJSD_sendCMDR (SD_CLK_167KHz, responseBuffer, SD_RSP_48, command, data);
-}
-
-static bool _NJSD_cmd_17byte_response (u8* responseBuffer, u8 command, u32 data) {
- return _NJSD_sendCMDR (SD_CLK_167KHz, responseBuffer, SD_RSP_136, command, data);
-}
-
-static bool _NJSD_cardInit (void) {
- // If the commands succeed the first time, assume they'll always succeed
- if (! _NJSD_sendCLK (SD_CLK_167KHz, 256) ) {
- return false;
- }
- if (! _NJSD_sendCMDN (SD_CLK_167KHz, GO_IDLE_STATE, 0) ) {
- return false;
- }
- _NJSD_sendCLK (SD_CLK_167KHz, 8);
-
- _NJSD_sendCLK (SD_CLK_167KHz, 256);
- _NJSD_sendCMDN (SD_CLK_167KHz, GO_IDLE_STATE, 0);
- _NJSD_sendCLK (SD_CLK_167KHz, 8);
-
- return _SD_InitCard (_NJSD_cmd_6byte_response,
- _NJSD_cmd_17byte_response,
- true,
- &_NJSD_relativeCardAddress);
-}
-
-
-static bool _NJSD_isInserted(void) {
- u8 responseBuffer [8];
- _NJSD_sendCMDR (SD_CLK_167KHz, responseBuffer, SD_RSP_48, SEND_STATUS, 0);
-
- // Make sure the card responded correctly
- if (responseBuffer[0] != SEND_STATUS) {
- return false;
- }
- return true;
-}
-
-static bool _NJSD_clearStatus (void) {
- return _NJSD_reset();
-}
-
-static bool _NJSD_shutdown(void) {
- return _NJSD_clearStatus();
-}
-
-static bool _NJSD_startup(void) {
- if (! _NJSD_init(0xA0406000) ) {
- return false;
- }
- if (! _NJSD_cardInit() ) {
- return false;
- }
- return true;
-}
-
-
-static bool _NJSD_writeSectors (u32 sector, u32 numSectors, const void* buffer) {
- u8 crc[8];
- u32 offset = sector * BYTES_PER_READ;
- u8* data = (u8*) buffer;
-
- while (numSectors--) {
- _SD_CRC16 ( data, BYTES_PER_READ, crc);
-
- if (! _NJSD_writeSector (data, crc, offset)) {
- return false;
- }
- offset += BYTES_PER_READ;
- data += BYTES_PER_READ;
- }
- return true;
-}
-
-#ifdef _IO_ALLOW_UNALIGNED
-static bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) {
- u32 tmp[BYTES_PER_READ>>2];
- int i;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
-#endif
-
- u8* tbuf = (u8*)buffer;
-
- if (numSectors == 0) {
- return false;
- }
-
-#ifdef _NJSD_SYNC
- old_REG_IME = REG_IME;
- REG_IME = 0;
-#endif
-
- if (numSectors > 1) {
- _NJSD_sendCMDR (_NJSD_speed, NULL, SD_RSP_DATA, READ_MULTIPLE_BLOCK, sector * BYTES_PER_READ);
- for (i = 0; i < numSectors - 2; i++) {
- if (((int)buffer & 0x03) != 0){
- cardPolledTransfer (0xA1406000, tmp, BYTES_PER_READ, _NJSD_read_cmd);
- memcpy (tbuf + i * BYTES_PER_READ, tmp, BYTES_PER_READ);
- } else {
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + i * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_cmd);
- }
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
- }
- if (((int)buffer & 0x03) != 0){
- cardPolledTransfer (0xA1406000, tmp, BYTES_PER_READ, _NJSD_read_end_cmd);
- memcpy (tbuf + (numSectors - 2) * BYTES_PER_READ, tmp, BYTES_PER_READ);
- } else {
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + (numSectors - 2) * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_end_cmd);
- }
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- if (((int)buffer & 0x03) != 0){
- cardPolledTransfer (0xA1406000, tmp, BYTES_PER_READ, _NJSD_read_cmd);
- memcpy (tbuf + (numSectors - 1) * BYTES_PER_READ, tmp, BYTES_PER_READ);
- } else {
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + (numSectors - 1) * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_cmd);
- }
- } else {
- _NJSD_sendCMDR (_NJSD_speed, NULL, SD_RSP_STREAM, READ_SINGLE_BLOCK, sector * BYTES_PER_READ);
- if (((int)buffer & 0x03) != 0){
- cardPolledTransfer (0xA1406000, tmp, BYTES_PER_READ, _NJSD_read_cmd);
- memcpy (tbuf, tmp, BYTES_PER_READ);
- } else {
- cardPolledTransfer (0xA1406000, (u32*)tbuf, BYTES_PER_READ, _NJSD_read_cmd);
- }
- }
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return true;
-}
-#else // not defined _IO_ALLOW_UNALIGNED
-bool _NJSD_readSectors (u32 sector, u32 numSectors, void* buffer) {
- int i;
-
-#ifdef _NJSD_SYNC
- u32 old_REG_IME;
-#endif
-
- u8* tbuf = (u8*)buffer;
-
- if (numSectors == 0) {
- return false;
- }
-
-#ifdef _NJSD_SYNC
- old_REG_IME = REG_IME;
- REG_IME = 0;
-#endif
-
- if (numSectors > 1) {
- _NJSD_sendCMDR (_NJSD_speed, NULL, SD_RSP_DATA, READ_MULTIPLE_BLOCK, sector * BYTES_PER_READ);
- for (i = 0; i < numSectors - 2; i++) {
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + i * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_cmd);
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
- }
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + (numSectors - 2) * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_end_cmd);
- if (!_NJSD_waitIRQ ()) {
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return false;
- }
-
- cardPolledTransfer (0xA1406000, (u32*)(tbuf + (numSectors - 1) * BYTES_PER_READ), BYTES_PER_READ, _NJSD_read_cmd);
- } else {
- _NJSD_sendCMDR (_NJSD_speed, NULL, SD_RSP_STREAM, READ_SINGLE_BLOCK, sector * BYTES_PER_READ);
- cardPolledTransfer (0xA1406000, (u32*)tbuf, BYTES_PER_READ, _NJSD_read_cmd);
- }
-
-#ifdef _NJSD_SYNC
- REG_IME = old_REG_IME;
-#endif
- return true;
-}
-#endif // _IO_ALLOW_UNALIGNED
-
-const IO_INTERFACE _io_njsd = {
- DEVICE_TYPE_NJSD,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_NDS,
- (FN_MEDIUM_STARTUP)&_NJSD_startup,
- (FN_MEDIUM_ISINSERTED)&_NJSD_isInserted,
- (FN_MEDIUM_READSECTORS)&_NJSD_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_NJSD_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_NJSD_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_NJSD_shutdown
-} ;
-
-#endif // defined NDS
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.h
deleted file mode 100644
index b668a510bc..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_njsd.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- io_njsd.h
-
- Hardware Routines for reading an SD card using
- a NinjaDS SD adapter.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-08-02 - Chishm
- * Original release
-*/
-
-#ifndef IO_NJSD_H
-#define IO_NJSD_H
-
-#include "disc_io.h"
-
-#ifdef NDS
-
-// 'NJSD'
-#define DEVICE_TYPE_NJSD 0x44534A4E
-
-
-// export interface
-extern const IO_INTERFACE _io_njsd;
-
-#endif // defined NDS
-
-#endif // define IO_NJSD_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.c
deleted file mode 100644
index 88d8b48778..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.c
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- io_nmmc.c
-
- Hardware Routines for reading an SD or MMC card using
- a Neoflash MK2 or MK3.
-
- Written by www.neoflash.com
-
- Submit bug reports for this device to the NeoFlash forums
-
- See license.txt for license details.
-
- 2006-02-09 - www.neoflash.com:
- * First stable release
-
- 2006-02-13 - Chishm
- * Added ReadMK2Config function
- * Added read config test to init function so no unnecessary card commands are sent
- * Changed data read and write functions to use multiple block commands
-*/
-
-#include "io_nmmc.h"
-
-#ifdef NDS
-
-#include <nds/card.h>
-
-int _NMMC_spi_freq = 3;
-
-#define MK2_CONFIG_ZIP_RAM_CLOSE (1 << 5)
-#define MK2_CONFIG_GAME_FLASH_CLOSE ((1 << 4) | (1 << 0))
-//#define MK2_CONFIG_ZIP_RAM_CLOSE ((1 << 5) | (1 << 1))
-//#define MK2_CONFIG_GAME_FLASH_CLOSE (1 << 4)
-
-#define MMC_READ_MULTIPLE_BLOCK 18
-#define MMC_READ_BLOCK 17
-#define MMC_WRITE_MULTIPLE_BLOCK 25
-#define MMC_WRITE_BLOCK 24
-#define MMC_STOP_TRANSMISSION 12
-#define MMC_SET_BLOCKLEN 16
-#define MMC_SET_BLOCK_COUNT 23
-#define MMC_SEND_CSD 9
-
-// SPI functions
-
-static inline void _Neo_OpenSPI( u8 frequency )
-{
- CARD_CR1 = 0x0000A040 | frequency;
-}
-
-static inline u8 _Neo_SPI( u8 dataByte )
-{
- CARD_EEPDATA = dataByte;
- while (CARD_CR1 & 0x80); // card busy
- return CARD_EEPDATA;
-}
-
-static inline void _Neo_CloseSPI ( void )
-{
- CARD_CR1 = 0;
-}
-
-static inline void _Neo_MK2GameMode(void) {
- _Neo_OpenSPI(_NMMC_spi_freq); // Enable DS Card's SPI port
- _Neo_SPI(0xF1); // Switch to game mode
- _Neo_CloseSPI(); // Disable DS Card's SPI port
-}
-
-static inline void _Neo_EnableEEPROM( bool enable ) {
- _Neo_OpenSPI(_NMMC_spi_freq);
- if(enable) _Neo_SPI(0x06);
- else _Neo_SPI(0x0E);
- _Neo_CloseSPI();
-}
-
-static void _Neo_WriteMK2Config(u8 config) {
- _Neo_EnableEEPROM(true);
- _Neo_OpenSPI(_NMMC_spi_freq);
- _Neo_SPI(0xFA); // Send mem conf write command
- _Neo_SPI(0x01); // Send high byte (0x01)
- _Neo_SPI(config); // Send low byte
- _Neo_CloseSPI();
- _Neo_EnableEEPROM(false);
-}
-
-static u8 _Neo_ReadMK2Config(void)
-{
- u8 config;
- _Neo_EnableEEPROM(true);
- _Neo_OpenSPI(_NMMC_spi_freq);
- _Neo_SPI(0xf8); // Send mem conf read command
- _Neo_SPI(0x01); // Send high byte
- config = _Neo_SPI(0x00); // Get low byte
- _Neo_CloseSPI();
- _Neo_EnableEEPROM(false);
- return config;
-}
-
-// Low level functions
-
-u8 selectMMC_command [8] = {0xFF, 0x00, 0x6A, 0xDF, 0x37, 0x59, 0x33, 0xA3};
-
-static void _Neo_SelectMMC (u8 dataByte)
-{
- selectMMC_command[1] = dataByte; // Set enable / disable byte
- cardWriteCommand (selectMMC_command); // Send "5. Use the EEPROM CS to access the MK2 MMC/SD card"
- CARD_CR2 = CARD_ACTIVATE | CARD_nRESET;
- while (CARD_CR2 & CARD_BUSY);
- return;
-}
-
-static void _Neo_EnableMMC( bool enable )
-{
- if ( enable == false) {
- _Neo_CloseSPI ();
- _Neo_SelectMMC (0);
- _Neo_SelectMMC (0);
- } else {
- _Neo_SelectMMC (1);
- _Neo_SelectMMC (1);
- _Neo_OpenSPI (_NMMC_spi_freq);
- }
- return;
-}
-
-static void _Neo_SendMMCCommand( u8 command, u32 argument )
-{
- _Neo_SPI (0xFF);
- _Neo_SPI (command | 0x40);
- _Neo_SPI ((argument >> 24) & 0xff);
- _Neo_SPI ((argument >> 16) & 0xff);
- _Neo_SPI ((argument >> 8) & 0xff) ;
- _Neo_SPI (argument & 0xff);
- _Neo_SPI (0x95);
- _Neo_SPI (0xFF);
- return;
-}
-
-static bool _Neo_CheckMMCResponse( u8 response, u8 mask ) {
- u32 i;
- for(i=0;i<256;i++) {
- if( ( _Neo_SPI( 0xFF ) & mask ) == response )
- return true;
- }
- return false;
-}
-
-// Neo MMC functions
-
-static bool _Neo_InitMMC(void) {
- _Neo_MK2GameMode();
- _Neo_WriteMK2Config( MK2_CONFIG_ZIP_RAM_CLOSE | MK2_CONFIG_GAME_FLASH_CLOSE);
-
- // Make sure the configuration was accepted
- if (_Neo_ReadMK2Config() != (MK2_CONFIG_ZIP_RAM_CLOSE | MK2_CONFIG_GAME_FLASH_CLOSE)) {
- return false; // If not, then it wasn't initialised properly
- }
-
- return true;
-}
-
-// Neo MMC driver functions
-
-static bool _NMMC_isInserted(void) {
- int i;
-
- _Neo_EnableMMC( true ); // Open SPI port to MMC card
- _Neo_SendMMCCommand(MMC_SEND_CSD, 0);
- if( _Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured
- _Neo_EnableMMC( false );
- return false;
- }
- if( _Neo_CheckMMCResponse( 0xFE, 0xFF ) == false ) { // Check for Start Block token
- _Neo_EnableMMC( false );
- return false;
- }
-
- // consume data from card, and send clocks.
- for (i = 0; i < 28; i++) {
- _Neo_SPI(0xff);
- }
-
- return true;
-}
-
-static bool _NMMC_clearStatus (void) {
- u32 i;
-
- _Neo_EnableMMC( true ); // Open SPI port to MMC card
- for (i = 0; i < 10; i++) {
- _Neo_SPI(0xFF); // Send 10 0xFF bytes to MMC card
- }
- _Neo_SendMMCCommand(0, 0); // Send GO_IDLE_STATE command
- if( _Neo_CheckMMCResponse( 0x01, 0xFF ) == false ) { // Check that it replied with 0x01 (not idle, no other error)
- _Neo_EnableMMC( false );
- return false;
- }
- for(i=0;i<256;i++) {
- _Neo_SendMMCCommand(1, 0); // Poll with SEND_OP_COND
- if( _Neo_CheckMMCResponse( 0x00, 0x01 ) == true ) { // Check for idle state
- _Neo_EnableMMC( false ); // Close SPI port to MMC card
- return true; // Card is now idle
- }
- }
- _Neo_EnableMMC( false );
- return false;
-}
-
-static bool _NMMC_shutdown(void) {
- return _NMMC_clearStatus();
-}
-
-static bool _NMMC_startUp(void) {
- int i;
- int transSpeed;
- if (_Neo_InitMMC() == false) {
- return false;
- }
- if (_NMMC_clearStatus() == false) {
- return false;
- }
- _Neo_EnableMMC( true ); // Open SPI port to MMC card
-
- // Set block length
- _Neo_SendMMCCommand(MMC_SET_BLOCKLEN, BYTES_PER_READ );
- if( _Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured
- _Neo_EnableMMC( false );
- return false;
- }
-
- // Check if we can use a higher SPI frequency
- _Neo_SendMMCCommand(MMC_SEND_CSD, 0);
- if( _Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured
- _Neo_EnableMMC( false );
- return false;
- }
- if( _Neo_CheckMMCResponse( 0xFE, 0xFF ) == false ) { // Check for Start Block token
- _Neo_EnableMMC( false );
- return false;
- }
- for (i = 0; i < 3; i++) {
- _Neo_SPI(0xFF);
- }
- transSpeed = _Neo_SPI (0xFF);
- for (i = 0; i < 24; i++) {
- _Neo_SPI(0xFF);
- }
- if ((transSpeed & 0xf0) >= 0x30) {
- _NMMC_spi_freq = 0;
- }
-
- _Neo_EnableMMC( false );
-
- return true;
-}
-
-
-static bool _NMMC_writeSectors (u32 sector, u32 totalSecs, const void* buffer)
-{
- u32 i;
- u8 *p=(u8*)buffer;
-
- sector *= BYTES_PER_READ;
-
- _Neo_EnableMMC( true ); // Open SPI port to MMC card
- _Neo_SendMMCCommand( 25, sector );
- if( _Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured
- _Neo_EnableMMC( false );
- return false;
- }
-
- while (totalSecs--) {
- _Neo_SPI( 0xFC ); // Send Start Block token
- for( i = 0; i < BYTES_PER_READ; i++ ) // Send a block of data
- _Neo_SPI( *p++ );
- _Neo_SPI( 0xFF ); // Send fake CRC16
- _Neo_SPI( 0xFF ); // Send fake CRC16
-
- if( ( _Neo_SPI( 0xFF ) & 0x0F ) != 0x05 ) { // Make sure the block was accepted
- _Neo_EnableMMC( false );
- return false;
- }
- while( _Neo_SPI( 0xFF ) == 0x00 ); // Wait for the block to be written
- }
-
- // Stop transmission block
- _Neo_SPI( 0xFD ); // Send Stop Transmission Block token
- for( i = 0; i < BYTES_PER_READ; i++ ) // Send a block of fake data
- _Neo_SPI( 0xFF );
- _Neo_SPI( 0xFF ); // Send fake CRC16
- _Neo_SPI( 0xFF ); // Send fake CRC16
-
- _Neo_SPI (0xFF); // Send 8 clocks
- while( _Neo_SPI( 0xFF ) == 0x00 ); // Wait for the busy signal to clear
-
-
- for ( i = 0; i < 0x10; i++) {
- _Neo_SPI (0xFF); // Send clocks for the MMC card to finish what it's doing
- }
-
- _Neo_EnableMMC( false ); // Close SPI port to MMC card
- return true;
-}
-
-static bool _NMMC_readSectors (u32 sector, u32 totalSecs, void* buffer)
-{
- u32 i;
- u8 *p=(u8*)buffer;
-
- sector *= BYTES_PER_READ;
-
- _Neo_EnableMMC( true ); // Open SPI port to MMC card
-
- while (totalSecs--) {
- _Neo_SendMMCCommand(MMC_READ_BLOCK, sector );
- if( _Neo_CheckMMCResponse( 0x00, 0xFF ) == false ) { // Make sure no errors occured
- _Neo_EnableMMC( false );
- return false;
- }
-
- if( _Neo_CheckMMCResponse( 0xFE, 0xFF ) == false ) { // Check for Start Block token
- _Neo_EnableMMC( false );
- return false;
- }
- for( i = 0; i < BYTES_PER_READ; i++ ) // Read in a block of data
- *p++ = _Neo_SPI( 0xFF );
- _Neo_SPI( 0xFF ); // Ignore CRC16
- _Neo_SPI( 0xFF ); // Ignore CRC16
- sector += BYTES_PER_READ;
- }
-
- _Neo_EnableMMC( false ); // Close SPI port to MMC card
- return true;
-}
-
-
-const IO_INTERFACE _io_nmmc = {
- DEVICE_TYPE_NMMC,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_NDS,
- (FN_MEDIUM_STARTUP)&_NMMC_startUp,
- (FN_MEDIUM_ISINSERTED)&_NMMC_isInserted,
- (FN_MEDIUM_READSECTORS)&_NMMC_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_NMMC_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_NMMC_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_NMMC_shutdown
-} ;
-
-#endif // defined NDS
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.h
deleted file mode 100644
index aeb2c64222..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_nmmc.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- io_nmmc.h
-
- Hardware Routines for reading an SD or MMC card using
- a Neoflash MK2 or MK3.
-
- Original version written by www.neoflash.com,
- moddified and used with permission of www.neoflash.com
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_NMMC_H
-#define IO_NMMC_H
-
-#include "disc_io.h"
-
-#ifdef NDS
-
-// 'NMMC'
-#define DEVICE_TYPE_NMMC 0x434D4D4E
-
-
-// export interface
-extern const IO_INTERFACE _io_nmmc;
-
-#endif // defined NDS
-
-#endif // define IO_NMMC_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.c
deleted file mode 100644
index 9dabbdcd84..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- io_m3_common.h
-
- Routines common to all version of the Super Card
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "io_sc_common.h"
-
-/*-----------------------------------------------------------------
-_SC_changeMode (was SC_Unlock)
-Added by MightyMax
-Modified by Chishm
-Modified again by loopy
-1=ram(readonly), 5=ram, 3=SD interface?
------------------------------------------------------------------*/
-void _SC_changeMode(u8 mode) {
- vu16 *unlockAddress = (vu16*)0x09FFFFFE;
- *unlockAddress = 0xA55A ;
- *unlockAddress = 0xA55A ;
- *unlockAddress = mode ;
- *unlockAddress = mode ;
-}
-
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.h
deleted file mode 100644
index da30b7e5e3..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sc_common.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- io_sc_common.h
-
- Routines common to all version of the Super Card
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_SC_COMMON_H
-#define IO_SC_COMMON_H
-
-#include "disc_io.h"
-
-// Values for changing mode
-#define SC_MODE_RAM 0x5
-#define SC_MODE_MEDIA 0x3
-#define SC_MODE_RAM_RO 0x1
-
-extern void _SC_changeMode (u8 mode);
-
-#endif // IO_SC_COMMON_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.c
deleted file mode 100644
index 06d1378028..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- io_sccf.c based on
-
- compact_flash.c
- By chishm (Michael Chisholm)
-
- Hardware Routines for reading a compact flash card
- using the Super Card CF
-
- CF routines modified with help from Darkfader
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-#include "io_sccf.h"
-#include "io_sc_common.h"
-#include "io_cf_common.h"
-
-//---------------------------------------------------------------
-// SC CF Addresses
-#define REG_SCCF_STS ((vu16*)0x098C0000) // Status of the CF Card / Device control
-#define REG_SCCF_CMD ((vu16*)0x090E0000) // Commands sent to control chip and status return
-#define REG_SCCF_ERR ((vu16*)0x09020000) // Errors / Features
-
-#define REG_SCCF_SEC ((vu16*)0x09040000) // Number of sector to transfer
-#define REG_SCCF_LBA1 ((vu16*)0x09060000) // 1st byte of sector address
-#define REG_SCCF_LBA2 ((vu16*)0x09080000) // 2nd byte of sector address
-#define REG_SCCF_LBA3 ((vu16*)0x090A0000) // 3rd byte of sector address
-#define REG_SCCF_LBA4 ((vu16*)0x090C0000) // last nibble of sector address | 0xE0
-
-#define REG_SCCF_DATA ((vu16*)0x09000000) // Pointer to buffer of CF data transered from card
-
-static const CF_REGISTERS _SCCF_Registers = {
- REG_SCCF_DATA,
- REG_SCCF_STS,
- REG_SCCF_CMD,
- REG_SCCF_ERR,
- REG_SCCF_SEC,
- REG_SCCF_LBA1,
- REG_SCCF_LBA2,
- REG_SCCF_LBA3,
- REG_SCCF_LBA4
-};
-
-
-static bool _SCCF_startup(void) {
- _SC_changeMode (SC_MODE_MEDIA);
- return _CF_startup(&_SCCF_Registers);
-}
-
-
-const IO_INTERFACE _io_sccf = {
- DEVICE_TYPE_SCCF,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_SCCF_startup,
- (FN_MEDIUM_ISINSERTED)&_CF_isInserted,
- (FN_MEDIUM_READSECTORS)&_CF_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_CF_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_CF_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_CF_shutdown
-} ;
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.h
deleted file mode 100644
index 86e428bfd5..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sccf.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- io_sccf.h
-
- Hardware Routines for reading a compact flash card
- using the Supercard CF
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-*/
-
-#ifndef IO_SCCF_H
-#define IO_SCCF_H
-
-// 'SCCF'
-#define DEVICE_TYPE_SCCF 0x46434353
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_sccf;
-
-#endif // define IO_SCCF_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.c
deleted file mode 100644
index 231b93fc37..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- io_scsd.c
-
- Hardware Routines for reading a Secure Digital card
- using the SC SD
-
- Some code based on scsd_c.c, written by Amadeus
- and Jean-Pierre Thomasset as part of DSLinux.
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-22 - Chishm
- * First release of stable code
-
- 2006-07-25 - Chishm
- * Improved startup function that doesn't delay hundreds of seconds
- before reporting no card inserted.
-
- 2006-08-05 - Chishm
- * Tries multiple times to get a Relative Card Address at startup
-
- 2006-08-07 - Chishm
- * Moved the SD initialization to a common function
-
- 2006-08-19 - Chishm
- * Added SuperCard Lite support
-*/
-
-#include "io_scsd.h"
-#include "io_sd_common.h"
-#include "io_sc_common.h"
-
-//---------------------------------------------------------------
-// SCSD register addresses
-#define REG_SCSD_CMD (*(vu16*)(0x09800000))
- /* bit 0: command bit to read */
- /* bit 7: command bit to write */
-
-#define REG_SCSD_DATAWRITE (*(vu16*)(0x09000000))
-#define REG_SCSD_DATAREAD (*(vu16*)(0x09100000))
-#define REG_SCSD_DATAREAD_32 (*(vu32*)(0x09100000))
-#define REG_SCSD_LITE_ENABLE (*(vu16*)(0x09440000))
-#define REG_SCSD_LOCK (*(vu16*)(0x09FFFFFE))
- /* bit 0: 1 */
- /* bit 1: enable IO interface (SD,CF) */
- /* bit 2: enable R/W SDRAM access */
-
-//---------------------------------------------------------------
-// Responses
-#define SCSD_STS_BUSY 0x100
-#define SCSD_STS_INSERTED 0x300
-
-//---------------------------------------------------------------
-// Send / receive timeouts, to stop infinite wait loops
-#define NUM_STARTUP_CLOCKS 100 // Number of empty (0xFF when sending) bytes to send/receive to/from the card
-#define TRANSMIT_TIMEOUT 100000 // 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 BUSY_WAIT_TIMEOUT 500000
-#define WRITE_TIMEOUT 3000 // Time to wait for the card to finish writing
-//---------------------------------------------------------------
-// Variables required for tracking SD state
-static u32 _SCSD_relativeCardAddress = 0; // Preshifted Relative Card Address
-
-//---------------------------------------------------------------
-// Internal SC SD functions
-
-extern bool _SCSD_writeData_s (u8 *data, u16* crc);
-
-static inline void _SCSD_unlock (void) {
- _SC_changeMode (SC_MODE_MEDIA);
-}
-
-static inline void _SCSD_enable_lite (void) {
- REG_SCSD_LITE_ENABLE = 0;
-}
-
-static bool _SCSD_sendCommand (u8 command, u32 argument) {
- u8 databuff[6];
- u8 *tempDataPtr = databuff;
- int length = 6;
- u16 dataByte;
- int curBit;
- int i;
-
- *tempDataPtr++ = command | 0x40;
- *tempDataPtr++ = argument>>24;
- *tempDataPtr++ = argument>>16;
- *tempDataPtr++ = argument>>8;
- *tempDataPtr++ = argument;
- *tempDataPtr = _SD_CRC7 (databuff, 5);
-
- i = BUSY_WAIT_TIMEOUT;
- while (((REG_SCSD_CMD & 0x01) == 0) && (--i));
- if (i == 0) {
- return false;
- }
-
- dataByte = REG_SCSD_CMD;
-
- tempDataPtr = databuff;
-
- while (length--) {
- dataByte = *tempDataPtr++;
- for (curBit = 7; curBit >=0; curBit--){
- REG_SCSD_CMD = dataByte;
- dataByte = dataByte << 1;
- }
- }
-
- return true;
-}
-
-// Returns the response from the SD card to a previous command.
-static bool _SCSD_getResponse (u8* dest, u32 length) {
- u32 i;
- int dataByte;
- int numBits = length * 8;
-
- // Wait for the card to be non-busy
- i = BUSY_WAIT_TIMEOUT;
- while (((REG_SCSD_CMD & 0x01) != 0) && (--i));
- if (dest == NULL) {
- return true;
- }
-
- if (i == 0) {
- // Still busy after the timeout has passed
- return false;
- }
-
- // The first bit is always 0
- dataByte = 0;
- numBits--;
- // Read the remaining bits in the response.
- // It's always most significant bit first
- while (numBits--) {
- dataByte = (dataByte << 1) | (REG_SCSD_CMD & 0x01);
- if ((numBits & 0x7) == 0) {
- // It's read a whole byte, so store it
- *dest++ = (u8)dataByte;
- dataByte = 0;
- }
- }
-
- // Send 16 more clocks, 8 more than the delay required between a response and the next command
- for (i = 0; i < 16; i++) {
- dataByte = REG_SCSD_CMD;
- }
-
- return true;
-}
-
-static inline bool _SCSD_getResponse_R1 (u8* dest) {
- return _SCSD_getResponse (dest, 6);
-}
-
-static inline bool _SCSD_getResponse_R1b (u8* dest) {
- return _SCSD_getResponse (dest, 6);
-}
-
-static inline bool _SCSD_getResponse_R2 (u8* dest) {
- return _SCSD_getResponse (dest, 17);
-}
-
-static inline bool _SCSD_getResponse_R3 (u8* dest) {
- return _SCSD_getResponse (dest, 6);
-}
-
-static inline bool _SCSD_getResponse_R6 (u8* dest) {
- return _SCSD_getResponse (dest, 6);
-}
-
-static void _SCSD_sendClocks (u32 numClocks) {
- u16 temp;
- do {
- (void) temp; /* avoid set but not used warning */
- temp = REG_SCSD_CMD;
- } while (numClocks--);
-}
-
-static bool _SCSD_cmd_6byte_response (u8* responseBuffer, u8 command, u32 data) {
- _SCSD_sendCommand (command, data);
- return _SCSD_getResponse (responseBuffer, 6);
-}
-
-static bool _SCSD_cmd_17byte_response (u8* responseBuffer, u8 command, u32 data) {
- _SCSD_sendCommand (command, data);
- return _SCSD_getResponse (responseBuffer, 17);
-}
-
-
-static bool _SCSD_initCard (void) {
- _SCSD_enable_lite();
-
- // Give the card time to stabilise
- _SCSD_sendClocks (NUM_STARTUP_CLOCKS);
-
- // Reset the card
- if (!_SCSD_sendCommand (GO_IDLE_STATE, 0)) {
- return false;
- }
-
- _SCSD_sendClocks (NUM_STARTUP_CLOCKS);
-
- // Card is now reset, including it's address
- _SCSD_relativeCardAddress = 0;
-
- // Init the card
- return _SD_InitCard (_SCSD_cmd_6byte_response,
- _SCSD_cmd_17byte_response,
- true,
- &_SCSD_relativeCardAddress);
-}
-
-static bool _SCSD_readData (void* buffer) {
- u8* buff_u8 = (u8*)buffer;
- u16* buff = (u16*)buffer;
- volatile register u32 temp;
- int i;
-
- i = BUSY_WAIT_TIMEOUT;
- while ((REG_SCSD_DATAREAD & SCSD_STS_BUSY) && (--i));
- if (i == 0) {
- return false;
- }
-
- i=256;
- if ((u32)buff_u8 & 0x01) {
- while(i--) {
- temp = REG_SCSD_DATAREAD_32;
- temp = REG_SCSD_DATAREAD_32 >> 16;
- *buff_u8++ = (u8)temp;
- *buff_u8++ = (u8)(temp >> 8);
- }
- } else {
- while(i--) {
- temp = REG_SCSD_DATAREAD_32;
- temp = REG_SCSD_DATAREAD_32 >> 16;
- *buff++ = temp;
- }
- }
-
-
- for (i = 0; i < 8; i++) {
- temp = REG_SCSD_DATAREAD_32;
- }
-
- temp = REG_SCSD_DATAREAD;
-
- return true;
-}
-
-//---------------------------------------------------------------
-// Functions needed for the external interface
-
-static bool _SCSD_startUp (void) {
- _SCSD_unlock();
- return _SCSD_initCard();
-}
-
-static bool _SCSD_isInserted (void) {
- u8 responseBuffer [6];
-
- // Make sure the card receives the command
- if (!_SCSD_sendCommand (SEND_STATUS, 0)) {
- return false;
- }
- // Make sure the card responds
- if (!_SCSD_getResponse_R1 (responseBuffer)) {
- return false;
- }
- // Make sure the card responded correctly
- if (responseBuffer[0] != SEND_STATUS) {
- return false;
- }
- return true;
-}
-
-static bool _SCSD_readSectors (u32 sector, u32 numSectors, void* buffer) {
- u32 i;
- u8* dest = (u8*) buffer;
- u8 responseBuffer[6];
-
- if (numSectors == 1) {
- // If it's only reading one sector, use the (slightly faster) READ_SINGLE_BLOCK
- if (!_SCSD_sendCommand (READ_SINGLE_BLOCK, sector * BYTES_PER_READ)) {
- return false;
- }
-
- if (!_SCSD_readData (buffer)) {
- return false;
- }
-
- } else {
- // Stream the required number of sectors from the card
- if (!_SCSD_sendCommand (READ_MULTIPLE_BLOCK, sector * BYTES_PER_READ)) {
- return false;
- }
-
- for(i=0; i < numSectors; i++, dest+=BYTES_PER_READ) {
- if (!_SCSD_readData(dest)) {
- return false;
- }
- }
-
- // Stop the streaming
- _SCSD_sendCommand (STOP_TRANSMISSION, 0);
- _SCSD_getResponse_R1b (responseBuffer);
- }
-
- _SCSD_sendClocks(0x10);
- return true;
-}
-
-static bool _SCSD_writeSectors (u32 sector, u32 numSectors, const void* buffer) {
- u16 crc[4]; // One per data line
- u8 responseBuffer[6];
- u32 offset = sector * BYTES_PER_READ;
- u8* data = (u8*) buffer;
- int i;
-
- while (numSectors--) {
- // Calculate the CRC16
- _SD_CRC16 ( data, BYTES_PER_READ, (u8*)crc);
-
- // Send write command and get a response
- _SCSD_sendCommand (WRITE_BLOCK, offset);
- if (!_SCSD_getResponse_R1 (responseBuffer)) {
- return false;
- }
-
- // Send the data and CRC
- if (! _SCSD_writeData_s (data, crc)) {
- return false;
- }
-
- // Send a few clocks to the SD card
- _SCSD_sendClocks(0x10);
-
- offset += BYTES_PER_READ;
- data += BYTES_PER_READ;
-
- // Wait until card is finished programming
- i = WRITE_TIMEOUT;
- responseBuffer[3] = 0;
- do {
- _SCSD_sendCommand (SEND_STATUS, _SCSD_relativeCardAddress);
- _SCSD_getResponse_R1 (responseBuffer);
- i--;
- if (i <= 0) {
- return false;
- }
- } while (((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA)));
- }
-
- return true;
-}
-
-static bool _SCSD_clearStatus (void) {
- return _SCSD_initCard ();
-}
-
-static bool _SCSD_shutdown (void) {
- _SC_changeMode (SC_MODE_RAM_RO);
- return true;
-}
-
-const IO_INTERFACE _io_scsd = {
- DEVICE_TYPE_SCSD,
- FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_SLOT_GBA,
- (FN_MEDIUM_STARTUP)&_SCSD_startUp,
- (FN_MEDIUM_ISINSERTED)&_SCSD_isInserted,
- (FN_MEDIUM_READSECTORS)&_SCSD_readSectors,
- (FN_MEDIUM_WRITESECTORS)&_SCSD_writeSectors,
- (FN_MEDIUM_CLEARSTATUS)&_SCSD_clearStatus,
- (FN_MEDIUM_SHUTDOWN)&_SCSD_shutdown
-} ;
-
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.h
deleted file mode 100644
index 25a02544df..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- io_scsd.h
-
- Hardware Routines for reading a Secure Digital card
- using the Supercard SD
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-
- 2006-07-22 - Chishm
- * First release of stable code
-*/
-
-#ifndef IO_SCSD_H
-#define IO_SCSD_H
-
-// 'SCSD'
-#define DEVICE_TYPE_SCSD 0x44534353
-
-#include "disc_io.h"
-
-// export interface
-extern const IO_INTERFACE _io_scsd ;
-
-#endif // define IO_SCSD_H
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd_s.S b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd_s.S
deleted file mode 100644
index 5ae8fdd2b8..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_scsd_s.S
+++ /dev/null
@@ -1,139 +0,0 @@
-@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-@ io_scsd_s.s
-@
-@ Hardware Routines for reading a Secure Digital card
-@ using the SC SD
-@
-@ Based on code supplied by Romman
-@
-@ Copyright (c) 2006 Michael "Chishm" Chisholm
-@
-@ Redistribution and use in source and binary forms, with or without modification,
-@ are permitted provided that the following conditions are met:
-@
-@ 1. Redistributions of source code must retain the above copyright notice,
-@ this list of conditions and the following disclaimer.
-@ 2. Redistributions in binary form must reproduce the above copyright notice,
-@ this list of conditions and the following disclaimer in the documentation and/or
-@ other materials provided with the distribution.
-@ 3. The name of the author may not be used to endorse or promote products derived
-@ from this software without specific prior written permission.
-@
-@ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-@ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-@ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
-@ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-@ 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,
-@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-@
-@ 2006-07-22 - Chishm
-@ * First release of stable code
-@
-@ 2006-08-19 - Chishm
-@ * Added SuperCard Lite support
-@
-@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-
- .align 4
- .arm
-
- .equ REG_SCSD_DATAWRITE, 0x09000000
- .equ BYTES_PER_READ, 0x200
- .equ SCSD_STS_BUSY, 0x100
- .equ BUSY_WAIT_TIMEOUT, 0x10000
- .equ FALSE, 0
- .equ TRUE, 1
-
-@ bool _SCSD_writeData_s (u8 *data, u16* crc)
-
- .global _SCSD_writeData_s
-
-_SCSD_writeData_s:
- stmfd r13!, {r4-r5}
- mov r5, #BYTES_PER_READ
- mov r2, #REG_SCSD_DATAWRITE
-
-@ Wait for a free data buffer on the SD card
- mov r4, #BUSY_WAIT_TIMEOUT
-_SCSD_writeData_busy_wait:
- @ Test for timeout
- subs r4, r4, #1
- moveq r0, #FALSE @ return false on failure
- beq _SCSD_writeData_return
- @ Check the busy bit of the status register
- ldrh r3, [r2]
- tst r3, #SCSD_STS_BUSY
- beq _SCSD_writeData_busy_wait
-
- ldrh r3, [r2] @ extra clock
-
- mov r3, #0 @ start bit
- strh r3,[r2]
-
-@ Check if the data buffer is aligned on a halfword boundary
- tst r0, #1
- beq _SCSD_writeData_data_loop
-
-@ Used when the source data is unaligned
-_SCSD_writeData_data_loop_unaligned:
- ldrb r3, [r0], #1
- ldrb r4, [r0], #1
- orr r3, r3, r4, lsl #8
- stmia r2, {r3-r4}
- subs r5, r5, #2
- bne _SCSD_writeData_data_loop_unaligned
- b _SCSD_writeData_crc
-
-@ Write the data to the card
-@ 4 halfwords are transmitted to the Supercard at once, for timing purposes
-@ Only the first halfword needs to contain data for standard SuperCards
-@ For the SuperCard Lite, the data is split into 4 nibbles, one per halfword
-_SCSD_writeData_data_loop:
- ldrh r3, [r0], #2
-
-@ This bit added for SCLite. Notice that the shift is not the same as in
-@ the original (buggy) code supplied by Romman
- add r3, r3, r3, lsl #20
- mov r4, r3, lsr #8
-
- stmia r2, {r3-r4}
-
- subs r5, r5, #2
- bne _SCSD_writeData_data_loop
-
-@ Send the data CRC
-_SCSD_writeData_crc:
- cmp r1, #0
- movne r0, r1
- movne r1, #0
- movne r5, #8
- bne _SCSD_writeData_data_loop
-
- mov r3, #0xff @ end bit
- strh r3, [r2]
-
-@ Wait for the SD card to signal that it is finished recieving
- mov r4, #BUSY_WAIT_TIMEOUT
-_SCSD_writeData_finished_wait:
- @ Test for timeout
- subs r4, r4, #1
- moveq r0, #FALSE @ return false on failure
- beq _SCSD_writeData_return
- @ Check the busy bit of the status register
- ldrh r3, [r2]
- tst r3, #0x100
- bne _SCSD_writeData_finished_wait
-
-@ Send 8 more clocks, as required by the SD card
- ldmia r2, {r3-r4}
-
-@ return true for success
- mov r0, #TRUE
-
-_SCSD_writeData_return:
- ldmfd r13!,{r4-r5}
- bx r14
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.c b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.c
deleted file mode 100644
index 86dd37355b..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- io_sd_common.c
-
- By chishm (Michael Chisholm)
-
- Common SD card routines
-
- SD routines partially based on sd.s by Romman
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-08-07 - Chishm
- * Moved the SD initialization to a common function
- * Increased timeouts for slower cards
-
- 2006-08-08 - Chishm
- * Init aborts when it doesn't get a valid response to APP_CMD - speeds up detection when no card is inserted
-*/
-
-#include "io_sd_common.h"
-
-#define MAX_STARTUP_TRIES 1000 // Arbitrary value, check if the card is ready 20 times before giving up
-#define RESPONSE_TIMEOUT 256 // Number of clocks sent to the SD card before giving up
-
-/*
-Improved CRC7 function provided by cory1492
-Calculates the CRC of an SD command, and includes the end bit in the byte
-*/
-u8 _SD_CRC7(u8* data, int cnt) {
- int i, a;
- u8 crc, temp;
-
- crc = 0;
- for (a = 0; a < cnt; a++)
- {
- temp = data[a];
- for (i = 0; i < 8; i++)
- {
- crc <<= 1;
- if ((temp & 0x80) ^ (crc & 0x80)) crc ^= 0x09;
- temp <<= 1;
- }
- }
- crc = (crc << 1) | 1;
- return(crc);
-}
-
-/*
-Calculates the CRC16 for a sector of data. Calculates it
-as 4 separate lots, merged into one buffer. This is used
-for 4 SD data lines, not for 1 data line alone.
-*/
-void _SD_CRC16 (u8* buff, int buffLength, u8* crc16buff) {
- u32 a, b, c, d;
- int count;
- u32 bitPattern = 0x80808080; // r7
- u32 crcConst = 0x1021; // r8
- u32 dataByte = 0; // r2
-
- a = 0; // r3
- b = 0; // r4
- c = 0; // r5
- d = 0; // r6
-
- buffLength = buffLength * 8;
-
-
- do {
- if (bitPattern & 0x80) dataByte = *buff++;
-
- a = a << 1;
- if ( a & 0x10000) a ^= crcConst;
- if (dataByte & (bitPattern >> 24)) a ^= crcConst;
-
- b = b << 1;
- if (b & 0x10000) b ^= crcConst;
- if (dataByte & (bitPattern >> 25)) b ^= crcConst;
-
- c = c << 1;
- if (c & 0x10000) c ^= crcConst;
- if (dataByte & (bitPattern >> 26)) c ^= crcConst;
-
- d = d << 1;
- if (d & 0x10000) d ^= crcConst;
- if (dataByte & (bitPattern >> 27)) d ^= crcConst;
-
- bitPattern = (bitPattern >> 4) | (bitPattern << 28);
- } while (buffLength-=4);
-
- count = 16; // r8
-
- do {
- bitPattern = bitPattern << 4;
- if (a & 0x8000) bitPattern |= 8;
- if (b & 0x8000) bitPattern |= 4;
- if (c & 0x8000) bitPattern |= 2;
- if (d & 0x8000) bitPattern |= 1;
-
- a = a << 1;
- b = b << 1;
- c = c << 1;
- d = d << 1;
-
- count--;
-
- if (!(count & 0x01)) {
- *crc16buff++ = (u8)(bitPattern & 0xff);
- }
- } while (count != 0);
-
- return;
-}
-
-/*
-Initialise the SD card, after it has been sent into an Idle state
-cmd_6byte_response: a pointer to a function that sends the SD card a command and gets a 6 byte response
-cmd_17byte_response: a pointer to a function that sends the SD card a command and gets a 17 byte response
-use4bitBus: initialise card to use a 4 bit data bus when communicating with the card
-RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits.
-*/
-bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response,
- _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response,
- bool use4bitBus,
- u32 *RCA)
-{
- u8 responseBuffer[17] = {0};
- int i;
-
- for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
- cmd_6byte_response (responseBuffer, APP_CMD, 0);
- // Check that the card gave the correct response
- if (responseBuffer[0] != APP_CMD) {
- return false;
- }
- if (
- cmd_6byte_response (responseBuffer, SD_APP_OP_COND, SD_OCR_VALUE) &&
- ((responseBuffer[1] & 0x80) != 0))
- {
- // Card is ready to receive commands now
- break;
- }
- }
- if (i >= MAX_STARTUP_TRIES) {
- return false;
- }
-
- // The card's name, as assigned by the manufacturer
- cmd_17byte_response (responseBuffer, ALL_SEND_CID, 0);
-
- // Get a new address
- for (i = 0; i < MAX_STARTUP_TRIES ; i++) {
- cmd_6byte_response (responseBuffer, SEND_RELATIVE_ADDR, 0);
- *RCA = (responseBuffer[1] << 24) | (responseBuffer[2] << 16);
- if ((responseBuffer[3] & 0x1e) != (SD_STATE_STBY << 1)) {
- break;
- }
- }
- if (i >= MAX_STARTUP_TRIES) {
- return false;
- }
-
- // Some cards won't go to higher speeds unless they think you checked their capabilities
- cmd_17byte_response (responseBuffer, SEND_CSD, *RCA);
-
- // Only this card should respond to all future commands
- cmd_6byte_response (responseBuffer, SELECT_CARD, *RCA);
-
- if (use4bitBus) {
- // Set a 4 bit data bus
- cmd_6byte_response (responseBuffer, APP_CMD, *RCA);
- cmd_6byte_response (responseBuffer, SET_BUS_WIDTH, 2); // 4-bit mode.
- }
-
- // Use 512 byte blocks
- cmd_6byte_response (responseBuffer, SET_BLOCKLEN, 512); // 512 byte blocks
-
- // Wait until card is ready for data
- i = 0;
- do {
- if (i >= RESPONSE_TIMEOUT) {
- return false;
- }
- i++;
- } while (!cmd_6byte_response (responseBuffer, SEND_STATUS, *RCA) && ((responseBuffer[3] & 0x1f) != ((SD_STATE_TRAN << 1) | READY_FOR_DATA)));
-
- return true;
-}
-
-
diff --git a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.h b/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.h
deleted file mode 100644
index 887160e293..0000000000
--- a/c/src/lib/libbsp/arm/nds/libfat/source/disc_io/io_sd_common.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- io_sd_common.h
-
- By chishm (Michael Chisholm)
-
- Common SD card routines
-
- SD routines partially based on sd.s by Romman
-
- Copyright (c) 2006 Michael "Chishm" Chisholm
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or
- other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- 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,
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- 2006-07-11 - Chishm
- * Original release
-
- 2006-07-28 - Chishm
- * Changed voltage range that the SD card can use
-
- 2006-11-14 - Chishm
- * Reduced voltage range again. Hopefully fixes MicroSD cards.
-*/
-
-#ifndef IO_SD_COMMON_H
-#define IO_SD_COMMON_H
-
-#include "disc_io.h"
-
-/* SD commands */
-#define GO_IDLE_STATE 0
-#define ALL_SEND_CID 2
-#define SEND_RELATIVE_ADDR 3
-#define SELECT_CARD 7
-#define SEND_CSD 9
-#define STOP_TRANSMISSION 12
-#define SEND_STATUS 13
-#define GO_INACTIVE_STATE 15
-#define SET_BLOCKLEN 16
-#define READ_SINGLE_BLOCK 17
-#define READ_MULTIPLE_BLOCK 18
-#define WRITE_BLOCK 24
-#define WRITE_MULTIPLE_BLOCK 25
-#define APP_CMD 55
-
-/* SD App commands */
-#define SET_BUS_WIDTH 6
-#define SD_APP_OP_COND 41
-
-/* OCR (Operating Conditions Register) send value */
-#define SD_OCR_VALUE 0x00030000 /* 2.8V to 3.0V */
-//#define SD_OCR_VALUE 0x003F8000 /* 2.7V to 3.4V */
-//#define SD_OCR_VALUE 0x00FC0000
-
-/* SD Data repsonses */
-#define SD_CARD_BUSY 0xff
-
-/* SD states */
-#define SD_STATE_IDLE 0 // Idle state, after power on or GO_IDLE_STATE command
-#define SD_STATE_READY 1 // Ready state, after card replies non-busy to SD_APP_OP_COND
-#define SD_STATE_IDENT 2 // Identification state, after ALL_SEND_CID
-#define SD_STATE_STBY 3 // Standby state, when card is deselected
-#define SD_STATE_TRAN 4 // Transfer state, after card is selected and ready for data transfer
-#define SD_STATE_DATA 5 //
-#define SD_STATE_RCV 6 // Receive data state
-#define SD_STATE_PRG 7 // Programming state
-#define SD_STATE_DIS 8 // Disconnect state
-#define SD_STATE_INA 9 // Inactive state, after GO_INACTIVE_STATE
-
-#define READY_FOR_DATA 1 // bit 8 in card status
-
-/*
-Calculate the CRC7 of a command and return it preshifted with
-an end bit added
-*/
-extern u8 _SD_CRC7(u8* data, int size);
-
-/*
-Calculate the CRC16 of a block of data, ready for transmission on
-four data lines at once
-*/
-extern void _SD_CRC16 (u8* buff, int buffLength, u8* crc16buff);
-
-typedef bool (*_SD_FN_CMD_6BYTE_RESPONSE) (u8* responseBuffer, u8 command, u32 data);
-typedef bool (*_SD_FN_CMD_17BYTE_RESPONSE) (u8* responseBuffer, u8 command, u32 data);
-
-/*
-Initialise the SD card, after it has been sent into an Idle state
-cmd_6byte_response: a pointer to a function that sends the SD card a command and gets a 6 byte response
-cmd_17byte_response: a pointer to a function that sends the SD card a command and gets a 17 byte response
-use4bitBus: initialise card to use a 4 bit data bus when communicating with the card
-RCA: a pointer to the location to store the card's Relative Card Address, preshifted up by 16 bits.
-*/
-extern bool _SD_InitCard (_SD_FN_CMD_6BYTE_RESPONSE cmd_6byte_response,
- _SD_FN_CMD_17BYTE_RESPONSE cmd_17byte_response,
- bool use4bitBus,
- u32 *RCA);
-
-#endif // define IO_SD_COMMON_H