root / hw / sd.h @ beb811bd
History | View | Annotate | Download (2.9 kB)
1 | a1bb27b1 | pbrook | /*
|
---|---|---|---|
2 | a1bb27b1 | pbrook | * SD Memory Card emulation. Mostly correct for MMC too.
|
3 | a1bb27b1 | pbrook | *
|
4 | a1bb27b1 | pbrook | * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
|
5 | a1bb27b1 | pbrook | *
|
6 | a1bb27b1 | pbrook | * Redistribution and use in source and binary forms, with or without
|
7 | a1bb27b1 | pbrook | * modification, are permitted provided that the following conditions
|
8 | a1bb27b1 | pbrook | * are met:
|
9 | a1bb27b1 | pbrook | *
|
10 | a1bb27b1 | pbrook | * 1. Redistributions of source code must retain the above copyright
|
11 | a1bb27b1 | pbrook | * notice, this list of conditions and the following disclaimer.
|
12 | a1bb27b1 | pbrook | * 2. Redistributions in binary form must reproduce the above copyright
|
13 | a1bb27b1 | pbrook | * notice, this list of conditions and the following disclaimer in
|
14 | a1bb27b1 | pbrook | * the documentation and/or other materials provided with the
|
15 | a1bb27b1 | pbrook | * distribution.
|
16 | a1bb27b1 | pbrook | *
|
17 | a1bb27b1 | pbrook | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
|
18 | a1bb27b1 | pbrook | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
19 | a1bb27b1 | pbrook | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
20 | a1bb27b1 | pbrook | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
21 | a1bb27b1 | pbrook | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
22 | a1bb27b1 | pbrook | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
23 | a1bb27b1 | pbrook | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
24 | a1bb27b1 | pbrook | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
25 | a1bb27b1 | pbrook | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26 | a1bb27b1 | pbrook | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27 | a1bb27b1 | pbrook | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 | a1bb27b1 | pbrook | */
|
29 | a1bb27b1 | pbrook | #ifndef __hw_sd_h
|
30 | a1bb27b1 | pbrook | #define __hw_sd_h 1 |
31 | a1bb27b1 | pbrook | |
32 | a1bb27b1 | pbrook | #include <vl.h> |
33 | a1bb27b1 | pbrook | |
34 | a1bb27b1 | pbrook | #define OUT_OF_RANGE (1 << 31) |
35 | a1bb27b1 | pbrook | #define ADDRESS_ERROR (1 << 30) |
36 | a1bb27b1 | pbrook | #define BLOCK_LEN_ERROR (1 << 29) |
37 | a1bb27b1 | pbrook | #define ERASE_SEQ_ERROR (1 << 28) |
38 | a1bb27b1 | pbrook | #define ERASE_PARAM (1 << 27) |
39 | a1bb27b1 | pbrook | #define WP_VIOLATION (1 << 26) |
40 | a1bb27b1 | pbrook | #define CARD_IS_LOCKED (1 << 25) |
41 | a1bb27b1 | pbrook | #define LOCK_UNLOCK_FAILED (1 << 24) |
42 | a1bb27b1 | pbrook | #define COM_CRC_ERROR (1 << 23) |
43 | a1bb27b1 | pbrook | #define ILLEGAL_COMMAND (1 << 22) |
44 | a1bb27b1 | pbrook | #define CARD_ECC_FAILED (1 << 21) |
45 | a1bb27b1 | pbrook | #define CC_ERROR (1 << 20) |
46 | a1bb27b1 | pbrook | #define SD_ERROR (1 << 19) |
47 | a1bb27b1 | pbrook | #define CID_CSD_OVERWRITE (1 << 16) |
48 | a1bb27b1 | pbrook | #define WP_ERASE_SKIP (1 << 15) |
49 | a1bb27b1 | pbrook | #define CARD_ECC_DISABLED (1 << 14) |
50 | a1bb27b1 | pbrook | #define ERASE_RESET (1 << 13) |
51 | a1bb27b1 | pbrook | #define CURRENT_STATE (7 << 9) |
52 | a1bb27b1 | pbrook | #define READY_FOR_DATA (1 << 8) |
53 | a1bb27b1 | pbrook | #define APP_CMD (1 << 5) |
54 | a1bb27b1 | pbrook | #define AKE_SEQ_ERROR (1 << 3) |
55 | a1bb27b1 | pbrook | |
56 | a1bb27b1 | pbrook | typedef enum { |
57 | a1bb27b1 | pbrook | sd_none = -1,
|
58 | a1bb27b1 | pbrook | sd_bc = 0, /* broadcast -- no response */ |
59 | a1bb27b1 | pbrook | sd_bcr, /* broadcast with response */
|
60 | a1bb27b1 | pbrook | sd_ac, /* addressed -- no data transfer */
|
61 | a1bb27b1 | pbrook | sd_adtc, /* addressed with data transfer */
|
62 | a1bb27b1 | pbrook | } sd_cmd_type_t; |
63 | a1bb27b1 | pbrook | |
64 | a1bb27b1 | pbrook | struct sd_request_s {
|
65 | a1bb27b1 | pbrook | uint8_t cmd; |
66 | a1bb27b1 | pbrook | uint32_t arg; |
67 | a1bb27b1 | pbrook | uint8_t crc; |
68 | a1bb27b1 | pbrook | }; |
69 | a1bb27b1 | pbrook | |
70 | a1bb27b1 | pbrook | typedef struct SDState SDState; |
71 | a1bb27b1 | pbrook | |
72 | a1bb27b1 | pbrook | SDState *sd_init(BlockDriverState *bs); |
73 | a1bb27b1 | pbrook | int sd_do_command(SDState *sd, struct sd_request_s *req, |
74 | a1bb27b1 | pbrook | uint8_t *response); |
75 | a1bb27b1 | pbrook | void sd_write_data(SDState *sd, uint8_t value);
|
76 | a1bb27b1 | pbrook | uint8_t sd_read_data(SDState *sd); |
77 | a1bb27b1 | pbrook | void sd_set_cb(SDState *sd, void *opaque, |
78 | a1bb27b1 | pbrook | void (*readonly_cb)(void *, int), |
79 | a1bb27b1 | pbrook | void (*inserted_cb)(void *, int)); |
80 | a1bb27b1 | pbrook | int sd_data_ready(SDState *sd);
|
81 | a1bb27b1 | pbrook | |
82 | a1bb27b1 | pbrook | #endif /* __hw_sd_h */ |