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 #ifndef MBED_DIRHANDLE_H
yihui 0:700cadd8b708 17 #define MBED_DIRHANDLE_H
yihui 0:700cadd8b708 18
yihui 0:700cadd8b708 19 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
yihui 0:700cadd8b708 20 # define NAME_MAX 255
yihui 0:700cadd8b708 21 typedef int mode_t;
yihui 0:700cadd8b708 22
yihui 0:700cadd8b708 23 #else
yihui 0:700cadd8b708 24 # include <sys/syslimits.h>
yihui 0:700cadd8b708 25 #endif
yihui 0:700cadd8b708 26
yihui 0:700cadd8b708 27 #include "FileHandle.h"
yihui 0:700cadd8b708 28
yihui 0:700cadd8b708 29 struct dirent {
yihui 0:700cadd8b708 30 char d_name[NAME_MAX+1];
yihui 0:700cadd8b708 31 };
yihui 0:700cadd8b708 32
yihui 0:700cadd8b708 33 namespace mbed {
yihui 0:700cadd8b708 34
yihui 0:700cadd8b708 35 /** Represents a directory stream. Objects of this type are returned
yihui 0:700cadd8b708 36 * by a FileSystemLike's opendir method. Implementations must define
yihui 0:700cadd8b708 37 * at least closedir, readdir and rewinddir.
yihui 0:700cadd8b708 38 *
yihui 0:700cadd8b708 39 * If a FileSystemLike class defines the opendir method, then the
yihui 0:700cadd8b708 40 * directories of an object of that type can be accessed by
yihui 0:700cadd8b708 41 * DIR *d = opendir("/example/directory") (or opendir("/example")
yihui 0:700cadd8b708 42 * to open the root of the filesystem), and then using readdir(d) etc.
yihui 0:700cadd8b708 43 *
yihui 0:700cadd8b708 44 * The root directory is considered to contain all FileLike and
yihui 0:700cadd8b708 45 * FileSystemLike objects, so the DIR* returned by opendir("/") will
yihui 0:700cadd8b708 46 * reflect this.
yihui 0:700cadd8b708 47 */
yihui 0:700cadd8b708 48 class DirHandle {
yihui 0:700cadd8b708 49
yihui 0:700cadd8b708 50 public:
yihui 0:700cadd8b708 51 /** Closes the directory.
yihui 0:700cadd8b708 52 *
yihui 0:700cadd8b708 53 * @returns
yihui 0:700cadd8b708 54 * 0 on success,
yihui 0:700cadd8b708 55 * -1 on error.
yihui 0:700cadd8b708 56 */
yihui 0:700cadd8b708 57 virtual int closedir()=0;
yihui 0:700cadd8b708 58
yihui 0:700cadd8b708 59 /** Return the directory entry at the current position, and
yihui 0:700cadd8b708 60 * advances the position to the next entry.
yihui 0:700cadd8b708 61 *
yihui 0:700cadd8b708 62 * @returns
yihui 0:700cadd8b708 63 * A pointer to a dirent structure representing the
yihui 0:700cadd8b708 64 * directory entry at the current position, or NULL on reaching
yihui 0:700cadd8b708 65 * end of directory or error.
yihui 0:700cadd8b708 66 */
yihui 0:700cadd8b708 67 virtual struct dirent *readdir()=0;
yihui 0:700cadd8b708 68
yihui 0:700cadd8b708 69 /** Resets the position to the beginning of the directory.
yihui 0:700cadd8b708 70 */
yihui 0:700cadd8b708 71 virtual void rewinddir()=0;
yihui 0:700cadd8b708 72
yihui 0:700cadd8b708 73 /** Returns the current position of the DirHandle.
yihui 0:700cadd8b708 74 *
yihui 0:700cadd8b708 75 * @returns
yihui 0:700cadd8b708 76 * the current position,
yihui 0:700cadd8b708 77 * -1 on error.
yihui 0:700cadd8b708 78 */
yihui 0:700cadd8b708 79 virtual off_t telldir() { return -1; }
yihui 0:700cadd8b708 80
yihui 0:700cadd8b708 81 /** Sets the position of the DirHandle.
yihui 0:700cadd8b708 82 *
yihui 0:700cadd8b708 83 * @param location The location to seek to. Must be a value returned by telldir.
yihui 0:700cadd8b708 84 */
yihui 0:700cadd8b708 85 virtual void seekdir(off_t location) { }
yihui 0:700cadd8b708 86
yihui 0:700cadd8b708 87 virtual ~DirHandle() {}
yihui 0:700cadd8b708 88 };
yihui 0:700cadd8b708 89
yihui 0:700cadd8b708 90 } // namespace mbed
yihui 0:700cadd8b708 91
yihui 0:700cadd8b708 92 typedef mbed::DirHandle DIR;
yihui 0:700cadd8b708 93
yihui 0:700cadd8b708 94 extern "C" {
yihui 0:700cadd8b708 95 DIR *opendir(const char*);
yihui 0:700cadd8b708 96 struct dirent *readdir(DIR *);
yihui 0:700cadd8b708 97 int closedir(DIR*);
yihui 0:700cadd8b708 98 void rewinddir(DIR*);
yihui 0:700cadd8b708 99 long telldir(DIR*);
yihui 0:700cadd8b708 100 void seekdir(DIR*, long);
yihui 0:700cadd8b708 101 int mkdir(const char *name, mode_t n);
yihui 0:700cadd8b708 102 };
yihui 0:700cadd8b708 103
yihui 0:700cadd8b708 104 #endif /* MBED_DIRHANDLE_H */