nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 /* mbed Microcontroller Library
nexpaq 1:55a6170b404f 2 * Copyright (c) 2006-2012 ARM Limited
nexpaq 1:55a6170b404f 3 *
nexpaq 1:55a6170b404f 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
nexpaq 1:55a6170b404f 5 * of this software and associated documentation files (the "Software"), to deal
nexpaq 1:55a6170b404f 6 * in the Software without restriction, including without limitation the rights
nexpaq 1:55a6170b404f 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
nexpaq 1:55a6170b404f 8 * copies of the Software, and to permit persons to whom the Software is
nexpaq 1:55a6170b404f 9 * furnished to do so, subject to the following conditions:
nexpaq 1:55a6170b404f 10 *
nexpaq 1:55a6170b404f 11 * The above copyright notice and this permission notice shall be included in
nexpaq 1:55a6170b404f 12 * all copies or substantial portions of the Software.
nexpaq 1:55a6170b404f 13 *
nexpaq 1:55a6170b404f 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nexpaq 1:55a6170b404f 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nexpaq 1:55a6170b404f 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nexpaq 1:55a6170b404f 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nexpaq 1:55a6170b404f 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nexpaq 1:55a6170b404f 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
nexpaq 1:55a6170b404f 20 * SOFTWARE.
nexpaq 1:55a6170b404f 21 */
nexpaq 1:55a6170b404f 22 #include <string.h>
nexpaq 1:55a6170b404f 23 #include "ff.h"
nexpaq 1:55a6170b404f 24 #include "FATDirHandle.h"
nexpaq 1:55a6170b404f 25
nexpaq 1:55a6170b404f 26 using namespace mbed;
nexpaq 1:55a6170b404f 27
nexpaq 1:55a6170b404f 28 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir, PlatformMutex * mutex): _mutex(mutex) {
nexpaq 1:55a6170b404f 29 dir = the_dir;
nexpaq 1:55a6170b404f 30 }
nexpaq 1:55a6170b404f 31
nexpaq 1:55a6170b404f 32 int FATDirHandle::closedir() {
nexpaq 1:55a6170b404f 33 lock();
nexpaq 1:55a6170b404f 34 int retval = f_closedir(&dir);
nexpaq 1:55a6170b404f 35 unlock();
nexpaq 1:55a6170b404f 36 delete this;
nexpaq 1:55a6170b404f 37 return retval;
nexpaq 1:55a6170b404f 38 }
nexpaq 1:55a6170b404f 39
nexpaq 1:55a6170b404f 40 struct dirent *FATDirHandle::readdir() {
nexpaq 1:55a6170b404f 41 FILINFO finfo;
nexpaq 1:55a6170b404f 42
nexpaq 1:55a6170b404f 43 lock();
nexpaq 1:55a6170b404f 44 #if _USE_LFN
nexpaq 1:55a6170b404f 45 finfo.lfname = cur_entry.d_name;
nexpaq 1:55a6170b404f 46 finfo.lfsize = sizeof(cur_entry.d_name);
nexpaq 1:55a6170b404f 47 #endif // _USE_LFN
nexpaq 1:55a6170b404f 48
nexpaq 1:55a6170b404f 49 FRESULT res = f_readdir(&dir, &finfo);
nexpaq 1:55a6170b404f 50
nexpaq 1:55a6170b404f 51 #if _USE_LFN
nexpaq 1:55a6170b404f 52 if(res != 0 || finfo.fname[0]==0) {
nexpaq 1:55a6170b404f 53 unlock();
nexpaq 1:55a6170b404f 54 return NULL;
nexpaq 1:55a6170b404f 55 } else {
nexpaq 1:55a6170b404f 56 if(cur_entry.d_name[0]==0) {
nexpaq 1:55a6170b404f 57 // No long filename so use short filename.
nexpaq 1:55a6170b404f 58 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
nexpaq 1:55a6170b404f 59 }
nexpaq 1:55a6170b404f 60 unlock();
nexpaq 1:55a6170b404f 61 return &cur_entry;
nexpaq 1:55a6170b404f 62 }
nexpaq 1:55a6170b404f 63 #else
nexpaq 1:55a6170b404f 64 if(res != 0 || finfo.fname[0]==0) {
nexpaq 1:55a6170b404f 65 unlock();
nexpaq 1:55a6170b404f 66 return NULL;
nexpaq 1:55a6170b404f 67 } else {
nexpaq 1:55a6170b404f 68 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
nexpaq 1:55a6170b404f 69 unlock();
nexpaq 1:55a6170b404f 70 return &cur_entry;
nexpaq 1:55a6170b404f 71 }
nexpaq 1:55a6170b404f 72 #endif /* _USE_LFN */
nexpaq 1:55a6170b404f 73 }
nexpaq 1:55a6170b404f 74
nexpaq 1:55a6170b404f 75 void FATDirHandle::rewinddir() {
nexpaq 1:55a6170b404f 76 lock();
nexpaq 1:55a6170b404f 77 dir.index = 0;
nexpaq 1:55a6170b404f 78 unlock();
nexpaq 1:55a6170b404f 79 }
nexpaq 1:55a6170b404f 80
nexpaq 1:55a6170b404f 81 off_t FATDirHandle::telldir() {
nexpaq 1:55a6170b404f 82 lock();
nexpaq 1:55a6170b404f 83 off_t offset = dir.index;
nexpaq 1:55a6170b404f 84 unlock();
nexpaq 1:55a6170b404f 85 return offset;
nexpaq 1:55a6170b404f 86 }
nexpaq 1:55a6170b404f 87
nexpaq 1:55a6170b404f 88 void FATDirHandle::seekdir(off_t location) {
nexpaq 1:55a6170b404f 89 lock();
nexpaq 1:55a6170b404f 90 dir.index = location;
nexpaq 1:55a6170b404f 91 unlock();
nexpaq 1:55a6170b404f 92 }
nexpaq 1:55a6170b404f 93
nexpaq 1:55a6170b404f 94 void FATDirHandle::lock() {
nexpaq 1:55a6170b404f 95 _mutex->lock();
nexpaq 1:55a6170b404f 96 }
nexpaq 1:55a6170b404f 97
nexpaq 1:55a6170b404f 98 void FATDirHandle::unlock() {
nexpaq 1:55a6170b404f 99 _mutex->unlock();
nexpaq 1:55a6170b404f 100 }
nexpaq 1:55a6170b404f 101