1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
3 /*-----------------------------------------------------------------------*/
4 /* This is a stub disk I/O module that acts as front end of the existing */
5 /* disk I/O modules and attach it to FatFs module with common interface. */
6 /*-----------------------------------------------------------------------*/
11 #include <io/kblock.h>
13 #include "cfg/cfg_fat.h"
14 #define LOG_LEVEL FAT_LOG_LEVEL
15 #define LOG_FORMAT FAT_LOG_FORMAT
18 static KBlock *devs[_DRIVES];
20 void disk_assignDrive(KBlock *dev, int dev_num)
22 ASSERT(dev_num < _DRIVES);
27 /*-----------------------------------------------------------------------*/
28 /* Inidialize a Drive */
30 DSTATUS disk_initialize (
31 BYTE drv /* Physical drive nmuber (0..) */
34 return disk_status(drv);
39 /*-----------------------------------------------------------------------*/
40 /* Return Disk Status */
43 BYTE drv /* Physical drive nmuber (0..) */
46 KBlock *dev = devs[drv];
49 if (kblock_error(dev) != 0)
57 /*-----------------------------------------------------------------------*/
61 BYTE drv, /* Physical drive nmuber (0..) */
62 BYTE *buff, /* Data buffer to store read data */
63 DWORD sector, /* Sector address (LBA) */
64 BYTE count /* Number of sectors to read (1..255) */
67 KBlock *dev = devs[drv];
73 if (kblock_read(dev, sector++, buff, 0, dev->blk_size) != dev->blk_size)
75 buff += dev->blk_size;
82 /*-----------------------------------------------------------------------*/
87 BYTE drv, /* Physical drive nmuber (0..) */
88 const BYTE *buff, /* Data to be written */
89 DWORD sector, /* Sector address (LBA) */
90 BYTE count /* Number of sectors to write (1..255) */
93 KBlock *dev = devs[drv];
98 if (kblock_write(dev, sector++, buff, 0, dev->blk_size) != dev->blk_size)
100 buff += dev->blk_size;
104 #endif /* _READONLY */
108 /*-----------------------------------------------------------------------*/
109 /* Miscellaneous Functions */
112 BYTE drv, /* Physical drive nmuber (0..) */
113 BYTE ctrl, /* Control code */
114 void *buff /* Buffer to send/receive control data */
117 KBlock *dev = devs[drv];
124 if (kblock_flush(dev) == 0)
129 case GET_SECTOR_SIZE:
130 *(WORD *)buff = dev->blk_size;
133 case GET_SECTOR_COUNT:
134 *(DWORD *)buff = dev->blk_cnt;
142 LOG_ERR("unknown command: [%d]\n", ctrl);
148 DWORD get_fattime(void)