Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

MMC/SD card FAT16 interfacing!

Status
Not open for further replies.

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
sd card fat16

Hi all members!

Have a nice day!

Now, this's my free time. I'm studying MMC/SD card reader (micro). The read_sector() & write_sector() of MMC/SD card --->>> Correct!!!

My problem:
- fat_search_file() function not work correct !

code:
unsigned char fat_search_file (unsigned char *File_Name, unsigned int *Cluster, unsigned long *Size, unsigned char *Dir_Attrib, unsigned char *Buffer)
{
unsigned char a;
unsigned int Dir_Cluster_Store=0;

Dir_Cluster_Store = *Cluster;

for(a = 0;a < 100;a++)
{
*Cluster = fat_read_dir_ent(Dir_Cluster_Store,a,Size,Dir_Attrib,Buffer);
if (*Cluster == 0xffff)
{
return(0); //File not Found
}
if(strcmp((char*)File_Name, (char*)Buffer) == 0)
{
return(1); //File Found
}
}
return(2); //Error
}

please help me check it!

"myfat.h":


/*#######################################################################################
Connect ARM to MMC/SD

Copyright (C) 2004 Ulrich Radig
#######################################################################################*/

#ifndef _FAT_H_
#define _FAT_H_

//Prototypes
extern unsigned int fat_root_dir_addr (unsigned char *);
extern unsigned int fat_read_dir_ent (unsigned int,unsigned char,unsigned long*,unsigned char *,unsigned char *);
extern void fat_load (unsigned int,unsigned long *,unsigned char *);
extern void fat_read_file (unsigned int,unsigned char *,unsigned long);
extern void fat_write_file (unsigned int,unsigned char *,unsigned long);
extern void fat_init (void);
extern unsigned char fat_search_file (unsigned char *,unsigned int *,unsigned long *,unsigned char *,unsigned char *);

//Block Size in Bytes
//#define BlockSize 512

//Master Boot Record
#define MASTER_BOOT_RECORD 0

//Volume Boot Record location in Master Boot Record
#define VBR_ADDR 0x1C6

//define ASCII
#define SPACE 0x20
#define DIR_ENTRY_IS_FREE 0xE5
#define FIRST_LONG_ENTRY 0x01
#define SECOND_LONG_ENTRY 0x42

//define DIR_Attr
#define ATTR_LONG_NAME 0x0F
#define ATTR_READ_ONLY 0x01
#define ATTR_HIDDEN 0x02
#define ATTR_SYSTEM 0x04
#define ATTR_VOLUME_ID 0x08
#define ATTR_DIRECTORY 0x10
#define ATTR_ARCHIVE 0x20

// Partition Type used in the partition record
#define PART_TYPE_UNKNOWN 0x00
#define PART_TYPE_FAT12 0x01
#define PART_TYPE_XENIX 0x02
#define PART_TYPE_DOSFAT16 0x04
#define PART_TYPE_EXTDOS 0x05
#define PART_TYPE_FAT16 0x06
#define PART_TYPE_NTFS 0x07
#define PART_TYPE_FAT32 0x0B
#define PART_TYPE_FAT32LBA 0x0C
#define PART_TYPE_FAT16LBA 0x0E
#define PART_TYPE_EXTDOSLBA 0x0F
#define PART_TYPE_ONTRACK 0x33
#define PART_TYPE_NOVELL 0x40
#define PART_TYPE_PCIX 0x4B
#define PART_TYPE_PHOENIXSAVE 0xA0
#define PART_TYPE_CPM 0xDB
#define PART_TYPE_DBFS 0xE0
#define PART_TYPE_BBT 0xFF

// Some useful cluster numbers
#define MSDOSFSROOT 0 // cluster 0 means the root dir
#define CLUST_FREE 0 // cluster 0 also means a free cluster
#define MSDOSFSFREE CLUST_FREE
#define CLUST_FIRST 2 // first legal cluster number
#define CLUST_RSRVD 0xfffffff6 // reserved cluster range
#define CLUST_BAD 0xfffffff7 // a cluster with a defect
#define CLUST_EOFS 0xfffffff8 // start of eof cluster range
#define CLUST_EOFE 0xffffffff // end of eof cluster range

#define FAT12_MASK 0x00000fff // mask for 12 bit cluster numbers
#define FAT16_MASK 0x0000ffff // mask for 16 bit cluster numbers
#define FAT32_MASK 0x0fffffff // mask for FAT32 cluster numbers

struct BootSec
{
unsigned char BS_jmpBoot[3];
unsigned char BS_OEMName[8];
unsigned int BPB_BytesPerSec; //2 bytes, At record 11:12
unsigned char BPB_SecPerClus; // At record 13
unsigned int BPB_RsvdSecCnt; //2 bytes, At record 14:15
unsigned char BPB_NumFATs; // At record 16
unsigned int BPB_RootEntCnt; //2 bytes
unsigned int BPB_TotSec16; //2 bytes
unsigned char BPB_Media; //
unsigned int BPB_FATSz16; //2 bytes
unsigned int BPB_SecPerTrk; //2 bytes
unsigned int BPB_NumHeads; //2 bytes
unsigned long BPB_HiddSec; //4 bytes
unsigned long BPB_HugeSectors; //
unsigned long BPB_RootClust; // start cluster for root directory
unsigned long BPB_TotSec32; //4 bytes
};

struct partrecord // length 16 bytes
{
BYTE prIsActive; // 0x80 indicates active partition
BYTE prStartHead; // starting head for partition
WORD prStartCylSect; // starting cylinder and sector
BYTE prPartType; // partition type (see above)
BYTE prEndHead; // ending head for this partition
WORD prEndCylSect; // ending cylinder and sector
DWORD prStartLBA; // first LBA sector for this partition
DWORD prSize; // size of this partition (bytes or sectors ?)
};

struct partsector
{
char psPartCode[512-64-2]; // pad so struct is 512b
BYTE psPart[64]; // four partition records (64 bytes)
BYTE psBootSectSig0; // two signature bytes (2 bytes)
BYTE psBootSectSig1;
};

//FAT12 and FAT16 Structure Starting at Offset 36
#define BS_DRVNUM 36
#define BS_RESERVED1 37
#define BS_BOOTSIG 38
#define BS_VOLID 39
#define BS_VOLLAB 43
#define BS_FILSYSTYPE 54

//FAT32 Structure Starting at Offset 36
#define BPB_FATSZ32 36
#define BPB_EXTFLAGS 40
#define BPB_FSVER 42
#define BPB_ROOTCLUS 44
#define BPB_FSINFO 48
#define BPB_BKBOOTSEC 50
#define BPB_RESERVED 52

#define FAT32_BS_DRVNUM 64
#define FAT32_BS_RESERVED1 65
#define FAT32_BS_BOOTSIG 66
#define FAT32_BS_VOLID 67
#define FAT32_BS_VOLLAB 71
#define FAT32_BS_FILSYSTYPE 82
//End of Boot Sctor and BPB Structure

struct DirEntry {
unsigned char DIR_Name[11]; //8 chars filename
unsigned char DIR_Attr; //file attributes RSHA, Longname, Drive Label, Directory
unsigned char DIR_NTRes; //set to zero
unsigned char DIR_CrtTimeTenth; //creation time part in milliseconds
unsigned int DIR_CrtTime; //creation time
unsigned int DIR_CrtDate; //creation date
unsigned int DIR_LastAccDate; //last access date
unsigned int DIR_FstClusHI; //first cluster high word
unsigned int DIR_WrtTime; //last write time
unsigned int DIR_WrtDate; //last write date
unsigned int DIR_FstClusLO; //first cluster low word
unsigned long DIR_FileSize;
};

#endif //_FAT_H_
 

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
sd card fat 16

why nobody help me??? :?:
 

HeavenCreator

Newbie level 6
Joined
Sep 23, 2007
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
mmc dir_filesize

I can help you provided you provide whole code.
I am not getting anything with these snippets.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top