altos/test: Adjust CRC error rate after FEC fix
[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; either version 2 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, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_SDCARD_H_
20 #define _AO_SDCARD_H_
21
22 uint8_t
23 ao_sdcard_read_block(uint32_t block, uint8_t *data);
24
25 uint8_t
26 ao_sdcard_write_block(uint32_t block, uint8_t *data);
27
28 void
29 ao_sdcard_init(void);
30
31 /* Commands */
32 #define SDCARD_GO_IDLE_STATE            0
33 #define SDCARD_SEND_OP_COND             1
34 #define SDCARD_SEND_IF_COND             8
35 #define SDCARD_SEND_CSD                 9
36 #define SDCARD_SEND_CID                 10
37 #define SDCARD_SEND_STATUS              13
38 #define SDCARD_SET_BLOCKLEN             16
39 #define SDCARD_READ_BLOCK               17
40 #define SDCARD_WRITE_BLOCK              24
41 #define SDCARD_WRITE_MULTIPLE_BLOCK     25
42 #define SDCARD_ERASE_WR_BLK_START       32
43 #define SDCARD_ERASE_WR_BLK_END         33
44 #define SDCARD_ERASE                    38
45 #define SDCARD_APP_CMD                  55
46 #define SDCARD_READ_OCR                 58
47
48 /* App commands */
49 #define SDCARD_APP_SET_WR_BLK_ERASE_COUNT       23
50 #define SDCARD_APP_SEND_OP_COMD                 41
51
52 /* Status */
53 #define SDCARD_STATUS_READY_STATE       0x00
54 #define SDCARD_STATUS_IDLE_STATE        0x01
55 #define SDCARD_STATUS_ERASE_RESET       0x02
56 #define SDCARD_STATUS_ILLEGAL_COMMAND   0x04
57 #define SDCARD_STATUS_COM_CRC_ERROR     0x08
58 #define SDCARD_STATUS_ERASE_SEQ_ERROR   0x10
59 #define SDCARD_STATUS_ADDRESS_ERROR     0x20
60 #define SDCARD_STATUS_PARAMETER_ERROR   0x40
61 #define SDCARD_STATUS_TIMEOUT           0xff
62
63 #define SDCARD_DATA_START_BLOCK         0xfe
64 #define SDCARD_STOP_TRAN_TOKEN          0xfd
65 #define SDCARD_WRITE_MULTIPLE_TOKEN     0xfc
66 #define SDCARD_DATA_RES_MASK            0x1f
67 #define SDCARD_DATA_RES_ACCEPTED        0x05
68
69 #define SDCARD_CMD_TIMEOUT              AO_MS_TO_TICKS(20)
70 #define SDCARD_BUSY_TIMEOUT             AO_MS_TO_TICKS(20)
71 #define SDCARD_BLOCK_TIMEOUT            AO_MS_TO_TICKS(200)
72 #define SDCARD_IDLE_RETRY               10
73 #define SDCARD_OP_COND_RETRY            10
74
75 enum ao_sdtype {
76         ao_sdtype_unknown,
77         ao_sdtype_mmc3,
78         ao_sdtype_sd1,
79         ao_sdtype_sd2byte,
80         ao_sdtype_sd2block,
81 };
82
83 #endif /* _AO_SDCARD_H_ */