1 /*
2 Copyright (c) 2015 Fabio Belavenuto & Victor Trucco
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef MMC_H
19 #define MMC_H
20 
21 #include <arch/zxn.h>
22 
23 #define CARDTYPE_NONE 0
24 #define CARDTYPE_MMC  1
25 #define CARDTYPE_SD   2
26 #define CARDTYPE_SDHC 3
27 
28 #define EnableCard()  (IO_SPI_CONTROL = 0xFE)
29 #define DisableCard() (IO_SPI_CONTROL = 0xFF)
30 
31 #define SPI_slow()
32 #define SPI_fast()
33 
34 // MMC commandset
35 
36 #define     CMD0        0x40        /*Resets the multimedia card*/
37 #define     CMD1        0x41        /*Activates the card's initialization process*/
38 #define     CMD2        0x42        /*--*/
39 #define     CMD3        0x43        /*--*/
40 #define     CMD4        0x44        /*--*/
41 #define     CMD5        0x45        /*reseved*/
42 #define     CMD6        0x46        /*reserved*/
43 #define     CMD7        0x47        /*--*/
44 #define     CMD8        0x48        /*reserved*/
45 #define     CMD9        0x49        /*CSD : Ask the selected card to send its card specific data*/
46 #define     CMD10       0x4a        /*CID : Ask the selected card to send its card identification*/
47 #define     CMD11       0x4b        /*--*/
48 #define     CMD12       0x4c        /*--*/
49 #define     CMD13       0x4d        /*Ask the selected card to send its status register*/
50 #define     CMD14       0x4e        /*--*/
51 #define     CMD15       0x4f        /*--*/
52 #define     CMD16       0x50        /*Select a block length (in bytes) for all following block commands (Read:between 1-512 and Write:only 512)*/
53 #define     CMD17       0x51        /*Reads a block of the size selected by the SET_BLOCKLEN command, the start address and block length must be set so that the data transferred will not cross a physical block boundry*/
54 #define     CMD18       0x52        /*--*/
55 #define     CMD19       0x53        /*reserved*/
56 #define     CMD20       0x54        /*--*/
57 #define     CMD21       0x55        /*reserved*/
58 #define     CMD22       0x56        /*reserved*/
59 #define     CMD23       0x57        /*reserved*/
60 #define     CMD24       0x58        /*Writes a block of the size selected by CMD16, the start address must be alligned on a sector boundry, the block length is always 512 bytes*/
61 #define     CMD25       0x59        /*--*/
62 #define     CMD26       0x5a        /*--*/
63 #define     CMD27       0x5b        /*Programming of the programmable bits of the CSD*/
64 #define     CMD28       0x5c        /*If the card has write protection features, this command sets the write protection bit of the addressed group. The porperties of the write protection are coded in the card specific data (WP_GRP_SIZE)*/
65 #define     CMD29       0x5d        /*If the card has write protection features, this command clears the write protection bit of the addressed group*/
66 #define     CMD30       0x5e        /*If the card has write protection features, this command asks the card to send the status of the write protection bits. 32 write protection bits (representing 32 write protect groups starting at the specific address) followed by 16 CRD bits are transferred in a payload format via the data line*/
67 #define     CMD31       0x5f        /*reserved*/
68 #define     CMD32       0x60        /*sets the address of the first sector of the erase group*/
69 #define     CMD33       0x61        /*Sets the address of the last sector in a cont. range within the selected erase group, or the address of a single sector to be selected for erase*/
70 #define     CMD34       0x62        /*Removes on previously selected sector from the erase selection*/
71 #define     CMD35       0x63        /*Sets the address of the first erase group within a range to be selected for erase*/
72 #define     CMD36       0x64        /*Sets the address of the last erase group within a continuos range to be selected for erase*/
73 #define     CMD37       0x65        /*Removes one previously selected erase group from the erase selection*/
74 #define     CMD38       0x66        /*Erases all previously selected sectors*/
75 #define     CMD39       0x67        /*--*/
76 #define     CMD40       0x68        /*--*/
77 #define     CMD41       0x69        /*reserved*/
78 #define     CMD42       0x6a        /*reserved*/
79 #define     CMD43       0x6b        /*reserved*/
80 #define     CMD44       0x6c        /*reserved*/
81 #define     CMD45       0x6d        /*reserved*/
82 #define     CMD46       0x6e        /*reserved*/
83 #define     CMD47       0x6f        /*reserved*/
84 #define     CMD48       0x70        /*reserved*/
85 #define     CMD49       0x71        /*reserved*/
86 #define     CMD50       0x72        /*reserved*/
87 #define     CMD51       0x73        /*reserved*/
88 #define     CMD52       0x74        /*reserved*/
89 #define     CMD53       0x75        /*reserved*/
90 #define     CMD54       0x76        /*reserved*/
91 #define     CMD55       0x77        /*reserved*/
92 #define     CMD56       0x78        /*reserved*/
93 #define     CMD57       0x79        /*reserved*/
94 #define     CMD58       0x7a        /*reserved*/
95 #define     CMD59       0x7b        /*Turns the CRC option ON or OFF. A '1' in the CRC option bit will turn the option ON, a '0' will turn it OFF*/
96 #define     CMD60       0x7c        /*--*/
97 #define     CMD61       0x7d        /*--*/
98 #define     CMD62       0x7e        /*--*/
99 #define     CMD63       0x7f        /*--*/
100 
101 unsigned char MMC_Init(void);
102 unsigned char MMC_Read(unsigned long lba, unsigned char *pReadBuffer) __z88dk_callee;
103 
104 #endif
105