push dir entry to sram

This commit is contained in:
David Voswinkel 2009-08-17 21:44:38 +02:00
parent ed0a95cad5
commit 7046230e31
8 changed files with 75 additions and 30 deletions

View File

@ -27,7 +27,7 @@
#define DEBUG_USB_TRANS 4 #define DEBUG_USB_TRANS 4
#define DEBUG_SRAM 8 #define DEBUG_SRAM 8
#define DEBUG_SRAM_RAW 16 #define DEBUG_SRAM_RAW 16
#define DEBUG_SREG 32 #define DEBUG_FAT 32
#define DEBUG_CRC 64 #define DEBUG_CRC 64
#define DEBUG_SHM 128 #define DEBUG_SHM 128

View File

@ -20,6 +20,9 @@
#include "dir.h" #include "dir.h"
#include "debug.h"
#include "sram.h"
#include "config.h"
#include <string.h> #include <string.h>
@ -30,20 +33,27 @@ void dir_entry_start(){
positon = 0; 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; uint32_t addr;
dir_ent_t ent; dir_ent_t ent;
strncpy(ent.file_name,file_name,13); strncpy(ent.file_name,file_name,13);
ent.id = id;
ent.file_size = file_size; ent.file_size = file_size;
ent.file_attr = file_attr; ent.file_attr = file_attr;
addr = DIR_ENTRY_LOC + (positon << DIR_ENTRY_SIZE_SHIFT ); addr = DIR_ENTRY_LOC + (positon << DIR_ENTRY_SIZE_SHIFT );
sram_bulk_copy(addr, (uint8_t *) &ent, DIR_ENTRY_SIZE ); sram_bulk_copy(addr, (uint8_t *) &ent, DIR_ENTRY_SIZE );
dir_entry_dump(&ent);
positon++; positon++;
} }
void dir_entry_header(uint16_t position, uint8_t * header){ void dir_entry_header(uint16_t position, uint8_t * header){
uint32_t addr; uint32_t addr;
dir_ent_t ent;
addr = DIR_ENTRY_LOC + ( position << DIR_ENTRY_SIZE_SHIFT ) + DIR_ENTRY_HEADER_OFF; addr = DIR_ENTRY_LOC + ( position << DIR_ENTRY_SIZE_SHIFT ) + DIR_ENTRY_HEADER_OFF;
sram_bulk_copy(addr, (uint8_t *) header, DIR_ENTRY_HEADER_SIZE); sram_bulk_copy(addr, (uint8_t *) header, DIR_ENTRY_HEADER_SIZE);
} }

View File

@ -1,4 +1,4 @@
˝/* /*
* ===================================================================================== * =====================================================================================
* *
* ________ .__ __ ________ ____ ________ * ________ .__ __ ________ ____ ________
@ -40,7 +40,7 @@ typedef struct {
} dir_ent_t; // 64 } dir_ent_t; // 64
void dir_entry_start(); 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); void dir_entry_header(uint16_t position, uint8_t * header);
/* /*

View File

@ -5,6 +5,8 @@
#include "mmc.h" #include "mmc.h"
#include "fat.h" #include "fat.h"
#include "file.h" #include "file.h"
#include "dir.h"
#include "config.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. // 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. // die dateien werden mit namen und datei größe angezeigt.
// ******************************************************************************************************************************* // *******************************************************************************************************************************
void lsRowsOfClust(uint32_t start_sec) void lsRowsOfClust(uint32_t start_sec)
{ {
uint8_t row; // reihen uint8_t row; // reihen
uint8_t sec = 0; // sektoren uint8_t sec = 0; // sektoren
do { do {
fat_loadSector(start_sec + sec); // sektoren des clusters laden fat_loadSector(start_sec + sec); // sektoren des clusters laden
for (row = 0; row < 16; row++) { // geht durch reihen des sektors for (row = 0; row < 16; row++) { // geht durch reihen des sektors
fat_loadRowOfSector(row); // reihe eines sektors (auf dem puffer) laden fat_loadRowOfSector(row); // reihe eines sektors (auf dem puffer) laden
if ((file.attrib == 0x20 || file.attrib == 0x10) if ((file.name[0] != 0xE5 && file.name[0] != 0x00)) {
&& (file.name[0] != 0xE5 && file.name[0] != 0x00)) { if (file.attrib == 0x20)
printf("Name: %s Size:%li\n", file.name, file.length); printf("Name: %s Size:%li\n", file.name, file.length);
if (file.attrib == 0x10)
printf("Dir: %s\n", file.name);
} }
} }
} while (++sec < fat.secPerClust); } 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) void ffls(void)
{ {
uint32_t clust; // cluster uint32_t clust; // cluster
uint16_t s; // fat16 root dir sektoren uint16_t s; // fat16 root dir sektoren
if (fat.dir == 0 && fat.fatType == 16) { // IM ROOTDIR. fat16 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 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 lsRowsOfClust(fat.rootDir + s); // zeigt reihen eines root dir clust an
} }
} printf("Fat16\n");
} else {
else {
printf("Fat32\n");
if (fat.dir == 0 && fat.fatType == 32) if (fat.dir == 0 && fat.fatType == 32)
clust = fat.rootDir; // IM ROOTDIR. fat32 clust = fat.rootDir; // IM ROOTDIR. fat32
else else
clust = fat.dir; // NICHT ROOT DIR clust = fat.dir; // NICHT ROOT DIR
while (!((clust == 0xfffffff && fat.fatType == 32) || (clust == 0xffff && fat.fatType == 16))) { // prüft ob weitere 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 lsRowsOfClust(fat_clustToSec(clust)); // zeigt reihen des clusters an
clust = fat_getNextCluster(clust); // liest nächsten cluster des dir-eintrags 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 !) // 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, // die variable fat.dir enthält den start cluster des direktory in dem man sich grade befindet, anhand diesem,

View File

@ -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 void ffseek(uint32_t offset); // setzt zeiger:bytesOfSec auf position in der geöffneten datei.
extern uint8_t ffcd(char name[]); // wechselt direktory extern uint8_t ffcd(char name[]); // wechselt direktory
extern void ffls(void); // zeigt direktory inhalt an 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 ffcdLower(void); // geht ein direktory zurück, also cd.. (parent direktory)
extern uint8_t ffrm(char name[]); // löscht datei aus aktuellem verzeichniss. extern uint8_t ffrm(char name[]); // löscht datei aus aktuellem verzeichniss.
extern void ffmkdir(char name[]); // legt ordner in aktuellem verzeichniss an. extern void ffmkdir(char name[]); // legt ordner in aktuellem verzeichniss an.

View File

@ -51,7 +51,7 @@
extern const char _rom[] PROGMEM; extern const char _rom[] PROGMEM;
extern FILE uart_stdout; 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]; uint8_t read_buffer[TRANSFER_BUFFER_SIZE];
uint32_t req_addr = 0; uint32_t req_addr = 0;

View File

@ -97,19 +97,19 @@ void system_init(void)
void sreg_set(uint32_t addr) void sreg_set(uint32_t addr)
{ {
uint8_t i = 24; uint8_t i = 24;
debug(DEBUG_SREG,"sreg_set: addr=0x%08lx",addr); debug(DEBUG_SRAM,"sreg_set: addr=0x%08lx",addr);
while(i--) { while(i--) {
if ((addr & ( 1L << i))){ if ((addr & ( 1L << i))){
debug(DEBUG_SREG,"1"); debug(DEBUG_SRAM,"1");
AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN); AVR_ADDR_SER_PORT |= ( 1 << AVR_ADDR_SER_PIN);
} else { } else {
AVR_ADDR_SER_PORT &= ~( 1 << AVR_ADDR_SER_PIN); 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);
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);
AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN); AVR_ADDR_LATCH_PORT &= ~(1 << AVR_ADDR_LATCH_PIN);

View File

@ -35,6 +35,7 @@
#include "mmc.h" #include "mmc.h"
#include "fat.h" #include "fat.h"
#include "file.h" #include "file.h"
#include "dir.h"
void test_read_write() void test_read_write()
@ -109,7 +110,6 @@ void test_crc()
test_non_zero_memory(0x000000, 0x10000); test_non_zero_memory(0x000000, 0x10000);
} }
void test_sdcard(void){ void test_sdcard(void){
@ -124,7 +124,8 @@ void test_sdcard(void){
} }
printf("Root dirlist\n"); printf("Root dirlist\n");
ffls(); ffls_smc();
dump_memory(DIR_ENTRY_LOC , DIR_ENTRY_LOC + (64 * 2));
#if (WRITE==1) #if (WRITE==1)
char datei[12]="test.txt"; // hier muss platz für 11 zeichen sein (8.3), da fat_str diesen string benutzt !! char datei[12]="test.txt"; // hier muss platz für 11 zeichen sein (8.3), da fat_str diesen string benutzt !!