ButterflyMP3

avrfat16.h File Reference

Fat16 Functions. More...

#include "types.h"
#include "uart.h"
Include dependency graph for avrfat16.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PARTITION_START   446
 Start address of partition 1 in MBR.
#define FILE_ATTR_READ_ONLY   0x01
#define FILE_ATTR_HIDDEN   0x02
#define FILE_ATTR_SYSTEM   0x04
#define FILE_ATTR_SYSHID   0x06
#define FILE_ATTR_VOLUME_ID   0x08
#define FILE_ATTR_DIRECTORY   0x10
#define FILE_ATTR_ARCHIVE   0x20
#define FILE_ATTR_LFN_TEXT   0x0F
#define FILE_ATTR_LFN_MASK   0x3F
#define FILE_HEADER_BLANK   0x00
#define FILE_HEADER_DELETED   0xE5
#define FILE_TYPE_DIR   0x10
#define FILE_TYPE_FILE   0x20
#define FILE_TYPE_MP3   0x55
#define FAT16_LDIR_Ord   0
#define FAT16_LDIR_Name1   1
#define FAT16_LDIR_Attr   11
#define FAT16_LDIR_Type   12
#define FAT16_LDIR_Chksum   13
#define FAT16_LDIR_Name2   14
#define FAT16_LDIR_FstClusLO   26
#define FAT16_LDIR_Name3   28
#define LFN_TYPE_INDEX   208
#define LFN_TYPE_FILENAME   0x00
 No bits set.
#define LFN_TYPE_ID3_TITLE   0x01
 Bit 0.
#define LFN_TYPE_ID3_ARTIST   0x02
 Bit 1.
#define LFN_BUFFER_LENGTH   208
#define LFN_TITLE_INDEX   0
#define LFN_TITLE_LENGTH   100
 Title length including '\0'.
#define LFN_ARTIST_INDEX   100
#define LFN_ARTIST_LENGTH   100
 Artist length including '\0'.
#define LFN_FREE_INDEX   200
#define LFN_FREE_LEN   8
 Currently 8 free bytes in buffer if using ID3 tags not filenames.

Functions

uint8 FAT_initFat16 (void)
 read MBR and bootsector and set fat variables
uint8 FAT_readCluster (uint32 cluster, uint8 sector_offset)
 read a sector from a cluster
uint32 FAT_NextCluster (uint32 cluster)
 FAT_NextCluster.
uint32 FAT_getNextSong (uint32 filenumber, uint32 dir_lba)
 FAT_readRoot.
uint32 FAT_getPrevSong (uint32 filenumber, uint32 dir_lba)
 GetPrevSong.
uint32 FAT_getNumberedSong (char songNumber, uint32 dir_lba)
 GetNumberedSong.
uint8 FAT_ChkSum (uint8 *pFcbName)
 FAT_ChkSum()
uint8 FAT_readFile (uint32 filenumber, uint32 dir_first_sector)
 FAT_readRoot.
uint8 FAT_scanDir (uint32 directory_cluster)
 FAT_scanDir.
uint8 FAT_scanDir_lba (uint32 lba_addr)
 FAT_scanDir_lba.
uint32 FAT_cluster2lba (uint32 cluster)
 FAT_cluster2lba.
uint32 FAT_lba2cluster (uint32 lba_addr)
 FAT_lba2cluster.
uint32 FAT_getParentDir (uint32 lba_addr)
 FAT_getParentDir.
void FAT_Scratch2Cluster (void)
 FAT_Scratch2Cluster.

Variables

uint32 FAT16_fat_begin_lba
uint32 FAT16_cluster_begin_lba
uint8 FAT16_sectors_per_cluster
uint32 FAT16_dir_first_sector
uint32 FAT16_root_dir_first_sector
uint32 FAT16_parent_dir_first_sector
uint8 FAT16_filetype
uint8 FAT16_longfilename [208+1]
 buffer for long filenames / ID3 tags
uint8 FAT16_LFNTitleLen
uint8 FAT16_LFNArtistLen
uint16 FAT16_entryMAX
 Maximum entry number in FAT table. (aka file number)
uint16 FAT16_entryMIN
 Minimum entry number in FAT table. (aka file number)
uint8FAT_buffer
 512 byte buffer for sector reads/writes
uint8FAT_scratch
 32 byte buffer for filenames and data
uint8(* FAT_read )(uint32 lba)
 pointer to read block function
uint8(* FAT_write )(uint32 lba)
 pointer to write block function

Detailed Description

Fat16 Functions.

Author:
Nick Lott
Date:
September 2004
Id:
avrfat16.h,v 1.20 2009/01/10 23:16:08 brokentoaster Exp

Copyright (C) 2004 Nick Lott <brokentoaster@users.sf.net>

This is a simple implementation of the FAT16 file system. It is designed to be small for use with MP3 players and MMC cards. Currently it is readonly.NOTE: The code acknowledges only the first partition on the drive.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Target(s)...: ATmega169

Compiler....: AVR-GCC 3.3.1; avr-libc 1.0

Definition in file avrfat16.h.


Define Documentation

#define FAT16_LDIR_Attr   11

Definition at line 60 of file avrfat16.h.

Referenced by FAT_readFile().

#define FAT16_LDIR_Chksum   13

Definition at line 62 of file avrfat16.h.

Referenced by FAT_readFile().

#define FAT16_LDIR_FstClusLO   26

Definition at line 64 of file avrfat16.h.

#define FAT16_LDIR_Name1   1

Definition at line 59 of file avrfat16.h.

#define FAT16_LDIR_Name2   14

Definition at line 63 of file avrfat16.h.

#define FAT16_LDIR_Name3   28

Definition at line 65 of file avrfat16.h.

#define FAT16_LDIR_Ord   0

Definition at line 58 of file avrfat16.h.

Referenced by FAT_readFile().

#define FAT16_LDIR_Type   12

Definition at line 61 of file avrfat16.h.

#define FILE_ATTR_ARCHIVE   0x20

Definition at line 50 of file avrfat16.h.

Referenced by FAT_readFile().

#define FILE_ATTR_DIRECTORY   0x10

Definition at line 49 of file avrfat16.h.

Referenced by FAT_readFile().

#define FILE_ATTR_HIDDEN   0x02

Definition at line 45 of file avrfat16.h.

Referenced by FAT_readFile().

#define FILE_ATTR_LFN_MASK   0x3F

Definition at line 52 of file avrfat16.h.

Referenced by FAT_readFile().

#define FILE_ATTR_LFN_TEXT   0x0F

Definition at line 51 of file avrfat16.h.

Referenced by FAT_readFile().

#define FILE_ATTR_READ_ONLY   0x01

Definition at line 44 of file avrfat16.h.

#define FILE_ATTR_SYSHID   0x06

Definition at line 47 of file avrfat16.h.

#define FILE_ATTR_SYSTEM   0x04

Definition at line 46 of file avrfat16.h.

#define FILE_ATTR_VOLUME_ID   0x08

Definition at line 48 of file avrfat16.h.

#define FILE_HEADER_BLANK   0x00

Definition at line 53 of file avrfat16.h.

#define FILE_HEADER_DELETED   0xE5

Definition at line 54 of file avrfat16.h.

#define FILE_TYPE_DIR   0x10

Definition at line 55 of file avrfat16.h.

Referenced by cue_file(), FAT_readFile(), FAT_tester(), handle_interface(), and streaming().

#define FILE_TYPE_FILE   0x20

Definition at line 56 of file avrfat16.h.

Referenced by FAT_readFile(), and FAT_tester().

#define FILE_TYPE_MP3   0x55

Definition at line 57 of file avrfat16.h.

#define LFN_ARTIST_INDEX   100

Definition at line 75 of file avrfat16.h.

Referenced by cue_file().

#define LFN_ARTIST_LENGTH   100

Artist length including '\0'.

Definition at line 76 of file avrfat16.h.

Referenced by cue_file().

#define LFN_BUFFER_LENGTH   208

Definition at line 72 of file avrfat16.h.

Referenced by FAT_readFile().

#define LFN_FREE_INDEX   200

Definition at line 77 of file avrfat16.h.

#define LFN_FREE_LEN   8

Currently 8 free bytes in buffer if using ID3 tags not filenames.

Definition at line 78 of file avrfat16.h.

#define LFN_TITLE_INDEX   0

Definition at line 73 of file avrfat16.h.

Referenced by cue_file().

#define LFN_TITLE_LENGTH   100

Title length including '\0'.

Definition at line 74 of file avrfat16.h.

Referenced by cue_file().

#define LFN_TYPE_FILENAME   0x00

No bits set.

Definition at line 69 of file avrfat16.h.

Referenced by FAT_readFile().

#define LFN_TYPE_ID3_ARTIST   0x02

Bit 1.

Definition at line 71 of file avrfat16.h.

Referenced by cue_file().

#define LFN_TYPE_ID3_TITLE   0x01

Bit 0.

Definition at line 70 of file avrfat16.h.

Referenced by cue_file().

#define LFN_TYPE_INDEX   208

Definition at line 68 of file avrfat16.h.

Referenced by cue_file(), and FAT_readFile().

#define PARTITION_START   446

Start address of partition 1 in MBR.

Definition at line 39 of file avrfat16.h.

Referenced by FAT_initFat16().


Function Documentation

uint8 FAT_ChkSum ( uint8 pFcbName)

FAT_ChkSum()

Returns an unsigned byte check sum computed on an unsignedbyte array. The array must be 11 bytes long and is assumed to contain a name stored in the format of a MS-DOS directory entry.

Parameters:
pFcbNamePointer to an unsigned byte array assumed to be 11 bytes long. An 8-bit unsigned checksum of the array pointed to by pFcbName.

Definition at line 748 of file avrfat16.c.

Referenced by FAT_readFile().

uint32 FAT_cluster2lba ( uint32  cluster)

FAT_cluster2lba.

Calculate the sector address of a cluster.

Parameters:
uint32pointing to cluster
Returns:
lba of first sector in cluster

Definition at line 786 of file avrfat16.c.

References FAT16_cluster_begin_lba, and FAT16_sectors_per_cluster.

Referenced by FAT_getParentDir(), FAT_readFile(), and handle_interface().

uint32 FAT_getNextSong ( uint32  filenumber,
uint32  dir_lba 
)

FAT_readRoot.

Read the root directory of the disk and obtain details about FAT entry number <filenumber>

Parameters:
filenumber32bit uInt pointing to file of interst.
Returns:
error code GetNextSong
Parameters:
filenumberuint32 index of current file in directory
dir_lbauint32 lba of directory to search
Returns:
new filenumber or 0=err

Definition at line 627 of file avrfat16.c.

References FAT16_entryMAX, and FAT_readFile().

Referenced by FAT_scanDir_lba(), handle_interface(), restore_player(), and streaming().

Here is the call graph for this function:

uint32 FAT_getNumberedSong ( char  songNumber,
uint32  dir_lba 
)

GetNumberedSong.

Get the file number of a song given a 2 digit BCD of the first two digits of the filename. eg given CHAR2BCD(8) as an argument the function will find the first file in the current directory whos name begins with "08" and ends with ".mp3"

Parameters:
songNumberchar a BCD number 00 - 99 of song/sample
dir_lbauint32 lba of directory to search
Returns:
new filenumber or 0=err

Get the file number of a song given a 2 digit BCD of the first two digits of the filename. eg given CHAR2BCD(8) as an argument the function will find the first file in the current directory whos name begins with "08" and ends with ".mp3". Can be removed from code by setting FAT_NumberedSong_EN to 0.

Parameters:
songNumberchar a BCD number 00 - 99 of song/sample
dir_lbauint32 lba of directory to search
Returns:
new filenumber or 0=err

Definition at line 697 of file avrfat16.c.

References EOL, FAT16_entryMAX, FAT16_entryMIN, FAT16_longfilename, FAT_readFile(), PRINT, UART_Printfu08(), and UART_Puts().

Referenced by play_track_number().

Here is the call graph for this function:

uint32 FAT_getParentDir ( uint32  lba_addr)

FAT_getParentDir.

Parameters:
lba_addruint32 pointing to current directory starting sector
Returns:
first sector of the parent directory or 0 for error

return the first sector of the .. entry. assuming it is the second entry in the directory file. otherwise return 0 to do nothing.

Definition at line 867 of file avrfat16.c.

References FAT16_root_dir_first_sector, FAT_buffer, FAT_cluster2lba(), and FAT_read.

Referenced by handle_interface().

Here is the call graph for this function:

uint32 FAT_getPrevSong ( uint32  filenumber,
uint32  dir_lba 
)

GetPrevSong.

Parameters:
filenumberuint32 index of current file in directory
dir_lbauint32 lba of directory to search
Returns:
file number of next file or zero if none found.

Definition at line 660 of file avrfat16.c.

References FAT16_entryMIN, and FAT_readFile().

Referenced by handle_interface().

Here is the call graph for this function:

uint8 FAT_initFat16 ( void  )

read MBR and bootsector and set fat variables

read MBR and bootsector and set fat variables

read MBR and bootsector and set global fat variables

Returns:
non zero for error.

Definition at line 84 of file avrfat16.c.

References EOL, FAT16_cluster_begin_lba, FAT16_dir_first_sector, FAT16_fat_begin_lba, FAT16_parent_dir_first_sector, FAT16_root_dir_first_sector, FAT16_sectors_per_cluster, FAT_buffer, FAT_read, PARTITION_START, PRINT, UART_Printfu08(), and UART_Printfu16().

Referenced by FAT_tester(), and init_mmc_fat().

Here is the call graph for this function:

uint32 FAT_lba2cluster ( uint32  lba_addr)

FAT_lba2cluster.

Calculate the cluster address of a sector.

Parameters:
lba_addruint32 pointing to lba in cluster
Returns:
cluster containing lba

Calculate the cluster address of a sector.

Parameters:
lba_addruint32 pointing to lba_addr in cluster
Returns:
cluster containing the lba_addr

Definition at line 805 of file avrfat16.c.

References FAT16_cluster_begin_lba, and FAT16_sectors_per_cluster.

Referenced by FAT_readFile().

uint32 FAT_NextCluster ( uint32  cluster)

FAT_NextCluster.

looks up a cluster in fat

Parameters:
clustercurrent cluster
Returns:
next cluster
0 for error
0xffffff for end of file.

Definition at line 264 of file avrfat16.c.

References FAT16_fat_begin_lba, FAT_buffer, and FAT_read.

Referenced by cue_file(), FAT_readFile(), and streaming().

uint8 FAT_readCluster ( uint32  cluster,
uint8  sector_offset 
)

read a sector from a cluster

read a sector from a cluster

copys the volume label

Parameters:
destentaionfor label
Returns:
non zero for error. FAT_readCluster Reads a sector from a cluster into the buffer
Parameters:
clusterClusterto read from
sector_offsetSector to read from within cluster
Returns:
error code from FAT_read()

Definition at line 241 of file avrfat16.c.

References FAT16_cluster_begin_lba, FAT16_sectors_per_cluster, and FAT_read.

Referenced by cue_file(), and streaming().

uint8 FAT_readFile ( uint32  filenumber,
uint32  dir_first_sector 
)

FAT_readRoot.

Read the root directory of the disk and obtain details about FAT entry number filenumber

Parameters:
filenumber32bit uInt pointing to file of interst.
Returns:
error code FAT_read

Read any directory of the disk and obtain details about FAT entry number filenumber

Parameters:
filenumber32bit uInt pointing to file of interst.
dir_first_entry32bit uInt pointing to first cluster of directory
Returns:
error code

FAT_readRoot.

Read any directory of the disk and obtain details about FAT entry number filenumber

error codes:
0x00 mp3file found
0x02 end of directory
0x59 deleted file

Parameters:
filenumber32bit uInt pointing to file of interst.
dir_first_sector32bit uInt pointing to first cluster of directory
Returns:
error code

Definition at line 322 of file avrfat16.c.

References EOL, FAT16_entryMAX, FAT16_filetype, FAT16_LDIR_Attr, FAT16_LDIR_Chksum, FAT16_LDIR_Ord, FAT16_LFNTitleLen, FAT16_longfilename, FAT16_root_dir_first_sector, FAT16_sectors_per_cluster, FAT_buffer, FAT_ChkSum(), FAT_cluster2lba(), FAT_lba2cluster(), FAT_NextCluster(), FAT_read, FAT_scratch, FILE_ATTR_ARCHIVE, FILE_ATTR_DIRECTORY, FILE_ATTR_HIDDEN, FILE_ATTR_LFN_MASK, FILE_ATTR_LFN_TEXT, FILE_TYPE_DIR, FILE_TYPE_FILE, FLG_ROOTDIR, LFN_BUFFER_LENGTH, LFN_TYPE_FILENAME, LFN_TYPE_INDEX, PRINT, strLen(), and UART_Printfu08().

Referenced by cue_file(), FAT_getNextSong(), FAT_getNumberedSong(), FAT_getPrevSong(), and handle_interface().

Here is the call graph for this function:

uint8 FAT_scanDir ( uint32  directory_cluster)

FAT_scanDir.

scan a directory for songs, set max, min and currentdir variables

Parameters:
directory_clusteruint32 pointing to director start cluster
Returns:
number of files found (up to 255)
uint8 FAT_scanDir_lba ( uint32  lba_addr)

FAT_scanDir_lba.

scan a directory for songs, set max, min and currentdir variables

Parameters:
lba_addruint32 pointing to director starting sector
Returns:
number of files found (up to 255)

scan a directory for songs, set max, min and currentdir variables

Parameters:
lba_addruint32 pointing to directory starting sector
Returns:
number of files found (up to 255)

Definition at line 823 of file avrfat16.c.

References FAT16_dir_first_sector, FAT16_entryMAX, FAT16_entryMIN, FAT16_parent_dir_first_sector, and FAT_getNextSong().

Referenced by open_Dir().

Here is the call graph for this function:

void FAT_Scratch2Cluster ( void  )

FAT_Scratch2Cluster.

Extracts the first cluster from the scratchpad buffer left after the most recent FAT_readFile() call

Extracts the first cluster from the scratchpad buffer left after the most recent call of FAT_readFile()

Definition at line 935 of file avrfat16.c.

References FAT_scratch, and gCluster.

Referenced by cue_file(), and handle_interface().


Variable Documentation

Maximum entry number in FAT table. (aka file number)

Definition at line 92 of file avrfat16.h.

Referenced by FAT_getNextSong(), FAT_getNumberedSong(), FAT_readFile(), FAT_scanDir_lba(), handle_interface(), handle_mmc(), init_HW(), and init_mmc_fat().

Minimum entry number in FAT table. (aka file number)

Definition at line 93 of file avrfat16.h.

Referenced by FAT_getNumberedSong(), FAT_getPrevSong(), FAT_scanDir_lba(), handle_interface(), handle_mmc(), init_HW(), init_mmc_fat(), open_Dir(), restore_player(), and streaming().

Definition at line 81 of file avrfat16.h.

Referenced by FAT_initFat16(), FAT_NextCluster(), and FAT_tester().

Definition at line 88 of file avrfat16.h.

Referenced by cue_file(), FAT_readFile(), handle_interface(), and streaming().

Definition at line 91 of file avrfat16.h.

Referenced by cue_file().

Definition at line 90 of file avrfat16.h.

Referenced by cue_file(), and FAT_readFile().

buffer for long filenames / ID3 tags

Definition at line 89 of file avrfat16.h.

Referenced by cue_file(), FAT_getNumberedSong(), FAT_readFile(), and SIGNAL().

Definition at line 86 of file avrfat16.h.

Referenced by FAT_initFat16(), and FAT_scanDir_lba().

512 byte buffer for sector reads/writes

Definition at line 95 of file avrfat16.h.

Referenced by cue_file(), FAT_getParentDir(), FAT_initFat16(), FAT_NextCluster(), FAT_readFile(), FAT_tester(), init_HW(), and streaming().

pointer to read block function

Definition at line 97 of file avrfat16.h.

Referenced by FAT_getParentDir(), FAT_initFat16(), FAT_NextCluster(), FAT_readCluster(), FAT_readFile(), FAT_tester(), and init_HW().

32 byte buffer for filenames and data

Definition at line 96 of file avrfat16.h.

Referenced by cue_file(), FAT_readFile(), FAT_Scratch2Cluster(), and init_HW().

pointer to write block function

Definition at line 98 of file avrfat16.h.

Referenced by FAT_tester().

 All Files Functions Variables Typedefs Enumerations Enumerator Defines