-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdcard.h
187 lines (156 loc) · 5.35 KB
/
sdcard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* P2000T-SDCARD is free software: *
* you can redistribute it and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* P2000T-SDCARD is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
**************************************************************************/
#ifndef _SDCARD_H
#define _SDCARD_H
#include <z80.h>
#include "terminal.h"
#include "memory.h"
/**
* Perform low-level operations on the SD-card. Note that all functions
* operate with two globally shared uint8 arrays:
*
* - _resp: response object for the commands
* - _sectorblock: for reading 512 byte blocks and their 2-byte checksums
*
* It is assumed that the contents of _sectorblock is only valid and
* useful directly after setting it
*/
// shared buffer object to store the data of a single sector on the SD card
extern uint8_t _resp8[5];
extern uint8_t _resp58[5];
extern uint8_t _flag_sdcard_mounted;
/**
* @brief Initialize the SD card in such a way that sectors can be read
* from the card
*
* Returns 0 on success and 1 on error
*/
uint8_t init_sdcard(void);
/******************************************************************************
* RECEIVE OPERATIONS
******************************************************************************/
/**
* Receive a response R1
*
* Uses a response buffer object to write data to
*/
uint8_t receive_R1(void) __z88dk_callee;
/******************************************************************************
* COMMAND OPERATIONS
******************************************************************************/
/**
* Open the command interface
*/
void open_command(void) __z88dk_callee;
/**
* Close the command interface
*/
void close_command(void) __z88dk_callee;
/**
* Send pulses to SD card to trigger a reset state
*/
void sdpulse(void) __z88dk_callee;
/**
* CMD0: Reset the SD Memory Card
*/
uint8_t cmd0(void) __z88dk_callee;
/**
* CMD8: Sends interface condition
*/
void cmd8(uint8_t *resp) __z88dk_fastcall;
/**
* CMD17: Read block
*/
uint8_t cmd17(uint32_t addr) __z88dk_fastcall;
/**
* CMD24: Write block
*/
uint8_t cmd24(uint32_t addr) __z88dk_fastcall;
/**
* CMD55: Next command is application specific command
*/
void cmd55(void) __z88dk_callee;
/**
* CMD58: Read OCR register
*/
void cmd58(uint8_t *resp) __z88dk_fastcall;
/**
* ACMD41: Send host capacity support information
*/
uint8_t acmd41(void) __z88dk_callee;
/******************************************************************************
* BLOCK OPERATIONS
******************************************************************************/
/**
* @brief Read a 512 byte block including 2 bytes checksum from SD card
*/
void read_block(void) __z88dk_callee;
/**
* @brief Copy the first 0x100 bytes immediately from SD to RAM while discarding
* all other data.
*
* @param ram_addr external memory address
*/
void fast_sd_to_ram_first_0x100(uint16_t ram_addr) __z88dk_callee;
/**
* @brief Copy the last 0x100 bytes immediately from SD to RAM while discarding
* all other data.
*
* @param ram_addr external memory address
*/
void fast_sd_to_ram_last_0x100(uint16_t ram_addr) __z88dk_callee;
/**
* @brief Copy all 0x200 bytes immediately from SD to external RAM.
*
* @param ram_addr external memory address
*/
void fast_sd_to_ram_full(uint16_t ram_addr) __z88dk_callee;
/**
* @brief Copy all 0x200 bytes immediately from SD to internal RAM.
*
* @param ram_addr external memory address
*/
void fast_sd_to_intram_full(uint16_t ram_addr) __z88dk_callee;
/**
* @brief Read a single 512-byte sector
*
* @param addr sector address
*/
uint8_t read_sector(uint32_t addr) __z88dk_fastcall;
/******************************************************************************
* I/O CONTROL
******************************************************************************/
/**
* Set the SD CS signal to low (activating the SD card)
*/
void sdcs_reset(void) __z88dk_callee;
/**
* Set the SD CS signal to high (deactivating the SD card)
*/
void sdcs_set(void) __z88dk_callee;
/**
* SDOUT is pulled low, pulling MISO low via a 10k resistor
*/
void sdout_set(void) __z88dk_callee;
/**
* SDOUT is pulled high, pulling MISO high via a 10k resistor
*/
void sdout_reset(void) __z88dk_callee;
#endif // _SDCARD_H