No changes between revisions
/Designs/GPSRL03A/Makefile
0,0 → 1,52
PRG = glg
OBJ = main.o tff.o mmc.o
MCU_TARGET = atmega168
OPTIMIZE = -Os -mcall-prologues
DEFS =
LIBS =
DEBUG = dwarf-2
 
CC = avr-gcc
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
ALL_ASFLAGS = -mmcu=$(MCU_TARGET) -I. -x assembler-with-cpp $(ASFLAGS)
CFLAGS = -g$(DEBUG) -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
LDFLAGS = -Wl,-Map,$(PRG).map
 
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
 
 
 
all: $(PRG).elf lst text size
 
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 
clean:
rm -rf *.o $(PRG).elf *.eps *.bak *.a
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES)
rm -rf $(PRG).hex
 
 
 
size: $(PRG).elf
$(SIZE) $(PRG).elf
 
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
 
%.o : %.S
$(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 
 
text: hex
hex: $(PRG).hex
 
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
 
 
/Designs/GPSRL03A/diskio.h
0,0 → 1,64
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file R0.04a (C)ChaN, 2007
/-----------------------------------------------------------------------*/
 
#ifndef _DISKIO
 
#define _READONLY 0 /* 1: Read-only mode */
 
#include "integer.h"
 
 
/* Status of Disk Functions */
typedef BYTE DSTATUS;
 
/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
 
 
/*---------------------------------------*/
/* Prototypes for disk control functions */
 
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (BYTE, BYTE, void*);
void disk_timerproc (void);
 
 
 
 
/* Disk Status Bits (DSTATUS) */
 
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
 
 
/* Command code for disk_ioctrl() */
 
#define GET_SECTOR_COUNT 1
#define GET_SECTOR_SIZE 2
#define CTRL_SYNC 3
#define CTRL_POWER 4
#define CTRL_LOCK 5
#define CTRL_EJECT 6
#define MMC_GET_CSD 10
#define MMC_GET_CID 11
#define MMC_GET_OCR 12
#define ATA_GET_REV 20
#define ATA_GET_MODEL 21
#define ATA_GET_SN 22
 
 
#define _DISKIO
#endif
/Designs/GPSRL03A/ff.c
0,0 → 1,2036
/*----------------------------------------------------------------------------/
/ FatFs - FAT file system module R0.06 (C)ChaN, 2008
/-----------------------------------------------------------------------------/
/ The FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2008, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
/ commercial use without restriction under your responsibility.
/ * Redistributions of source code must retain the above copyright notice.
/
/-----------------------------------------------------------------------------/
/ Feb 26,'06 R0.00 Prototype.
/
/ Apr 29,'06 R0.01 First stable version.
/
/ Jun 01,'06 R0.02 Added FAT12 support.
/ Removed unbuffered mode.
/ Fixed a problem on small (<32M) patition.
/ Jun 10,'06 R0.02a Added a configuration option (_FS_MINIMUM).
/
/ Sep 22,'06 R0.03 Added f_rename().
/ Changed option _FS_MINIMUM to _FS_MINIMIZE.
/ Dec 11,'06 R0.03a Improved cluster scan algolithm to write files fast.
/ Fixed f_mkdir() creates incorrect directory on FAT32.
/
/ Feb 04,'07 R0.04 Supported multiple drive system.
/ Changed some interfaces for multiple drive system.
/ Changed f_mountdrv() to f_mount().
/ Added f_mkfs().
/ Apr 01,'07 R0.04a Supported multiple partitions on a plysical drive.
/ Added a capability of extending file size to f_lseek().
/ Added minimization level 3.
/ Fixed an endian sensitive code in f_mkfs().
/ May 05,'07 R0.04b Added a configuration option _USE_NTFLAG.
/ Added FSInfo support.
/ Fixed DBCS name can result FR_INVALID_NAME.
/ Fixed short seek (<= csize) collapses the file object.
/
/ Aug 25,'07 R0.05 Changed arguments of f_read(), f_write() and f_mkfs().
/ Fixed f_mkfs() on FAT32 creates incorrect FSInfo.
/ Fixed f_mkdir() on FAT32 creates incorrect directory.
/ Feb 03,'08 R0.05a Added f_truncate() and f_utime().
/ Fixed off by one error at FAT sub-type determination.
/ Fixed btr in f_read() can be mistruncated.
/ Fixed cached sector is not flushed when create and close
/ without write.
/
/ Apr 01,'08 R0.06 Added fputc(), fputs(), fprintf() and fgets().
/ Improved performance of f_lseek() on moving to the same
/ or following cluster.
/---------------------------------------------------------------------------*/
 
#include <string.h>
#include "ff.h" /* FatFs declarations */
#include "diskio.h" /* Include file for user provided disk functions */
 
 
/*--------------------------------------------------------------------------
 
Module Private Functions
 
---------------------------------------------------------------------------*/
 
static
FATFS *FatFs[_DRIVES]; /* Pointer to the file system objects (logical drives) */
static
WORD fsid; /* File system mount ID */
 
 
 
/*-----------------------------------------------------------------------*/
/* Change window offset */
/*-----------------------------------------------------------------------*/
 
static
BOOL move_window ( /* TRUE: successful, FALSE: failed */
FATFS *fs, /* File system object */
DWORD sector /* Sector number to make apperance in the fs->win[] */
) /* Move to zero only writes back dirty window */
{
DWORD wsect;
 
 
wsect = fs->winsect;
if (wsect != sector) { /* Changed current window */
#if !_FS_READONLY
BYTE n;
if (fs->winflag) { /* Write back dirty window if needed */
if (disk_write(fs->drive, fs->win, wsect, 1) != RES_OK)
return FALSE;
fs->winflag = 0;
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to FAT copy */
wsect += fs->sects_fat;
disk_write(fs->drive, fs->win, wsect, 1);
}
}
}
#endif
if (sector) {
if (disk_read(fs->drive, fs->win, sector, 1) != RES_OK)
return FALSE;
fs->winsect = sector;
}
}
return TRUE;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Clean-up cached data */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
FRESULT sync ( /* FR_OK: successful, FR_RW_ERROR: failed */
FATFS *fs /* File system object */
)
{
fs->winflag = 1;
if (!move_window(fs, 0)) return FR_RW_ERROR;
#if _USE_FSINFO
/* Update FSInfo sector if needed */
if (fs->fs_type == FS_FAT32 && fs->fsi_flag) {
fs->winsect = 0;
memset(fs->win, 0, 512);
ST_WORD(&fs->win[BS_55AA], 0xAA55);
ST_DWORD(&fs->win[FSI_LeadSig], 0x41615252);
ST_DWORD(&fs->win[FSI_StrucSig], 0x61417272);
ST_DWORD(&fs->win[FSI_Free_Count], fs->free_clust);
ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust);
disk_write(fs->drive, fs->win, fs->fsi_sector, 1);
fs->fsi_flag = 0;
}
#endif
/* Make sure that no pending write process in the physical drive */
if (disk_ioctl(fs->drive, CTRL_SYNC, NULL) != RES_OK)
return FR_RW_ERROR;
return FR_OK;
}
#endif
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get a cluster status */
/*-----------------------------------------------------------------------*/
 
static
DWORD get_cluster ( /* 0,>=2: successful, 1: failed */
FATFS *fs, /* File system object */
DWORD clust /* Cluster# to get the link information */
)
{
WORD wc, bc;
DWORD fatsect;
 
 
if (clust >= 2 && clust < fs->max_clust) { /* Is it a valid cluster#? */
fatsect = fs->fatbase;
switch (fs->fs_type) {
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fs, fatsect + (bc / SS(fs)))) break;
wc = fs->win[bc & (SS(fs) - 1)]; bc++;
if (!move_window(fs, fatsect + (bc / SS(fs)))) break;
wc |= (WORD)fs->win[bc & (SS(fs) - 1)] << 8;
return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
 
case FS_FAT16 :
if (!move_window(fs, fatsect + (clust / (SS(fs) / 2)))) break;
return LD_WORD(&fs->win[((WORD)clust * 2) & (SS(fs) - 1)]);
 
case FS_FAT32 :
if (!move_window(fs, fatsect + (clust / (SS(fs) / 4)))) break;
return LD_DWORD(&fs->win[((WORD)clust * 4) & (SS(fs) - 1)]) & 0x0FFFFFFF;
}
}
 
return 1; /* Out of cluster range, or an error occured */
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Change a cluster status */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
BOOL put_cluster ( /* TRUE: successful, FALSE: failed */
FATFS *fs, /* File system object */
DWORD clust, /* Cluster# to change (must be 2 to fs->max_clust-1) */
DWORD val /* New value to mark the cluster */
)
{
WORD bc;
BYTE *p;
DWORD fatsect;
 
 
fatsect = fs->fatbase;
switch (fs->fs_type) {
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fs, fatsect + (bc / SS(fs)))) return FALSE;
p = &fs->win[bc & (SS(fs) - 1)];
*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
bc++;
fs->winflag = 1;
if (!move_window(fs, fatsect + (bc / SS(fs)))) return FALSE;
p = &fs->win[bc & (SS(fs) - 1)];
*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
break;
 
case FS_FAT16 :
if (!move_window(fs, fatsect + (clust / (SS(fs) / 2)))) return FALSE;
ST_WORD(&fs->win[((WORD)clust * 2) & (SS(fs) - 1)], (WORD)val);
break;
 
case FS_FAT32 :
if (!move_window(fs, fatsect + (clust / (SS(fs) / 4)))) return FALSE;
ST_DWORD(&fs->win[((WORD)clust * 4) & (SS(fs) - 1)], val);
break;
 
default :
return FALSE;
}
fs->winflag = 1;
return TRUE;
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Remove a cluster chain */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
BOOL remove_chain ( /* TRUE: successful, FALSE: failed */
FATFS *fs, /* File system object */
DWORD clust /* Cluster# to remove chain from */
)
{
DWORD nxt;
 
 
while (clust >= 2 && clust < fs->max_clust) {
nxt = get_cluster(fs, clust);
if (nxt == 1) return FALSE;
if (!put_cluster(fs, clust, 0)) return FALSE;
if (fs->free_clust != 0xFFFFFFFF) {
fs->free_clust++;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
clust = nxt;
}
return TRUE;
}
#endif
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Stretch or create a cluster chain */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
DWORD create_chain ( /* 0: No free cluster, 1: Error, >=2: New cluster number */
FATFS *fs, /* File system object */
DWORD clust /* Cluster# to stretch, 0 means create new */
)
{
DWORD cstat, ncl, scl, mcl = fs->max_clust;
 
 
if (clust == 0) { /* Create new chain */
scl = fs->last_clust; /* Get suggested start point */
if (scl == 0 || scl >= mcl) scl = 1;
}
else { /* Stretch existing chain */
cstat = get_cluster(fs, clust); /* Check the cluster status */
if (cstat < 2) return 1; /* It is an invalid cluster */
if (cstat < mcl) return cstat; /* It is already followed by next cluster */
scl = clust;
}
 
ncl = scl; /* Start cluster */
for (;;) {
ncl++; /* Next cluster */
if (ncl >= mcl) { /* Wrap around */
ncl = 2;
if (ncl > scl) return 0; /* No free custer */
}
cstat = get_cluster(fs, ncl); /* Get the cluster status */
if (cstat == 0) break; /* Found a free cluster */
if (cstat == 1) return 1; /* Any error occured */
if (ncl == scl) return 0; /* No free custer */
}
 
if (!put_cluster(fs, ncl, 0x0FFFFFFF)) return 1; /* Mark the new cluster "in use" */
if (clust != 0 && !put_cluster(fs, clust, ncl)) return 1; /* Link it to previous one if needed */
 
fs->last_clust = ncl; /* Update fsinfo */
if (fs->free_clust != 0xFFFFFFFF) {
fs->free_clust--;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
 
return ncl; /* Return new cluster number */
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get sector# from cluster# */
/*-----------------------------------------------------------------------*/
 
static
DWORD clust2sect ( /* !=0: sector number, 0: failed - invalid cluster# */
FATFS *fs, /* File system object */
DWORD clust /* Cluster# to be converted */
)
{
clust -= 2;
if (clust >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */
return clust * fs->csize + fs->database;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Move directory pointer to next */
/*-----------------------------------------------------------------------*/
 
static
BOOL next_dir_entry ( /* TRUE: successful, FALSE: could not move next */
DIR *dj /* Pointer to directory object */
)
{
DWORD clust;
WORD idx;
 
 
idx = dj->index + 1;
if ((idx & ((SS(dj->fs) - 1) / 32)) == 0) { /* Table sector changed? */
dj->sect++; /* Next sector */
if (dj->clust == 0) { /* In static table */
if (idx >= dj->fs->n_rootdir) return FALSE; /* Reached to end of table */
} else { /* In dynamic table */
if (((idx / (SS(dj->fs) / 32)) & (dj->fs->csize - 1)) == 0) { /* Cluster changed? */
clust = get_cluster(dj->fs, dj->clust); /* Get next cluster */
if (clust < 2 || clust >= dj->fs->max_clust) /* Reached to end of table */
return FALSE;
dj->clust = clust; /* Initialize for new cluster */
dj->sect = clust2sect(dj->fs, clust);
}
}
}
dj->index = idx; /* Lower several bits of dj->index indicates offset in dj->sect */
return TRUE;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get file status from directory entry */
/*-----------------------------------------------------------------------*/
 
#if _FS_MINIMIZE <= 1
static
void get_fileinfo ( /* No return code */
FILINFO *finfo, /* Ptr to store the file information */
const BYTE *dir /* Ptr to the directory entry */
)
{
BYTE n, c, a;
char *p;
 
 
p = &finfo->fname[0];
a = _USE_NTFLAG ? dir[DIR_NTres] : 0; /* NT flag */
for (n = 0; n < 8; n++) { /* Convert file name (body) */
c = dir[n];
if (c == ' ') break;
if (c == 0x05) c = 0xE5;
if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20;
*p++ = c;
}
if (dir[8] != ' ') { /* Convert file name (extension) */
*p++ = '.';
for (n = 8; n < 11; n++) {
c = dir[n];
if (c == ' ') break;
if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20;
*p++ = c;
}
}
*p = '\0';
 
finfo->fattrib = dir[DIR_Attr]; /* Attribute */
finfo->fsize = LD_DWORD(&dir[DIR_FileSize]); /* Size */
finfo->fdate = LD_WORD(&dir[DIR_WrtDate]); /* Date */
finfo->ftime = LD_WORD(&dir[DIR_WrtTime]); /* Time */
}
#endif /* _FS_MINIMIZE <= 1 */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Pick a paragraph and create the name in format of directory entry */
/*-----------------------------------------------------------------------*/
 
static
char make_dirfile ( /* 1: error - detected an invalid format, '\0'or'/': next character */
const char **path, /* Pointer to the file path pointer */
char *dirname /* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */
)
{
BYTE n, t, c, a, b;
 
 
memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
a = 0; b = 0x18; /* NT flag */
n = 0; t = 8;
for (;;) {
c = *(*path)++;
if (c == '\0' || c == '/') { /* Reached to end of str or directory separator */
if (n == 0) break;
dirname[11] = _USE_NTFLAG ? (a & b) : 0;
return c;
}
if (c <= ' ' || c == 0x7F) break; /* Reject invisible chars */
if (c == '.') {
if (!(a & 1) && n >= 1 && n <= 8) { /* Enter extension part */
n = 8; t = 11; continue;
}
break;
}
if (_USE_SJIS &&
((c >= 0x81 && c <= 0x9F) || /* Accept S-JIS code */
(c >= 0xE0 && c <= 0xFC))) {
if (n == 0 && c == 0xE5) /* Change heading \xE5 to \x05 */
c = 0x05;
a ^= 0x01; goto md_l2;
}
if (c == '"') break; /* Reject " */
if (c <= ')') goto md_l1; /* Accept ! # $ % & ' ( ) */
if (c <= ',') break; /* Reject * + , */
if (c <= '9') goto md_l1; /* Accept - 0-9 */
if (c <= '?') break; /* Reject : ; < = > ? */
if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
if (c == '|') break; /* Reject | */
if (c >= '[' && c <= ']') break;/* Reject [ \ ] */
if (_USE_NTFLAG && c >= 'A' && c <= 'Z')
(t == 8) ? (b &= 0xF7) : (b &= 0xEF);
if (c >= 'a' && c <= 'z') { /* Convert to upper case */
c -= 0x20;
if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
}
}
md_l1:
a &= 0xFE;
md_l2:
if (n >= t) break;
dirname[n++] = c;
}
return 1;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Trace a file path */
/*-----------------------------------------------------------------------*/
 
static
FRESULT trace_path ( /* FR_OK(0): successful, !=0: error code */
DIR *dj, /* Pointer to directory object to return last directory */
char *fn, /* Pointer to last segment name to return {file(8),ext(3),attr(1)} */
const char *path, /* Full-path string to trace a file or directory */
BYTE **dir /* Pointer to pointer to found entry to retutn */
)
{
DWORD clust;
char ds;
BYTE *dptr = NULL;
FATFS *fs = dj->fs;
 
 
/* Initialize directory object */
clust = fs->dirbase;
if (fs->fs_type == FS_FAT32) {
dj->clust = dj->sclust = clust;
dj->sect = clust2sect(fs, clust);
} else {
dj->clust = dj->sclust = 0;
dj->sect = clust;
}
dj->index = 0;
 
if (*path == '\0') { /* Null path means the root directory */
*dir = NULL; return FR_OK;
}
 
for (;;) {
ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */
if (ds == 1) return FR_INVALID_NAME;
for (;;) {
if (!move_window(fs, dj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dj->index & ((SS(fs) - 1) / 32)) * 32]; /* Pointer to the directory entry */
if (dptr[DIR_Name] == 0) /* Has it reached to end of dir? */
return !ds ? FR_NO_FILE : FR_NO_PATH;
if (dptr[DIR_Name] != 0xE5 /* Matched? */
&& !(dptr[DIR_Attr] & AM_VOL)
&& !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
if (!next_dir_entry(dj)) /* Next directory pointer */
return !ds ? FR_NO_FILE : FR_NO_PATH;
}
if (!ds) { *dir = dptr; return FR_OK; } /* Matched with end of path */
if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */
clust = ((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) | LD_WORD(&dptr[DIR_FstClusLO]); /* Get cluster# of the directory */
dj->clust = dj->sclust = clust; /* Restart scanning at the new directory */
dj->sect = clust2sect(fs, clust);
dj->index = 2;
}
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Reserve a directory entry */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
FRESULT reserve_direntry ( /* FR_OK: successful, FR_DENIED: no free entry, FR_RW_ERROR: a disk error occured */
DIR *dj, /* Target directory to create new entry */
BYTE **dir /* Pointer to pointer to created entry to retutn */
)
{
DWORD clust, sector;
BYTE c, n, *dptr;
FATFS *fs = dj->fs;
 
 
/* Re-initialize directory object */
clust = dj->sclust;
if (clust != 0) { /* Dyanmic directory table */
dj->clust = clust;
dj->sect = clust2sect(fs, clust);
} else { /* Static directory table */
dj->sect = fs->dirbase;
}
dj->index = 0;
 
do {
if (!move_window(fs, dj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dj->index & ((SS(dj->fs) - 1) / 32)) * 32]; /* Pointer to the directory entry */
c = dptr[DIR_Name];
if (c == 0 || c == 0xE5) { /* Found an empty entry */
*dir = dptr; return FR_OK;
}
} while (next_dir_entry(dj)); /* Next directory pointer */
/* Reached to end of the directory table */
 
/* Abort when it is a static table or could not stretch dynamic table */
if (clust == 0 || !(clust = create_chain(fs, dj->clust))) return FR_DENIED;
if (clust == 1 || !move_window(fs, 0)) return FR_RW_ERROR;
 
/* Cleanup the expanded table */
fs->winsect = sector = clust2sect(fs, clust);
memset(fs->win, 0, SS(fs));
for (n = fs->csize; n; n--) {
if (disk_write(fs->drive, fs->win, sector, 1) != RES_OK)
return FR_RW_ERROR;
sector++;
}
fs->winflag = 1;
*dir = fs->win;
 
return FR_OK;
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Load boot record and check if it is an FAT boot record */
/*-----------------------------------------------------------------------*/
 
static
BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error */
FATFS *fs, /* File system object */
DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */
)
{
if (disk_read(fs->drive, fs->win, sect, 1) != RES_OK) /* Load boot record */
return 2;
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */
return 2;
 
if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3)) /* Check FAT signature */
return 0;
if (!memcmp(&fs->win[BS_FilSysType32], "FAT32", 5) && !(fs->win[BPB_ExtFlags] & 0x80))
return 0;
 
return 1;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Make sure that the file system is valid */
/*-----------------------------------------------------------------------*/
 
static
FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */
const char **path, /* Pointer to pointer to the path name (drive number) */
FATFS **rfs, /* Pointer to pointer to the found file system object */
BYTE chk_wp /* !=0: Check media write protection for write access */
)
{
BYTE drv, fmt, *tbl;
DSTATUS stat;
DWORD bootsect, fatsize, totalsect, maxclust;
const char *p = *path;
FATFS *fs;
 
 
/* Get drive number from the path name */
while (*p == ' ') p++; /* Strip leading spaces */
drv = p[0] - '0'; /* Is there a drive number? */
if (drv <= 9 && p[1] == ':')
p += 2; /* Found a drive number, get and strip it */
else
drv = 0; /* No drive number is given, use drive number 0 as default */
if (*p == '/') p++; /* Strip heading slash */
*path = p; /* Return pointer to the path name */
 
/* Check if the drive number is valid or not */
if (drv >= _DRIVES) return FR_INVALID_DRIVE; /* Is the drive number valid? */
*rfs = fs = FatFs[drv]; /* Returen pointer to the corresponding file system object */
if (!fs) return FR_NOT_ENABLED; /* Is the file system object registered? */
 
if (fs->fs_type) { /* If the logical drive has been mounted */
stat = disk_status(fs->drive);
if (!(stat & STA_NOINIT)) { /* and physical drive is kept initialized (has not been changed), */
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
#endif
return FR_OK; /* The file system object is valid */
}
}
 
/* The logical drive must be re-mounted. Following code attempts to mount the logical drive */
 
memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
fs->drive = LD2PD(drv); /* Bind the logical drive and a physical drive */
stat = disk_initialize(fs->drive); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY;
#if S_MAX_SIZ > 512 /* Get disk sector size if needed */
if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > S_MAX_SIZ)
return FR_NO_FILESYSTEM;
#endif
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
#endif
/* Search FAT partition on the drive */
fmt = check_fs(fs, bootsect = 0); /* Check sector 0 as an SFD format */
if (fmt == 1) { /* Not an FAT boot record, it may be patitioned */
/* Check a partition listed in top of the partition table */
tbl = &fs->win[MBR_Table + LD2PT(drv) * 16]; /* Partition table */
if (tbl[4]) { /* Is the partition existing? */
bootsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */
fmt = check_fs(fs, bootsect); /* Check the partition */
}
}
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != SS(fs)) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
 
/* Initialize the file system object */
fatsize = LD_WORD(&fs->win[BPB_FATSz16]); /* Number of sectors per FAT */
if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]);
fs->sects_fat = fatsize;
fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */
fatsize *= fs->n_fats; /* (Number of sectors in FAT area) */
fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */
fs->csize = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */
fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]); /* Nmuber of root directory entries */
totalsect = LD_WORD(&fs->win[BPB_TotSec16]); /* Number of sectors on the file system */
if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]);
fs->max_clust = maxclust = (totalsect /* max_clust = Last cluster# + 1 */
- LD_WORD(&fs->win[BPB_RsvdSecCnt]) - fatsize - fs->n_rootdir / (SS(fs)/32)
) / fs->csize + 2;
 
fmt = FS_FAT12; /* Determine the FAT sub type */
if (maxclust >= 0xFF7) fmt = FS_FAT16;
if (maxclust >= 0xFFF7) fmt = FS_FAT32;
 
if (fmt == FS_FAT32)
fs->dirbase = LD_DWORD(&fs->win[BPB_RootClus]); /* Root directory start cluster */
else
fs->dirbase = fs->fatbase + fatsize; /* Root directory start sector (lba) */
fs->database = fs->fatbase + fatsize + fs->n_rootdir / (SS(fs)/32); /* Data start sector (lba) */
 
#if !_FS_READONLY
/* Initialize allocation information */
fs->free_clust = 0xFFFFFFFF;
#if _USE_FSINFO
/* Get fsinfo if needed */
if (fmt == FS_FAT32) {
fs->fsi_sector = bootsect + LD_WORD(&fs->win[BPB_FSInfo]);
if (disk_read(fs->drive, fs->win, fs->fsi_sector, 1) == RES_OK &&
LD_WORD(&fs->win[BS_55AA]) == 0xAA55 &&
LD_DWORD(&fs->win[FSI_LeadSig]) == 0x41615252 &&
LD_DWORD(&fs->win[FSI_StrucSig]) == 0x61417272) {
fs->last_clust = LD_DWORD(&fs->win[FSI_Nxt_Free]);
fs->free_clust = LD_DWORD(&fs->win[FSI_Free_Count]);
}
}
#endif
#endif
 
fs->fs_type = fmt; /* FAT syb-type */
fs->id = ++fsid; /* File system mount ID */
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Check if the file/dir object is valid or not */
/*-----------------------------------------------------------------------*/
 
static
FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */
const FATFS *fs, /* Pointer to the file system object */
WORD id /* Member id of the target object to be checked */
)
{
if (!fs || !fs->fs_type || fs->id != id)
return FR_INVALID_OBJECT;
if (disk_status(fs->drive) & STA_NOINIT)
return FR_NOT_READY;
 
return FR_OK;
}
 
 
 
 
/*--------------------------------------------------------------------------
 
Public Functions
 
--------------------------------------------------------------------------*/
 
 
 
/*-----------------------------------------------------------------------*/
/* Mount/Unmount a Locical Drive */
/*-----------------------------------------------------------------------*/
 
FRESULT f_mount (
BYTE drv, /* Logical drive number to be mounted/unmounted */
FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
)
{
if (drv >= _DRIVES) return FR_INVALID_DRIVE;
 
if (FatFs[drv]) FatFs[drv]->fs_type = 0; /* Clear old object */
 
FatFs[drv] = fs; /* Register and clear new object */
if (fs) fs->fs_type = 0;
 
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Open or Create a File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_open (
FIL *fp, /* Pointer to the blank file object */
const char *path, /* Pointer to the file name */
BYTE mode /* Access mode and file open mode flags */
)
{
FRESULT res;
DIR dj;
BYTE *dir;
char fn[8+3+1];
 
 
fp->fs = NULL; /* Clear file object */
#if !_FS_READONLY
mode &= (FA_READ|FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW);
res = auto_mount(&path, &dj.fs, (BYTE)(mode & (FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)));
#else
mode &= FA_READ;
res = auto_mount(&path, &dj.fs, 0);
#endif
if (res != FR_OK) return res;
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
 
#if !_FS_READONLY
/* Create or Open a file */
if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)) {
DWORD ps, rs;
if (res != FR_OK) { /* No file, create new */
if (res != FR_NO_FILE) return res;
res = reserve_direntry(&dj, &dir);
if (res != FR_OK) return res;
memset(dir, 0, 32); /* Initialize the new entry with open name */
memcpy(&dir[DIR_Name], fn, 8+3);
dir[DIR_NTres] = fn[11];
mode |= FA_CREATE_ALWAYS;
}
else { /* Any object is already existing */
if (mode & FA_CREATE_NEW) /* Cannot create new */
return FR_EXIST;
if (!dir || (dir[DIR_Attr] & (AM_RDO|AM_DIR))) /* Cannot overwrite it (R/O or DIR) */
return FR_DENIED;
if (mode & FA_CREATE_ALWAYS) { /* Resize it to zero if needed */
rs = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]); /* Get start cluster */
ST_WORD(&dir[DIR_FstClusHI], 0); /* cluster = 0 */
ST_WORD(&dir[DIR_FstClusLO], 0);
ST_DWORD(&dir[DIR_FileSize], 0); /* size = 0 */
dj.fs->winflag = 1;
ps = dj.fs->winsect; /* Remove the cluster chain */
if (!remove_chain(dj.fs, rs) || !move_window(dj.fs, ps))
return FR_RW_ERROR;
dj.fs->last_clust = rs - 1; /* Reuse the cluster hole */
}
}
if (mode & FA_CREATE_ALWAYS) {
dir[DIR_Attr] = 0; /* Reset attribute */
ps = get_fattime();
ST_DWORD(&dir[DIR_CrtTime], ps); /* Created time */
dj.fs->winflag = 1;
mode |= FA__WRITTEN; /* Set file changed flag */
}
}
/* Open an existing file */
else {
#endif /* !_FS_READONLY */
if (res != FR_OK) return res; /* Trace failed */
if (!dir || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */
return FR_NO_FILE;
#if !_FS_READONLY
if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */
return FR_DENIED;
}
fp->dir_sect = dj.fs->winsect; /* Pointer to the directory entry */
fp->dir_ptr = dir;
#endif
fp->flag = mode; /* File access mode */
fp->org_clust = /* File start cluster */
((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]);
fp->fsize = LD_DWORD(&dir[DIR_FileSize]); /* File size */
fp->fptr = 0; fp->csect = 255; /* File pointer */
fp->curr_sect = 0;
fp->fs = dj.fs; fp->id = dj.fs->id; /* Owner file system object of the file */
 
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Read File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_read (
FIL *fp, /* Pointer to the file object */
void *buff, /* Pointer to data buffer */
UINT btr, /* Number of bytes to read */
UINT *br /* Pointer to number of bytes read */
)
{
FRESULT res;
DWORD clust, sect, remain;
UINT rcnt, cc;
BYTE *rbuff = buff;
 
 
*br = 0;
res = validate(fp->fs, fp->id); /* Check validity of the object */
if (res != FR_OK) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
remain = fp->fsize - fp->fptr;
if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
 
for ( ; btr; /* Repeat until all data transferred */
rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */
if (fp->csect >= fp->fs->csize) { /* On the cluster boundary? */
clust = (fp->fptr == 0) ? /* On the top of the file? */
fp->org_clust : get_cluster(fp->fs, fp->curr_clust);
if (clust < 2 || clust >= fp->fs->max_clust) goto fr_error;
fp->curr_clust = clust; /* Update current cluster */
fp->csect = 0; /* Reset sector address in the cluster */
}
sect = clust2sect(fp->fs, fp->curr_clust) + fp->csect; /* Get current sector */
cc = btr / SS(fp->fs); /* When remaining bytes >= sector size, */
if (cc) { /* Read maximum contiguous sectors directly */
if (fp->csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - fp->csect;
if (disk_read(fp->fs->drive, rbuff, sect, (BYTE)cc) != RES_OK)
goto fr_error;
fp->csect += (BYTE)cc; /* Next sector address in the cluster */
rcnt = SS(fp->fs) * cc; /* Number of bytes transferred */
continue;
}
if (sect != fp->curr_sect) { /* Is window offset changed? */
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write back file I/O buffer if needed */
if (disk_write(fp->fs->drive, fp->buffer, fp->curr_sect, 1) != RES_OK)
goto fr_error;
fp->flag &= (BYTE)~FA__DIRTY;
}
#endif
if (disk_read(fp->fs->drive, fp->buffer, sect, 1) != RES_OK) /* Fill file I/O buffer with file data */
goto fr_error;
fp->curr_sect = sect;
}
fp->csect++; /* Next sector address in the cluster */
}
rcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs)); /* Get partial sector from file I/O buffer */
if (rcnt > btr) rcnt = btr;
memcpy(rbuff, &fp->buffer[fp->fptr % SS(fp->fs)], rcnt);
}
 
return FR_OK;
 
fr_error: /* Abort this file due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
#if !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Write File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_write (
FIL *fp, /* Pointer to the file object */
const void *buff, /* Pointer to the data to be written */
UINT btw, /* Number of bytes to write */
UINT *bw /* Pointer to number of bytes written */
)
{
FRESULT res;
DWORD clust, sect;
UINT wcnt, cc;
const BYTE *wbuff = buff;
 
 
*bw = 0;
res = validate(fp->fs, fp->id); /* Check validity of the object */
if (res != FR_OK) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
 
for ( ; btw; /* Repeat until all data transferred */
wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */
if (fp->csect >= fp->fs->csize) { /* On the cluster boundary? */
if (fp->fptr == 0) { /* On the top of the file? */
clust = fp->org_clust; /* Follow from the origin */
if (clust == 0) /* When there is no cluster chain, */
fp->org_clust = clust = create_chain(fp->fs, 0); /* Create a new cluster chain */
} else { /* Middle or end of the file */
clust = create_chain(fp->fs, fp->curr_clust); /* Trace or streach cluster chain */
}
if (clust == 0) break; /* Could not allocate a new cluster (disk full) */
if (clust == 1 || clust >= fp->fs->max_clust) goto fw_error;
fp->curr_clust = clust; /* Update current cluster */
fp->csect = 0; /* Reset sector address in the cluster */
}
sect = clust2sect(fp->fs, fp->curr_clust) + fp->csect; /* Get current sector */
cc = btw / SS(fp->fs); /* When remaining bytes >= sector size, */
if (cc) { /* Write maximum contiguous sectors directly */
if (fp->csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - fp->csect;
if (disk_write(fp->fs->drive, wbuff, sect, (BYTE)cc) != RES_OK)
goto fw_error;
fp->csect += (BYTE)cc; /* Next sector address in the cluster */
wcnt = SS(fp->fs) * cc; /* Number of bytes transferred */
continue;
}
if (sect != fp->curr_sect) { /* Is window offset changed? */
if (fp->flag & FA__DIRTY) { /* Write back file I/O buffer if needed */
if (disk_write(fp->fs->drive, fp->buffer, fp->curr_sect, 1) != RES_OK)
goto fw_error;
fp->flag &= (BYTE)~FA__DIRTY;
}
if (fp->fptr < fp->fsize && /* Fill file I/O buffer with file data */
disk_read(fp->fs->drive, fp->buffer, sect, 1) != RES_OK)
goto fw_error;
fp->curr_sect = sect;
}
fp->csect++; /* Next sector address in the cluster */
}
wcnt = SS(fp->fs) - (fp->fptr % SS(fp->fs)); /* Put partial sector into file I/O buffer */
if (wcnt > btw) wcnt = btw;
memcpy(&fp->buffer[fp->fptr % SS(fp->fs)], wbuff, wcnt);
fp->flag |= FA__DIRTY;
}
 
if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */
fp->flag |= FA__WRITTEN; /* Set file changed flag */
return FR_OK;
 
fw_error: /* Abort this file due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Synchronize the file object */
/*-----------------------------------------------------------------------*/
 
FRESULT f_sync (
FIL *fp /* Pointer to the file object */
)
{
FRESULT res;
DWORD tim;
BYTE *dir;
 
 
res = validate(fp->fs, fp->id); /* Check validity of the object */
if (res == FR_OK) {
if (fp->flag & FA__WRITTEN) { /* Has the file been written? */
/* Write back data buffer if needed */
if (fp->flag & FA__DIRTY) {
if (disk_write(fp->fs->drive, fp->buffer, fp->curr_sect, 1) != RES_OK)
return FR_RW_ERROR;
fp->flag &= (BYTE)~FA__DIRTY;
}
/* Update the directory entry */
if (!move_window(fp->fs, fp->dir_sect))
return FR_RW_ERROR;
dir = fp->dir_ptr;
dir[DIR_Attr] |= AM_ARC; /* Set archive bit */
ST_DWORD(&dir[DIR_FileSize], fp->fsize); /* Update file size */
ST_WORD(&dir[DIR_FstClusLO], fp->org_clust); /* Update start cluster */
ST_WORD(&dir[DIR_FstClusHI], fp->org_clust >> 16);
tim = get_fattime(); /* Updated time */
ST_DWORD(&dir[DIR_WrtTime], tim);
fp->flag &= (BYTE)~FA__WRITTEN;
res = sync(fp->fs);
}
}
return res;
}
 
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Close File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_close (
FIL *fp /* Pointer to the file object to be closed */
)
{
FRESULT res;
 
 
#if !_FS_READONLY
res = f_sync(fp);
#else
res = validate(fp->fs, fp->id);
#endif
if (res == FR_OK) fp->fs = NULL;
return res;
}
 
 
 
 
#if _FS_MINIMIZE <= 2
/*-----------------------------------------------------------------------*/
/* Seek File R/W Pointer */
/*-----------------------------------------------------------------------*/
 
FRESULT f_lseek (
FIL *fp, /* Pointer to the file object */
DWORD ofs /* File pointer from top of file */
)
{
FRESULT res;
DWORD clust, csize, nsect, ifptr;
 
 
res = validate(fp->fs, fp->id); /* Check validity of the object */
if (res != FR_OK) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR;
if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */
#if !_FS_READONLY
&& !(fp->flag & FA_WRITE)
#endif
) ofs = fp->fsize;
 
ifptr = fp->fptr;
fp->fptr = 0; fp->csect = 255;
nsect = 0;
if (ofs > 0) {
csize = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */
if (ifptr > 0 &&
(ofs - 1) / csize >= (ifptr - 1) / csize) {/* When seek to same or following cluster, */
fp->fptr = (ifptr - 1) & ~(csize - 1); /* start from the current cluster */
ofs -= fp->fptr;
clust = fp->curr_clust;
} else { /* When seek to back cluster, */
clust = fp->org_clust; /* start from the first cluster */
#if !_FS_READONLY
if (clust == 0) { /* If no cluster chain, create a new chain */
clust = create_chain(fp->fs, 0);
if (clust == 1) goto fk_error;
fp->org_clust = clust;
}
#endif
fp->curr_clust = clust;
}
if (clust != 0) {
while (ofs > csize) { /* Cluster following loop */
#if !_FS_READONLY
if (fp->flag & FA_WRITE) { /* Check if in write mode or not */
clust = create_chain(fp->fs, clust); /* Force streached if in write mode */
if (clust == 0) { /* When disk gets full, clip file size */
ofs = csize; break;
}
} else
#endif
clust = get_cluster(fp->fs, clust); /* Follow cluster chain if not in write mode */
if (clust < 2 || clust >= fp->fs->max_clust) goto fk_error;
fp->curr_clust = clust;
fp->fptr += csize;
ofs -= csize;
}
fp->fptr += ofs;
fp->csect = (BYTE)(ofs / SS(fp->fs)); /* Sector offset in the cluster */
if (ofs & (SS(fp->fs) - 1)) {
nsect = clust2sect(fp->fs, clust) + fp->csect; /* Current sector */
fp->csect++;
}
}
}
if (nsect && nsect != fp->curr_sect) {
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty buffer if needed */
if (disk_write(fp->fs->drive, fp->buffer, fp->curr_sect, 1) != RES_OK)
goto fk_error;
fp->flag &= (BYTE)~FA__DIRTY;
}
#endif
if (disk_read(fp->fs->drive, fp->buffer, nsect, 1) != RES_OK)
goto fk_error;
fp->curr_sect = nsect;
}
 
#if !_FS_READONLY
if (fp->fptr > fp->fsize) { /* Set changed flag if the file was extended */
fp->fsize = fp->fptr;
fp->flag |= FA__WRITTEN;
}
#endif
 
return FR_OK;
 
fk_error: /* Abort this file due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
#if _FS_MINIMIZE <= 1
/*-----------------------------------------------------------------------*/
/* Create a directroy object */
/*-----------------------------------------------------------------------*/
 
FRESULT f_opendir (
DIR *dj, /* Pointer to directory object to create */
const char *path /* Pointer to the directory path */
)
{
FRESULT res;
BYTE *dir;
char fn[8+3+1];
 
 
res = auto_mount(&path, &dj->fs, 0);
if (res == FR_OK) {
res = trace_path(dj, fn, path, &dir); /* Trace the directory path */
if (res == FR_OK) { /* Trace completed */
if (dir) { /* It is not the root dir */
if (dir[DIR_Attr] & AM_DIR) { /* The entry is a directory */
dj->clust = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]);
dj->sect = clust2sect(dj->fs, dj->clust);
dj->index = 2;
} else { /* The entry is not a directory */
res = FR_NO_FILE;
}
}
dj->id = dj->fs->id;
}
}
 
return res;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Read Directory Entry in Sequense */
/*-----------------------------------------------------------------------*/
 
FRESULT f_readdir (
DIR *dj, /* Pointer to the directory object */
FILINFO *finfo /* Pointer to file information to return */
)
{
BYTE *dir, c, res;
 
 
res = validate(dj->fs, dj->id); /* Check validity of the object */
if (res != FR_OK) return res;
 
finfo->fname[0] = 0;
while (dj->sect) {
if (!move_window(dj->fs, dj->sect))
return FR_RW_ERROR;
dir = &dj->fs->win[(dj->index & ((SS(dj->fs) - 1) >> 5)) * 32]; /* pointer to the directory entry */
c = dir[DIR_Name];
if (c == 0) break; /* Has it reached to end of dir? */
if (c != 0xE5 && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */
get_fileinfo(finfo, dir);
if (!next_dir_entry(dj)) dj->sect = 0; /* Next entry */
if (finfo->fname[0]) break; /* Found valid entry */
}
 
return FR_OK;
}
 
 
 
 
#if _FS_MINIMIZE == 0
/*-----------------------------------------------------------------------*/
/* Get File Status */
/*-----------------------------------------------------------------------*/
 
FRESULT f_stat (
const char *path, /* Pointer to the file path */
FILINFO *finfo /* Pointer to file information to return */
)
{
FRESULT res;
DIR dj;
BYTE *dir;
char fn[8+3+1];
 
 
res = auto_mount(&path, &dj.fs, 0);
if (res == FR_OK) {
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) { /* Trace completed */
if (dir) /* Found an object */
get_fileinfo(finfo, dir);
else /* It is root dir */
res = FR_INVALID_NAME;
}
}
 
return res;
}
 
 
 
#if !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Truncate File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_truncate (
FIL *fp /* Pointer to the file object */
)
{
FRESULT res;
DWORD ncl;
 
 
res = validate(fp->fs, fp->id); /* Check validity of the object */
if (res != FR_OK) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
 
if (fp->fsize > fp->fptr) {
fp->fsize = fp->fptr; /* Set file size to current R/W point */
fp->flag |= FA__WRITTEN;
if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */
if (!remove_chain(fp->fs, fp->org_clust)) goto ft_error;
fp->org_clust = 0;
} else { /* When truncate a part of the file, remove remaining clusters */
ncl = get_cluster(fp->fs, fp->curr_clust);
if (ncl < 2) goto ft_error;
if (ncl < fp->fs->max_clust) {
if (!put_cluster(fp->fs, fp->curr_clust, 0x0FFFFFFF)) goto ft_error;
if (!remove_chain(fp->fs, ncl)) goto ft_error;
}
}
}
 
return FR_OK;
 
ft_error: /* Abort this file due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get Number of Free Clusters */
/*-----------------------------------------------------------------------*/
 
FRESULT f_getfree (
const char *drv, /* Pointer to the logical drive number (root dir) */
DWORD *nclust, /* Pointer to the variable to return number of free clusters */
FATFS **fatfs /* Pointer to pointer to corresponding file system object to return */
)
{
FRESULT res;
DWORD n, clust, sect;
BYTE fat, f, *p;
 
 
/* Get drive number */
res = auto_mount(&drv, fatfs, 0);
if (res != FR_OK) return res;
 
/* If number of free cluster is valid, return it without cluster scan. */
if ((*fatfs)->free_clust <= (*fatfs)->max_clust - 2) {
*nclust = (*fatfs)->free_clust;
return FR_OK;
}
 
/* Get number of free clusters */
fat = (*fatfs)->fs_type;
n = 0;
if (fat == FS_FAT12) {
clust = 2;
do {
if ((WORD)get_cluster(*fatfs, clust) == 0) n++;
} while (++clust < (*fatfs)->max_clust);
} else {
clust = (*fatfs)->max_clust;
sect = (*fatfs)->fatbase;
f = 0; p = 0;
do {
if (!f) {
if (!move_window(*fatfs, sect++)) return FR_RW_ERROR;
p = (*fatfs)->win;
}
if (fat == FS_FAT16) {
if (LD_WORD(p) == 0) n++;
p += 2; f += 1;
} else {
if (LD_DWORD(p) == 0) n++;
p += 4; f += 2;
}
} while (--clust);
}
(*fatfs)->free_clust = n;
#if _USE_FSINFO
if (fat == FS_FAT32) (*fatfs)->fsi_flag = 1;
#endif
 
*nclust = n;
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Delete a File or Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_unlink (
const char *path /* Pointer to the file or directory path */
)
{
FRESULT res;
DIR dj;
BYTE *dir, *sdir;
DWORD dclust, dsect;
char fn[8+3+1];
 
 
res = auto_mount(&path, &dj.fs, 1);
if (res != FR_OK) return res;
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
if (res != FR_OK) return res; /* Trace failed */
if (!dir) return FR_INVALID_NAME; /* It is the root directory */
if (dir[DIR_Attr] & AM_RDO) return FR_DENIED; /* It is a R/O object */
dsect = dj.fs->winsect;
dclust = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]);
 
if (dir[DIR_Attr] & AM_DIR) { /* It is a sub-directory */
dj.clust = dclust; /* Check if the sub-dir is empty or not */
dj.sect = clust2sect(dj.fs, dclust);
dj.index = 2;
do {
if (!move_window(dj.fs, dj.sect)) return FR_RW_ERROR;
sdir = &dj.fs->win[(dj.index & ((SS(dj.fs) - 1) >> 5)) * 32];
if (sdir[DIR_Name] == 0) break;
if (sdir[DIR_Name] != 0xE5 && !(sdir[DIR_Attr] & AM_VOL))
return FR_DENIED; /* The directory is not empty */
} while (next_dir_entry(&dj));
}
 
if (!move_window(dj.fs, dsect)) return FR_RW_ERROR; /* Mark the directory entry 'deleted' */
dir[DIR_Name] = 0xE5;
dj.fs->winflag = 1;
if (!remove_chain(dj.fs, dclust)) return FR_RW_ERROR; /* Remove the cluster chain */
 
return sync(dj.fs);
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Create a Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_mkdir (
const char *path /* Pointer to the directory path */
)
{
FRESULT res;
DIR dj;
BYTE *dir, *fw, n;
char fn[8+3+1];
DWORD sect, dsect, dclust, pclust, tim;
 
 
res = auto_mount(&path, &dj.fs, 1);
if (res != FR_OK) return res;
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) return FR_EXIST; /* Any file or directory is already existing */
if (res != FR_NO_FILE) return res;
 
res = reserve_direntry(&dj, &dir); /* Reserve a directory entry */
if (res != FR_OK) return res;
sect = dj.fs->winsect;
dclust = create_chain(dj.fs, 0); /* Allocate a cluster for new directory table */
if (dclust == 1) return FR_RW_ERROR;
dsect = clust2sect(dj.fs, dclust);
if (!dsect) return FR_DENIED;
if (!move_window(dj.fs, dsect)) return FR_RW_ERROR;
 
fw = dj.fs->win;
memset(fw, 0, SS(dj.fs)); /* Clear the new directory table */
for (n = 1; n < dj.fs->csize; n++) {
if (disk_write(dj.fs->drive, fw, ++dsect, 1) != RES_OK)
return FR_RW_ERROR;
}
memset(&fw[DIR_Name], ' ', 8+3); /* Create "." entry */
fw[DIR_Name] = '.';
fw[DIR_Attr] = AM_DIR;
tim = get_fattime();
ST_DWORD(&fw[DIR_WrtTime], tim);
memcpy(&fw[32], &fw[0], 32); fw[33] = '.'; /* Create ".." entry */
ST_WORD(&fw[ DIR_FstClusLO], dclust);
ST_WORD(&fw[ DIR_FstClusHI], dclust >> 16);
pclust = dj.sclust;
if (dj.fs->fs_type == FS_FAT32 && pclust == dj.fs->dirbase) pclust = 0;
ST_WORD(&fw[32+DIR_FstClusLO], pclust);
ST_WORD(&fw[32+DIR_FstClusHI], pclust >> 16);
dj.fs->winflag = 1;
 
if (!move_window(dj.fs, sect)) return FR_RW_ERROR;
memset(&dir[0], 0, 32); /* Initialize the new entry */
memcpy(&dir[DIR_Name], fn, 8+3); /* Name */
dir[DIR_NTres] = fn[11];
dir[DIR_Attr] = AM_DIR; /* Attribute */
ST_DWORD(&dir[DIR_WrtTime], tim); /* Crated time */
ST_WORD(&dir[DIR_FstClusLO], dclust); /* Table start cluster */
ST_WORD(&dir[DIR_FstClusHI], dclust >> 16);
 
return sync(dj.fs);
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Change File Attribute */
/*-----------------------------------------------------------------------*/
 
FRESULT f_chmod (
const char *path, /* Pointer to the file path */
BYTE value, /* Attribute bits */
BYTE mask /* Attribute mask to change */
)
{
FRESULT res;
DIR dj;
BYTE *dir;
char fn[8+3+1];
 
 
res = auto_mount(&path, &dj.fs, 1);
if (res == FR_OK) {
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) { /* Trace completed */
if (!dir) {
res = FR_INVALID_NAME; /* Root directory */
} else {
mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */
dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */
res = sync(dj.fs);
}
}
}
return res;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Change Timestamp */
/*-----------------------------------------------------------------------*/
 
FRESULT f_utime (
const char *path, /* Pointer to the file/directory name */
const FILINFO *finfo /* Pointer to the timestamp to be set */
)
{
FRESULT res;
DIR dj;
BYTE *dir;
char fn[8+3+1];
 
 
res = auto_mount(&path, &dj.fs, 1);
if (res == FR_OK) {
res = trace_path(&dj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) { /* Trace completed */
if (!dir) {
res = FR_INVALID_NAME; /* Root directory */
} else {
ST_WORD(&dir[DIR_WrtTime], finfo->ftime);
ST_WORD(&dir[DIR_WrtDate], finfo->fdate);
res = sync(dj.fs);
}
}
}
return res;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Rename File/Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_rename (
const char *path_old, /* Pointer to the old name */
const char *path_new /* Pointer to the new name */
)
{
FRESULT res;
DIR dj;
DWORD sect_old;
BYTE *dir_old, *dir_new, direntry[32-11];
char fn[8+3+1];
 
 
res = auto_mount(&path_old, &dj.fs, 1);
if (res != FR_OK) return res;
 
res = trace_path(&dj, fn, path_old, &dir_old); /* Check old object */
if (res != FR_OK) return res; /* The old object is not found */
if (!dir_old) return FR_NO_FILE;
sect_old = dj.fs->winsect; /* Save the object information */
memcpy(direntry, &dir_old[DIR_Attr], 32-11);
 
res = trace_path(&dj, fn, path_new, &dir_new); /* Check new object */
if (res == FR_OK) return FR_EXIST; /* The new object name is already existing */
if (res != FR_NO_FILE) return res; /* Is there no old name? */
res = reserve_direntry(&dj, &dir_new); /* Reserve a directory entry */
if (res != FR_OK) return res;
 
memcpy(&dir_new[DIR_Attr], direntry, 32-11); /* Create new entry */
memcpy(&dir_new[DIR_Name], fn, 8+3);
dir_new[DIR_NTres] = fn[11];
dj.fs->winflag = 1;
 
if (!move_window(dj.fs, sect_old)) return FR_RW_ERROR; /* Delete old entry */
dir_old[DIR_Name] = 0xE5;
 
return sync(dj.fs);
}
 
#endif /* !_FS_READONLY */
#endif /* _FS_MINIMIZE == 0 */
#endif /* _FS_MINIMIZE <= 1 */
#endif /* _FS_MINIMIZE <= 2 */
 
 
 
#if _USE_MKFS && !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Create File System on the Drive */
/*-----------------------------------------------------------------------*/
#define N_ROOTDIR 512 /* Multiple of 32 and <= 2048 */
#define N_FATS 1 /* 1 or 2 */
#define MAX_SECTOR 64000000UL /* Maximum partition size */
#define MIN_SECTOR 2000UL /* Minimum partition size */
 
 
 
FRESULT f_mkfs (
BYTE drv, /* Logical drive number */
BYTE partition, /* Partitioning rule 0:FDISK, 1:SFD */
WORD allocsize /* Allocation unit size [bytes] */
)
{
BYTE fmt, m, *tbl;
DWORD b_part, b_fat, b_dir, b_data; /* Area offset (LBA) */
DWORD n_part, n_rsv, n_fat, n_dir; /* Area size */
DWORD n_clust, n;
FATFS *fs;
DSTATUS stat;
 
 
/* Check validity of the parameters */
if (drv >= _DRIVES) return FR_INVALID_DRIVE;
if (partition >= 2) return FR_MKFS_ABORTED;
for (n = 512; n <= 32768U && n != allocsize; n <<= 1);
if (n != allocsize) return FR_MKFS_ABORTED;
 
/* Check mounted drive and clear work area */
fs = FatFs[drv];
if (!fs) return FR_NOT_ENABLED;
fs->fs_type = 0;
drv = LD2PD(drv);
 
/* Get disk statics */
stat = disk_initialize(drv);
if (stat & STA_NOINIT) return FR_NOT_READY;
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
if (disk_ioctl(drv, GET_SECTOR_COUNT, &n_part) != RES_OK || n_part < MIN_SECTOR)
return FR_MKFS_ABORTED;
if (n_part > MAX_SECTOR) n_part = MAX_SECTOR;
b_part = (!partition) ? 63 : 0; /* Boot sector */
n_part -= b_part;
#if S_MAX_SIZ > 512 /* Check disk sector size */
if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK
|| SS(fs) > S_MAX_SIZ
|| SS(fs) > allocsize)
return FR_MKFS_ABORTED;
#endif
allocsize /= SS(fs); /* Number of sectors per cluster */
 
/* Pre-compute number of clusters and FAT type */
n_clust = n_part / allocsize;
fmt = FS_FAT12;
if (n_clust >= 0xFF5) fmt = FS_FAT16;
if (n_clust >= 0xFFF5) fmt = FS_FAT32;
 
/* Determine offset and size of FAT structure */
switch (fmt) {
case FS_FAT12:
n_fat = ((n_clust * 3 + 1) / 2 + 3 + SS(fs) - 1) / SS(fs);
n_rsv = 1 + partition;
n_dir = N_ROOTDIR * 32 / SS(fs);
break;
case FS_FAT16:
n_fat = ((n_clust * 2) + 4 + SS(fs) - 1) / SS(fs);
n_rsv = 1 + partition;
n_dir = N_ROOTDIR * 32 / SS(fs);
break;
default:
n_fat = ((n_clust * 4) + 8 + SS(fs) - 1) / SS(fs);
n_rsv = 33 - partition;
n_dir = 0;
}
b_fat = b_part + n_rsv; /* FATs start sector */
b_dir = b_fat + n_fat * N_FATS; /* Directory start sector */
b_data = b_dir + n_dir; /* Data start sector */
 
/* Align data start sector to erase block boundary (for flash memory media) */
if (disk_ioctl(drv, GET_BLOCK_SIZE, &n) != RES_OK) return FR_MKFS_ABORTED;
n = (b_data + n - 1) & ~(n - 1);
n_fat += (n - b_data) / N_FATS;
/* b_dir and b_data are no longer used below */
 
/* Determine number of cluster and final check of validity of the FAT type */
n_clust = (n_part - n_rsv - n_fat * N_FATS - n_dir) / allocsize;
if ( (fmt == FS_FAT16 && n_clust < 0xFF5)
|| (fmt == FS_FAT32 && n_clust < 0xFFF5))
return FR_MKFS_ABORTED;
 
/* Create partition table if needed */
if (!partition) {
DWORD n_disk = b_part + n_part;
 
tbl = &fs->win[MBR_Table];
ST_DWORD(&tbl[0], 0x00010180); /* Partition start in CHS */
if (n_disk < 63UL * 255 * 1024) { /* Partition end in CHS */
n_disk = n_disk / 63 / 255;
tbl[7] = (BYTE)n_disk;
tbl[6] = (BYTE)((n_disk >> 2) | 63);
} else {
ST_WORD(&tbl[6], 0xFFFF);
}
tbl[5] = 254;
if (fmt != FS_FAT32) /* System ID */
tbl[4] = (n_part < 0x10000) ? 0x04 : 0x06;
else
tbl[4] = 0x0c;
ST_DWORD(&tbl[8], 63); /* Partition start in LBA */
ST_DWORD(&tbl[12], n_part); /* Partition size in LBA */
ST_WORD(&tbl[64], 0xAA55); /* Signature */
if (disk_write(drv, fs->win, 0, 1) != RES_OK)
return FR_RW_ERROR;
}
 
/* Create boot record */
tbl = fs->win; /* Clear buffer */
memset(tbl, 0, SS(fs));
ST_DWORD(&tbl[BS_jmpBoot], 0x90FEEB); /* Boot code (jmp $, nop) */
ST_WORD(&tbl[BPB_BytsPerSec], SS(fs)); /* Sector size */
tbl[BPB_SecPerClus] = (BYTE)allocsize; /* Sectors per cluster */
ST_WORD(&tbl[BPB_RsvdSecCnt], n_rsv); /* Reserved sectors */
tbl[BPB_NumFATs] = N_FATS; /* Number of FATs */
ST_WORD(&tbl[BPB_RootEntCnt], SS(fs) / 32 * n_dir); /* Number of rootdir entries */
if (n_part < 0x10000) { /* Number of total sectors */
ST_WORD(&tbl[BPB_TotSec16], n_part);
} else {
ST_DWORD(&tbl[BPB_TotSec32], n_part);
}
tbl[BPB_Media] = 0xF8; /* Media descripter */
ST_WORD(&tbl[BPB_SecPerTrk], 63); /* Number of sectors per track */
ST_WORD(&tbl[BPB_NumHeads], 255); /* Number of heads */
ST_DWORD(&tbl[BPB_HiddSec], b_part); /* Hidden sectors */
n = get_fattime(); /* Use current time as a VSN */
if (fmt != FS_FAT32) {
ST_DWORD(&tbl[BS_VolID], n); /* Volume serial number */
ST_WORD(&tbl[BPB_FATSz16], n_fat); /* Number of secters per FAT */
tbl[BS_DrvNum] = 0x80; /* Drive number */
tbl[BS_BootSig] = 0x29; /* Extended boot signature */
memcpy(&tbl[BS_VolLab], "NO NAME FAT ", 19); /* Volume lavel, FAT signature */
} else {
ST_DWORD(&tbl[BS_VolID32], n); /* Volume serial number */
ST_DWORD(&tbl[BPB_FATSz32], n_fat); /* Number of secters per FAT */
ST_DWORD(&tbl[BPB_RootClus], 2); /* Root directory cluster (2) */
ST_WORD(&tbl[BPB_FSInfo], 1); /* FSInfo record (bs+1) */
ST_WORD(&tbl[BPB_BkBootSec], 6); /* Backup boot record (bs+6) */
tbl[BS_DrvNum32] = 0x80; /* Drive number */
tbl[BS_BootSig32] = 0x29; /* Extended boot signature */
memcpy(&tbl[BS_VolLab32], "NO NAME FAT32 ", 19); /* Volume lavel, FAT signature */
}
ST_WORD(&tbl[BS_55AA], 0xAA55); /* Signature */
if (disk_write(drv, tbl, b_part+0, 1) != RES_OK)
return FR_RW_ERROR;
if (fmt == FS_FAT32)
disk_write(drv, tbl, b_part+6, 1);
 
/* Initialize FAT area */
for (m = 0; m < N_FATS; m++) {
memset(tbl, 0, SS(fs)); /* 1st sector of the FAT */
if (fmt != FS_FAT32) {
n = (fmt == FS_FAT12) ? 0x00FFFFF8 : 0xFFFFFFF8;
ST_DWORD(&tbl[0], n); /* Reserve cluster #0-1 (FAT12/16) */
} else {
ST_DWORD(&tbl[0], 0xFFFFFFF8); /* Reserve cluster #0-1 (FAT32) */
ST_DWORD(&tbl[4], 0xFFFFFFFF);
ST_DWORD(&tbl[8], 0x0FFFFFFF); /* Reserve cluster #2 for root dir */
}
if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
return FR_RW_ERROR;
memset(tbl, 0, SS(fs)); /* Following FAT entries are filled by zero */
for (n = 1; n < n_fat; n++) {
if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
return FR_RW_ERROR;
}
}
 
/* Initialize Root directory */
m = (BYTE)((fmt == FS_FAT32) ? allocsize : n_dir);
do {
if (disk_write(drv, tbl, b_fat++, 1) != RES_OK)
return FR_RW_ERROR;
} while (--m);
 
/* Create FSInfo record if needed */
if (fmt == FS_FAT32) {
ST_WORD(&tbl[BS_55AA], 0xAA55);
ST_DWORD(&tbl[FSI_LeadSig], 0x41615252);
ST_DWORD(&tbl[FSI_StrucSig], 0x61417272);
ST_DWORD(&tbl[FSI_Free_Count], n_clust - 1);
ST_DWORD(&tbl[FSI_Nxt_Free], 0xFFFFFFFF);
disk_write(drv, tbl, b_part+1, 1);
disk_write(drv, tbl, b_part+7, 1);
}
 
return (disk_ioctl(drv, CTRL_SYNC, NULL) == RES_OK) ? FR_OK : FR_RW_ERROR;
}
 
#endif /* _USE_MKFS && !_FS_READONLY */
 
 
 
 
#if _USE_STRFUNC >= 1
/*-----------------------------------------------------------------------*/
/* Get a string from the file */
/*-----------------------------------------------------------------------*/
char* fgets (
char* buff, /* Pointer to the string buffer to read */
int len, /* Size of string buffer */
FIL* fil /* Pointer to the file object */
)
{
int i = 0;
char *p = buff;
UINT rc;
 
 
while (i < len - 1) { /* Read bytes until buffer gets filled */
f_read(fil, p, 1, &rc);
if (rc != 1) break; /* Break when no data to read */
#if _USE_STRFUNC >= 2
if (*p == '\r') continue; /* Strip '\r' */
#endif
i++;
if (*p++ == '\n') break; /* Break when reached end of line */
}
*p = 0;
return i ? buff : 0; /* When no data read (eof or error), return with error. */
}
 
 
 
#if !_FS_READONLY
#include <stdarg.h>
/*-----------------------------------------------------------------------*/
/* Put a character to the file */
/*-----------------------------------------------------------------------*/
int fputc (
int chr, /* A character to be output */
FIL* fil /* Ponter to the file object */
)
{
UINT bw;
char c;
 
 
#if _USE_STRFUNC >= 2
if (chr == '\n') fputc ('\r', fil); /* LF -> CRLF conversion */
#endif
if (!fil) { /* Special value may be used to switch the destination to any other device */
/* put_console(chr); */
return chr;
}
c = (char)chr;
f_write(fil, &c, 1, &bw); /* Write a byte to the file */
return bw ? chr : EOF; /* Return the resulut */
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Put a string to the file */
/*-----------------------------------------------------------------------*/
int fputs (
const char* str, /* Pointer to the string to be output */
FIL* fil /* Pointer to the file object */
)
{
int n;
 
 
for (n = 0; *str; str++, n++) {
if (fputc(*str, fil) == EOF) return EOF;
}
return n;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Put a formatted string to the file */
/*-----------------------------------------------------------------------*/
int fprintf (
FIL* fil, /* Pointer to the file object */
const char* str, /* Pointer to the format string */
... /* Optional arguments... */
)
{
va_list arp;
UCHAR c, f, r;
ULONG val;
char s[16];
int i, w, res, cc;
 
 
va_start(arp, str);
 
for (cc = res = 0; cc != EOF; res += cc) {
c = *str++;
if (c == 0) break; /* End of string */
if (c != '%') { /* Non escape cahracter */
cc = fputc(c, fil);
if (cc != EOF) cc = 1;
continue;
}
w = f = 0;
c = *str++;
if (c == '0') { /* Flag: '0' padding */
f = 1; c = *str++;
}
while (c >= '0' && c <= '9') { /* Precision */
w = w * 10 + (c - '0');
c = *str++;
}
if (c == 'l') { /* Prefix: Size is long int */
f |= 2; c = *str++;
}
if (c == 's') { /* Type is string */
cc = fputs(va_arg(arp, char*), fil);
continue;
}
if (c == 'c') { /* Type is character */
cc = fputc(va_arg(arp, char), fil);
if (cc != EOF) cc = 1;
continue;
}
r = 0;
if (c == 'd') r = 10; /* Type is signed decimal */
if (c == 'u') r = 10; /* Type is unsigned decimal */
if (c == 'X') r = 16; /* Type is unsigned hexdecimal */
if (r == 0) break; /* Unknown type */
if (f & 2) { /* Get the value */
val = (ULONG)va_arg(arp, long);
} else {
val = (c == 'd') ? (ULONG)(long)va_arg(arp, int) : (ULONG)va_arg(arp, unsigned int);
}
/* Put numeral string */
if (c == 'd') {
if (val >= 0x80000000) {
val = 0 - val;
f |= 4;
}
}
i = sizeof(s) - 1; s[i] = 0;
do {
c = (UCHAR)(val % r + '0');
if (c > '9') c += 7;
s[--i] = c;
val /= r;
} while (i && val);
if (i && (f & 4)) s[--i] = '-';
w = sizeof(s) - 1 - w;
while (i && i > w) s[--i] = (f & 1) ? '0' : ' ';
cc = fputs(&s[i], fil);
}
 
va_end(arp);
return (cc == EOF) ? cc : res;
}
 
#endif /* !_FS_READONLY */
#endif /* _USE_STRFUNC >= 1*/
/Designs/GPSRL03A/ff.h
0,0 → 1,339
/*--------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.06 (C)ChaN, 2008
/---------------------------------------------------------------------------/
/ FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2008, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
/ commercial use without any restriction under your responsibility.
/ * Redistributions of source code must retain the above copyright notice.
/
/---------------------------------------------------------------------------*/
 
#ifndef _FATFS
 
#define _MCU_ENDIAN 0
/* The _MCU_ENDIAN defines which access method is used to the FAT structure.
/ 1: Enable word access.
/ 2: Disable word access and use byte-by-byte access instead.
/ When the architectural byte order of the MCU is big-endian and/or address
/ miss-aligned access results incorrect behavior, the _MCU_ENDIAN must be set to 2.
/ If it is not the case, it can also be set to 1 for good code efficiency. */
 
#define _FS_READONLY 0
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
/ f_truncate and useless f_getfree. */
 
#define _FS_MINIMIZE 0
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
/ 0: Full function.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename are removed.
/ 2: f_opendir and f_readdir are removed in addition to level 1.
/ 3: f_lseek is removed in addition to level 2. */
 
#define _USE_STRFUNC 0
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
 
#define _USE_MKFS 0
/* When _USE_MKFS is set to 1 and _FS_READONLY is set to 0, f_mkfs function is
/ enabled. */
 
#define _DRIVES 2
/* Number of logical drives to be used. This affects the size of internal table. */
 
#define _MULTI_PARTITION 0
/* When _MULTI_PARTITION is set to 0, each logical drive is bound to same
/ physical drive number and can mount only 1st primaly partition. When it is
/ set to 1, each logical drive can mount a partition listed in Drives[]. */
 
#define _USE_FSINFO 0
/* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */
 
#define _USE_SJIS 1
/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise
/ only US-ASCII(7bit) code can be accepted as file/directory name. */
 
#define _USE_NTFLAG 1
/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved.
/ Note that the files are always accessed in case insensitive. */
 
 
#include "integer.h"
 
 
 
/* Definitions corresponds to multiple sector size (not tested) */
#define S_MAX_SIZ 512U /* Do not change */
#if S_MAX_SIZ > 512U
#define SS(fs) ((fs)->s_size)
#else
#define SS(fs) 512U
#endif
 
 
/* File system object structure */
typedef struct _FATFS {
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD sects_fat; /* Sectors per fat */
DWORD max_clust; /* Maximum cluster# + 1 */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector (cluster# for FAT32) */
DWORD database; /* Data start sector */
#if !_FS_READONLY
DWORD last_clust; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */
#if _USE_FSINFO
DWORD fsi_sector; /* fsinfo sector */
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
BYTE pad2;
#endif
#endif
BYTE fs_type; /* FAT sub type */
BYTE csize; /* Number of sectors per cluster */
#if S_MAX_SIZ > 512U
WORD s_size; /* Sector size */
#endif
BYTE n_fats; /* Number of FAT copies */
BYTE drive; /* Physical drive number */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1;
BYTE win[S_MAX_SIZ]; /* Disk access window for Directory/FAT */
} FATFS;
 
 
/* Directory object structure */
typedef struct _DIR {
WORD id; /* Owner file system mount ID */
WORD index; /* Current index */
FATFS* fs; /* Pointer to the owner file system object */
DWORD sclust; /* Start cluster */
DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */
} DIR;
 
 
/* File object structure */
typedef struct _FIL {
WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */
BYTE csect; /* Sector address in the cluster */
FATFS* fs; /* Pointer to the owner file system object */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster */
DWORD curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
#if _FS_READONLY == 0
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
BYTE buffer[S_MAX_SIZ]; /* File R/W buffer */
} FIL;
 
 
/* File status structure */
typedef struct _FILINFO {
DWORD fsize; /* Size */
WORD fdate; /* Date */
WORD ftime; /* Time */
BYTE fattrib; /* Attribute */
char fname[8+1+3+1]; /* Name (8.3 format) */
} FILINFO;
 
 
 
/* Definitions corresponds to multi partition */
 
#if _MULTI_PARTITION != 0 /* Multiple partition cfg */
 
typedef struct _PARTITION {
BYTE pd; /* Physical drive # (0-255) */
BYTE pt; /* Partition # (0-3) */
} PARTITION;
extern
const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
#define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
#define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
 
#else /* Single partition cfg */
 
#define LD2PD(drv) (drv) /* Physical drive# is equal to logical drive# */
#define LD2PT(drv) 0 /* Always mounts the 1st partition */
 
#endif
 
 
/* File function return code (FRESULT) */
 
typedef enum {
FR_OK = 0, /* 0 */
FR_NOT_READY, /* 1 */
FR_NO_FILE, /* 2 */
FR_NO_PATH, /* 3 */
FR_INVALID_NAME, /* 4 */
FR_INVALID_DRIVE, /* 5 */
FR_DENIED, /* 6 */
FR_EXIST, /* 7 */
FR_RW_ERROR, /* 8 */
FR_WRITE_PROTECTED, /* 9 */
FR_NOT_ENABLED, /* 10 */
FR_NO_FILESYSTEM, /* 11 */
FR_INVALID_OBJECT, /* 12 */
FR_MKFS_ABORTED /* 13 */
} FRESULT;
 
 
 
/*-----------------------------------------------------*/
/* FatFs module application interface */
 
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_truncate (FIL*); /* Truncate file */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
FRESULT f_utime (const char*, const FILINFO*); /* Change file/dir timestamp */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */
#if _USE_STRFUNC
#define feof(fp) ((fp)->fptr == (fp)->fsize)
#define EOF -1
int fputc (int, FIL*); /* Put a character to the file */
int fputs (const char*, FIL*); /* Put a string to the file */
int fprintf (FIL*, const char*, ...); /* Put a formatted string to the file */
char* fgets (char*, int, FIL*); /* Get a string from the file */
#endif
 
/* User defined function to give a current time to fatfs module */
 
DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
 
 
 
/* File access control and file status flags (FIL.flag) */
 
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#if _FS_READONLY == 0
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20
#define FA__DIRTY 0x40
#endif
#define FA__ERROR 0x80
 
 
/* FAT sub type (FATFS.fs_type) */
 
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
 
 
/* File attribute bits for directory entry */
 
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
 
 
 
/* Offset of FAT structure members */
 
#define BS_jmpBoot 0
#define BS_OEMName 3
#define BPB_BytsPerSec 11
#define BPB_SecPerClus 13
#define BPB_RsvdSecCnt 14
#define BPB_NumFATs 16
#define BPB_RootEntCnt 17
#define BPB_TotSec16 19
#define BPB_Media 21
#define BPB_FATSz16 22
#define BPB_SecPerTrk 24
#define BPB_NumHeads 26
#define BPB_HiddSec 28
#define BPB_TotSec32 32
#define BS_55AA 510
 
#define BS_DrvNum 36
#define BS_BootSig 38
#define BS_VolID 39
#define BS_VolLab 43
#define BS_FilSysType 54
 
#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 BS_DrvNum32 64
#define BS_BootSig32 66
#define BS_VolID32 67
#define BS_VolLab32 71
#define BS_FilSysType32 82
 
#define FSI_LeadSig 0
#define FSI_StrucSig 484
#define FSI_Free_Count 488
#define FSI_Nxt_Free 492
 
#define MBR_Table 446
 
#define DIR_Name 0
#define DIR_Attr 11
#define DIR_NTres 12
#define DIR_CrtTime 14
#define DIR_CrtDate 16
#define DIR_FstClusHI 20
#define DIR_WrtTime 22
#define DIR_WrtDate 24
#define DIR_FstClusLO 26
#define DIR_FileSize 28
 
 
 
/* Multi-byte word access macros */
 
#if _MCU_ENDIAN == 1 /* Use word access */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#elif _MCU_ENDIAN == 2 /* Use byte-by-byte access */
#define LD_WORD(ptr) (WORD)(((WORD)*(volatile BYTE*)((ptr)+1)<<8)|(WORD)*(volatile BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(volatile BYTE*)((ptr)+3)<<24)|((DWORD)*(volatile BYTE*)((ptr)+2)<<16)|((WORD)*(volatile BYTE*)((ptr)+1)<<8)|*(volatile BYTE*)(ptr))
#define ST_WORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(volatile BYTE*)(ptr)=(BYTE)(val); *(volatile BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(volatile BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(volatile BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24)
#else
#error Do not forget to set _MCU_ENDIAN properly!
#endif
 
 
#define _FATFS
#endif /* _FATFS */
/Designs/GPSRL03A/glg.elf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:executable
+*
\ No newline at end of property
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Designs/GPSRL03A/glg.hex
0,0 → 1,561
:100000000C944C000C9469000C9469000C946900E9
:100010000C9469000C9469000C9469000C946900BC
:100020000C9469000C9469000C9469000C947A019A
:100030000C9469000C9469000C9469000C9469009C
:100040000C9469000C9469000C94D6000C9469001F
:100050000C9469000C946B000C9469000C9469007A
:100060000C9469000C9469000D0A002C0024475080
:10007000524D4300244750474741002E6C6F6700A4
:10008000244750524D430024505352463130362CB1
:1000900032312A30460D0A0011241FBECFEFD4E0C2
:1000A000DEBFCDBF11E0A0E0B1E0ECEEF2E202C0B5
:1000B00005900D92A630B107D9F714E0A6E0B1E0A3
:1000C00001C01D92A734B107E1F70E94BA010C9458
:1000D00075110C9400001F920F920FB60F9211240D
:1000E0002F933F938F9320917800309179008091E6
:1000F0007C00203D310570F4809109018F3030F093
:100100008091690181608093690106C08F5F80934F
:10011000090102C01092090181E02C32380770F009
:10012000809108018F3030F0809169018E7F80933B
:10013000690106C08F5F8093080102C01092080118
:1001400030936F0120936E0182E480937C00809154
:100150007C0030930A022093090281E480937C00A2
:100160008FED80937A008F913F912F910F900FBE6A
:100170000F901F90189560E070E081EA96E3089573
:10018000F894E1ECF0E0108210927101109270018D
:100190001092720181E48093C40088E98083809189
:1001A00069018D7F80936901789408951F920F9261
:1001B0000FB60F9211248F939F93EF93FF9390911B
:1001C000C60080917201863988F48F5F8093720136
:1001D00080917001E82FFF27E059FE4F93838F5FD6
:1001E000863908F080E08093700105C08091690134
:1001F000826080936901FF91EF919F918F910F90A1
:100200000FBE0F901F90189590E08091690180FFBC
:1002100003C080E090E00895209171018091720107
:10022000882319F420E030E015C0E22FFF27E059C1
:10023000FE4F3381E22FEF5FF8948091720181507D
:10024000809372017894E63908F0E0E0E093710160
:10025000232F33278091690181FF03C00E94C000D2
:10026000D3CF822F222389F2992311F4243269F605
:10027000E92FFF27E95EFE4F20839F5F8A3021F040
:10028000923508F0C1CFC1CF892F99270895982FB3
:100290000FC083E085BD90931601809116018823DD
:1002A000E1F715BC90931601809116018823E1F7C0
:1002B000615078F70895DC01FB016F5F7F4F9491E7
:1002C000992329F08C91981711F41196F5CF892F65
:1002D00099270895FC010AC08081813218F480E0DA
:1002E00090E0089531968C32B9F761506623A1F7FA
:1002F000CF0108951F920F920FB60F9211242F93E2
:100300003F934F935F936F937F938F939F93AF939D
:10031000BF93EF93FF9380911601882319F08150CA
:1003200080931601809106019091070101969093A8
:100330000701809306018055964448F0109207010A
:1003400010920601809169018460809369010E9486
:10035000C80DFF91EF91BF91AF919F918F917F91C8
:100360006F915F914F913F912F910F900FBE0F9022
:100370001F901895CDEFD4E0DEBFCDBF8DE085B9DD
:100380008EE284B98FE388B917B88EEA8BB982E51B
:100390008AB980E58CBD81E08DBD83ED90E39093BB
:1003A0008900809388008AE08093810082E08093B6
:1003B0006F0082E187BD82E484BD81E480937C008C
:1003C0008FED80937A00789467E272E080E00E947B
:1003D000EF08CC24DD2447E1E42E41E0F42E3BE09D
:1003E000A32E32E0B32E2E010894411C511C22E1B1
:1003F000622E21E0722E9AE6892E91E0992E89E0F4
:10040000282E312C2E0C3F1C1092C100299884E616
:10041000809316018091690180FF03C084E6809378
:100420001601809116018823A9F7299A8FEF8093EE
:1004300016018091690180FD05C080E00E94BF0D1A
:1004400081FF03C08FEF80931601809116018823EE
:1004500081F761E085E00E9447010E94C00027E823
:1004600030E006C08091C00085FFFCCF9093C600AD
:10047000F9012F5F3F4F94919923A1F70E94040146
:10048000882309F4C1CF60E870E0C7010E945B01D6
:10049000882329F462E0C7010E946A016C01C1143B
:1004A000D10461F3F6018081813441F769E0C7012D
:1004B0000E946A016C01009711F463E0A8C0FC017E
:1004C0008481958190931801809317018281938193
:1004D00090931A01809319018081918190931C015E
:1004E00080931B016BE770E08DE191E00E948D101D
:1004F00042E1B701C5010E944409892B09F086C079
:1005000040911502509116026091170270911802E5
:10051000C5010E948B05892B09F078C062E085E057
:100520000E94470165C064E770E0C7010E945B015B
:10053000882341F06DE670E0C7010E945B018823CB
:1005400009F044C0012F11279201A801B701C5018C
:100550000E94C006892B09F052C089819A81081730
:10056000190709F04CC04AE050E0B30180916E01D8
:1005700090916F010E94B8104AE050E0B401809160
:10058000090290910A020E94B810B301C7010E94AB
:10059000B1106BE670E08BE191E00E948D10B40128
:1005A0008CE191E00E94B11068E670E0C1010E9408
:1005B0008D1092014BE050E0B701C5010E94C006CA
:1005C000892BE9F489819A810B97C9F4809169019B
:1005D00082FF0EC0C5010E945D06892B11F066E006
:1005E00016C0F894809169018B7F8093690178949B
:1005F0000E940401182F882309F095CF0FC065E0F1
:1006000006C061E082E30E944701FECE64E01092E2
:10061000C100299889E10E944701FFCF1092C100D3
:100620002998C5010E94B406892B59F367E0EFCFE2
:10063000CF93DF93C0910A01D0910B01BC016250AE
:1006400070408E899F8902976817790728F020E00B
:1006500030E040E050E012C0882799272D8D3327E5
:10066000442755270E94E9109B01AC01888999898C
:10067000AA89BB89280F391F4A1F5B1FCA01B9010C
:10068000DF91CF910895FC01892B61F080819181E8
:100690008617970739F480E00E94BF0D9927817073
:1006A000907008958CE090E00895A0E0B0E0EBE554
:1006B000F3E00C942E114B015C01C0910A01D09122
:1006C0000B01CC80DD80EE80FF80C616D706E806E1
:1006D000F90609F44FC08F8D8823A1F180E2682EBE
:1006E000712C6C0E7D1E01E0A7019601B30180E024
:1006F0000E94D30E892BD9F51F8E8C899D89AA273C
:10070000BB27288539854A855B85820F931FA41FE7
:10071000B51FC816D906EA06FB06A0F41E8D10C048
:100720008C899D89AA27BB27C80ED91EEA1EFB1EED
:1007300001E0A7019601B30180E00E94D30E1150A1
:10074000123070F781149104A104B10499F0BE0134
:10075000605E7F4F01E0A501940180E00E94510F8F
:10076000892B29F48C829D82AE82BF8203C080E0F7
:1007700090E002C081E090E0EEE0CDB7DEB70C94EF
:100780004A11A0E0B0E0E7ECF3E00C942D11EC018D
:100790005B0180900A0190900B01F401C084D18428
:1007A000E284F384848D813021F0823009F070C0BE
:1007B00056C08E01000F111F0C0F1D1F16950795B7
:1007C000B801672F77276695882799276C0D7D1DBF
:1007D0008E1D9F1D0E945503882309F459C060E2B5
:1007E000662E712C680C791CF801F170E60DF71D6E
:1007F000CE0181709070582E882339F080818F70DF
:100800009A2D9295907F982B01C09A2D9083E801A4
:10081000219681E0F401878FBE01672F77276695C7
:10082000882799276C0D7D1D8E1D9F1D0E945503E5
:10083000882371F1FE01F170E60DF71D552039F0A6
:1008400044E0B694A7944A95E1F72A2D06C020818A
:10085000207F8B2D99278F70282B208313C06D2F1D
:100860007727882799276C0D7D1D8E1D9F1D0E945F
:100870005503882369F0CC0FDD1FD170C80DD91D39
:10088000B9A2A8A281E0F401878F81E090E002C0C4
:1008900080E090E0EFE0CDB7DEB70C944911A0E026
:1008A000B0E0E5E5F4E00C9431118C01E0900A0130
:1008B000F0900B01029708F467C0F70186899789C9
:1008C0000817190708F060C0A084B184C284D384DB
:1008D000848D813021F0823009F056C040C0E8019B
:1008E000CC0FDD1FC00FD11FD695C795BE01672F56
:1008F00077276695882799276A0D7B1D8C1D9D1D7E
:100900000E945503882309F43FC0FE01F170EE0DEB
:10091000FF1D90A02196BE01672F77276695882737
:1009200099276A0D7B1D8C1D9D1D0E9455038823F0
:1009300059F1292D3327D170EC0EFD1EF70180A14E
:100940009927982F8827822B932B00FF06C024E03D
:10095000969587952A95E1F719C09F7017C0612F6A
:100960007727882799276A0D7B1D8C1D9D1D0E9466
:100970005503882349F0000F111F1170E00EF11E7E
:10098000F70180A191A102C081E090E0EBE0CDB73A
:10099000DEB70C944D11EF92FF920F931F93CF93FC
:1009A000DF93EC01E0900A01F0900B010A811B81BA
:1009B0000F5F1F4FC8018F709070892BD1F58A850A
:1009C0009B85AC85BD850196A11DB11D8A879B873E
:1009D000AC87BD87488559854115510539F4F70124
:1009E000828193810817190720F128C0F701858DAE
:1009F000992701979801B4E036952795BA95E1F7C4
:100A000082239323892BA9F4CA010E944F049C01DD
:100A10000297A0F0F701868997892817390770F4A3
:100A200039872887C9010E9418036A877B878C87CA
:100A30009D871B830A8381E090E002C080E090E004
:100A4000E6E0CDB7DEB70C945211A0E0B0E0EBE2E7
:100A5000F5E00C9432117C01A0900A01B0900B01DA
:100A6000F501C688D788009749F4008D118D0230B2
:100A7000110580F00C151D0568F40EC00E944F048E
:100A800082309105E8F18C159D0510F4BC013DC044
:100A9000870102C001E010E0E8012196CC15DD05D8
:100AA00028F00230110578F1C2E0D0E0CE010E94BA
:100AB0004F04009731F0019719F1C017D10719F1D0
:100AC000ECCF6FEF7FEFCE010E94C1038823C1F00E
:100AD000E114F10431F0BE01C7010E94C103882373
:100AE00079F0F501D18FC08F828D938DFFEF8F3F0D
:100AF0009F0721F00197F501938F828FBE0105C0FA
:100B000061E070E002C060E070E0CB01EAE0CDB7E8
:100B1000DEB70C944E11A0E0B0E0E1E9F5E00C94F2
:100B20002A11EC013A014B014C805D80688179818A
:100B3000C2010E9443031C01892B09F0B8C02A811D
:100B400022230CF4B1C08A859B85AC85BD858615B2
:100B50009705A805B90520F421FD02C03C014D010F
:100B60001E821F821886198681E08B8361147104AE
:100B70008104910409F47EC02E853F85211531053D
:100B800071F480E090E00E9425059C018130910580
:100B900009F487C09F878E87892B09F46BC0F20107
:100BA000858DE82EFF240027112789E0EE0CFF1C1D
:100BB000001F111F8A95D1F7398B288BE614F70493
:100BC0000805190550F58A8181FF04C0C9010E94FA
:100BD000250503C0C9010E944F049C010097D9F06C
:100BE000019709F45EC0F2018689978928173907B1
:100BF00008F057C08E819F81A885B9858E0D9F1DF5
:100C0000A01FB11F8E839F83A887B9876E187F08A6
:100C1000800A910AD1CF3701480164015301089439
:100C2000A108B108C108D10809E0D694C794B794C7
:100C3000A7940A95D1F7EA2CFF2400271127C901B0
:100C40000E941803E60EF71E081F191FEA8AFB8A86
:100C50000C8B1D8BF201858D8A198B838E819F8170
:100C6000A885B985860D971DA81DB91D8E839F8304
:100C7000A887B9876A8161FF1AC02E813F814885A4
:100C800059858A859B85AC85BD8582179307A40706
:100C9000B50768F42A873B874C875D8760626A8363
:100CA00006C08A8180688A8318E0212E312CC10118
:100CB000E2E1CDB7DEB70C944611EF92FF920F93AD
:100CC0001F93CF93DF93EC01688179818C819D81A3
:100CD0000E9443037C01892B09F040C08A8185FF73
:100CE0003DC06E897F89888D998D0E945503882328
:100CF00091F10A8D1B8DF8018385806283878A8537
:100D00009B85AC85BD85848F958FA68FB78F8E858B
:100D10009F85938F828F0E94BB00F801668B778B33
:100D2000808F918F8A818F7D8A83E0910A01F09173
:100D30000B0181E0878F60E070E080E090E00E942E
:100D40005503882341F040E050E063E080E00E94DA
:100D5000E80D892B19F098E0E92EF12CC701E6E0A7
:100D6000CDB7DEB70C945211CF93DF93EC010E9404
:100D70005D06009711F41D821C82DF91CF910895CA
:100D8000A0E0B0E0E6ECF6E00C942C11EC018B0155
:100D90007A013901CC80DD80F901118210826881ED
:100DA0007981C6010E9443034C01892B09F01AC1C5
:100DB0008A8188230CF413C181FD04C0E6E08E2EE5
:100DC000912C10C12A853B854C855D85C701AA27DA
:100DD000BB27820F931FA41FB51F82179307A40779
:100DE000B50708F4FFC0580170E2472E512C4C0C97
:100DF0005D1CD9C02E813F8148855985DA01C90122
:100E00009170A070B0700097A105B10509F093C072
:100E10008B8181508B83882349F02A893B894C89B7
:100E20005D892F5F3F4F4F4F5F4F30C02115310518
:100E30004105510569F42E853F852115310589F459
:100E400080E090E00E9425059C019F878E8705C069
:100E5000888999890E9425059C012115310509F48D
:100E6000A6C02130310509F4B7C0F60186899789FB
:100E70002817390708F0B0C0398B288BC9010E94A8
:100E800018039B01AC01F601858D8B832A8B3B8B6C
:100E90004C8B5D8B8701012F11270695002361F193
:100EA0008B81102F801708F4182F012FB50180E0D7
:100EB0000E94D30E892B09F08FC08B818F5F811B1D
:100EC0008B83812F992701979C01442737FD4095FB
:100ED000542F8C010F5F1F4F8A899B89AC89BD8974
:100EE000820F931FA41FB51F8A8B9B8BAC8BBD8B6E
:100EF000102F0027110F3DC02E813F814885598555
:100F00008A859B85AC85BD85281739074A075B070D
:100F100090F060E070E080E090E00E94550388234C
:100F200009F45AC08A899B89AC89BD89F6018483FA
:100F30009583A683B7836A897B898C899D890E9462
:100F40005503882309F448C08E819F81917020E069
:100F500032E0281B390B87012E153F0508F4890163
:100F6000A801B501840D951D0E94A11081E0F60134
:100F7000878FA00EB11EC801AA27BB272E813F81F3
:100F800048855985280F391F4A1F5B1F2E833F83D1
:100F900048875987F30180819181800F911F918348
:100FA0008083E01AF10AE114F10409F023CF2E81C5
:100FB0003F81488559858A859B85AC85BD8582178B
:100FC0009307A407B50720F42A873B874C875D87E2
:100FD0008A8180628A8306C08A8180688A8328E049
:100FE000822E912CC401E0E1CDB7DEB70C944811FC
:100FF000A0E0B0E0EEEFF7E00C942C11EC018B01D7
:101000007A0139018C809D80F901118210826881FA
:101010007981C4010E9443035C01892B09F0D9C086
:101020008A8188230CF4D2C080FD04C006E0A02E83
:10103000B12CCFC02A853B854C855D858E819F81F3
:10104000A885B985281B390B4A0B5B0BC701AA275A
:10105000BB27281739074A075B0708F4790168019D
:1010600010E2412E512C480C591CA8C02E813F8102
:1010700048855985DA01C9019170A070B070009758
:10108000A105B10509F066C08B8181508B8388234F
:1010900049F02A893B894C895D892F5F3F4F4F4F2B
:1010A0005F4F22C0211531054105510519F42E85E8
:1010B0003F8505C0888999890E944F049C01223090
:1010C000310508F480C0F40186899789281739070B
:1010D00008F079C0398B288BC9010E9418039B0145
:1010E000AC01F401858D8B832A8B3B8B4C8B5D8B04
:1010F0008701012F11270695002361F18B81102FA5
:10110000801708F4182F012FB60180E00E94510FBC
:10111000892B09F058C08B818F5F811B8B83812FB6
:10112000992701979C01442737FD4095542F8C0146
:101130000F5F1F4F8A899B89AC89BD89820F931FDE
:10114000A41FB51F8A8B9B8BAC8BBD8B102F0027E8
:10115000110F1AC06A897B898C899D890E94550369
:10116000882389F16E817F81717080E092E0861B17
:10117000970B87018E159F0508F48C01640D751D72
:10118000A801C6010E94A110C00ED11EC801AA2745
:10119000BB272E813F8148855985280F391F4A1F5B
:1011A0005B1F2E833F8348875987F301808191819C
:1011B000800F911F91838083E01AF10AE114F104FA
:1011C00009F054CF06C08A8180688A83F8E0AF2E88
:1011D000B12CC501E0E1CDB7DEB70C944811FB019D
:1011E000882319F085E090E00895A0910A01B0915C
:1011F0000B0170930B0160930A01109729F080E2B4
:1012000092E01D920197E9F7309719F480E090E0A1
:10121000089580E292E011920197E9F780E090E072
:1012200008950F93CF93DF939B01AC01C0910A0106
:10123000D0910B01BE01605E7F4F01E080E00E9413
:10124000510F892BD9F4C25EDD4F88819981CE512F
:10125000D24085559A4A91F400E043E050E060E0C6
:1012600071E0CE018A5A9F4F0E949410892B09F495
:1012700001E081E00827802F992702C082E090E0FA
:10128000DF91CF910F910895ADE1B0E0EAE4F9E08C
:101290000C942A119D8F8C8F6B01A0900A01B09045
:1012A0000B01FC0115821482F42FFF71FB8F03C028
:1012B0000894C11CD11CD6018C918032C9F38F32A5
:1012C00019F40894C11CD11CA114B10409F415C16E
:1012D0001B8D1E71F501848D882361F080E00E94D2
:1012E000BF0D992780FD06C0112309F429C382FD93
:1012F00007C126C380E292E0D5011D920197E9F76C
:1013000080E00E94AE0F992780FF03C021E030E00B
:1013100045C3112311F082FDF3C060E070E080E06E
:1013200090E00E941109813021F0EE24FF24870112
:101330001EC0E2EEF1E0AE0EBF1ED5018C91EEE1D3
:10134000FEEFAE0EBF1E882309F4DDC026EE31E0AD
:10135000A20EB31ED501ED90FD900D911C91EAE116
:10136000FEEFAE0EBF1EC801B7010E94110988230F
:1013700009F0C9C0F50183A594A58050924009F0F9
:10138000C2C0F50166A977A96115710519F0882712
:1013900099270DC024E430E0A20EB31ED5016D9153
:1013A0007D918D919C91ECEBFFEFAE0EBF1EF50190
:1013B000758B648B20A9268F3327442755270E94DD
:1013C000E9103B014C01A501425D5F4FF50186A587
:1013D00097A5AA27BB27E80EF91E0A1F1B1FE08648
:1013E000F1860287138785A5858F21A932A93383CA
:1013F000228363A974A96115710521F07B0100277F
:1014000011270DC080E490E0A80EB91ED501ED9023
:10141000FD900D911C91E0ECFFEFAE0EBF1EDA01C6
:101420008D919C91AA27BB27E81AF90A0A0B1B0B7E
:10143000E618F70808091909E4E036952795EA95B2
:10144000E1F7C901AA27BB27E81AF90A0A0B1B0B07
:10145000F501258D332744275527C801B7010E9480
:1014600008112E5F3F4F4F4F5F4FF501378B268B93
:10147000283FFFE03F07F0E04F07F0E05F0710F480
:1014800061E006C0285F3F4F40405040E0F562E019
:10149000F5012085318542855385D401C301820F32
:1014A000931FA41FB51F84879587A687B78782815E
:1014B000938174E0969587957A95E1F7AA27BB27E3
:1014C000820F931FA41FB51F860D971DA81DB91D60
:1014D000808B918BA28BB38B648F8FEF9FEF938F59
:1014E000828F80910C0190910D01019690930D01D6
:1014F00080930C019183808323C22AE030E04EC2A6
:1015000029E030E04BC22BE030E048C236014E010A
:101510000894811C911C50E2452E512C4E0E5F1EEA
:101520004DE0242E312C2C0E3D1E4BE050E060E2AD
:1015300070E0C4010E94AA1040E068E030E058E189
:1015400002C048E06BE0D3012D913D01222311F050
:101550002F3251F4442309F443C053235C87822F74
:10156000992787FD90953EC0922F2132C8F12F37E1
:10157000B9F12E3239F430FD33C0442389F14930BA
:1015800000F32EC0223261F12A3208F12D3240F1EF
:101590002A33E8F0203420F130FD19C02C3701F156
:1015A000822F8B558330E0F0865E8A3128F46830D4
:1015B00011F4577F01C05F7E822F81568A3138F443
:1015C000922F9052683011F4386001C03061461794
:1015D00038F43E7FF401E40FF11D90834F5FB3CFE9
:1015E00081E090E0D82EB1E08B1719F424E030E0D0
:1015F00055C06F89788D898D9A8D0E9455038823F7
:1016000019F428E030E04AC00F8518890F70107077
:1016100035E0000F111F3A95E1F7040D151DF80193
:1016200080818823A9F0853E71F0F8018385E82E3A
:10163000FF24E3FC08C04BE050E0B401C8010E9465
:101640009410892B51F0C1010E94CB04882389F6A4
:10165000DD2059F422E030E021C0DD2021F46801D2
:1016600020E030E01BC0E4FC03C023E030E016C003
:10167000F801828D938D9C8B8B8B9E8B8D8B0E9422
:1016800018036F8B788F898F9A8F82E090E0988B08
:101690008F874BCF20E030E0CC24DD24FB8D4F2F13
:1016A0005527CA018C719070892B09F4FEC0211551
:1016B000310509F48FC02230310509F06FC1609007
:1016C0000A0170900B010B891C890115110551F05D
:1016D0001E8B0D8BC8010E9418036F8B788F898F2A
:1016E0009A8F09C0F30184859585A685B7858F8B70
:1016F000988FA98FBA8F188A1F8620E2E22EF12CCC
:10170000E60CF71C9DE0492E512C4C0E5D1E6F8996
:10171000788D898D9A8D0E945503882309F40AC11A
:101720004701CF84D888FFE0CF22DD2485E0CC0CB0
:10173000DD1C8A95E1F7CE0CDF1CD6018C91882345
:1017400009F418C1853E09F415C1C2010E94CB04F9
:101750008823E9F6012B09F4EAC08D899E890E944D
:1017600025058C01009709F4E2C0019709F4E2C055
:1017700060E070E080E090E00E945503882309F467
:10178000D9C0C8010E9418036B017C01F301648376
:1017900075838683978380E092E0D4011D92019740
:1017A000E9F7158D10C001E0A7019601B40180E0B2
:1017B0000E94D30E892B09F0BDC00894C11CD11C16
:1017C000E11CF11C1150112371F781E0F301878FA7
:1017D0006401D0C042FF03C027E030E0DFC0C11485
:1017E000D10409F4A4C0F6018385817109F09FC07A
:1017F00043FF46C0828C938C138E128E148E158EEE
:10180000168E178E81E0F501878F24803580468003
:101810005780E0900A01F0900B0184011BC0C801C1
:101820000E944F043C01019709F484C060E070E01D
:10183000C8010E94C103882309F47CC0F701828D8E
:10184000938DFFEF8F3F9F0721F00196F701938F54
:10185000828F83010230110530F0F7018689978964
:1018600008171907E0F2C201B1010E94550388234D
:1018700009F460C0089481089108F501918E808E6A
:10188000FB8DF3FF23C080E2F60183870E94BB003B
:10189000F601668B778B808F918F66877787808B39
:1018A000918B81E0F501878F11C02115310509F079
:1018B00075C0C114D10409F440C0F601838599278D
:1018C00084FD3BC041FF02C080FD31C0F501848131
:1018D0009581A681B781EC8DFD8D868B978BA08F2E
:1018E000B18FD38EC28E2B8D2283F601828D938D84
:1018F000EC8DFD8D97878687F601848D958DA68D5D
:10190000B78DEC8DFD8D82879387A487B58716826E
:1019100017821086118681E08383B582A482D50167
:101920008D919C919183808320E030E037C026E048
:1019300030E034C028E030E031C022E030E02EC09A
:10194000E0910A01F0910B01848595851C8A1B8A20
:101950001E8A1D8AAA27BB278F8B988FA98FBA8FC3
:10196000188A1F86FA8BE98BD6018C91882309F49B
:1019700091CECCCD80E2F60111928A95E9F7F6017D
:10198000DE0111968BE00D9001928150E1F78C857C
:10199000F6018487FB8DF860FB8F72CFC901E2E10D
:1019A0006D960C94461182E3809310018FEF8EBDEB
:1019B0000DB407FEFDCF8EB58FEF8EBD0DB407FEC3
:1019C000FDCF8EB5282F33278F3F21F08091100156
:1019D000882391F7C9010895FC018AE080930F01E3
:1019E0008FEF8EBD0DB407FEFDCF8EB58F3F29F46E
:1019F00080910F01882329F1F3CF8E3F11F58FEFEE
:101A00008EBD0DB407FEFDCF8EB580838FEF8EBDEA
:101A10000DB407FEFDCF8EB581836250704011F08A
:101A20003296EDCF8FEF8EBD0DB407FEFDCF8EB594
:101A30008FEF8EBD0DB407FEFDCF8EB581E090E037
:101A4000089580E090E008951F93CF93DF93EC0119
:101A5000162F0E94D30C8F3F19F080E090E031C028
:101A60001EBD0DB407FEFDCF1D3F19F481E090E0CF
:101A700028C090E088818EBD0DB407FEFDCF89811E
:101A80008EBD0DB407FEFDCF915011F02296F2CF1E
:101A90008FEF8EBD0DB407FEFDCF8FEF8EBD0DB461
:101AA00007FEFDCF8FEF8EBD0DB407FEFDCF8EB5C7
:101AB00090E08F71853009F091E081E09827892FBF
:101AC0009927DF91CF911F910895DF92EF92FF92B6
:101AD0000F931F93D82E7A018B010E94D30C8F3F56
:101AE00019F02FEF30E044C0DEBC0DB407FEFDCF8F
:101AF000812F9927AA27BB278EBD0DB407FEFDCFE6
:101B0000C801AA27BB278EBD0DB407FEFDCFBB279A
:101B1000A12F902F8F2D8EBD0DB407FEFDCFEEBCF3
:101B20000DB407FEFDCF80E4D81611F485E906C098
:101B300088E4D81611F487E801C080E08EBD0DB4AA
:101B400007FEFDCF8CE4D81631F48FEF8EBD0DB4B7
:101B500007FEFDCF8EB59AE08FEF8EBD0DB407FE68
:101B6000FDCF8EB5282F332787FF02C09150A1F7F4
:101B7000C9011F910F91FF90EF90DF900895882386
:101B800019F081E090E0089580910401992708956B
:101B900080910F01882319F0815080930F0180916B
:101BA0001001882319F081508093100190910E014B
:101BB00083B1817080930E01981749F480910401DC
:101BC00090FF02C0836001C08D7F8093040108955F
:101BD000A0E1B0E0EEEEFDE00C943811FA018823AC
:101BE00019F024E030E0DAC08A012A98633009F461
:101BF00082C0643028F4613079F0623051F474C0EE
:101C00006B3009F488C06C3009F49FC06A3009F465
:101C100078C024E030E0B8C040E050E060E070E020
:101C200089E40E94650D882309F0ACC060E170E092
:101C3000CE0101960E94EC0C882309F4A3C089818F
:101C400082958695869583707A8549858130C1F421
:101C5000872F99270196242F3327322F2227820F8F
:101C6000931FAA27BB276AE0880F991FAA1FBB1FD3
:101C70006A95D1F7F80180839183A283B38338C03A
:101C8000429546954695437028853327220F331F8A
:101C9000220F331F240F311D2F5F3F4F8F81992754
:101CA00083709070982F8827990F990F280F391FEC
:101CB000442755276E816F706E5F7370770F670FC3
:101CC0008B85881F8827881F860F9927099704C04E
:101CD000220F331F441F551F8A95D2F7F801208326
:101CE00031834283538304C080E092E091838083F8
:101CF00020E030E049C00E94D30C90E08F3F01F516
:101D00001EC08091040180FD47C040E050E060E0CB
:101D100070E089E409C08091040180FD3DC040E08D
:101D200050E060E070E08AE40E94650D882351F580
:101D300060E170E0C8010E94EC0C90E0811191E03C
:101D400081E09827292F33271FC08091040180FD4F
:101D500023C040E050E060E070E08AE70E94650D3B
:101D6000882381F490E08FEF8EBD0DB407FEFDCF88
:101D70008EB5F80180839F5F943009F4B9CF0F5F6F
:101D80001F4FF1CF21E030E02A9A8FEF8EBD0DB4C6
:101D900007FEFDCF8EB502C023E030E0C901E4E0CC
:101DA00060960C945411CF92DF92EF92FF920F93B2
:101DB000CF93DF93EB0169017A01882309F067C0B3
:101DC000002309F464C08091040180FF03C083E014
:101DD00090E05FC08091040182FF03C082E090E048
:101DE00058C080911101992782FD07C0E9E0CC0C11
:101DF000DD1CEE1CFF1CEA95D1F72A98013079F41E
:101E0000B701A60188E50E94650D882391F56EEF64
:101E1000CE010E94240D811181E008272AC081FF94
:101E20000EC040E050E060E070E087E70E94650D82
:101E3000402F55276627772787E50E94650DB70154
:101E4000A60189E50E94650D882399F46CEFCE0107
:101E50000E94240D882329F0015019F0C050DE4F54
:101E6000F5CF6DEF80E090E00E94240D882309F407
:101E700001E02A9A8FEF8EBD0DB407FEFDCF8EB51F
:101E800080E090E0002329F081E090E002C084E04F
:101E900090E0DF91CF910F91FF90EF90DF90CF9086
:101EA00008950F93CF93DF93EB01882309F050C07F
:101EB000002309F44DC08091040180FF03C083E03A
:101EC00090E048C08091110182FD07C0F9E0220F27
:101ED000331F441F551FFA95D1F72A98013081F41A
:101EE000BA01A90181E50E94650D882319F560E01A
:101EF00072E0CE010E94EC0C811181E008271AC02B
:101F0000BA01A90182E50E94650D882399F460E079
:101F100072E0CE010E94EC0C882329F0015019F0E8
:101F2000C050DE4FF4CF40E050E060E070E08CE461
:101F30000E94650D2A9A8FEF8EBD0DB407FEFDCF6E
:101F40008EB580E090E0002329F081E090E002C0AF
:101F500084E090E0DF91CF910F910895A4E0B0E08C
:101F6000E4EBFFE00C943611882319F081E090E057
:101F7000D0C08091040181FDC9C09AE08FEF8EBD71
:101F80000DB407FEFDCF8EB59150C1F72A9840E001
:101F900050E060E070E080E40E94650D813009F05F
:101FA000A0C084E680930F014AEA51E060E070E04F
:101FB00088E40E94650D813009F054C07E010894C8
:101FC000E11CF11C87019E012B5F3F4F8FEF8EBDFF
:101FD0000DB407FEFDCF8EB5F80181938F01E21796
:101FE000F307A1F78B81813009F07BC08C818A3A9D
:101FF00009F077C040E050E060E070E087E70E94C1
:10200000650D823048F440E050E060E070E489E61D
:102010000E94650D882321F080910F01882351F7DC
:1020200080910F01882309F45CC040E050E060E03B
:1020300070E08AE70E94650D882309F052C08FEF97
:102040008EBD0DB407FEFDCF8EB5F70181937F01E4
:10205000E017F107A1F7898186FF02C016E042C0B0
:1020600012E040C040E050E060E070E087E70E948E
:10207000650D823058F440E050E060E070E089E6A1
:102080000E94650D823010F412E001C011E01230A0
:1020900079F440E050E060E070E087E70E94650D71
:1020A000823078F440E050E060E070E089E605C0FE
:1020B00040E050E060E070E081E40E94650D88231C
:1020C00021F080910F01882311F780910F0188235F
:1020D00041F040E052E060E070E080E50E94650D74
:1020E000811110E0109311012A9A8FEF8EBD0DB46B
:1020F00007FEFDCF8EB5112321F0809104018E7F64
:1021000003C08091040181608093040180910401E7
:102110009927E6E024960C945211FB01DC0105900E
:102120000D920020E1F70895FB01DC0104C08D91C0
:102130000190801921F441505040C8F7881B990B39
:102140000895FB01DC0102C001900D924150504006
:10215000D8F70895DC0101C06D9341505040E0F77D
:102160000895FB01DC0101900D920020E1F7089534
:10217000FB019F01E8944230C4F04532B4F44A3088
:1021800029F497FB1EF4909581959F4F642F772734
:102190000E946111805D8A330CF0895D8193CB01CF
:1021A0000097A1F716F45DE251931082C9010C94D7
:1021B000D910DC01FC01672F71917723E1F7329789
:1021C00004C07C916D9370836291AE17BF07C8F312
:1021D0000895629FD001739FF001829FE00DF11D71
:1021E000649FE00DF11D929FF00D839FF00D749F91
:1021F000F00D659FF00D9927729FB00DE11DF91F3D
:10220000639FB00DE11DF91FBD01CF011124089599
:10221000A1E21A2EAA1BBB1BFD010DC0AA1FBB1FEA
:10222000EE1FFF1FA217B307E407F50720F0A21B5C
:10223000B30BE40BF50B661F771F881F991F1A94C9
:1022400069F760957095809590959B01AC01BD01F3
:10225000CF0108952F923F924F925F926F927F929B
:102260008F929F92AF92BF92CF92DF92EF92FF92A6
:102270000F931F93CF93DF93CDB7DEB7CA1BDB0B52
:102280000FB6F894DEBF0FBECDBF09942A883988F7
:1022900048885F846E847D848C849B84AA84B984FE
:1022A000C884DF80EE80FD800C811B81AA81B9810A
:1022B000CE0FD11D0FB6F894DEBF0FBECDBFED011E
:1022C0000895AA1BBB1B51E107C0AA1FBB1FA6177D
:1022D000B70710F0A61BB70B881F991F5A95A9F7CF
:0C22E00080959095BC01CD010895FFCFC2
:0622EC0046415400010010
:00000001FF
/Designs/GPSRL03A/glg.lst
0,0 → 1,6162
 
glg.elf: file format elf32-avr
 
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000006 00800100 000022ec 00002360 2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 000022ec 00000000 00000000 00000074 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .bss 00000341 00800106 000022f2 00002366 2**0
ALLOC
3 .stab 0000087c 00000000 00000000 00002368 2**2
CONTENTS, READONLY, DEBUGGING
4 .stabstr 0000019e 00000000 00000000 00002be4 2**0
CONTENTS, READONLY, DEBUGGING
5 .debug_aranges 00000060 00000000 00000000 00002d82 2**0
CONTENTS, READONLY, DEBUGGING
6 .debug_pubnames 0000019e 00000000 00000000 00002de2 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_info 00001cfd 00000000 00000000 00002f80 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_abbrev 000007a6 00000000 00000000 00004c7d 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_line 000019a4 00000000 00000000 00005423 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_frame 00000260 00000000 00000000 00006dc8 2**2
CONTENTS, READONLY, DEBUGGING
11 .debug_str 000005e8 00000000 00000000 00007028 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_loc 000020ca 00000000 00000000 00007610 2**0
CONTENTS, READONLY, DEBUGGING
13 .debug_ranges 00000178 00000000 00000000 000096da 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
 
00000000 <__vectors>:
0: 0c 94 4c 00 jmp 0x98 ; 0x98 <__ctors_end>
4: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
8: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
c: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
10: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
14: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
18: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
1c: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
20: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
24: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
28: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
2c: 0c 94 7a 01 jmp 0x2f4 ; 0x2f4 <__vector_11>
30: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
34: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
38: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
3c: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
40: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
44: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
48: 0c 94 d6 00 jmp 0x1ac ; 0x1ac <__vector_18>
4c: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
50: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
54: 0c 94 6b 00 jmp 0xd6 ; 0xd6 <__vector_21>
58: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
5c: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
60: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
64: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__bad_interrupt>
 
00000068 <__c.2081>:
68: 0d 0a 00 ...
 
0000006b <__c.2079>:
6b: 2c 00 ,.
 
0000006d <__c.2075>:
6d: 24 47 50 52 4d 43 00 $GPRMC.
 
00000074 <__c.2073>:
74: 24 47 50 47 47 41 00 $GPGGA.
 
0000007b <__c.2071>:
7b: 2e 6c 6f 67 00 .log.
 
00000080 <__c.2065>:
80: 24 47 50 52 4d 43 00 $GPRMC.
 
00000087 <__c.2014>:
87: 24 50 53 52 46 31 30 36 2c 32 31 2a 30 46 0d 0a $PSRF106,21*0F..
...
 
00000098 <__ctors_end>:
98: 11 24 eor r1, r1
9a: 1f be out 0x3f, r1 ; 63
9c: cf ef ldi r28, 0xFF ; 255
9e: d4 e0 ldi r29, 0x04 ; 4
a0: de bf out 0x3e, r29 ; 62
a2: cd bf out 0x3d, r28 ; 61
 
000000a4 <__do_copy_data>:
a4: 11 e0 ldi r17, 0x01 ; 1
a6: a0 e0 ldi r26, 0x00 ; 0
a8: b1 e0 ldi r27, 0x01 ; 1
aa: ec ee ldi r30, 0xEC ; 236
ac: f2 e2 ldi r31, 0x22 ; 34
ae: 02 c0 rjmp .+4 ; 0xb4 <.do_copy_data_start>
 
000000b0 <.do_copy_data_loop>:
b0: 05 90 lpm r0, Z+
b2: 0d 92 st X+, r0
 
000000b4 <.do_copy_data_start>:
b4: a6 30 cpi r26, 0x06 ; 6
b6: b1 07 cpc r27, r17
b8: d9 f7 brne .-10 ; 0xb0 <.do_copy_data_loop>
 
000000ba <__do_clear_bss>:
ba: 14 e0 ldi r17, 0x04 ; 4
bc: a6 e0 ldi r26, 0x06 ; 6
be: b1 e0 ldi r27, 0x01 ; 1
c0: 01 c0 rjmp .+2 ; 0xc4 <.do_clear_bss_start>
 
000000c2 <.do_clear_bss_loop>:
c2: 1d 92 st X+, r1
 
000000c4 <.do_clear_bss_start>:
c4: a7 34 cpi r26, 0x47 ; 71
c6: b1 07 cpc r27, r17
c8: e1 f7 brne .-8 ; 0xc2 <.do_clear_bss_loop>
ca: 0e 94 ba 01 call 0x374 ; 0x374 <main>
ce: 0c 94 75 11 jmp 0x22ea ; 0x22ea <_exit>
 
000000d2 <__bad_interrupt>:
d2: 0c 94 00 00 jmp 0 ; 0x0 <__heap_end>
 
000000d6 <__vector_21>:
/*---------------------------------------------------------*/
/* ADC interrupt */
/*---------------------------------------------------------*/
 
ISR(ADC_vect)
{
d6: 1f 92 push r1
d8: 0f 92 push r0
da: 0f b6 in r0, 0x3f ; 63
dc: 0f 92 push r0
de: 11 24 eor r1, r1
e0: 2f 93 push r18
e2: 3f 93 push r19
e4: 8f 93 push r24
WORD n;
static BYTE l, h;
 
n = ADC;
e6: 20 91 78 00 lds r18, 0x0078
ea: 30 91 79 00 lds r19, 0x0079
 
if(ADMUX == POWER_check)
ee: 80 91 7c 00 lds r24, 0x007C
{
if (n < VTH_LOW) {
f2: 20 3d cpi r18, 0xD0 ; 208
f4: 31 05 cpc r19, r1
f6: 70 f4 brcc .+28 ; 0x114 <__vector_21+0x3e>
if (l >= 15) {
f8: 80 91 09 01 lds r24, 0x0109
fc: 8f 30 cpi r24, 0x0F ; 15
fe: 30 f0 brcs .+12 ; 0x10c <__vector_21+0x36>
Stat |= 0x01;
100: 80 91 69 01 lds r24, 0x0169
104: 81 60 ori r24, 0x01 ; 1
106: 80 93 69 01 sts 0x0169, r24
10a: 06 c0 rjmp .+12 ; 0x118 <__vector_21+0x42>
}
else {l++;}
10c: 8f 5f subi r24, 0xFF ; 255
10e: 80 93 09 01 sts 0x0109, r24
112: 02 c0 rjmp .+4 ; 0x118 <__vector_21+0x42>
}
else {l = 0;}
114: 10 92 09 01 sts 0x0109, r1
 
if (n > VTH_HIGH) {
118: 81 e0 ldi r24, 0x01 ; 1
11a: 2c 32 cpi r18, 0x2C ; 44
11c: 38 07 cpc r19, r24
11e: 70 f0 brcs .+28 ; 0x13c <__vector_21+0x66>
if (h >= 15) {
120: 80 91 08 01 lds r24, 0x0108
124: 8f 30 cpi r24, 0x0F ; 15
126: 30 f0 brcs .+12 ; 0x134 <__vector_21+0x5e>
Stat &= 0xFE;
128: 80 91 69 01 lds r24, 0x0169
12c: 8e 7f andi r24, 0xFE ; 254
12e: 80 93 69 01 sts 0x0169, r24
132: 06 c0 rjmp .+12 ; 0x140 <__vector_21+0x6a>
}
else {h++;}
134: 8f 5f subi r24, 0xFF ; 255
136: 80 93 08 01 sts 0x0108, r24
13a: 02 c0 rjmp .+4 ; 0x140 <__vector_21+0x6a>
}
else {h = 0;}
13c: 10 92 08 01 sts 0x0108, r1
 
battery = n;
140: 30 93 6f 01 sts 0x016F, r19
144: 20 93 6e 01 sts 0x016E, r18
ADMUX = ANALOG_IN1;
148: 82 e4 ldi r24, 0x42 ; 66
14a: 80 93 7c 00 sts 0x007C, r24
}
 
if(ADMUX == ANALOG_IN1)
14e: 80 91 7c 00 lds r24, 0x007C
{
intensity = n;
152: 30 93 0a 02 sts 0x020A, r19
156: 20 93 09 02 sts 0x0209, r18
ADMUX = POWER_check;
15a: 81 e4 ldi r24, 0x41 ; 65
15c: 80 93 7c 00 sts 0x007C, r24
}
 
//!!!!
//Stat &= 0xFE;
 
ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADIF)|_BV(ADIE)|0b111;
160: 8f ed ldi r24, 0xDF ; 223
162: 80 93 7a 00 sts 0x007A, r24
166: 8f 91 pop r24
168: 3f 91 pop r19
16a: 2f 91 pop r18
16c: 0f 90 pop r0
16e: 0f be out 0x3f, r0 ; 63
170: 0f 90 pop r0
172: 1f 90 pop r1
174: 18 95 reti
 
00000176 <get_fattime>:
/* FatFs module. Any valid time must be returned even if */
/* the system does not support a real time clock. */
 
 
DWORD get_fattime ()
{
176: 60 e0 ldi r22, 0x00 ; 0
178: 70 e0 ldi r23, 0x00 ; 0
17a: 81 ea ldi r24, 0xA1 ; 161
17c: 96 e3 ldi r25, 0x36 ; 54
17e: 08 95 ret
 
00000180 <uart_init>:
/* UART control */
 
 
static
void uart_init (void)
{
180: f8 94 cli
cli();
UCSR0B = 0;
182: e1 ec ldi r30, 0xC1 ; 193
184: f0 e0 ldi r31, 0x00 ; 0
186: 10 82 st Z, r1
rxfifo.idx_r = 0;
188: 10 92 71 01 sts 0x0171, r1
rxfifo.idx_w = 0;
18c: 10 92 70 01 sts 0x0170, r1
rxfifo.count = 0;
190: 10 92 72 01 sts 0x0172, r1
UBRR0L = SYSCLK/16/9600; // Enable USRAT0 in N81,4800bps
194: 81 e4 ldi r24, 0x41 ; 65
196: 80 93 c4 00 sts 0x00C4, r24
UCSR0B = _BV(RXCIE0)|_BV(RXEN0)|_BV(TXEN0);
19a: 88 e9 ldi r24, 0x98 ; 152
19c: 80 83 st Z, r24
Stat &= 0xFD; // Clear overflow flag
19e: 80 91 69 01 lds r24, 0x0169
1a2: 8d 7f andi r24, 0xFD ; 253
1a4: 80 93 69 01 sts 0x0169, r24
sei();
1a8: 78 94 sei
1aa: 08 95 ret
 
000001ac <__vector_18>:
}
 
 
/* USART0 RXC interrupt */
ISR(USART_RX_vect)
{
1ac: 1f 92 push r1
1ae: 0f 92 push r0
1b0: 0f b6 in r0, 0x3f ; 63
1b2: 0f 92 push r0
1b4: 11 24 eor r1, r1
1b6: 8f 93 push r24
1b8: 9f 93 push r25
1ba: ef 93 push r30
1bc: ff 93 push r31
uint8_t d, n, i;
 
 
d = UDR0;
1be: 90 91 c6 00 lds r25, 0x00C6
n = rxfifo.count;
1c2: 80 91 72 01 lds r24, 0x0172
if(n < sizeof(rxfifo.buff)) {
1c6: 86 39 cpi r24, 0x96 ; 150
1c8: 88 f4 brcc .+34 ; 0x1ec <__vector_18+0x40>
rxfifo.count = ++n;
1ca: 8f 5f subi r24, 0xFF ; 255
1cc: 80 93 72 01 sts 0x0172, r24
i = rxfifo.idx_w;
1d0: 80 91 70 01 lds r24, 0x0170
rxfifo.buff[i++] = d;
1d4: e8 2f mov r30, r24
1d6: ff 27 eor r31, r31
1d8: e0 59 subi r30, 0x90 ; 144
1da: fe 4f sbci r31, 0xFE ; 254
1dc: 93 83 std Z+3, r25 ; 0x03
1de: 8f 5f subi r24, 0xFF ; 255
if(i >= sizeof(rxfifo.buff))
1e0: 86 39 cpi r24, 0x96 ; 150
1e2: 08 f0 brcs .+2 ; 0x1e6 <__vector_18+0x3a>
1e4: 80 e0 ldi r24, 0x00 ; 0
i = 0;
rxfifo.idx_w = i;
1e6: 80 93 70 01 sts 0x0170, r24
1ea: 05 c0 rjmp .+10 ; 0x1f6 <__vector_18+0x4a>
} else {
Stat |= 2;
1ec: 80 91 69 01 lds r24, 0x0169
1f0: 82 60 ori r24, 0x02 ; 2
1f2: 80 93 69 01 sts 0x0169, r24
1f6: ff 91 pop r31
1f8: ef 91 pop r30
1fa: 9f 91 pop r25
1fc: 8f 91 pop r24
1fe: 0f 90 pop r0
200: 0f be out 0x3f, r0 ; 63
202: 0f 90 pop r0
204: 1f 90 pop r1
206: 18 95 reti
 
00000208 <get_line>:
/* Get a line received from GPS module */
/*----------------------------------------------------*/
 
static
BYTE get_line (void) // 0: Power fail occured, >0: Number of bytes received.
{
208: 90 e0 ldi r25, 0x00 ; 0
BYTE c, i = 0;
 
 
for (;;) {
if (Stat & 1) return 0; // When power fail is detected, return with zero.
20a: 80 91 69 01 lds r24, 0x0169
20e: 80 ff sbrs r24, 0
210: 03 c0 rjmp .+6 ; 0x218 <get_line+0x10>
212: 80 e0 ldi r24, 0x00 ; 0
214: 90 e0 ldi r25, 0x00 ; 0
216: 08 95 ret
uint8_t uart_get ()
{
uint8_t d, i;
 
 
i = rxfifo.idx_r;
218: 20 91 71 01 lds r18, 0x0171
if (rxfifo.count == 0) return 0;
21c: 80 91 72 01 lds r24, 0x0172
220: 88 23 and r24, r24
222: 19 f4 brne .+6 ; 0x22a <get_line+0x22>
224: 20 e0 ldi r18, 0x00 ; 0
226: 30 e0 ldi r19, 0x00 ; 0
228: 15 c0 rjmp .+42 ; 0x254 <get_line+0x4c>
d = rxfifo.buff[i++];
22a: e2 2f mov r30, r18
22c: ff 27 eor r31, r31
22e: e0 59 subi r30, 0x90 ; 144
230: fe 4f sbci r31, 0xFE ; 254
232: 33 81 ldd r19, Z+3 ; 0x03
234: e2 2f mov r30, r18
236: ef 5f subi r30, 0xFF ; 255
cli();
238: f8 94 cli
rxfifo.count--;
23a: 80 91 72 01 lds r24, 0x0172
23e: 81 50 subi r24, 0x01 ; 1
240: 80 93 72 01 sts 0x0172, r24
sei();
244: 78 94 sei
if(i >= sizeof(rxfifo.buff))
246: e6 39 cpi r30, 0x96 ; 150
248: 08 f0 brcs .+2 ; 0x24c <get_line+0x44>
24a: e0 e0 ldi r30, 0x00 ; 0
i = 0;
rxfifo.idx_r = i;
24c: e0 93 71 01 sts 0x0171, r30
 
return d;
250: 23 2f mov r18, r19
252: 33 27 eor r19, r19
 
 
for (;;) {
if (Stat & 1) return 0; // When power fail is detected, return with zero.
c = uart_get();
if (Stat & 2) { // When buffer overflow has occured, restert to receive line.
254: 80 91 69 01 lds r24, 0x0169
258: 81 ff sbrs r24, 1
25a: 03 c0 rjmp .+6 ; 0x262 <get_line+0x5a>
uart_init();
25c: 0e 94 c0 00 call 0x180 ; 0x180 <uart_init>
260: d3 cf rjmp .-90 ; 0x208 <get_line>
BYTE c, i = 0;
 
 
for (;;) {
if (Stat & 1) return 0; // When power fail is detected, return with zero.
c = uart_get();
262: 82 2f mov r24, r18
if (Stat & 2) { // When buffer overflow has occured, restert to receive line.
uart_init();
i = 0; c = 0;
}
if (!c || (i == 0 && c != '$')) continue;
264: 22 23 and r18, r18
266: 89 f2 breq .-94 ; 0x20a <get_line+0x2>
268: 99 23 and r25, r25
26a: 11 f4 brne .+4 ; 0x270 <get_line+0x68>
26c: 24 32 cpi r18, 0x24 ; 36
26e: 69 f6 brne .-102 ; 0x20a <get_line+0x2>
Buff[i++] = c;
270: e9 2f mov r30, r25
272: ff 27 eor r31, r31
274: e9 5e subi r30, 0xE9 ; 233
276: fe 4f sbci r31, 0xFE ; 254
278: 20 83 st Z, r18
27a: 9f 5f subi r25, 0xFF ; 255
if (c == '\n') break;
27c: 8a 30 cpi r24, 0x0A ; 10
27e: 21 f0 breq .+8 ; 0x288 <get_line+0x80>
if (i >= sizeof(Buff)) i = 0;
280: 92 35 cpi r25, 0x52 ; 82
282: 08 f0 brcs .+2 ; 0x286 <get_line+0x7e>
284: c1 cf rjmp .-126 ; 0x208 <get_line>
286: c1 cf rjmp .-126 ; 0x20a <get_line+0x2>
}
return i;
288: 89 2f mov r24, r25
28a: 99 27 eor r25, r25
}
28c: 08 95 ret
 
0000028e <beep>:
/*--------------------------------------------------------------------------*/
/* Controls */
 
static
void beep (BYTE len, BYTE cnt)
{
28e: 98 2f mov r25, r24
290: 0f c0 rjmp .+30 ; 0x2b0 <beep+0x22>
while (cnt--) {
BEEP_ON();
292: 83 e0 ldi r24, 0x03 ; 3
294: 85 bd out 0x25, r24 ; 37
DELAY(len);
296: 90 93 16 01 sts 0x0116, r25
29a: 80 91 16 01 lds r24, 0x0116
29e: 88 23 and r24, r24
2a0: e1 f7 brne .-8 ; 0x29a <beep+0xc>
BEEP_OFF();
2a2: 15 bc out 0x25, r1 ; 37
DELAY(len);
2a4: 90 93 16 01 sts 0x0116, r25
2a8: 80 91 16 01 lds r24, 0x0116
2ac: 88 23 and r24, r24
2ae: e1 f7 brne .-8 ; 0x2a8 <beep+0x1a>
/* Controls */
 
static
void beep (BYTE len, BYTE cnt)
{
while (cnt--) {
2b0: 61 50 subi r22, 0x01 ; 1
2b2: 78 f7 brcc .-34 ; 0x292 <beep+0x4>
2b4: 08 95 ret
 
000002b6 <gp_comp>:
 
 
/* Compare sentence header string */
static
BYTE gp_comp (BYTE *str1, const prog_uint8_t *str2)
{
2b6: dc 01 movw r26, r24
2b8: fb 01 movw r30, r22
BYTE c;
 
do {
c = pgm_read_byte(str2++);
2ba: 6f 5f subi r22, 0xFF ; 255
2bc: 7f 4f sbci r23, 0xFF ; 255
2be: 94 91 lpm r25, Z
} while (c && c == *str1++);
2c0: 99 23 and r25, r25
2c2: 29 f0 breq .+10 ; 0x2ce <gp_comp+0x18>
2c4: 8c 91 ld r24, X
2c6: 98 17 cp r25, r24
2c8: 11 f4 brne .+4 ; 0x2ce <gp_comp+0x18>
2ca: 11 96 adiw r26, 0x01 ; 1
2cc: f5 cf rjmp .-22 ; 0x2b8 <gp_comp+0x2>
return c;
}
2ce: 89 2f mov r24, r25
2d0: 99 27 eor r25, r25
2d2: 08 95 ret
 
000002d4 <gp_col>:
/* Get a column item */
static
BYTE* gp_col ( /* Returns pointer to the item (returns a NULL when not found) */
const BYTE* buf, /* Pointer to the sentence */
BYTE col /* Column number (0 is the 1st item) */
) {
2d4: fc 01 movw r30, r24
2d6: 0a c0 rjmp .+20 ; 0x2ec <gp_col+0x18>
BYTE c;
 
 
while (col) {
do {
c = *buf++;
2d8: 80 81 ld r24, Z
if (c <= ' ') return NULL;
2da: 81 32 cpi r24, 0x21 ; 33
2dc: 18 f4 brcc .+6 ; 0x2e4 <gp_col+0x10>
2de: 80 e0 ldi r24, 0x00 ; 0
2e0: 90 e0 ldi r25, 0x00 ; 0
2e2: 08 95 ret
BYTE c;
 
 
while (col) {
do {
c = *buf++;
2e4: 31 96 adiw r30, 0x01 ; 1
if (c <= ' ') return NULL;
} while (c != ',');
2e6: 8c 32 cpi r24, 0x2C ; 44
2e8: b9 f7 brne .-18 ; 0x2d8 <gp_col+0x4>
col--;
2ea: 61 50 subi r22, 0x01 ; 1
BYTE col /* Column number (0 is the 1st item) */
) {
BYTE c;
 
 
while (col) {
2ec: 66 23 and r22, r22
2ee: a1 f7 brne .-24 ; 0x2d8 <gp_col+0x4>
c = *buf++;
if (c <= ' ') return NULL;
} while (c != ',');
col--;
}
return (BYTE*)buf;
2f0: cf 01 movw r24, r30
}
2f2: 08 95 ret
 
000002f4 <__vector_11>:
/* 100Hz timer interrupt generated by OC1A */
/*---------------------------------------------------------*/
 
 
ISR(TIMER1_COMPA_vect)
{
2f4: 1f 92 push r1
2f6: 0f 92 push r0
2f8: 0f b6 in r0, 0x3f ; 63
2fa: 0f 92 push r0
2fc: 11 24 eor r1, r1
2fe: 2f 93 push r18
300: 3f 93 push r19
302: 4f 93 push r20
304: 5f 93 push r21
306: 6f 93 push r22
308: 7f 93 push r23
30a: 8f 93 push r24
30c: 9f 93 push r25
30e: af 93 push r26
310: bf 93 push r27
312: ef 93 push r30
314: ff 93 push r31
BYTE n;
static WORD ivt_sync;
 
 
n = Timer;
316: 80 91 16 01 lds r24, 0x0116
if (n) Timer = n - 1;
31a: 88 23 and r24, r24
31c: 19 f0 breq .+6 ; 0x324 <__vector_11+0x30>
31e: 81 50 subi r24, 0x01 ; 1
320: 80 93 16 01 sts 0x0116, r24
 
if (++ivt_sync >= 180 * 100) {
324: 80 91 06 01 lds r24, 0x0106
328: 90 91 07 01 lds r25, 0x0107
32c: 01 96 adiw r24, 0x01 ; 1
32e: 90 93 07 01 sts 0x0107, r25
332: 80 93 06 01 sts 0x0106, r24
336: 80 55 subi r24, 0x50 ; 80
338: 96 44 sbci r25, 0x46 ; 70
33a: 48 f0 brcs .+18 ; 0x34e <__vector_11+0x5a>
ivt_sync = 0;
33c: 10 92 07 01 sts 0x0107, r1
340: 10 92 06 01 sts 0x0106, r1
Stat |= 4;
344: 80 91 69 01 lds r24, 0x0169
348: 84 60 ori r24, 0x04 ; 4
34a: 80 93 69 01 sts 0x0169, r24
}
 
disk_timerproc(); /* Drive timer procedure of low level disk I/O module */
34e: 0e 94 c8 0d call 0x1b90 ; 0x1b90 <disk_timerproc>
352: ff 91 pop r31
354: ef 91 pop r30
356: bf 91 pop r27
358: af 91 pop r26
35a: 9f 91 pop r25
35c: 8f 91 pop r24
35e: 7f 91 pop r23
360: 6f 91 pop r22
362: 5f 91 pop r21
364: 4f 91 pop r20
366: 3f 91 pop r19
368: 2f 91 pop r18
36a: 0f 90 pop r0
36c: 0f be out 0x3f, r0 ; 63
36e: 0f 90 pop r0
370: 1f 90 pop r1
372: 18 95 reti
 
00000374 <main>:
/*-----------------------------------------------------------------------*/
/* Main */
 
 
int main ()
{
374: cd ef ldi r28, 0xFD ; 253
376: d4 e0 ldi r29, 0x04 ; 4
378: de bf out 0x3e, r29 ; 62
37a: cd bf out 0x3d, r28 ; 61
 
 
static
void ioinit (void)
{
PORTB = 0b00001101; // Port B
37c: 8d e0 ldi r24, 0x0D ; 13
37e: 85 b9 out 0x05, r24 ; 5
DDRB = 0b00101110;
380: 8e e2 ldi r24, 0x2E ; 46
382: 84 b9 out 0x04, r24 ; 4
PORTC = 0b00111111; // Port C
384: 8f e3 ldi r24, 0x3F ; 63
386: 88 b9 out 0x08, r24 ; 8
DDRC = 0b00000000;
388: 17 b8 out 0x07, r1 ; 7
PORTD = 0b10101110; // Port D
38a: 8e ea ldi r24, 0xAE ; 174
38c: 8b b9 out 0x0b, r24 ; 11
DDRD = 0b01010010;
38e: 82 e5 ldi r24, 0x52 ; 82
390: 8a b9 out 0x0a, r24 ; 10
 
SPCR = 0b01010000; /* Initialize SPI port (Mode 0) */
392: 80 e5 ldi r24, 0x50 ; 80
394: 8c bd out 0x2c, r24 ; 44
SPSR = 0b00000001;
396: 81 e0 ldi r24, 0x01 ; 1
398: 8d bd out 0x2d, r24 ; 45
 
OCR1A = SYSCLK/8/100-1; // Timer1: 100Hz interval (OC1A)
39a: 83 ed ldi r24, 0xD3 ; 211
39c: 90 e3 ldi r25, 0x30 ; 48
39e: 90 93 89 00 sts 0x0089, r25
3a2: 80 93 88 00 sts 0x0088, r24
TCCR1B = 0b00001010;
3a6: 8a e0 ldi r24, 0x0A ; 10
3a8: 80 93 81 00 sts 0x0081, r24
TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
3ac: 82 e0 ldi r24, 0x02 ; 2
3ae: 80 93 6f 00 sts 0x006F, r24
 
OCR0A = SYSCLK/64/4000/2-1; // Timer0: 4kHz sound (OC0A)
3b2: 82 e1 ldi r24, 0x12 ; 18
3b4: 87 bd out 0x27, r24 ; 39
TCCR0A = 0b01000010;
3b6: 82 e4 ldi r24, 0x42 ; 66
3b8: 84 bd out 0x24, r24 ; 36
 
ADMUX = POWER_check; // Select ADC input
3ba: 81 e4 ldi r24, 0x41 ; 65
3bc: 80 93 7c 00 sts 0x007C, r24
ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADIF)|_BV(ADIE)|0b111;
3c0: 8f ed ldi r24, 0xDF ; 223
3c2: 80 93 7a 00 sts 0x007A, r24
 
sei();
3c6: 78 94 sei
BYTE b, err, *p = NULL;
WORD s;
 
 
ioinit();
f_mount(0, &fatfs); /* Enable file I/O layer */
3c8: 67 e2 ldi r22, 0x27 ; 39
3ca: 72 e0 ldi r23, 0x02 ; 2
3cc: 80 e0 ldi r24, 0x00 ; 0
3ce: 0e 94 ef 08 call 0x11de ; 0x11de <f_mount>
3d2: cc 24 eor r12, r12
3d4: dd 24 eor r13, r13
3d6: 47 e1 ldi r20, 0x17 ; 23
3d8: e4 2e mov r14, r20
3da: 41 e0 ldi r20, 0x01 ; 1
3dc: f4 2e mov r15, r20
3de: 3b e0 ldi r19, 0x0B ; 11
3e0: a3 2e mov r10, r19
3e2: 32 e0 ldi r19, 0x02 ; 2
3e4: b3 2e mov r11, r19
// || !gp_comp(Buff, PSTR("$GPGSV"))
// || !gp_comp(Buff, PSTR("$GPZDA"))
// || !gp_comp(Buff, PSTR("$GPVTG"))
)
{
if (f_write(&file1, Buff, b, &s) || b != s) { err = 5; break; };
3e6: 2e 01 movw r4, r28
3e8: 08 94 sec
3ea: 41 1c adc r4, r1
3ec: 51 1c adc r5, r1
3ee: 22 e1 ldi r18, 0x12 ; 18
3f0: 62 2e mov r6, r18
3f2: 21 e0 ldi r18, 0x01 ; 1
3f4: 72 2e mov r7, r18
3f6: 9a e6 ldi r25, 0x6A ; 106
3f8: 89 2e mov r8, r25
3fa: 91 e0 ldi r25, 0x01 ; 1
3fc: 99 2e mov r9, r25
3fe: 89 e0 ldi r24, 0x09 ; 9
400: 28 2e mov r2, r24
402: 31 2c mov r3, r1
404: 2e 0c add r2, r14
406: 3f 1c adc r3, r15
 
 
static
void uart_stop (void)
{
UCSR0B = 0;
408: 10 92 c1 00 sts 0x00C1, r1
ioinit();
f_mount(0, &fatfs); /* Enable file I/O layer */
 
for (;;) {
uart_stop();
GPS_OFF();
40c: 29 98 cbi 0x05, 1 ; 5
Timer = 100;
40e: 84 e6 ldi r24, 0x64 ; 100
410: 80 93 16 01 sts 0x0116, r24
do {
if (Stat & 1) Timer = 100;
414: 80 91 69 01 lds r24, 0x0169
418: 80 ff sbrs r24, 0
41a: 03 c0 rjmp .+6 ; 0x422 <main+0xae>
41c: 84 e6 ldi r24, 0x64 ; 100
41e: 80 93 16 01 sts 0x0116, r24
} while (Timer);
422: 80 91 16 01 lds r24, 0x0116
426: 88 23 and r24, r24
428: a9 f7 brne .-22 ; 0x414 <main+0xa0>
 
GPS_ON();
42a: 29 9a sbi 0x05, 1 ; 5
Timer = 255;
42c: 8f ef ldi r24, 0xFF ; 255
42e: 80 93 16 01 sts 0x0116, r24
do {
if ((Stat & 1) || (disk_status(0) & STA_NODISK)) Timer = 255;
432: 80 91 69 01 lds r24, 0x0169
436: 80 fd sbrc r24, 0
438: 05 c0 rjmp .+10 ; 0x444 <main+0xd0>
43a: 80 e0 ldi r24, 0x00 ; 0
43c: 0e 94 bf 0d call 0x1b7e ; 0x1b7e <disk_status>
440: 81 ff sbrs r24, 1
442: 03 c0 rjmp .+6 ; 0x44a <main+0xd6>
444: 8f ef ldi r24, 0xFF ; 255
446: 80 93 16 01 sts 0x0116, r24
} while (Timer);
44a: 80 91 16 01 lds r24, 0x0116
44e: 88 23 and r24, r24
450: 81 f7 brne .-32 ; 0x432 <main+0xbe>
 
beep(5, 1); // Single beep. Start to get current time.
452: 61 e0 ldi r22, 0x01 ; 1
454: 85 e0 ldi r24, 0x05 ; 5
456: 0e 94 47 01 call 0x28e ; 0x28e <beep>
uart_init();
45a: 0e 94 c0 00 call 0x180 ; 0x180 <uart_init>
/* Initialize GPS module (depends on each product) */
static
void gp_init (void)
{
const prog_char *s =
PSTR("$PSRF106,21*0F\r\n"); // Select datum of WGS84 (for EM-406A)
45e: 27 e8 ldi r18, 0x87 ; 135
460: 30 e0 ldi r19, 0x00 ; 0
462: 06 c0 rjmp .+12 ; 0x470 <main+0xfc>
 
/* Put a character to transmit */
static
void uart_put (uint8_t d)
{
while (bit_is_clear(UCSR0A, UDRE0));
464: 80 91 c0 00 lds r24, 0x00C0
468: 85 ff sbrs r24, 5
46a: fc cf rjmp .-8 ; 0x464 <main+0xf0>
UDR0 = d;
46c: 90 93 c6 00 sts 0x00C6, r25
470: f9 01 movw r30, r18
{
const prog_char *s =
PSTR("$PSRF106,21*0F\r\n"); // Select datum of WGS84 (for EM-406A)
char c;
 
while ((c = pgm_read_byte(s++)) != 0) uart_put(c);
472: 2f 5f subi r18, 0xFF ; 255
474: 3f 4f sbci r19, 0xFF ; 255
476: 94 91 lpm r25, Z
478: 99 23 and r25, r25
47a: a1 f7 brne .-24 ; 0x464 <main+0xf0>
 
beep(5, 1); // Single beep. Start to get current time.
uart_init();
gp_init(); // Initialize GPS module to let output data in NMEA-0183 format.
do { // Wait for valid RMC sentence.
b = get_line();
47c: 0e 94 04 01 call 0x208 ; 0x208 <get_line>
if (!b) break;
480: 88 23 and r24, r24
482: 09 f4 brne .+2 ; 0x486 <main+0x112>
484: c1 cf rjmp .-126 ; 0x408 <main+0x94>
if (gp_comp(Buff, PSTR("$GPRMC"))) continue;
486: 60 e8 ldi r22, 0x80 ; 128
488: 70 e0 ldi r23, 0x00 ; 0
48a: c7 01 movw r24, r14
48c: 0e 94 5b 01 call 0x2b6 ; 0x2b6 <gp_comp>
490: 88 23 and r24, r24
492: 29 f4 brne .+10 ; 0x49e <main+0x12a>
p = gp_col(Buff,2);
494: 62 e0 ldi r22, 0x02 ; 2
496: c7 01 movw r24, r14
498: 0e 94 6a 01 call 0x2d4 ; 0x2d4 <gp_col>
49c: 6c 01 movw r12, r24
} while (!p || *p != 'A');
49e: c1 14 cp r12, r1
4a0: d1 04 cpc r13, r1
4a2: 61 f3 breq .-40 ; 0x47c <main+0x108>
4a4: f6 01 movw r30, r12
4a6: 80 81 ld r24, Z
4a8: 81 34 cpi r24, 0x41 ; 65
4aa: 41 f7 brne .-48 ; 0x47c <main+0x108>
if (!b) continue;
p = gp_col(Buff,9); // Open log file with the name of current date (YYMMDD.log in UTC).
4ac: 69 e0 ldi r22, 0x09 ; 9
4ae: c7 01 movw r24, r14
4b0: 0e 94 6a 01 call 0x2d4 ; 0x2d4 <gp_col>
4b4: 6c 01 movw r12, r24
if (!p) {err = 3; break;}
4b6: 00 97 sbiw r24, 0x00 ; 0
4b8: 11 f4 brne .+4 ; 0x4be <main+0x14a>
4ba: 63 e0 ldi r22, 0x03 ; 3
4bc: a8 c0 rjmp .+336 ; 0x60e <__stack+0x10f>
 
memcpy(&Buff[0], p+4, 2);
4be: fc 01 movw r30, r24
4c0: 84 81 ldd r24, Z+4 ; 0x04
4c2: 95 81 ldd r25, Z+5 ; 0x05
4c4: 90 93 18 01 sts 0x0118, r25
4c8: 80 93 17 01 sts 0x0117, r24
memcpy(&Buff[2], p+2, 2);
4cc: 82 81 ldd r24, Z+2 ; 0x02
4ce: 93 81 ldd r25, Z+3 ; 0x03
4d0: 90 93 1a 01 sts 0x011A, r25
4d4: 80 93 19 01 sts 0x0119, r24
memcpy(&Buff[4], p+0, 2);
4d8: 80 81 ld r24, Z
4da: 91 81 ldd r25, Z+1 ; 0x01
4dc: 90 93 1c 01 sts 0x011C, r25
4e0: 80 93 1b 01 sts 0x011B, r24
strcpy_P(&Buff[6], PSTR(".log"));
4e4: 6b e7 ldi r22, 0x7B ; 123
4e6: 70 e0 ldi r23, 0x00 ; 0
4e8: 8d e1 ldi r24, 0x1D ; 29
4ea: 91 e0 ldi r25, 0x01 ; 1
4ec: 0e 94 8d 10 call 0x211a ; 0x211a <strcpy_P>
if (f_open(&file1, Buff, FA_OPEN_ALWAYS | FA_WRITE) || f_lseek(&file1, file1.fsize)) { err = 4; break; }
4f0: 42 e1 ldi r20, 0x12 ; 18
4f2: b7 01 movw r22, r14
4f4: c5 01 movw r24, r10
4f6: 0e 94 44 09 call 0x1288 ; 0x1288 <f_open>
4fa: 89 2b or r24, r25
4fc: 09 f0 breq .+2 ; 0x500 <__stack+0x1>
4fe: 86 c0 rjmp .+268 ; 0x60c <__stack+0x10d>
500: 40 91 15 02 lds r20, 0x0215
504: 50 91 16 02 lds r21, 0x0216
508: 60 91 17 02 lds r22, 0x0217
50c: 70 91 18 02 lds r23, 0x0218
510: c5 01 movw r24, r10
512: 0e 94 8b 05 call 0xb16 ; 0xb16 <f_lseek>
516: 89 2b or r24, r25
518: 09 f0 breq .+2 ; 0x51c <__stack+0x1d>
51a: 78 c0 rjmp .+240 ; 0x60c <__stack+0x10d>
 
beep(5, 2); // Two beeps. Start logging.
51c: 62 e0 ldi r22, 0x02 ; 2
51e: 85 e0 ldi r24, 0x05 ; 5
520: 0e 94 47 01 call 0x28e ; 0x28e <beep>
524: 65 c0 rjmp .+202 ; 0x5f0 <__stack+0xf1>
err = 0;
while ((b = get_line()) > 0) {
if ( !gp_comp(Buff, PSTR("$GPGGA")) // Which sentence is logged?
526: 64 e7 ldi r22, 0x74 ; 116
528: 70 e0 ldi r23, 0x00 ; 0
52a: c7 01 movw r24, r14
52c: 0e 94 5b 01 call 0x2b6 ; 0x2b6 <gp_comp>
530: 88 23 and r24, r24
532: 41 f0 breq .+16 ; 0x544 <__stack+0x45>
534: 6d e6 ldi r22, 0x6D ; 109
536: 70 e0 ldi r23, 0x00 ; 0
538: c7 01 movw r24, r14
53a: 0e 94 5b 01 call 0x2b6 ; 0x2b6 <gp_comp>
53e: 88 23 and r24, r24
540: 09 f0 breq .+2 ; 0x544 <__stack+0x45>
542: 44 c0 rjmp .+136 ; 0x5cc <__stack+0xcd>
// || !gp_comp(Buff, PSTR("$GPGSV"))
// || !gp_comp(Buff, PSTR("$GPZDA"))
// || !gp_comp(Buff, PSTR("$GPVTG"))
)
{
if (f_write(&file1, Buff, b, &s) || b != s) { err = 5; break; };
544: 01 2f mov r16, r17
546: 11 27 eor r17, r17
548: 92 01 movw r18, r4
54a: a8 01 movw r20, r16
54c: b7 01 movw r22, r14
54e: c5 01 movw r24, r10
550: 0e 94 c0 06 call 0xd80 ; 0xd80 <f_write>
554: 89 2b or r24, r25
556: 09 f0 breq .+2 ; 0x55a <__stack+0x5b>
558: 52 c0 rjmp .+164 ; 0x5fe <__stack+0xff>
55a: 89 81 ldd r24, Y+1 ; 0x01
55c: 9a 81 ldd r25, Y+2 ; 0x02
55e: 08 17 cp r16, r24
560: 19 07 cpc r17, r25
562: 09 f0 breq .+2 ; 0x566 <__stack+0x67>
564: 4c c0 rjmp .+152 ; 0x5fe <__stack+0xff>
itoa(battery,&Value1,10);
566: 4a e0 ldi r20, 0x0A ; 10
568: 50 e0 ldi r21, 0x00 ; 0
56a: b3 01 movw r22, r6
56c: 80 91 6e 01 lds r24, 0x016E
570: 90 91 6f 01 lds r25, 0x016F
574: 0e 94 b8 10 call 0x2170 ; 0x2170 <itoa>
itoa(intensity,&Value2,10);
578: 4a e0 ldi r20, 0x0A ; 10
57a: 50 e0 ldi r21, 0x00 ; 0
57c: b4 01 movw r22, r8
57e: 80 91 09 02 lds r24, 0x0209
582: 90 91 0a 02 lds r25, 0x020A
586: 0e 94 b8 10 call 0x2170 ; 0x2170 <itoa>
strcpy(&Buff[0], Value1);
58a: b3 01 movw r22, r6
58c: c7 01 movw r24, r14
58e: 0e 94 b1 10 call 0x2162 ; 0x2162 <strcpy>
strcpy_P(&Buff[4], PSTR(","));
592: 6b e6 ldi r22, 0x6B ; 107
594: 70 e0 ldi r23, 0x00 ; 0
596: 8b e1 ldi r24, 0x1B ; 27
598: 91 e0 ldi r25, 0x01 ; 1
59a: 0e 94 8d 10 call 0x211a ; 0x211a <strcpy_P>
strcpy(&Buff[5], Value2);
59e: b4 01 movw r22, r8
5a0: 8c e1 ldi r24, 0x1C ; 28
5a2: 91 e0 ldi r25, 0x01 ; 1
5a4: 0e 94 b1 10 call 0x2162 ; 0x2162 <strcpy>
strcpy_P(&Buff[9], PSTR("\r\n"));
5a8: 68 e6 ldi r22, 0x68 ; 104
5aa: 70 e0 ldi r23, 0x00 ; 0
5ac: c1 01 movw r24, r2
5ae: 0e 94 8d 10 call 0x211a ; 0x211a <strcpy_P>
if (f_write(&file1, Buff, 11, &s) || 11 != s) { err = 5; break; };
5b2: 92 01 movw r18, r4
5b4: 4b e0 ldi r20, 0x0B ; 11
5b6: 50 e0 ldi r21, 0x00 ; 0
5b8: b7 01 movw r22, r14
5ba: c5 01 movw r24, r10
5bc: 0e 94 c0 06 call 0xd80 ; 0xd80 <f_write>
5c0: 89 2b or r24, r25
5c2: e9 f4 brne .+58 ; 0x5fe <__stack+0xff>
5c4: 89 81 ldd r24, Y+1 ; 0x01
5c6: 9a 81 ldd r25, Y+2 ; 0x02
5c8: 0b 97 sbiw r24, 0x0b ; 11
5ca: c9 f4 brne .+50 ; 0x5fe <__stack+0xff>
}
if ((Stat & 4) == 0) continue;
5cc: 80 91 69 01 lds r24, 0x0169
5d0: 82 ff sbrs r24, 2
5d2: 0e c0 rjmp .+28 ; 0x5f0 <__stack+0xf1>
if (f_sync(&file1)) { err = 6; break; };// Synchronize the file in interval of 300 sec.
5d4: c5 01 movw r24, r10
5d6: 0e 94 5d 06 call 0xcba ; 0xcba <f_sync>
5da: 89 2b or r24, r25
5dc: 11 f0 breq .+4 ; 0x5e2 <__stack+0xe3>
5de: 66 e0 ldi r22, 0x06 ; 6
5e0: 16 c0 rjmp .+44 ; 0x60e <__stack+0x10f>
cli(); Stat &= 0xFB; sei(); // Clear sync request
5e2: f8 94 cli
5e4: 80 91 69 01 lds r24, 0x0169
5e8: 8b 7f andi r24, 0xFB ; 251
5ea: 80 93 69 01 sts 0x0169, r24
5ee: 78 94 sei
strcpy_P(&Buff[6], PSTR(".log"));
if (f_open(&file1, Buff, FA_OPEN_ALWAYS | FA_WRITE) || f_lseek(&file1, file1.fsize)) { err = 4; break; }
 
beep(5, 2); // Two beeps. Start logging.
err = 0;
while ((b = get_line()) > 0) {
5f0: 0e 94 04 01 call 0x208 ; 0x208 <get_line>
5f4: 18 2f mov r17, r24
5f6: 88 23 and r24, r24
5f8: 09 f0 breq .+2 ; 0x5fc <__stack+0xfd>
5fa: 95 cf rjmp .-214 ; 0x526 <__stack+0x27>
5fc: 0f c0 rjmp .+30 ; 0x61c <__stack+0x11d>
5fe: 65 e0 ldi r22, 0x05 ; 5
600: 06 c0 rjmp .+12 ; 0x60e <__stack+0x10f>
uart_stop();
GPS_OFF();
if (f_close(&file1)) { err = 7; break; };
 
// When a long beep is sounded, the shutdoun process has been succeeded.
beep(50, 1);
602: 61 e0 ldi r22, 0x01 ; 1
604: 82 e3 ldi r24, 0x32 ; 50
606: 0e 94 47 01 call 0x28e ; 0x28e <beep>
60a: fe ce rjmp .-516 ; 0x408 <main+0x94>
60c: 64 e0 ldi r22, 0x04 ; 4
 
 
static
void uart_stop (void)
{
UCSR0B = 0;
60e: 10 92 c1 00 sts 0x00C1, r1
beep(50, 1);
}
 
// Unrecoverble error. Enter shutdown state.
uart_stop();
GPS_OFF();
612: 29 98 cbi 0x05, 1 ; 5
beep(25, err);
614: 89 e1 ldi r24, 0x19 ; 25
616: 0e 94 47 01 call 0x28e ; 0x28e <beep>
61a: ff cf rjmp .-2 ; 0x61a <__stack+0x11b>
 
 
static
void uart_stop (void)
{
UCSR0B = 0;
61c: 10 92 c1 00 sts 0x00C1, r1
}
if (err) break;
 
// Turn-off GPS power and close the log file by power supply is discharged.
uart_stop();
GPS_OFF();
620: 29 98 cbi 0x05, 1 ; 5
if (f_close(&file1)) { err = 7; break; };
622: c5 01 movw r24, r10
624: 0e 94 b4 06 call 0xd68 ; 0xd68 <f_close>
628: 89 2b or r24, r25
62a: 59 f3 breq .-42 ; 0x602 <__stack+0x103>
62c: 67 e0 ldi r22, 0x07 ; 7
62e: ef cf rjmp .-34 ; 0x60e <__stack+0x10f>
 
00000630 <clust2sect>:
 
static
DWORD clust2sect ( /* !=0: sector number, 0: failed - invalid cluster# */
CLUST clust /* Cluster# to be converted */
)
{
630: cf 93 push r28
632: df 93 push r29
FATFS *fs = FatFs;
634: c0 91 0a 01 lds r28, 0x010A
638: d0 91 0b 01 lds r29, 0x010B
 
 
clust -= 2;
63c: bc 01 movw r22, r24
63e: 62 50 subi r22, 0x02 ; 2
640: 70 40 sbci r23, 0x00 ; 0
if (clust >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */
642: 8e 89 ldd r24, Y+22 ; 0x16
644: 9f 89 ldd r25, Y+23 ; 0x17
646: 02 97 sbiw r24, 0x02 ; 2
648: 68 17 cp r22, r24
64a: 79 07 cpc r23, r25
64c: 28 f0 brcs .+10 ; 0x658 <clust2sect+0x28>
64e: 20 e0 ldi r18, 0x00 ; 0
650: 30 e0 ldi r19, 0x00 ; 0
652: 40 e0 ldi r20, 0x00 ; 0
654: 50 e0 ldi r21, 0x00 ; 0
656: 12 c0 rjmp .+36 ; 0x67c <clust2sect+0x4c>
return (DWORD)clust * fs->sects_clust + fs->database;
658: 88 27 eor r24, r24
65a: 99 27 eor r25, r25
65c: 2d 8d ldd r18, Y+29 ; 0x1d
65e: 33 27 eor r19, r19
660: 44 27 eor r20, r20
662: 55 27 eor r21, r21
664: 0e 94 e9 10 call 0x21d2 ; 0x21d2 <__mulsi3>
668: 9b 01 movw r18, r22
66a: ac 01 movw r20, r24
66c: 88 89 ldd r24, Y+16 ; 0x10
66e: 99 89 ldd r25, Y+17 ; 0x11
670: aa 89 ldd r26, Y+18 ; 0x12
672: bb 89 ldd r27, Y+19 ; 0x13
674: 28 0f add r18, r24
676: 39 1f adc r19, r25
678: 4a 1f adc r20, r26
67a: 5b 1f adc r21, r27
}
67c: ca 01 movw r24, r20
67e: b9 01 movw r22, r18
680: df 91 pop r29
682: cf 91 pop r28
684: 08 95 ret
 
00000686 <validate>:
static
FRESULT validate ( /* FR_OK(0): The id is valid, !=0: Not valid */
const FATFS *fs, /* Pointer to the file system object */
WORD id /* id member of the target object to be checked */
)
{
686: fc 01 movw r30, r24
if (!fs || fs->id != id)
688: 89 2b or r24, r25
68a: 61 f0 breq .+24 ; 0x6a4 <validate+0x1e>
68c: 80 81 ld r24, Z
68e: 91 81 ldd r25, Z+1 ; 0x01
690: 86 17 cp r24, r22
692: 97 07 cpc r25, r23
694: 39 f4 brne .+14 ; 0x6a4 <validate+0x1e>
return FR_INVALID_OBJECT;
if (disk_status(0) & STA_NOINIT)
696: 80 e0 ldi r24, 0x00 ; 0
698: 0e 94 bf 0d call 0x1b7e ; 0x1b7e <disk_status>
69c: 99 27 eor r25, r25
69e: 81 70 andi r24, 0x01 ; 1
6a0: 90 70 andi r25, 0x00 ; 0
6a2: 08 95 ret
6a4: 8c e0 ldi r24, 0x0C ; 12
6a6: 90 e0 ldi r25, 0x00 ; 0
return FR_NOT_READY;
 
return FR_OK;
}
6a8: 08 95 ret
 
000006aa <move_window>:
 
static
BOOL move_window ( /* TRUE: successful, FALSE: failed */
DWORD sector /* Sector number to make apperance in the FatFs->win */
) /* Move to zero only writes back dirty window */
{
6aa: a0 e0 ldi r26, 0x00 ; 0
6ac: b0 e0 ldi r27, 0x00 ; 0
6ae: eb e5 ldi r30, 0x5B ; 91
6b0: f3 e0 ldi r31, 0x03 ; 3
6b2: 0c 94 2e 11 jmp 0x225c ; 0x225c <__prologue_saves__+0x8>
6b6: 4b 01 movw r8, r22
6b8: 5c 01 movw r10, r24
DWORD wsect;
FATFS *fs = FatFs;
6ba: c0 91 0a 01 lds r28, 0x010A
6be: d0 91 0b 01 lds r29, 0x010B
 
 
wsect = fs->winsect;
6c2: cc 80 ldd r12, Y+4 ; 0x04
6c4: dd 80 ldd r13, Y+5 ; 0x05
6c6: ee 80 ldd r14, Y+6 ; 0x06
6c8: ff 80 ldd r15, Y+7 ; 0x07
if (wsect != sector) { /* Changed current window */
6ca: c6 16 cp r12, r22
6cc: d7 06 cpc r13, r23
6ce: e8 06 cpc r14, r24
6d0: f9 06 cpc r15, r25
6d2: 09 f4 brne .+2 ; 0x6d6 <move_window+0x2c>
6d4: 4f c0 rjmp .+158 ; 0x774 <move_window+0xca>
#if !_FS_READONLY
BYTE n;
if (fs->winflag) { /* Write back dirty window if needed */
6d6: 8f 8d ldd r24, Y+31 ; 0x1f
6d8: 88 23 and r24, r24
6da: a1 f1 breq .+104 ; 0x744 <move_window+0x9a>
if (disk_write(0, fs->win, wsect, 1) != RES_OK)
6dc: 80 e2 ldi r24, 0x20 ; 32
6de: 68 2e mov r6, r24
6e0: 71 2c mov r7, r1
6e2: 6c 0e add r6, r28
6e4: 7d 1e adc r7, r29
6e6: 01 e0 ldi r16, 0x01 ; 1
6e8: a7 01 movw r20, r14
6ea: 96 01 movw r18, r12
6ec: b3 01 movw r22, r6
6ee: 80 e0 ldi r24, 0x00 ; 0
6f0: 0e 94 d3 0e call 0x1da6 ; 0x1da6 <disk_write>
6f4: 89 2b or r24, r25
6f6: d9 f5 brne .+118 ; 0x76e <move_window+0xc4>
return FALSE;
fs->winflag = 0;
6f8: 1f 8e std Y+31, r1 ; 0x1f
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
6fa: 8c 89 ldd r24, Y+20 ; 0x14
6fc: 9d 89 ldd r25, Y+21 ; 0x15
6fe: aa 27 eor r26, r26
700: bb 27 eor r27, r27
702: 28 85 ldd r18, Y+8 ; 0x08
704: 39 85 ldd r19, Y+9 ; 0x09
706: 4a 85 ldd r20, Y+10 ; 0x0a
708: 5b 85 ldd r21, Y+11 ; 0x0b
70a: 82 0f add r24, r18
70c: 93 1f adc r25, r19
70e: a4 1f adc r26, r20
710: b5 1f adc r27, r21
712: c8 16 cp r12, r24
714: d9 06 cpc r13, r25
716: ea 06 cpc r14, r26
718: fb 06 cpc r15, r27
71a: a0 f4 brcc .+40 ; 0x744 <move_window+0x9a>
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
71c: 1e 8d ldd r17, Y+30 ; 0x1e
71e: 10 c0 rjmp .+32 ; 0x740 <move_window+0x96>
wsect += fs->sects_fat;
720: 8c 89 ldd r24, Y+20 ; 0x14
722: 9d 89 ldd r25, Y+21 ; 0x15
724: aa 27 eor r26, r26
726: bb 27 eor r27, r27
728: c8 0e add r12, r24
72a: d9 1e adc r13, r25
72c: ea 1e adc r14, r26
72e: fb 1e adc r15, r27
disk_write(0, fs->win, wsect, 1);
730: 01 e0 ldi r16, 0x01 ; 1
732: a7 01 movw r20, r14
734: 96 01 movw r18, r12
736: b3 01 movw r22, r6
738: 80 e0 ldi r24, 0x00 ; 0
73a: 0e 94 d3 0e call 0x1da6 ; 0x1da6 <disk_write>
if (fs->winflag) { /* Write back dirty window if needed */
if (disk_write(0, fs->win, wsect, 1) != RES_OK)
return FALSE;
fs->winflag = 0;
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
73e: 11 50 subi r17, 0x01 ; 1
740: 12 30 cpi r17, 0x02 ; 2
742: 70 f7 brcc .-36 ; 0x720 <move_window+0x76>
disk_write(0, fs->win, wsect, 1);
}
}
}
#endif
if (sector) {
744: 81 14 cp r8, r1
746: 91 04 cpc r9, r1
748: a1 04 cpc r10, r1
74a: b1 04 cpc r11, r1
74c: 99 f0 breq .+38 ; 0x774 <move_window+0xca>
if (disk_read(0, fs->win, sector, 1) != RES_OK)
74e: be 01 movw r22, r28
750: 60 5e subi r22, 0xE0 ; 224
752: 7f 4f sbci r23, 0xFF ; 255
754: 01 e0 ldi r16, 0x01 ; 1
756: a5 01 movw r20, r10
758: 94 01 movw r18, r8
75a: 80 e0 ldi r24, 0x00 ; 0
75c: 0e 94 51 0f call 0x1ea2 ; 0x1ea2 <disk_read>
760: 89 2b or r24, r25
762: 29 f4 brne .+10 ; 0x76e <move_window+0xc4>
return FALSE;
fs->winsect = sector;
764: 8c 82 std Y+4, r8 ; 0x04
766: 9d 82 std Y+5, r9 ; 0x05
768: ae 82 std Y+6, r10 ; 0x06
76a: bf 82 std Y+7, r11 ; 0x07
76c: 03 c0 rjmp .+6 ; 0x774 <move_window+0xca>
76e: 80 e0 ldi r24, 0x00 ; 0
770: 90 e0 ldi r25, 0x00 ; 0
772: 02 c0 rjmp .+4 ; 0x778 <move_window+0xce>
774: 81 e0 ldi r24, 0x01 ; 1
776: 90 e0 ldi r25, 0x00 ; 0
778: ee e0 ldi r30, 0x0E ; 14
77a: cd b7 in r28, 0x3d ; 61
77c: de b7 in r29, 0x3e ; 62
77e: 0c 94 4a 11 jmp 0x2294 ; 0x2294 <__epilogue_restores__+0x8>
 
00000782 <put_cluster>:
static
BOOL put_cluster ( /* TRUE: successful, FALSE: failed */
CLUST clust, /* Cluster# to change */
CLUST val /* New value to mark the cluster */
)
{
782: a0 e0 ldi r26, 0x00 ; 0
784: b0 e0 ldi r27, 0x00 ; 0
786: e7 ec ldi r30, 0xC7 ; 199
788: f3 e0 ldi r31, 0x03 ; 3
78a: 0c 94 2d 11 jmp 0x225a ; 0x225a <__prologue_saves__+0x6>
78e: ec 01 movw r28, r24
790: 5b 01 movw r10, r22
WORD bc;
BYTE *p;
DWORD fatsect;
FATFS *fs = FatFs;
792: 80 90 0a 01 lds r8, 0x010A
796: 90 90 0b 01 lds r9, 0x010B
 
 
fatsect = fs->fatbase;
79a: f4 01 movw r30, r8
79c: c0 84 ldd r12, Z+8 ; 0x08
79e: d1 84 ldd r13, Z+9 ; 0x09
7a0: e2 84 ldd r14, Z+10 ; 0x0a
7a2: f3 84 ldd r15, Z+11 ; 0x0b
switch (fs->fs_type) {
7a4: 84 8d ldd r24, Z+28 ; 0x1c
7a6: 81 30 cpi r24, 0x01 ; 1
7a8: 21 f0 breq .+8 ; 0x7b2 <put_cluster+0x30>
7aa: 82 30 cpi r24, 0x02 ; 2
7ac: 09 f0 breq .+2 ; 0x7b0 <put_cluster+0x2e>
7ae: 70 c0 rjmp .+224 ; 0x890 <put_cluster+0x10e>
7b0: 56 c0 rjmp .+172 ; 0x85e <put_cluster+0xdc>
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
7b2: 8e 01 movw r16, r28
7b4: 00 0f add r16, r16
7b6: 11 1f adc r17, r17
7b8: 0c 0f add r16, r28
7ba: 1d 1f adc r17, r29
7bc: 16 95 lsr r17
7be: 07 95 ror r16
if (!move_window(fatsect + bc / 512)) return FALSE;
7c0: b8 01 movw r22, r16
7c2: 67 2f mov r22, r23
7c4: 77 27 eor r23, r23
7c6: 66 95 lsr r22
7c8: 88 27 eor r24, r24
7ca: 99 27 eor r25, r25
7cc: 6c 0d add r22, r12
7ce: 7d 1d adc r23, r13
7d0: 8e 1d adc r24, r14
7d2: 9f 1d adc r25, r15
7d4: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
7d8: 88 23 and r24, r24
7da: 09 f4 brne .+2 ; 0x7de <put_cluster+0x5c>
7dc: 59 c0 rjmp .+178 ; 0x890 <put_cluster+0x10e>
p = &fs->win[bc % 512];
7de: 60 e2 ldi r22, 0x20 ; 32
7e0: 66 2e mov r6, r22
7e2: 71 2c mov r7, r1
7e4: 68 0c add r6, r8
7e6: 79 1c adc r7, r9
7e8: f8 01 movw r30, r16
7ea: f1 70 andi r31, 0x01 ; 1
7ec: e6 0d add r30, r6
7ee: f7 1d adc r31, r7
*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
7f0: ce 01 movw r24, r28
7f2: 81 70 andi r24, 0x01 ; 1
7f4: 90 70 andi r25, 0x00 ; 0
7f6: 58 2e mov r5, r24
7f8: 88 23 and r24, r24
7fa: 39 f0 breq .+14 ; 0x80a <put_cluster+0x88>
7fc: 80 81 ld r24, Z
7fe: 8f 70 andi r24, 0x0F ; 15
800: 9a 2d mov r25, r10
802: 92 95 swap r25
804: 90 7f andi r25, 0xF0 ; 240
806: 98 2b or r25, r24
808: 01 c0 rjmp .+2 ; 0x80c <put_cluster+0x8a>
80a: 9a 2d mov r25, r10
80c: 90 83 st Z, r25
bc++;
80e: e8 01 movw r28, r16
810: 21 96 adiw r28, 0x01 ; 1
fs->winflag = 1;
812: 81 e0 ldi r24, 0x01 ; 1
814: f4 01 movw r30, r8
816: 87 8f std Z+31, r24 ; 0x1f
if (!move_window(fatsect + bc / 512)) return FALSE;
818: be 01 movw r22, r28
81a: 67 2f mov r22, r23
81c: 77 27 eor r23, r23
81e: 66 95 lsr r22
820: 88 27 eor r24, r24
822: 99 27 eor r25, r25
824: 6c 0d add r22, r12
826: 7d 1d adc r23, r13
828: 8e 1d adc r24, r14
82a: 9f 1d adc r25, r15
82c: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
830: 88 23 and r24, r24
832: 71 f1 breq .+92 ; 0x890 <put_cluster+0x10e>
p = &fs->win[bc % 512];
834: fe 01 movw r30, r28
836: f1 70 andi r31, 0x01 ; 1
838: e6 0d add r30, r6
83a: f7 1d adc r31, r7
*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
83c: 55 20 and r5, r5
83e: 39 f0 breq .+14 ; 0x84e <put_cluster+0xcc>
840: 44 e0 ldi r20, 0x04 ; 4
842: b6 94 lsr r11
844: a7 94 ror r10
846: 4a 95 dec r20
848: e1 f7 brne .-8 ; 0x842 <put_cluster+0xc0>
84a: 2a 2d mov r18, r10
84c: 06 c0 rjmp .+12 ; 0x85a <put_cluster+0xd8>
84e: 20 81 ld r18, Z
850: 20 7f andi r18, 0xF0 ; 240
852: 8b 2d mov r24, r11
854: 99 27 eor r25, r25
856: 8f 70 andi r24, 0x0F ; 15
858: 28 2b or r18, r24
85a: 20 83 st Z, r18
85c: 13 c0 rjmp .+38 ; 0x884 <put_cluster+0x102>
break;
 
case FS_FAT16 :
if (!move_window(fatsect + clust / 256)) return FALSE;
85e: 6d 2f mov r22, r29
860: 77 27 eor r23, r23
862: 88 27 eor r24, r24
864: 99 27 eor r25, r25
866: 6c 0d add r22, r12
868: 7d 1d adc r23, r13
86a: 8e 1d adc r24, r14
86c: 9f 1d adc r25, r15
86e: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
872: 88 23 and r24, r24
874: 69 f0 breq .+26 ; 0x890 <put_cluster+0x10e>
ST_WORD(&fs->win[((WORD)clust * 2) % 512], (WORD)val);
876: cc 0f add r28, r28
878: dd 1f adc r29, r29
87a: d1 70 andi r29, 0x01 ; 1
87c: c8 0d add r28, r8
87e: d9 1d adc r29, r9
880: b9 a2 std Y+33, r11 ; 0x21
882: a8 a2 std Y+32, r10 ; 0x20
break;
#endif
default :
return FALSE;
}
fs->winflag = 1;
884: 81 e0 ldi r24, 0x01 ; 1
886: f4 01 movw r30, r8
888: 87 8f std Z+31, r24 ; 0x1f
88a: 81 e0 ldi r24, 0x01 ; 1
88c: 90 e0 ldi r25, 0x00 ; 0
88e: 02 c0 rjmp .+4 ; 0x894 <put_cluster+0x112>
return TRUE;
890: 80 e0 ldi r24, 0x00 ; 0
892: 90 e0 ldi r25, 0x00 ; 0
894: ef e0 ldi r30, 0x0F ; 15
896: cd b7 in r28, 0x3d ; 61
898: de b7 in r29, 0x3e ; 62
89a: 0c 94 49 11 jmp 0x2292 ; 0x2292 <__epilogue_restores__+0x6>
 
0000089e <get_cluster>:
 
static
CLUST get_cluster ( /* 0,>=2: successful, 1: failed */
CLUST clust /* Cluster# to get the link information */
)
{
89e: a0 e0 ldi r26, 0x00 ; 0
8a0: b0 e0 ldi r27, 0x00 ; 0
8a2: e5 e5 ldi r30, 0x55 ; 85
8a4: f4 e0 ldi r31, 0x04 ; 4
8a6: 0c 94 31 11 jmp 0x2262 ; 0x2262 <__prologue_saves__+0xe>
8aa: 8c 01 movw r16, r24
WORD wc, bc;
DWORD fatsect;
FATFS *fs = FatFs;
8ac: e0 90 0a 01 lds r14, 0x010A
8b0: f0 90 0b 01 lds r15, 0x010B
 
 
if (clust >= 2 && clust < fs->max_clust) { /* Valid cluster# */
8b4: 02 97 sbiw r24, 0x02 ; 2
8b6: 08 f4 brcc .+2 ; 0x8ba <get_cluster+0x1c>
8b8: 67 c0 rjmp .+206 ; 0x988 <get_cluster+0xea>
8ba: f7 01 movw r30, r14
8bc: 86 89 ldd r24, Z+22 ; 0x16
8be: 97 89 ldd r25, Z+23 ; 0x17
8c0: 08 17 cp r16, r24
8c2: 19 07 cpc r17, r25
8c4: 08 f0 brcs .+2 ; 0x8c8 <get_cluster+0x2a>
8c6: 60 c0 rjmp .+192 ; 0x988 <get_cluster+0xea>
fatsect = fs->fatbase;
8c8: a0 84 ldd r10, Z+8 ; 0x08
8ca: b1 84 ldd r11, Z+9 ; 0x09
8cc: c2 84 ldd r12, Z+10 ; 0x0a
8ce: d3 84 ldd r13, Z+11 ; 0x0b
switch (fs->fs_type) {
8d0: 84 8d ldd r24, Z+28 ; 0x1c
8d2: 81 30 cpi r24, 0x01 ; 1
8d4: 21 f0 breq .+8 ; 0x8de <get_cluster+0x40>
8d6: 82 30 cpi r24, 0x02 ; 2
8d8: 09 f0 breq .+2 ; 0x8dc <get_cluster+0x3e>
8da: 56 c0 rjmp .+172 ; 0x988 <get_cluster+0xea>
8dc: 40 c0 rjmp .+128 ; 0x95e <get_cluster+0xc0>
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
8de: e8 01 movw r28, r16
8e0: cc 0f add r28, r28
8e2: dd 1f adc r29, r29
8e4: c0 0f add r28, r16
8e6: d1 1f adc r29, r17
8e8: d6 95 lsr r29
8ea: c7 95 ror r28
if (!move_window(fatsect + bc / 512)) break;
8ec: be 01 movw r22, r28
8ee: 67 2f mov r22, r23
8f0: 77 27 eor r23, r23
8f2: 66 95 lsr r22
8f4: 88 27 eor r24, r24
8f6: 99 27 eor r25, r25
8f8: 6a 0d add r22, r10
8fa: 7b 1d adc r23, r11
8fc: 8c 1d adc r24, r12
8fe: 9d 1d adc r25, r13
900: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
904: 88 23 and r24, r24
906: 09 f4 brne .+2 ; 0x90a <get_cluster+0x6c>
908: 3f c0 rjmp .+126 ; 0x988 <get_cluster+0xea>
wc = fs->win[bc % 512]; bc++;
90a: fe 01 movw r30, r28
90c: f1 70 andi r31, 0x01 ; 1
90e: ee 0d add r30, r14
910: ff 1d adc r31, r15
912: 90 a0 ldd r9, Z+32 ; 0x20
914: 21 96 adiw r28, 0x01 ; 1
if (!move_window(fatsect + bc / 512)) break;
916: be 01 movw r22, r28
918: 67 2f mov r22, r23
91a: 77 27 eor r23, r23
91c: 66 95 lsr r22
91e: 88 27 eor r24, r24
920: 99 27 eor r25, r25
922: 6a 0d add r22, r10
924: 7b 1d adc r23, r11
926: 8c 1d adc r24, r12
928: 9d 1d adc r25, r13
92a: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
92e: 88 23 and r24, r24
930: 59 f1 breq .+86 ; 0x988 <get_cluster+0xea>
fatsect = fs->fatbase;
switch (fs->fs_type) {
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fatsect + bc / 512)) break;
wc = fs->win[bc % 512]; bc++;
932: 29 2d mov r18, r9
934: 33 27 eor r19, r19
if (!move_window(fatsect + bc / 512)) break;
wc |= (WORD)fs->win[bc % 512] << 8;
936: d1 70 andi r29, 0x01 ; 1
938: ec 0e add r14, r28
93a: fd 1e adc r15, r29
93c: f7 01 movw r30, r14
93e: 80 a1 ldd r24, Z+32 ; 0x20
940: 99 27 eor r25, r25
942: 98 2f mov r25, r24
944: 88 27 eor r24, r24
946: 82 2b or r24, r18
948: 93 2b or r25, r19
return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
94a: 00 ff sbrs r16, 0
94c: 06 c0 rjmp .+12 ; 0x95a <get_cluster+0xbc>
94e: 24 e0 ldi r18, 0x04 ; 4
950: 96 95 lsr r25
952: 87 95 ror r24
954: 2a 95 dec r18
956: e1 f7 brne .-8 ; 0x950 <get_cluster+0xb2>
958: 19 c0 rjmp .+50 ; 0x98c <get_cluster+0xee>
95a: 9f 70 andi r25, 0x0F ; 15
95c: 17 c0 rjmp .+46 ; 0x98c <get_cluster+0xee>
 
case FS_FAT16 :
if (!move_window(fatsect + clust / 256)) break;
95e: 61 2f mov r22, r17
960: 77 27 eor r23, r23
962: 88 27 eor r24, r24
964: 99 27 eor r25, r25
966: 6a 0d add r22, r10
968: 7b 1d adc r23, r11
96a: 8c 1d adc r24, r12
96c: 9d 1d adc r25, r13
96e: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
972: 88 23 and r24, r24
974: 49 f0 breq .+18 ; 0x988 <get_cluster+0xea>
return LD_WORD(&fs->win[((WORD)clust * 2) % 512]);
976: 00 0f add r16, r16
978: 11 1f adc r17, r17
97a: 11 70 andi r17, 0x01 ; 1
97c: e0 0e add r14, r16
97e: f1 1e adc r15, r17
980: f7 01 movw r30, r14
982: 80 a1 ldd r24, Z+32 ; 0x20
984: 91 a1 ldd r25, Z+33 ; 0x21
986: 02 c0 rjmp .+4 ; 0x98c <get_cluster+0xee>
988: 81 e0 ldi r24, 0x01 ; 1
98a: 90 e0 ldi r25, 0x00 ; 0
98c: eb e0 ldi r30, 0x0B ; 11
98e: cd b7 in r28, 0x3d ; 61
990: de b7 in r29, 0x3e ; 62
992: 0c 94 4d 11 jmp 0x229a ; 0x229a <__epilogue_restores__+0xe>
 
00000996 <next_dir_entry>:
 
static
BOOL next_dir_entry ( /* TRUE: successful, FALSE: could not move next */
DIR *dirobj /* Pointer to directory object */
)
{
996: ef 92 push r14
998: ff 92 push r15
99a: 0f 93 push r16
99c: 1f 93 push r17
99e: cf 93 push r28
9a0: df 93 push r29
9a2: ec 01 movw r28, r24
CLUST clust;
WORD idx;
FATFS *fs = FatFs;
9a4: e0 90 0a 01 lds r14, 0x010A
9a8: f0 90 0b 01 lds r15, 0x010B
 
 
idx = dirobj->index + 1;
9ac: 0a 81 ldd r16, Y+2 ; 0x02
9ae: 1b 81 ldd r17, Y+3 ; 0x03
9b0: 0f 5f subi r16, 0xFF ; 255
9b2: 1f 4f sbci r17, 0xFF ; 255
if ((idx & 15) == 0) { /* Table sector changed? */
9b4: c8 01 movw r24, r16
9b6: 8f 70 andi r24, 0x0F ; 15
9b8: 90 70 andi r25, 0x00 ; 0
9ba: 89 2b or r24, r25
9bc: d1 f5 brne .+116 ; 0xa32 <next_dir_entry+0x9c>
dirobj->sect++; /* Next sector */
9be: 8a 85 ldd r24, Y+10 ; 0x0a
9c0: 9b 85 ldd r25, Y+11 ; 0x0b
9c2: ac 85 ldd r26, Y+12 ; 0x0c
9c4: bd 85 ldd r27, Y+13 ; 0x0d
9c6: 01 96 adiw r24, 0x01 ; 1
9c8: a1 1d adc r26, r1
9ca: b1 1d adc r27, r1
9cc: 8a 87 std Y+10, r24 ; 0x0a
9ce: 9b 87 std Y+11, r25 ; 0x0b
9d0: ac 87 std Y+12, r26 ; 0x0c
9d2: bd 87 std Y+13, r27 ; 0x0d
if (!dirobj->clust) { /* In static table */
9d4: 48 85 ldd r20, Y+8 ; 0x08
9d6: 59 85 ldd r21, Y+9 ; 0x09
9d8: 41 15 cp r20, r1
9da: 51 05 cpc r21, r1
9dc: 39 f4 brne .+14 ; 0x9ec <next_dir_entry+0x56>
if (idx >= fs->n_rootdir) return FALSE; /* Reached to end of table */
9de: f7 01 movw r30, r14
9e0: 82 81 ldd r24, Z+2 ; 0x02
9e2: 93 81 ldd r25, Z+3 ; 0x03
9e4: 08 17 cp r16, r24
9e6: 19 07 cpc r17, r25
9e8: 20 f1 brcs .+72 ; 0xa32 <next_dir_entry+0x9c>
9ea: 28 c0 rjmp .+80 ; 0xa3c <next_dir_entry+0xa6>
} else { /* In dynamic table */
if (((idx / 16) & (fs->sects_clust - 1)) == 0) { /* Cluster changed? */
9ec: f7 01 movw r30, r14
9ee: 85 8d ldd r24, Z+29 ; 0x1d
9f0: 99 27 eor r25, r25
9f2: 01 97 sbiw r24, 0x01 ; 1
9f4: 98 01 movw r18, r16
9f6: b4 e0 ldi r27, 0x04 ; 4
9f8: 36 95 lsr r19
9fa: 27 95 ror r18
9fc: ba 95 dec r27
9fe: e1 f7 brne .-8 ; 0x9f8 <next_dir_entry+0x62>
a00: 82 23 and r24, r18
a02: 93 23 and r25, r19
a04: 89 2b or r24, r25
a06: a9 f4 brne .+42 ; 0xa32 <next_dir_entry+0x9c>
clust = get_cluster(dirobj->clust); /* Get next cluster */
a08: ca 01 movw r24, r20
a0a: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
a0e: 9c 01 movw r18, r24
if (clust < 2 || clust >= fs->max_clust) /* Reached to end of table */
a10: 02 97 sbiw r24, 0x02 ; 2
a12: a0 f0 brcs .+40 ; 0xa3c <next_dir_entry+0xa6>
a14: f7 01 movw r30, r14
a16: 86 89 ldd r24, Z+22 ; 0x16
a18: 97 89 ldd r25, Z+23 ; 0x17
a1a: 28 17 cp r18, r24
a1c: 39 07 cpc r19, r25
a1e: 70 f4 brcc .+28 ; 0xa3c <next_dir_entry+0xa6>
return FALSE;
dirobj->clust = clust; /* Initialize for new cluster */
a20: 39 87 std Y+9, r19 ; 0x09
a22: 28 87 std Y+8, r18 ; 0x08
dirobj->sect = clust2sect(clust);
a24: c9 01 movw r24, r18
a26: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
a2a: 6a 87 std Y+10, r22 ; 0x0a
a2c: 7b 87 std Y+11, r23 ; 0x0b
a2e: 8c 87 std Y+12, r24 ; 0x0c
a30: 9d 87 std Y+13, r25 ; 0x0d
}
}
}
dirobj->index = idx; /* Lower 4 bit of dirobj->index indicates offset in dirobj->sect */
a32: 1b 83 std Y+3, r17 ; 0x03
a34: 0a 83 std Y+2, r16 ; 0x02
a36: 81 e0 ldi r24, 0x01 ; 1
a38: 90 e0 ldi r25, 0x00 ; 0
a3a: 02 c0 rjmp .+4 ; 0xa40 <next_dir_entry+0xaa>
return TRUE;
a3c: 80 e0 ldi r24, 0x00 ; 0
a3e: 90 e0 ldi r25, 0x00 ; 0
a40: e6 e0 ldi r30, 0x06 ; 6
a42: cd b7 in r28, 0x3d ; 61
a44: de b7 in r29, 0x3e ; 62
a46: 0c 94 52 11 jmp 0x22a4 ; 0x22a4 <__epilogue_restores__+0x18>
 
00000a4a <create_chain>:
#if !_FS_READONLY
static
CLUST create_chain ( /* 0: no free cluster, 1: error, >=2: new cluster number */
CLUST clust /* Cluster# to stretch, 0 means create new */
)
{
a4a: a0 e0 ldi r26, 0x00 ; 0
a4c: b0 e0 ldi r27, 0x00 ; 0
a4e: eb e2 ldi r30, 0x2B ; 43
a50: f5 e0 ldi r31, 0x05 ; 5
a52: 0c 94 32 11 jmp 0x2264 ; 0x2264 <__prologue_saves__+0x10>
a56: 7c 01 movw r14, r24
CLUST cstat, ncl, scl, mcl;
FATFS *fs = FatFs;
a58: a0 90 0a 01 lds r10, 0x010A
a5c: b0 90 0b 01 lds r11, 0x010B
 
 
mcl = fs->max_clust;
a60: f5 01 movw r30, r10
a62: c6 88 ldd r12, Z+22 ; 0x16
a64: d7 88 ldd r13, Z+23 ; 0x17
if (clust == 0) { /* Create new chain */
a66: 00 97 sbiw r24, 0x00 ; 0
a68: 49 f4 brne .+18 ; 0xa7c <create_chain+0x32>
scl = fs->last_clust; /* Get last allocated cluster */
a6a: 00 8d ldd r16, Z+24 ; 0x18
a6c: 11 8d ldd r17, Z+25 ; 0x19
if (scl < 2 || scl >= mcl) scl = 1;
a6e: 02 30 cpi r16, 0x02 ; 2
a70: 11 05 cpc r17, r1
a72: 80 f0 brcs .+32 ; 0xa94 <create_chain+0x4a>
a74: 0c 15 cp r16, r12
a76: 1d 05 cpc r17, r13
a78: 68 f4 brcc .+26 ; 0xa94 <create_chain+0x4a>
a7a: 0e c0 rjmp .+28 ; 0xa98 <create_chain+0x4e>
}
else { /* Stretch existing chain */
cstat = get_cluster(clust); /* Check the cluster status */
a7c: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
if (cstat < 2) return 1; /* It is an invalid cluster */
a80: 82 30 cpi r24, 0x02 ; 2
a82: 91 05 cpc r25, r1
a84: e8 f1 brcs .+122 ; 0xb00 <create_chain+0xb6>
if (cstat < mcl) return cstat; /* It is already followed by next cluster */
a86: 8c 15 cp r24, r12
a88: 9d 05 cpc r25, r13
a8a: 10 f4 brcc .+4 ; 0xa90 <create_chain+0x46>
a8c: bc 01 movw r22, r24
a8e: 3d c0 rjmp .+122 ; 0xb0a <create_chain+0xc0>
a90: 87 01 movw r16, r14
a92: 02 c0 rjmp .+4 ; 0xa98 <create_chain+0x4e>
a94: 01 e0 ldi r16, 0x01 ; 1
a96: 10 e0 ldi r17, 0x00 ; 0
a98: e8 01 movw r28, r16
scl = clust;
}
 
ncl = scl; /* Start cluster */
for (;;) {
ncl++; /* Next cluster */
a9a: 21 96 adiw r28, 0x01 ; 1
if (ncl >= mcl) { /* Wrap around */
a9c: cc 15 cp r28, r12
a9e: dd 05 cpc r29, r13
aa0: 28 f0 brcs .+10 ; 0xaac <create_chain+0x62>
ncl = 2;
if (ncl > scl) return 0; /* No free custer */
aa2: 02 30 cpi r16, 0x02 ; 2
aa4: 11 05 cpc r17, r1
aa6: 78 f1 brcs .+94 ; 0xb06 <create_chain+0xbc>
aa8: c2 e0 ldi r28, 0x02 ; 2
aaa: d0 e0 ldi r29, 0x00 ; 0
}
cstat = get_cluster(ncl); /* Get the cluster status */
aac: ce 01 movw r24, r28
aae: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
if (cstat == 0) break; /* Found a free cluster */
ab2: 00 97 sbiw r24, 0x00 ; 0
ab4: 31 f0 breq .+12 ; 0xac2 <create_chain+0x78>
if (cstat == 1) return 1; /* Any error occured */
ab6: 01 97 sbiw r24, 0x01 ; 1
ab8: 19 f1 breq .+70 ; 0xb00 <create_chain+0xb6>
if (ncl == scl) return 0; /* No free custer */
aba: c0 17 cp r28, r16
abc: d1 07 cpc r29, r17
abe: 19 f1 breq .+70 ; 0xb06 <create_chain+0xbc>
ac0: ec cf rjmp .-40 ; 0xa9a <create_chain+0x50>
}
 
if (!put_cluster(ncl, (CLUST)0x0FFFFFFF)) return 1; /* Mark the new cluster "in use" */
ac2: 6f ef ldi r22, 0xFF ; 255
ac4: 7f ef ldi r23, 0xFF ; 255
ac6: ce 01 movw r24, r28
ac8: 0e 94 c1 03 call 0x782 ; 0x782 <put_cluster>
acc: 88 23 and r24, r24
ace: c1 f0 breq .+48 ; 0xb00 <create_chain+0xb6>
if (clust && !put_cluster(clust, ncl)) return 1; /* Link it to previous one if needed */
ad0: e1 14 cp r14, r1
ad2: f1 04 cpc r15, r1
ad4: 31 f0 breq .+12 ; 0xae2 <create_chain+0x98>
ad6: be 01 movw r22, r28
ad8: c7 01 movw r24, r14
ada: 0e 94 c1 03 call 0x782 ; 0x782 <put_cluster>
ade: 88 23 and r24, r24
ae0: 79 f0 breq .+30 ; 0xb00 <create_chain+0xb6>
 
fs->last_clust = ncl; /* Update fsinfo */
ae2: f5 01 movw r30, r10
ae4: d1 8f std Z+25, r29 ; 0x19
ae6: c0 8f std Z+24, r28 ; 0x18
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
ae8: 82 8d ldd r24, Z+26 ; 0x1a
aea: 93 8d ldd r25, Z+27 ; 0x1b
aec: ff ef ldi r31, 0xFF ; 255
aee: 8f 3f cpi r24, 0xFF ; 255
af0: 9f 07 cpc r25, r31
af2: 21 f0 breq .+8 ; 0xafc <create_chain+0xb2>
fs->free_clust--;
af4: 01 97 sbiw r24, 0x01 ; 1
af6: f5 01 movw r30, r10
af8: 93 8f std Z+27, r25 ; 0x1b
afa: 82 8f std Z+26, r24 ; 0x1a
afc: be 01 movw r22, r28
afe: 05 c0 rjmp .+10 ; 0xb0a <create_chain+0xc0>
b00: 61 e0 ldi r22, 0x01 ; 1
b02: 70 e0 ldi r23, 0x00 ; 0
b04: 02 c0 rjmp .+4 ; 0xb0a <create_chain+0xc0>
b06: 60 e0 ldi r22, 0x00 ; 0
b08: 70 e0 ldi r23, 0x00 ; 0
fs->fsi_flag = 1;
#endif
}
 
return ncl; /* Return new cluster number */
}
b0a: cb 01 movw r24, r22
b0c: ea e0 ldi r30, 0x0A ; 10
b0e: cd b7 in r28, 0x3d ; 61
b10: de b7 in r29, 0x3e ; 62
b12: 0c 94 4e 11 jmp 0x229c ; 0x229c <__epilogue_restores__+0x10>
 
00000b16 <f_lseek>:
 
FRESULT f_lseek (
FIL *fp, /* Pointer to the file object */
DWORD ofs /* File pointer from top of file */
)
{
b16: a0 e0 ldi r26, 0x00 ; 0
b18: b0 e0 ldi r27, 0x00 ; 0
b1a: e1 e9 ldi r30, 0x91 ; 145
b1c: f5 e0 ldi r31, 0x05 ; 5
b1e: 0c 94 2a 11 jmp 0x2254 ; 0x2254 <__prologue_saves__>
b22: ec 01 movw r28, r24
b24: 3a 01 movw r6, r20
b26: 4b 01 movw r8, r22
CLUST clust;
DWORD csize;
BYTE csect;
FRESULT res;
FATFS *fs = fp->fs;
b28: 4c 80 ldd r4, Y+4 ; 0x04
b2a: 5d 80 ldd r5, Y+5 ; 0x05
 
 
res = validate(fs, fp->id); /* Check validity of the object */
b2c: 68 81 ld r22, Y
b2e: 79 81 ldd r23, Y+1 ; 0x01
b30: c2 01 movw r24, r4
b32: 0e 94 43 03 call 0x686 ; 0x686 <validate>
b36: 1c 01 movw r2, r24
if (res) return res;
b38: 89 2b or r24, r25
b3a: 09 f0 breq .+2 ; 0xb3e <f_lseek+0x28>
b3c: b8 c0 rjmp .+368 ; 0xcae <f_lseek+0x198>
 
if (fp->flag & FA__ERROR) return FR_RW_ERROR;
b3e: 2a 81 ldd r18, Y+2 ; 0x02
b40: 22 23 and r18, r18
b42: 0c f4 brge .+2 ; 0xb46 <f_lseek+0x30>
b44: b1 c0 rjmp .+354 ; 0xca8 <f_lseek+0x192>
#if !_FS_READONLY
if (ofs > fp->fsize && !(fp->flag & FA_WRITE))
b46: 8a 85 ldd r24, Y+10 ; 0x0a
b48: 9b 85 ldd r25, Y+11 ; 0x0b
b4a: ac 85 ldd r26, Y+12 ; 0x0c
b4c: bd 85 ldd r27, Y+13 ; 0x0d
b4e: 86 15 cp r24, r6
b50: 97 05 cpc r25, r7
b52: a8 05 cpc r26, r8
b54: b9 05 cpc r27, r9
b56: 20 f4 brcc .+8 ; 0xb60 <f_lseek+0x4a>
b58: 21 fd sbrc r18, 1
b5a: 02 c0 rjmp .+4 ; 0xb60 <f_lseek+0x4a>
b5c: 3c 01 movw r6, r24
b5e: 4d 01 movw r8, r26
#else
if (ofs > fp->fsize)
#endif
ofs = fp->fsize;
fp->fptr = 0; fp->sect_clust = 1; /* Set file R/W pointer to top of the file */
b60: 1e 82 std Y+6, r1 ; 0x06
b62: 1f 82 std Y+7, r1 ; 0x07
b64: 18 86 std Y+8, r1 ; 0x08
b66: 19 86 std Y+9, r1 ; 0x09
b68: 81 e0 ldi r24, 0x01 ; 1
b6a: 8b 83 std Y+3, r24 ; 0x03
 
/* Move file R/W pointer if needed */
if (ofs) {
b6c: 61 14 cp r6, r1
b6e: 71 04 cpc r7, r1
b70: 81 04 cpc r8, r1
b72: 91 04 cpc r9, r1
b74: 09 f4 brne .+2 ; 0xb78 <f_lseek+0x62>
b76: 7e c0 rjmp .+252 ; 0xc74 <f_lseek+0x15e>
clust = fp->org_clust; /* Get start cluster */
b78: 2e 85 ldd r18, Y+14 ; 0x0e
b7a: 3f 85 ldd r19, Y+15 ; 0x0f
#if !_FS_READONLY
if (!clust) { /* If the file does not have a cluster chain, create new cluster chain */
b7c: 21 15 cp r18, r1
b7e: 31 05 cpc r19, r1
b80: 71 f4 brne .+28 ; 0xb9e <f_lseek+0x88>
clust = create_chain(0);
b82: 80 e0 ldi r24, 0x00 ; 0
b84: 90 e0 ldi r25, 0x00 ; 0
b86: 0e 94 25 05 call 0xa4a ; 0xa4a <create_chain>
b8a: 9c 01 movw r18, r24
if (clust == 1) goto fk_error;
b8c: 81 30 cpi r24, 0x01 ; 1
b8e: 91 05 cpc r25, r1
b90: 09 f4 brne .+2 ; 0xb94 <f_lseek+0x7e>
b92: 87 c0 rjmp .+270 ; 0xca2 <f_lseek+0x18c>
fp->org_clust = clust;
b94: 9f 87 std Y+15, r25 ; 0x0f
b96: 8e 87 std Y+14, r24 ; 0x0e
}
#endif
if (clust) { /* If the file has a cluster chain, it can be followed */
b98: 89 2b or r24, r25
b9a: 09 f4 brne .+2 ; 0xb9e <f_lseek+0x88>
b9c: 6b c0 rjmp .+214 ; 0xc74 <f_lseek+0x15e>
csize = (DWORD)fs->sects_clust * 512; /* Cluster size in unit of byte */
b9e: f2 01 movw r30, r4
ba0: 85 8d ldd r24, Z+29 ; 0x1d
ba2: e8 2e mov r14, r24
ba4: ff 24 eor r15, r15
ba6: 00 27 eor r16, r16
ba8: 11 27 eor r17, r17
baa: 89 e0 ldi r24, 0x09 ; 9
bac: ee 0c add r14, r14
bae: ff 1c adc r15, r15
bb0: 00 1f adc r16, r16
bb2: 11 1f adc r17, r17
bb4: 8a 95 dec r24
bb6: d1 f7 brne .-12 ; 0xbac <f_lseek+0x96>
for (;;) { /* Loop to skip leading clusters */
fp->curr_clust = clust; /* Update current cluster */
bb8: 39 8b std Y+17, r19 ; 0x11
bba: 28 8b std Y+16, r18 ; 0x10
if (ofs <= csize) break;
bbc: e6 14 cp r14, r6
bbe: f7 04 cpc r15, r7
bc0: 08 05 cpc r16, r8
bc2: 19 05 cpc r17, r9
bc4: 50 f5 brcc .+84 ; 0xc1a <f_lseek+0x104>
#if !_FS_READONLY
if (fp->flag & FA_WRITE) /* Check if in write mode or not */
bc6: 8a 81 ldd r24, Y+2 ; 0x02
bc8: 81 ff sbrs r24, 1
bca: 04 c0 rjmp .+8 ; 0xbd4 <f_lseek+0xbe>
clust = create_chain(clust); /* Force streached if in write mode */
bcc: c9 01 movw r24, r18
bce: 0e 94 25 05 call 0xa4a ; 0xa4a <create_chain>
bd2: 03 c0 rjmp .+6 ; 0xbda <f_lseek+0xc4>
else
#endif
clust = get_cluster(clust); /* Only follow cluster chain if not in write mode */
bd4: c9 01 movw r24, r18
bd6: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
bda: 9c 01 movw r18, r24
if (clust == 0) { /* Stop if could not follow the cluster chain */
bdc: 00 97 sbiw r24, 0x00 ; 0
bde: d9 f0 breq .+54 ; 0xc16 <f_lseek+0x100>
ofs = csize; break;
}
if (clust == 1 || clust >= fs->max_clust) goto fk_error;
be0: 01 97 sbiw r24, 0x01 ; 1
be2: 09 f4 brne .+2 ; 0xbe6 <f_lseek+0xd0>
be4: 5e c0 rjmp .+188 ; 0xca2 <f_lseek+0x18c>
be6: f2 01 movw r30, r4
be8: 86 89 ldd r24, Z+22 ; 0x16
bea: 97 89 ldd r25, Z+23 ; 0x17
bec: 28 17 cp r18, r24
bee: 39 07 cpc r19, r25
bf0: 08 f0 brcs .+2 ; 0xbf4 <f_lseek+0xde>
bf2: 57 c0 rjmp .+174 ; 0xca2 <f_lseek+0x18c>
fp->fptr += csize; /* Update R/W pointer */
bf4: 8e 81 ldd r24, Y+6 ; 0x06
bf6: 9f 81 ldd r25, Y+7 ; 0x07
bf8: a8 85 ldd r26, Y+8 ; 0x08
bfa: b9 85 ldd r27, Y+9 ; 0x09
bfc: 8e 0d add r24, r14
bfe: 9f 1d adc r25, r15
c00: a0 1f adc r26, r16
c02: b1 1f adc r27, r17
c04: 8e 83 std Y+6, r24 ; 0x06
c06: 9f 83 std Y+7, r25 ; 0x07
c08: a8 87 std Y+8, r26 ; 0x08
c0a: b9 87 std Y+9, r27 ; 0x09
ofs -= csize;
c0c: 6e 18 sub r6, r14
c0e: 7f 08 sbc r7, r15
c10: 80 0a sbc r8, r16
c12: 91 0a sbc r9, r17
c14: d1 cf rjmp .-94 ; 0xbb8 <f_lseek+0xa2>
}
c16: 37 01 movw r6, r14
c18: 48 01 movw r8, r16
csect = (BYTE)((ofs - 1) / 512); /* Sector offset in the cluster */
c1a: 64 01 movw r12, r8
c1c: 53 01 movw r10, r6
c1e: 08 94 sec
c20: a1 08 sbc r10, r1
c22: b1 08 sbc r11, r1
c24: c1 08 sbc r12, r1
c26: d1 08 sbc r13, r1
c28: 09 e0 ldi r16, 0x09 ; 9
c2a: d6 94 lsr r13
c2c: c7 94 ror r12
c2e: b7 94 ror r11
c30: a7 94 ror r10
c32: 0a 95 dec r16
c34: d1 f7 brne .-12 ; 0xc2a <f_lseek+0x114>
fp->curr_sect = clust2sect(clust) + csect; /* Current sector */
c36: ea 2c mov r14, r10
c38: ff 24 eor r15, r15
c3a: 00 27 eor r16, r16
c3c: 11 27 eor r17, r17
c3e: c9 01 movw r24, r18
c40: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
c44: e6 0e add r14, r22
c46: f7 1e adc r15, r23
c48: 08 1f adc r16, r24
c4a: 19 1f adc r17, r25
c4c: ea 8a std Y+18, r14 ; 0x12
c4e: fb 8a std Y+19, r15 ; 0x13
c50: 0c 8b std Y+20, r16 ; 0x14
c52: 1d 8b std Y+21, r17 ; 0x15
fp->sect_clust = fs->sects_clust - csect; /* Left sector counter in the cluster */
c54: f2 01 movw r30, r4
c56: 85 8d ldd r24, Z+29 ; 0x1d
c58: 8a 19 sub r24, r10
c5a: 8b 83 std Y+3, r24 ; 0x03
fp->fptr += ofs; /* Update file R/W pointer */
c5c: 8e 81 ldd r24, Y+6 ; 0x06
c5e: 9f 81 ldd r25, Y+7 ; 0x07
c60: a8 85 ldd r26, Y+8 ; 0x08
c62: b9 85 ldd r27, Y+9 ; 0x09
c64: 86 0d add r24, r6
c66: 97 1d adc r25, r7
c68: a8 1d adc r26, r8
c6a: b9 1d adc r27, r9
c6c: 8e 83 std Y+6, r24 ; 0x06
c6e: 9f 83 std Y+7, r25 ; 0x07
c70: a8 87 std Y+8, r26 ; 0x08
c72: b9 87 std Y+9, r27 ; 0x09
}
}
#if !_FS_READONLY
if ((fp->flag & FA_WRITE) && fp->fptr > fp->fsize) { /* Set updated flag if in write mode */
c74: 6a 81 ldd r22, Y+2 ; 0x02
c76: 61 ff sbrs r22, 1
c78: 1a c0 rjmp .+52 ; 0xcae <f_lseek+0x198>
c7a: 2e 81 ldd r18, Y+6 ; 0x06
c7c: 3f 81 ldd r19, Y+7 ; 0x07
c7e: 48 85 ldd r20, Y+8 ; 0x08
c80: 59 85 ldd r21, Y+9 ; 0x09
c82: 8a 85 ldd r24, Y+10 ; 0x0a
c84: 9b 85 ldd r25, Y+11 ; 0x0b
c86: ac 85 ldd r26, Y+12 ; 0x0c
c88: bd 85 ldd r27, Y+13 ; 0x0d
c8a: 82 17 cp r24, r18
c8c: 93 07 cpc r25, r19
c8e: a4 07 cpc r26, r20
c90: b5 07 cpc r27, r21
c92: 68 f4 brcc .+26 ; 0xcae <f_lseek+0x198>
fp->fsize = fp->fptr;
c94: 2a 87 std Y+10, r18 ; 0x0a
c96: 3b 87 std Y+11, r19 ; 0x0b
c98: 4c 87 std Y+12, r20 ; 0x0c
c9a: 5d 87 std Y+13, r21 ; 0x0d
fp->flag |= FA__WRITTEN;
c9c: 60 62 ori r22, 0x20 ; 32
c9e: 6a 83 std Y+2, r22 ; 0x02
ca0: 06 c0 rjmp .+12 ; 0xcae <f_lseek+0x198>
#endif
 
return FR_OK;
 
fk_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
ca2: 8a 81 ldd r24, Y+2 ; 0x02
ca4: 80 68 ori r24, 0x80 ; 128
ca6: 8a 83 std Y+2, r24 ; 0x02
ca8: 18 e0 ldi r17, 0x08 ; 8
caa: 21 2e mov r2, r17
cac: 31 2c mov r3, r1
return FR_RW_ERROR;
}
cae: c1 01 movw r24, r2
cb0: e2 e1 ldi r30, 0x12 ; 18
cb2: cd b7 in r28, 0x3d ; 61
cb4: de b7 in r29, 0x3e ; 62
cb6: 0c 94 46 11 jmp 0x228c ; 0x228c <__epilogue_restores__>
 
00000cba <f_sync>:
/*-----------------------------------------------------------------------*/
 
FRESULT f_sync (
FIL *fp /* Pointer to the file object */
)
{
cba: ef 92 push r14
cbc: ff 92 push r15
cbe: 0f 93 push r16
cc0: 1f 93 push r17
cc2: cf 93 push r28
cc4: df 93 push r29
cc6: ec 01 movw r28, r24
BYTE *dir;
FRESULT res;
FATFS *fs = fp->fs;
 
 
res = validate(fs, fp->id); /* Check validity of the object */
cc8: 68 81 ld r22, Y
cca: 79 81 ldd r23, Y+1 ; 0x01
ccc: 8c 81 ldd r24, Y+4 ; 0x04
cce: 9d 81 ldd r25, Y+5 ; 0x05
cd0: 0e 94 43 03 call 0x686 ; 0x686 <validate>
cd4: 7c 01 movw r14, r24
if (res == FR_OK) {
cd6: 89 2b or r24, r25
cd8: 09 f0 breq .+2 ; 0xcdc <f_sync+0x22>
cda: 40 c0 rjmp .+128 ; 0xd5c <f_sync+0xa2>
if (fp->flag & FA__WRITTEN) { /* Has the file been written? */
cdc: 8a 81 ldd r24, Y+2 ; 0x02
cde: 85 ff sbrs r24, 5
ce0: 3d c0 rjmp .+122 ; 0xd5c <f_sync+0xa2>
/* Update the directory entry */
if (!move_window(fp->dir_sect))
ce2: 6e 89 ldd r22, Y+22 ; 0x16
ce4: 7f 89 ldd r23, Y+23 ; 0x17
ce6: 88 8d ldd r24, Y+24 ; 0x18
ce8: 99 8d ldd r25, Y+25 ; 0x19
cea: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
cee: 88 23 and r24, r24
cf0: 91 f1 breq .+100 ; 0xd56 <f_sync+0x9c>
return FR_RW_ERROR;
dir = fp->dir_ptr;
cf2: 0a 8d ldd r16, Y+26 ; 0x1a
cf4: 1b 8d ldd r17, Y+27 ; 0x1b
dir[DIR_Attr] |= AM_ARC; /* Set archive bit */
cf6: f8 01 movw r30, r16
cf8: 83 85 ldd r24, Z+11 ; 0x0b
cfa: 80 62 ori r24, 0x20 ; 32
cfc: 83 87 std Z+11, r24 ; 0x0b
ST_DWORD(&dir[DIR_FileSize], fp->fsize); /* Update file size */
cfe: 8a 85 ldd r24, Y+10 ; 0x0a
d00: 9b 85 ldd r25, Y+11 ; 0x0b
d02: ac 85 ldd r26, Y+12 ; 0x0c
d04: bd 85 ldd r27, Y+13 ; 0x0d
d06: 84 8f std Z+28, r24 ; 0x1c
d08: 95 8f std Z+29, r25 ; 0x1d
d0a: a6 8f std Z+30, r26 ; 0x1e
d0c: b7 8f std Z+31, r27 ; 0x1f
ST_WORD(&dir[DIR_FstClusLO], fp->org_clust); /* Update start cluster */
d0e: 8e 85 ldd r24, Y+14 ; 0x0e
d10: 9f 85 ldd r25, Y+15 ; 0x0f
d12: 93 8f std Z+27, r25 ; 0x1b
d14: 82 8f std Z+26, r24 ; 0x1a
#if _FAT32
ST_WORD(&dir[DIR_FstClusHI], fp->org_clust >> 16);
#endif
tim = get_fattime(); /* Updated time */
d16: 0e 94 bb 00 call 0x176 ; 0x176 <get_fattime>
ST_DWORD(&dir[DIR_WrtTime], tim);
d1a: f8 01 movw r30, r16
d1c: 66 8b std Z+22, r22 ; 0x16
d1e: 77 8b std Z+23, r23 ; 0x17
d20: 80 8f std Z+24, r24 ; 0x18
d22: 91 8f std Z+25, r25 ; 0x19
fp->flag &= ~FA__WRITTEN;
d24: 8a 81 ldd r24, Y+2 ; 0x02
d26: 8f 7d andi r24, 0xDF ; 223
d28: 8a 83 std Y+2, r24 ; 0x02
FRESULT sync (void) /* FR_OK: successful, FR_RW_ERROR: failed */
{
FATFS *fs = FatFs;
 
 
fs->winflag = 1;
d2a: e0 91 0a 01 lds r30, 0x010A
d2e: f0 91 0b 01 lds r31, 0x010B
d32: 81 e0 ldi r24, 0x01 ; 1
d34: 87 8f std Z+31, r24 ; 0x1f
if (!move_window(0)) return FR_RW_ERROR;
d36: 60 e0 ldi r22, 0x00 ; 0
d38: 70 e0 ldi r23, 0x00 ; 0
d3a: 80 e0 ldi r24, 0x00 ; 0
d3c: 90 e0 ldi r25, 0x00 ; 0
d3e: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
d42: 88 23 and r24, r24
d44: 41 f0 breq .+16 ; 0xd56 <f_sync+0x9c>
ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust);
disk_write(0, fs->win, fs->fsi_sector, 1);
fs->fsi_flag = 0;
}
#endif
if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK) return FR_RW_ERROR;
d46: 40 e0 ldi r20, 0x00 ; 0
d48: 50 e0 ldi r21, 0x00 ; 0
d4a: 63 e0 ldi r22, 0x03 ; 3
d4c: 80 e0 ldi r24, 0x00 ; 0
d4e: 0e 94 e8 0d call 0x1bd0 ; 0x1bd0 <disk_ioctl>
d52: 89 2b or r24, r25
d54: 19 f0 breq .+6 ; 0xd5c <f_sync+0xa2>
d56: 98 e0 ldi r25, 0x08 ; 8
d58: e9 2e mov r14, r25
d5a: f1 2c mov r15, r1
fp->flag &= ~FA__WRITTEN;
res = sync();
}
}
return res;
}
d5c: c7 01 movw r24, r14
d5e: e6 e0 ldi r30, 0x06 ; 6
d60: cd b7 in r28, 0x3d ; 61
d62: de b7 in r29, 0x3e ; 62
d64: 0c 94 52 11 jmp 0x22a4 ; 0x22a4 <__epilogue_restores__+0x18>
 
00000d68 <f_close>:
/*-----------------------------------------------------------------------*/
 
FRESULT f_close (
FIL *fp /* Pointer to the file object to be closed */
)
{
d68: cf 93 push r28
d6a: df 93 push r29
d6c: ec 01 movw r28, r24
FRESULT res;
 
 
#if !_FS_READONLY
res = f_sync(fp);
d6e: 0e 94 5d 06 call 0xcba ; 0xcba <f_sync>
#else
res = validate(fp->fs, fp->id);
#endif
if (res == FR_OK)
d72: 00 97 sbiw r24, 0x00 ; 0
d74: 11 f4 brne .+4 ; 0xd7a <f_close+0x12>
fp->fs = NULL;
d76: 1d 82 std Y+5, r1 ; 0x05
d78: 1c 82 std Y+4, r1 ; 0x04
d7a: df 91 pop r29
d7c: cf 91 pop r28
d7e: 08 95 ret
 
00000d80 <f_write>:
FIL *fp, /* Pointer to the file object */
const void *buff, /* Pointer to the data to be written */
WORD btw, /* Number of bytes to write */
WORD *bw /* Pointer to number of bytes written */
)
{
d80: a0 e0 ldi r26, 0x00 ; 0
d82: b0 e0 ldi r27, 0x00 ; 0
d84: e6 ec ldi r30, 0xC6 ; 198
d86: f6 e0 ldi r31, 0x06 ; 6
d88: 0c 94 2c 11 jmp 0x2258 ; 0x2258 <__prologue_saves__+0x4>
d8c: ec 01 movw r28, r24
d8e: 8b 01 movw r16, r22
d90: 7a 01 movw r14, r20
d92: 39 01 movw r6, r18
WORD wcnt;
CLUST clust;
BYTE cc;
FRESULT res;
const BYTE *wbuff = buff;
FATFS *fs = fp->fs;
d94: cc 80 ldd r12, Y+4 ; 0x04
d96: dd 80 ldd r13, Y+5 ; 0x05
 
 
*bw = 0;
d98: f9 01 movw r30, r18
d9a: 11 82 std Z+1, r1 ; 0x01
d9c: 10 82 st Z, r1
res = validate(fs, fp->id); /* Check validity of the object */
d9e: 68 81 ld r22, Y
da0: 79 81 ldd r23, Y+1 ; 0x01
da2: c6 01 movw r24, r12
da4: 0e 94 43 03 call 0x686 ; 0x686 <validate>
da8: 4c 01 movw r8, r24
if (res) return res;
daa: 89 2b or r24, r25
dac: 09 f0 breq .+2 ; 0xdb0 <f_write+0x30>
dae: 1a c1 rjmp .+564 ; 0xfe4 <f_write+0x264>
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
db0: 8a 81 ldd r24, Y+2 ; 0x02
db2: 88 23 and r24, r24
db4: 0c f4 brge .+2 ; 0xdb8 <f_write+0x38>
db6: 13 c1 rjmp .+550 ; 0xfde <f_write+0x25e>
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
db8: 81 fd sbrc r24, 1
dba: 04 c0 rjmp .+8 ; 0xdc4 <f_write+0x44>
dbc: e6 e0 ldi r30, 0x06 ; 6
dbe: 8e 2e mov r8, r30
dc0: 91 2c mov r9, r1
dc2: 10 c1 rjmp .+544 ; 0xfe4 <f_write+0x264>
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
dc4: 2a 85 ldd r18, Y+10 ; 0x0a
dc6: 3b 85 ldd r19, Y+11 ; 0x0b
dc8: 4c 85 ldd r20, Y+12 ; 0x0c
dca: 5d 85 ldd r21, Y+13 ; 0x0d
dcc: c7 01 movw r24, r14
dce: aa 27 eor r26, r26
dd0: bb 27 eor r27, r27
dd2: 82 0f add r24, r18
dd4: 93 1f adc r25, r19
dd6: a4 1f adc r26, r20
dd8: b5 1f adc r27, r21
dda: 82 17 cp r24, r18
ddc: 93 07 cpc r25, r19
dde: a4 07 cpc r26, r20
de0: b5 07 cpc r27, r21
de2: 08 f4 brcc .+2 ; 0xde6 <f_write+0x66>
de4: ff c0 rjmp .+510 ; 0xfe4 <f_write+0x264>
DWORD sect;
WORD wcnt;
CLUST clust;
BYTE cc;
FRESULT res;
const BYTE *wbuff = buff;
de6: 58 01 movw r10, r16
}
if (!move_window(fp->curr_sect)) /* Move sector window */
goto fw_error;
wcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes bytes to sector window */
if (wcnt > btw) wcnt = btw;
memcpy(&fs->win[(WORD)fp->fptr % 512], wbuff, wcnt);
de8: 70 e2 ldi r23, 0x20 ; 32
dea: 47 2e mov r4, r23
dec: 51 2c mov r5, r1
dee: 4c 0c add r4, r12
df0: 5d 1c adc r5, r13
df2: d9 c0 rjmp .+434 ; 0xfa6 <f_write+0x226>
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
 
for ( ; btw; /* Repeat until all data transferred */
wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
if ((fp->fptr % 512) == 0) { /* On the sector boundary */
df4: 2e 81 ldd r18, Y+6 ; 0x06
df6: 3f 81 ldd r19, Y+7 ; 0x07
df8: 48 85 ldd r20, Y+8 ; 0x08
dfa: 59 85 ldd r21, Y+9 ; 0x09
dfc: da 01 movw r26, r20
dfe: c9 01 movw r24, r18
e00: 91 70 andi r25, 0x01 ; 1
e02: a0 70 andi r26, 0x00 ; 0
e04: b0 70 andi r27, 0x00 ; 0
e06: 00 97 sbiw r24, 0x00 ; 0
e08: a1 05 cpc r26, r1
e0a: b1 05 cpc r27, r1
e0c: 09 f0 breq .+2 ; 0xe10 <f_write+0x90>
e0e: 93 c0 rjmp .+294 ; 0xf36 <f_write+0x1b6>
if (--(fp->sect_clust)) { /* Decrement left sector counter */
e10: 8b 81 ldd r24, Y+3 ; 0x03
e12: 81 50 subi r24, 0x01 ; 1
e14: 8b 83 std Y+3, r24 ; 0x03
e16: 88 23 and r24, r24
e18: 49 f0 breq .+18 ; 0xe2c <f_write+0xac>
sect = fp->curr_sect + 1; /* Get current sector */
e1a: 2a 89 ldd r18, Y+18 ; 0x12
e1c: 3b 89 ldd r19, Y+19 ; 0x13
e1e: 4c 89 ldd r20, Y+20 ; 0x14
e20: 5d 89 ldd r21, Y+21 ; 0x15
e22: 2f 5f subi r18, 0xFF ; 255
e24: 3f 4f sbci r19, 0xFF ; 255
e26: 4f 4f sbci r20, 0xFF ; 255
e28: 5f 4f sbci r21, 0xFF ; 255
e2a: 30 c0 rjmp .+96 ; 0xe8c <f_write+0x10c>
} else { /* On the cluster boundary, get next cluster */
if (fp->fptr == 0) { /* Is top of the file */
e2c: 21 15 cp r18, r1
e2e: 31 05 cpc r19, r1
e30: 41 05 cpc r20, r1
e32: 51 05 cpc r21, r1
e34: 69 f4 brne .+26 ; 0xe50 <f_write+0xd0>
clust = fp->org_clust;
e36: 2e 85 ldd r18, Y+14 ; 0x0e
e38: 3f 85 ldd r19, Y+15 ; 0x0f
if (clust == 0) /* No cluster is created yet */
e3a: 21 15 cp r18, r1
e3c: 31 05 cpc r19, r1
e3e: 89 f4 brne .+34 ; 0xe62 <f_write+0xe2>
fp->org_clust = clust = create_chain(0); /* Create a new cluster chain */
e40: 80 e0 ldi r24, 0x00 ; 0
e42: 90 e0 ldi r25, 0x00 ; 0
e44: 0e 94 25 05 call 0xa4a ; 0xa4a <create_chain>
e48: 9c 01 movw r18, r24
e4a: 9f 87 std Y+15, r25 ; 0x0f
e4c: 8e 87 std Y+14, r24 ; 0x0e
e4e: 05 c0 rjmp .+10 ; 0xe5a <f_write+0xda>
} else { /* Middle or end of file */
clust = create_chain(fp->curr_clust); /* Trace or streach cluster chain */
e50: 88 89 ldd r24, Y+16 ; 0x10
e52: 99 89 ldd r25, Y+17 ; 0x11
e54: 0e 94 25 05 call 0xa4a ; 0xa4a <create_chain>
e58: 9c 01 movw r18, r24
}
if (clust == 0) break; /* Disk full */
e5a: 21 15 cp r18, r1
e5c: 31 05 cpc r19, r1
e5e: 09 f4 brne .+2 ; 0xe62 <f_write+0xe2>
e60: a6 c0 rjmp .+332 ; 0xfae <f_write+0x22e>
if (clust == 1 || clust >= fs->max_clust) goto fw_error;
e62: 21 30 cpi r18, 0x01 ; 1
e64: 31 05 cpc r19, r1
e66: 09 f4 brne .+2 ; 0xe6a <f_write+0xea>
e68: b7 c0 rjmp .+366 ; 0xfd8 <f_write+0x258>
e6a: f6 01 movw r30, r12
e6c: 86 89 ldd r24, Z+22 ; 0x16
e6e: 97 89 ldd r25, Z+23 ; 0x17
e70: 28 17 cp r18, r24
e72: 39 07 cpc r19, r25
e74: 08 f0 brcs .+2 ; 0xe78 <f_write+0xf8>
e76: b0 c0 rjmp .+352 ; 0xfd8 <f_write+0x258>
fp->curr_clust = clust; /* Current cluster */
e78: 39 8b std Y+17, r19 ; 0x11
e7a: 28 8b std Y+16, r18 ; 0x10
sect = clust2sect(clust); /* Get current sector */
e7c: c9 01 movw r24, r18
e7e: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
e82: 9b 01 movw r18, r22
e84: ac 01 movw r20, r24
fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */
e86: f6 01 movw r30, r12
e88: 85 8d ldd r24, Z+29 ; 0x1d
e8a: 8b 83 std Y+3, r24 ; 0x03
}
fp->curr_sect = sect; /* Update current sector */
e8c: 2a 8b std Y+18, r18 ; 0x12
e8e: 3b 8b std Y+19, r19 ; 0x13
e90: 4c 8b std Y+20, r20 ; 0x14
e92: 5d 8b std Y+21, r21 ; 0x15
cc = btw / 512; /* When left bytes >= 512, */
e94: 87 01 movw r16, r14
e96: 01 2f mov r16, r17
e98: 11 27 eor r17, r17
e9a: 06 95 lsr r16
if (cc) { /* Write maximum contiguous sectors directly */
e9c: 00 23 and r16, r16
e9e: 61 f1 breq .+88 ; 0xef8 <f_write+0x178>
ea0: 8b 81 ldd r24, Y+3 ; 0x03
ea2: 10 2f mov r17, r16
ea4: 80 17 cp r24, r16
ea6: 08 f4 brcc .+2 ; 0xeaa <f_write+0x12a>
ea8: 18 2f mov r17, r24
if (cc > fp->sect_clust) cc = fp->sect_clust;
if (disk_write(0, wbuff, sect, cc) != RES_OK)
eaa: 01 2f mov r16, r17
eac: b5 01 movw r22, r10
eae: 80 e0 ldi r24, 0x00 ; 0
eb0: 0e 94 d3 0e call 0x1da6 ; 0x1da6 <disk_write>
eb4: 89 2b or r24, r25
eb6: 09 f0 breq .+2 ; 0xeba <f_write+0x13a>
eb8: 8f c0 rjmp .+286 ; 0xfd8 <f_write+0x258>
goto fw_error;
fp->sect_clust -= cc - 1;
eba: 8b 81 ldd r24, Y+3 ; 0x03
ebc: 8f 5f subi r24, 0xFF ; 255
ebe: 81 1b sub r24, r17
ec0: 8b 83 std Y+3, r24 ; 0x03
fp->curr_sect += cc - 1;
ec2: 81 2f mov r24, r17
ec4: 99 27 eor r25, r25
ec6: 01 97 sbiw r24, 0x01 ; 1
ec8: 9c 01 movw r18, r24
eca: 44 27 eor r20, r20
ecc: 37 fd sbrc r19, 7
ece: 40 95 com r20
ed0: 54 2f mov r21, r20
ed2: 8c 01 movw r16, r24
ed4: 0f 5f subi r16, 0xFF ; 255
ed6: 1f 4f sbci r17, 0xFF ; 255
ed8: 8a 89 ldd r24, Y+18 ; 0x12
eda: 9b 89 ldd r25, Y+19 ; 0x13
edc: ac 89 ldd r26, Y+20 ; 0x14
ede: bd 89 ldd r27, Y+21 ; 0x15
ee0: 82 0f add r24, r18
ee2: 93 1f adc r25, r19
ee4: a4 1f adc r26, r20
ee6: b5 1f adc r27, r21
ee8: 8a 8b std Y+18, r24 ; 0x12
eea: 9b 8b std Y+19, r25 ; 0x13
eec: ac 8b std Y+20, r26 ; 0x14
eee: bd 8b std Y+21, r27 ; 0x15
wcnt = cc * 512; continue;
ef0: 10 2f mov r17, r16
ef2: 00 27 eor r16, r16
ef4: 11 0f add r17, r17
ef6: 3d c0 rjmp .+122 ; 0xf72 <f_write+0x1f2>
}
if (fp->fptr >= fp->fsize) { /* Flush R/W window if needed */
ef8: 2e 81 ldd r18, Y+6 ; 0x06
efa: 3f 81 ldd r19, Y+7 ; 0x07
efc: 48 85 ldd r20, Y+8 ; 0x08
efe: 59 85 ldd r21, Y+9 ; 0x09
f00: 8a 85 ldd r24, Y+10 ; 0x0a
f02: 9b 85 ldd r25, Y+11 ; 0x0b
f04: ac 85 ldd r26, Y+12 ; 0x0c
f06: bd 85 ldd r27, Y+13 ; 0x0d
f08: 28 17 cp r18, r24
f0a: 39 07 cpc r19, r25
f0c: 4a 07 cpc r20, r26
f0e: 5b 07 cpc r21, r27
f10: 90 f0 brcs .+36 ; 0xf36 <f_write+0x1b6>
if (!move_window(0)) goto fw_error;
f12: 60 e0 ldi r22, 0x00 ; 0
f14: 70 e0 ldi r23, 0x00 ; 0
f16: 80 e0 ldi r24, 0x00 ; 0
f18: 90 e0 ldi r25, 0x00 ; 0
f1a: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
f1e: 88 23 and r24, r24
f20: 09 f4 brne .+2 ; 0xf24 <f_write+0x1a4>
f22: 5a c0 rjmp .+180 ; 0xfd8 <f_write+0x258>
fs->winsect = fp->curr_sect;
f24: 8a 89 ldd r24, Y+18 ; 0x12
f26: 9b 89 ldd r25, Y+19 ; 0x13
f28: ac 89 ldd r26, Y+20 ; 0x14
f2a: bd 89 ldd r27, Y+21 ; 0x15
f2c: f6 01 movw r30, r12
f2e: 84 83 std Z+4, r24 ; 0x04
f30: 95 83 std Z+5, r25 ; 0x05
f32: a6 83 std Z+6, r26 ; 0x06
f34: b7 83 std Z+7, r27 ; 0x07
}
}
if (!move_window(fp->curr_sect)) /* Move sector window */
f36: 6a 89 ldd r22, Y+18 ; 0x12
f38: 7b 89 ldd r23, Y+19 ; 0x13
f3a: 8c 89 ldd r24, Y+20 ; 0x14
f3c: 9d 89 ldd r25, Y+21 ; 0x15
f3e: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
f42: 88 23 and r24, r24
f44: 09 f4 brne .+2 ; 0xf48 <f_write+0x1c8>
f46: 48 c0 rjmp .+144 ; 0xfd8 <f_write+0x258>
goto fw_error;
wcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes bytes to sector window */
f48: 8e 81 ldd r24, Y+6 ; 0x06
f4a: 9f 81 ldd r25, Y+7 ; 0x07
f4c: 91 70 andi r25, 0x01 ; 1
f4e: 20 e0 ldi r18, 0x00 ; 0
f50: 32 e0 ldi r19, 0x02 ; 2
f52: 28 1b sub r18, r24
f54: 39 0b sbc r19, r25
f56: 87 01 movw r16, r14
f58: 2e 15 cp r18, r14
f5a: 3f 05 cpc r19, r15
f5c: 08 f4 brcc .+2 ; 0xf60 <f_write+0x1e0>
f5e: 89 01 movw r16, r18
if (wcnt > btw) wcnt = btw;
memcpy(&fs->win[(WORD)fp->fptr % 512], wbuff, wcnt);
f60: a8 01 movw r20, r16
f62: b5 01 movw r22, r10
f64: 84 0d add r24, r4
f66: 95 1d adc r25, r5
f68: 0e 94 a1 10 call 0x2142 ; 0x2142 <memcpy>
fs->winflag = 1;
f6c: 81 e0 ldi r24, 0x01 ; 1
f6e: f6 01 movw r30, r12
f70: 87 8f std Z+31, r24 ; 0x1f
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
 
for ( ; btw; /* Repeat until all data transferred */
wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
f72: a0 0e add r10, r16
f74: b1 1e adc r11, r17
f76: c8 01 movw r24, r16
f78: aa 27 eor r26, r26
f7a: bb 27 eor r27, r27
f7c: 2e 81 ldd r18, Y+6 ; 0x06
f7e: 3f 81 ldd r19, Y+7 ; 0x07
f80: 48 85 ldd r20, Y+8 ; 0x08
f82: 59 85 ldd r21, Y+9 ; 0x09
f84: 28 0f add r18, r24
f86: 39 1f adc r19, r25
f88: 4a 1f adc r20, r26
f8a: 5b 1f adc r21, r27
f8c: 2e 83 std Y+6, r18 ; 0x06
f8e: 3f 83 std Y+7, r19 ; 0x07
f90: 48 87 std Y+8, r20 ; 0x08
f92: 59 87 std Y+9, r21 ; 0x09
f94: f3 01 movw r30, r6
f96: 80 81 ld r24, Z
f98: 91 81 ldd r25, Z+1 ; 0x01
f9a: 80 0f add r24, r16
f9c: 91 1f adc r25, r17
f9e: 91 83 std Z+1, r25 ; 0x01
fa0: 80 83 st Z, r24
fa2: e0 1a sub r14, r16
fa4: f1 0a sbc r15, r17
if (res) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
 
for ( ; btw; /* Repeat until all data transferred */
fa6: e1 14 cp r14, r1
fa8: f1 04 cpc r15, r1
faa: 09 f0 breq .+2 ; 0xfae <f_write+0x22e>
fac: 23 cf rjmp .-442 ; 0xdf4 <f_write+0x74>
if (wcnt > btw) wcnt = btw;
memcpy(&fs->win[(WORD)fp->fptr % 512], wbuff, wcnt);
fs->winflag = 1;
}
 
if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */
fae: 2e 81 ldd r18, Y+6 ; 0x06
fb0: 3f 81 ldd r19, Y+7 ; 0x07
fb2: 48 85 ldd r20, Y+8 ; 0x08
fb4: 59 85 ldd r21, Y+9 ; 0x09
fb6: 8a 85 ldd r24, Y+10 ; 0x0a
fb8: 9b 85 ldd r25, Y+11 ; 0x0b
fba: ac 85 ldd r26, Y+12 ; 0x0c
fbc: bd 85 ldd r27, Y+13 ; 0x0d
fbe: 82 17 cp r24, r18
fc0: 93 07 cpc r25, r19
fc2: a4 07 cpc r26, r20
fc4: b5 07 cpc r27, r21
fc6: 20 f4 brcc .+8 ; 0xfd0 <f_write+0x250>
fc8: 2a 87 std Y+10, r18 ; 0x0a
fca: 3b 87 std Y+11, r19 ; 0x0b
fcc: 4c 87 std Y+12, r20 ; 0x0c
fce: 5d 87 std Y+13, r21 ; 0x0d
fp->flag |= FA__WRITTEN; /* Set file changed flag */
fd0: 8a 81 ldd r24, Y+2 ; 0x02
fd2: 80 62 ori r24, 0x20 ; 32
fd4: 8a 83 std Y+2, r24 ; 0x02
fd6: 06 c0 rjmp .+12 ; 0xfe4 <f_write+0x264>
return FR_OK;
 
fw_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
fd8: 8a 81 ldd r24, Y+2 ; 0x02
fda: 80 68 ori r24, 0x80 ; 128
fdc: 8a 83 std Y+2, r24 ; 0x02
fde: 28 e0 ldi r18, 0x08 ; 8
fe0: 82 2e mov r8, r18
fe2: 91 2c mov r9, r1
return FR_RW_ERROR;
}
fe4: c4 01 movw r24, r8
fe6: e0 e1 ldi r30, 0x10 ; 16
fe8: cd b7 in r28, 0x3d ; 61
fea: de b7 in r29, 0x3e ; 62
fec: 0c 94 48 11 jmp 0x2290 ; 0x2290 <__epilogue_restores__+0x4>
 
00000ff0 <f_read>:
FIL *fp, /* Pointer to the file object */
void *buff, /* Pointer to data buffer */
WORD btr, /* Number of bytes to read */
WORD *br /* Pointer to number of bytes read */
)
{
ff0: a0 e0 ldi r26, 0x00 ; 0
ff2: b0 e0 ldi r27, 0x00 ; 0
ff4: ee ef ldi r30, 0xFE ; 254
ff6: f7 e0 ldi r31, 0x07 ; 7
ff8: 0c 94 2c 11 jmp 0x2258 ; 0x2258 <__prologue_saves__+0x4>
ffc: ec 01 movw r28, r24
ffe: 8b 01 movw r16, r22
1000: 7a 01 movw r14, r20
1002: 39 01 movw r6, r18
DWORD sect, remain;
WORD rcnt;
CLUST clust;
BYTE cc, *rbuff = buff;
FRESULT res;
FATFS *fs = fp->fs;
1004: 8c 80 ldd r8, Y+4 ; 0x04
1006: 9d 80 ldd r9, Y+5 ; 0x05
 
 
*br = 0;
1008: f9 01 movw r30, r18
100a: 11 82 std Z+1, r1 ; 0x01
100c: 10 82 st Z, r1
res = validate(fs, fp->id); /* Check validity of the object */
100e: 68 81 ld r22, Y
1010: 79 81 ldd r23, Y+1 ; 0x01
1012: c4 01 movw r24, r8
1014: 0e 94 43 03 call 0x686 ; 0x686 <validate>
1018: 5c 01 movw r10, r24
if (res) return res;
101a: 89 2b or r24, r25
101c: 09 f0 breq .+2 ; 0x1020 <f_read+0x30>
101e: d9 c0 rjmp .+434 ; 0x11d2 <f_read+0x1e2>
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
1020: 8a 81 ldd r24, Y+2 ; 0x02
1022: 88 23 and r24, r24
1024: 0c f4 brge .+2 ; 0x1028 <f_read+0x38>
1026: d2 c0 rjmp .+420 ; 0x11cc <f_read+0x1dc>
if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
1028: 80 fd sbrc r24, 0
102a: 04 c0 rjmp .+8 ; 0x1034 <f_read+0x44>
102c: 06 e0 ldi r16, 0x06 ; 6
102e: a0 2e mov r10, r16
1030: b1 2c mov r11, r1
1032: cf c0 rjmp .+414 ; 0x11d2 <f_read+0x1e2>
remain = fp->fsize - fp->fptr;
1034: 2a 85 ldd r18, Y+10 ; 0x0a
1036: 3b 85 ldd r19, Y+11 ; 0x0b
1038: 4c 85 ldd r20, Y+12 ; 0x0c
103a: 5d 85 ldd r21, Y+13 ; 0x0d
103c: 8e 81 ldd r24, Y+6 ; 0x06
103e: 9f 81 ldd r25, Y+7 ; 0x07
1040: a8 85 ldd r26, Y+8 ; 0x08
1042: b9 85 ldd r27, Y+9 ; 0x09
1044: 28 1b sub r18, r24
1046: 39 0b sbc r19, r25
1048: 4a 0b sbc r20, r26
104a: 5b 0b sbc r21, r27
if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */
104c: c7 01 movw r24, r14
104e: aa 27 eor r26, r26
1050: bb 27 eor r27, r27
1052: 28 17 cp r18, r24
1054: 39 07 cpc r19, r25
1056: 4a 07 cpc r20, r26
1058: 5b 07 cpc r21, r27
105a: 08 f4 brcc .+2 ; 0x105e <f_read+0x6e>
105c: 79 01 movw r14, r18
)
{
DWORD sect, remain;
WORD rcnt;
CLUST clust;
BYTE cc, *rbuff = buff;
105e: 68 01 movw r12, r16
}
}
if (!move_window(fp->curr_sect)) goto fr_error; /* Move sector window */
rcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes from sector window */
if (rcnt > btr) rcnt = btr;
memcpy(rbuff, &fs->win[(WORD)fp->fptr % 512], rcnt);
1060: 10 e2 ldi r17, 0x20 ; 32
1062: 41 2e mov r4, r17
1064: 51 2c mov r5, r1
1066: 48 0c add r4, r8
1068: 59 1c adc r5, r9
106a: a8 c0 rjmp .+336 ; 0x11bc <f_read+0x1cc>
remain = fp->fsize - fp->fptr;
if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */
 
for ( ; btr; /* Repeat until all data transferred */
rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
if ((fp->fptr % 512) == 0) { /* On the sector boundary */
106c: 2e 81 ldd r18, Y+6 ; 0x06
106e: 3f 81 ldd r19, Y+7 ; 0x07
1070: 48 85 ldd r20, Y+8 ; 0x08
1072: 59 85 ldd r21, Y+9 ; 0x09
1074: da 01 movw r26, r20
1076: c9 01 movw r24, r18
1078: 91 70 andi r25, 0x01 ; 1
107a: a0 70 andi r26, 0x00 ; 0
107c: b0 70 andi r27, 0x00 ; 0
107e: 00 97 sbiw r24, 0x00 ; 0
1080: a1 05 cpc r26, r1
1082: b1 05 cpc r27, r1
1084: 09 f0 breq .+2 ; 0x1088 <f_read+0x98>
1086: 66 c0 rjmp .+204 ; 0x1154 <f_read+0x164>
if (--fp->sect_clust) { /* Decrement left sector counter */
1088: 8b 81 ldd r24, Y+3 ; 0x03
108a: 81 50 subi r24, 0x01 ; 1
108c: 8b 83 std Y+3, r24 ; 0x03
108e: 88 23 and r24, r24
1090: 49 f0 breq .+18 ; 0x10a4 <f_read+0xb4>
sect = fp->curr_sect + 1; /* Get current sector */
1092: 2a 89 ldd r18, Y+18 ; 0x12
1094: 3b 89 ldd r19, Y+19 ; 0x13
1096: 4c 89 ldd r20, Y+20 ; 0x14
1098: 5d 89 ldd r21, Y+21 ; 0x15
109a: 2f 5f subi r18, 0xFF ; 255
109c: 3f 4f sbci r19, 0xFF ; 255
109e: 4f 4f sbci r20, 0xFF ; 255
10a0: 5f 4f sbci r21, 0xFF ; 255
10a2: 22 c0 rjmp .+68 ; 0x10e8 <f_read+0xf8>
} else { /* On the cluster boundary, get next cluster */
clust = (fp->fptr == 0) ?
10a4: 21 15 cp r18, r1
10a6: 31 05 cpc r19, r1
10a8: 41 05 cpc r20, r1
10aa: 51 05 cpc r21, r1
10ac: 19 f4 brne .+6 ; 0x10b4 <f_read+0xc4>
10ae: 2e 85 ldd r18, Y+14 ; 0x0e
10b0: 3f 85 ldd r19, Y+15 ; 0x0f
10b2: 05 c0 rjmp .+10 ; 0x10be <f_read+0xce>
10b4: 88 89 ldd r24, Y+16 ; 0x10
10b6: 99 89 ldd r25, Y+17 ; 0x11
10b8: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
10bc: 9c 01 movw r18, r24
fp->org_clust : get_cluster(fp->curr_clust);
if (clust < 2 || clust >= fs->max_clust)
10be: 22 30 cpi r18, 0x02 ; 2
10c0: 31 05 cpc r19, r1
10c2: 08 f4 brcc .+2 ; 0x10c6 <f_read+0xd6>
10c4: 80 c0 rjmp .+256 ; 0x11c6 <f_read+0x1d6>
10c6: f4 01 movw r30, r8
10c8: 86 89 ldd r24, Z+22 ; 0x16
10ca: 97 89 ldd r25, Z+23 ; 0x17
10cc: 28 17 cp r18, r24
10ce: 39 07 cpc r19, r25
10d0: 08 f0 brcs .+2 ; 0x10d4 <f_read+0xe4>
10d2: 79 c0 rjmp .+242 ; 0x11c6 <f_read+0x1d6>
goto fr_error;
fp->curr_clust = clust; /* Current cluster */
10d4: 39 8b std Y+17, r19 ; 0x11
10d6: 28 8b std Y+16, r18 ; 0x10
sect = clust2sect(clust); /* Get current sector */
10d8: c9 01 movw r24, r18
10da: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
10de: 9b 01 movw r18, r22
10e0: ac 01 movw r20, r24
fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */
10e2: f4 01 movw r30, r8
10e4: 85 8d ldd r24, Z+29 ; 0x1d
10e6: 8b 83 std Y+3, r24 ; 0x03
}
fp->curr_sect = sect; /* Update current sector */
10e8: 2a 8b std Y+18, r18 ; 0x12
10ea: 3b 8b std Y+19, r19 ; 0x13
10ec: 4c 8b std Y+20, r20 ; 0x14
10ee: 5d 8b std Y+21, r21 ; 0x15
cc = btr / 512; /* When left bytes >= 512, */
10f0: 87 01 movw r16, r14
10f2: 01 2f mov r16, r17
10f4: 11 27 eor r17, r17
10f6: 06 95 lsr r16
if (cc) { /* Read maximum contiguous sectors directly */
10f8: 00 23 and r16, r16
10fa: 61 f1 breq .+88 ; 0x1154 <f_read+0x164>
10fc: 8b 81 ldd r24, Y+3 ; 0x03
10fe: 10 2f mov r17, r16
1100: 80 17 cp r24, r16
1102: 08 f4 brcc .+2 ; 0x1106 <f_read+0x116>
1104: 18 2f mov r17, r24
if (cc > fp->sect_clust) cc = fp->sect_clust;
if (disk_read(0, rbuff, sect, cc) != RES_OK)
1106: 01 2f mov r16, r17
1108: b6 01 movw r22, r12
110a: 80 e0 ldi r24, 0x00 ; 0
110c: 0e 94 51 0f call 0x1ea2 ; 0x1ea2 <disk_read>
1110: 89 2b or r24, r25
1112: 09 f0 breq .+2 ; 0x1116 <f_read+0x126>
1114: 58 c0 rjmp .+176 ; 0x11c6 <f_read+0x1d6>
goto fr_error;
fp->sect_clust -= cc - 1;
1116: 8b 81 ldd r24, Y+3 ; 0x03
1118: 8f 5f subi r24, 0xFF ; 255
111a: 81 1b sub r24, r17
111c: 8b 83 std Y+3, r24 ; 0x03
fp->curr_sect += cc - 1;
111e: 81 2f mov r24, r17
1120: 99 27 eor r25, r25
1122: 01 97 sbiw r24, 0x01 ; 1
1124: 9c 01 movw r18, r24
1126: 44 27 eor r20, r20
1128: 37 fd sbrc r19, 7
112a: 40 95 com r20
112c: 54 2f mov r21, r20
112e: 8c 01 movw r16, r24
1130: 0f 5f subi r16, 0xFF ; 255
1132: 1f 4f sbci r17, 0xFF ; 255
1134: 8a 89 ldd r24, Y+18 ; 0x12
1136: 9b 89 ldd r25, Y+19 ; 0x13
1138: ac 89 ldd r26, Y+20 ; 0x14
113a: bd 89 ldd r27, Y+21 ; 0x15
113c: 82 0f add r24, r18
113e: 93 1f adc r25, r19
1140: a4 1f adc r26, r20
1142: b5 1f adc r27, r21
1144: 8a 8b std Y+18, r24 ; 0x12
1146: 9b 8b std Y+19, r25 ; 0x13
1148: ac 8b std Y+20, r26 ; 0x14
114a: bd 8b std Y+21, r27 ; 0x15
rcnt = cc * 512; continue;
114c: 10 2f mov r17, r16
114e: 00 27 eor r16, r16
1150: 11 0f add r17, r17
1152: 1a c0 rjmp .+52 ; 0x1188 <f_read+0x198>
}
}
if (!move_window(fp->curr_sect)) goto fr_error; /* Move sector window */
1154: 6a 89 ldd r22, Y+18 ; 0x12
1156: 7b 89 ldd r23, Y+19 ; 0x13
1158: 8c 89 ldd r24, Y+20 ; 0x14
115a: 9d 89 ldd r25, Y+21 ; 0x15
115c: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
1160: 88 23 and r24, r24
1162: 89 f1 breq .+98 ; 0x11c6 <f_read+0x1d6>
rcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes from sector window */
1164: 6e 81 ldd r22, Y+6 ; 0x06
1166: 7f 81 ldd r23, Y+7 ; 0x07
1168: 71 70 andi r23, 0x01 ; 1
116a: 80 e0 ldi r24, 0x00 ; 0
116c: 92 e0 ldi r25, 0x02 ; 2
116e: 86 1b sub r24, r22
1170: 97 0b sbc r25, r23
1172: 87 01 movw r16, r14
1174: 8e 15 cp r24, r14
1176: 9f 05 cpc r25, r15
1178: 08 f4 brcc .+2 ; 0x117c <f_read+0x18c>
117a: 8c 01 movw r16, r24
if (rcnt > btr) rcnt = btr;
memcpy(rbuff, &fs->win[(WORD)fp->fptr % 512], rcnt);
117c: 64 0d add r22, r4
117e: 75 1d adc r23, r5
1180: a8 01 movw r20, r16
1182: c6 01 movw r24, r12
1184: 0e 94 a1 10 call 0x2142 ; 0x2142 <memcpy>
if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
remain = fp->fsize - fp->fptr;
if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */
 
for ( ; btr; /* Repeat until all data transferred */
rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
1188: c0 0e add r12, r16
118a: d1 1e adc r13, r17
118c: c8 01 movw r24, r16
118e: aa 27 eor r26, r26
1190: bb 27 eor r27, r27
1192: 2e 81 ldd r18, Y+6 ; 0x06
1194: 3f 81 ldd r19, Y+7 ; 0x07
1196: 48 85 ldd r20, Y+8 ; 0x08
1198: 59 85 ldd r21, Y+9 ; 0x09
119a: 28 0f add r18, r24
119c: 39 1f adc r19, r25
119e: 4a 1f adc r20, r26
11a0: 5b 1f adc r21, r27
11a2: 2e 83 std Y+6, r18 ; 0x06
11a4: 3f 83 std Y+7, r19 ; 0x07
11a6: 48 87 std Y+8, r20 ; 0x08
11a8: 59 87 std Y+9, r21 ; 0x09
11aa: f3 01 movw r30, r6
11ac: 80 81 ld r24, Z
11ae: 91 81 ldd r25, Z+1 ; 0x01
11b0: 80 0f add r24, r16
11b2: 91 1f adc r25, r17
11b4: 91 83 std Z+1, r25 ; 0x01
11b6: 80 83 st Z, r24
11b8: e0 1a sub r14, r16
11ba: f1 0a sbc r15, r17
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
remain = fp->fsize - fp->fptr;
if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */
 
for ( ; btr; /* Repeat until all data transferred */
11bc: e1 14 cp r14, r1
11be: f1 04 cpc r15, r1
11c0: 09 f0 breq .+2 ; 0x11c4 <f_read+0x1d4>
11c2: 54 cf rjmp .-344 ; 0x106c <f_read+0x7c>
11c4: 06 c0 rjmp .+12 ; 0x11d2 <f_read+0x1e2>
}
 
return FR_OK;
 
fr_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
11c6: 8a 81 ldd r24, Y+2 ; 0x02
11c8: 80 68 ori r24, 0x80 ; 128
11ca: 8a 83 std Y+2, r24 ; 0x02
11cc: f8 e0 ldi r31, 0x08 ; 8
11ce: af 2e mov r10, r31
11d0: b1 2c mov r11, r1
return FR_RW_ERROR;
}
11d2: c5 01 movw r24, r10
11d4: e0 e1 ldi r30, 0x10 ; 16
11d6: cd b7 in r28, 0x3d ; 61
11d8: de b7 in r29, 0x3e ; 62
11da: 0c 94 48 11 jmp 0x2290 ; 0x2290 <__epilogue_restores__+0x4>
 
000011de <f_mount>:
 
FRESULT f_mount (
BYTE drv, /* Logical drive number to be mounted/unmounted */
FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
)
{
11de: fb 01 movw r30, r22
FATFS *fsobj;
 
 
if (drv) return FR_INVALID_DRIVE;
11e0: 88 23 and r24, r24
11e2: 19 f0 breq .+6 ; 0x11ea <f_mount+0xc>
11e4: 85 e0 ldi r24, 0x05 ; 5
11e6: 90 e0 ldi r25, 0x00 ; 0
11e8: 08 95 ret
fsobj = FatFs;
11ea: a0 91 0a 01 lds r26, 0x010A
11ee: b0 91 0b 01 lds r27, 0x010B
FatFs = fs;
11f2: 70 93 0b 01 sts 0x010B, r23
11f6: 60 93 0a 01 sts 0x010A, r22
if (fsobj) memset(fsobj, 0, sizeof(FATFS));
11fa: 10 97 sbiw r26, 0x00 ; 0
11fc: 29 f0 breq .+10 ; 0x1208 <f_mount+0x2a>
11fe: 80 e2 ldi r24, 0x20 ; 32
1200: 92 e0 ldi r25, 0x02 ; 2
1202: 1d 92 st X+, r1
1204: 01 97 sbiw r24, 0x01 ; 1
1206: e9 f7 brne .-6 ; 0x1202 <f_mount+0x24>
if (fs) memset(fs, 0, sizeof(FATFS));
1208: 30 97 sbiw r30, 0x00 ; 0
120a: 19 f4 brne .+6 ; 0x1212 <f_mount+0x34>
120c: 80 e0 ldi r24, 0x00 ; 0
120e: 90 e0 ldi r25, 0x00 ; 0
1210: 08 95 ret
1212: 80 e2 ldi r24, 0x20 ; 32
1214: 92 e0 ldi r25, 0x02 ; 2
1216: 11 92 st Z+, r1
1218: 01 97 sbiw r24, 0x01 ; 1
121a: e9 f7 brne .-6 ; 0x1216 <f_mount+0x38>
121c: 80 e0 ldi r24, 0x00 ; 0
121e: 90 e0 ldi r25, 0x00 ; 0
 
return FR_OK;
}
1220: 08 95 ret
 
00001222 <check_fs>:
 
static
BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error */
DWORD sect /* Sector# to check if it is a FAT boot record or not */
)
{
1222: 0f 93 push r16
1224: cf 93 push r28
1226: df 93 push r29
1228: 9b 01 movw r18, r22
122a: ac 01 movw r20, r24
FATFS *fs = FatFs;
122c: c0 91 0a 01 lds r28, 0x010A
1230: d0 91 0b 01 lds r29, 0x010B
 
if (disk_read(0, fs->win, sect, 1) != RES_OK) /* Load boot record */
1234: be 01 movw r22, r28
1236: 60 5e subi r22, 0xE0 ; 224
1238: 7f 4f sbci r23, 0xFF ; 255
123a: 01 e0 ldi r16, 0x01 ; 1
123c: 80 e0 ldi r24, 0x00 ; 0
123e: 0e 94 51 0f call 0x1ea2 ; 0x1ea2 <disk_read>
1242: 89 2b or r24, r25
1244: d9 f4 brne .+54 ; 0x127c <check_fs+0x5a>
return 2;
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
1246: c2 5e subi r28, 0xE2 ; 226
1248: dd 4f sbci r29, 0xFD ; 253
124a: 88 81 ld r24, Y
124c: 99 81 ldd r25, Y+1 ; 0x01
124e: ce 51 subi r28, 0x1E ; 30
1250: d2 40 sbci r29, 0x02 ; 2
1252: 85 55 subi r24, 0x55 ; 85
1254: 9a 4a sbci r25, 0xAA ; 170
1256: 91 f4 brne .+36 ; 0x127c <check_fs+0x5a>
1258: 00 e0 ldi r16, 0x00 ; 0
return 2;
 
if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3)) /* Check FAT signature */
125a: 43 e0 ldi r20, 0x03 ; 3
125c: 50 e0 ldi r21, 0x00 ; 0
125e: 60 e0 ldi r22, 0x00 ; 0
1260: 71 e0 ldi r23, 0x01 ; 1
1262: ce 01 movw r24, r28
1264: 8a 5a subi r24, 0xAA ; 170
1266: 9f 4f sbci r25, 0xFF ; 255
1268: 0e 94 94 10 call 0x2128 ; 0x2128 <memcmp>
126c: 89 2b or r24, r25
126e: 09 f4 brne .+2 ; 0x1272 <check_fs+0x50>
1270: 01 e0 ldi r16, 0x01 ; 1
1272: 81 e0 ldi r24, 0x01 ; 1
1274: 08 27 eor r16, r24
1276: 80 2f mov r24, r16
1278: 99 27 eor r25, r25
127a: 02 c0 rjmp .+4 ; 0x1280 <check_fs+0x5e>
127c: 82 e0 ldi r24, 0x02 ; 2
127e: 90 e0 ldi r25, 0x00 ; 0
1280: df 91 pop r29
1282: cf 91 pop r28
1284: 0f 91 pop r16
1286: 08 95 ret
 
00001288 <f_open>:
FRESULT f_open (
FIL *fp, /* Pointer to the blank file object */
const char *path, /* Pointer to the file name */
BYTE mode /* Access mode and file open mode flags */
)
{
1288: ad e1 ldi r26, 0x1D ; 29
128a: b0 e0 ldi r27, 0x00 ; 0
128c: ea e4 ldi r30, 0x4A ; 74
128e: f9 e0 ldi r31, 0x09 ; 9
1290: 0c 94 2a 11 jmp 0x2254 ; 0x2254 <__prologue_saves__>
1294: 9d 8f std Y+29, r25 ; 0x1d
1296: 8c 8f std Y+28, r24 ; 0x1c
1298: 6b 01 movw r12, r22
FRESULT res;
BYTE *dir;
DIR dirobj;
char fn[8+3+1];
FATFS *fs = FatFs;
129a: a0 90 0a 01 lds r10, 0x010A
129e: b0 90 0b 01 lds r11, 0x010B
 
 
fp->fs = NULL;
12a2: fc 01 movw r30, r24
12a4: 15 82 std Z+5, r1 ; 0x05
12a6: 14 82 std Z+4, r1 ; 0x04
#if !_FS_READONLY
mode &= (FA_READ|FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW);
12a8: f4 2f mov r31, r20
12aa: ff 71 andi r31, 0x1F ; 31
12ac: fb 8f std Y+27, r31 ; 0x1b
12ae: 03 c0 rjmp .+6 ; 0x12b6 <f_open+0x2e>
const char *p = *path;
FATFS *fs = FatFs;
 
 
 
while (*p == ' ') p++; /* Strip leading spaces */
12b0: 08 94 sec
12b2: c1 1c adc r12, r1
12b4: d1 1c adc r13, r1
12b6: d6 01 movw r26, r12
12b8: 8c 91 ld r24, X
12ba: 80 32 cpi r24, 0x20 ; 32
12bc: c9 f3 breq .-14 ; 0x12b0 <f_open+0x28>
if (*p == '/') p++; /* Strip heading slash */
12be: 8f 32 cpi r24, 0x2F ; 47
12c0: 19 f4 brne .+6 ; 0x12c8 <f_open+0x40>
12c2: 08 94 sec
12c4: c1 1c adc r12, r1
12c6: d1 1c adc r13, r1
*path = p; /* Return pointer to the path name */
 
/* Is the file system object registered? */
if (!fs) return FR_NOT_ENABLED;
12c8: a1 14 cp r10, r1
12ca: b1 04 cpc r11, r1
12cc: 09 f4 brne .+2 ; 0x12d0 <f_open+0x48>
12ce: 15 c1 rjmp .+554 ; 0x14fa <f_open+0x272>
 
 
fp->fs = NULL;
#if !_FS_READONLY
mode &= (FA_READ|FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW);
res = auto_mount(&path, (BYTE)(mode & (FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)));
12d0: 1b 8d ldd r17, Y+27 ; 0x1b
12d2: 1e 71 andi r17, 0x1E ; 30
 
/* Is the file system object registered? */
if (!fs) return FR_NOT_ENABLED;
 
/* Chekck if the logical drive has been mounted or not */
if (fs->fs_type) {
12d4: f5 01 movw r30, r10
12d6: 84 8d ldd r24, Z+28 ; 0x1c
12d8: 88 23 and r24, r24
12da: 61 f0 breq .+24 ; 0x12f4 <f_open+0x6c>
stat = disk_status(0);
12dc: 80 e0 ldi r24, 0x00 ; 0
12de: 0e 94 bf 0d call 0x1b7e ; 0x1b7e <disk_status>
if (!(stat & STA_NOINIT)) { /* If the physical drive is kept initialized */
12e2: 99 27 eor r25, r25
12e4: 80 fd sbrc r24, 0
12e6: 06 c0 rjmp .+12 ; 0x12f4 <f_open+0x6c>
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
12e8: 11 23 and r17, r17
12ea: 09 f4 brne .+2 ; 0x12ee <f_open+0x66>
12ec: 29 c3 rjmp .+1618 ; 0x1940 <f_open+0x6b8>
12ee: 82 fd sbrc r24, 2
12f0: 07 c1 rjmp .+526 ; 0x1500 <f_open+0x278>
12f2: 26 c3 rjmp .+1612 ; 0x1940 <f_open+0x6b8>
}
}
 
/* The logical drive has not been mounted, following code attempts to mount the logical drive */
 
memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
12f4: 80 e2 ldi r24, 0x20 ; 32
12f6: 92 e0 ldi r25, 0x02 ; 2
12f8: d5 01 movw r26, r10
12fa: 1d 92 st X+, r1
12fc: 01 97 sbiw r24, 0x01 ; 1
12fe: e9 f7 brne .-6 ; 0x12fa <f_open+0x72>
stat = disk_initialize(0); /* Initialize low level disk I/O layer */
1300: 80 e0 ldi r24, 0x00 ; 0
1302: 0e 94 ae 0f call 0x1f5c ; 0x1f5c <disk_initialize>
if (stat & STA_NOINIT) /* Check if the drive is ready */
1306: 99 27 eor r25, r25
1308: 80 ff sbrs r24, 0
130a: 03 c0 rjmp .+6 ; 0x1312 <f_open+0x8a>
130c: 21 e0 ldi r18, 0x01 ; 1
130e: 30 e0 ldi r19, 0x00 ; 0
1310: 45 c3 rjmp .+1674 ; 0x199c <f_open+0x714>
return FR_NOT_READY;
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
1312: 11 23 and r17, r17
1314: 11 f0 breq .+4 ; 0x131a <f_open+0x92>
1316: 82 fd sbrc r24, 2
1318: f3 c0 rjmp .+486 ; 0x1500 <f_open+0x278>
return FR_WRITE_PROTECTED;
#endif
 
/* Search FAT partition on the drive */
fmt = check_fs(bootsect = 0); /* Check sector 0 as an SFD format */
131a: 60 e0 ldi r22, 0x00 ; 0
131c: 70 e0 ldi r23, 0x00 ; 0
131e: 80 e0 ldi r24, 0x00 ; 0
1320: 90 e0 ldi r25, 0x00 ; 0
1322: 0e 94 11 09 call 0x1222 ; 0x1222 <check_fs>
if (fmt == 1) { /* Not a FAT boot record, it may be patitioned */
1326: 81 30 cpi r24, 0x01 ; 1
1328: 21 f0 breq .+8 ; 0x1332 <f_open+0xaa>
132a: ee 24 eor r14, r14
132c: ff 24 eor r15, r15
132e: 87 01 movw r16, r14
1330: 1e c0 rjmp .+60 ; 0x136e <f_open+0xe6>
/* Check a partition listed in top of the partition table */
if (fs->win[MBR_Table+4]) { /* Is the 1st partition existing? */
1332: e2 ee ldi r30, 0xE2 ; 226
1334: f1 e0 ldi r31, 0x01 ; 1
1336: ae 0e add r10, r30
1338: bf 1e adc r11, r31
133a: d5 01 movw r26, r10
133c: 8c 91 ld r24, X
133e: ee e1 ldi r30, 0x1E ; 30
1340: fe ef ldi r31, 0xFE ; 254
1342: ae 0e add r10, r30
1344: bf 1e adc r11, r31
1346: 88 23 and r24, r24
1348: 09 f4 brne .+2 ; 0x134c <f_open+0xc4>
134a: dd c0 rjmp .+442 ; 0x1506 <f_open+0x27e>
bootsect = LD_DWORD(&fs->win[MBR_Table+8]); /* Partition offset in LBA */
134c: 26 ee ldi r18, 0xE6 ; 230
134e: 31 e0 ldi r19, 0x01 ; 1
1350: a2 0e add r10, r18
1352: b3 1e adc r11, r19
1354: d5 01 movw r26, r10
1356: ed 90 ld r14, X+
1358: fd 90 ld r15, X+
135a: 0d 91 ld r16, X+
135c: 1c 91 ld r17, X
135e: ea e1 ldi r30, 0x1A ; 26
1360: fe ef ldi r31, 0xFE ; 254
1362: ae 0e add r10, r30
1364: bf 1e adc r11, r31
fmt = check_fs(bootsect); /* Check the partition */
1366: c8 01 movw r24, r16
1368: b7 01 movw r22, r14
136a: 0e 94 11 09 call 0x1222 ; 0x1222 <check_fs>
}
}
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512) /* No valid FAT patition is found */
136e: 88 23 and r24, r24
1370: 09 f0 breq .+2 ; 0x1374 <f_open+0xec>
1372: c9 c0 rjmp .+402 ; 0x1506 <f_open+0x27e>
1374: f5 01 movw r30, r10
1376: 83 a5 ldd r24, Z+43 ; 0x2b
1378: 94 a5 ldd r25, Z+44 ; 0x2c
137a: 80 50 subi r24, 0x00 ; 0
137c: 92 40 sbci r25, 0x02 ; 2
137e: 09 f0 breq .+2 ; 0x1382 <f_open+0xfa>
1380: c2 c0 rjmp .+388 ; 0x1506 <f_open+0x27e>
return FR_NO_FILESYSTEM;
 
/* Initialize the file system object */
fatsize = LD_WORD(&fs->win[BPB_FATSz16]); /* Number of sectors per FAT */
1382: f5 01 movw r30, r10
1384: 66 a9 ldd r22, Z+54 ; 0x36
1386: 77 a9 ldd r23, Z+55 ; 0x37
if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]);
1388: 61 15 cp r22, r1
138a: 71 05 cpc r23, r1
138c: 19 f0 breq .+6 ; 0x1394 <f_open+0x10c>
}
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
 
/* Initialize the file system object */
fatsize = LD_WORD(&fs->win[BPB_FATSz16]); /* Number of sectors per FAT */
138e: 88 27 eor r24, r24
1390: 99 27 eor r25, r25
1392: 0d c0 rjmp .+26 ; 0x13ae <f_open+0x126>
if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]);
1394: 24 e4 ldi r18, 0x44 ; 68
1396: 30 e0 ldi r19, 0x00 ; 0
1398: a2 0e add r10, r18
139a: b3 1e adc r11, r19
139c: d5 01 movw r26, r10
139e: 6d 91 ld r22, X+
13a0: 7d 91 ld r23, X+
13a2: 8d 91 ld r24, X+
13a4: 9c 91 ld r25, X
13a6: ec eb ldi r30, 0xBC ; 188
13a8: ff ef ldi r31, 0xFF ; 255
13aa: ae 0e add r10, r30
13ac: bf 1e adc r11, r31
fs->sects_fat = (CLUST)fatsize;
13ae: f5 01 movw r30, r10
13b0: 75 8b std Z+21, r23 ; 0x15
13b2: 64 8b std Z+20, r22 ; 0x14
fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */
13b4: 20 a9 ldd r18, Z+48 ; 0x30
13b6: 26 8f std Z+30, r18 ; 0x1e
fatsize *= fs->n_fats; /* (Number of sectors in FAT area) */
13b8: 33 27 eor r19, r19
13ba: 44 27 eor r20, r20
13bc: 55 27 eor r21, r21
13be: 0e 94 e9 10 call 0x21d2 ; 0x21d2 <__mulsi3>
13c2: 3b 01 movw r6, r22
13c4: 4c 01 movw r8, r24
fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */
13c6: a5 01 movw r20, r10
13c8: 42 5d subi r20, 0xD2 ; 210
13ca: 5f 4f sbci r21, 0xFF ; 255
13cc: f5 01 movw r30, r10
13ce: 86 a5 ldd r24, Z+46 ; 0x2e
13d0: 97 a5 ldd r25, Z+47 ; 0x2f
13d2: aa 27 eor r26, r26
13d4: bb 27 eor r27, r27
13d6: e8 0e add r14, r24
13d8: f9 1e adc r15, r25
13da: 0a 1f adc r16, r26
13dc: 1b 1f adc r17, r27
13de: e0 86 std Z+8, r14 ; 0x08
13e0: f1 86 std Z+9, r15 ; 0x09
13e2: 02 87 std Z+10, r16 ; 0x0a
13e4: 13 87 std Z+11, r17 ; 0x0b
fs->sects_clust = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */
13e6: 85 a5 ldd r24, Z+45 ; 0x2d
13e8: 85 8f std Z+29, r24 ; 0x1d
fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]); /* Nmuber of root directory entries */
13ea: 21 a9 ldd r18, Z+49 ; 0x31
13ec: 32 a9 ldd r19, Z+50 ; 0x32
13ee: 33 83 std Z+3, r19 ; 0x03
13f0: 22 83 std Z+2, r18 ; 0x02
totalsect = LD_WORD(&fs->win[BPB_TotSec16]); /* Number of sectors on the file system */
13f2: 63 a9 ldd r22, Z+51 ; 0x33
13f4: 74 a9 ldd r23, Z+52 ; 0x34
if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]);
13f6: 61 15 cp r22, r1
13f8: 71 05 cpc r23, r1
13fa: 21 f0 breq .+8 ; 0x1404 <f_open+0x17c>
fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */
fatsize *= fs->n_fats; /* (Number of sectors in FAT area) */
fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */
fs->sects_clust = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */
fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]); /* Nmuber of root directory entries */
totalsect = LD_WORD(&fs->win[BPB_TotSec16]); /* Number of sectors on the file system */
13fc: 7b 01 movw r14, r22
13fe: 00 27 eor r16, r16
1400: 11 27 eor r17, r17
1402: 0d c0 rjmp .+26 ; 0x141e <f_open+0x196>
if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]);
1404: 80 e4 ldi r24, 0x40 ; 64
1406: 90 e0 ldi r25, 0x00 ; 0
1408: a8 0e add r10, r24
140a: b9 1e adc r11, r25
140c: d5 01 movw r26, r10
140e: ed 90 ld r14, X+
1410: fd 90 ld r15, X+
1412: 0d 91 ld r16, X+
1414: 1c 91 ld r17, X
1416: e0 ec ldi r30, 0xC0 ; 192
1418: ff ef ldi r31, 0xFF ; 255
141a: ae 0e add r10, r30
141c: bf 1e adc r11, r31
fs->max_clust = maxclust = (totalsect /* Last cluster# + 1 */
141e: da 01 movw r26, r20
1420: 8d 91 ld r24, X+
1422: 9c 91 ld r25, X
1424: aa 27 eor r26, r26
1426: bb 27 eor r27, r27
1428: e8 1a sub r14, r24
142a: f9 0a sbc r15, r25
142c: 0a 0b sbc r16, r26
142e: 1b 0b sbc r17, r27
1430: e6 18 sub r14, r6
1432: f7 08 sbc r15, r7
1434: 08 09 sbc r16, r8
1436: 19 09 sbc r17, r9
1438: e4 e0 ldi r30, 0x04 ; 4
143a: 36 95 lsr r19
143c: 27 95 ror r18
143e: ea 95 dec r30
1440: e1 f7 brne .-8 ; 0x143a <f_open+0x1b2>
1442: c9 01 movw r24, r18
1444: aa 27 eor r26, r26
1446: bb 27 eor r27, r27
1448: e8 1a sub r14, r24
144a: f9 0a sbc r15, r25
144c: 0a 0b sbc r16, r26
144e: 1b 0b sbc r17, r27
1450: f5 01 movw r30, r10
1452: 25 8d ldd r18, Z+29 ; 0x1d
1454: 33 27 eor r19, r19
1456: 44 27 eor r20, r20
1458: 55 27 eor r21, r21
145a: c8 01 movw r24, r16
145c: b7 01 movw r22, r14
145e: 0e 94 08 11 call 0x2210 ; 0x2210 <__udivmodsi4>
1462: 2e 5f subi r18, 0xFE ; 254
1464: 3f 4f sbci r19, 0xFF ; 255
1466: 4f 4f sbci r20, 0xFF ; 255
1468: 5f 4f sbci r21, 0xFF ; 255
146a: f5 01 movw r30, r10
146c: 37 8b std Z+23, r19 ; 0x17
146e: 26 8b std Z+22, r18 ; 0x16
- LD_WORD(&fs->win[BPB_RsvdSecCnt]) - fatsize - fs->n_rootdir / 16
) / fs->sects_clust + 2;
 
fmt = FS_FAT12; /* Determine the FAT sub type */
if (maxclust > 0xFF7) fmt = FS_FAT16;
1470: 28 3f cpi r18, 0xF8 ; 248
1472: ff e0 ldi r31, 0x0F ; 15
1474: 3f 07 cpc r19, r31
1476: f0 e0 ldi r31, 0x00 ; 0
1478: 4f 07 cpc r20, r31
147a: f0 e0 ldi r31, 0x00 ; 0
147c: 5f 07 cpc r21, r31
147e: 10 f4 brcc .+4 ; 0x1484 <f_open+0x1fc>
1480: 61 e0 ldi r22, 0x01 ; 1
1482: 06 c0 rjmp .+12 ; 0x1490 <f_open+0x208>
if (maxclust > 0xFFF7)
1484: 28 5f subi r18, 0xF8 ; 248
1486: 3f 4f sbci r19, 0xFF ; 255
1488: 40 40 sbci r20, 0x00 ; 0
148a: 50 40 sbci r21, 0x00 ; 0
148c: e0 f5 brcc .+120 ; 0x1506 <f_open+0x27e>
148e: 62 e0 ldi r22, 0x02 ; 2
fmt = FS_FAT32;
if (fmt == FS_FAT32)
fs->dirbase = LD_DWORD(&fs->win[BPB_RootClus]); /* Root directory start cluster */
else
#endif
fs->dirbase = fs->fatbase + fatsize; /* Root directory start sector (lba) */
1490: f5 01 movw r30, r10
1492: 20 85 ldd r18, Z+8 ; 0x08
1494: 31 85 ldd r19, Z+9 ; 0x09
1496: 42 85 ldd r20, Z+10 ; 0x0a
1498: 53 85 ldd r21, Z+11 ; 0x0b
149a: d4 01 movw r26, r8
149c: c3 01 movw r24, r6
149e: 82 0f add r24, r18
14a0: 93 1f adc r25, r19
14a2: a4 1f adc r26, r20
14a4: b5 1f adc r27, r21
14a6: 84 87 std Z+12, r24 ; 0x0c
14a8: 95 87 std Z+13, r25 ; 0x0d
14aa: a6 87 std Z+14, r26 ; 0x0e
14ac: b7 87 std Z+15, r27 ; 0x0f
fs->database = fs->fatbase + fatsize + fs->n_rootdir / 16; /* Data start sector (lba) */
14ae: 82 81 ldd r24, Z+2 ; 0x02
14b0: 93 81 ldd r25, Z+3 ; 0x03
14b2: 74 e0 ldi r23, 0x04 ; 4
14b4: 96 95 lsr r25
14b6: 87 95 ror r24
14b8: 7a 95 dec r23
14ba: e1 f7 brne .-8 ; 0x14b4 <f_open+0x22c>
14bc: aa 27 eor r26, r26
14be: bb 27 eor r27, r27
14c0: 82 0f add r24, r18
14c2: 93 1f adc r25, r19
14c4: a4 1f adc r26, r20
14c6: b5 1f adc r27, r21
14c8: 86 0d add r24, r6
14ca: 97 1d adc r25, r7
14cc: a8 1d adc r26, r8
14ce: b9 1d adc r27, r9
14d0: 80 8b std Z+16, r24 ; 0x10
14d2: 91 8b std Z+17, r25 ; 0x11
14d4: a2 8b std Z+18, r26 ; 0x12
14d6: b3 8b std Z+19, r27 ; 0x13
fs->fs_type = fmt; /* FAT sub-type */
14d8: 64 8f std Z+28, r22 ; 0x1c
 
#if !_FS_READONLY
fs->free_clust = (CLUST)0xFFFFFFFF;
14da: 8f ef ldi r24, 0xFF ; 255
14dc: 9f ef ldi r25, 0xFF ; 255
14de: 93 8f std Z+27, r25 ; 0x1b
14e0: 82 8f std Z+26, r24 ; 0x1a
fs->free_clust = LD_DWORD(&fs->win[FSI_Free_Count]);
}
}
#endif
#endif
fs->id = ++fsid; /* File system mount ID */
14e2: 80 91 0c 01 lds r24, 0x010C
14e6: 90 91 0d 01 lds r25, 0x010D
14ea: 01 96 adiw r24, 0x01 ; 1
14ec: 90 93 0d 01 sts 0x010D, r25
14f0: 80 93 0c 01 sts 0x010C, r24
14f4: 91 83 std Z+1, r25 ; 0x01
14f6: 80 83 st Z, r24
14f8: 23 c2 rjmp .+1094 ; 0x1940 <f_open+0x6b8>
14fa: 2a e0 ldi r18, 0x0A ; 10
14fc: 30 e0 ldi r19, 0x00 ; 0
14fe: 4e c2 rjmp .+1180 ; 0x199c <f_open+0x714>
1500: 29 e0 ldi r18, 0x09 ; 9
1502: 30 e0 ldi r19, 0x00 ; 0
1504: 4b c2 rjmp .+1174 ; 0x199c <f_open+0x714>
1506: 2b e0 ldi r18, 0x0B ; 11
1508: 30 e0 ldi r19, 0x00 ; 0
150a: 48 c2 rjmp .+1168 ; 0x199c <f_open+0x714>
150c: 36 01 movw r6, r12
)
{
BYTE n, t, c, a, b;
 
 
memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
150e: 4e 01 movw r8, r28
1510: 08 94 sec
1512: 81 1c adc r8, r1
1514: 91 1c adc r9, r1
for (;;) {
ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */
if (ds == 1) return FR_INVALID_NAME;
for (;;) {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
1516: 50 e2 ldi r21, 0x20 ; 32
1518: 45 2e mov r4, r21
151a: 51 2c mov r5, r1
151c: 4e 0e add r4, r30
151e: 5f 1e adc r5, r31
if (dptr[DIR_Name] == 0) /* Has it reached to end of dir? */
return !ds ? FR_NO_FILE : FR_NO_PATH;
if (dptr[DIR_Name] != 0xE5 /* Matched? */
&& !(dptr[DIR_Attr] & AM_VOL)
&& !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
if (!next_dir_entry(dirobj)) /* Next directory pointer */
1520: 4d e0 ldi r20, 0x0D ; 13
1522: 24 2e mov r2, r20
1524: 31 2c mov r3, r1
1526: 2c 0e add r2, r28
1528: 3d 1e adc r3, r29
)
{
BYTE n, t, c, a, b;
 
 
memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
152a: 4b e0 ldi r20, 0x0B ; 11
152c: 50 e0 ldi r21, 0x00 ; 0
152e: 60 e2 ldi r22, 0x20 ; 32
1530: 70 e0 ldi r23, 0x00 ; 0
1532: c4 01 movw r24, r8
1534: 0e 94 aa 10 call 0x2154 ; 0x2154 <memset>
1538: 40 e0 ldi r20, 0x00 ; 0
153a: 68 e0 ldi r22, 0x08 ; 8
153c: 30 e0 ldi r19, 0x00 ; 0
153e: 58 e1 ldi r21, 0x18 ; 24
1540: 02 c0 rjmp .+4 ; 0x1546 <f_open+0x2be>
1542: 48 e0 ldi r20, 0x08 ; 8
1544: 6b e0 ldi r22, 0x0B ; 11
a = 0; b = 0x18; /* NT flag */
n = 0; t = 8;
for (;;) {
c = *(*path)++;
1546: d3 01 movw r26, r6
1548: 2d 91 ld r18, X+
154a: 3d 01 movw r6, r26
if (c == '\0' || c == '/') { /* Reached to end of str or directory separator */
154c: 22 23 and r18, r18
154e: 11 f0 breq .+4 ; 0x1554 <f_open+0x2cc>
1550: 2f 32 cpi r18, 0x2F ; 47
1552: 51 f4 brne .+20 ; 0x1568 <f_open+0x2e0>
if (n == 0) break;
1554: 44 23 and r20, r20
1556: 09 f4 brne .+2 ; 0x155a <f_open+0x2d2>
1558: 43 c0 rjmp .+134 ; 0x15e0 <f_open+0x358>
dirname[11] = _USE_NTFLAG ? (a & b) : 0;
155a: 53 23 and r21, r19
155c: 5c 87 std Y+12, r21 ; 0x0c
return c;
155e: 82 2f mov r24, r18
1560: 99 27 eor r25, r25
1562: 87 fd sbrc r24, 7
1564: 90 95 com r25
1566: 3e c0 rjmp .+124 ; 0x15e4 <f_open+0x35c>
 
memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
a = 0; b = 0x18; /* NT flag */
n = 0; t = 8;
for (;;) {
c = *(*path)++;
1568: 92 2f mov r25, r18
if (c == '\0' || c == '/') { /* Reached to end of str or directory separator */
if (n == 0) break;
dirname[11] = _USE_NTFLAG ? (a & b) : 0;
return c;
}
if (c <= ' ' || c == 0x7F) break; /* Reject invisible chars */
156a: 21 32 cpi r18, 0x21 ; 33
156c: c8 f1 brcs .+114 ; 0x15e0 <f_open+0x358>
156e: 2f 37 cpi r18, 0x7F ; 127
1570: b9 f1 breq .+110 ; 0x15e0 <f_open+0x358>
if (c == '.') {
1572: 2e 32 cpi r18, 0x2E ; 46
1574: 39 f4 brne .+14 ; 0x1584 <f_open+0x2fc>
if (!(a & 1) && n >= 1 && n <= 8) { /* Enter extension part */
1576: 30 fd sbrc r19, 0
1578: 33 c0 rjmp .+102 ; 0x15e0 <f_open+0x358>
157a: 44 23 and r20, r20
157c: 89 f1 breq .+98 ; 0x15e0 <f_open+0x358>
157e: 49 30 cpi r20, 0x09 ; 9
1580: 00 f3 brcs .-64 ; 0x1542 <f_open+0x2ba>
1582: 2e c0 rjmp .+92 ; 0x15e0 <f_open+0x358>
(c >= 0xE0 && c <= 0xFC))) {
if (n == 0 && c == 0xE5) /* Change heading \xE5 to \x05 */
c = 0x05;
a ^= 1; goto md_l2;
}
if (c == '"') break; /* Reject " */
1584: 22 32 cpi r18, 0x22 ; 34
1586: 61 f1 breq .+88 ; 0x15e0 <f_open+0x358>
if (c <= ')') goto md_l1; /* Accept ! # $ % & ' ( ) */
1588: 2a 32 cpi r18, 0x2A ; 42
158a: 08 f1 brcs .+66 ; 0x15ce <f_open+0x346>
if (c <= ',') break; /* Reject * + , */
158c: 2d 32 cpi r18, 0x2D ; 45
158e: 40 f1 brcs .+80 ; 0x15e0 <f_open+0x358>
if (c <= '9') goto md_l1; /* Accept - 0-9 */
1590: 2a 33 cpi r18, 0x3A ; 58
1592: e8 f0 brcs .+58 ; 0x15ce <f_open+0x346>
if (c <= '?') break; /* Reject : ; < = > ? */
1594: 20 34 cpi r18, 0x40 ; 64
1596: 20 f1 brcs .+72 ; 0x15e0 <f_open+0x358>
if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
1598: 30 fd sbrc r19, 0
159a: 19 c0 rjmp .+50 ; 0x15ce <f_open+0x346>
if (c == '|') break; /* Reject | */
159c: 2c 37 cpi r18, 0x7C ; 124
159e: 01 f1 breq .+64 ; 0x15e0 <f_open+0x358>
if (c >= '[' && c <= ']') break;/* Reject [ \ ] */
15a0: 82 2f mov r24, r18
15a2: 8b 55 subi r24, 0x5B ; 91
15a4: 83 30 cpi r24, 0x03 ; 3
15a6: e0 f0 brcs .+56 ; 0x15e0 <f_open+0x358>
if (_USE_NTFLAG && c >= 'A' && c <= 'Z')
15a8: 86 5e subi r24, 0xE6 ; 230
15aa: 8a 31 cpi r24, 0x1A ; 26
15ac: 28 f4 brcc .+10 ; 0x15b8 <f_open+0x330>
(t == 8) ? (b &= ~0x08) : (b &= ~0x10);
15ae: 68 30 cpi r22, 0x08 ; 8
15b0: 11 f4 brne .+4 ; 0x15b6 <f_open+0x32e>
15b2: 57 7f andi r21, 0xF7 ; 247
15b4: 01 c0 rjmp .+2 ; 0x15b8 <f_open+0x330>
15b6: 5f 7e andi r21, 0xEF ; 239
if (c >= 'a' && c <= 'z') { /* Convert to upper case */
15b8: 82 2f mov r24, r18
15ba: 81 56 subi r24, 0x61 ; 97
15bc: 8a 31 cpi r24, 0x1A ; 26
15be: 38 f4 brcc .+14 ; 0x15ce <f_open+0x346>
c -= 0x20;
15c0: 92 2f mov r25, r18
15c2: 90 52 subi r25, 0x20 ; 32
if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
15c4: 68 30 cpi r22, 0x08 ; 8
15c6: 11 f4 brne .+4 ; 0x15cc <f_open+0x344>
15c8: 38 60 ori r19, 0x08 ; 8
15ca: 01 c0 rjmp .+2 ; 0x15ce <f_open+0x346>
15cc: 30 61 ori r19, 0x10 ; 16
}
}
md_l1:
a &= ~1;
md_l2:
if (n >= t) break;
15ce: 46 17 cp r20, r22
15d0: 38 f4 brcc .+14 ; 0x15e0 <f_open+0x358>
c -= 0x20;
if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
}
}
md_l1:
a &= ~1;
15d2: 3e 7f andi r19, 0xFE ; 254
md_l2:
if (n >= t) break;
dirname[n++] = c;
15d4: f4 01 movw r30, r8
15d6: e4 0f add r30, r20
15d8: f1 1d adc r31, r1
15da: 90 83 st Z, r25
15dc: 4f 5f subi r20, 0xFF ; 255
15de: b3 cf rjmp .-154 ; 0x1546 <f_open+0x2be>
15e0: 81 e0 ldi r24, 0x01 ; 1
15e2: 90 e0 ldi r25, 0x00 ; 0
if (*path == '\0') { /* Null path means the root directory */
*dir = NULL; return FR_OK;
}
 
for (;;) {
ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */
15e4: d8 2e mov r13, r24
if (ds == 1) return FR_INVALID_NAME;
15e6: b1 e0 ldi r27, 0x01 ; 1
15e8: 8b 17 cp r24, r27
15ea: 19 f4 brne .+6 ; 0x15f2 <f_open+0x36a>
15ec: 24 e0 ldi r18, 0x04 ; 4
15ee: 30 e0 ldi r19, 0x00 ; 0
15f0: 55 c0 rjmp .+170 ; 0x169c <f_open+0x414>
for (;;) {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
15f2: 6f 89 ldd r22, Y+23 ; 0x17
15f4: 78 8d ldd r23, Y+24 ; 0x18
15f6: 89 8d ldd r24, Y+25 ; 0x19
15f8: 9a 8d ldd r25, Y+26 ; 0x1a
15fa: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
15fe: 88 23 and r24, r24
1600: 19 f4 brne .+6 ; 0x1608 <f_open+0x380>
1602: 28 e0 ldi r18, 0x08 ; 8
1604: 30 e0 ldi r19, 0x00 ; 0
1606: 4a c0 rjmp .+148 ; 0x169c <f_open+0x414>
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
1608: 0f 85 ldd r16, Y+15 ; 0x0f
160a: 18 89 ldd r17, Y+16 ; 0x10
160c: 0f 70 andi r16, 0x0F ; 15
160e: 10 70 andi r17, 0x00 ; 0
1610: 35 e0 ldi r19, 0x05 ; 5
1612: 00 0f add r16, r16
1614: 11 1f adc r17, r17
1616: 3a 95 dec r19
1618: e1 f7 brne .-8 ; 0x1612 <f_open+0x38a>
161a: 04 0d add r16, r4
161c: 15 1d adc r17, r5
if (dptr[DIR_Name] == 0) /* Has it reached to end of dir? */
161e: f8 01 movw r30, r16
1620: 80 81 ld r24, Z
1622: 88 23 and r24, r24
1624: a9 f0 breq .+42 ; 0x1650 <f_open+0x3c8>
return !ds ? FR_NO_FILE : FR_NO_PATH;
if (dptr[DIR_Name] != 0xE5 /* Matched? */
1626: 85 3e cpi r24, 0xE5 ; 229
1628: 71 f0 breq .+28 ; 0x1646 <f_open+0x3be>
162a: f8 01 movw r30, r16
162c: 83 85 ldd r24, Z+11 ; 0x0b
162e: e8 2e mov r14, r24
1630: ff 24 eor r15, r15
1632: e3 fc sbrc r14, 3
1634: 08 c0 rjmp .+16 ; 0x1646 <f_open+0x3be>
1636: 4b e0 ldi r20, 0x0B ; 11
1638: 50 e0 ldi r21, 0x00 ; 0
163a: b4 01 movw r22, r8
163c: c8 01 movw r24, r16
163e: 0e 94 94 10 call 0x2128 ; 0x2128 <memcmp>
1642: 89 2b or r24, r25
1644: 51 f0 breq .+20 ; 0x165a <f_open+0x3d2>
&& !(dptr[DIR_Attr] & AM_VOL)
&& !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
if (!next_dir_entry(dirobj)) /* Next directory pointer */
1646: c1 01 movw r24, r2
1648: 0e 94 cb 04 call 0x996 ; 0x996 <next_dir_entry>
164c: 88 23 and r24, r24
164e: 89 f6 brne .-94 ; 0x15f2 <f_open+0x36a>
return !ds ? FR_NO_FILE : FR_NO_PATH;
1650: dd 20 and r13, r13
1652: 59 f4 brne .+22 ; 0x166a <f_open+0x3e2>
1654: 22 e0 ldi r18, 0x02 ; 2
1656: 30 e0 ldi r19, 0x00 ; 0
1658: 21 c0 rjmp .+66 ; 0x169c <f_open+0x414>
}
if (!ds) { *dir = dptr; return FR_OK; } /* Matched with end of path */
165a: dd 20 and r13, r13
165c: 21 f4 brne .+8 ; 0x1666 <f_open+0x3de>
165e: 68 01 movw r12, r16
1660: 20 e0 ldi r18, 0x00 ; 0
1662: 30 e0 ldi r19, 0x00 ; 0
1664: 1b c0 rjmp .+54 ; 0x169c <f_open+0x414>
if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */
1666: e4 fc sbrc r14, 4
1668: 03 c0 rjmp .+6 ; 0x1670 <f_open+0x3e8>
166a: 23 e0 ldi r18, 0x03 ; 3
166c: 30 e0 ldi r19, 0x00 ; 0
166e: 16 c0 rjmp .+44 ; 0x169c <f_open+0x414>
clust = /* Get cluster# of the directory */
1670: f8 01 movw r30, r16
1672: 82 8d ldd r24, Z+26 ; 0x1a
1674: 93 8d ldd r25, Z+27 ; 0x1b
#if _FAT32
((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dptr[DIR_FstClusLO]);
dirobj->clust = dirobj->sclust = clust; /* Restart scannig with the new directory */
1676: 9c 8b std Y+20, r25 ; 0x14
1678: 8b 8b std Y+19, r24 ; 0x13
167a: 9e 8b std Y+22, r25 ; 0x16
167c: 8d 8b std Y+21, r24 ; 0x15
dirobj->sect = clust2sect(clust);
167e: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
1682: 6f 8b std Y+23, r22 ; 0x17
1684: 78 8f std Y+24, r23 ; 0x18
1686: 89 8f std Y+25, r24 ; 0x19
1688: 9a 8f std Y+26, r25 ; 0x1a
dirobj->index = 2;
168a: 82 e0 ldi r24, 0x02 ; 2
168c: 90 e0 ldi r25, 0x00 ; 0
168e: 98 8b std Y+16, r25 ; 0x10
1690: 8f 87 std Y+15, r24 ; 0x0f
1692: 4b cf rjmp .-362 ; 0x152a <f_open+0x2a2>
1694: 20 e0 ldi r18, 0x00 ; 0
1696: 30 e0 ldi r19, 0x00 ; 0
1698: cc 24 eor r12, r12
169a: dd 24 eor r13, r13
/* Trace the file path */
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
 
#if !_FS_READONLY
/* Create or Open a File */
if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)) {
169c: fb 8d ldd r31, Y+27 ; 0x1b
169e: 4f 2f mov r20, r31
16a0: 55 27 eor r21, r21
16a2: ca 01 movw r24, r20
16a4: 8c 71 andi r24, 0x1C ; 28
16a6: 90 70 andi r25, 0x00 ; 0
16a8: 89 2b or r24, r25
16aa: 09 f4 brne .+2 ; 0x16ae <f_open+0x426>
16ac: fe c0 rjmp .+508 ; 0x18aa <f_open+0x622>
CLUST rs;
DWORD dw;
if (res != FR_OK) { /* No file, create new */
16ae: 21 15 cp r18, r1
16b0: 31 05 cpc r19, r1
16b2: 09 f4 brne .+2 ; 0x16b6 <f_open+0x42e>
16b4: 8f c0 rjmp .+286 ; 0x17d4 <f_open+0x54c>
if (res != FR_NO_FILE) return res;
16b6: 22 30 cpi r18, 0x02 ; 2
16b8: 31 05 cpc r19, r1
16ba: 09 f0 breq .+2 ; 0x16be <f_open+0x436>
16bc: 6f c1 rjmp .+734 ; 0x199c <f_open+0x714>
)
{
CLUST clust;
DWORD sector;
BYTE c, n, *dptr;
FATFS *fs = FatFs;
16be: 60 90 0a 01 lds r6, 0x010A
16c2: 70 90 0b 01 lds r7, 0x010B
 
 
/* Re-initialize directory object */
clust = dirobj->sclust;
16c6: 0b 89 ldd r16, Y+19 ; 0x13
16c8: 1c 89 ldd r17, Y+20 ; 0x14
if (clust) { /* Dyanmic directory table */
16ca: 01 15 cp r16, r1
16cc: 11 05 cpc r17, r1
16ce: 51 f0 breq .+20 ; 0x16e4 <f_open+0x45c>
dirobj->clust = clust;
16d0: 1e 8b std Y+22, r17 ; 0x16
16d2: 0d 8b std Y+21, r16 ; 0x15
dirobj->sect = clust2sect(clust);
16d4: c8 01 movw r24, r16
16d6: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
16da: 6f 8b std Y+23, r22 ; 0x17
16dc: 78 8f std Y+24, r23 ; 0x18
16de: 89 8f std Y+25, r24 ; 0x19
16e0: 9a 8f std Y+26, r25 ; 0x1a
16e2: 09 c0 rjmp .+18 ; 0x16f6 <f_open+0x46e>
} else { /* Static directory table */
dirobj->sect = fs->dirbase;
16e4: f3 01 movw r30, r6
16e6: 84 85 ldd r24, Z+12 ; 0x0c
16e8: 95 85 ldd r25, Z+13 ; 0x0d
16ea: a6 85 ldd r26, Z+14 ; 0x0e
16ec: b7 85 ldd r27, Z+15 ; 0x0f
16ee: 8f 8b std Y+23, r24 ; 0x17
16f0: 98 8f std Y+24, r25 ; 0x18
16f2: a9 8f std Y+25, r26 ; 0x19
16f4: ba 8f std Y+26, r27 ; 0x1a
}
dirobj->index = 0;
16f6: 18 8a std Y+16, r1 ; 0x10
16f8: 1f 86 std Y+15, r1 ; 0x0f
 
do {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
16fa: 20 e2 ldi r18, 0x20 ; 32
16fc: e2 2e mov r14, r18
16fe: f1 2c mov r15, r1
1700: e6 0c add r14, r6
1702: f7 1c adc r15, r7
c = dptr[DIR_Name];
if (c == 0 || c == 0xE5) { /* Found an empty entry! */
*dir = dptr; return FR_OK;
}
} while (next_dir_entry(dirobj)); /* Next directory pointer */
1704: 9d e0 ldi r25, 0x0D ; 13
1706: 49 2e mov r4, r25
1708: 51 2c mov r5, r1
170a: 4c 0e add r4, r28
170c: 5d 1e adc r5, r29
dirobj->sect = fs->dirbase;
}
dirobj->index = 0;
 
do {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
170e: 6f 89 ldd r22, Y+23 ; 0x17
1710: 78 8d ldd r23, Y+24 ; 0x18
1712: 89 8d ldd r24, Y+25 ; 0x19
1714: 9a 8d ldd r25, Y+26 ; 0x1a
1716: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
171a: 88 23 and r24, r24
171c: 09 f4 brne .+2 ; 0x1720 <f_open+0x498>
171e: 0a c1 rjmp .+532 ; 0x1934 <f_open+0x6ac>
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
1720: 47 01 movw r8, r14
1722: cf 84 ldd r12, Y+15 ; 0x0f
1724: d8 88 ldd r13, Y+16 ; 0x10
1726: ff e0 ldi r31, 0x0F ; 15
1728: cf 22 and r12, r31
172a: dd 24 eor r13, r13
172c: 85 e0 ldi r24, 0x05 ; 5
172e: cc 0c add r12, r12
1730: dd 1c adc r13, r13
1732: 8a 95 dec r24
1734: e1 f7 brne .-8 ; 0x172e <f_open+0x4a6>
1736: ce 0c add r12, r14
1738: df 1c adc r13, r15
c = dptr[DIR_Name];
173a: d6 01 movw r26, r12
173c: 8c 91 ld r24, X
if (c == 0 || c == 0xE5) { /* Found an empty entry! */
173e: 88 23 and r24, r24
1740: 09 f4 brne .+2 ; 0x1744 <f_open+0x4bc>
1742: 18 c1 rjmp .+560 ; 0x1974 <f_open+0x6ec>
1744: 85 3e cpi r24, 0xE5 ; 229
1746: 09 f4 brne .+2 ; 0x174a <f_open+0x4c2>
1748: 15 c1 rjmp .+554 ; 0x1974 <f_open+0x6ec>
*dir = dptr; return FR_OK;
}
} while (next_dir_entry(dirobj)); /* Next directory pointer */
174a: c2 01 movw r24, r4
174c: 0e 94 cb 04 call 0x996 ; 0x996 <next_dir_entry>
1750: 88 23 and r24, r24
1752: e9 f6 brne .-70 ; 0x170e <f_open+0x486>
/* Reached to end of the directory table */
 
/* Abort when static table or could not stretch dynamic table */
if (!clust || !(clust = create_chain(dirobj->clust))) return FR_DENIED;
1754: 01 2b or r16, r17
1756: 09 f4 brne .+2 ; 0x175a <f_open+0x4d2>
1758: ea c0 rjmp .+468 ; 0x192e <f_open+0x6a6>
175a: 8d 89 ldd r24, Y+21 ; 0x15
175c: 9e 89 ldd r25, Y+22 ; 0x16
175e: 0e 94 25 05 call 0xa4a ; 0xa4a <create_chain>
1762: 8c 01 movw r16, r24
1764: 00 97 sbiw r24, 0x00 ; 0
1766: 09 f4 brne .+2 ; 0x176a <f_open+0x4e2>
1768: e2 c0 rjmp .+452 ; 0x192e <f_open+0x6a6>
if (clust == 1 || !move_window(0)) return FR_RW_ERROR;
176a: 01 97 sbiw r24, 0x01 ; 1
176c: 09 f4 brne .+2 ; 0x1770 <f_open+0x4e8>
176e: e2 c0 rjmp .+452 ; 0x1934 <f_open+0x6ac>
1770: 60 e0 ldi r22, 0x00 ; 0
1772: 70 e0 ldi r23, 0x00 ; 0
1774: 80 e0 ldi r24, 0x00 ; 0
1776: 90 e0 ldi r25, 0x00 ; 0
1778: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
177c: 88 23 and r24, r24
177e: 09 f4 brne .+2 ; 0x1782 <f_open+0x4fa>
1780: d9 c0 rjmp .+434 ; 0x1934 <f_open+0x6ac>
 
fs->winsect = sector = clust2sect(clust); /* Cleanup the expanded table */
1782: c8 01 movw r24, r16
1784: 0e 94 18 03 call 0x630 ; 0x630 <clust2sect>
1788: 6b 01 movw r12, r22
178a: 7c 01 movw r14, r24
178c: f3 01 movw r30, r6
178e: 64 83 std Z+4, r22 ; 0x04
1790: 75 83 std Z+5, r23 ; 0x05
1792: 86 83 std Z+6, r24 ; 0x06
1794: 97 83 std Z+7, r25 ; 0x07
memset(fs->win, 0, 512);
1796: 80 e0 ldi r24, 0x00 ; 0
1798: 92 e0 ldi r25, 0x02 ; 2
179a: d4 01 movw r26, r8
179c: 1d 92 st X+, r1
179e: 01 97 sbiw r24, 0x01 ; 1
17a0: e9 f7 brne .-6 ; 0x179c <f_open+0x514>
for (n = fs->sects_clust; n; n--) {
17a2: 15 8d ldd r17, Z+29 ; 0x1d
17a4: 10 c0 rjmp .+32 ; 0x17c6 <f_open+0x53e>
if (disk_write(0, fs->win, sector, 1) != RES_OK)
17a6: 01 e0 ldi r16, 0x01 ; 1
17a8: a7 01 movw r20, r14
17aa: 96 01 movw r18, r12
17ac: b4 01 movw r22, r8
17ae: 80 e0 ldi r24, 0x00 ; 0
17b0: 0e 94 d3 0e call 0x1da6 ; 0x1da6 <disk_write>
17b4: 89 2b or r24, r25
17b6: 09 f0 breq .+2 ; 0x17ba <f_open+0x532>
17b8: bd c0 rjmp .+378 ; 0x1934 <f_open+0x6ac>
return FR_RW_ERROR;
sector++;
17ba: 08 94 sec
17bc: c1 1c adc r12, r1
17be: d1 1c adc r13, r1
17c0: e1 1c adc r14, r1
17c2: f1 1c adc r15, r1
if (!clust || !(clust = create_chain(dirobj->clust))) return FR_DENIED;
if (clust == 1 || !move_window(0)) return FR_RW_ERROR;
 
fs->winsect = sector = clust2sect(clust); /* Cleanup the expanded table */
memset(fs->win, 0, 512);
for (n = fs->sects_clust; n; n--) {
17c4: 11 50 subi r17, 0x01 ; 1
17c6: 11 23 and r17, r17
17c8: 71 f7 brne .-36 ; 0x17a6 <f_open+0x51e>
if (disk_write(0, fs->win, sector, 1) != RES_OK)
return FR_RW_ERROR;
sector++;
}
fs->winflag = 1;
17ca: 81 e0 ldi r24, 0x01 ; 1
17cc: f3 01 movw r30, r6
17ce: 87 8f std Z+31, r24 ; 0x1f
17d0: 64 01 movw r12, r8
17d2: d0 c0 rjmp .+416 ; 0x1974 <f_open+0x6ec>
memset(dir, 0, 32); /* Initialize the new entry */
memcpy(&dir[DIR_Name], fn, 8+3);
dir[DIR_NTres] = fn[11];
mode |= FA_CREATE_ALWAYS;
} else { /* Any object is already existing */
if (mode & FA_CREATE_NEW) /* Cannot create new */
17d4: 42 ff sbrs r20, 2
17d6: 03 c0 rjmp .+6 ; 0x17de <f_open+0x556>
17d8: 27 e0 ldi r18, 0x07 ; 7
17da: 30 e0 ldi r19, 0x00 ; 0
17dc: df c0 rjmp .+446 ; 0x199c <f_open+0x714>
return FR_EXIST;
if (dir == NULL || (dir[DIR_Attr] & (AM_RDO|AM_DIR))) /* Cannot overwrite (R/O or DIR) */
17de: c1 14 cp r12, r1
17e0: d1 04 cpc r13, r1
17e2: 09 f4 brne .+2 ; 0x17e6 <f_open+0x55e>
17e4: a4 c0 rjmp .+328 ; 0x192e <f_open+0x6a6>
17e6: f6 01 movw r30, r12
17e8: 83 85 ldd r24, Z+11 ; 0x0b
17ea: 81 71 andi r24, 0x11 ; 17
17ec: 09 f0 breq .+2 ; 0x17f0 <f_open+0x568>
17ee: 9f c0 rjmp .+318 ; 0x192e <f_open+0x6a6>
return FR_DENIED;
if (mode & FA_CREATE_ALWAYS) { /* Resize it to zero */
17f0: 43 ff sbrs r20, 3
17f2: 46 c0 rjmp .+140 ; 0x1880 <f_open+0x5f8>
#if _FAT32
rs = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]);
ST_WORD(&dir[DIR_FstClusHI], 0);
#else
rs = LD_WORD(&dir[DIR_FstClusLO]);
17f4: 82 8c ldd r8, Z+26 ; 0x1a
17f6: 93 8c ldd r9, Z+27 ; 0x1b
#endif
ST_WORD(&dir[DIR_FstClusLO], 0); /* cluster = 0 */
17f8: 13 8e std Z+27, r1 ; 0x1b
17fa: 12 8e std Z+26, r1 ; 0x1a
ST_DWORD(&dir[DIR_FileSize], 0); /* size = 0 */
17fc: 14 8e std Z+28, r1 ; 0x1c
17fe: 15 8e std Z+29, r1 ; 0x1d
1800: 16 8e std Z+30, r1 ; 0x1e
1802: 17 8e std Z+31, r1 ; 0x1f
fs->winflag = 1;
1804: 81 e0 ldi r24, 0x01 ; 1
1806: f5 01 movw r30, r10
1808: 87 8f std Z+31, r24 ; 0x1f
dw = fs->winsect; /* Remove the cluster chain */
180a: 24 80 ldd r2, Z+4 ; 0x04
180c: 35 80 ldd r3, Z+5 ; 0x05
180e: 46 80 ldd r4, Z+6 ; 0x06
1810: 57 80 ldd r5, Z+7 ; 0x07
BOOL remove_chain ( /* TRUE: successful, FALSE: failed */
CLUST clust /* Cluster# to remove chain from */
)
{
CLUST nxt;
FATFS *fs = FatFs;
1812: e0 90 0a 01 lds r14, 0x010A
1816: f0 90 0b 01 lds r15, 0x010B
181a: 84 01 movw r16, r8
181c: 1b c0 rjmp .+54 ; 0x1854 <f_open+0x5cc>
 
 
while (clust >= 2 && clust < fs->max_clust) {
nxt = get_cluster(clust);
181e: c8 01 movw r24, r16
1820: 0e 94 4f 04 call 0x89e ; 0x89e <get_cluster>
1824: 3c 01 movw r6, r24
if (nxt == 1) return FALSE;
1826: 01 97 sbiw r24, 0x01 ; 1
1828: 09 f4 brne .+2 ; 0x182c <f_open+0x5a4>
182a: 84 c0 rjmp .+264 ; 0x1934 <f_open+0x6ac>
if (!put_cluster(clust, 0)) return FALSE;
182c: 60 e0 ldi r22, 0x00 ; 0
182e: 70 e0 ldi r23, 0x00 ; 0
1830: c8 01 movw r24, r16
1832: 0e 94 c1 03 call 0x782 ; 0x782 <put_cluster>
1836: 88 23 and r24, r24
1838: 09 f4 brne .+2 ; 0x183c <f_open+0x5b4>
183a: 7c c0 rjmp .+248 ; 0x1934 <f_open+0x6ac>
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
183c: f7 01 movw r30, r14
183e: 82 8d ldd r24, Z+26 ; 0x1a
1840: 93 8d ldd r25, Z+27 ; 0x1b
1842: ff ef ldi r31, 0xFF ; 255
1844: 8f 3f cpi r24, 0xFF ; 255
1846: 9f 07 cpc r25, r31
1848: 21 f0 breq .+8 ; 0x1852 <f_open+0x5ca>
fs->free_clust++;
184a: 01 96 adiw r24, 0x01 ; 1
184c: f7 01 movw r30, r14
184e: 93 8f std Z+27, r25 ; 0x1b
1850: 82 8f std Z+26, r24 ; 0x1a
1852: 83 01 movw r16, r6
{
CLUST nxt;
FATFS *fs = FatFs;
 
 
while (clust >= 2 && clust < fs->max_clust) {
1854: 02 30 cpi r16, 0x02 ; 2
1856: 11 05 cpc r17, r1
1858: 30 f0 brcs .+12 ; 0x1866 <f_open+0x5de>
185a: f7 01 movw r30, r14
185c: 86 89 ldd r24, Z+22 ; 0x16
185e: 97 89 ldd r25, Z+23 ; 0x17
1860: 08 17 cp r16, r24
1862: 19 07 cpc r17, r25
1864: e0 f2 brcs .-72 ; 0x181e <f_open+0x596>
#endif
ST_WORD(&dir[DIR_FstClusLO], 0); /* cluster = 0 */
ST_DWORD(&dir[DIR_FileSize], 0); /* size = 0 */
fs->winflag = 1;
dw = fs->winsect; /* Remove the cluster chain */
if (!remove_chain(rs) || !move_window(dw))
1866: c2 01 movw r24, r4
1868: b1 01 movw r22, r2
186a: 0e 94 55 03 call 0x6aa ; 0x6aa <move_window>
186e: 88 23 and r24, r24
1870: 09 f4 brne .+2 ; 0x1874 <f_open+0x5ec>
1872: 60 c0 rjmp .+192 ; 0x1934 <f_open+0x6ac>
return FR_RW_ERROR;
fs->last_clust = rs - 1; /* Reuse the cluster hole */
1874: 08 94 sec
1876: 81 08 sbc r8, r1
1878: 91 08 sbc r9, r1
187a: f5 01 movw r30, r10
187c: 91 8e std Z+25, r9 ; 0x19
187e: 80 8e std Z+24, r8 ; 0x18
}
}
if (mode & FA_CREATE_ALWAYS) {
1880: fb 8d ldd r31, Y+27 ; 0x1b
1882: f3 ff sbrs r31, 3
1884: 23 c0 rjmp .+70 ; 0x18cc <f_open+0x644>
dir[DIR_Attr] = AM_ARC; /* New attribute */
1886: 80 e2 ldi r24, 0x20 ; 32
1888: f6 01 movw r30, r12
188a: 83 87 std Z+11, r24 ; 0x0b
dw = get_fattime();
188c: 0e 94 bb 00 call 0x176 ; 0x176 <get_fattime>
ST_DWORD(&dir[DIR_WrtTime], dw); /* Updated time */
1890: f6 01 movw r30, r12
1892: 66 8b std Z+22, r22 ; 0x16
1894: 77 8b std Z+23, r23 ; 0x17
1896: 80 8f std Z+24, r24 ; 0x18
1898: 91 8f std Z+25, r25 ; 0x19
ST_DWORD(&dir[DIR_CrtTime], dw); /* Created time */
189a: 66 87 std Z+14, r22 ; 0x0e
189c: 77 87 std Z+15, r23 ; 0x0f
189e: 80 8b std Z+16, r24 ; 0x10
18a0: 91 8b std Z+17, r25 ; 0x11
fs->winflag = 1;
18a2: 81 e0 ldi r24, 0x01 ; 1
18a4: f5 01 movw r30, r10
18a6: 87 8f std Z+31, r24 ; 0x1f
18a8: 11 c0 rjmp .+34 ; 0x18cc <f_open+0x644>
}
}
/* Open a File */
else {
#endif /* !_FS_READONLY */
if (res != FR_OK) return res; /* Trace failed */
18aa: 21 15 cp r18, r1
18ac: 31 05 cpc r19, r1
18ae: 09 f0 breq .+2 ; 0x18b2 <f_open+0x62a>
18b0: 75 c0 rjmp .+234 ; 0x199c <f_open+0x714>
if (dir == NULL || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */
18b2: c1 14 cp r12, r1
18b4: d1 04 cpc r13, r1
18b6: 09 f4 brne .+2 ; 0x18ba <f_open+0x632>
18b8: 40 c0 rjmp .+128 ; 0x193a <f_open+0x6b2>
18ba: f6 01 movw r30, r12
18bc: 83 85 ldd r24, Z+11 ; 0x0b
18be: 99 27 eor r25, r25
18c0: 84 fd sbrc r24, 4
18c2: 3b c0 rjmp .+118 ; 0x193a <f_open+0x6b2>
return FR_NO_FILE;
#if !_FS_READONLY
if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */
18c4: 41 ff sbrs r20, 1
18c6: 02 c0 rjmp .+4 ; 0x18cc <f_open+0x644>
18c8: 80 fd sbrc r24, 0
18ca: 31 c0 rjmp .+98 ; 0x192e <f_open+0x6a6>
return FR_DENIED;
}
 
fp->dir_sect = fs->winsect; /* Pointer to the directory entry */
18cc: f5 01 movw r30, r10
18ce: 84 81 ldd r24, Z+4 ; 0x04
18d0: 95 81 ldd r25, Z+5 ; 0x05
18d2: a6 81 ldd r26, Z+6 ; 0x06
18d4: b7 81 ldd r27, Z+7 ; 0x07
18d6: ec 8d ldd r30, Y+28 ; 0x1c
18d8: fd 8d ldd r31, Y+29 ; 0x1d
18da: 86 8b std Z+22, r24 ; 0x16
18dc: 97 8b std Z+23, r25 ; 0x17
18de: a0 8f std Z+24, r26 ; 0x18
18e0: b1 8f std Z+25, r27 ; 0x19
fp->dir_ptr = dir;
18e2: d3 8e std Z+27, r13 ; 0x1b
18e4: c2 8e std Z+26, r12 ; 0x1a
#endif
fp->flag = mode; /* File access mode */
18e6: 2b 8d ldd r18, Y+27 ; 0x1b
18e8: 22 83 std Z+2, r18 ; 0x02
fp->org_clust = /* File start cluster */
18ea: f6 01 movw r30, r12
18ec: 82 8d ldd r24, Z+26 ; 0x1a
18ee: 93 8d ldd r25, Z+27 ; 0x1b
18f0: ec 8d ldd r30, Y+28 ; 0x1c
18f2: fd 8d ldd r31, Y+29 ; 0x1d
18f4: 97 87 std Z+15, r25 ; 0x0f
18f6: 86 87 std Z+14, r24 ; 0x0e
#if _FAT32
((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dir[DIR_FstClusLO]);
fp->fsize = LD_DWORD(&dir[DIR_FileSize]); /* File size */
18f8: f6 01 movw r30, r12
18fa: 84 8d ldd r24, Z+28 ; 0x1c
18fc: 95 8d ldd r25, Z+29 ; 0x1d
18fe: a6 8d ldd r26, Z+30 ; 0x1e
1900: b7 8d ldd r27, Z+31 ; 0x1f
1902: ec 8d ldd r30, Y+28 ; 0x1c
1904: fd 8d ldd r31, Y+29 ; 0x1d
1906: 82 87 std Z+10, r24 ; 0x0a
1908: 93 87 std Z+11, r25 ; 0x0b
190a: a4 87 std Z+12, r26 ; 0x0c
190c: b5 87 std Z+13, r27 ; 0x0d
fp->fptr = 0; /* File ptr */
190e: 16 82 std Z+6, r1 ; 0x06
1910: 17 82 std Z+7, r1 ; 0x07
1912: 10 86 std Z+8, r1 ; 0x08
1914: 11 86 std Z+9, r1 ; 0x09
fp->sect_clust = 1; /* Sector counter */
1916: 81 e0 ldi r24, 0x01 ; 1
1918: 83 83 std Z+3, r24 ; 0x03
fp->fs = fs; fp->id = fs->id; /* Owner file system object of the file */
191a: b5 82 std Z+5, r11 ; 0x05
191c: a4 82 std Z+4, r10 ; 0x04
191e: d5 01 movw r26, r10
1920: 8d 91 ld r24, X+
1922: 9c 91 ld r25, X
1924: 91 83 std Z+1, r25 ; 0x01
1926: 80 83 st Z, r24
1928: 20 e0 ldi r18, 0x00 ; 0
192a: 30 e0 ldi r19, 0x00 ; 0
192c: 37 c0 rjmp .+110 ; 0x199c <f_open+0x714>
 
return FR_OK;
192e: 26 e0 ldi r18, 0x06 ; 6
1930: 30 e0 ldi r19, 0x00 ; 0
1932: 34 c0 rjmp .+104 ; 0x199c <f_open+0x714>
1934: 28 e0 ldi r18, 0x08 ; 8
1936: 30 e0 ldi r19, 0x00 ; 0
1938: 31 c0 rjmp .+98 ; 0x199c <f_open+0x714>
193a: 22 e0 ldi r18, 0x02 ; 2
193c: 30 e0 ldi r19, 0x00 ; 0
193e: 2e c0 rjmp .+92 ; 0x199c <f_open+0x714>
)
{
CLUST clust;
char ds;
BYTE *dptr = NULL;
FATFS *fs = FatFs;
1940: e0 91 0a 01 lds r30, 0x010A
1944: f0 91 0b 01 lds r31, 0x010B
 
/* Initialize directory object */
clust = fs->dirbase;
1948: 84 85 ldd r24, Z+12 ; 0x0c
194a: 95 85 ldd r25, Z+13 ; 0x0d
dirobj->clust = dirobj->sclust = clust;
dirobj->sect = clust2sect(clust);
} else
#endif
{
dirobj->clust = dirobj->sclust = 0;
194c: 1c 8a std Y+20, r1 ; 0x14
194e: 1b 8a std Y+19, r1 ; 0x13
1950: 1e 8a std Y+22, r1 ; 0x16
1952: 1d 8a std Y+21, r1 ; 0x15
dirobj->sect = clust;
1954: aa 27 eor r26, r26
1956: bb 27 eor r27, r27
1958: 8f 8b std Y+23, r24 ; 0x17
195a: 98 8f std Y+24, r25 ; 0x18
195c: a9 8f std Y+25, r26 ; 0x19
195e: ba 8f std Y+26, r27 ; 0x1a
}
dirobj->index = 0;
1960: 18 8a std Y+16, r1 ; 0x10
1962: 1f 86 std Y+15, r1 ; 0x0f
dirobj->fs = fs;
1964: fa 8b std Y+18, r31 ; 0x12
1966: e9 8b std Y+17, r30 ; 0x11
 
if (*path == '\0') { /* Null path means the root directory */
1968: d6 01 movw r26, r12
196a: 8c 91 ld r24, X
196c: 88 23 and r24, r24
196e: 09 f4 brne .+2 ; 0x1972 <f_open+0x6ea>
1970: 91 ce rjmp .-734 ; 0x1694 <f_open+0x40c>
1972: cc cd rjmp .-1128 ; 0x150c <f_open+0x284>
DWORD dw;
if (res != FR_OK) { /* No file, create new */
if (res != FR_NO_FILE) return res;
res = reserve_direntry(&dirobj, &dir);
if (res != FR_OK) return res;
memset(dir, 0, 32); /* Initialize the new entry */
1974: 80 e2 ldi r24, 0x20 ; 32
1976: f6 01 movw r30, r12
1978: 11 92 st Z+, r1
197a: 8a 95 dec r24
197c: e9 f7 brne .-6 ; 0x1978 <f_open+0x6f0>
memcpy(&dir[DIR_Name], fn, 8+3);
197e: f6 01 movw r30, r12
1980: de 01 movw r26, r28
1982: 11 96 adiw r26, 0x01 ; 1
1984: 8b e0 ldi r24, 0x0B ; 11
1986: 0d 90 ld r0, X+
1988: 01 92 st Z+, r0
198a: 81 50 subi r24, 0x01 ; 1
198c: e1 f7 brne .-8 ; 0x1986 <f_open+0x6fe>
dir[DIR_NTres] = fn[11];
198e: 8c 85 ldd r24, Y+12 ; 0x0c
1990: f6 01 movw r30, r12
1992: 84 87 std Z+12, r24 ; 0x0c
mode |= FA_CREATE_ALWAYS;
1994: fb 8d ldd r31, Y+27 ; 0x1b
1996: f8 60 ori r31, 0x08 ; 8
1998: fb 8f std Y+27, r31 ; 0x1b
199a: 72 cf rjmp .-284 ; 0x1880 <f_open+0x5f8>
fp->fptr = 0; /* File ptr */
fp->sect_clust = 1; /* Sector counter */
fp->fs = fs; fp->id = fs->id; /* Owner file system object of the file */
 
return FR_OK;
}
199c: c9 01 movw r24, r18
199e: e2 e1 ldi r30, 0x12 ; 18
19a0: 6d 96 adiw r28, 0x1d ; 29
19a2: 0c 94 46 11 jmp 0x228c ; 0x228c <__epilogue_restores__>
 
000019a6 <wait_ready>:
/* Wait for card ready */
/*-----------------------------------------------------------------------*/
 
static
BYTE wait_ready (void)
{
19a6: 82 e3 ldi r24, 0x32 ; 50
19a8: 80 93 10 01 sts 0x0110, r24
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
19ac: 8f ef ldi r24, 0xFF ; 255
19ae: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
19b0: 0d b4 in r0, 0x2d ; 45
19b2: 07 fe sbrs r0, 7
19b4: fd cf rjmp .-6 ; 0x19b0 <wait_ready+0xa>
return SPDR;
19b6: 8e b5 in r24, 0x2e ; 46
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
19b8: 8f ef ldi r24, 0xFF ; 255
19ba: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
19bc: 0d b4 in r0, 0x2d ; 45
19be: 07 fe sbrs r0, 7
19c0: fd cf rjmp .-6 ; 0x19bc <wait_ready+0x16>
return SPDR;
19c2: 8e b5 in r24, 0x2e ; 46
19c4: 28 2f mov r18, r24
19c6: 33 27 eor r19, r19
 
Timer2 = 50; /* Wait for ready in timeout of 500ms */
rcvr_spi();
do
res = rcvr_spi();
while ((res != 0xFF) && Timer2);
19c8: 8f 3f cpi r24, 0xFF ; 255
19ca: 21 f0 breq .+8 ; 0x19d4 <wait_ready+0x2e>
19cc: 80 91 10 01 lds r24, 0x0110
19d0: 88 23 and r24, r24
19d2: 91 f7 brne .-28 ; 0x19b8 <wait_ready+0x12>
 
return res;
}
19d4: c9 01 movw r24, r18
19d6: 08 95 ret
 
000019d8 <rcvr_datablock>:
static
BOOL rcvr_datablock (
BYTE *buff, /* Data buffer to store received data */
UINT btr /* Byte count (must be even number) */
)
{
19d8: fc 01 movw r30, r24
BYTE token;
 
 
Timer1 = 10;
19da: 8a e0 ldi r24, 0x0A ; 10
19dc: 80 93 0f 01 sts 0x010F, r24
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
19e0: 8f ef ldi r24, 0xFF ; 255
19e2: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
19e4: 0d b4 in r0, 0x2d ; 45
19e6: 07 fe sbrs r0, 7
19e8: fd cf rjmp .-6 ; 0x19e4 <rcvr_datablock+0xc>
return SPDR;
19ea: 8e b5 in r24, 0x2e ; 46
 
 
Timer1 = 10;
do { /* Wait for data packet in timeout of 100ms */
token = rcvr_spi();
} while ((token == 0xFF) && Timer1);
19ec: 8f 3f cpi r24, 0xFF ; 255
19ee: 29 f4 brne .+10 ; 0x19fa <rcvr_datablock+0x22>
19f0: 80 91 0f 01 lds r24, 0x010F
19f4: 88 23 and r24, r24
19f6: 29 f1 breq .+74 ; 0x1a42 <rcvr_datablock+0x6a>
19f8: f3 cf rjmp .-26 ; 0x19e0 <rcvr_datablock+0x8>
if(token != 0xFE) return FALSE; /* If not valid data token, retutn with error */
19fa: 8e 3f cpi r24, 0xFE ; 254
19fc: 11 f5 brne .+68 ; 0x1a42 <rcvr_datablock+0x6a>
 
do { /* Receive the data block into buffer */
rcvr_spi_m(buff++);
19fe: 8f ef ldi r24, 0xFF ; 255
1a00: 8e bd out 0x2e, r24 ; 46
1a02: 0d b4 in r0, 0x2d ; 45
1a04: 07 fe sbrs r0, 7
1a06: fd cf rjmp .-6 ; 0x1a02 <rcvr_datablock+0x2a>
1a08: 8e b5 in r24, 0x2e ; 46
1a0a: 80 83 st Z, r24
rcvr_spi_m(buff++);
1a0c: 8f ef ldi r24, 0xFF ; 255
1a0e: 8e bd out 0x2e, r24 ; 46
1a10: 0d b4 in r0, 0x2d ; 45
1a12: 07 fe sbrs r0, 7
1a14: fd cf rjmp .-6 ; 0x1a10 <rcvr_datablock+0x38>
1a16: 8e b5 in r24, 0x2e ; 46
1a18: 81 83 std Z+1, r24 ; 0x01
} while (btr -= 2);
1a1a: 62 50 subi r22, 0x02 ; 2
1a1c: 70 40 sbci r23, 0x00 ; 0
1a1e: 11 f0 breq .+4 ; 0x1a24 <rcvr_datablock+0x4c>
1a20: 32 96 adiw r30, 0x02 ; 2
1a22: ed cf rjmp .-38 ; 0x19fe <rcvr_datablock+0x26>
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1a24: 8f ef ldi r24, 0xFF ; 255
1a26: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1a28: 0d b4 in r0, 0x2d ; 45
1a2a: 07 fe sbrs r0, 7
1a2c: fd cf rjmp .-6 ; 0x1a28 <rcvr_datablock+0x50>
return SPDR;
1a2e: 8e b5 in r24, 0x2e ; 46
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1a30: 8f ef ldi r24, 0xFF ; 255
1a32: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1a34: 0d b4 in r0, 0x2d ; 45
1a36: 07 fe sbrs r0, 7
1a38: fd cf rjmp .-6 ; 0x1a34 <rcvr_datablock+0x5c>
return SPDR;
1a3a: 8e b5 in r24, 0x2e ; 46
1a3c: 81 e0 ldi r24, 0x01 ; 1
1a3e: 90 e0 ldi r25, 0x00 ; 0
1a40: 08 95 ret
rcvr_spi_m(buff++);
} while (btr -= 2);
rcvr_spi(); /* Discard CRC */
rcvr_spi();
 
return TRUE; /* Return with success */
1a42: 80 e0 ldi r24, 0x00 ; 0
1a44: 90 e0 ldi r25, 0x00 ; 0
}
1a46: 08 95 ret
 
00001a48 <xmit_datablock>:
static
BOOL xmit_datablock (
const BYTE *buff, /* 512 byte data block to be transmitted */
BYTE token /* Data/Stop token */
)
{
1a48: 1f 93 push r17
1a4a: cf 93 push r28
1a4c: df 93 push r29
1a4e: ec 01 movw r28, r24
1a50: 16 2f mov r17, r22
BYTE resp, wc;
 
 
if (wait_ready() != 0xFF) return FALSE;
1a52: 0e 94 d3 0c call 0x19a6 ; 0x19a6 <wait_ready>
1a56: 8f 3f cpi r24, 0xFF ; 255
1a58: 19 f0 breq .+6 ; 0x1a60 <xmit_datablock+0x18>
1a5a: 80 e0 ldi r24, 0x00 ; 0
1a5c: 90 e0 ldi r25, 0x00 ; 0
1a5e: 31 c0 rjmp .+98 ; 0x1ac2 <xmit_datablock+0x7a>
 
xmit_spi(token); /* Xmit data token */
1a60: 1e bd out 0x2e, r17 ; 46
1a62: 0d b4 in r0, 0x2d ; 45
1a64: 07 fe sbrs r0, 7
1a66: fd cf rjmp .-6 ; 0x1a62 <xmit_datablock+0x1a>
if (token != 0xFD) { /* Is data token */
1a68: 1d 3f cpi r17, 0xFD ; 253
1a6a: 19 f4 brne .+6 ; 0x1a72 <xmit_datablock+0x2a>
1a6c: 81 e0 ldi r24, 0x01 ; 1
1a6e: 90 e0 ldi r25, 0x00 ; 0
1a70: 28 c0 rjmp .+80 ; 0x1ac2 <xmit_datablock+0x7a>
1a72: 90 e0 ldi r25, 0x00 ; 0
wc = 0;
do { /* Xmit the 512 byte data block to MMC */
xmit_spi(*buff++);
1a74: 88 81 ld r24, Y
1a76: 8e bd out 0x2e, r24 ; 46
1a78: 0d b4 in r0, 0x2d ; 45
1a7a: 07 fe sbrs r0, 7
1a7c: fd cf rjmp .-6 ; 0x1a78 <xmit_datablock+0x30>
xmit_spi(*buff++);
1a7e: 89 81 ldd r24, Y+1 ; 0x01
1a80: 8e bd out 0x2e, r24 ; 46
1a82: 0d b4 in r0, 0x2d ; 45
1a84: 07 fe sbrs r0, 7
1a86: fd cf rjmp .-6 ; 0x1a82 <xmit_datablock+0x3a>
} while (--wc);
1a88: 91 50 subi r25, 0x01 ; 1
1a8a: 11 f0 breq .+4 ; 0x1a90 <xmit_datablock+0x48>
1a8c: 22 96 adiw r28, 0x02 ; 2
1a8e: f2 cf rjmp .-28 ; 0x1a74 <xmit_datablock+0x2c>
xmit_spi(0xFF); /* CRC (Dummy) */
1a90: 8f ef ldi r24, 0xFF ; 255
1a92: 8e bd out 0x2e, r24 ; 46
1a94: 0d b4 in r0, 0x2d ; 45
1a96: 07 fe sbrs r0, 7
1a98: fd cf rjmp .-6 ; 0x1a94 <xmit_datablock+0x4c>
xmit_spi(0xFF);
1a9a: 8f ef ldi r24, 0xFF ; 255
1a9c: 8e bd out 0x2e, r24 ; 46
1a9e: 0d b4 in r0, 0x2d ; 45
1aa0: 07 fe sbrs r0, 7
1aa2: fd cf rjmp .-6 ; 0x1a9e <xmit_datablock+0x56>
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1aa4: 8f ef ldi r24, 0xFF ; 255
1aa6: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1aa8: 0d b4 in r0, 0x2d ; 45
1aaa: 07 fe sbrs r0, 7
1aac: fd cf rjmp .-6 ; 0x1aa8 <xmit_datablock+0x60>
return SPDR;
1aae: 8e b5 in r24, 0x2e ; 46
1ab0: 90 e0 ldi r25, 0x00 ; 0
1ab2: 8f 71 andi r24, 0x1F ; 31
1ab4: 85 30 cpi r24, 0x05 ; 5
1ab6: 09 f0 breq .+2 ; 0x1aba <xmit_datablock+0x72>
1ab8: 91 e0 ldi r25, 0x01 ; 1
1aba: 81 e0 ldi r24, 0x01 ; 1
1abc: 98 27 eor r25, r24
1abe: 89 2f mov r24, r25
1ac0: 99 27 eor r25, r25
1ac2: df 91 pop r29
1ac4: cf 91 pop r28
1ac6: 1f 91 pop r17
1ac8: 08 95 ret
 
00001aca <send_cmd>:
static
BYTE send_cmd (
BYTE cmd, /* Command byte */
DWORD arg /* Argument */
)
{
1aca: df 92 push r13
1acc: ef 92 push r14
1ace: ff 92 push r15
1ad0: 0f 93 push r16
1ad2: 1f 93 push r17
1ad4: d8 2e mov r13, r24
1ad6: 7a 01 movw r14, r20
1ad8: 8b 01 movw r16, r22
BYTE n, res;
 
 
if (wait_ready() != 0xFF) return 0xFF;
1ada: 0e 94 d3 0c call 0x19a6 ; 0x19a6 <wait_ready>
1ade: 8f 3f cpi r24, 0xFF ; 255
1ae0: 19 f0 breq .+6 ; 0x1ae8 <send_cmd+0x1e>
1ae2: 2f ef ldi r18, 0xFF ; 255
1ae4: 30 e0 ldi r19, 0x00 ; 0
1ae6: 44 c0 rjmp .+136 ; 0x1b70 <send_cmd+0xa6>
 
/* Send command packet */
xmit_spi(cmd); /* Command */
1ae8: de bc out 0x2e, r13 ; 46
1aea: 0d b4 in r0, 0x2d ; 45
1aec: 07 fe sbrs r0, 7
1aee: fd cf rjmp .-6 ; 0x1aea <send_cmd+0x20>
xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
1af0: 81 2f mov r24, r17
1af2: 99 27 eor r25, r25
1af4: aa 27 eor r26, r26
1af6: bb 27 eor r27, r27
1af8: 8e bd out 0x2e, r24 ; 46
1afa: 0d b4 in r0, 0x2d ; 45
1afc: 07 fe sbrs r0, 7
1afe: fd cf rjmp .-6 ; 0x1afa <send_cmd+0x30>
xmit_spi((BYTE)(arg >> 16)); /* Argument[23..16] */
1b00: c8 01 movw r24, r16
1b02: aa 27 eor r26, r26
1b04: bb 27 eor r27, r27
1b06: 8e bd out 0x2e, r24 ; 46
1b08: 0d b4 in r0, 0x2d ; 45
1b0a: 07 fe sbrs r0, 7
1b0c: fd cf rjmp .-6 ; 0x1b08 <send_cmd+0x3e>
xmit_spi((BYTE)(arg >> 8)); /* Argument[15..8] */
1b0e: bb 27 eor r27, r27
1b10: a1 2f mov r26, r17
1b12: 90 2f mov r25, r16
1b14: 8f 2d mov r24, r15
1b16: 8e bd out 0x2e, r24 ; 46
1b18: 0d b4 in r0, 0x2d ; 45
1b1a: 07 fe sbrs r0, 7
1b1c: fd cf rjmp .-6 ; 0x1b18 <send_cmd+0x4e>
xmit_spi((BYTE)arg); /* Argument[7..0] */
1b1e: ee bc out 0x2e, r14 ; 46
1b20: 0d b4 in r0, 0x2d ; 45
1b22: 07 fe sbrs r0, 7
1b24: fd cf rjmp .-6 ; 0x1b20 <send_cmd+0x56>
n = 0;
if (cmd == CMD0) n = 0x95; /* CRC for CMD0(0) */
1b26: 80 e4 ldi r24, 0x40 ; 64
1b28: d8 16 cp r13, r24
1b2a: 11 f4 brne .+4 ; 0x1b30 <send_cmd+0x66>
1b2c: 85 e9 ldi r24, 0x95 ; 149
1b2e: 06 c0 rjmp .+12 ; 0x1b3c <send_cmd+0x72>
if (cmd == CMD8) n = 0x87; /* CRC for CMD8(0x1AA) */
1b30: 88 e4 ldi r24, 0x48 ; 72
1b32: d8 16 cp r13, r24
1b34: 11 f4 brne .+4 ; 0x1b3a <send_cmd+0x70>
1b36: 87 e8 ldi r24, 0x87 ; 135
1b38: 01 c0 rjmp .+2 ; 0x1b3c <send_cmd+0x72>
1b3a: 80 e0 ldi r24, 0x00 ; 0
xmit_spi(n);
1b3c: 8e bd out 0x2e, r24 ; 46
1b3e: 0d b4 in r0, 0x2d ; 45
1b40: 07 fe sbrs r0, 7
1b42: fd cf rjmp .-6 ; 0x1b3e <send_cmd+0x74>
 
/* Receive command response */
if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */
1b44: 8c e4 ldi r24, 0x4C ; 76
1b46: d8 16 cp r13, r24
1b48: 31 f4 brne .+12 ; 0x1b56 <send_cmd+0x8c>
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1b4a: 8f ef ldi r24, 0xFF ; 255
1b4c: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1b4e: 0d b4 in r0, 0x2d ; 45
1b50: 07 fe sbrs r0, 7
1b52: fd cf rjmp .-6 ; 0x1b4e <send_cmd+0x84>
return SPDR;
1b54: 8e b5 in r24, 0x2e ; 46
1b56: 9a e0 ldi r25, 0x0A ; 10
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1b58: 8f ef ldi r24, 0xFF ; 255
1b5a: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1b5c: 0d b4 in r0, 0x2d ; 45
1b5e: 07 fe sbrs r0, 7
1b60: fd cf rjmp .-6 ; 0x1b5c <send_cmd+0x92>
return SPDR;
1b62: 8e b5 in r24, 0x2e ; 46
1b64: 28 2f mov r18, r24
1b66: 33 27 eor r19, r19
/* Receive command response */
if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do
res = rcvr_spi();
while ((res & 0x80) && --n);
1b68: 87 ff sbrs r24, 7
1b6a: 02 c0 rjmp .+4 ; 0x1b70 <send_cmd+0xa6>
1b6c: 91 50 subi r25, 0x01 ; 1
1b6e: a1 f7 brne .-24 ; 0x1b58 <send_cmd+0x8e>
 
return res; /* Return with the response value */
}
1b70: c9 01 movw r24, r18
1b72: 1f 91 pop r17
1b74: 0f 91 pop r16
1b76: ff 90 pop r15
1b78: ef 90 pop r14
1b7a: df 90 pop r13
1b7c: 08 95 ret
 
00001b7e <disk_status>:
/*-----------------------------------------------------------------------*/
 
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0) */
)
{
1b7e: 88 23 and r24, r24
1b80: 19 f0 breq .+6 ; 0x1b88 <disk_status+0xa>
if (drv) return STA_NOINIT; /* Supports only single drive */
1b82: 81 e0 ldi r24, 0x01 ; 1
1b84: 90 e0 ldi r25, 0x00 ; 0
1b86: 08 95 ret
return Stat;
1b88: 80 91 04 01 lds r24, 0x0104
1b8c: 99 27 eor r25, r25
}
1b8e: 08 95 ret
 
00001b90 <disk_timerproc>:
/* Device timer interrupt procedure */
/* This must be called in period of 10ms */
/* (Platform dependent) */
 
void disk_timerproc (void)
{
1b90: 80 91 0f 01 lds r24, 0x010F
static BYTE pv;
BYTE n, s;
 
 
n = Timer1; /* 100Hz decrement timer */
if (n) Timer1 = --n;
1b94: 88 23 and r24, r24
1b96: 19 f0 breq .+6 ; 0x1b9e <disk_timerproc+0xe>
1b98: 81 50 subi r24, 0x01 ; 1
1b9a: 80 93 0f 01 sts 0x010F, r24
n = Timer2;
1b9e: 80 91 10 01 lds r24, 0x0110
if (n) Timer2 = --n;
1ba2: 88 23 and r24, r24
1ba4: 19 f0 breq .+6 ; 0x1bac <disk_timerproc+0x1c>
1ba6: 81 50 subi r24, 0x01 ; 1
1ba8: 80 93 10 01 sts 0x0110, r24
 
n = pv;
1bac: 90 91 0e 01 lds r25, 0x010E
pv = SOCKPORT & (SOCKINS); /* Sample socket switch */
1bb0: 83 b1 in r24, 0x03 ; 3
1bb2: 81 70 andi r24, 0x01 ; 1
1bb4: 80 93 0e 01 sts 0x010E, r24
 
if (n == pv) { /* Have contacts stabled? */
1bb8: 98 17 cp r25, r24
1bba: 49 f4 brne .+18 ; 0x1bce <disk_timerproc+0x3e>
s = Stat;
1bbc: 80 91 04 01 lds r24, 0x0104
if (pv & SOCKINS) /* INS = H (Socket empty) */
1bc0: 90 ff sbrs r25, 0
1bc2: 02 c0 rjmp .+4 ; 0x1bc8 <disk_timerproc+0x38>
s |= (STA_NODISK | STA_NOINIT);
1bc4: 83 60 ori r24, 0x03 ; 3
1bc6: 01 c0 rjmp .+2 ; 0x1bca <disk_timerproc+0x3a>
else /* INS = L (Card inserted) */
s &= ~STA_NODISK;
1bc8: 8d 7f andi r24, 0xFD ; 253
 
Stat = s;
1bca: 80 93 04 01 sts 0x0104, r24
1bce: 08 95 ret
 
00001bd0 <disk_ioctl>:
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
1bd0: a0 e1 ldi r26, 0x10 ; 16
1bd2: b0 e0 ldi r27, 0x00 ; 0
1bd4: ee ee ldi r30, 0xEE ; 238
1bd6: fd e0 ldi r31, 0x0D ; 13
1bd8: 0c 94 38 11 jmp 0x2270 ; 0x2270 <__prologue_saves__+0x1c>
1bdc: fa 01 movw r30, r20
DRESULT res;
BYTE n, csd[16], *ptr = buff;
WORD csize;
 
 
if (drv) return RES_PARERR;
1bde: 88 23 and r24, r24
1be0: 19 f0 breq .+6 ; 0x1be8 <disk_ioctl+0x18>
1be2: 24 e0 ldi r18, 0x04 ; 4
1be4: 30 e0 ldi r19, 0x00 ; 0
1be6: da c0 rjmp .+436 ; 0x1d9c <disk_ioctl+0x1cc>
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
DRESULT res;
BYTE n, csd[16], *ptr = buff;
1be8: 8a 01 movw r16, r20
WORD csize;
 
 
if (drv) return RES_PARERR;
 
SELECT(); /* CS = L */
1bea: 2a 98 cbi 0x05, 2 ; 5
 
res = RES_ERROR;
switch (ctrl) {
1bec: 63 30 cpi r22, 0x03 ; 3
1bee: 09 f4 brne .+2 ; 0x1bf2 <disk_ioctl+0x22>
1bf0: 82 c0 rjmp .+260 ; 0x1cf6 <disk_ioctl+0x126>
1bf2: 64 30 cpi r22, 0x04 ; 4
1bf4: 28 f4 brcc .+10 ; 0x1c00 <disk_ioctl+0x30>
1bf6: 61 30 cpi r22, 0x01 ; 1
1bf8: 79 f0 breq .+30 ; 0x1c18 <disk_ioctl+0x48>
1bfa: 62 30 cpi r22, 0x02 ; 2
1bfc: 51 f4 brne .+20 ; 0x1c12 <disk_ioctl+0x42>
1bfe: 74 c0 rjmp .+232 ; 0x1ce8 <disk_ioctl+0x118>
1c00: 6b 30 cpi r22, 0x0B ; 11
1c02: 09 f4 brne .+2 ; 0x1c06 <disk_ioctl+0x36>
1c04: 88 c0 rjmp .+272 ; 0x1d16 <disk_ioctl+0x146>
1c06: 6c 30 cpi r22, 0x0C ; 12
1c08: 09 f4 brne .+2 ; 0x1c0c <disk_ioctl+0x3c>
1c0a: 9f c0 rjmp .+318 ; 0x1d4a <disk_ioctl+0x17a>
1c0c: 6a 30 cpi r22, 0x0A ; 10
1c0e: 09 f4 brne .+2 ; 0x1c12 <disk_ioctl+0x42>
1c10: 78 c0 rjmp .+240 ; 0x1d02 <disk_ioctl+0x132>
1c12: 24 e0 ldi r18, 0x04 ; 4
1c14: 30 e0 ldi r19, 0x00 ; 0
1c16: b8 c0 rjmp .+368 ; 0x1d88 <disk_ioctl+0x1b8>
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
1c18: 40 e0 ldi r20, 0x00 ; 0
1c1a: 50 e0 ldi r21, 0x00 ; 0
1c1c: 60 e0 ldi r22, 0x00 ; 0
1c1e: 70 e0 ldi r23, 0x00 ; 0
1c20: 89 e4 ldi r24, 0x49 ; 73
1c22: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1c26: 88 23 and r24, r24
1c28: 09 f0 breq .+2 ; 0x1c2c <disk_ioctl+0x5c>
1c2a: ac c0 rjmp .+344 ; 0x1d84 <disk_ioctl+0x1b4>
1c2c: 60 e1 ldi r22, 0x10 ; 16
1c2e: 70 e0 ldi r23, 0x00 ; 0
1c30: ce 01 movw r24, r28
1c32: 01 96 adiw r24, 0x01 ; 1
1c34: 0e 94 ec 0c call 0x19d8 ; 0x19d8 <rcvr_datablock>
1c38: 88 23 and r24, r24
1c3a: 09 f4 brne .+2 ; 0x1c3e <disk_ioctl+0x6e>
1c3c: a3 c0 rjmp .+326 ; 0x1d84 <disk_ioctl+0x1b4>
if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
1c3e: 89 81 ldd r24, Y+1 ; 0x01
1c40: 82 95 swap r24
1c42: 86 95 lsr r24
1c44: 86 95 lsr r24
1c46: 83 70 andi r24, 0x03 ; 3
1c48: 7a 85 ldd r23, Y+10 ; 0x0a
1c4a: 49 85 ldd r20, Y+9 ; 0x09
1c4c: 81 30 cpi r24, 0x01 ; 1
1c4e: c1 f4 brne .+48 ; 0x1c80 <disk_ioctl+0xb0>
csize = csd[9] + ((WORD)csd[8] << 8) + 1;
*(DWORD*)buff = (DWORD)csize << 10;
1c50: 87 2f mov r24, r23
1c52: 99 27 eor r25, r25
1c54: 01 96 adiw r24, 0x01 ; 1
1c56: 24 2f mov r18, r20
1c58: 33 27 eor r19, r19
1c5a: 32 2f mov r19, r18
1c5c: 22 27 eor r18, r18
1c5e: 82 0f add r24, r18
1c60: 93 1f adc r25, r19
1c62: aa 27 eor r26, r26
1c64: bb 27 eor r27, r27
1c66: 6a e0 ldi r22, 0x0A ; 10
1c68: 88 0f add r24, r24
1c6a: 99 1f adc r25, r25
1c6c: aa 1f adc r26, r26
1c6e: bb 1f adc r27, r27
1c70: 6a 95 dec r22
1c72: d1 f7 brne .-12 ; 0x1c68 <disk_ioctl+0x98>
1c74: f8 01 movw r30, r16
1c76: 80 83 st Z, r24
1c78: 91 83 std Z+1, r25 ; 0x01
1c7a: a2 83 std Z+2, r26 ; 0x02
1c7c: b3 83 std Z+3, r27 ; 0x03
1c7e: 38 c0 rjmp .+112 ; 0x1cf0 <disk_ioctl+0x120>
} else { /* MMC or SDC ver 1.XX */
n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
*(DWORD*)buff = (DWORD)csize << (n - 9);
1c80: 42 95 swap r20
1c82: 46 95 lsr r20
1c84: 46 95 lsr r20
1c86: 43 70 andi r20, 0x03 ; 3
1c88: 28 85 ldd r18, Y+8 ; 0x08
1c8a: 33 27 eor r19, r19
1c8c: 22 0f add r18, r18
1c8e: 33 1f adc r19, r19
1c90: 22 0f add r18, r18
1c92: 33 1f adc r19, r19
1c94: 24 0f add r18, r20
1c96: 31 1d adc r19, r1
1c98: 2f 5f subi r18, 0xFF ; 255
1c9a: 3f 4f sbci r19, 0xFF ; 255
1c9c: 8f 81 ldd r24, Y+7 ; 0x07
1c9e: 99 27 eor r25, r25
1ca0: 83 70 andi r24, 0x03 ; 3
1ca2: 90 70 andi r25, 0x00 ; 0
1ca4: 98 2f mov r25, r24
1ca6: 88 27 eor r24, r24
1ca8: 99 0f add r25, r25
1caa: 99 0f add r25, r25
1cac: 28 0f add r18, r24
1cae: 39 1f adc r19, r25
1cb0: 44 27 eor r20, r20
1cb2: 55 27 eor r21, r21
1cb4: 6e 81 ldd r22, Y+6 ; 0x06
1cb6: 6f 70 andi r22, 0x0F ; 15
1cb8: 6e 5f subi r22, 0xFE ; 254
1cba: 73 70 andi r23, 0x03 ; 3
1cbc: 77 0f add r23, r23
1cbe: 67 0f add r22, r23
1cc0: 8b 85 ldd r24, Y+11 ; 0x0b
1cc2: 88 1f adc r24, r24
1cc4: 88 27 eor r24, r24
1cc6: 88 1f adc r24, r24
1cc8: 86 0f add r24, r22
1cca: 99 27 eor r25, r25
1ccc: 09 97 sbiw r24, 0x09 ; 9
1cce: 04 c0 rjmp .+8 ; 0x1cd8 <disk_ioctl+0x108>
1cd0: 22 0f add r18, r18
1cd2: 33 1f adc r19, r19
1cd4: 44 1f adc r20, r20
1cd6: 55 1f adc r21, r21
1cd8: 8a 95 dec r24
1cda: d2 f7 brpl .-12 ; 0x1cd0 <disk_ioctl+0x100>
1cdc: f8 01 movw r30, r16
1cde: 20 83 st Z, r18
1ce0: 31 83 std Z+1, r19 ; 0x01
1ce2: 42 83 std Z+2, r20 ; 0x02
1ce4: 53 83 std Z+3, r21 ; 0x03
1ce6: 04 c0 rjmp .+8 ; 0x1cf0 <disk_ioctl+0x120>
res = RES_OK;
}
break;
 
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
*(WORD*)buff = 512;
1ce8: 80 e0 ldi r24, 0x00 ; 0
1cea: 92 e0 ldi r25, 0x02 ; 2
1cec: 91 83 std Z+1, r25 ; 0x01
1cee: 80 83 st Z, r24
1cf0: 20 e0 ldi r18, 0x00 ; 0
1cf2: 30 e0 ldi r19, 0x00 ; 0
1cf4: 49 c0 rjmp .+146 ; 0x1d88 <disk_ioctl+0x1b8>
res = RES_OK;
break;
 
case CTRL_SYNC : /* Make sure that data has been written */
if (wait_ready() == 0xFF)
1cf6: 0e 94 d3 0c call 0x19a6 ; 0x19a6 <wait_ready>
1cfa: 90 e0 ldi r25, 0x00 ; 0
1cfc: 8f 3f cpi r24, 0xFF ; 255
1cfe: 01 f5 brne .+64 ; 0x1d40 <disk_ioctl+0x170>
1d00: 1e c0 rjmp .+60 ; 0x1d3e <disk_ioctl+0x16e>
res = RES_OK;
break;
 
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
1d02: 80 91 04 01 lds r24, 0x0104
1d06: 80 fd sbrc r24, 0
1d08: 47 c0 rjmp .+142 ; 0x1d98 <disk_ioctl+0x1c8>
if ((send_cmd(CMD9, 0) == 0) /* READ_CSD */
1d0a: 40 e0 ldi r20, 0x00 ; 0
1d0c: 50 e0 ldi r21, 0x00 ; 0
1d0e: 60 e0 ldi r22, 0x00 ; 0
1d10: 70 e0 ldi r23, 0x00 ; 0
1d12: 89 e4 ldi r24, 0x49 ; 73
1d14: 09 c0 rjmp .+18 ; 0x1d28 <disk_ioctl+0x158>
&& rcvr_datablock(ptr, 16))
res = RES_OK;
break;
 
case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
1d16: 80 91 04 01 lds r24, 0x0104
1d1a: 80 fd sbrc r24, 0
1d1c: 3d c0 rjmp .+122 ; 0x1d98 <disk_ioctl+0x1c8>
if ((send_cmd(CMD10, 0) == 0) /* READ_CID */
1d1e: 40 e0 ldi r20, 0x00 ; 0
1d20: 50 e0 ldi r21, 0x00 ; 0
1d22: 60 e0 ldi r22, 0x00 ; 0
1d24: 70 e0 ldi r23, 0x00 ; 0
1d26: 8a e4 ldi r24, 0x4A ; 74
1d28: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1d2c: 88 23 and r24, r24
1d2e: 51 f5 brne .+84 ; 0x1d84 <disk_ioctl+0x1b4>
1d30: 60 e1 ldi r22, 0x10 ; 16
1d32: 70 e0 ldi r23, 0x00 ; 0
1d34: c8 01 movw r24, r16
1d36: 0e 94 ec 0c call 0x19d8 ; 0x19d8 <rcvr_datablock>
1d3a: 90 e0 ldi r25, 0x00 ; 0
1d3c: 81 11 cpse r24, r1
1d3e: 91 e0 ldi r25, 0x01 ; 1
1d40: 81 e0 ldi r24, 0x01 ; 1
1d42: 98 27 eor r25, r24
1d44: 29 2f mov r18, r25
1d46: 33 27 eor r19, r19
1d48: 1f c0 rjmp .+62 ; 0x1d88 <disk_ioctl+0x1b8>
&& rcvr_datablock(ptr, 16))
res = RES_OK;
break;
 
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
1d4a: 80 91 04 01 lds r24, 0x0104
1d4e: 80 fd sbrc r24, 0
1d50: 23 c0 rjmp .+70 ; 0x1d98 <disk_ioctl+0x1c8>
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
1d52: 40 e0 ldi r20, 0x00 ; 0
1d54: 50 e0 ldi r21, 0x00 ; 0
1d56: 60 e0 ldi r22, 0x00 ; 0
1d58: 70 e0 ldi r23, 0x00 ; 0
1d5a: 8a e7 ldi r24, 0x7A ; 122
1d5c: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1d60: 88 23 and r24, r24
1d62: 81 f4 brne .+32 ; 0x1d84 <disk_ioctl+0x1b4>
1d64: 90 e0 ldi r25, 0x00 ; 0
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1d66: 8f ef ldi r24, 0xFF ; 255
1d68: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1d6a: 0d b4 in r0, 0x2d ; 45
1d6c: 07 fe sbrs r0, 7
1d6e: fd cf rjmp .-6 ; 0x1d6a <disk_ioctl+0x19a>
return SPDR;
1d70: 8e b5 in r24, 0x2e ; 46
 
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
for (n = 0; n < 4; n++)
*ptr++ = rcvr_spi();
1d72: f8 01 movw r30, r16
1d74: 80 83 st Z, r24
break;
 
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
for (n = 0; n < 4; n++)
1d76: 9f 5f subi r25, 0xFF ; 255
1d78: 94 30 cpi r25, 0x04 ; 4
1d7a: 09 f4 brne .+2 ; 0x1d7e <disk_ioctl+0x1ae>
1d7c: b9 cf rjmp .-142 ; 0x1cf0 <disk_ioctl+0x120>
*ptr++ = rcvr_spi();
1d7e: 0f 5f subi r16, 0xFF ; 255
1d80: 1f 4f sbci r17, 0xFF ; 255
1d82: f1 cf rjmp .-30 ; 0x1d66 <disk_ioctl+0x196>
1d84: 21 e0 ldi r18, 0x01 ; 1
1d86: 30 e0 ldi r19, 0x00 ; 0
 
default:
res = RES_PARERR;
}
 
DESELECT(); /* CS = H */
1d88: 2a 9a sbi 0x05, 2 ; 5
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1d8a: 8f ef ldi r24, 0xFF ; 255
1d8c: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1d8e: 0d b4 in r0, 0x2d ; 45
1d90: 07 fe sbrs r0, 7
1d92: fd cf rjmp .-6 ; 0x1d8e <disk_ioctl+0x1be>
return SPDR;
1d94: 8e b5 in r24, 0x2e ; 46
1d96: 02 c0 rjmp .+4 ; 0x1d9c <disk_ioctl+0x1cc>
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return res;
1d98: 23 e0 ldi r18, 0x03 ; 3
1d9a: 30 e0 ldi r19, 0x00 ; 0
}
1d9c: c9 01 movw r24, r18
1d9e: e4 e0 ldi r30, 0x04 ; 4
1da0: 60 96 adiw r28, 0x10 ; 16
1da2: 0c 94 54 11 jmp 0x22a8 ; 0x22a8 <__epilogue_restores__+0x1c>
 
00001da6 <disk_write>:
BYTE drv, /* Physical drive nmuber (0) */
const BYTE *buff, /* Pointer to the data to be written */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
1da6: cf 92 push r12
1da8: df 92 push r13
1daa: ef 92 push r14
1dac: ff 92 push r15
1dae: 0f 93 push r16
1db0: cf 93 push r28
1db2: df 93 push r29
1db4: eb 01 movw r28, r22
1db6: 69 01 movw r12, r18
1db8: 7a 01 movw r14, r20
if (drv || !count) return RES_PARERR;
1dba: 88 23 and r24, r24
1dbc: 09 f0 breq .+2 ; 0x1dc0 <disk_write+0x1a>
1dbe: 67 c0 rjmp .+206 ; 0x1e8e <disk_write+0xe8>
1dc0: 00 23 and r16, r16
1dc2: 09 f4 brne .+2 ; 0x1dc6 <disk_write+0x20>
1dc4: 64 c0 rjmp .+200 ; 0x1e8e <disk_write+0xe8>
if (Stat & STA_NOINIT) return RES_NOTRDY;
1dc6: 80 91 04 01 lds r24, 0x0104
1dca: 80 ff sbrs r24, 0
1dcc: 03 c0 rjmp .+6 ; 0x1dd4 <disk_write+0x2e>
1dce: 83 e0 ldi r24, 0x03 ; 3
1dd0: 90 e0 ldi r25, 0x00 ; 0
1dd2: 5f c0 rjmp .+190 ; 0x1e92 <disk_write+0xec>
if (Stat & STA_PROTECT) return RES_WRPRT;
1dd4: 80 91 04 01 lds r24, 0x0104
1dd8: 82 ff sbrs r24, 2
1dda: 03 c0 rjmp .+6 ; 0x1de2 <disk_write+0x3c>
1ddc: 82 e0 ldi r24, 0x02 ; 2
1dde: 90 e0 ldi r25, 0x00 ; 0
1de0: 58 c0 rjmp .+176 ; 0x1e92 <disk_write+0xec>
 
if (!(CardType & 4)) sector *= 512; /* Convert to byte address if needed */
1de2: 80 91 11 01 lds r24, 0x0111
1de6: 99 27 eor r25, r25
1de8: 82 fd sbrc r24, 2
1dea: 07 c0 rjmp .+14 ; 0x1dfa <disk_write+0x54>
1dec: e9 e0 ldi r30, 0x09 ; 9
1dee: cc 0c add r12, r12
1df0: dd 1c adc r13, r13
1df2: ee 1c adc r14, r14
1df4: ff 1c adc r15, r15
1df6: ea 95 dec r30
1df8: d1 f7 brne .-12 ; 0x1dee <disk_write+0x48>
 
SELECT(); /* CS = L */
1dfa: 2a 98 cbi 0x05, 2 ; 5
 
if (count == 1) { /* Single block write */
1dfc: 01 30 cpi r16, 0x01 ; 1
1dfe: 79 f4 brne .+30 ; 0x1e1e <disk_write+0x78>
if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
1e00: b7 01 movw r22, r14
1e02: a6 01 movw r20, r12
1e04: 88 e5 ldi r24, 0x58 ; 88
1e06: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1e0a: 88 23 and r24, r24
1e0c: 91 f5 brne .+100 ; 0x1e72 <disk_write+0xcc>
1e0e: 6e ef ldi r22, 0xFE ; 254
1e10: ce 01 movw r24, r28
1e12: 0e 94 24 0d call 0x1a48 ; 0x1a48 <xmit_datablock>
1e16: 81 11 cpse r24, r1
1e18: 81 e0 ldi r24, 0x01 ; 1
1e1a: 08 27 eor r16, r24
1e1c: 2a c0 rjmp .+84 ; 0x1e72 <disk_write+0xcc>
&& xmit_datablock(buff, 0xFE))
count = 0;
}
else { /* Multiple block write */
if (CardType & 2) {
1e1e: 81 ff sbrs r24, 1
1e20: 0e c0 rjmp .+28 ; 0x1e3e <disk_write+0x98>
send_cmd(CMD55, 0); send_cmd(CMD23, count); /* ACMD23 */
1e22: 40 e0 ldi r20, 0x00 ; 0
1e24: 50 e0 ldi r21, 0x00 ; 0
1e26: 60 e0 ldi r22, 0x00 ; 0
1e28: 70 e0 ldi r23, 0x00 ; 0
1e2a: 87 e7 ldi r24, 0x77 ; 119
1e2c: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1e30: 40 2f mov r20, r16
1e32: 55 27 eor r21, r21
1e34: 66 27 eor r22, r22
1e36: 77 27 eor r23, r23
1e38: 87 e5 ldi r24, 0x57 ; 87
1e3a: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
}
if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
1e3e: b7 01 movw r22, r14
1e40: a6 01 movw r20, r12
1e42: 89 e5 ldi r24, 0x59 ; 89
1e44: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1e48: 88 23 and r24, r24
1e4a: 99 f4 brne .+38 ; 0x1e72 <disk_write+0xcc>
do {
if (!xmit_datablock(buff, 0xFC)) break;
1e4c: 6c ef ldi r22, 0xFC ; 252
1e4e: ce 01 movw r24, r28
1e50: 0e 94 24 0d call 0x1a48 ; 0x1a48 <xmit_datablock>
1e54: 88 23 and r24, r24
1e56: 29 f0 breq .+10 ; 0x1e62 <disk_write+0xbc>
buff += 512;
} while (--count);
1e58: 01 50 subi r16, 0x01 ; 1
1e5a: 19 f0 breq .+6 ; 0x1e62 <disk_write+0xbc>
send_cmd(CMD55, 0); send_cmd(CMD23, count); /* ACMD23 */
}
if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
do {
if (!xmit_datablock(buff, 0xFC)) break;
buff += 512;
1e5c: c0 50 subi r28, 0x00 ; 0
1e5e: de 4f sbci r29, 0xFE ; 254
1e60: f5 cf rjmp .-22 ; 0x1e4c <disk_write+0xa6>
} while (--count);
if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */
1e62: 6d ef ldi r22, 0xFD ; 253
1e64: 80 e0 ldi r24, 0x00 ; 0
1e66: 90 e0 ldi r25, 0x00 ; 0
1e68: 0e 94 24 0d call 0x1a48 ; 0x1a48 <xmit_datablock>
1e6c: 88 23 and r24, r24
1e6e: 09 f4 brne .+2 ; 0x1e72 <disk_write+0xcc>
1e70: 01 e0 ldi r16, 0x01 ; 1
count = 1;
}
}
 
DESELECT(); /* CS = H */
1e72: 2a 9a sbi 0x05, 2 ; 5
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1e74: 8f ef ldi r24, 0xFF ; 255
1e76: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1e78: 0d b4 in r0, 0x2d ; 45
1e7a: 07 fe sbrs r0, 7
1e7c: fd cf rjmp .-6 ; 0x1e78 <disk_write+0xd2>
return SPDR;
1e7e: 8e b5 in r24, 0x2e ; 46
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return count ? RES_ERROR : RES_OK;
1e80: 80 e0 ldi r24, 0x00 ; 0
1e82: 90 e0 ldi r25, 0x00 ; 0
1e84: 00 23 and r16, r16
1e86: 29 f0 breq .+10 ; 0x1e92 <disk_write+0xec>
1e88: 81 e0 ldi r24, 0x01 ; 1
1e8a: 90 e0 ldi r25, 0x00 ; 0
1e8c: 02 c0 rjmp .+4 ; 0x1e92 <disk_write+0xec>
1e8e: 84 e0 ldi r24, 0x04 ; 4
1e90: 90 e0 ldi r25, 0x00 ; 0
1e92: df 91 pop r29
1e94: cf 91 pop r28
1e96: 0f 91 pop r16
1e98: ff 90 pop r15
1e9a: ef 90 pop r14
1e9c: df 90 pop r13
1e9e: cf 90 pop r12
1ea0: 08 95 ret
 
00001ea2 <disk_read>:
BYTE drv, /* Physical drive nmuber (0) */
BYTE *buff, /* Pointer to the data buffer to store read data */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
1ea2: 0f 93 push r16
1ea4: cf 93 push r28
1ea6: df 93 push r29
1ea8: eb 01 movw r28, r22
if (drv || !count) return RES_PARERR;
1eaa: 88 23 and r24, r24
1eac: 09 f0 breq .+2 ; 0x1eb0 <disk_read+0xe>
1eae: 50 c0 rjmp .+160 ; 0x1f50 <disk_read+0xae>
1eb0: 00 23 and r16, r16
1eb2: 09 f4 brne .+2 ; 0x1eb6 <disk_read+0x14>
1eb4: 4d c0 rjmp .+154 ; 0x1f50 <disk_read+0xae>
if (Stat & STA_NOINIT) return RES_NOTRDY;
1eb6: 80 91 04 01 lds r24, 0x0104
1eba: 80 ff sbrs r24, 0
1ebc: 03 c0 rjmp .+6 ; 0x1ec4 <disk_read+0x22>
1ebe: 83 e0 ldi r24, 0x03 ; 3
1ec0: 90 e0 ldi r25, 0x00 ; 0
1ec2: 48 c0 rjmp .+144 ; 0x1f54 <disk_read+0xb2>
 
if (!(CardType & 4)) sector *= 512; /* Convert to byte address if needed */
1ec4: 80 91 11 01 lds r24, 0x0111
1ec8: 82 fd sbrc r24, 2
1eca: 07 c0 rjmp .+14 ; 0x1eda <disk_read+0x38>
1ecc: f9 e0 ldi r31, 0x09 ; 9
1ece: 22 0f add r18, r18
1ed0: 33 1f adc r19, r19
1ed2: 44 1f adc r20, r20
1ed4: 55 1f adc r21, r21
1ed6: fa 95 dec r31
1ed8: d1 f7 brne .-12 ; 0x1ece <disk_read+0x2c>
 
SELECT(); /* CS = L */
1eda: 2a 98 cbi 0x05, 2 ; 5
 
if (count == 1) { /* Single block read */
1edc: 01 30 cpi r16, 0x01 ; 1
1ede: 81 f4 brne .+32 ; 0x1f00 <disk_read+0x5e>
if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */
1ee0: ba 01 movw r22, r20
1ee2: a9 01 movw r20, r18
1ee4: 81 e5 ldi r24, 0x51 ; 81
1ee6: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1eea: 88 23 and r24, r24
1eec: 19 f5 brne .+70 ; 0x1f34 <disk_read+0x92>
1eee: 60 e0 ldi r22, 0x00 ; 0
1ef0: 72 e0 ldi r23, 0x02 ; 2
1ef2: ce 01 movw r24, r28
1ef4: 0e 94 ec 0c call 0x19d8 ; 0x19d8 <rcvr_datablock>
1ef8: 81 11 cpse r24, r1
1efa: 81 e0 ldi r24, 0x01 ; 1
1efc: 08 27 eor r16, r24
1efe: 1a c0 rjmp .+52 ; 0x1f34 <disk_read+0x92>
&& rcvr_datablock(buff, 512))
count = 0;
}
else { /* Multiple block read */
if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */
1f00: ba 01 movw r22, r20
1f02: a9 01 movw r20, r18
1f04: 82 e5 ldi r24, 0x52 ; 82
1f06: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1f0a: 88 23 and r24, r24
1f0c: 99 f4 brne .+38 ; 0x1f34 <disk_read+0x92>
do {
if (!rcvr_datablock(buff, 512)) break;
1f0e: 60 e0 ldi r22, 0x00 ; 0
1f10: 72 e0 ldi r23, 0x02 ; 2
1f12: ce 01 movw r24, r28
1f14: 0e 94 ec 0c call 0x19d8 ; 0x19d8 <rcvr_datablock>
1f18: 88 23 and r24, r24
1f1a: 29 f0 breq .+10 ; 0x1f26 <disk_read+0x84>
buff += 512;
} while (--count);
1f1c: 01 50 subi r16, 0x01 ; 1
1f1e: 19 f0 breq .+6 ; 0x1f26 <disk_read+0x84>
}
else { /* Multiple block read */
if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */
do {
if (!rcvr_datablock(buff, 512)) break;
buff += 512;
1f20: c0 50 subi r28, 0x00 ; 0
1f22: de 4f sbci r29, 0xFE ; 254
1f24: f4 cf rjmp .-24 ; 0x1f0e <disk_read+0x6c>
} while (--count);
send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
1f26: 40 e0 ldi r20, 0x00 ; 0
1f28: 50 e0 ldi r21, 0x00 ; 0
1f2a: 60 e0 ldi r22, 0x00 ; 0
1f2c: 70 e0 ldi r23, 0x00 ; 0
1f2e: 8c e4 ldi r24, 0x4C ; 76
1f30: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
}
}
 
DESELECT(); /* CS = H */
1f34: 2a 9a sbi 0x05, 2 ; 5
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1f36: 8f ef ldi r24, 0xFF ; 255
1f38: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1f3a: 0d b4 in r0, 0x2d ; 45
1f3c: 07 fe sbrs r0, 7
1f3e: fd cf rjmp .-6 ; 0x1f3a <disk_read+0x98>
return SPDR;
1f40: 8e b5 in r24, 0x2e ; 46
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return count ? RES_ERROR : RES_OK;
1f42: 80 e0 ldi r24, 0x00 ; 0
1f44: 90 e0 ldi r25, 0x00 ; 0
1f46: 00 23 and r16, r16
1f48: 29 f0 breq .+10 ; 0x1f54 <disk_read+0xb2>
1f4a: 81 e0 ldi r24, 0x01 ; 1
1f4c: 90 e0 ldi r25, 0x00 ; 0
1f4e: 02 c0 rjmp .+4 ; 0x1f54 <disk_read+0xb2>
1f50: 84 e0 ldi r24, 0x04 ; 4
1f52: 90 e0 ldi r25, 0x00 ; 0
1f54: df 91 pop r29
1f56: cf 91 pop r28
1f58: 0f 91 pop r16
1f5a: 08 95 ret
 
00001f5c <disk_initialize>:
/*-----------------------------------------------------------------------*/
 
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0) */
)
{
1f5c: a4 e0 ldi r26, 0x04 ; 4
1f5e: b0 e0 ldi r27, 0x00 ; 0
1f60: e4 eb ldi r30, 0xB4 ; 180
1f62: ff e0 ldi r31, 0x0F ; 15
1f64: 0c 94 36 11 jmp 0x226c ; 0x226c <__prologue_saves__+0x18>
BYTE n, ty, ocr[4];
 
 
if (drv) return STA_NOINIT; /* Supports only single drive */
1f68: 88 23 and r24, r24
1f6a: 19 f0 breq .+6 ; 0x1f72 <disk_initialize+0x16>
1f6c: 81 e0 ldi r24, 0x01 ; 1
1f6e: 90 e0 ldi r25, 0x00 ; 0
1f70: d0 c0 rjmp .+416 ; 0x2112 <disk_initialize+0x1b6>
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
1f72: 80 91 04 01 lds r24, 0x0104
1f76: 81 fd sbrc r24, 1
1f78: c9 c0 rjmp .+402 ; 0x210c <disk_initialize+0x1b0>
1f7a: 9a e0 ldi r25, 0x0A ; 10
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1f7c: 8f ef ldi r24, 0xFF ; 255
1f7e: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1f80: 0d b4 in r0, 0x2d ; 45
1f82: 07 fe sbrs r0, 7
1f84: fd cf rjmp .-6 ; 0x1f80 <disk_initialize+0x24>
return SPDR;
1f86: 8e b5 in r24, 0x2e ; 46
 
 
if (drv) return STA_NOINIT; /* Supports only single drive */
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
 
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
1f88: 91 50 subi r25, 0x01 ; 1
1f8a: c1 f7 brne .-16 ; 0x1f7c <disk_initialize+0x20>
 
SELECT(); /* CS = L */
1f8c: 2a 98 cbi 0x05, 2 ; 5
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
1f8e: 40 e0 ldi r20, 0x00 ; 0
1f90: 50 e0 ldi r21, 0x00 ; 0
1f92: 60 e0 ldi r22, 0x00 ; 0
1f94: 70 e0 ldi r23, 0x00 ; 0
1f96: 80 e4 ldi r24, 0x40 ; 64
1f98: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1f9c: 81 30 cpi r24, 0x01 ; 1
1f9e: 09 f0 breq .+2 ; 0x1fa2 <disk_initialize+0x46>
1fa0: a0 c0 rjmp .+320 ; 0x20e2 <disk_initialize+0x186>
Timer1 = 100; /* Initialization timeout of 1000 msec */
1fa2: 84 e6 ldi r24, 0x64 ; 100
1fa4: 80 93 0f 01 sts 0x010F, r24
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDC Ver2+ */
1fa8: 4a ea ldi r20, 0xAA ; 170
1faa: 51 e0 ldi r21, 0x01 ; 1
1fac: 60 e0 ldi r22, 0x00 ; 0
1fae: 70 e0 ldi r23, 0x00 ; 0
1fb0: 88 e4 ldi r24, 0x48 ; 72
1fb2: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
1fb6: 81 30 cpi r24, 0x01 ; 1
1fb8: 09 f0 breq .+2 ; 0x1fbc <disk_initialize+0x60>
1fba: 54 c0 rjmp .+168 ; 0x2064 <disk_initialize+0x108>
1fbc: 7e 01 movw r14, r28
1fbe: 08 94 sec
1fc0: e1 1c adc r14, r1
1fc2: f1 1c adc r15, r1
1fc4: 87 01 movw r16, r14
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
1fc6: 9e 01 movw r18, r28
1fc8: 2b 5f subi r18, 0xFB ; 251
1fca: 3f 4f sbci r19, 0xFF ; 255
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
1fcc: 8f ef ldi r24, 0xFF ; 255
1fce: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
1fd0: 0d b4 in r0, 0x2d ; 45
1fd2: 07 fe sbrs r0, 7
1fd4: fd cf rjmp .-6 ; 0x1fd0 <disk_initialize+0x74>
return SPDR;
1fd6: 8e b5 in r24, 0x2e ; 46
SELECT(); /* CS = L */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
Timer1 = 100; /* Initialization timeout of 1000 msec */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDC Ver2+ */
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
1fd8: f8 01 movw r30, r16
1fda: 81 93 st Z+, r24
1fdc: 8f 01 movw r16, r30
1fde: e2 17 cp r30, r18
1fe0: f3 07 cpc r31, r19
1fe2: a1 f7 brne .-24 ; 0x1fcc <disk_initialize+0x70>
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
1fe4: 8b 81 ldd r24, Y+3 ; 0x03
1fe6: 81 30 cpi r24, 0x01 ; 1
1fe8: 09 f0 breq .+2 ; 0x1fec <disk_initialize+0x90>
1fea: 7b c0 rjmp .+246 ; 0x20e2 <disk_initialize+0x186>
1fec: 8c 81 ldd r24, Y+4 ; 0x04
1fee: 8a 3a cpi r24, 0xAA ; 170
1ff0: 09 f0 breq .+2 ; 0x1ff4 <disk_initialize+0x98>
1ff2: 77 c0 rjmp .+238 ; 0x20e2 <disk_initialize+0x186>
do {
if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 1UL << 30) == 0) break; /* ACMD41 with HCS bit */
1ff4: 40 e0 ldi r20, 0x00 ; 0
1ff6: 50 e0 ldi r21, 0x00 ; 0
1ff8: 60 e0 ldi r22, 0x00 ; 0
1ffa: 70 e0 ldi r23, 0x00 ; 0
1ffc: 87 e7 ldi r24, 0x77 ; 119
1ffe: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
2002: 82 30 cpi r24, 0x02 ; 2
2004: 48 f4 brcc .+18 ; 0x2018 <disk_initialize+0xbc>
2006: 40 e0 ldi r20, 0x00 ; 0
2008: 50 e0 ldi r21, 0x00 ; 0
200a: 60 e0 ldi r22, 0x00 ; 0
200c: 70 e4 ldi r23, 0x40 ; 64
200e: 89 e6 ldi r24, 0x69 ; 105
2010: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
2014: 88 23 and r24, r24
2016: 21 f0 breq .+8 ; 0x2020 <disk_initialize+0xc4>
} while (Timer1);
2018: 80 91 0f 01 lds r24, 0x010F
201c: 88 23 and r24, r24
201e: 51 f7 brne .-44 ; 0x1ff4 <disk_initialize+0x98>
if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit */
2020: 80 91 0f 01 lds r24, 0x010F
2024: 88 23 and r24, r24
2026: 09 f4 brne .+2 ; 0x202a <disk_initialize+0xce>
2028: 5c c0 rjmp .+184 ; 0x20e2 <disk_initialize+0x186>
202a: 40 e0 ldi r20, 0x00 ; 0
202c: 50 e0 ldi r21, 0x00 ; 0
202e: 60 e0 ldi r22, 0x00 ; 0
2030: 70 e0 ldi r23, 0x00 ; 0
2032: 8a e7 ldi r24, 0x7A ; 122
2034: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
2038: 88 23 and r24, r24
203a: 09 f0 breq .+2 ; 0x203e <disk_initialize+0xe2>
203c: 52 c0 rjmp .+164 ; 0x20e2 <disk_initialize+0x186>
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
203e: 8f ef ldi r24, 0xFF ; 255
2040: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
2042: 0d b4 in r0, 0x2d ; 45
2044: 07 fe sbrs r0, 7
2046: fd cf rjmp .-6 ; 0x2042 <disk_initialize+0xe6>
return SPDR;
2048: 8e b5 in r24, 0x2e ; 46
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
do {
if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 1UL << 30) == 0) break; /* ACMD41 with HCS bit */
} while (Timer1);
if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit */
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
204a: f7 01 movw r30, r14
204c: 81 93 st Z+, r24
204e: 7f 01 movw r14, r30
2050: e0 17 cp r30, r16
2052: f1 07 cpc r31, r17
2054: a1 f7 brne .-24 ; 0x203e <disk_initialize+0xe2>
ty = (ocr[0] & 0x40) ? 6 : 2;
2056: 89 81 ldd r24, Y+1 ; 0x01
2058: 86 ff sbrs r24, 6
205a: 02 c0 rjmp .+4 ; 0x2060 <disk_initialize+0x104>
205c: 16 e0 ldi r17, 0x06 ; 6
205e: 42 c0 rjmp .+132 ; 0x20e4 <disk_initialize+0x188>
2060: 12 e0 ldi r17, 0x02 ; 2
2062: 40 c0 rjmp .+128 ; 0x20e4 <disk_initialize+0x188>
}
}
} else { /* SDC Ver1 or MMC */
ty = (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) <= 1) ? 2 : 1; /* SDC : MMC */
2064: 40 e0 ldi r20, 0x00 ; 0
2066: 50 e0 ldi r21, 0x00 ; 0
2068: 60 e0 ldi r22, 0x00 ; 0
206a: 70 e0 ldi r23, 0x00 ; 0
206c: 87 e7 ldi r24, 0x77 ; 119
206e: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
2072: 82 30 cpi r24, 0x02 ; 2
2074: 58 f4 brcc .+22 ; 0x208c <disk_initialize+0x130>
2076: 40 e0 ldi r20, 0x00 ; 0
2078: 50 e0 ldi r21, 0x00 ; 0
207a: 60 e0 ldi r22, 0x00 ; 0
207c: 70 e0 ldi r23, 0x00 ; 0
207e: 89 e6 ldi r24, 0x69 ; 105
2080: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
2084: 82 30 cpi r24, 0x02 ; 2
2086: 10 f4 brcc .+4 ; 0x208c <disk_initialize+0x130>
2088: 12 e0 ldi r17, 0x02 ; 2
208a: 01 c0 rjmp .+2 ; 0x208e <disk_initialize+0x132>
208c: 11 e0 ldi r17, 0x01 ; 1
do {
if (ty == 2) {
208e: 12 30 cpi r17, 0x02 ; 2
2090: 79 f4 brne .+30 ; 0x20b0 <disk_initialize+0x154>
if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) == 0) break; /* ACMD41 */
2092: 40 e0 ldi r20, 0x00 ; 0
2094: 50 e0 ldi r21, 0x00 ; 0
2096: 60 e0 ldi r22, 0x00 ; 0
2098: 70 e0 ldi r23, 0x00 ; 0
209a: 87 e7 ldi r24, 0x77 ; 119
209c: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
20a0: 82 30 cpi r24, 0x02 ; 2
20a2: 78 f4 brcc .+30 ; 0x20c2 <disk_initialize+0x166>
20a4: 40 e0 ldi r20, 0x00 ; 0
20a6: 50 e0 ldi r21, 0x00 ; 0
20a8: 60 e0 ldi r22, 0x00 ; 0
20aa: 70 e0 ldi r23, 0x00 ; 0
20ac: 89 e6 ldi r24, 0x69 ; 105
20ae: 05 c0 rjmp .+10 ; 0x20ba <disk_initialize+0x15e>
} else {
if (send_cmd(CMD1, 0) == 0) break; /* CMD1 */
20b0: 40 e0 ldi r20, 0x00 ; 0
20b2: 50 e0 ldi r21, 0x00 ; 0
20b4: 60 e0 ldi r22, 0x00 ; 0
20b6: 70 e0 ldi r23, 0x00 ; 0
20b8: 81 e4 ldi r24, 0x41 ; 65
20ba: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
20be: 88 23 and r24, r24
20c0: 21 f0 breq .+8 ; 0x20ca <disk_initialize+0x16e>
}
} while (Timer1);
20c2: 80 91 0f 01 lds r24, 0x010F
20c6: 88 23 and r24, r24
20c8: 11 f7 brne .-60 ; 0x208e <disk_initialize+0x132>
if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Select R/W block length */
20ca: 80 91 0f 01 lds r24, 0x010F
20ce: 88 23 and r24, r24
20d0: 41 f0 breq .+16 ; 0x20e2 <disk_initialize+0x186>
20d2: 40 e0 ldi r20, 0x00 ; 0
20d4: 52 e0 ldi r21, 0x02 ; 2
20d6: 60 e0 ldi r22, 0x00 ; 0
20d8: 70 e0 ldi r23, 0x00 ; 0
20da: 80 e5 ldi r24, 0x50 ; 80
20dc: 0e 94 65 0d call 0x1aca ; 0x1aca <send_cmd>
20e0: 81 11 cpse r24, r1
20e2: 10 e0 ldi r17, 0x00 ; 0
ty = 0;
}
}
CardType = ty;
20e4: 10 93 11 01 sts 0x0111, r17
DESELECT(); /* CS = H */
20e8: 2a 9a sbi 0x05, 2 ; 5
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
20ea: 8f ef ldi r24, 0xFF ; 255
20ec: 8e bd out 0x2e, r24 ; 46
loop_until_bit_is_set(SPSR, SPIF);
20ee: 0d b4 in r0, 0x2d ; 45
20f0: 07 fe sbrs r0, 7
20f2: fd cf rjmp .-6 ; 0x20ee <disk_initialize+0x192>
return SPDR;
20f4: 8e b5 in r24, 0x2e ; 46
}
CardType = ty;
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
if (ty) { /* Initialization succeded */
20f6: 11 23 and r17, r17
20f8: 21 f0 breq .+8 ; 0x2102 <disk_initialize+0x1a6>
Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
20fa: 80 91 04 01 lds r24, 0x0104
20fe: 8e 7f andi r24, 0xFE ; 254
2100: 03 c0 rjmp .+6 ; 0x2108 <disk_initialize+0x1ac>
} else { /* Initialization failed */
Stat |= STA_NOINIT; /* Set STA_NOINIT */
2102: 80 91 04 01 lds r24, 0x0104
2106: 81 60 ori r24, 0x01 ; 1
2108: 80 93 04 01 sts 0x0104, r24
}
 
return Stat;
210c: 80 91 04 01 lds r24, 0x0104
2110: 99 27 eor r25, r25
2112: e6 e0 ldi r30, 0x06 ; 6
2114: 24 96 adiw r28, 0x04 ; 4
2116: 0c 94 52 11 jmp 0x22a4 ; 0x22a4 <__epilogue_restores__+0x18>
 
0000211a <strcpy_P>:
211a: fb 01 movw r30, r22
211c: dc 01 movw r26, r24
211e: 05 90 lpm r0, Z+
2120: 0d 92 st X+, r0
2122: 00 20 and r0, r0
2124: e1 f7 brne .-8 ; 0x211e <strcpy_P+0x4>
2126: 08 95 ret
 
00002128 <memcmp>:
2128: fb 01 movw r30, r22
212a: dc 01 movw r26, r24
212c: 04 c0 rjmp .+8 ; 0x2136 <memcmp+0xe>
212e: 8d 91 ld r24, X+
2130: 01 90 ld r0, Z+
2132: 80 19 sub r24, r0
2134: 21 f4 brne .+8 ; 0x213e <memcmp+0x16>
2136: 41 50 subi r20, 0x01 ; 1
2138: 50 40 sbci r21, 0x00 ; 0
213a: c8 f7 brcc .-14 ; 0x212e <memcmp+0x6>
213c: 88 1b sub r24, r24
213e: 99 0b sbc r25, r25
2140: 08 95 ret
 
00002142 <memcpy>:
2142: fb 01 movw r30, r22
2144: dc 01 movw r26, r24
2146: 02 c0 rjmp .+4 ; 0x214c <memcpy+0xa>
2148: 01 90 ld r0, Z+
214a: 0d 92 st X+, r0
214c: 41 50 subi r20, 0x01 ; 1
214e: 50 40 sbci r21, 0x00 ; 0
2150: d8 f7 brcc .-10 ; 0x2148 <memcpy+0x6>
2152: 08 95 ret
 
00002154 <memset>:
2154: dc 01 movw r26, r24
2156: 01 c0 rjmp .+2 ; 0x215a <memset+0x6>
2158: 6d 93 st X+, r22
215a: 41 50 subi r20, 0x01 ; 1
215c: 50 40 sbci r21, 0x00 ; 0
215e: e0 f7 brcc .-8 ; 0x2158 <memset+0x4>
2160: 08 95 ret
 
00002162 <strcpy>:
2162: fb 01 movw r30, r22
2164: dc 01 movw r26, r24
2166: 01 90 ld r0, Z+
2168: 0d 92 st X+, r0
216a: 00 20 and r0, r0
216c: e1 f7 brne .-8 ; 0x2166 <strcpy+0x4>
216e: 08 95 ret
 
00002170 <itoa>:
2170: fb 01 movw r30, r22
2172: 9f 01 movw r18, r30
2174: e8 94 clt
2176: 42 30 cpi r20, 0x02 ; 2
2178: c4 f0 brlt .+48 ; 0x21aa <itoa+0x3a>
217a: 45 32 cpi r20, 0x25 ; 37
217c: b4 f4 brge .+44 ; 0x21aa <itoa+0x3a>
217e: 4a 30 cpi r20, 0x0A ; 10
2180: 29 f4 brne .+10 ; 0x218c <itoa+0x1c>
2182: 97 fb bst r25, 7
2184: 1e f4 brtc .+6 ; 0x218c <itoa+0x1c>
2186: 90 95 com r25
2188: 81 95 neg r24
218a: 9f 4f sbci r25, 0xFF ; 255
218c: 64 2f mov r22, r20
218e: 77 27 eor r23, r23
2190: 0e 94 61 11 call 0x22c2 ; 0x22c2 <__udivmodhi4>
2194: 80 5d subi r24, 0xD0 ; 208
2196: 8a 33 cpi r24, 0x3A ; 58
2198: 0c f0 brlt .+2 ; 0x219c <itoa+0x2c>
219a: 89 5d subi r24, 0xD9 ; 217
219c: 81 93 st Z+, r24
219e: cb 01 movw r24, r22
21a0: 00 97 sbiw r24, 0x00 ; 0
21a2: a1 f7 brne .-24 ; 0x218c <itoa+0x1c>
21a4: 16 f4 brtc .+4 ; 0x21aa <itoa+0x3a>
21a6: 5d e2 ldi r21, 0x2D ; 45
21a8: 51 93 st Z+, r21
21aa: 10 82 st Z, r1
21ac: c9 01 movw r24, r18
21ae: 0c 94 d9 10 jmp 0x21b2 ; 0x21b2 <strrev>
 
000021b2 <strrev>:
21b2: dc 01 movw r26, r24
21b4: fc 01 movw r30, r24
21b6: 67 2f mov r22, r23
21b8: 71 91 ld r23, Z+
21ba: 77 23 and r23, r23
21bc: e1 f7 brne .-8 ; 0x21b6 <strrev+0x4>
21be: 32 97 sbiw r30, 0x02 ; 2
21c0: 04 c0 rjmp .+8 ; 0x21ca <strrev+0x18>
21c2: 7c 91 ld r23, X
21c4: 6d 93 st X+, r22
21c6: 70 83 st Z, r23
21c8: 62 91 ld r22, -Z
21ca: ae 17 cp r26, r30
21cc: bf 07 cpc r27, r31
21ce: c8 f3 brcs .-14 ; 0x21c2 <strrev+0x10>
21d0: 08 95 ret
 
000021d2 <__mulsi3>:
21d2: 62 9f mul r22, r18
21d4: d0 01 movw r26, r0
21d6: 73 9f mul r23, r19
21d8: f0 01 movw r30, r0
21da: 82 9f mul r24, r18
21dc: e0 0d add r30, r0
21de: f1 1d adc r31, r1
21e0: 64 9f mul r22, r20
21e2: e0 0d add r30, r0
21e4: f1 1d adc r31, r1
21e6: 92 9f mul r25, r18
21e8: f0 0d add r31, r0
21ea: 83 9f mul r24, r19
21ec: f0 0d add r31, r0
21ee: 74 9f mul r23, r20
21f0: f0 0d add r31, r0
21f2: 65 9f mul r22, r21
21f4: f0 0d add r31, r0
21f6: 99 27 eor r25, r25
21f8: 72 9f mul r23, r18
21fa: b0 0d add r27, r0
21fc: e1 1d adc r30, r1
21fe: f9 1f adc r31, r25
2200: 63 9f mul r22, r19
2202: b0 0d add r27, r0
2204: e1 1d adc r30, r1
2206: f9 1f adc r31, r25
2208: bd 01 movw r22, r26
220a: cf 01 movw r24, r30
220c: 11 24 eor r1, r1
220e: 08 95 ret
 
00002210 <__udivmodsi4>:
2210: a1 e2 ldi r26, 0x21 ; 33
2212: 1a 2e mov r1, r26
2214: aa 1b sub r26, r26
2216: bb 1b sub r27, r27
2218: fd 01 movw r30, r26
221a: 0d c0 rjmp .+26 ; 0x2236 <__udivmodsi4_ep>
 
0000221c <__udivmodsi4_loop>:
221c: aa 1f adc r26, r26
221e: bb 1f adc r27, r27
2220: ee 1f adc r30, r30
2222: ff 1f adc r31, r31
2224: a2 17 cp r26, r18
2226: b3 07 cpc r27, r19
2228: e4 07 cpc r30, r20
222a: f5 07 cpc r31, r21
222c: 20 f0 brcs .+8 ; 0x2236 <__udivmodsi4_ep>
222e: a2 1b sub r26, r18
2230: b3 0b sbc r27, r19
2232: e4 0b sbc r30, r20
2234: f5 0b sbc r31, r21
 
00002236 <__udivmodsi4_ep>:
2236: 66 1f adc r22, r22
2238: 77 1f adc r23, r23
223a: 88 1f adc r24, r24
223c: 99 1f adc r25, r25
223e: 1a 94 dec r1
2240: 69 f7 brne .-38 ; 0x221c <__udivmodsi4_loop>
2242: 60 95 com r22
2244: 70 95 com r23
2246: 80 95 com r24
2248: 90 95 com r25
224a: 9b 01 movw r18, r22
224c: ac 01 movw r20, r24
224e: bd 01 movw r22, r26
2250: cf 01 movw r24, r30
2252: 08 95 ret
 
00002254 <__prologue_saves__>:
2254: 2f 92 push r2
2256: 3f 92 push r3
2258: 4f 92 push r4
225a: 5f 92 push r5
225c: 6f 92 push r6
225e: 7f 92 push r7
2260: 8f 92 push r8
2262: 9f 92 push r9
2264: af 92 push r10
2266: bf 92 push r11
2268: cf 92 push r12
226a: df 92 push r13
226c: ef 92 push r14
226e: ff 92 push r15
2270: 0f 93 push r16
2272: 1f 93 push r17
2274: cf 93 push r28
2276: df 93 push r29
2278: cd b7 in r28, 0x3d ; 61
227a: de b7 in r29, 0x3e ; 62
227c: ca 1b sub r28, r26
227e: db 0b sbc r29, r27
2280: 0f b6 in r0, 0x3f ; 63
2282: f8 94 cli
2284: de bf out 0x3e, r29 ; 62
2286: 0f be out 0x3f, r0 ; 63
2288: cd bf out 0x3d, r28 ; 61
228a: 09 94 ijmp
 
0000228c <__epilogue_restores__>:
228c: 2a 88 ldd r2, Y+18 ; 0x12
228e: 39 88 ldd r3, Y+17 ; 0x11
2290: 48 88 ldd r4, Y+16 ; 0x10
2292: 5f 84 ldd r5, Y+15 ; 0x0f
2294: 6e 84 ldd r6, Y+14 ; 0x0e
2296: 7d 84 ldd r7, Y+13 ; 0x0d
2298: 8c 84 ldd r8, Y+12 ; 0x0c
229a: 9b 84 ldd r9, Y+11 ; 0x0b
229c: aa 84 ldd r10, Y+10 ; 0x0a
229e: b9 84 ldd r11, Y+9 ; 0x09
22a0: c8 84 ldd r12, Y+8 ; 0x08
22a2: df 80 ldd r13, Y+7 ; 0x07
22a4: ee 80 ldd r14, Y+6 ; 0x06
22a6: fd 80 ldd r15, Y+5 ; 0x05
22a8: 0c 81 ldd r16, Y+4 ; 0x04
22aa: 1b 81 ldd r17, Y+3 ; 0x03
22ac: aa 81 ldd r26, Y+2 ; 0x02
22ae: b9 81 ldd r27, Y+1 ; 0x01
22b0: ce 0f add r28, r30
22b2: d1 1d adc r29, r1
22b4: 0f b6 in r0, 0x3f ; 63
22b6: f8 94 cli
22b8: de bf out 0x3e, r29 ; 62
22ba: 0f be out 0x3f, r0 ; 63
22bc: cd bf out 0x3d, r28 ; 61
22be: ed 01 movw r28, r26
22c0: 08 95 ret
 
000022c2 <__udivmodhi4>:
22c2: aa 1b sub r26, r26
22c4: bb 1b sub r27, r27
22c6: 51 e1 ldi r21, 0x11 ; 17
22c8: 07 c0 rjmp .+14 ; 0x22d8 <__udivmodhi4_ep>
 
000022ca <__udivmodhi4_loop>:
22ca: aa 1f adc r26, r26
22cc: bb 1f adc r27, r27
22ce: a6 17 cp r26, r22
22d0: b7 07 cpc r27, r23
22d2: 10 f0 brcs .+4 ; 0x22d8 <__udivmodhi4_ep>
22d4: a6 1b sub r26, r22
22d6: b7 0b sbc r27, r23
 
000022d8 <__udivmodhi4_ep>:
22d8: 88 1f adc r24, r24
22da: 99 1f adc r25, r25
22dc: 5a 95 dec r21
22de: a9 f7 brne .-22 ; 0x22ca <__udivmodhi4_loop>
22e0: 80 95 com r24
22e2: 90 95 com r25
22e4: bc 01 movw r22, r24
22e6: cd 01 movw r24, r26
22e8: 08 95 ret
 
000022ea <_exit>:
22ea: ff cf rjmp .-2 ; 0x22ea <_exit>
/Designs/GPSRL03A/glg.map
0,0 → 1,532
Archive member included because of file (symbol)
 
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_mulsi3.o)
tff.o (__mulsi3)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodsi4.o)
tff.o (__udivmodsi4)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_prologue.o)
tff.o (__prologue_saves__)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_epilogue.o)
tff.o (__epilogue_restores__)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o (exit)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
main.o (__do_copy_data)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
main.o (__do_clear_bss)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy_P.o)
main.o (strcpy_P)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcmp.o)
tff.o (memcmp)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcpy.o)
tff.o (memcpy)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memset.o)
tff.o (memset)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy.o)
main.o (strcpy)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o)
main.o (itoa)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strrev.o)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o) (strrev)
/usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodhi4.o)
/usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o) (__udivmodhi4)
 
Allocating common symbols
Common symbol size file
 
Value1 0x4 main.o
Timer 0x1 main.o
Buff 0x52 main.o
Stat 0x1 main.o
Value2 0x4 main.o
battery 0x2 main.o
rxfifo 0x99 main.o
intensity 0x2 main.o
file1 0x1c main.o
fatfs 0x220 main.o
 
Memory Configuration
 
Name Origin Length Attributes
text 0x00000000 0x00020000 xr
data 0x00800060 0x0000ffa0 rw !x
eeprom 0x00810000 0x00010000 rw !x
fuse 0x00820000 0x00000400 rw !x
lock 0x00830000 0x00000400 rw !x
signature 0x00840000 0x00000400 rw !x
*default* 0x00000000 0xffffffff
 
Linker script and memory map
 
Address of section .data set to 0x800100
LOAD /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
LOAD main.o
LOAD tff.o
LOAD mmc.o
LOAD /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a
LOAD /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a
LOAD /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a
 
.hash
*(.hash)
 
.dynsym
*(.dynsym)
 
.dynstr
*(.dynstr)
 
.gnu.version
*(.gnu.version)
 
.gnu.version_d
*(.gnu.version_d)
 
.gnu.version_r
*(.gnu.version_r)
 
.rel.init
*(.rel.init)
 
.rela.init
*(.rela.init)
 
.rel.text
*(.rel.text)
*(.rel.text.*)
*(.rel.gnu.linkonce.t*)
 
.rela.text
*(.rela.text)
*(.rela.text.*)
*(.rela.gnu.linkonce.t*)
 
.rel.fini
*(.rel.fini)
 
.rela.fini
*(.rela.fini)
 
.rel.rodata
*(.rel.rodata)
*(.rel.rodata.*)
*(.rel.gnu.linkonce.r*)
 
.rela.rodata
*(.rela.rodata)
*(.rela.rodata.*)
*(.rela.gnu.linkonce.r*)
 
.rel.data
*(.rel.data)
*(.rel.data.*)
*(.rel.gnu.linkonce.d*)
 
.rela.data
*(.rela.data)
*(.rela.data.*)
*(.rela.gnu.linkonce.d*)
 
.rel.ctors
*(.rel.ctors)
 
.rela.ctors
*(.rela.ctors)
 
.rel.dtors
*(.rel.dtors)
 
.rela.dtors
*(.rela.dtors)
 
.rel.got
*(.rel.got)
 
.rela.got
*(.rela.got)
 
.rel.bss
*(.rel.bss)
 
.rela.bss
*(.rela.bss)
 
.rel.plt
*(.rel.plt)
 
.rela.plt
*(.rela.plt)
 
.text 0x00000000 0x22ec
*(.vectors)
.vectors 0x00000000 0x68 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
0x00000000 __vectors
0x00000000 __vector_default
*(.vectors)
*(.progmem.gcc*)
*(.progmem*)
.progmem.data 0x00000068 0x30 main.o
0x00000098 . = ALIGN (0x2)
0x00000098 __trampolines_start = .
*(.trampolines)
.trampolines 0x00000098 0x0 linker stubs
*(.trampolines*)
0x00000098 __trampolines_end = .
*(.jumptables)
*(.jumptables*)
*(.lowtext)
*(.lowtext*)
0x00000098 __ctors_start = .
*(.ctors)
0x00000098 __ctors_end = .
0x00000098 __dtors_start = .
*(.dtors)
0x00000098 __dtors_end = .
SORT(*)(.ctors)
SORT(*)(.dtors)
*(.init0)
.init0 0x00000098 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
0x00000098 __init
*(.init0)
*(.init1)
*(.init1)
*(.init2)
.init2 0x00000098 0xc /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
*(.init2)
*(.init3)
*(.init3)
*(.init4)
.init4 0x000000a4 0x16 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
0x000000a4 __do_copy_data
.init4 0x000000ba 0x10 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
0x000000ba __do_clear_bss
*(.init4)
*(.init5)
*(.init5)
*(.init6)
*(.init6)
*(.init7)
*(.init7)
*(.init8)
*(.init8)
*(.init9)
.init9 0x000000ca 0x8 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
*(.init9)
*(.text)
.text 0x000000d2 0x4 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
0x000000d2 __vector_22
0x000000d2 __vector_1
0x000000d2 __vector_24
0x000000d2 __vector_12
0x000000d2 __bad_interrupt
0x000000d2 __vector_6
0x000000d2 __vector_3
0x000000d2 __vector_23
0x000000d2 __vector_25
0x000000d2 __vector_13
0x000000d2 __vector_17
0x000000d2 __vector_19
0x000000d2 __vector_7
0x000000d2 __vector_5
0x000000d2 __vector_4
0x000000d2 __vector_9
0x000000d2 __vector_2
0x000000d2 __vector_15
0x000000d2 __vector_8
0x000000d2 __vector_14
0x000000d2 __vector_10
0x000000d2 __vector_16
0x000000d2 __vector_20
.text 0x000000d6 0x55a main.o
0x000002f4 __vector_11
0x00000176 get_fattime
0x00000374 main
0x000000d6 __vector_21
0x000001ac __vector_18
.text 0x00000630 0x1376 tff.o
0x00000d68 f_close
0x00000ff0 f_read
0x00000cba f_sync
0x000011de f_mount
0x00000b16 f_lseek
0x00000d80 f_write
0x00001288 f_open
.text 0x000019a6 0x774 mmc.o
0x00001f5c disk_initialize
0x00001b7e disk_status
0x00001bd0 disk_ioctl
0x00001b90 disk_timerproc
0x00001da6 disk_write
0x00001ea2 disk_read
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_mulsi3.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodsi4.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_prologue.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_epilogue.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
.text 0x0000211a 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
.text 0x0000211a 0xe /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy_P.o)
0x0000211a strcpy_P
.text 0x00002128 0x1a /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcmp.o)
0x00002128 memcmp
.text 0x00002142 0x12 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcpy.o)
0x00002142 memcpy
.text 0x00002154 0xe /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memset.o)
0x00002154 memset
.text 0x00002162 0xe /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy.o)
0x00002162 strcpy
.text 0x00002170 0x42 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o)
0x00002170 itoa
.text 0x000021b2 0x20 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strrev.o)
0x000021b2 strrev
.text 0x000021d2 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodhi4.o)
0x000021d2 . = ALIGN (0x2)
*(.text.*)
.text.libgcc 0x000021d2 0x3e /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_mulsi3.o)
0x000021d2 __mulsi3
.text.libgcc 0x00002210 0x44 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodsi4.o)
0x00002210 __udivmodsi4
.text.libgcc 0x00002254 0x38 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_prologue.o)
0x00002254 __prologue_saves__
.text.libgcc 0x0000228c 0x36 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_epilogue.o)
0x0000228c __epilogue_restores__
.text.libgcc 0x000022c2 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
.text.libgcc 0x000022c2 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
.text.libgcc 0x000022c2 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
.text.libgcc 0x000022c2 0x28 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodhi4.o)
0x000022c2 __udivmodhi4
0x000022ea . = ALIGN (0x2)
*(.fini9)
.fini9 0x000022ea 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
0x000022ea exit
0x000022ea _exit
*(.fini9)
*(.fini8)
*(.fini8)
*(.fini7)
*(.fini7)
*(.fini6)
*(.fini6)
*(.fini5)
*(.fini5)
*(.fini4)
*(.fini4)
*(.fini3)
*(.fini3)
*(.fini2)
*(.fini2)
*(.fini1)
*(.fini1)
*(.fini0)
.fini0 0x000022ea 0x2 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
*(.fini0)
0x000022ec _etext = .
 
.data 0x00800100 0x6 load address 0x000022ec
0x00800100 PROVIDE (__data_start, .)
*(.data)
.data 0x00800100 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
.data 0x00800100 0x0 main.o
.data 0x00800100 0x4 tff.o
.data 0x00800104 0x1 mmc.o
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_mulsi3.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodsi4.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_prologue.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_epilogue.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy_P.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcmp.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcpy.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memset.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strrev.o)
.data 0x00800105 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodhi4.o)
*(.data*)
*(.rodata)
*(.rodata*)
*(.gnu.linkonce.d*)
0x00800106 . = ALIGN (0x2)
*fill* 0x00800105 0x1 00
0x00800106 _edata = .
0x00800106 PROVIDE (__data_end, .)
 
.bss 0x00800106 0x341 load address 0x000022f2
0x00800106 PROVIDE (__bss_start, .)
*(.bss)
.bss 0x00800106 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
.bss 0x00800106 0x4 main.o
.bss 0x0080010a 0x4 tff.o
.bss 0x0080010e 0x4 mmc.o
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_mulsi3.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodsi4.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_prologue.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_epilogue.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_exit.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_copy_data.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_clear_bss.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy_P.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcmp.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcpy.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memset.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strrev.o)
.bss 0x00800112 0x0 /usr/lib/gcc/avr/4.2.2/avr5/libgcc.a(_udivmodhi4.o)
*(.bss*)
*(COMMON)
COMMON 0x00800112 0x335 main.o
0x00800112 Value1
0x00800116 Timer
0x00800117 Buff
0x00800169 Stat
0x0080016a Value2
0x0080016e battery
0x00800170 rxfifo
0x00800209 intensity
0x0080020b file1
0x00800227 fatfs
0x00800447 PROVIDE (__bss_end, .)
0x000022ec __data_load_start = LOADADDR (.data)
0x000022f2 __data_load_end = (__data_load_start + SIZEOF (.data))
 
.noinit 0x00800447 0x0
0x00800447 PROVIDE (__noinit_start, .)
*(.noinit*)
0x00800447 PROVIDE (__noinit_end, .)
0x00800447 _end = .
0x00800447 PROVIDE (__heap_start, .)
 
.eeprom 0x00810000 0x0
*(.eeprom*)
0x00810000 __eeprom_end = .
 
.fuse
*(.fuse)
*(.lfuse)
*(.hfuse)
*(.efuse)
 
.lock
*(.lock*)
 
.signature
*(.signature*)
 
.stab 0x00000000 0x87c
*(.stab)
.stab 0x00000000 0x378 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
.stab 0x00000378 0x6c /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy_P.o)
0x78 (size before relaxing)
.stab 0x000003e4 0xb4 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcmp.o)
0xc0 (size before relaxing)
.stab 0x00000498 0x84 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memcpy.o)
0x90 (size before relaxing)
.stab 0x0000051c 0x6c /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(memset.o)
0x78 (size before relaxing)
.stab 0x00000588 0x6c /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strcpy.o)
0x78 (size before relaxing)
.stab 0x000005f4 0x1b0 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(itoa.o)
0x1bc (size before relaxing)
.stab 0x000007a4 0xd8 /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/libc.a(strrev.o)
0xe4 (size before relaxing)
 
.stabstr 0x00000000 0x19e
*(.stabstr)
.stabstr 0x00000000 0x19e /usr/lib/gcc/avr/4.2.2/../../../../avr/lib/avr5/crtm168.o
 
.stab.excl
*(.stab.excl)
 
.stab.exclstr
*(.stab.exclstr)
 
.stab.index
*(.stab.index)
 
.stab.indexstr
*(.stab.indexstr)
 
.comment
*(.comment)
 
.debug
*(.debug)
 
.line
*(.line)
 
.debug_srcinfo
*(.debug_srcinfo)
 
.debug_sfnames
*(.debug_sfnames)
 
.debug_aranges 0x00000000 0x60
*(.debug_aranges)
.debug_aranges
0x00000000 0x20 main.o
.debug_aranges
0x00000020 0x20 tff.o
.debug_aranges
0x00000040 0x20 mmc.o
 
.debug_pubnames
0x00000000 0x19e
*(.debug_pubnames)
.debug_pubnames
0x00000000 0xc6 main.o
.debug_pubnames
0x000000c6 0x63 tff.o
.debug_pubnames
0x00000129 0x75 mmc.o
 
.debug_info 0x00000000 0x1cfd
*(.debug_info)
.debug_info 0x00000000 0x8c0 main.o
.debug_info 0x000008c0 0xea2 tff.o
.debug_info 0x00001762 0x59b mmc.o
*(.gnu.linkonce.wi.*)
 
.debug_abbrev 0x00000000 0x7a6
*(.debug_abbrev)
.debug_abbrev 0x00000000 0x2fb main.o
.debug_abbrev 0x000002fb 0x2ca tff.o
.debug_abbrev 0x000005c5 0x1e1 mmc.o
 
.debug_line 0x00000000 0x19a4
*(.debug_line)
.debug_line 0x00000000 0x5df main.o
.debug_line 0x000005df 0xd36 tff.o
.debug_line 0x00001315 0x68f mmc.o
 
.debug_frame 0x00000000 0x260
*(.debug_frame)
.debug_frame 0x00000000 0xb0 main.o
.debug_frame 0x000000b0 0x100 tff.o
.debug_frame 0x000001b0 0xb0 mmc.o
 
.debug_str 0x00000000 0x5e8
*(.debug_str)
.debug_str 0x00000000 0x289 main.o
0x2e4 (size before relaxing)
.debug_str 0x00000289 0x29f tff.o
0x431 (size before relaxing)
.debug_str 0x00000528 0xc0 mmc.o
0x1e4 (size before relaxing)
 
.debug_loc 0x00000000 0x20ca
*(.debug_loc)
.debug_loc 0x00000000 0x2d9 main.o
.debug_loc 0x000002d9 0x190c tff.o
.debug_loc 0x00001be5 0x4e5 mmc.o
 
.debug_macinfo
*(.debug_macinfo)
OUTPUT(glg.elf elf32-avr)
LOAD linker stubs
 
.debug_ranges 0x00000000 0x178
.debug_ranges 0x00000000 0x178 tff.o
/Designs/GPSRL03A/glg_sch.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/Designs/GPSRL03A/integer.h
0,0 → 1,23
#ifndef _INTEGER
 
typedef int INT;
typedef unsigned int UINT;
 
typedef char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
 
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
 
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
 
typedef unsigned char BOOL;
#define FALSE 0
#define TRUE 1
 
#define _INTEGER
#endif
/Designs/GPSRL03A/main.c
0,0 → 1,429
/*---------------------------------------------------------------*/
/* GPS data logger R0.02 (C)ChaN, 2008 */
/*---------------------------------------------------------------*/
 
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <string.h>
#include "tff.h"
#include "diskio.h"
 
 
#define SYSCLK 10000000UL
 
#define BEEP_ON() TCCR0B=0b011
#define BEEP_OFF() TCCR0B=0b000
#define GPS_ON() PORTB|=0x02
#define GPS_OFF() PORTB&=0xFD
#define DELAY(dly) for(Timer=dly;Timer;)
 
#define VTH_LOW (WORD)(8000UL*100/3838)
#define VTH_HIGH (WORD)(11500UL*100/3838)
#define POWER_check 0b01000000 | 1
#define ANALOG_IN1 0b01000000 | 2
 
 
FATFS fatfs; /* File system object for each logical drive */
FIL file1; /* File object */
BYTE Buff[82]; /* File/Console buffer */
 
BYTE Value1[4]; // logged values
BYTE Value2[4];
 
uint16_t battery; // battery voltage
uint16_t intensity; // radiation intensity
 
volatile BYTE Timer; /* 100Hz decrement timer */
volatile BYTE Stat; /* Status */
 
 
typedef struct _fifo {
uint8_t idx_w;
uint8_t idx_r;
uint8_t count;
uint8_t buff[150];
} FIFO;
volatile FIFO rxfifo;
 
 
 
/*---------------------------------------------------------*/
/* ADC interrupt */
/*---------------------------------------------------------*/
 
ISR(ADC_vect)
{
WORD n;
static BYTE l, h;
 
n = ADC;
 
if(ADMUX == POWER_check)
{
if (n < VTH_LOW) {
if (l >= 15) {
Stat |= 0x01;
}
else {l++;}
}
else {l = 0;}
 
if (n > VTH_HIGH) {
if (h >= 15) {
Stat &= 0xFE;
}
else {h++;}
}
else {h = 0;}
 
battery = n;
ADMUX = ANALOG_IN1;
}
 
if(ADMUX == ANALOG_IN1)
{
intensity = n;
ADMUX = POWER_check;
}
 
//!!!!
//Stat &= 0xFE;
 
ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADIF)|_BV(ADIE)|0b111;
}
 
 
/*---------------------------------------------------------*/
/* 100Hz timer interrupt generated by OC1A */
/*---------------------------------------------------------*/
 
 
ISR(TIMER1_COMPA_vect)
{
BYTE n;
static WORD ivt_sync;
 
 
n = Timer;
if (n) Timer = n - 1;
 
if (++ivt_sync >= 180 * 100) {
ivt_sync = 0;
Stat |= 4;
}
 
disk_timerproc(); /* Drive timer procedure of low level disk I/O module */
 
}
 
 
 
/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from */
/* FatFs module. Any valid time must be returned even if */
/* the system does not support a real time clock. */
 
 
DWORD get_fattime ()
{
return ((2007UL - 1980) << 25) /* Fixed to 2007.5.1, 00:00:00 */
| ((5UL) << 21)
| ((1UL) << 16)
| (0 << 11)
| (0 << 5)
| (0 >> 1);
}
 
 
/*--------------------------------------------------------------------------*/
/* UART control */
 
 
static
void uart_init (void)
{
cli();
UCSR0B = 0;
rxfifo.idx_r = 0;
rxfifo.idx_w = 0;
rxfifo.count = 0;
UBRR0L = SYSCLK/16/9600; // Enable USRAT0 in N81,4800bps
UCSR0B = _BV(RXCIE0)|_BV(RXEN0)|_BV(TXEN0);
Stat &= 0xFD; // Clear overflow flag
sei();
}
 
 
static
void uart_stop (void)
{
UCSR0B = 0;
}
 
 
/* Get a received character */
static
uint8_t uart_get ()
{
uint8_t d, i;
 
 
i = rxfifo.idx_r;
if (rxfifo.count == 0) return 0;
d = rxfifo.buff[i++];
cli();
rxfifo.count--;
sei();
if(i >= sizeof(rxfifo.buff))
i = 0;
rxfifo.idx_r = i;
 
return d;
}
 
 
/* Put a character to transmit */
static
void uart_put (uint8_t d)
{
while (bit_is_clear(UCSR0A, UDRE0));
UDR0 = d;
}
 
 
/* USART0 RXC interrupt */
ISR(USART_RX_vect)
{
uint8_t d, n, i;
 
 
d = UDR0;
n = rxfifo.count;
if(n < sizeof(rxfifo.buff)) {
rxfifo.count = ++n;
i = rxfifo.idx_w;
rxfifo.buff[i++] = d;
if(i >= sizeof(rxfifo.buff))
i = 0;
rxfifo.idx_w = i;
} else {
Stat |= 2;
}
}
 
 
 
/*----------------------------------------------------*/
/* Get a line received from GPS module */
/*----------------------------------------------------*/
 
static
BYTE get_line (void) // 0: Power fail occured, >0: Number of bytes received.
{
BYTE c, i = 0;
 
 
for (;;) {
if (Stat & 1) return 0; // When power fail is detected, return with zero.
c = uart_get();
if (Stat & 2) { // When buffer overflow has occured, restert to receive line.
uart_init();
i = 0; c = 0;
}
if (!c || (i == 0 && c != '$')) continue;
Buff[i++] = c;
if (c == '\n') break;
if (i >= sizeof(Buff)) i = 0;
}
return i;
}
 
 
 
/*--------------------------------------------------------------------------*/
/* Controls */
 
static
void beep (BYTE len, BYTE cnt)
{
while (cnt--) {
BEEP_ON();
DELAY(len);
BEEP_OFF();
DELAY(len);
}
}
 
 
 
 
/* Compare sentence header string */
static
BYTE gp_comp (BYTE *str1, const prog_uint8_t *str2)
{
BYTE c;
 
do {
c = pgm_read_byte(str2++);
} while (c && c == *str1++);
return c;
}
 
 
 
/* Initialize GPS module (depends on each product) */
static
void gp_init (void)
{
const prog_char *s =
PSTR("$PSRF106,21*0F\r\n"); // Select datum of WGS84 (for EM-406A)
char c;
 
while ((c = pgm_read_byte(s++)) != 0) uart_put(c);
}
 
 
 
/* Get a column item */
static
BYTE* gp_col ( /* Returns pointer to the item (returns a NULL when not found) */
const BYTE* buf, /* Pointer to the sentence */
BYTE col /* Column number (0 is the 1st item) */
) {
BYTE c;
 
 
while (col) {
do {
c = *buf++;
if (c <= ' ') return NULL;
} while (c != ',');
col--;
}
return (BYTE*)buf;
}
 
 
 
static
void ioinit (void)
{
PORTB = 0b00001101; // Port B
DDRB = 0b00101110;
PORTC = 0b00111111; // Port C
DDRC = 0b00000000;
PORTD = 0b10101110; // Port D
DDRD = 0b01010010;
 
SPCR = 0b01010000; /* Initialize SPI port (Mode 0) */
SPSR = 0b00000001;
 
OCR1A = SYSCLK/8/100-1; // Timer1: 100Hz interval (OC1A)
TCCR1B = 0b00001010;
TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
 
OCR0A = SYSCLK/64/4000/2-1; // Timer0: 4kHz sound (OC0A)
TCCR0A = 0b01000010;
 
ADMUX = POWER_check; // Select ADC input
ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADIF)|_BV(ADIE)|0b111;
 
sei();
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Main */
 
 
int main ()
{
BYTE b, err, *p = NULL;
WORD s;
 
 
ioinit();
f_mount(0, &fatfs); /* Enable file I/O layer */
 
for (;;) {
uart_stop();
GPS_OFF();
Timer = 100;
do {
if (Stat & 1) Timer = 100;
} while (Timer);
 
GPS_ON();
Timer = 255;
do {
if ((Stat & 1) || (disk_status(0) & STA_NODISK)) Timer = 255;
} while (Timer);
 
beep(5, 1); // Single beep. Start to get current time.
uart_init();
gp_init(); // Initialize GPS module to let output data in NMEA-0183 format.
do { // Wait for valid RMC sentence.
b = get_line();
if (!b) break;
if (gp_comp(Buff, PSTR("$GPRMC"))) continue;
p = gp_col(Buff,2);
} while (!p || *p != 'A');
if (!b) continue;
p = gp_col(Buff,9); // Open log file with the name of current date (YYMMDD.log in UTC).
if (!p) {err = 3; break;}
 
memcpy(&Buff[0], p+4, 2);
memcpy(&Buff[2], p+2, 2);
memcpy(&Buff[4], p+0, 2);
strcpy_P(&Buff[6], PSTR(".log"));
if (f_open(&file1, Buff, FA_OPEN_ALWAYS | FA_WRITE) || f_lseek(&file1, file1.fsize)) { err = 4; break; }
 
beep(5, 2); // Two beeps. Start logging.
err = 0;
while ((b = get_line()) > 0) {
if ( !gp_comp(Buff, PSTR("$GPGGA")) // Which sentence is logged?
|| !gp_comp(Buff, PSTR("$GPRMC"))
// || !gp_comp(Buff, PSTR("$GPGSA"))
// || !gp_comp(Buff, PSTR("$GPGLL"))
// || !gp_comp(Buff, PSTR("$GPGSV"))
// || !gp_comp(Buff, PSTR("$GPZDA"))
// || !gp_comp(Buff, PSTR("$GPVTG"))
)
{
if (f_write(&file1, Buff, b, &s) || b != s) { err = 5; break; };
itoa(battery,&Value1,10);
itoa(intensity,&Value2,10);
strcpy(&Buff[0], Value1);
strcpy_P(&Buff[4], PSTR(","));
strcpy(&Buff[5], Value2);
strcpy_P(&Buff[9], PSTR("\r\n"));
if (f_write(&file1, Buff, 11, &s) || 11 != s) { err = 5; break; };
}
if ((Stat & 4) == 0) continue;
if (f_sync(&file1)) { err = 6; break; };// Synchronize the file in interval of 300 sec.
cli(); Stat &= 0xFB; sei(); // Clear sync request
}
if (err) break;
 
// Turn-off GPS power and close the log file by power supply is discharged.
uart_stop();
GPS_OFF();
if (f_close(&file1)) { err = 7; break; };
 
// When a long beep is sounded, the shutdoun process has been succeeded.
beep(50, 1);
}
 
// Unrecoverble error. Enter shutdown state.
uart_stop();
GPS_OFF();
beep(25, err);
for (;;);
}
 
 
/Designs/GPSRL03A/mmc.c
0,0 → 1,487
/*-----------------------------------------------------------------------*/
/* MMC/SDC (in SPI mode) control module (C)ChaN, 2006 */
/*-----------------------------------------------------------------------*/
/* Only rcvr_spi(), xmit_spi(), disk_timerproc(), disk_initialize () and */
/* some macros are platform dependent. */
/*-----------------------------------------------------------------------*/
 
 
#include <avr/io.h>
#include "diskio.h"
 
 
/* Definitions for MMC/SDC command */
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
#define CMD1 (0x40+1) /* SEND_OP_COND */
#define CMD8 (0x40+8) /* SEND_IF_COND */
#define CMD9 (0x40+9) /* SEND_CSD */
#define CMD10 (0x40+10) /* SEND_CID */
#define CMD12 (0x40+12) /* STOP_TRANSMISSION */
#define CMD16 (0x40+16) /* SET_BLOCKLEN */
#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */
#define CMD18 (0x40+18) /* READ_MULTIPLE_BLOCK */
#define CMD23 (0x40+23) /* SET_BLOCK_COUNT */
#define CMD24 (0x40+24) /* WRITE_BLOCK */
#define CMD25 (0x40+25) /* WRITE_MULTIPLE_BLOCK */
#define CMD41 (0x40+41) /* SEND_OP_COND (ACMD) */
#define CMD55 (0x40+55) /* APP_CMD */
#define CMD58 (0x40+58) /* READ_OCR */
 
 
/* Control signals (Platform dependent) */
#define SELECT() PORTB &= ~_BV(PB2) /* MMC CS = L */
#define DESELECT() PORTB |= _BV(PB2) /* MMC CS = H */
 
#define SOCKPORT PINB /* Socket contact port */
#define SOCKINS 0x01 /* Card detect switch (PB0) */
 
 
 
/*--------------------------------------------------------------------------
 
Module Private Functions
 
---------------------------------------------------------------------------*/
 
static volatile
DSTATUS Stat = STA_NOINIT; /* Disk status */
 
static volatile
BYTE Timer1, Timer2; /* 100Hz decrement timer */
 
static
BYTE CardType; /* b0:MMC, b1:SDC, b2:Block addressing */
 
 
 
/*-----------------------------------------------------------------------*/
/* Transmit a byte to MMC via SPI (Platform dependent) */
/*-----------------------------------------------------------------------*/
 
#define xmit_spi(dat) SPDR=(dat); loop_until_bit_is_set(SPSR,SPIF)
 
 
 
/*-----------------------------------------------------------------------*/
/* Receive a byte from MMC via SPI (Platform dependent) */
/*-----------------------------------------------------------------------*/
 
static
BYTE rcvr_spi (void)
{
SPDR = 0xFF;
loop_until_bit_is_set(SPSR, SPIF);
return SPDR;
}
 
/* Alternative macro to receive data fast */
#define rcvr_spi_m(dst) SPDR=0xFF; loop_until_bit_is_set(SPSR,SPIF); *(dst)=SPDR
 
 
 
/*-----------------------------------------------------------------------*/
/* Wait for card ready */
/*-----------------------------------------------------------------------*/
 
static
BYTE wait_ready (void)
{
BYTE res;
 
 
Timer2 = 50; /* Wait for ready in timeout of 500ms */
rcvr_spi();
do
res = rcvr_spi();
while ((res != 0xFF) && Timer2);
 
return res;
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Receive a data packet from MMC */
/*-----------------------------------------------------------------------*/
 
static
BOOL rcvr_datablock (
BYTE *buff, /* Data buffer to store received data */
UINT btr /* Byte count (must be even number) */
)
{
BYTE token;
 
 
Timer1 = 10;
do { /* Wait for data packet in timeout of 100ms */
token = rcvr_spi();
} while ((token == 0xFF) && Timer1);
if(token != 0xFE) return FALSE; /* If not valid data token, retutn with error */
 
do { /* Receive the data block into buffer */
rcvr_spi_m(buff++);
rcvr_spi_m(buff++);
} while (btr -= 2);
rcvr_spi(); /* Discard CRC */
rcvr_spi();
 
return TRUE; /* Return with success */
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Send a data packet to MMC */
/*-----------------------------------------------------------------------*/
 
#if _READONLY == 0
static
BOOL xmit_datablock (
const BYTE *buff, /* 512 byte data block to be transmitted */
BYTE token /* Data/Stop token */
)
{
BYTE resp, wc;
 
 
if (wait_ready() != 0xFF) return FALSE;
 
xmit_spi(token); /* Xmit data token */
if (token != 0xFD) { /* Is data token */
wc = 0;
do { /* Xmit the 512 byte data block to MMC */
xmit_spi(*buff++);
xmit_spi(*buff++);
} while (--wc);
xmit_spi(0xFF); /* CRC (Dummy) */
xmit_spi(0xFF);
resp = rcvr_spi(); /* Reveive data response */
if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */
return FALSE;
}
 
return TRUE;
}
#endif /* _READONLY */
 
 
 
/*-----------------------------------------------------------------------*/
/* Send a command packet to MMC */
/*-----------------------------------------------------------------------*/
 
static
BYTE send_cmd (
BYTE cmd, /* Command byte */
DWORD arg /* Argument */
)
{
BYTE n, res;
 
 
if (wait_ready() != 0xFF) return 0xFF;
 
/* Send command packet */
xmit_spi(cmd); /* Command */
xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
xmit_spi((BYTE)(arg >> 16)); /* Argument[23..16] */
xmit_spi((BYTE)(arg >> 8)); /* Argument[15..8] */
xmit_spi((BYTE)arg); /* Argument[7..0] */
n = 0;
if (cmd == CMD0) n = 0x95; /* CRC for CMD0(0) */
if (cmd == CMD8) n = 0x87; /* CRC for CMD8(0x1AA) */
xmit_spi(n);
 
/* Receive command response */
if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do
res = rcvr_spi();
while ((res & 0x80) && --n);
 
return res; /* Return with the response value */
}
 
 
 
 
/*--------------------------------------------------------------------------
 
Public Functions
 
---------------------------------------------------------------------------*/
 
 
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
 
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0) */
)
{
BYTE n, ty, ocr[4];
 
 
if (drv) return STA_NOINIT; /* Supports only single drive */
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
 
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
 
SELECT(); /* CS = L */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
Timer1 = 100; /* Initialization timeout of 1000 msec */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDC Ver2+ */
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
do {
if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 1UL << 30) == 0) break; /* ACMD41 with HCS bit */
} while (Timer1);
if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit */
for (n = 0; n < 4; n++) ocr[n] = rcvr_spi();
ty = (ocr[0] & 0x40) ? 6 : 2;
}
}
} else { /* SDC Ver1 or MMC */
ty = (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) <= 1) ? 2 : 1; /* SDC : MMC */
do {
if (ty == 2) {
if (send_cmd(CMD55, 0) <= 1 && send_cmd(CMD41, 0) == 0) break; /* ACMD41 */
} else {
if (send_cmd(CMD1, 0) == 0) break; /* CMD1 */
}
} while (Timer1);
if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Select R/W block length */
ty = 0;
}
}
CardType = ty;
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
if (ty) { /* Initialization succeded */
Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
} else { /* Initialization failed */
Stat |= STA_NOINIT; /* Set STA_NOINIT */
}
 
return Stat;
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Get Disk Status */
/*-----------------------------------------------------------------------*/
 
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0) */
)
{
if (drv) return STA_NOINIT; /* Supports only single drive */
return Stat;
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
/*-----------------------------------------------------------------------*/
 
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0) */
BYTE *buff, /* Pointer to the data buffer to store read data */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
 
if (!(CardType & 4)) sector *= 512; /* Convert to byte address if needed */
 
SELECT(); /* CS = L */
 
if (count == 1) { /* Single block read */
if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */
&& rcvr_datablock(buff, 512))
count = 0;
}
else { /* Multiple block read */
if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */
do {
if (!rcvr_datablock(buff, 512)) break;
buff += 512;
} while (--count);
send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
}
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return count ? RES_ERROR : RES_OK;
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
 
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0) */
const BYTE *buff, /* Pointer to the data to be written */
DWORD sector, /* Start sector number (LBA) */
BYTE count /* Sector count (1..255) */
)
{
if (drv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (Stat & STA_PROTECT) return RES_WRPRT;
 
if (!(CardType & 4)) sector *= 512; /* Convert to byte address if needed */
 
SELECT(); /* CS = L */
 
if (count == 1) { /* Single block write */
if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
&& xmit_datablock(buff, 0xFE))
count = 0;
}
else { /* Multiple block write */
if (CardType & 2) {
send_cmd(CMD55, 0); send_cmd(CMD23, count); /* ACMD23 */
}
if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
do {
if (!xmit_datablock(buff, 0xFC)) break;
buff += 512;
} while (--count);
if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */
count = 1;
}
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return count ? RES_ERROR : RES_OK;
}
#endif /* _READONLY */
 
 
 
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/
 
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
DRESULT res;
BYTE n, csd[16], *ptr = buff;
WORD csize;
 
 
if (drv) return RES_PARERR;
 
SELECT(); /* CS = L */
 
res = RES_ERROR;
switch (ctrl) {
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
csize = csd[9] + ((WORD)csd[8] << 8) + 1;
*(DWORD*)buff = (DWORD)csize << 10;
} else { /* MMC or SDC ver 1.XX */
n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
*(DWORD*)buff = (DWORD)csize << (n - 9);
}
res = RES_OK;
}
break;
 
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
*(WORD*)buff = 512;
res = RES_OK;
break;
 
case CTRL_SYNC : /* Make sure that data has been written */
if (wait_ready() == 0xFF)
res = RES_OK;
break;
 
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
if ((send_cmd(CMD9, 0) == 0) /* READ_CSD */
&& rcvr_datablock(ptr, 16))
res = RES_OK;
break;
 
case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
if ((send_cmd(CMD10, 0) == 0) /* READ_CID */
&& rcvr_datablock(ptr, 16))
res = RES_OK;
break;
 
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
for (n = 0; n < 4; n++)
*ptr++ = rcvr_spi();
res = RES_OK;
}
break;
 
default:
res = RES_PARERR;
}
 
DESELECT(); /* CS = H */
rcvr_spi(); /* Idle (Release DO) */
 
return res;
}
 
 
 
/*---------------------------------------*/
/* Device timer interrupt procedure */
/* This must be called in period of 10ms */
/* (Platform dependent) */
 
void disk_timerproc (void)
{
static BYTE pv;
BYTE n, s;
 
 
n = Timer1; /* 100Hz decrement timer */
if (n) Timer1 = --n;
n = Timer2;
if (n) Timer2 = --n;
 
n = pv;
pv = SOCKPORT & (SOCKINS); /* Sample socket switch */
 
if (n == pv) { /* Have contacts stabled? */
s = Stat;
if (pv & SOCKINS) /* INS = H (Socket empty) */
s |= (STA_NODISK | STA_NOINIT);
else /* INS = L (Card inserted) */
s &= ~STA_NODISK;
 
Stat = s;
}
}
 
/Designs/GPSRL03A/tff.c
0,0 → 1,1580
/*--------------------------------------------------------------------------/
/ FatFs - Tiny FAT file system module R0.04b (C)ChaN, 2007
/---------------------------------------------------------------------------/
/ The FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2007, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
/ profit use without any restriction under your responsibility.
/ * Redistributions of source code must retain the above copyright notice.
/
/---------------------------------------------------------------------------/
/ Feb 26, 2006 R0.00 Prototype.
/ Apr 29, 2006 R0.01 First stable version.
/ Jun 01, 2006 R0.02 Added FAT12 support.
/ Removed unbuffered mode.
/ Fixed a problem on small (<32M) patition.
/ Jun 10, 2006 R0.02a Added a configuration option (_FS_MINIMUM).
/ Sep 22, 2006 R0.03 Added f_rename().
/ Changed option _FS_MINIMUM to _FS_MINIMIZE.
/ Dec 09, 2006 R0.03a Improved cluster scan algolithm to write files fast.
/ Feb 04, 2007 R0.04 Added FAT32 supprt.
/ Changed some interfaces incidental to FatFs.
/ Changed f_mountdrv() to f_mount().
/ Apr 01, 2007 R0.04a Added a capability of extending file size to f_lseek().
/ Added minimization level 3.
/ Fixed a problem in FAT32 support.
/ xxx xx, 2007 R0.04b Added a configuration option _USE_NTFLAG.
/ Added FSInfo support.
/ Fixed some problems corresponds to FAT32 support.
/ Fixed DBCS name can result FR_INVALID_NAME.
/ Fixed short seek (<= csize) collapses the file object.
/---------------------------------------------------------------------------*/
 
#include <string.h>
#include "tff.h" /* Tiny-FatFs declarations */
#include "diskio.h" /* Include file for user provided disk functions */
 
 
static
FATFS *FatFs; /* Pointer to the file system objects (logical drive) */
static
WORD fsid; /* File system mount ID */
 
 
/*-------------------------------------------------------------------------
 
Module Private Functions
 
-------------------------------------------------------------------------*/
 
 
/*-----------------------------------------------------------------------*/
/* Change window offset */
/*-----------------------------------------------------------------------*/
 
static
BOOL move_window ( /* TRUE: successful, FALSE: failed */
DWORD sector /* Sector number to make apperance in the FatFs->win */
) /* Move to zero only writes back dirty window */
{
DWORD wsect;
FATFS *fs = FatFs;
 
 
wsect = fs->winsect;
if (wsect != sector) { /* Changed current window */
#if !_FS_READONLY
BYTE n;
if (fs->winflag) { /* Write back dirty window if needed */
if (disk_write(0, fs->win, wsect, 1) != RES_OK)
return FALSE;
fs->winflag = 0;
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
wsect += fs->sects_fat;
disk_write(0, fs->win, wsect, 1);
}
}
}
#endif
if (sector) {
if (disk_read(0, fs->win, sector, 1) != RES_OK)
return FALSE;
fs->winsect = sector;
}
}
return TRUE;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Clean-up cached data */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
FRESULT sync (void) /* FR_OK: successful, FR_RW_ERROR: failed */
{
FATFS *fs = FatFs;
 
 
fs->winflag = 1;
if (!move_window(0)) return FR_RW_ERROR;
#if _USE_FSINFO
if (fs->fs_type == FS_FAT32 && fs->fsi_flag) { /* Update FSInfo sector if needed */
fs->winsect = 0;
memset(fs->win, 0, 512);
ST_WORD(&fs->win[BS_55AA], 0xAA55);
ST_DWORD(&fs->win[FSI_LeadSig], 0x41615252);
ST_DWORD(&fs->win[FSI_StrucSig], 0x61417272);
ST_DWORD(&fs->win[FSI_Free_Count], fs->free_clust);
ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust);
disk_write(0, fs->win, fs->fsi_sector, 1);
fs->fsi_flag = 0;
}
#endif
if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK) return FR_RW_ERROR;
return FR_OK;
}
#endif
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get a cluster status */
/*-----------------------------------------------------------------------*/
 
static
CLUST get_cluster ( /* 0,>=2: successful, 1: failed */
CLUST clust /* Cluster# to get the link information */
)
{
WORD wc, bc;
DWORD fatsect;
FATFS *fs = FatFs;
 
 
if (clust >= 2 && clust < fs->max_clust) { /* Valid cluster# */
fatsect = fs->fatbase;
switch (fs->fs_type) {
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fatsect + bc / 512)) break;
wc = fs->win[bc % 512]; bc++;
if (!move_window(fatsect + bc / 512)) break;
wc |= (WORD)fs->win[bc % 512] << 8;
return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
 
case FS_FAT16 :
if (!move_window(fatsect + clust / 256)) break;
return LD_WORD(&fs->win[((WORD)clust * 2) % 512]);
#if _FAT32
case FS_FAT32 :
if (!move_window(fatsect + clust / 128)) break;
return LD_DWORD(&fs->win[((WORD)clust * 4) % 512]) & 0x0FFFFFFF;
#endif
}
}
 
return 1; /* There is no cluster information, or an error occured */
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Change a cluster status */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
BOOL put_cluster ( /* TRUE: successful, FALSE: failed */
CLUST clust, /* Cluster# to change */
CLUST val /* New value to mark the cluster */
)
{
WORD bc;
BYTE *p;
DWORD fatsect;
FATFS *fs = FatFs;
 
 
fatsect = fs->fatbase;
switch (fs->fs_type) {
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fatsect + bc / 512)) return FALSE;
p = &fs->win[bc % 512];
*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
bc++;
fs->winflag = 1;
if (!move_window(fatsect + bc / 512)) return FALSE;
p = &fs->win[bc % 512];
*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
break;
 
case FS_FAT16 :
if (!move_window(fatsect + clust / 256)) return FALSE;
ST_WORD(&fs->win[((WORD)clust * 2) % 512], (WORD)val);
break;
#if _FAT32
case FS_FAT32 :
if (!move_window(fatsect + clust / 128)) return FALSE;
ST_DWORD(&fs->win[((WORD)clust * 4) % 512], val);
break;
#endif
default :
return FALSE;
}
fs->winflag = 1;
return TRUE;
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Remove a cluster chain */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
BOOL remove_chain ( /* TRUE: successful, FALSE: failed */
CLUST clust /* Cluster# to remove chain from */
)
{
CLUST nxt;
FATFS *fs = FatFs;
 
 
while (clust >= 2 && clust < fs->max_clust) {
nxt = get_cluster(clust);
if (nxt == 1) return FALSE;
if (!put_cluster(clust, 0)) return FALSE;
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
fs->free_clust++;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
clust = nxt;
}
return TRUE;
}
#endif
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Stretch or create a cluster chain */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
CLUST create_chain ( /* 0: no free cluster, 1: error, >=2: new cluster number */
CLUST clust /* Cluster# to stretch, 0 means create new */
)
{
CLUST cstat, ncl, scl, mcl;
FATFS *fs = FatFs;
 
 
mcl = fs->max_clust;
if (clust == 0) { /* Create new chain */
scl = fs->last_clust; /* Get last allocated cluster */
if (scl < 2 || scl >= mcl) scl = 1;
}
else { /* Stretch existing chain */
cstat = get_cluster(clust); /* Check the cluster status */
if (cstat < 2) return 1; /* It is an invalid cluster */
if (cstat < mcl) return cstat; /* It is already followed by next cluster */
scl = clust;
}
 
ncl = scl; /* Start cluster */
for (;;) {
ncl++; /* Next cluster */
if (ncl >= mcl) { /* Wrap around */
ncl = 2;
if (ncl > scl) return 0; /* No free custer */
}
cstat = get_cluster(ncl); /* Get the cluster status */
if (cstat == 0) break; /* Found a free cluster */
if (cstat == 1) return 1; /* Any error occured */
if (ncl == scl) return 0; /* No free custer */
}
 
if (!put_cluster(ncl, (CLUST)0x0FFFFFFF)) return 1; /* Mark the new cluster "in use" */
if (clust && !put_cluster(clust, ncl)) return 1; /* Link it to previous one if needed */
 
fs->last_clust = ncl; /* Update fsinfo */
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
fs->free_clust--;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
 
return ncl; /* Return new cluster number */
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get sector# from cluster# */
/*-----------------------------------------------------------------------*/
 
static
DWORD clust2sect ( /* !=0: sector number, 0: failed - invalid cluster# */
CLUST clust /* Cluster# to be converted */
)
{
FATFS *fs = FatFs;
 
 
clust -= 2;
if (clust >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */
return (DWORD)clust * fs->sects_clust + fs->database;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Move directory pointer to next */
/*-----------------------------------------------------------------------*/
 
static
BOOL next_dir_entry ( /* TRUE: successful, FALSE: could not move next */
DIR *dirobj /* Pointer to directory object */
)
{
CLUST clust;
WORD idx;
FATFS *fs = FatFs;
 
 
idx = dirobj->index + 1;
if ((idx & 15) == 0) { /* Table sector changed? */
dirobj->sect++; /* Next sector */
if (!dirobj->clust) { /* In static table */
if (idx >= fs->n_rootdir) return FALSE; /* Reached to end of table */
} else { /* In dynamic table */
if (((idx / 16) & (fs->sects_clust - 1)) == 0) { /* Cluster changed? */
clust = get_cluster(dirobj->clust); /* Get next cluster */
if (clust < 2 || clust >= fs->max_clust) /* Reached to end of table */
return FALSE;
dirobj->clust = clust; /* Initialize for new cluster */
dirobj->sect = clust2sect(clust);
}
}
}
dirobj->index = idx; /* Lower 4 bit of dirobj->index indicates offset in dirobj->sect */
return TRUE;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Get file status from directory entry */
/*-----------------------------------------------------------------------*/
 
#if _FS_MINIMIZE <= 1
static
void get_fileinfo ( /* No return code */
FILINFO *finfo, /* Ptr to store the File Information */
const BYTE *dir /* Ptr to the directory entry */
)
{
BYTE n, c, a;
char *p;
 
 
p = &finfo->fname[0];
a = _USE_NTFLAG ? dir[DIR_NTres] : 0; /* NT flag */
for (n = 0; n < 8; n++) { /* Convert file name (body) */
c = dir[n];
if (c == ' ') break;
if (c == 0x05) c = 0xE5;
if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20;
*p++ = c;
}
if (dir[8] != ' ') { /* Convert file name (extension) */
*p++ = '.';
for (n = 8; n < 11; n++) {
c = dir[n];
if (c == ' ') break;
if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20;
*p++ = c;
}
}
*p = '\0';
 
finfo->fattrib = dir[DIR_Attr]; /* Attribute */
finfo->fsize = LD_DWORD(&dir[DIR_FileSize]); /* Size */
finfo->fdate = LD_WORD(&dir[DIR_WrtDate]); /* Date */
finfo->ftime = LD_WORD(&dir[DIR_WrtTime]); /* Time */
}
#endif /* _FS_MINIMIZE <= 1 */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Pick a paragraph and create the name in format of directory entry */
/*-----------------------------------------------------------------------*/
 
static
char make_dirfile ( /* 1: error - detected an invalid format, '\0'or'/': next character */
const char **path, /* Pointer to the file path pointer */
char *dirname /* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */
)
{
BYTE n, t, c, a, b;
 
 
memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
a = 0; b = 0x18; /* NT flag */
n = 0; t = 8;
for (;;) {
c = *(*path)++;
if (c == '\0' || c == '/') { /* Reached to end of str or directory separator */
if (n == 0) break;
dirname[11] = _USE_NTFLAG ? (a & b) : 0;
return c;
}
if (c <= ' ' || c == 0x7F) break; /* Reject invisible chars */
if (c == '.') {
if (!(a & 1) && n >= 1 && n <= 8) { /* Enter extension part */
n = 8; t = 11; continue;
}
break;
}
if (_USE_SJIS &&
((c >= 0x81 && c <= 0x9F) || /* Accept S-JIS code */
(c >= 0xE0 && c <= 0xFC))) {
if (n == 0 && c == 0xE5) /* Change heading \xE5 to \x05 */
c = 0x05;
a ^= 1; goto md_l2;
}
if (c == '"') break; /* Reject " */
if (c <= ')') goto md_l1; /* Accept ! # $ % & ' ( ) */
if (c <= ',') break; /* Reject * + , */
if (c <= '9') goto md_l1; /* Accept - 0-9 */
if (c <= '?') break; /* Reject : ; < = > ? */
if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
if (c == '|') break; /* Reject | */
if (c >= '[' && c <= ']') break;/* Reject [ \ ] */
if (_USE_NTFLAG && c >= 'A' && c <= 'Z')
(t == 8) ? (b &= ~0x08) : (b &= ~0x10);
if (c >= 'a' && c <= 'z') { /* Convert to upper case */
c -= 0x20;
if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10);
}
}
md_l1:
a &= ~1;
md_l2:
if (n >= t) break;
dirname[n++] = c;
}
return 1;
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Trace a file path */
/*-----------------------------------------------------------------------*/
 
static
FRESULT trace_path ( /* FR_OK(0): successful, !=0: error code */
DIR *dirobj, /* Pointer to directory object to return last directory */
char *fn, /* Pointer to last segment name to return */
const char *path, /* Full-path string to trace a file or directory */
BYTE **dir /* Directory pointer in Win[] to retutn */
)
{
CLUST clust;
char ds;
BYTE *dptr = NULL;
FATFS *fs = FatFs;
 
/* Initialize directory object */
clust = fs->dirbase;
#if _FAT32
if (fs->fs_type == FS_FAT32) {
dirobj->clust = dirobj->sclust = clust;
dirobj->sect = clust2sect(clust);
} else
#endif
{
dirobj->clust = dirobj->sclust = 0;
dirobj->sect = clust;
}
dirobj->index = 0;
dirobj->fs = fs;
 
if (*path == '\0') { /* Null path means the root directory */
*dir = NULL; return FR_OK;
}
 
for (;;) {
ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */
if (ds == 1) return FR_INVALID_NAME;
for (;;) {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
if (dptr[DIR_Name] == 0) /* Has it reached to end of dir? */
return !ds ? FR_NO_FILE : FR_NO_PATH;
if (dptr[DIR_Name] != 0xE5 /* Matched? */
&& !(dptr[DIR_Attr] & AM_VOL)
&& !memcmp(&dptr[DIR_Name], fn, 8+3) ) break;
if (!next_dir_entry(dirobj)) /* Next directory pointer */
return !ds ? FR_NO_FILE : FR_NO_PATH;
}
if (!ds) { *dir = dptr; return FR_OK; } /* Matched with end of path */
if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */
clust = /* Get cluster# of the directory */
#if _FAT32
((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dptr[DIR_FstClusLO]);
dirobj->clust = dirobj->sclust = clust; /* Restart scannig with the new directory */
dirobj->sect = clust2sect(clust);
dirobj->index = 2;
}
}
 
 
 
/*-----------------------------------------------------------------------*/
/* Reserve a directory entry */
/*-----------------------------------------------------------------------*/
 
#if !_FS_READONLY
static
FRESULT reserve_direntry ( /* FR_OK: successful, FR_DENIED: no free entry, FR_RW_ERROR: a disk error occured */
DIR *dirobj, /* Target directory to create new entry */
BYTE **dir /* Pointer to pointer to created entry to retutn */
)
{
CLUST clust;
DWORD sector;
BYTE c, n, *dptr;
FATFS *fs = FatFs;
 
 
/* Re-initialize directory object */
clust = dirobj->sclust;
if (clust) { /* Dyanmic directory table */
dirobj->clust = clust;
dirobj->sect = clust2sect(clust);
} else { /* Static directory table */
dirobj->sect = fs->dirbase;
}
dirobj->index = 0;
 
do {
if (!move_window(dirobj->sect)) return FR_RW_ERROR;
dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */
c = dptr[DIR_Name];
if (c == 0 || c == 0xE5) { /* Found an empty entry! */
*dir = dptr; return FR_OK;
}
} while (next_dir_entry(dirobj)); /* Next directory pointer */
/* Reached to end of the directory table */
 
/* Abort when static table or could not stretch dynamic table */
if (!clust || !(clust = create_chain(dirobj->clust))) return FR_DENIED;
if (clust == 1 || !move_window(0)) return FR_RW_ERROR;
 
fs->winsect = sector = clust2sect(clust); /* Cleanup the expanded table */
memset(fs->win, 0, 512);
for (n = fs->sects_clust; n; n--) {
if (disk_write(0, fs->win, sector, 1) != RES_OK)
return FR_RW_ERROR;
sector++;
}
fs->winflag = 1;
*dir = fs->win;
return FR_OK;
}
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Load boot record and check if it is a FAT boot record */
/*-----------------------------------------------------------------------*/
 
static
BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error */
DWORD sect /* Sector# to check if it is a FAT boot record or not */
)
{
FATFS *fs = FatFs;
 
if (disk_read(0, fs->win, sect, 1) != RES_OK) /* Load boot record */
return 2;
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;
 
if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3)) /* Check FAT signature */
return 0;
#if _FAT32
if (!memcmp(&fs->win[BS_FilSysType32], "FAT32", 5) && !(fs->win[BPB_ExtFlags] & 0x80))
return 0;
#endif
return 1;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Make sure that the file system is valid */
/*-----------------------------------------------------------------------*/
 
static
FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */
const char **path, /* Pointer to pointer to the path name (drive number) */
BYTE chk_wp /* !=0: Check media write protection for wrinting fuctions */
)
{
BYTE fmt;
DSTATUS stat;
DWORD bootsect, fatsize, totalsect, maxclust;
const char *p = *path;
FATFS *fs = FatFs;
 
 
 
while (*p == ' ') p++; /* Strip leading spaces */
if (*p == '/') p++; /* Strip heading slash */
*path = p; /* Return pointer to the path name */
 
/* Is the file system object registered? */
if (!fs) return FR_NOT_ENABLED;
 
/* Chekck if the logical drive has been mounted or not */
if (fs->fs_type) {
stat = disk_status(0);
if (!(stat & STA_NOINIT)) { /* If the physical drive is kept initialized */
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
#endif
return FR_OK; /* The file system object is valid */
}
}
 
/* The logical drive has not been mounted, following code attempts to mount the logical drive */
 
memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
stat = disk_initialize(0); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY;
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;
#endif
 
/* Search FAT partition on the drive */
fmt = check_fs(bootsect = 0); /* Check sector 0 as an SFD format */
if (fmt == 1) { /* Not a FAT boot record, it may be patitioned */
/* Check a partition listed in top of the partition table */
if (fs->win[MBR_Table+4]) { /* Is the 1st partition existing? */
bootsect = LD_DWORD(&fs->win[MBR_Table+8]); /* Partition offset in LBA */
fmt = check_fs(bootsect); /* Check the partition */
}
}
if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;
 
/* Initialize the file system object */
fatsize = LD_WORD(&fs->win[BPB_FATSz16]); /* Number of sectors per FAT */
if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]);
fs->sects_fat = (CLUST)fatsize;
fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */
fatsize *= fs->n_fats; /* (Number of sectors in FAT area) */
fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */
fs->sects_clust = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */
fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]); /* Nmuber of root directory entries */
totalsect = LD_WORD(&fs->win[BPB_TotSec16]); /* Number of sectors on the file system */
if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]);
fs->max_clust = maxclust = (totalsect /* Last cluster# + 1 */
- LD_WORD(&fs->win[BPB_RsvdSecCnt]) - fatsize - fs->n_rootdir / 16
) / fs->sects_clust + 2;
 
fmt = FS_FAT12; /* Determine the FAT sub type */
if (maxclust > 0xFF7) fmt = FS_FAT16;
if (maxclust > 0xFFF7)
#if !_FAT32
return FR_NO_FILESYSTEM;
#else
fmt = FS_FAT32;
if (fmt == FS_FAT32)
fs->dirbase = LD_DWORD(&fs->win[BPB_RootClus]); /* Root directory start cluster */
else
#endif
fs->dirbase = fs->fatbase + fatsize; /* Root directory start sector (lba) */
fs->database = fs->fatbase + fatsize + fs->n_rootdir / 16; /* Data start sector (lba) */
fs->fs_type = fmt; /* FAT sub-type */
 
#if !_FS_READONLY
fs->free_clust = (CLUST)0xFFFFFFFF;
#if _USE_FSINFO
/* Load fsinfo sector if needed */
if (fmt == FS_FAT32) {
fs->fsi_sector = bootsect + LD_WORD(&fs->win[BPB_FSInfo]);
if (disk_read(0, fs->win, fs->fsi_sector, 1) == RES_OK &&
LD_WORD(&fs->win[BS_55AA]) == 0xAA55 &&
LD_DWORD(&fs->win[FSI_LeadSig]) == 0x41615252 &&
LD_DWORD(&fs->win[FSI_StrucSig]) == 0x61417272) {
fs->last_clust = LD_DWORD(&fs->win[FSI_Nxt_Free]);
fs->free_clust = LD_DWORD(&fs->win[FSI_Free_Count]);
}
}
#endif
#endif
fs->id = ++fsid; /* File system mount ID */
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Check if the file/dir object is valid or not */
/*-----------------------------------------------------------------------*/
 
static
FRESULT validate ( /* FR_OK(0): The id is valid, !=0: Not valid */
const FATFS *fs, /* Pointer to the file system object */
WORD id /* id member of the target object to be checked */
)
{
if (!fs || fs->id != id)
return FR_INVALID_OBJECT;
if (disk_status(0) & STA_NOINIT)
return FR_NOT_READY;
 
return FR_OK;
}
 
 
 
 
/*--------------------------------------------------------------------------
 
Public Functions
 
--------------------------------------------------------------------------*/
 
 
/*-----------------------------------------------------------------------*/
/* Mount/Unmount a Locical Drive */
/*-----------------------------------------------------------------------*/
 
FRESULT f_mount (
BYTE drv, /* Logical drive number to be mounted/unmounted */
FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
)
{
FATFS *fsobj;
 
 
if (drv) return FR_INVALID_DRIVE;
fsobj = FatFs;
FatFs = fs;
if (fsobj) memset(fsobj, 0, sizeof(FATFS));
if (fs) memset(fs, 0, sizeof(FATFS));
 
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Open or Create a File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_open (
FIL *fp, /* Pointer to the blank file object */
const char *path, /* Pointer to the file name */
BYTE mode /* Access mode and file open mode flags */
)
{
FRESULT res;
BYTE *dir;
DIR dirobj;
char fn[8+3+1];
FATFS *fs = FatFs;
 
 
fp->fs = NULL;
#if !_FS_READONLY
mode &= (FA_READ|FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW);
res = auto_mount(&path, (BYTE)(mode & (FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)));
#else
mode &= FA_READ;
res = auto_mount(&path, 0);
#endif
if (res != FR_OK) return res;
 
/* Trace the file path */
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
 
#if !_FS_READONLY
/* Create or Open a File */
if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)) {
CLUST rs;
DWORD dw;
if (res != FR_OK) { /* No file, create new */
if (res != FR_NO_FILE) return res;
res = reserve_direntry(&dirobj, &dir);
if (res != FR_OK) return res;
memset(dir, 0, 32); /* Initialize the new entry */
memcpy(&dir[DIR_Name], fn, 8+3);
dir[DIR_NTres] = fn[11];
mode |= FA_CREATE_ALWAYS;
} else { /* Any object is already existing */
if (mode & FA_CREATE_NEW) /* Cannot create new */
return FR_EXIST;
if (dir == NULL || (dir[DIR_Attr] & (AM_RDO|AM_DIR))) /* Cannot overwrite (R/O or DIR) */
return FR_DENIED;
if (mode & FA_CREATE_ALWAYS) { /* Resize it to zero */
#if _FAT32
rs = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]);
ST_WORD(&dir[DIR_FstClusHI], 0);
#else
rs = LD_WORD(&dir[DIR_FstClusLO]);
#endif
ST_WORD(&dir[DIR_FstClusLO], 0); /* cluster = 0 */
ST_DWORD(&dir[DIR_FileSize], 0); /* size = 0 */
fs->winflag = 1;
dw = fs->winsect; /* Remove the cluster chain */
if (!remove_chain(rs) || !move_window(dw))
return FR_RW_ERROR;
fs->last_clust = rs - 1; /* Reuse the cluster hole */
}
}
if (mode & FA_CREATE_ALWAYS) {
dir[DIR_Attr] = AM_ARC; /* New attribute */
dw = get_fattime();
ST_DWORD(&dir[DIR_WrtTime], dw); /* Updated time */
ST_DWORD(&dir[DIR_CrtTime], dw); /* Created time */
fs->winflag = 1;
}
}
/* Open a File */
else {
#endif /* !_FS_READONLY */
if (res != FR_OK) return res; /* Trace failed */
if (dir == NULL || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */
return FR_NO_FILE;
#if !_FS_READONLY
if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */
return FR_DENIED;
}
 
fp->dir_sect = fs->winsect; /* Pointer to the directory entry */
fp->dir_ptr = dir;
#endif
fp->flag = mode; /* File access mode */
fp->org_clust = /* File start cluster */
#if _FAT32
((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dir[DIR_FstClusLO]);
fp->fsize = LD_DWORD(&dir[DIR_FileSize]); /* File size */
fp->fptr = 0; /* File ptr */
fp->sect_clust = 1; /* Sector counter */
fp->fs = fs; fp->id = fs->id; /* Owner file system object of the file */
 
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Read File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_read (
FIL *fp, /* Pointer to the file object */
void *buff, /* Pointer to data buffer */
WORD btr, /* Number of bytes to read */
WORD *br /* Pointer to number of bytes read */
)
{
DWORD sect, remain;
WORD rcnt;
CLUST clust;
BYTE cc, *rbuff = buff;
FRESULT res;
FATFS *fs = fp->fs;
 
 
*br = 0;
res = validate(fs, fp->id); /* Check validity of the object */
if (res) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
remain = fp->fsize - fp->fptr;
if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */
 
for ( ; btr; /* Repeat until all data transferred */
rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
if ((fp->fptr % 512) == 0) { /* On the sector boundary */
if (--fp->sect_clust) { /* Decrement left sector counter */
sect = fp->curr_sect + 1; /* Get current sector */
} else { /* On the cluster boundary, get next cluster */
clust = (fp->fptr == 0) ?
fp->org_clust : get_cluster(fp->curr_clust);
if (clust < 2 || clust >= fs->max_clust)
goto fr_error;
fp->curr_clust = clust; /* Current cluster */
sect = clust2sect(clust); /* Get current sector */
fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */
}
fp->curr_sect = sect; /* Update current sector */
cc = btr / 512; /* When left bytes >= 512, */
if (cc) { /* Read maximum contiguous sectors directly */
if (cc > fp->sect_clust) cc = fp->sect_clust;
if (disk_read(0, rbuff, sect, cc) != RES_OK)
goto fr_error;
fp->sect_clust -= cc - 1;
fp->curr_sect += cc - 1;
rcnt = cc * 512; continue;
}
}
if (!move_window(fp->curr_sect)) goto fr_error; /* Move sector window */
rcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes from sector window */
if (rcnt > btr) rcnt = btr;
memcpy(rbuff, &fs->win[(WORD)fp->fptr % 512], rcnt);
}
 
return FR_OK;
 
fr_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
#if !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Write File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_write (
FIL *fp, /* Pointer to the file object */
const void *buff, /* Pointer to the data to be written */
WORD btw, /* Number of bytes to write */
WORD *bw /* Pointer to number of bytes written */
)
{
DWORD sect;
WORD wcnt;
CLUST clust;
BYTE cc;
FRESULT res;
const BYTE *wbuff = buff;
FATFS *fs = fp->fs;
 
 
*bw = 0;
res = validate(fs, fp->id); /* Check validity of the object */
if (res) return res;
if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */
 
for ( ; btw; /* Repeat until all data transferred */
wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
if ((fp->fptr % 512) == 0) { /* On the sector boundary */
if (--(fp->sect_clust)) { /* Decrement left sector counter */
sect = fp->curr_sect + 1; /* Get current sector */
} else { /* On the cluster boundary, get next cluster */
if (fp->fptr == 0) { /* Is top of the file */
clust = fp->org_clust;
if (clust == 0) /* No cluster is created yet */
fp->org_clust = clust = create_chain(0); /* Create a new cluster chain */
} else { /* Middle or end of file */
clust = create_chain(fp->curr_clust); /* Trace or streach cluster chain */
}
if (clust == 0) break; /* Disk full */
if (clust == 1 || clust >= fs->max_clust) goto fw_error;
fp->curr_clust = clust; /* Current cluster */
sect = clust2sect(clust); /* Get current sector */
fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */
}
fp->curr_sect = sect; /* Update current sector */
cc = btw / 512; /* When left bytes >= 512, */
if (cc) { /* Write maximum contiguous sectors directly */
if (cc > fp->sect_clust) cc = fp->sect_clust;
if (disk_write(0, wbuff, sect, cc) != RES_OK)
goto fw_error;
fp->sect_clust -= cc - 1;
fp->curr_sect += cc - 1;
wcnt = cc * 512; continue;
}
if (fp->fptr >= fp->fsize) { /* Flush R/W window if needed */
if (!move_window(0)) goto fw_error;
fs->winsect = fp->curr_sect;
}
}
if (!move_window(fp->curr_sect)) /* Move sector window */
goto fw_error;
wcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes bytes to sector window */
if (wcnt > btw) wcnt = btw;
memcpy(&fs->win[(WORD)fp->fptr % 512], wbuff, wcnt);
fs->winflag = 1;
}
 
if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */
fp->flag |= FA__WRITTEN; /* Set file changed flag */
return FR_OK;
 
fw_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Synchronize between File and Disk */
/*-----------------------------------------------------------------------*/
 
FRESULT f_sync (
FIL *fp /* Pointer to the file object */
)
{
DWORD tim;
BYTE *dir;
FRESULT res;
FATFS *fs = fp->fs;
 
 
res = validate(fs, fp->id); /* Check validity of the object */
if (res == FR_OK) {
if (fp->flag & FA__WRITTEN) { /* Has the file been written? */
/* Update the directory entry */
if (!move_window(fp->dir_sect))
return FR_RW_ERROR;
dir = fp->dir_ptr;
dir[DIR_Attr] |= AM_ARC; /* Set archive bit */
ST_DWORD(&dir[DIR_FileSize], fp->fsize); /* Update file size */
ST_WORD(&dir[DIR_FstClusLO], fp->org_clust); /* Update start cluster */
#if _FAT32
ST_WORD(&dir[DIR_FstClusHI], fp->org_clust >> 16);
#endif
tim = get_fattime(); /* Updated time */
ST_DWORD(&dir[DIR_WrtTime], tim);
fp->flag &= ~FA__WRITTEN;
res = sync();
}
}
return res;
}
 
#endif /* !_FS_READONLY */
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Close File */
/*-----------------------------------------------------------------------*/
 
FRESULT f_close (
FIL *fp /* Pointer to the file object to be closed */
)
{
FRESULT res;
 
 
#if !_FS_READONLY
res = f_sync(fp);
#else
res = validate(fp->fs, fp->id);
#endif
if (res == FR_OK)
fp->fs = NULL;
 
return res;
}
 
 
 
 
#if _FS_MINIMIZE <= 2
/*-----------------------------------------------------------------------*/
/* Seek File Pointer */
/*-----------------------------------------------------------------------*/
 
FRESULT f_lseek (
FIL *fp, /* Pointer to the file object */
DWORD ofs /* File pointer from top of file */
)
{
CLUST clust;
DWORD csize;
BYTE csect;
FRESULT res;
FATFS *fs = fp->fs;
 
 
res = validate(fs, fp->id); /* Check validity of the object */
if (res) return res;
 
if (fp->flag & FA__ERROR) return FR_RW_ERROR;
#if !_FS_READONLY
if (ofs > fp->fsize && !(fp->flag & FA_WRITE))
#else
if (ofs > fp->fsize)
#endif
ofs = fp->fsize;
fp->fptr = 0; fp->sect_clust = 1; /* Set file R/W pointer to top of the file */
 
/* Move file R/W pointer if needed */
if (ofs) {
clust = fp->org_clust; /* Get start cluster */
#if !_FS_READONLY
if (!clust) { /* If the file does not have a cluster chain, create new cluster chain */
clust = create_chain(0);
if (clust == 1) goto fk_error;
fp->org_clust = clust;
}
#endif
if (clust) { /* If the file has a cluster chain, it can be followed */
csize = (DWORD)fs->sects_clust * 512; /* Cluster size in unit of byte */
for (;;) { /* Loop to skip leading clusters */
fp->curr_clust = clust; /* Update current cluster */
if (ofs <= csize) break;
#if !_FS_READONLY
if (fp->flag & FA_WRITE) /* Check if in write mode or not */
clust = create_chain(clust); /* Force streached if in write mode */
else
#endif
clust = get_cluster(clust); /* Only follow cluster chain if not in write mode */
if (clust == 0) { /* Stop if could not follow the cluster chain */
ofs = csize; break;
}
if (clust == 1 || clust >= fs->max_clust) goto fk_error;
fp->fptr += csize; /* Update R/W pointer */
ofs -= csize;
}
csect = (BYTE)((ofs - 1) / 512); /* Sector offset in the cluster */
fp->curr_sect = clust2sect(clust) + csect; /* Current sector */
fp->sect_clust = fs->sects_clust - csect; /* Left sector counter in the cluster */
fp->fptr += ofs; /* Update file R/W pointer */
}
}
#if !_FS_READONLY
if ((fp->flag & FA_WRITE) && fp->fptr > fp->fsize) { /* Set updated flag if in write mode */
fp->fsize = fp->fptr;
fp->flag |= FA__WRITTEN;
}
#endif
 
return FR_OK;
 
fk_error: /* Abort this function due to an unrecoverable error */
fp->flag |= FA__ERROR;
return FR_RW_ERROR;
}
 
 
 
 
#if _FS_MINIMIZE <= 1
/*-----------------------------------------------------------------------*/
/* Open a directroy */
/*-----------------------------------------------------------------------*/
 
FRESULT f_opendir (
DIR *dirobj, /* Pointer to directory object to create */
const char *path /* Pointer to the directory path */
)
{
BYTE *dir;
char fn[8+3+1];
FRESULT res;
FATFS *fs = FatFs;
 
 
res = auto_mount(&path, 0);
if (res != FR_OK) return res;
 
res = trace_path(dirobj, fn, path, &dir); /* Trace the directory path */
if (res == FR_OK) { /* Trace completed */
if (dir != NULL) { /* It is not the root dir */
if (dir[DIR_Attr] & AM_DIR) { /* The entry is a directory */
dirobj->clust =
#if _FAT32
((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dir[DIR_FstClusLO]);
dirobj->sect = clust2sect(dirobj->clust);
dirobj->index = 2;
} else { /* The entry is not a directory */
res = FR_NO_FILE;
}
}
dirobj->id = fs->id;
}
return res;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Read Directory Entry in Sequense */
/*-----------------------------------------------------------------------*/
 
FRESULT f_readdir (
DIR *dirobj, /* Pointer to the directory object */
FILINFO *finfo /* Pointer to file information to return */
)
{
BYTE *dir, c;
FRESULT res;
FATFS *fs = dirobj->fs;
 
 
res = validate(fs, dirobj->id); /* Check validity of the object */
if (res) return res;
 
finfo->fname[0] = 0;
while (dirobj->sect) {
if (!move_window(dirobj->sect))
return FR_RW_ERROR;
dir = &fs->win[(dirobj->index & 15) * 32]; /* pointer to the directory entry */
c = dir[DIR_Name];
if (c == 0) break; /* Has it reached to end of dir? */
if (c != 0xE5 && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */
get_fileinfo(finfo, dir);
if (!next_dir_entry(dirobj)) dirobj->sect = 0; /* Next entry */
if (finfo->fname[0]) break; /* Found valid entry */
}
 
return FR_OK;
}
 
 
 
 
#if _FS_MINIMIZE == 0
/*-----------------------------------------------------------------------*/
/* Get File Status */
/*-----------------------------------------------------------------------*/
 
FRESULT f_stat (
const char *path, /* Pointer to the file path */
FILINFO *finfo /* Pointer to file information to return */
)
{
BYTE *dir;
char fn[8+3+1];
FRESULT res;
DIR dirobj;
 
 
res = auto_mount(&path, 0);
if (res != FR_OK) return res;
 
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) { /* Trace completed */
if (dir) /* Found an object */
get_fileinfo(finfo, dir);
else /* It is root dir */
res = FR_INVALID_NAME;
}
 
return res;
}
 
 
 
 
#if !_FS_READONLY
/*-----------------------------------------------------------------------*/
/* Get Number of Free Clusters */
/*-----------------------------------------------------------------------*/
 
FRESULT f_getfree (
const char *drv, /* Logical drive number */
DWORD *nclust, /* Pointer to the double word to return number of free clusters */
FATFS **fatfs /* Pointer to pointer to the file system object to return */
)
{
DWORD n, sect;
CLUST clust;
BYTE fat, f, *p;
FRESULT res;
FATFS *fs;
 
 
/* Get drive number */
res = auto_mount(&drv, 0);
if (res != FR_OK) return res;
*fatfs = fs = FatFs;
 
/* If number of free cluster is valid, return it without cluster scan. */
if (fs->free_clust <= fs->max_clust - 2) {
*nclust = fs->free_clust;
return FR_OK;
}
 
/* Count number of free clusters */
fat = fs->fs_type;
n = 0;
if (fat == FS_FAT12) {
clust = 2;
do {
if ((WORD)get_cluster(clust) == 0) n++;
} while (++clust < fs->max_clust);
} else {
clust = fs->max_clust;
sect = fs->fatbase;
f = 0; p = 0;
do {
if (!f) {
if (!move_window(sect++)) return FR_RW_ERROR;
p = fs->win;
}
if (!_FAT32 || fat == FS_FAT16) {
if (LD_WORD(p) == 0) n++;
p += 2; f += 1;
} else {
if (LD_DWORD(p) == 0) n++;
p += 4; f += 2;
}
} while (--clust);
}
fs->free_clust = n;
#if _USE_FSINFO
if (fat == FS_FAT32) fs->fsi_flag = 1;
#endif
 
*nclust = n;
return FR_OK;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Delete a File or a Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_unlink (
const char *path /* Pointer to the file or directory path */
)
{
BYTE *dir, *sdir;
DWORD dsect;
char fn[8+3+1];
CLUST dclust;
FRESULT res;
DIR dirobj;
FATFS *fs = FatFs;
 
 
res = auto_mount(&path, 1);
if (res != FR_OK) return res;
 
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
if (res != FR_OK) return res; /* Trace failed */
if (dir == NULL) return FR_INVALID_NAME; /* It is the root directory */
if (dir[DIR_Attr] & AM_RDO) return FR_DENIED; /* It is a R/O object */
dsect = fs->winsect;
dclust =
#if _FAT32
((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) |
#endif
LD_WORD(&dir[DIR_FstClusLO]);
if (dir[DIR_Attr] & AM_DIR) { /* It is a sub-directory */
dirobj.clust = dclust; /* Check if the sub-dir is empty or not */
dirobj.sect = clust2sect(dclust);
dirobj.index = 2;
do {
if (!move_window(dirobj.sect)) return FR_RW_ERROR;
sdir = &fs->win[(dirobj.index & 15) * 32];
if (sdir[DIR_Name] == 0) break;
if (sdir[DIR_Name] != 0xE5 && !(sdir[DIR_Attr] & AM_VOL))
return FR_DENIED; /* The directory is not empty */
} while (next_dir_entry(&dirobj));
}
 
if (!move_window(dsect)) return FR_RW_ERROR; /* Mark the directory entry 'deleted' */
dir[DIR_Name] = 0xE5;
fs->winflag = 1;
if (!remove_chain(dclust)) return FR_RW_ERROR; /* Remove the cluster chain */
 
return sync();
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Create a Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_mkdir (
const char *path /* Pointer to the directory path */
)
{
BYTE *dir, *fw, n;
char fn[8+3+1];
DWORD sect, dsect, tim;
CLUST dclust, pclust;
FRESULT res;
DIR dirobj;
FATFS *fs = FatFs;
 
 
res = auto_mount(&path, 1);
if (res != FR_OK) return res;
 
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) return FR_EXIST; /* Any file or directory is already existing */
if (res != FR_NO_FILE) return res;
 
res = reserve_direntry(&dirobj, &dir); /* Reserve a directory entry */
if (res != FR_OK) return res;
sect = fs->winsect;
dclust = create_chain(0); /* Allocate a cluster for new directory table */
if (dclust == 1) return FR_RW_ERROR;
dsect = clust2sect(dclust);
if (!dsect) return FR_DENIED;
if (!move_window(dsect)) return FR_RW_ERROR;
 
fw = fs->win;
memset(fw, 0, 512); /* Clear the directory table */
for (n = 1; n < fs->sects_clust; n++) {
if (disk_write(0, fw, ++dsect, 1) != RES_OK)
return FR_RW_ERROR;
}
 
memset(&fw[DIR_Name], ' ', 8+3); /* Create "." entry */
fw[DIR_Name] = '.';
fw[DIR_Attr] = AM_DIR;
tim = get_fattime();
ST_DWORD(&fw[DIR_WrtTime], tim);
memcpy(&fw[32], &fw[0], 32); fw[33] = '.'; /* Create ".." entry */
pclust = dirobj.sclust;
#if _FAT32
ST_WORD(&fw[ DIR_FstClusHI], dclust >> 16);
if (fs->fs_type == FS_FAT32 && pclust == fs->dirbase) pclust = 0;
ST_WORD(&fw[32+DIR_FstClusHI], pclust >> 16);
#endif
ST_WORD(&fw[ DIR_FstClusLO], dclust);
ST_WORD(&fw[32+DIR_FstClusLO], pclust);
fs->winflag = 1;
 
if (!move_window(sect)) return FR_RW_ERROR;
memset(&dir[0], 0, 32); /* Clean-up the new entry */
memcpy(&dir[DIR_Name], fn, 8+3); /* Name */
dir[DIR_NTres] = fn[11];
dir[DIR_Attr] = AM_DIR; /* Attribute */
ST_DWORD(&dir[DIR_WrtTime], tim); /* Crated time */
ST_WORD(&dir[DIR_FstClusLO], dclust); /* Table start cluster */
#if _FAT32
ST_WORD(&dir[DIR_FstClusHI], dclust >> 16);
#endif
 
return sync();
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Change File Attribute */
/*-----------------------------------------------------------------------*/
 
FRESULT f_chmod (
const char *path, /* Pointer to the file path */
BYTE value, /* Attribute bits */
BYTE mask /* Attribute mask to change */
)
{
FRESULT res;
BYTE *dir;
DIR dirobj;
char fn[8+3+1];
 
 
res = auto_mount(&path, 1);
if (res == FR_OK) {
res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) { /* Trace completed */
if (dir == NULL) {
res = FR_INVALID_NAME;
} else {
mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */
dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */
res = sync();
}
}
}
return res;
}
 
 
 
 
/*-----------------------------------------------------------------------*/
/* Rename File/Directory */
/*-----------------------------------------------------------------------*/
 
FRESULT f_rename (
const char *path_old, /* Pointer to the old name */
const char *path_new /* Pointer to the new name */
)
{
FRESULT res;
DWORD sect_old;
BYTE *dir_old, *dir_new, direntry[32-11];
DIR dirobj;
char fn[8+3+1];
FATFS *fs = FatFs;
 
 
res = auto_mount(&path_old, 1);
if (res != FR_OK) return res;
 
res = trace_path(&dirobj, fn, path_old, &dir_old); /* Check old object */
if (res != FR_OK) return res; /* The old object is not found */
if (!dir_old) return FR_NO_FILE;
sect_old = fs->winsect; /* Save the object information */
memcpy(direntry, &dir_old[11], 32-11);
 
res = trace_path(&dirobj, fn, path_new, &dir_new); /* Check new object */
if (res == FR_OK) return FR_EXIST; /* The new object name is already existing */
if (res != FR_NO_FILE) return res; /* Is there no old name? */
res = reserve_direntry(&dirobj, &dir_new); /* Reserve a directory entry */
if (res != FR_OK) return res;
 
memcpy(&dir_new[DIR_Attr], direntry, 32-11); /* Create new entry */
memcpy(&dir_new[DIR_Name], fn, 8+3);
dir_new[DIR_NTres] = fn[11];
fs->winflag = 1;
 
if (!move_window(sect_old)) return FR_RW_ERROR; /* Remove old entry */
dir_old[DIR_Name] = 0xE5;
 
return sync();
}
 
#endif /* !_FS_READONLY */
#endif /* _FS_MINIMIZE == 0 */
#endif /* _FS_MINIMIZE <= 1 */
#endif /* _FS_MINIMIZE <= 2 */
 
/Designs/GPSRL03A/tff.h
0,0 → 1,289
/*--------------------------------------------------------------------------/
/ Tiny-FatFs - FAT file system module include file R0.04b (C)ChaN, 2007
/---------------------------------------------------------------------------/
/ FatFs module is an experimenal project to implement FAT file system to
/ cheap microcontrollers. This is a free software and is opened for education,
/ research and development under license policy of following trems.
/
/ Copyright (C) 2007, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is no warranty.
/ * You can use, modify and/or redistribute it for personal, non-profit or
/ profit use without any restriction under your responsibility.
/ * Redistributions of source code must retain the above copyright notice.
/
/---------------------------------------------------------------------------*/
 
#ifndef _FATFS
 
#define _MCU_ENDIAN 1
/* The _MCU_ENDIAN defines which access method is used to the FAT structure.
/ 1: Enable word access.
/ 2: Disable word access and use byte-by-byte access instead.
/ When the architectural byte order of the MCU is big-endian and/or address
/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2.
/ If it is not the case, it can be set to 1 for good code efficiency. */
 
#define _FS_READONLY 0
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename
/ and useless f_getfree. */
 
#define _FS_MINIMIZE 2
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
/ 0: Full function.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed.
/ 2: f_opendir and f_readdir are removed in addition to level 1.
/ 3: f_lseek is removed in addition to level 2. */
 
#define _FAT32 0
/* To support FAT32 in addition of FAT12/16, set _FAT32 to 1. */
 
#define _USE_FSINFO 0
/* To support FSInfo on FAT32 volume, set _USE_FSINFO to 1. */
 
#define _USE_SJIS 0
/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise
/ only US-ASCII(7bit) code can be accepted as file/directory name. */
 
#define _USE_NTFLAG 1
/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. */
 
 
#include "integer.h"
 
 
/* Type definition for cluster number */
#if _FAT32
typedef DWORD CLUST;
#else
typedef WORD CLUST;
#undef _USE_FSINFO
#define _USE_FSINFO 0
#endif
 
 
/* File system object structure */
typedef struct _FATFS {
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries */
DWORD winsect; /* Current sector appearing in the win[] */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector */
DWORD database; /* Data start sector */
CLUST sects_fat; /* Sectors per fat */
CLUST max_clust; /* Maximum cluster# + 1 */
#if !_FS_READONLY
CLUST last_clust; /* Last allocated cluster */
CLUST free_clust; /* Number of free clusters */
#if _USE_FSINFO
DWORD fsi_sector; /* fsinfo sector */
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
BYTE pad1;
#endif
#endif
BYTE fs_type; /* FAT sub type */
BYTE sects_clust; /* Sectors per cluster */
BYTE n_fats; /* Number of FAT copies */
BYTE winflag; /* win[] dirty flag (1:must be written back) */
BYTE win[512]; /* Disk access window for Directory/FAT/File */
} FATFS;
 
 
/* Directory object structure */
typedef struct _DIR {
WORD id; /* Owner file system mount ID */
WORD index; /* Current index */
FATFS* fs; /* Pointer to the owner file system object */
CLUST sclust; /* Start cluster */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
} DIR;
 
 
/* File object structure */
typedef struct _FIL {
WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */
BYTE sect_clust; /* Left sectors in cluster */
FATFS* fs; /* Pointer to owner file system */
DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */
CLUST org_clust; /* File start cluster */
CLUST curr_clust; /* Current cluster */
DWORD curr_sect; /* Current sector */
#if !_FS_READONLY
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
} FIL;
 
 
/* File status structure */
typedef struct _FILINFO {
DWORD fsize; /* Size */
WORD fdate; /* Date */
WORD ftime; /* Time */
BYTE fattrib; /* Attribute */
char fname[8+1+3+1]; /* Name (8.3 format) */
} FILINFO;
 
 
/* File function return code (FRESULT) */
 
typedef enum {
FR_OK = 0, /* 0 */
FR_NOT_READY, /* 1 */
FR_NO_FILE, /* 2 */
FR_NO_PATH, /* 3 */
FR_INVALID_NAME, /* 4 */
FR_INVALID_DRIVE, /* 5 */
FR_DENIED, /* 6 */
FR_EXIST, /* 7 */
FR_RW_ERROR, /* 8 */
FR_WRITE_PROTECTED, /* 9 */
FR_NOT_ENABLED, /* 10 */
FR_NO_FILESYSTEM, /* 11 */
FR_INVALID_OBJECT /* 12 */
} FRESULT;
 
 
 
/*-----------------------------------------------------*/
/* FatFs module application interface */
 
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */
FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
 
 
/* User defined function to give a current time to fatfs module */
 
DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
 
 
 
/* File access control and file status flags (FIL.flag) */
 
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#if !_FS_READONLY
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20
#endif
#define FA__ERROR 0x80
 
 
/* FAT sub type (FATFS.fs_type) */
 
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
 
 
/* File attribute bits for directory entry */
 
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
 
 
 
/* Offset of FAT structure members */
 
#define BS_jmpBoot 0
#define BS_OEMName 3
#define BPB_BytsPerSec 11
#define BPB_SecPerClus 13
#define BPB_RsvdSecCnt 14
#define BPB_NumFATs 16
#define BPB_RootEntCnt 17
#define BPB_TotSec16 19
#define BPB_Media 21
#define BPB_FATSz16 22
#define BPB_SecPerTrk 24
#define BPB_NumHeads 26
#define BPB_HiddSec 28
#define BPB_TotSec32 32
#define BS_55AA 510
 
#define BS_DrvNum 36
#define BS_BootSig 38
#define BS_VolID 39
#define BS_VolLab 43
#define BS_FilSysType 54
 
#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 BS_DrvNum32 64
#define BS_BootSig32 66
#define BS_VolID32 67
#define BS_VolLab32 71
#define BS_FilSysType32 82
 
#define FSI_LeadSig 0
#define FSI_StrucSig 484
#define FSI_Free_Count 488
#define FSI_Nxt_Free 492
 
#define MBR_Table 446
 
#define DIR_Name 0
#define DIR_Attr 11
#define DIR_NTres 12
#define DIR_CrtTime 14
#define DIR_CrtDate 16
#define DIR_FstClusHI 20
#define DIR_WrtTime 22
#define DIR_WrtDate 24
#define DIR_FstClusLO 26
#define DIR_FileSize 28
 
 
 
/* Multi-byte word access macros */
 
#if _MCU_ENDIAN == 1 /* Use word access */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else
#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24)
#else
#error Do not forget to set _MCU_ENDIAN properly!
#endif
#endif
 
 
 
#define _FATFS
#endif /* _FATFS */
/Designs/GPSRL03A/tt.ini
0,0 → 1,0
bps=115200