| RTOS_MSPM0 1.1 ECE445M starter code

eDisk.h
Go to the documentation of this file.
1
17 /*-----------------------------------------------------------------------
18 / Low level disk interface modlue include file R0.04a (C)ChaN, 2007
19 /-----------------------------------------------------------------------
20 * Modified by Jonathan Valvano to simplify usage in Lab 4
21
22 */
23 #ifndef _DISKIO
24
28 #define _USE_WRITE 1
32 #define _USE_IOCTL 1
33
34 typedef signed int INT;
35 typedef unsigned int UINT;
36
37 /* These types are assumed as 8-bit integer */
38 typedef signed char CHAR;
39 typedef unsigned char UCHAR;
40 typedef unsigned char BYTE;
41
42 /* These types are assumed as 16-bit integer */
43 typedef signed short SHORT;
44 typedef unsigned short USHORT;
45 typedef unsigned short WORD;
46
47 /* These types are assumed as 32-bit integer */
48 typedef signed long LONG;
49 typedef unsigned long ULONG;
50 typedef unsigned long DWORD;
51
52
56 typedef enum { FALSE = 0, TRUE } BOOL;
57
61 typedef BYTE DSTATUS;
62
63 /* Results of Disk Functions */
64 typedef enum {
65 RES_OK = 0, /* 0: Successful */
66 RES_ERROR, /* 1: R/W Error */
67 RES_WRPRT, /* 2: Write Protected */
68 RES_NOTRDY, /* 3: Not Ready */
69 RES_PARERR /* 4: Invalid Parameter */
70 } DRESULT;
71
72
73 /*---------------------------------------*/
74 /* Prototypes for disk control functions */
75
92 DSTATUS eDisk_Init(BYTE drive);
93
108 DSTATUS eDisk_Status (BYTE drive);
109
110
111
130 DRESULT eDisk_Read (
131 BYTE drv, // Physical drive number (0)
132 BYTE *buff, // Pointer to buffer to read data
133 DWORD sector, // Start sector number (LBA)
134 UINT count); // Sector count (1..255)
135
152 DRESULT eDisk_ReadBlock (
153 BYTE *buff, /* Pointer to the data buffer to store read data */
154 DWORD sector); /* Start sector number (LBA) */
155
156 #if _READONLY == 0
157
158
177 DRESULT eDisk_Write (
178 BYTE drv, // Physical drive number (0)
179 const BYTE *buff, // Pointer to the data to be written
180 DWORD sector, // Start sector number (LBA)
181 UINT count); // Sector count (1..255)
182
183
200 DRESULT eDisk_WriteBlock (
201 const BYTE *buff, /* Pointer to the data to be written */
202 DWORD sector); /* Start sector number (LBA) */
203
204
205 #endif
212 void CS_Init(void);
213
220 void disk_timerproc(void);
221
230 DRESULT disk_ioctl (BYTE drv, BYTE cmd, void *buff);
231
232
236 #define STA_NOINIT 0x01 /* Drive not initialized */
237 #define STA_NODISK 0x02 /* No medium in the drive */
238 #define STA_PROTECT 0x04 /* Write protected */
239
240 /* Command code for disk_ioctrl fucntion */
241
242 /* Generic command (Used by FatFs) */
243 #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
244 #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
245 #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
246 #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
247 #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
248
249 /* Generic command (Not used by FatFs) */
250 #define CTRL_FORMAT 5 /* Create physical format on the media */
251 #define CTRL_POWER_IDLE 6 /* Put the device idle state */
252 #define CTRL_POWER_OFF 7 /* Put the device off state */
253 #define CTRL_LOCK 8 /* Lock media removal */
254 #define CTRL_UNLOCK 9 /* Unlock media removal */
255 #define CTRL_EJECT 10 /* Eject media */
256
257 /* MMC/SDC specific command (Not used by FatFs) */
258 #define MMC_GET_TYPE 50 /* Get card type */
259 #define MMC_GET_CSD 51 /* Get CSD */
260 #define MMC_GET_CID 52 /* Get CID */
261 #define MMC_GET_OCR 53 /* Get OCR */
262 #define MMC_GET_SDSTAT 54 /* Get SD status */
263
264 /* ATA/CF specific command (Not used by FatFs) */
265 #define ATA_GET_REV 60 /* Get F/W revision */
266 #define ATA_GET_MODEL 61 /* Get model name */
267 #define ATA_GET_SN 62 /* Get serial number */
268
269 /* MMC card type flags (MMC_GET_TYPE) */
270 #define CT_MMC 0x01 /* MMC ver 3 */
271 #define CT_SD1 0x02 /* SD ver 1 */
272 #define CT_SD2 0x04 /* SD ver 2 */
273 #define CT_SDC (CT_SD1|CT_SD2) /* SD */
274 #define CT_BLOCK 0x08 /* Block addressing */
275
276
277 #define _DISKIO
278 #endif
disk_timerproc
void disk_timerproc(void)
This should be called every 10 ms.
eDisk_Write
DRESULT eDisk_Write(BYTE drv, const BYTE *buff, DWORD sector, UINT count)
Write bytes to SD card.
eDisk_Init
DSTATUS eDisk_Init(BYTE drive)
Initialize the interface between microcontroller and the SD card.
BOOL
BOOL
Boolean type.
Definition: eDisk.h:56
eDisk_Status
DSTATUS eDisk_Status(BYTE drive)
Check the status of the SD card.
eDisk_ReadBlock
DRESULT eDisk_ReadBlock(BYTE *buff, DWORD sector)
Read 512-byte block from SD card.
eDisk_Read
DRESULT eDisk_Read(BYTE drv, BYTE *buff, DWORD sector, UINT count)
Read bytes from SD card.
disk_ioctl
DRESULT disk_ioctl(BYTE drv, BYTE cmd, void *buff)
Disk input/output.
DSTATUS
BYTE DSTATUS
Status of Disk Functions.
Definition: eDisk.h:61
eDisk_WriteBlock
DRESULT eDisk_WriteBlock(const BYTE *buff, DWORD sector)
Write 512-byte block from SD card.
CS_Init
void CS_Init(void)
Configure SDC chip select.