Prusa MINI Firmware overview
onboard_sd.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------
2 / * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3 / * Copyright (c) 2019 BigTreeTech [https://github.com/bigtreetech]
4 / * Low level disk interface module include file (C)ChaN, 2015
5 /-----------------------------------------------------------------------*/
6 
7 #pragma once
8 
9 #define _DISKIO_WRITE 1 /* 1: Enable disk_write function */
10 #define _DISKIO_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
11 #define _DISKIO_ISDIO 0 /* 1: Enable iSDIO control fucntion */
12 
13 typedef unsigned char BYTE;
14 typedef unsigned short WORD;
15 typedef unsigned long DWORD;
16 typedef unsigned int UINT;
17 
18 /* Status of Disk Functions */
19 typedef BYTE DSTATUS;
20 
21 /* Results of Disk Functions */
22 typedef enum {
23  RES_OK = 0, /* 0: Successful */
24  RES_ERROR, /* 1: R/W Error */
25  RES_WRPRT, /* 2: Write Protected */
26  RES_NOTRDY, /* 3: Not Ready */
27  RES_PARERR /* 4: Invalid Parameter */
28 } DRESULT;
29 
30 
31 #if _DISKIO_ISDIO
32 /* Command structure for iSDIO ioctl command */
33 typedef struct {
34  BYTE func; /* Function number: 0..7 */
35  WORD ndata; /* Number of bytes to transfer: 1..512, or mask + data */
36  DWORD addr; /* Register address: 0..0x1FFFF */
37  void* data; /* Pointer to the data (to be written | read buffer) */
38 } SDIO_CMD;
39 #endif
40 
41 /*---------------------------------------*/
42 /* Prototypes for disk control functions */
43 
46 DRESULT disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
47 #if _DISKIO_WRITE
48  DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
49 #endif
50 #if _DISKIO_IOCTL
51  DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff);
52 #endif
53 
54 /* Disk Status Bits (DSTATUS) */
55 #define STA_NOINIT 0x01 /* Drive not initialized */
56 #define STA_NODISK 0x02 /* No medium in the drive */
57 #define STA_PROTECT 0x04 /* Write protected */
58 
59 /* Command code for disk_ioctrl fucntion */
60 
61 /* Generic command (Used by FatFs) */
62 #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
63 #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
64 #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
65 #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
66 #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
67 
68 /* Generic command (Not used by FatFs) */
69 #define CTRL_FORMAT 5 /* Create physical format on the media */
70 #define CTRL_POWER_IDLE 6 /* Put the device idle state */
71 #define CTRL_POWER_OFF 7 /* Put the device off state */
72 #define CTRL_LOCK 8 /* Lock media removal */
73 #define CTRL_UNLOCK 9 /* Unlock media removal */
74 #define CTRL_EJECT 10 /* Eject media */
75 
76 /* MMC/SDC specific ioctl command (Not used by FatFs) */
77 #define MMC_GET_TYPE 50 /* Get card type */
78 #define MMC_GET_CSD 51 /* Get CSD */
79 #define MMC_GET_CID 52 /* Get CID */
80 #define MMC_GET_OCR 53 /* Get OCR */
81 #define MMC_GET_SDSTAT 54 /* Get SD status */
82 #define ISDIO_READ 55 /* Read data form SD iSDIO register */
83 #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
84 #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
85 
86 /* ATA/CF specific ioctl command (Not used by FatFs) */
87 #define ATA_GET_REV 60 /* Get F/W revision */
88 #define ATA_GET_MODEL 61 /* Get model name */
89 #define ATA_GET_SN 62 /* Get serial number */
90 
91 /* MMC card type flags (MMC_GET_TYPE) */
92 #define CT_MMC 0x01 /* MMC ver 3 */
93 #define CT_SD1 0x02 /* SD ver 1 */
94 #define CT_SD2 0x04 /* SD ver 2 */
95 #define CT_SDC (CT_SD1|CT_SD2) /* SD */
96 #define CT_BLOCK 0x08 /* Block addressing */
STA_NOINIT
#define STA_NOINIT
Definition: onboard_sd.h:55
GET_SECTOR_COUNT
#define GET_SECTOR_COUNT
Definition: onboard_sd.h:63
RES_PARERR
Definition: onboard_sd.h:27
CMD33
const uint8_t CMD33
Definition: SdInfo.h:56
OUT_WRITE
#define OUT_WRITE(IO, V)
Definition: fastio.h:108
MMC_GET_OCR
#define MMC_GET_OCR
Definition: onboard_sd.h:80
MMC_GET_CSD
#define MMC_GET_CSD
Definition: onboard_sd.h:78
RES_WRPRT
Definition: onboard_sd.h:25
CMD8
const uint8_t CMD8
Definition: SdInfo.h:46
ONBOARD_SD_CS_PIN
#define ONBOARD_SD_CS_PIN
Definition: pins_AZSMZ_MINI.h:90
disk_initialize
DSTATUS disk_initialize(BYTE pdrv)
Initializes a Drive.
Definition: diskio.c:91
CT_SD1
#define CT_SD1
Definition: onboard_sd.h:93
RES_ERROR
Definition: onboard_sd.h:24
WORD
unsigned short WORD
Definition: onboard_sd.h:14
data
uint8_t data[8]
Definition: masstorage.h:49
ON_BOARD_SPI_DEVICE
#define ON_BOARD_SPI_DEVICE
Definition: pins_BIGTREE_SKR_E3_DIP.h:206
disk_read
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
Reads Sector(s)
Definition: diskio.c:113
CMD18
const uint8_t CMD18
Definition: SdInfo.h:52
SPI_MODE0
#define SPI_MODE0
Definition: SPI.h:29
CMD0
const uint8_t CMD0
Definition: SdInfo.h:45
millis
uint32_t millis(void)
Definition: wiring_time.c:29
CT_SDC
#define CT_SDC
Definition: onboard_sd.h:95
CMD17
const uint8_t CMD17
Definition: SdInfo.h:51
MMC_GET_SDSTAT
#define MMC_GET_SDSTAT
Definition: onboard_sd.h:81
MMC_GET_CID
#define MMC_GET_CID
Definition: onboard_sd.h:79
STA_PROTECT
#define STA_PROTECT
Definition: onboard_sd.h:57
CMD58
const uint8_t CMD58
Definition: SdInfo.h:59
CT_MMC
#define CT_MMC
Definition: onboard_sd.h:92
ISDIO_MRITE
#define ISDIO_MRITE
Definition: onboard_sd.h:84
CMD12
const uint8_t CMD12
Definition: SdInfo.h:49
STA_NODISK
#define STA_NODISK
Definition: onboard_sd.h:56
RES_OK
Definition: onboard_sd.h:23
disk_status
DSTATUS disk_status(BYTE pdrv)
Gets Disk Status.
Definition: diskio.c:76
MSBFIRST
Definition: wiring_constants.h:67
DSTATUS
BYTE DSTATUS
Definition: onboard_sd.h:19
MMC_GET_TYPE
#define MMC_GET_TYPE
Definition: onboard_sd.h:77
CMD9
const uint8_t CMD9
Definition: SdInfo.h:47
disk_write
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
Writes Sector(s)
Definition: diskio.c:135
onboard_sd.h
CMD32
const uint8_t CMD32
Definition: SdInfo.h:55
CT_BLOCK
#define CT_BLOCK
Definition: onboard_sd.h:96
disk_ioctl
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
I/O control operation.
Definition: diskio.c:157
DWORD
unsigned long DWORD
Definition: onboard_sd.h:15
ISDIO_READ
#define ISDIO_READ
Definition: onboard_sd.h:82
CT_SD2
#define CT_SD2
Definition: onboard_sd.h:94
CMD24
const uint8_t CMD24
Definition: SdInfo.h:53
HIGH
#define HIGH
Definition: wiring_constants.h:71
CMD10
const uint8_t CMD10
Definition: SdInfo.h:48
CMD25
const uint8_t CMD25
Definition: SdInfo.h:54
GET_BLOCK_SIZE
#define GET_BLOCK_SIZE
Definition: onboard_sd.h:65
BYTE
unsigned char BYTE
Definition: onboard_sd.h:13
DRESULT
DRESULT
Definition: onboard_sd.h:22
ISDIO_WRITE
#define ISDIO_WRITE
Definition: onboard_sd.h:83
CTRL_TRIM
#define CTRL_TRIM
Definition: onboard_sd.h:66
CMD55
const uint8_t CMD55
Definition: SdInfo.h:58
CMD38
const uint8_t CMD38
Definition: SdInfo.h:57
SPIClass
Wirish SPI interface.
Definition: SPI.h:63
ACMD23
const uint8_t ACMD23
Definition: SdInfo.h:61
ACMD41
const uint8_t ACMD41
Definition: SdInfo.h:62
RES_NOTRDY
Definition: onboard_sd.h:26
UINT
unsigned int UINT
Definition: onboard_sd.h:16
CTRL_SYNC
#define CTRL_SYNC
Definition: onboard_sd.h:62