mbed lib with startup delay fixed for Nucleo401RE
Fork of mbed-src by
cpp/FileSystemLike.cpp@2:143cac498751, 2013-02-18 (annotated)
- Committer:
- emilmont
- Date:
- Mon Feb 18 11:44:18 2013 +0000
- Revision:
- 2:143cac498751
- Parent:
- 1:62685faffa05
Update mbed sources to Rev 59
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:fd0d7bdfcdc2 | 1 | /* mbed Microcontroller Library |
emilmont | 2:143cac498751 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 0:fd0d7bdfcdc2 | 3 | * |
emilmont | 2:143cac498751 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
emilmont | 2:143cac498751 | 5 | * you may not use this file except in compliance with the License. |
emilmont | 2:143cac498751 | 6 | * You may obtain a copy of the License at |
mbed_official | 0:fd0d7bdfcdc2 | 7 | * |
emilmont | 2:143cac498751 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 0:fd0d7bdfcdc2 | 9 | * |
emilmont | 2:143cac498751 | 10 | * Unless required by applicable law or agreed to in writing, software |
emilmont | 2:143cac498751 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
emilmont | 2:143cac498751 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
emilmont | 2:143cac498751 | 13 | * See the License for the specific language governing permissions and |
emilmont | 2:143cac498751 | 14 | * limitations under the License. |
mbed_official | 0:fd0d7bdfcdc2 | 15 | */ |
mbed_official | 0:fd0d7bdfcdc2 | 16 | #include "FileSystemLike.h" |
mbed_official | 0:fd0d7bdfcdc2 | 17 | |
mbed_official | 0:fd0d7bdfcdc2 | 18 | namespace mbed { |
mbed_official | 0:fd0d7bdfcdc2 | 19 | |
mbed_official | 0:fd0d7bdfcdc2 | 20 | class BaseDirHandle : public DirHandle { |
mbed_official | 0:fd0d7bdfcdc2 | 21 | public: |
mbed_official | 0:fd0d7bdfcdc2 | 22 | /* |
mbed_official | 0:fd0d7bdfcdc2 | 23 | We keep track of our current location as the n'th object in the |
mbed_official | 0:fd0d7bdfcdc2 | 24 | FileSystemLike list. Using a Base* instead would cause problems if that |
mbed_official | 0:fd0d7bdfcdc2 | 25 | object were to be destroyed between readdirs. |
mbed_official | 0:fd0d7bdfcdc2 | 26 | Using this method does mean though that destroying/creating objects can |
mbed_official | 0:fd0d7bdfcdc2 | 27 | give unusual results from readdir. |
mbed_official | 0:fd0d7bdfcdc2 | 28 | */ |
mbed_official | 0:fd0d7bdfcdc2 | 29 | off_t n; |
mbed_official | 0:fd0d7bdfcdc2 | 30 | struct dirent cur_entry; |
emilmont | 2:143cac498751 | 31 | |
mbed_official | 0:fd0d7bdfcdc2 | 32 | BaseDirHandle() { |
mbed_official | 0:fd0d7bdfcdc2 | 33 | n = 0; |
mbed_official | 0:fd0d7bdfcdc2 | 34 | } |
emilmont | 2:143cac498751 | 35 | |
mbed_official | 0:fd0d7bdfcdc2 | 36 | virtual int closedir() { |
mbed_official | 0:fd0d7bdfcdc2 | 37 | delete this; |
mbed_official | 0:fd0d7bdfcdc2 | 38 | return 0; |
mbed_official | 0:fd0d7bdfcdc2 | 39 | } |
emilmont | 2:143cac498751 | 40 | |
mbed_official | 0:fd0d7bdfcdc2 | 41 | virtual struct dirent *readdir() { |
emilmont | 2:143cac498751 | 42 | FileBase *ptr = FileBase::get(n); |
emilmont | 2:143cac498751 | 43 | if (ptr == NULL) return NULL; |
emilmont | 2:143cac498751 | 44 | |
mbed_official | 0:fd0d7bdfcdc2 | 45 | /* Increment n, so next readdir gets the next item */ |
mbed_official | 0:fd0d7bdfcdc2 | 46 | n++; |
emilmont | 2:143cac498751 | 47 | |
emilmont | 2:143cac498751 | 48 | /* Setup cur entry and return a pointer to it */ |
emilmont | 2:143cac498751 | 49 | std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX); |
mbed_official | 0:fd0d7bdfcdc2 | 50 | return &cur_entry; |
mbed_official | 0:fd0d7bdfcdc2 | 51 | } |
emilmont | 2:143cac498751 | 52 | |
mbed_official | 0:fd0d7bdfcdc2 | 53 | virtual off_t telldir() { |
mbed_official | 0:fd0d7bdfcdc2 | 54 | return n; |
mbed_official | 0:fd0d7bdfcdc2 | 55 | } |
emilmont | 2:143cac498751 | 56 | |
emilmont | 2:143cac498751 | 57 | virtual void seekdir(off_t offset) { |
mbed_official | 0:fd0d7bdfcdc2 | 58 | n = offset; |
mbed_official | 0:fd0d7bdfcdc2 | 59 | } |
emilmont | 2:143cac498751 | 60 | |
mbed_official | 0:fd0d7bdfcdc2 | 61 | virtual void rewinddir() { |
mbed_official | 0:fd0d7bdfcdc2 | 62 | n = 0; |
mbed_official | 0:fd0d7bdfcdc2 | 63 | } |
mbed_official | 0:fd0d7bdfcdc2 | 64 | }; |
mbed_official | 0:fd0d7bdfcdc2 | 65 | |
emilmont | 2:143cac498751 | 66 | FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) { |
emilmont | 2:143cac498751 | 67 | |
emilmont | 2:143cac498751 | 68 | } |
emilmont | 2:143cac498751 | 69 | |
emilmont | 2:143cac498751 | 70 | FileSystemLike::~FileSystemLike() { |
emilmont | 2:143cac498751 | 71 | |
emilmont | 2:143cac498751 | 72 | } |
emilmont | 2:143cac498751 | 73 | |
mbed_official | 0:fd0d7bdfcdc2 | 74 | DirHandle *FileSystemLike::opendir() { |
mbed_official | 0:fd0d7bdfcdc2 | 75 | return new BaseDirHandle(); |
mbed_official | 0:fd0d7bdfcdc2 | 76 | } |
mbed_official | 0:fd0d7bdfcdc2 | 77 | |
mbed_official | 0:fd0d7bdfcdc2 | 78 | } // namespace mbed |