mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-04-24 19:50:31 +00:00
FatFs: use a cache for directory traversing
...as FatFs uses only single sector reads
This commit is contained in:
@@ -7,15 +7,26 @@
|
||||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
#include "ff.h" /* Obtains integer types */
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
#include "hardware.h"
|
||||
#include "mmc.h"
|
||||
#include "fat_compat.h"
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_MMC 0
|
||||
#define DEV_USB 1
|
||||
|
||||
static char enable_cache = 0;
|
||||
static LBA_t cache_sector;
|
||||
static LBA_t database;
|
||||
|
||||
void disk_cache_set(char enable, LBA_t base) {
|
||||
cache_sector = -1;
|
||||
database = base;
|
||||
enable_cache = enable;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
@@ -99,14 +110,22 @@ DRESULT disk_read (
|
||||
int result;
|
||||
|
||||
//iprintf("disk_read: %d LBA: %d count: %d\n", pdrv, sector, count);
|
||||
if(enable_cache && cache_sector != -1 && sector >= cache_sector && (sector + count - 1) <= (cache_sector + SECTOR_BUFFER_SIZE/512 - 1)) {
|
||||
memcpy(buff, §or_buffer[512*(sector-cache_sector)], count*512);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
if (count == 1)
|
||||
if(enable_cache && sector >= database) {
|
||||
result = MMC_ReadMultiple(sector, sector_buffer, SECTOR_BUFFER_SIZE/512);
|
||||
memcpy(buff, sector_buffer, count*512);
|
||||
cache_sector = sector;
|
||||
} else if (count == 1) {
|
||||
result = MMC_Read(sector, buff);
|
||||
else
|
||||
} else {
|
||||
result = MMC_ReadMultiple(sector, buff, count);
|
||||
}
|
||||
|
||||
// translate the reslut code here
|
||||
res = result ? RES_OK : RES_ERROR;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void disk_cache_set(char enable, LBA_t base);
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include "mmc.h"
|
||||
#include "fat_compat.h"
|
||||
#include "fpga.h"
|
||||
@@ -374,6 +375,9 @@ char ScanDirectory(unsigned long mode, char *extension, unsigned char options) {
|
||||
find_dir = options & FIND_DIR;
|
||||
}
|
||||
|
||||
//enable caching in the sector buffer while traversing the directory,
|
||||
//because FatFs is inefficiently using single sector reads
|
||||
disk_cache_set(true, fs.database);
|
||||
f_rewinddir(&dir);
|
||||
nNewEntries = 0;
|
||||
while (1) {
|
||||
@@ -533,6 +537,7 @@ char ScanDirectory(unsigned long mode, char *extension, unsigned char options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
disk_cache_set(false, 0);
|
||||
|
||||
if (nNewEntries) {
|
||||
if (mode == SCAN_NEXT_PAGE) {
|
||||
|
||||
Reference in New Issue
Block a user