From 7046230e31c27aa86b7b41ac1fbc934bc0ca7b9e Mon Sep 17 00:00:00 2001 From: David Voswinkel Date: Mon, 17 Aug 2009 21:44:38 +0200 Subject: [PATCH] push dir entry to sram --- avr/usbload/config.h | 2 +- avr/usbload/dir.c | 14 +++++++-- avr/usbload/dir.h | 4 +-- avr/usbload/file.c | 69 ++++++++++++++++++++++++++++++++----------- avr/usbload/file.h | 1 + avr/usbload/main.c | 2 +- avr/usbload/sram.c | 8 ++--- avr/usbload/testing.c | 5 ++-- 8 files changed, 75 insertions(+), 30 deletions(-) diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 4f60793..888c954 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -27,7 +27,7 @@ #define DEBUG_USB_TRANS 4 #define DEBUG_SRAM 8 #define DEBUG_SRAM_RAW 16 -#define DEBUG_SREG 32 +#define DEBUG_FAT 32 #define DEBUG_CRC 64 #define DEBUG_SHM 128 diff --git a/avr/usbload/dir.c b/avr/usbload/dir.c index 947bd8f..78e4f52 100644 --- a/avr/usbload/dir.c +++ b/avr/usbload/dir.c @@ -20,6 +20,9 @@ #include "dir.h" +#include "debug.h" +#include "sram.h" +#include "config.h" #include @@ -30,20 +33,27 @@ void dir_entry_start(){ positon = 0; } -void dir_entry_add(uint16_t id, uint8_t file_name,uint32_t file_size,uint8_t file_attr){ +void dir_entry_dump(dir_ent_t* ent){ + debug(DEBUG_FAT,"dir_entry_dump: id=%i name=%s size=%i attr=%d\n", ent->id, ent->file_name, + ent->file_size, ent->file_attr); +} + + +void dir_entry_add(uint16_t id, uint8_t* file_name,uint32_t file_size,uint8_t file_attr){ uint32_t addr; dir_ent_t ent; strncpy(ent.file_name,file_name,13); + ent.id = id; ent.file_size = file_size; ent.file_attr = file_attr; addr = DIR_ENTRY_LOC + (positon << DIR_ENTRY_SIZE_SHIFT ); sram_bulk_copy(addr, (uint8_t *) &ent, DIR_ENTRY_SIZE ); + dir_entry_dump(&ent); positon++; } void dir_entry_header(uint16_t position, uint8_t * header){ uint32_t addr; - dir_ent_t ent; addr = DIR_ENTRY_LOC + ( position << DIR_ENTRY_SIZE_SHIFT ) + DIR_ENTRY_HEADER_OFF; sram_bulk_copy(addr, (uint8_t *) header, DIR_ENTRY_HEADER_SIZE); } diff --git a/avr/usbload/dir.h b/avr/usbload/dir.h index 0a9eec8..b521309 100644 --- a/avr/usbload/dir.h +++ b/avr/usbload/dir.h @@ -1,4 +1,4 @@ -˝/* +/* * ===================================================================================== * * ________ .__ __ ________ ____ ________ @@ -40,7 +40,7 @@ typedef struct { } dir_ent_t; // 64 void dir_entry_start(); -void dir_entry_add(uint16_t id, uint8_t file_name,uint32_t file_size,uint8_t file_attr); +void dir_entry_add(uint16_t id, uint8_t* file_name,uint32_t file_size,uint8_t file_attr); void dir_entry_header(uint16_t position, uint8_t * header); /* diff --git a/avr/usbload/file.c b/avr/usbload/file.c index fae69cd..bc2ed4f 100644 --- a/avr/usbload/file.c +++ b/avr/usbload/file.c @@ -5,6 +5,8 @@ #include "mmc.h" #include "fat.h" #include "file.h" +#include "dir.h" + #include "config.h" // ******************************************************************************************************************************* @@ -148,60 +150,91 @@ uint8_t ffcd(char name[]) // eintrag in der reihe ist (nicht gelöscht, nicht frei usw). die sektoren des clusters werden nachgeladen. // die dateien werden mit namen und datei größe angezeigt. // ******************************************************************************************************************************* + void lsRowsOfClust(uint32_t start_sec) { - uint8_t row; // reihen uint8_t sec = 0; // sektoren do { fat_loadSector(start_sec + sec); // sektoren des clusters laden for (row = 0; row < 16; row++) { // geht durch reihen des sektors fat_loadRowOfSector(row); // reihe eines sektors (auf dem puffer) laden - if ((file.attrib == 0x20 || file.attrib == 0x10) - && (file.name[0] != 0xE5 && file.name[0] != 0x00)) { - printf("Name:%s Size:%li\n", file.name, file.length); + if ((file.name[0] != 0xE5 && file.name[0] != 0x00)) { + if (file.attrib == 0x20) + printf("Name: %s Size:%li\n", file.name, file.length); + if (file.attrib == 0x10) + printf("Dir: %s\n", file.name); } } } while (++sec < fat.secPerClust); } -// ******************************************************************************************************************************* -// zeigt inhalt eines direktory an. -// unterscheidung ob man sich im rootDir befindet nötig, weil bei fat16 im root dir eine bestimmt anzahl sektoren durchsucht -// werden müssen und bei fat32 ab einem start cluster ! ruft lsRowsOfClust auf um cluster/sektoren anzuzeigen. -// ******************************************************************************************************************************* void ffls(void) { uint32_t clust; // cluster uint16_t s; // fat16 root dir sektoren - if (fat.dir == 0 && fat.fatType == 16) { // IM ROOTDIR. fat16 - printf("Fat16\n"); for (s = 0; s < (uint16_t) (fat.dataDirSec + 2 - fat.rootDir); s++) { // zählt durch RootDir sektoren (errechnet anzahl - // rootDir sektoren). lsRowsOfClust(fat.rootDir + s); // zeigt reihen eines root dir clust an } - } - - else { - printf("Fat32\n"); + printf("Fat16\n"); + } else { if (fat.dir == 0 && fat.fatType == 32) clust = fat.rootDir; // IM ROOTDIR. fat32 else clust = fat.dir; // NICHT ROOT DIR while (!((clust == 0xfffffff && fat.fatType == 32) || (clust == 0xffff && fat.fatType == 16))) { // prüft ob weitere - // sektoren zum lesen da - // sind (fat32||fat16) lsRowsOfClust(fat_clustToSec(clust)); // zeigt reihen des clusters an clust = fat_getNextCluster(clust); // liest nächsten cluster des dir-eintrags } + printf("Fat32\n"); } } +void lsRowsOfClust_smc(uint32_t start_sec) +{ + uint8_t row; // reihen + uint8_t sec = 0; // sektoren + do { + fat_loadSector(start_sec + sec); // sektoren des clusters laden + for (row = 0; row < 16; row++) { // geht durch reihen des sektors + fat_loadRowOfSector(row); // reihe eines sektors (auf dem puffer) laden + if ((file.name[0] != 0xE5 && file.name[0] != 0x00)) { + if (file.attrib == 0x20) + dir_entry_add((uint16_t)file.firstCluster, file.name, file.length ,file.attrib); + } + } + } while (++sec < fat.secPerClust); +} + + +void ffls_smc(void) +{ + + uint32_t clust; // cluster + uint16_t s; // fat16 root dir sektoren + if (fat.dir == 0 && fat.fatType == 16) { // IM ROOTDIR. fat16 + for (s = 0; s < (uint16_t) (fat.dataDirSec + 2 - fat.rootDir); s++) { // zählt durch RootDir sektoren (errechnet anzahl + lsRowsOfClust_smc(fat.rootDir + s); // zeigt reihen eines root dir clust an + } + printf("Fat16\n"); + } else { + if (fat.dir == 0 && fat.fatType == 32) + clust = fat.rootDir; // IM ROOTDIR. fat32 + else + clust = fat.dir; // NICHT ROOT DIR + while (!((clust == 0xfffffff && fat.fatType == 32) || (clust == 0xffff && fat.fatType == 16))) { // prüft ob weitere + lsRowsOfClust_smc(fat_clustToSec(clust)); // zeigt reihen des clusters an + clust = fat_getNextCluster(clust); // liest nächsten cluster des dir-eintrags + } + printf("Fat32\n"); + } +} + // ******************************************************************************************************************************* // wechselt in das parent verzeichniss (ein verzeichniss zurück !) // die variable fat.dir enthält den start cluster des direktory in dem man sich grade befindet, anhand diesem, diff --git a/avr/usbload/file.h b/avr/usbload/file.h index d1fb140..77d00e2 100644 --- a/avr/usbload/file.h +++ b/avr/usbload/file.h @@ -18,6 +18,7 @@ extern uint8_t ffclose(void); // muss aufgerufen werden bevor neue datei bea extern void ffseek(uint32_t offset); // setzt zeiger:bytesOfSec auf position in der geöffneten datei. extern uint8_t ffcd(char name[]); // wechselt direktory extern void ffls(void); // zeigt direktory inhalt an +extern void ffls_smc(void); // zeigt direktory inhalt an extern uint8_t ffcdLower(void); // geht ein direktory zurück, also cd.. (parent direktory) extern uint8_t ffrm(char name[]); // löscht datei aus aktuellem verzeichniss. extern void ffmkdir(char name[]); // legt ordner in aktuellem verzeichniss an. diff --git a/avr/usbload/main.c b/avr/usbload/main.c index ed1d196..4a98d0a 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -51,7 +51,7 @@ extern const char _rom[] PROGMEM; extern FILE uart_stdout; -uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC); +uint8_t debug_level = (DEBUG | DEBUG_USB | DEBUG_CRC | DEBUG_FAT); uint8_t read_buffer[TRANSFER_BUFFER_SIZE]; uint32_t req_addr = 0; diff --git a/avr/usbload/sram.c b/avr/usbload/sram.c index 14ae271..935cdfb 100644 --- a/avr/usbload/sram.c +++ b/avr/usbload/sram.c @@ -97,19 +97,19 @@ void system_init(void) void sreg_set(uint32_t addr) { uint8_t i = 24; - debug(DEBUG_SREG,"sreg_set: addr=0x%08lx",addr); + debug(DEBUG_SRAM,"sreg_set: addr=0x%08lx",addr); while(i--) { if ((addr & ( 1L << i))){ - debug(DEBUG_SREG,"1"); + debug(DEBUG_SRAM,"1"); AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN); } else { AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN); - debug(DEBUG_SREG,"0"); + debug(DEBUG_SRAM,"0"); } AVR_ADDR_SCK_PORT |= (1 << AVR_ADDR_SCK_PIN); AVR_ADDR_SCK_PORT &= ~(1 << AVR_ADDR_SCK_PIN); } - debug(DEBUG_SREG,"\n"); + debug(DEBUG_SRAM,"\n"); AVR_ADDR_LATCH_PORT |= (1 << AVR_ADDR_LATCH_PIN); AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN); diff --git a/avr/usbload/testing.c b/avr/usbload/testing.c index 9df795b..e9c67c0 100644 --- a/avr/usbload/testing.c +++ b/avr/usbload/testing.c @@ -35,6 +35,7 @@ #include "mmc.h" #include "fat.h" #include "file.h" +#include "dir.h" void test_read_write() @@ -109,7 +110,6 @@ void test_crc() test_non_zero_memory(0x000000, 0x10000); } - void test_sdcard(void){ @@ -124,7 +124,8 @@ void test_sdcard(void){ } printf("Root dirlist\n"); - ffls(); + ffls_smc(); + dump_memory(DIR_ENTRY_LOC , DIR_ENTRY_LOC + (64 * 2)); #if (WRITE==1) char datei[12]="test.txt"; // hier muss platz für 11 zeichen sein (8.3), da fat_str diesen string benutzt !!