SD Card Interface class. Log raw data bytes to memory addresses of your choice, or format the card and use the FAT file system to write files.

Dependencies:   mbed

Committer:
Blaze513
Date:
Sun Jan 16 09:20:30 2011 +0000
Revision:
6:ddf09d859ed7
Parent:
4:9a5878d316d5
gave access to Initialization function to FAT module.
added disk formatting functionality.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Blaze513 4:9a5878d316d5 1 /* mbed Microcontroller Library - FATFileHandle
Blaze513 4:9a5878d316d5 2 Copyright (c) 2008, sford */
Blaze513 4:9a5878d316d5 3
Blaze513 4:9a5878d316d5 4 //Modified by Thomas Hamilton, Copyright 2010
Blaze513 4:9a5878d316d5 5
Blaze513 4:9a5878d316d5 6 #include "FATFileHandle.h"
Blaze513 4:9a5878d316d5 7
Blaze513 4:9a5878d316d5 8 FATFileHandle::FATFileHandle(FAT_FIL InputFilStr)
Blaze513 4:9a5878d316d5 9 {
Blaze513 4:9a5878d316d5 10 FileObject = InputFilStr;
Blaze513 4:9a5878d316d5 11 }
Blaze513 4:9a5878d316d5 12
Blaze513 4:9a5878d316d5 13 ssize_t FATFileHandle::write(const void* buffer, size_t length)
Blaze513 4:9a5878d316d5 14 {
Blaze513 4:9a5878d316d5 15 UINT ByteWritten;
Blaze513 4:9a5878d316d5 16 if (f_write(&FileObject, buffer, (UINT)length, &ByteWritten))
Blaze513 4:9a5878d316d5 17 {
Blaze513 4:9a5878d316d5 18 return -1;
Blaze513 4:9a5878d316d5 19 }
Blaze513 4:9a5878d316d5 20 else
Blaze513 4:9a5878d316d5 21 {
Blaze513 4:9a5878d316d5 22 return (ssize_t)ByteWritten;
Blaze513 4:9a5878d316d5 23 }
Blaze513 4:9a5878d316d5 24 }
Blaze513 4:9a5878d316d5 25
Blaze513 4:9a5878d316d5 26 int FATFileHandle::close()
Blaze513 4:9a5878d316d5 27 {
Blaze513 4:9a5878d316d5 28 if (f_close(&FileObject))
Blaze513 4:9a5878d316d5 29 {
Blaze513 4:9a5878d316d5 30 return -1;
Blaze513 4:9a5878d316d5 31 }
Blaze513 4:9a5878d316d5 32 else
Blaze513 4:9a5878d316d5 33 {
Blaze513 4:9a5878d316d5 34 delete this;
Blaze513 4:9a5878d316d5 35 return 0;
Blaze513 4:9a5878d316d5 36 }
Blaze513 4:9a5878d316d5 37 }
Blaze513 4:9a5878d316d5 38
Blaze513 4:9a5878d316d5 39 ssize_t FATFileHandle::read(void* buffer, size_t length)
Blaze513 4:9a5878d316d5 40 {
Blaze513 4:9a5878d316d5 41 UINT ByteRead;
Blaze513 4:9a5878d316d5 42 if (f_read(&FileObject, buffer, (UINT)length, &ByteRead))
Blaze513 4:9a5878d316d5 43 {
Blaze513 4:9a5878d316d5 44 return -1;
Blaze513 4:9a5878d316d5 45 }
Blaze513 4:9a5878d316d5 46 else
Blaze513 4:9a5878d316d5 47 {
Blaze513 4:9a5878d316d5 48 return (ssize_t)ByteRead;
Blaze513 4:9a5878d316d5 49 }
Blaze513 4:9a5878d316d5 50 }
Blaze513 4:9a5878d316d5 51
Blaze513 4:9a5878d316d5 52 int FATFileHandle::isatty()
Blaze513 4:9a5878d316d5 53 {
Blaze513 4:9a5878d316d5 54 return 0;
Blaze513 4:9a5878d316d5 55 }
Blaze513 4:9a5878d316d5 56
Blaze513 4:9a5878d316d5 57 off_t FATFileHandle::lseek(off_t offset, int whence)
Blaze513 4:9a5878d316d5 58 {
Blaze513 4:9a5878d316d5 59 switch (whence)
Blaze513 4:9a5878d316d5 60 {
Blaze513 4:9a5878d316d5 61 case SEEK_CUR: offset += FileObject.fptr; break;
Blaze513 4:9a5878d316d5 62 case SEEK_END: offset += FileObject.fsize; break;
Blaze513 4:9a5878d316d5 63 }
Blaze513 4:9a5878d316d5 64 if (f_lseek(&FileObject, (DWORD)offset))
Blaze513 4:9a5878d316d5 65 {
Blaze513 4:9a5878d316d5 66 return -1;
Blaze513 4:9a5878d316d5 67 }
Blaze513 4:9a5878d316d5 68 else
Blaze513 4:9a5878d316d5 69 {
Blaze513 4:9a5878d316d5 70 return (off_t)FileObject.fptr;
Blaze513 4:9a5878d316d5 71 }
Blaze513 4:9a5878d316d5 72 }
Blaze513 4:9a5878d316d5 73
Blaze513 4:9a5878d316d5 74 int FATFileHandle::fsync()
Blaze513 4:9a5878d316d5 75 {
Blaze513 4:9a5878d316d5 76 if (f_sync(&FileObject))
Blaze513 4:9a5878d316d5 77 {
Blaze513 4:9a5878d316d5 78 return -1;
Blaze513 4:9a5878d316d5 79 }
Blaze513 4:9a5878d316d5 80 else
Blaze513 4:9a5878d316d5 81 {
Blaze513 4:9a5878d316d5 82 return 0;
Blaze513 4:9a5878d316d5 83 }
Blaze513 4:9a5878d316d5 84 }
Blaze513 4:9a5878d316d5 85
Blaze513 4:9a5878d316d5 86 off_t FATFileHandle::flen()
Blaze513 4:9a5878d316d5 87 {
Blaze513 4:9a5878d316d5 88 return (off_t)FileObject.fsize;
Blaze513 1:94c648931f84 89 }