rtos sd encoder systems

Dependencies:   mbed

Committer:
eembed
Date:
Fri Aug 30 11:55:47 2019 +0000
Revision:
3:a921792d9913
Parent:
0:5459cdde6298
commit before edit; ~JKD;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eembed 0:5459cdde6298 1 /* mbed Microcontroller Library
eembed 0:5459cdde6298 2 * Copyright (c) 2006-2012 ARM Limited
eembed 0:5459cdde6298 3 *
eembed 0:5459cdde6298 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
eembed 0:5459cdde6298 5 * of this software and associated documentation files (the "Software"), to deal
eembed 0:5459cdde6298 6 * in the Software without restriction, including without limitation the rights
eembed 0:5459cdde6298 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
eembed 0:5459cdde6298 8 * copies of the Software, and to permit persons to whom the Software is
eembed 0:5459cdde6298 9 * furnished to do so, subject to the following conditions:
eembed 0:5459cdde6298 10 *
eembed 0:5459cdde6298 11 * The above copyright notice and this permission notice shall be included in
eembed 0:5459cdde6298 12 * all copies or substantial portions of the Software.
eembed 0:5459cdde6298 13 *
eembed 0:5459cdde6298 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
eembed 0:5459cdde6298 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
eembed 0:5459cdde6298 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
eembed 0:5459cdde6298 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
eembed 0:5459cdde6298 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
eembed 0:5459cdde6298 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
eembed 0:5459cdde6298 20 * SOFTWARE.
eembed 0:5459cdde6298 21 */
eembed 0:5459cdde6298 22 #include "ff.h"
eembed 0:5459cdde6298 23 #include "ffconf.h"
eembed 0:5459cdde6298 24 #include "mbed_debug.h"
eembed 0:5459cdde6298 25
eembed 0:5459cdde6298 26 #include "FATFileHandle.h"
eembed 0:5459cdde6298 27
eembed 0:5459cdde6298 28 FATFileHandle::FATFileHandle(FIL fh) {
eembed 0:5459cdde6298 29 _fh = fh;
eembed 0:5459cdde6298 30 }
eembed 0:5459cdde6298 31
eembed 0:5459cdde6298 32 int FATFileHandle::close() {
eembed 0:5459cdde6298 33 int retval = f_close(&_fh);
eembed 0:5459cdde6298 34 delete this;
eembed 0:5459cdde6298 35 return retval;
eembed 0:5459cdde6298 36 }
eembed 0:5459cdde6298 37
eembed 0:5459cdde6298 38 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
eembed 0:5459cdde6298 39 UINT n;
eembed 0:5459cdde6298 40 FRESULT res = f_write(&_fh, buffer, length, &n);
eembed 0:5459cdde6298 41 if (res) {
eembed 0:5459cdde6298 42 debug_if(FFS_DBG, "f_write() failed: %d", res);
eembed 0:5459cdde6298 43 return -1;
eembed 0:5459cdde6298 44 }
eembed 0:5459cdde6298 45 return n;
eembed 0:5459cdde6298 46 }
eembed 0:5459cdde6298 47
eembed 0:5459cdde6298 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
eembed 0:5459cdde6298 49 debug_if(FFS_DBG, "read(%d)\n", length);
eembed 0:5459cdde6298 50 UINT n;
eembed 0:5459cdde6298 51 FRESULT res = f_read(&_fh, buffer, length, &n);
eembed 0:5459cdde6298 52 if (res) {
eembed 0:5459cdde6298 53 debug_if(FFS_DBG, "f_read() failed: %d\n", res);
eembed 0:5459cdde6298 54 return -1;
eembed 0:5459cdde6298 55 }
eembed 0:5459cdde6298 56 return n;
eembed 0:5459cdde6298 57 }
eembed 0:5459cdde6298 58
eembed 0:5459cdde6298 59 int FATFileHandle::isatty() {
eembed 0:5459cdde6298 60 return 0;
eembed 0:5459cdde6298 61 }
eembed 0:5459cdde6298 62
eembed 0:5459cdde6298 63 off_t FATFileHandle::lseek(off_t position, int whence) {
eembed 0:5459cdde6298 64 if (whence == SEEK_END) {
eembed 0:5459cdde6298 65 position += _fh.fsize;
eembed 0:5459cdde6298 66 } else if(whence==SEEK_CUR) {
eembed 0:5459cdde6298 67 position += _fh.fptr;
eembed 0:5459cdde6298 68 }
eembed 0:5459cdde6298 69 FRESULT res = f_lseek(&_fh, position);
eembed 0:5459cdde6298 70 if (res) {
eembed 0:5459cdde6298 71 debug_if(FFS_DBG, "lseek failed: %d\n", res);
eembed 0:5459cdde6298 72 return -1;
eembed 0:5459cdde6298 73 } else {
eembed 0:5459cdde6298 74 debug_if(FFS_DBG, "lseek OK, returning %i\n", _fh.fptr);
eembed 0:5459cdde6298 75 return _fh.fptr;
eembed 0:5459cdde6298 76 }
eembed 0:5459cdde6298 77 }
eembed 0:5459cdde6298 78
eembed 0:5459cdde6298 79 int FATFileHandle::fsync() {
eembed 0:5459cdde6298 80 FRESULT res = f_sync(&_fh);
eembed 0:5459cdde6298 81 if (res) {
eembed 0:5459cdde6298 82 debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
eembed 0:5459cdde6298 83 return -1;
eembed 0:5459cdde6298 84 }
eembed 0:5459cdde6298 85 return 0;
eembed 0:5459cdde6298 86 }
eembed 0:5459cdde6298 87
eembed 0:5459cdde6298 88 off_t FATFileHandle::flen() {
eembed 0:5459cdde6298 89 return _fh.fsize;
eembed 0:5459cdde6298 90 }