sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
spi_sdcard_driver.h
Go to the documentation of this file.
1
5
#ifndef SPI_SDCARD_DRIVER_H
6
#define SPI_SDCARD_DRIVER_H
7
8
#include <
bdm.h
>
9
#include <stdint.h>
10
11
#define READ_TOKEN_TIMEOUT 4000
12
#define SECTOR_SIZE 512
13
14
#define CMD_ABORT_NO_READ_TOKEN 0x1
15
#define CMD_ABORT_CRC16_INVALID 0x2
16
#define CMD_ABORT_WRITE_ERROR 0x3
17
#define CMD_ABORT_UKNOWN_ERROR 0x7
18
19
typedef
enum
card_type_e {
20
CARD_TYPE_MMC = 0x00,
21
CARD_TYPE_SDV1 = 0x01,
22
CARD_TYPE_SDV2 = 0x02,
23
CARD_TYPE_SDV2HC = 0x04
24
} card_type_t;
25
26
typedef
enum
spisd_result_s {
27
SPISD_RESULT_OK = 0,
28
SPISD_RESULT_ERROR,
29
SPISD_RESULT_NO_CARD,
30
SPISD_RESULT_TIMEOUT,
31
} spisd_result_t;
32
33
/*
34
* START: structures copied from wisi's implementation
35
*/
36
struct
t_csdVer1
37
{
38
u8 reserved1 : 6;
39
u8 csd_structure : 2;
40
u8 taac : 8;
41
u8 nsac : 8;
42
u8 tran_speed : 8;
43
44
u16 cccHi : 8;
45
u16 read_bl_len : 4;
46
u16 cccLo : 4;
47
48
u32 c_sizeHi : 2;
49
u8 read_bl_partial : 1;
50
u8 write_blk_misalign : 1;
51
u8 read_blk_misalign : 1;
52
u8 dsr_imp : 1;
53
u8 reserved2 : 2;
54
55
u32 c_sizeMd : 8;
56
57
u32 c_sizeLo : 2;
58
u8 vdd_r_curr_max : 3;
59
u8 vdd_r_curr_min : 3;
60
61
u8 c_size_multHi : 2;
62
u8 vdd_w_curr_max : 3;
63
u8 vdd_w_curr_min : 3;
64
65
u8 c_size_multLo : 1;
66
// XXX: The folowing are not fixed to correct endianness!
67
u8 erase_blk_en : 1;
68
u8 sector_size_high : 6;
69
u8 sector_size_low : 1;
70
u8 wp_grp_size : 7;
71
u8 ep_grp_enable : 1;
72
u8 reserved5 : 2;
73
u8 r2w_factor : 3;
74
u8 write_bl_len_high : 2;
75
u8 write_bl_len_low : 2;
76
u8 write_bl_partial : 1;
77
u8 reserved6 : 5;
78
u8 file_format_group : 1;
79
u8 copy : 1;
80
u8 perm_write_protect : 1;
81
u8 tmp_write_protect : 1;
82
u8 file_format : 2;
83
u8 reserved7 : 2;
84
u8 crc : 7;
85
u8 fixedTo1 : 1;
86
}
__attribute__
((packed));
87
88
struct
t_csdVer2
89
{
90
u8 reserved1 : 6;
91
u8 csd_structure : 2;
92
u8 taac : 8;
93
u8 nsac : 8;
94
u8 tran_speed : 8;
95
96
u16 cccHi : 8;
97
u16 read_bl_len : 4;
98
u16 cccLo : 4;
99
100
// Not fixed!:
101
u8 read_bl_partial : 1;
102
u8 write_blk_misalign : 1;
103
u8 read_blk_misalign : 1;
104
u8 dsr_imp : 1;
105
u8 reserved2 : 4;
106
107
// fixed:
108
u32 c_sizeHi : 6;
109
u8 reserved3 : 2;
// I give up - this is far too unaligned...
110
// 79:58
111
u32 c_sizeMd : 8;
112
u32 c_sizeLo : 8;
// 16 22;
113
114
// Not fixed!:
115
u32 reserved4 : 1;
116
u8 erase_blk_en : 1;
117
u8 sector_size_high : 6;
118
u8 sector_size_low : 1;
119
u8 wp_grp_size : 7;
120
u8 ep_grp_enable : 1;
121
u8 reserved5 : 2;
122
u8 r2w_factor : 3;
123
u8 write_bl_len_high : 2;
124
u8 write_bl_len_low : 2;
125
u8 write_bl_partial : 1;
126
u8 reserved6 : 5;
127
u8 file_format_group : 1;
128
u8 copy : 1;
129
u8 perm_write_protect : 1;
130
u8 tmp_write_protect : 1;
131
u8 file_format : 2;
132
u8 reserved7 : 2;
133
u8 crc : 7;
134
u8 fixedTo1 : 1;
135
}
__attribute__
((packed));
136
/*
137
* END: structures copied from wisi's implementation
138
*/
139
140
typedef
struct
spisd_cid_t
141
{
/* Card Identification Data */
142
uint8_t ManufacturerID;
/* ManufacturerID */
143
uint16_t OEM_AppliID;
/* OEM/Application ID */
144
uint32_t ProdName1;
/* Product Name part1 */
145
uint8_t ProdName2;
/* Product Name part2*/
146
uint8_t ProdRev;
/* Product Revision */
147
uint32_t ProdSN;
/* Product Serial Number */
148
uint8_t Reserved1;
/* Reserved1 */
149
uint16_t ManufactDate;
/* Manufacturing Date */
150
uint8_t CID_CRC;
/* CID CRC */
151
}
spisd_cid_t
;
152
153
/* global struct for everything sdcard */
154
typedef
struct
spisd_t
155
{
156
uint8_t csd[16];
157
spisd_cid_t
cid;
158
card_type_t card_type;
159
uint8_t initialized;
160
uint8_t used;
161
}
spisd_t
;
162
163
/* globals */
164
extern
spisd_t
sdcard;
165
extern
struct
block_device
bd;
166
167
extern
uint16_t spisd_read_status_register();
168
169
/* init */
170
extern
int
spisd_init_card();
/* bring card up from identification mode to data-transfer mode */
171
extern
int
spisd_get_card_info();
/* get card info and reattach to bdm if card capacity changed */
172
extern
int
spisd_recover();
173
174
/* BDM functions */
175
extern
int
spisd_read(
struct
block_device
*bd, uint64_t sector,
void
*buffer, uint16_t
count
);
176
extern
int
spisd_write(
struct
block_device
*bd, uint64_t sector,
const
void
*buffer, uint16_t
count
);
177
extern
void
spisd_flush(
struct
block_device
*bd);
178
extern
int
spisd_stop(
struct
block_device
*bd);
179
180
181
#endif
bdm.h
__attribute__
Definition
gif_registers.h:40
block_device
Definition
bdm.h:23
spisd_cid_t
Definition
spi_sdcard_driver.h:141
spisd_t
Definition
spi_sdcard_driver.h:155
t_csdVer1
Definition
spi_sdcard_driver.h:37
t_csdVer2
Definition
spi_sdcard_driver.h:89
count
u32 count
start sector of fragmented bd/file
Definition
usbhdfsd-common.h:1
core
mx4sio_bd
src
spi_sdcard_driver.h
Generated by
1.18.0