APM:Libraries
diskio.c
Go to the documentation of this file.
1 #pragma GCC optimize ("O2")
2 
3 
4 /*-----------------------------------------------------------------------*/
5 /*
6 (c) 2017 night_ghost@ykoctpa.ru
7 
8 based on:
9 */
10 
11 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
12 /*-----------------------------------------------------------------------*/
13 /* If a working storage control module is available, it should be */
14 /* attached to the FatFs via a glue function rather than modifying it. */
15 /* This is an example of glue functions to attach various exsisting */
16 /* storage control modules to the FatFs module with a defined API. */
17 /*-----------------------------------------------------------------------*/
18 
19 #include "diskio.h" /* FatFs lower layer API */
20 #include "FatFs/drivers/sd.h"
21 
22 
23 /* Definitions of physical drive number for each drive */
24 #define DEV_SD 0
25 #define DEV_NODEV 1
26 
27 
28 /*-----------------------------------------------------------------------*/
29 /* Get Drive Status */
30 /*-----------------------------------------------------------------------*/
31 
33  BYTE pdrv /* Physical drive nmuber to identify the drive */
34 ){
35  switch (pdrv) {
36  case DEV_SD :
37  return sd_status();
38 
39  }
40  return STA_NOINIT;
41 }
42 
43 
44 
45 /*-----------------------------------------------------------------------*/
46 /* Inidialize a Drive */
47 /*-----------------------------------------------------------------------*/
48 
50  BYTE pdrv /* Physical drive nmuber to identify the drive */
51 ){
52 
53  switch (pdrv) {
54  case DEV_SD :
55  return sd_initialize();
56 
57  }
58  return STA_NOINIT;
59 }
60 
61 
62 
63 /*-----------------------------------------------------------------------*/
64 /* Read Sector(s) */
65 /*-----------------------------------------------------------------------*/
66 
68  BYTE pdrv, /* Physical drive nmuber to identify the drive */
69  BYTE *buff, /* Data buffer to store read data */
70  DWORD sector, /* Start sector in LBA */
71  UINT count /* Number of sectors to read */
72 )
73 {
74  switch (pdrv) {
75  case DEV_SD:
76 
77  return sd_read(buff, sector, count);
78 
79  }
80 
81  return RES_PARERR;
82 }
83 
84 
85 
86 /*-----------------------------------------------------------------------*/
87 /* Write Sector(s) */
88 /*-----------------------------------------------------------------------*/
89 
91  BYTE pdrv, /* Physical drive nmuber to identify the drive */
92  const BYTE *buff, /* Data to be written */
93  DWORD sector, /* Start sector in LBA */
94  UINT count /* Number of sectors to write */
95 )
96 {
97  switch (pdrv) {
98  case DEV_SD :
99  return sd_write(buff, sector, count);
100 
101  }
102 
103  return RES_PARERR;
104 }
105 
106 
107 
108 /*-----------------------------------------------------------------------*/
109 /* Miscellaneous Functions */
110 /*-----------------------------------------------------------------------*/
111 
113  BYTE pdrv, /* Physical drive nmuber (0..) */
114  BYTE cmd, /* Control code */
115  void *buff /* Buffer to send/receive control data */
116 )
117 {
118  switch (pdrv) {
119  case DEV_SD :
120 
121  return sd_ioctl(cmd, buff);
122 
123  }
124 
125  return RES_PARERR;
126 }
127 
#define STA_NOINIT
Definition: diskio.h:42
DRESULT sd_write(const uint8_t *buff, uint32_t sector, uint16_t count)
DRESULT sd_read(uint8_t *buff, uint32_t sector, uint16_t count)
DRESULT sd_ioctl(uint8_t cmd, void *buff)
DSTATUS sd_status()
unsigned long DWORD
Definition: integer.h:22
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
Definition: diskio.c:90
BYTE DSTATUS
Definition: diskio.h:17
DRESULT
Definition: diskio.h:20
unsigned char BYTE
Definition: integer.h:13
DSTATUS disk_status(BYTE pdrv)
Definition: diskio.c:32
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
Definition: diskio.c:112
DSTATUS sd_initialize()
DSTATUS disk_initialize(BYTE pdrv)
Definition: diskio.c:49
unsigned int UINT
Definition: integer.h:10
#define DEV_SD
Definition: diskio.c:24
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
Definition: diskio.c:67