ButterflyMP3

avrfat16.c File Reference

Fat16 Functions. More...

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "types.h"
#include "avrfat16.h"
#include "utils.h"
Include dependency graph for avrfat16.c:

Go to the source code of this file.

Defines

#define FLG_ROOTDIR   0

Functions

uint8 FAT_initFat16 (void)
 FAT_initFat16.
uint8 FAT_readCluster (uint32 cluster, uint8 sector_offset)
 FAT_get_label.
uint32 FAT_NextCluster (uint32 cluster)
 FAT_NextCluster.
uint8 FAT_readFile (uint32 filenumber, uint32 dir_first_sector)
 FAT_read.
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()
uint32 FAT_cluster2lba (uint32 cluster)
 FAT_cluster2lba.
uint32 FAT_lba2cluster (uint32 lba_addr)
 FAT_lba2cluster.
uint8 FAT_scanDir_lba (uint32 lba_addr)
 FAT_scanDir_lba.
uint32 FAT_getParentDir (uint32 lba_addr)
 FAT_getParentDir.
void FAT_Scratch2Cluster ()
 FAT_Scratch2Cluster.

Variables

uint32 gCluster
 current sector (cluster) in song main.h

Detailed Description

Fat16 Functions.

Author:
Nick Lott
Date:
September 2004
Id:
avrfat16.c,v 1.30 2009/01/19 23:36:09 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.c.


Define Documentation

#define FLG_ROOTDIR   0

Referenced by FAT_readFile().


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". 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  )

FAT_initFat16.

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_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 
)

FAT_get_label.

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_read.

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_lba ( uint32  lba_addr)

FAT_scanDir_lba.

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 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

current sector (cluster) in song main.h

Definition at line 79 of file main.c.

Referenced by cue_file(), FAT_Scratch2Cluster(), handle_interface(), restore_player(), save_player_state(), and streaming().

 All Files Functions Variables Typedefs Enumerations Enumerator Defines