altos: Increase SD card timeout at startup time
[fw/altos] / src / drivers / ao_sdcard.h
1 /*
2  * Copyright © 2013 Keith Packard <keithp@keithp.com>
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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #ifndef _AO_SDCARD_H_
19 #define _AO_SDCARD_H_
20
21 uint8_t
22 ao_sdcard_read_block(uint32_t block, uint8_t *data);
23
24 uint8_t
25 ao_sdcard_write_block(uint32_t block, uint8_t *data);
26
27 void
28 ao_sdcard_init(void);
29
30 /* Commands */
31 #define SDCARD_GO_IDLE_STATE            0
32 #define SDCARD_SEND_OP_COND             1
33 #define SDCARD_SEND_IF_COND             8
34 #define SDCARD_SEND_CSD                 9
35 #define SDCARD_SEND_CID                 10
36 #define SDCARD_SEND_STATUS              13
37 #define SDCARD_SET_BLOCKLEN             16
38 #define SDCARD_READ_BLOCK               17
39 #define SDCARD_WRITE_BLOCK              24
40 #define SDCARD_WRITE_MULTIPLE_BLOCK     25
41 #define SDCARD_ERASE_WR_BLK_START       32
42 #define SDCARD_ERASE_WR_BLK_END         33
43 #define SDCARD_ERASE                    38
44 #define SDCARD_APP_CMD                  55
45 #define SDCARD_READ_OCR                 58
46
47 /* App commands */
48 #define SDCARD_APP_SET_WR_BLK_ERASE_COUNT       23
49 #define SDCARD_APP_SEND_OP_COMD                 41
50
51 /* Status */
52 #define SDCARD_STATUS_READY_STATE       0
53 #define SDCARD_STATUS_IDLE_STATE        1
54 #define SDCARD_STATUS_ILLEGAL_COMMAND   4
55 #define SDCARD_STATUS_TIMEOUT           0xff
56
57 #define SDCARD_DATA_START_BLOCK         0xfe
58 #define SDCARD_STOP_TRAN_TOKEN          0xfd
59 #define SDCARD_WRITE_MULTIPLE_TOKEN     0xfc
60 #define SDCARD_DATA_RES_MASK            0x1f
61 #define SDCARD_DATA_RES_ACCEPTED        0x05
62
63 #define SDCARD_CMD_TIMEOUT              100
64 #define SDCARD_IDLE_WAIT                1000
65 #define SDCARD_BLOCK_TIMEOUT            100
66 #define SDCARD_IDLE_TIMEOUT             1000
67
68 enum ao_sdtype {
69         ao_sdtype_unknown,
70         ao_sdtype_mmc3,
71         ao_sdtype_sd1,
72         ao_sdtype_sd2byte,
73         ao_sdtype_sd2block,
74 };
75
76 #endif /* _AO_SDCARD_H_ */