1 | /*--------------------------------------------------------------------------------- |
---|
2 | $Id$ |
---|
3 | |
---|
4 | Copyright (C) 2005 |
---|
5 | Michael Noland (joat) |
---|
6 | Jason Rogers (dovoto) |
---|
7 | Dave Murphy (WinterMute) |
---|
8 | |
---|
9 | This software is provided 'as-is', without any express or implied |
---|
10 | warranty. In no event will the authors be held liable for any |
---|
11 | damages arising from the use of this software. |
---|
12 | |
---|
13 | Permission is granted to anyone to use this software for any |
---|
14 | purpose, including commercial applications, and to alter it and |
---|
15 | redistribute it freely, subject to the following restrictions: |
---|
16 | |
---|
17 | 1. The origin of this software must not be misrepresented; you |
---|
18 | must not claim that you wrote the original software. If you use |
---|
19 | this software in a product, an acknowledgment in the product |
---|
20 | documentation would be appreciated but is not required. |
---|
21 | 2. Altered source versions must be plainly marked as such, and |
---|
22 | must not be misrepresented as being the original software. |
---|
23 | 3. This notice may not be removed or altered from any source |
---|
24 | distribution. |
---|
25 | |
---|
26 | ---------------------------------------------------------------------------------*/ |
---|
27 | |
---|
28 | #ifndef NDS_CARD_INCLUDE |
---|
29 | #define NDS_CARD_INCLUDE |
---|
30 | |
---|
31 | |
---|
32 | #include "jtypes.h" |
---|
33 | |
---|
34 | // Card bus |
---|
35 | #define CARD_CR1 (*(vuint16*)0x040001A0) |
---|
36 | #define CARD_CR1H (*(vuint8*)0x040001A1) |
---|
37 | #define CARD_EEPDATA (*(vuint8*)0x040001A2) |
---|
38 | #define CARD_CR2 (*(vuint32*)0x040001A4) |
---|
39 | #define CARD_COMMAND ((vuint8*)0x040001A8) |
---|
40 | |
---|
41 | #define CARD_DATA_RD (*(vuint32*)0x04100010) |
---|
42 | |
---|
43 | #define CARD_1B0 (*(vuint32*)0x040001B0) |
---|
44 | #define CARD_1B4 (*(vuint32*)0x040001B4) |
---|
45 | #define CARD_1B8 (*(vuint16*)0x040001B8) |
---|
46 | #define CARD_1BA (*(vuint16*)0x040001BA) |
---|
47 | |
---|
48 | |
---|
49 | #define CARD_CR1_ENABLE 0x80 // in byte 1, i.e. 0x8000 |
---|
50 | #define CARD_CR1_IRQ 0x40 // in byte 1, i.e. 0x4000 |
---|
51 | |
---|
52 | |
---|
53 | // CARD_CR2 register: |
---|
54 | |
---|
55 | #define CARD_ACTIVATE (1<<31) // when writing, get the ball rolling |
---|
56 | // 1<<30 |
---|
57 | #define CARD_nRESET (1<<29) // value on the /reset pin (1 = high out, not a reset state, 0 = low out = in reset) |
---|
58 | #define CARD_28 (1<<28) // when writing |
---|
59 | #define CARD_27 (1<<27) // when writing |
---|
60 | #define CARD_26 (1<<26) |
---|
61 | #define CARD_22 (1<<22) |
---|
62 | #define CARD_19 (1<<19) |
---|
63 | #define CARD_ENCRYPTED (1<<14) // when writing, this command should be encrypted |
---|
64 | #define CARD_13 (1<<13) // when writing |
---|
65 | #define CARD_4 (1<<4) // when writing |
---|
66 | |
---|
67 | // 3 bits in b10..b8 indicate something |
---|
68 | // read bits |
---|
69 | #define CARD_BUSY (1<<31) // when reading, still expecting incomming data? |
---|
70 | #define CARD_DATA_READY (1<<23) // when reading, CARD_DATA_RD or CARD_DATA has another word of data and is good to go |
---|
71 | |
---|
72 | |
---|
73 | #ifdef __cplusplus |
---|
74 | extern "C" { |
---|
75 | #endif |
---|
76 | |
---|
77 | |
---|
78 | void cardWriteCommand(const uint8 * command); |
---|
79 | |
---|
80 | void cardPolledTransfer(uint32 flags, uint32 * destination, uint32 length, const uint8 * command); |
---|
81 | void cardStartTransfer(const uint8 * command, uint32 * destination, int channel, uint32 flags); |
---|
82 | uint32 cardWriteAndRead(const uint8 * command, uint32 flags); |
---|
83 | |
---|
84 | // These commands require the cart to not be initialized yet, which may mean the user |
---|
85 | // needs to eject and reinsert the cart or they will return random data. |
---|
86 | void cardRead00(uint32 address, uint32 * destination, uint32 length, uint32 flags); |
---|
87 | void cardReadHeader(uint8 * header); |
---|
88 | int cardReadID(uint32 flags); |
---|
89 | |
---|
90 | // Reads from the EEPROM |
---|
91 | void cardReadEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype); |
---|
92 | |
---|
93 | // Writes to the EEPROM. TYPE 3 EEPROM must be erased first (I think?) |
---|
94 | void cardWriteEeprom(uint32 address, uint8 *data, uint32 length, uint32 addrtype); |
---|
95 | |
---|
96 | // Returns the ID of the EEPROM chip? Doesn't work well, most chips give ff,ff |
---|
97 | // i = 0 or 1 |
---|
98 | uint8 cardEepromReadID(uint8 i); |
---|
99 | |
---|
100 | // Sends a command to the EEPROM |
---|
101 | uint8 cardEepromCommand(uint8 command, uint32 address); |
---|
102 | |
---|
103 | /* |
---|
104 | * -1:no card or no EEPROM |
---|
105 | * 0:unknown PassMe? |
---|
106 | * 1:TYPE 1 4Kbit(512Byte) EEPROM |
---|
107 | * 2:TYPE 2 64Kbit(8KByte)or 512kbit(64Kbyte) EEPROM |
---|
108 | * 3:TYPE 3 2Mbit(256KByte) FLASH MEMORY (some rare 4Mbit and 8Mbit chips also) |
---|
109 | */ |
---|
110 | int cardEepromGetType(void); |
---|
111 | |
---|
112 | // Returns the size in bytes of EEPROM |
---|
113 | uint32 cardEepromGetSize(void); |
---|
114 | |
---|
115 | // Erases the entire chip. TYPE 3 chips MUST be erased before writing to them. (I think?) |
---|
116 | void cardEepromChipErase(void); |
---|
117 | |
---|
118 | // Erases a single sector of the TYPE 3 chip |
---|
119 | void cardEepromSectorErase(uint32 address); |
---|
120 | |
---|
121 | #ifdef __cplusplus |
---|
122 | } |
---|
123 | #endif |
---|
124 | |
---|
125 | |
---|
126 | #endif |
---|
127 | |
---|