db fix (may still need serious fixing)
This commit is contained in:
parent
ecfe7d9831
commit
2b05f0b695
@ -31,7 +31,7 @@ uint16_t scan_flat(const char* path) {
|
|||||||
return numentries;
|
return numentries;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t scan_dir(char* path, char mkdb) {
|
uint16_t scan_dir(char* path, char mkdb, uint32_t this_dir_tgt) {
|
||||||
DIR dir;
|
DIR dir;
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
@ -40,37 +40,39 @@ uint16_t scan_dir(char* path, char mkdb) {
|
|||||||
static unsigned char depth = 0;
|
static unsigned char depth = 0;
|
||||||
static uint16_t crc;
|
static uint16_t crc;
|
||||||
static uint32_t db_tgt;
|
static uint32_t db_tgt;
|
||||||
static uint32_t dir_tgt;
|
static uint32_t next_subdir_tgt;
|
||||||
static uint32_t dir_end = 0;
|
static uint32_t dir_end = 0;
|
||||||
static uint8_t was_empty = 0;
|
static uint8_t was_empty = 0;
|
||||||
uint32_t dir_tgt_save, dir_tgt_next;
|
uint32_t dir_tgt;
|
||||||
uint16_t numentries;
|
uint16_t numentries;
|
||||||
uint32_t dirsize;
|
uint32_t dirsize;
|
||||||
uint8_t pass = 0;
|
uint8_t pass = 0;
|
||||||
|
|
||||||
|
dir_tgt = this_dir_tgt;
|
||||||
if(depth==0) {
|
if(depth==0) {
|
||||||
crc = 0;
|
crc = 0;
|
||||||
db_tgt = SRAM_DB_ADDR+0x10;
|
db_tgt = SRAM_DB_ADDR+0x10;
|
||||||
dir_tgt = SRAM_DIR_ADDR;
|
dir_tgt = SRAM_DIR_ADDR;
|
||||||
|
next_subdir_tgt = SRAM_DIR_ADDR;
|
||||||
dprintf("root dir @%lx\n", dir_tgt);
|
dprintf("root dir @%lx\n", dir_tgt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fno.lfn = file_lfn;
|
fno.lfn = file_lfn;
|
||||||
numentries=0;
|
numentries=0;
|
||||||
dir_tgt_next=0;
|
|
||||||
for(pass = 0; pass < 2; pass++) {
|
for(pass = 0; pass < 2; pass++) {
|
||||||
if(pass) {
|
if(pass) {
|
||||||
dirsize = 4*(numentries);
|
dirsize = 4*(numentries);
|
||||||
dir_tgt_next = dir_tgt + dirsize + 4; // number of entries + end marker
|
// dir_tgt_next = dir_tgt + dirsize + 4; // number of entries + end marker
|
||||||
if(dir_tgt_next > dir_end) {
|
next_subdir_tgt += dirsize + 4;
|
||||||
dir_end = dir_tgt_next;
|
if(next_subdir_tgt > dir_end) {
|
||||||
|
dir_end = next_subdir_tgt;
|
||||||
}
|
}
|
||||||
// dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, dir_tgt_next);
|
dprintf("path=%s depth=%d ptr=%lx entries=%d next subdir @%lx\n", path, depth, db_tgt, numentries, next_subdir_tgt /*dir_tgt_next*/);
|
||||||
// _delay_ms(50);
|
// _delay_ms(50);
|
||||||
if(mkdb) {
|
if(mkdb) {
|
||||||
// dprintf("d=%d Saving %lX to Address %lX [end]\n", depth, 0L, dir_tgt_next - 4);
|
dprintf("d=%d Saving %lX to Address %lX [end]\n", depth, 0L, next_subdir_tgt - 4);
|
||||||
// _delay_ms(50);
|
// _delay_ms(50);
|
||||||
sram_writelong(0L, dir_tgt_next - 4);
|
sram_writelong(0L, next_subdir_tgt - 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = f_opendir(&dir, (unsigned char*)path);
|
res = f_opendir(&dir, (unsigned char*)path);
|
||||||
@ -95,30 +97,28 @@ uint16_t scan_dir(char* path, char mkdb) {
|
|||||||
path[len]='/';
|
path[len]='/';
|
||||||
strncpy(path+len+1, (char*)fn, sizeof(fs_path)-len);
|
strncpy(path+len+1, (char*)fn, sizeof(fs_path)-len);
|
||||||
depth++;
|
depth++;
|
||||||
dir_tgt_save = dir_tgt;
|
|
||||||
dir_tgt = dir_tgt_next;
|
|
||||||
if(mkdb) {
|
if(mkdb) {
|
||||||
uint16_t pathlen = strlen(path);
|
uint16_t pathlen = strlen(path);
|
||||||
// write element pointer to current dir structure
|
// write element pointer to current dir structure
|
||||||
// dprintf("d=%d Saving %lX to Address %lX [dir]\n", depth, db_tgt, dir_tgt_save);
|
dprintf("d=%d Saving %lX to Address %lX [dir]\n", depth, db_tgt, dir_tgt);
|
||||||
// _delay_ms(50);
|
// _delay_ms(50);
|
||||||
sram_writelong(db_tgt|((uint32_t)0x80<<24), dir_tgt_save);
|
sram_writelong(db_tgt|((uint32_t)0x80<<24), dir_tgt);
|
||||||
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
|
// sram_writeblock((uint8_t*)&db_tgt, dir_tgt_save, sizeof(dir_tgt_save));
|
||||||
|
|
||||||
// save element:
|
// save element:
|
||||||
// - path name
|
// - path name
|
||||||
// - pointer to sub dir structure
|
// - pointer to sub dir structure
|
||||||
// dprintf(" Saving dir descriptor to %lX, tgt=%lX, path=%s\n", db_tgt, dir_tgt, path);
|
dprintf(" Saving dir descriptor to %lX, tgt=%lX, path=%s\n", db_tgt, next_subdir_tgt, path);
|
||||||
// _delay_ms(100);
|
// _delay_ms(100);
|
||||||
sram_writelong(dir_tgt, db_tgt);
|
sram_writelong(next_subdir_tgt, db_tgt);
|
||||||
sram_writebyte(len+1, db_tgt+sizeof(dir_tgt));
|
sram_writebyte(len+1, db_tgt+sizeof(next_subdir_tgt));
|
||||||
sram_writeblock(path, db_tgt+sizeof(dir_tgt)+sizeof(len), pathlen + 1);
|
sram_writeblock(path, db_tgt+sizeof(next_subdir_tgt)+sizeof(len), pathlen + 1);
|
||||||
// sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
|
// sram_writeblock((uint8_t*)&dir_tgt, db_tgt+256, sizeof(dir_tgt));
|
||||||
db_tgt += sizeof(dir_tgt) + sizeof(len) + pathlen + 1;
|
db_tgt += sizeof(next_subdir_tgt) + sizeof(len) + pathlen + 1;
|
||||||
}
|
}
|
||||||
scan_dir(path, mkdb);
|
scan_dir(path, mkdb, next_subdir_tgt);
|
||||||
dir_tgt = dir_tgt_save + 4;
|
dir_tgt += 4;
|
||||||
if(was_empty)dir_tgt_next += 4;
|
// if(was_empty)dir_tgt_next += 4;
|
||||||
was_empty = 0;
|
was_empty = 0;
|
||||||
depth--;
|
depth--;
|
||||||
path[len]=0;
|
path[len]=0;
|
||||||
|
|||||||
@ -16,7 +16,7 @@ typedef enum {
|
|||||||
char fs_path[256];
|
char fs_path[256];
|
||||||
SNES_FTYPE determine_filetype(char* filename);
|
SNES_FTYPE determine_filetype(char* filename);
|
||||||
//uint32_t scan_fs();
|
//uint32_t scan_fs();
|
||||||
uint16_t scan_dir(char* path, char mkdb);
|
uint16_t scan_dir(char* path, char mkdb, uint32_t this_subdir_tgt);
|
||||||
FRESULT get_db_id(uint16_t*);
|
FRESULT get_db_id(uint16_t*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -29,8 +29,8 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0};
|
static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0};
|
||||||
static uint8_t curr_bright = 0;
|
static uint8_t curr_bright = 15;
|
||||||
static uint8_t led_bounce_dir = 0;
|
static uint8_t led_bounce_dir = 1;
|
||||||
|
|
||||||
volatile uint8_t led_state;
|
volatile uint8_t led_state;
|
||||||
|
|
||||||
|
|||||||
@ -156,19 +156,19 @@ int main(void) {
|
|||||||
|
|
||||||
sram_writelong(0x12345678, SRAM_SCRATCHPAD);
|
sram_writelong(0x12345678, SRAM_SCRATCHPAD);
|
||||||
*fs_path=0;
|
*fs_path=0;
|
||||||
uint16_t curr_dir_id = scan_dir(fs_path, 0); // generate files footprint
|
uint16_t curr_dir_id = scan_dir(fs_path, 0, 0); // generate files footprint
|
||||||
dprintf("curr dir id = %x\n", curr_dir_id);
|
dprintf("curr dir id = %x\n", curr_dir_id);
|
||||||
uint16_t saved_dir_id;
|
uint16_t saved_dir_id;
|
||||||
|
|
||||||
led_pwm();
|
led_pwm();
|
||||||
|
|
||||||
if((get_db_id(&saved_dir_id) != FR_OK) // no database?
|
if((get_db_id(&saved_dir_id) != FR_OK) // no database?
|
||||||
|| saved_dir_id != curr_dir_id) { // files changed? // XXX
|
|| 1 || saved_dir_id != curr_dir_id) { // files changed? // XXX
|
||||||
dprintf("saved dir id = %x\n", saved_dir_id);
|
dprintf("saved dir id = %x\n", saved_dir_id);
|
||||||
_delay_ms(50);
|
_delay_ms(50);
|
||||||
dprintf("rebuilding database...");
|
dprintf("rebuilding database...");
|
||||||
_delay_ms(50);
|
_delay_ms(50);
|
||||||
curr_dir_id = scan_dir(fs_path, 1); // then rebuild database
|
curr_dir_id = scan_dir(fs_path, 1, 0); // then rebuild database
|
||||||
sram_writeblock(&curr_dir_id, SRAM_DB_ADDR, 2);
|
sram_writeblock(&curr_dir_id, SRAM_DB_ADDR, 2);
|
||||||
uint32_t endaddr, direndaddr;
|
uint32_t endaddr, direndaddr;
|
||||||
sram_readblock(&endaddr, SRAM_DB_ADDR+4, 4);
|
sram_readblock(&endaddr, SRAM_DB_ADDR+4, 4);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user