customized mbed library sources for nrf51822

Dependents:   Grove_Node Potentiometer BLE_Beacon I2C_Scanner

Committer:
yihui
Date:
Tue Nov 04 07:38:53 2014 +0000
Revision:
0:700cadd8b708
customized mbed-src library for nrf51822

Who changed what in which revision?

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