00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef NDS_CARD_INCLUDE
00028 #define NDS_CARD_INCLUDE
00029
00030
00031 #include "ndstypes.h"
00032
00033
00034 #define CARD_CR1 (*(vuint16*)0x040001A0)
00035 #define CARD_CR1H (*(vuint8*)0x040001A1)
00036 #define CARD_EEPDATA (*(vuint8*)0x040001A2)
00037 #define CARD_CR2 (*(vuint32*)0x040001A4)
00038 #define CARD_COMMAND ((vuint8*)0x040001A8)
00039
00040 #define CARD_DATA_RD (*(vuint32*)0x04100010)
00041
00042 #define CARD_1B0 (*(vuint32*)0x040001B0)
00043 #define CARD_1B4 (*(vuint32*)0x040001B4)
00044 #define CARD_1B8 (*(vuint16*)0x040001B8)
00045 #define CARD_1BA (*(vuint16*)0x040001BA)
00046
00047
00048 #define CARD_CR1_ENABLE 0x80 // in byte 1, i.e. 0x8000
00049 #define CARD_CR1_IRQ 0x40 // in byte 1, i.e. 0x4000
00050
00051
00052
00053
00054 #define CARD_ACTIVATE (1<<31) // when writing, get the ball rolling
00055 #define CARD_WR (1<<30) // Card write enable
00056 #define CARD_nRESET (1<<29) // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset)
00057 #define CARD_SEC_LARGE (1<<28) // Use "other" secure area mode, which tranfers blocks of 0x1000 bytes at a time
00058 #define CARD_CLK_SLOW (1<<27) // Transfer clock rate (0 = 6.7MHz, 1 = 4.2MHz)
00059 #define CARD_BLK_SIZE(n) (((n)&0x7)<<24) // Transfer block size, (0 = None, 1..6 = (0x100 << n) bytes, 7 = 4 bytes)
00060 #define CARD_SEC_CMD (1<<22) // The command transfer will be hardware encrypted (KEY2)
00061 #define CARD_DELAY2(n) (((n)&0x3F)<<16) // Transfer delay length part 2
00062 #define CARD_SEC_SEED (1<<15) // Apply encryption (KEY2) seed to hardware registers
00063 #define CARD_SEC_EN (1<<14) // Security enable
00064 #define CARD_SEC_DAT (1<<13) // The data transfer will be hardware encrypted (KEY2)
00065 #define CARD_DELAY1(n) ((n)&0x1FFF) // Transfer delay length part 1
00066
00067
00068
00069 #define CARD_BUSY (1<<31) // when reading, still expecting incomming data?
00070 #define CARD_DATA_READY (1<<23) // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go
00071
00072
00073 #define CARD_CMD_DUMMY 0x9F
00074 #define CARD_CMD_HEADER_READ 0x00
00075 #define CARD_CMD_HEADER_CHIPID 0x90
00076 #define CARD_CMD_ACTIVATE_BF 0x3C // Go into blowfish (KEY1) encryption mode
00077 #define CARD_CMD_ACTIVATE_SEC 0x40 // Go into hardware (KEY2) encryption mode
00078 #define CARD_CMD_SECURE_CHIPID 0x10
00079 #define CARD_CMD_SECURE_READ 0x20
00080 #define CARD_CMD_DISABLE_SEC 0x60 // Leave hardware (KEY2) encryption mode
00081 #define CARD_CMD_DATA_MODE 0xA0
00082 #define CARD_CMD_DATA_READ 0xB7
00083 #define CARD_CMD_DATA_CHIPID 0xB8
00084
00085
00086 #ifdef __cplusplus
00087 extern "C" {
00088 #endif
00089
00090
00091 void cardWriteCommand(const uint8 *command);
00092 void cardPolledTransfer(uint32 flags, uint32 *destination, uint32 length, const uint8 *command);
00093 void cardStartTransfer(const uint8 *command, uint32 *destination, int channel, uint32 flags);
00094 uint32 cardWriteAndRead(const uint8 *command, uint32 flags);
00095 void cardParamCommand (uint8 command, uint32 parameter, uint32 flags, uint32 *destination, uint32 length);
00096
00097
00098
00099 void cardReadHeader(uint8 *header);
00100 uint32 cardReadID(uint32 flags);
00101
00102
00103 void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
00104
00105
00106 void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype);
00107
00108
00109
00110 uint8 cardEepromReadID(uint8 i);
00111
00112
00113 uint8 cardEepromCommand(uint8 command, uint32 address);
00114
00115
00116
00117
00118
00119
00120
00121
00122 int cardEepromGetType(void);
00123
00124
00125 uint32 cardEepromGetSize();
00126
00127
00128 void cardEepromChipErase(void);
00129
00130
00131 void cardEepromSectorErase(uint32 address);
00132
00133 #ifdef __cplusplus
00134 }
00135 #endif
00136
00137
00138 #endif
00139