Use DMA for SCSI and SD card transfers for a massive performance boost.
[SCSI2SD-V6.git] / software / SCSI2SD / src / sd.h
1 //      Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
2 //
3 //      This file is part of SCSI2SD.
4 //
5 //      SCSI2SD is free software: you can redistribute it and/or modify
6 //      it under the terms of the GNU General Public License as published by
7 //      the Free Software Foundation, either version 3 of the License, or
8 //      (at your option) any later version.
9 //
10 //      SCSI2SD is distributed in the hope that it will be useful,
11 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //      GNU General Public License for more details.
14 //
15 //      You should have received a copy of the GNU General Public License
16 //      along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
17 #ifndef SD_H
18 #define SD_H
19
20 #define SD_SECTOR_SIZE 512
21
22 typedef enum
23 {
24         SD_GO_IDLE_STATE = 0,
25         SD_SEND_OP_COND = 1,
26         SD_SEND_IF_COND = 8, // SD V2
27         SD_SEND_CSD = 9,
28         SD_STOP_TRANSMISSION = 12,
29         SD_SEND_STATUS = 13,
30         SD_SET_BLOCKLEN = 16,
31         SD_READ_SINGLE_BLOCK = 17,
32         SD_READ_MULTIPLE_BLOCK = 18,
33         SD_APP_SET_WR_BLK_ERASE_COUNT = 23,
34         SD_APP_SEND_OP_COND = 41,
35         SD_APP_CMD = 55,
36         SD_READ_OCR = 58,
37         SD_CRC_ON_OFF = 59
38 } SD_CMD;
39
40 typedef enum
41 {
42         SD_R1_IDLE = 1,
43         SD_R1_ERASE_RESET = 2,
44         SD_R1_ILLEGAL = 4,
45         SD_R1_CRC = 8,
46         SD_R1_ERASE_SEQ = 0x10,
47         SD_R1_ADDRESS = 0x20,
48         SD_R1_PARAMETER = 0x40
49 } SD_R1;
50
51 typedef struct
52 {
53         int version; // SDHC = version 2.
54         int ccs; // Card Capacity Status. 1 = SDHC or SDXC
55         uint32 capacity; // in 512 byte blocks
56 } SdDevice;
57
58 extern SdDevice sdDev;
59
60 int sdInit(void);
61
62 void sdWriteMultiSectorPrep(void);
63 void sdWriteMultiSectorDMA(uint8_t* outputBuffer);
64 int sdWriteSectorDMAPoll();
65 void sdCompleteWrite(void);
66
67 void sdReadMultiSectorPrep(void);
68 void sdReadMultiSectorDMA(uint8_t* outputBuffer);
69 void sdReadSingleSectorDMA(uint32_t lba, uint8_t* outputBuffer);
70 int sdReadSectorDMAPoll();
71 void sdCompleteRead(void);
72
73 #endif